[PATCH] Window.c delay redraws with frame callback

Martin Minarik minarik11 at student.fiit.stuba.sk
Sat Mar 17 16:43:02 PDT 2012


---
 clients/window.c |  203
+++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 149 insertions(+), 54 deletions(-)

diff --git a/clients/window.c b/clients/window.c
index 9058e4e..06f0aaa 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -123,6 +117,7 @@ struct window {
 	int x, y;
 	int resize_edges;
 	int redraw_scheduled;
+	int frame_callback_pending;
 	struct task redraw_task;
 	int resize_scheduled;
 	struct task resize_task;
@@ -2105,18 +2155,49 @@ widget_redraw(struct widget *widget)
 		widget->redraw_handler(widget, widget->user_data);
 	wl_list_for_each(child, &widget->child_list, link)
 		widget_redraw(child);
+
+}
+
+static const struct wl_callback_listener frame_listener;
+
+static void redraw_frame_callback(void * data, struct wl_callback *
callback, uint32_t time){
+
+	struct window * window = data;
+
+	window->redraw_scheduled = 0;
+
+	if (callback)
+		wl_callback_destroy(callback);
+
+	window->frame_callback_pending=0;
 }

+static const struct wl_callback_listener frame_listener = {
+	redraw_frame_callback,
+};
+
+
+
 static void
 idle_redraw(struct task *task, uint32_t events)
 {
+	struct wl_callback * callback;
 	struct window *window =
 		container_of(task, struct window, redraw_task);

-	window_create_surface(window);
-	widget_redraw(window->widget);
-	window_flush(window);
-	window->redraw_scheduled = 0;
+
+	callback = wl_surface_frame(window->surface);
+	wl_callback_add_listener(callback,&frame_listener,window);
+
+
+	if  (!window->frame_callback_pending){
+
+		window_create_surface(window);
+		widget_redraw(window->widget);
+		window_flush(window);
+
+		window->frame_callback_pending = 1;
+	}
 }

 void
-- 
1.7.0.4






More information about the wayland-devel mailing list