[cogl/wip/rib/frame-synchronization: 3/5] cogl-hello: use new _add_frame_callback api



commit 1ffe587abbdebc217fd1e76ccc353db528acca44
Author: Robert Bragg <robert linux intel com>
Date:   Tue Jan 29 16:08:36 2013 +0000

    cogl-hello: use new _add_frame_callback api
    
    This updates cogl-hello to use the new
    cogl_onscreen_add_frame_callback() api to use _SYNC events for
    throttling.

 cogl/cogl-context.c   |    2 ++
 examples/cogl-hello.c |   25 +++++++++++--------------
 2 files changed, 13 insertions(+), 14 deletions(-)
---
diff --git a/cogl/cogl-context.c b/cogl/cogl-context.c
index dd645a1..6eab423 100644
--- a/cogl/cogl-context.c
+++ b/cogl/cogl-context.c
@@ -292,6 +292,8 @@ cogl_context_new (CoglDisplay *display,
   context->swap_callback_closures =
     g_hash_table_new (g_direct_hash, g_direct_equal);
 
+  COGL_TAILQ_INIT (&context->onscreen_events_queue);
+
   g_queue_init (&context->gles2_context_stack);
 
   context->journal_flush_attributes_array =
diff --git a/examples/cogl-hello.c b/examples/cogl-hello.c
index f8265f9..8d86a97 100644
--- a/examples/cogl-hello.c
+++ b/examples/cogl-hello.c
@@ -19,20 +19,17 @@ paint_cb (void *user_data)
     cogl_framebuffer_draw_primitive (data->fb, data->pipeline, data->triangle);
     cogl_onscreen_swap_buffers (COGL_ONSCREEN (data->fb));
 
-    /* If the driver can deliver swap complete events then we can remove
-     * the idle paint callback until we next get a swap complete event
-     * otherwise we keep the idle paint callback installed and simply
-     * paint as fast as the driver will allow... */
-    if (cogl_has_feature (data->ctx, COGL_FEATURE_ID_SWAP_BUFFERS_EVENT))
-      return FALSE; /* remove the callback */
-    else
-      return TRUE;
+    return FALSE; /* remove the callback */
 }
 
 static void
-swap_complete_cb (CoglFramebuffer *framebuffer, void *user_data)
+frame_event_cb (CoglOnscreen *onscreen,
+                CoglFrameEvent event,
+                CoglFrameInfo *info,
+                void *user_data)
 {
-    g_idle_add (paint_cb, user_data);
+    if (event == COGL_FRAME_EVENT_SYNC)
+        g_idle_add (paint_cb, user_data);
 }
 
 int
@@ -70,10 +67,10 @@ main (int argc, char **argv)
 
     g_source_attach (cogl_source, NULL);
 
-    if (cogl_has_feature (data.ctx, COGL_FEATURE_ID_SWAP_BUFFERS_EVENT))
-      cogl_onscreen_add_swap_buffers_callback (COGL_ONSCREEN (data.fb),
-                                               swap_complete_cb, &data);
-
+    cogl_onscreen_add_frame_callback (COGL_ONSCREEN (data.fb),
+                                      frame_event_cb,
+                                      &data,
+                                      NULL); /* destroy notify */
     g_idle_add (paint_cb, &data);
 
     loop = g_main_loop_new (NULL, TRUE);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]