[Cogl] [PATCH] Minor tidy up to share the event notification loop

Neil Roberts neil at linux.intel.com
Tue Jan 29 10:46:10 PST 2013


Previously there were two separate nearly identical functions to emit
either a frame sync or a frame complete event. They only differed by
the event type that they pass to the callback.

There was also a generic _cogl_dispatch_onscreen_events function which
had a switch statement to call the correct one of these functions
depending on the queued event type. To avoid having to keep this
switch statement up-to-date, this patch just moves the event emission
code to a common function which the dispatch function can directly
call with the event type. The two other functions are now just
wrappers around this common function.
---
 cogl/cogl-onscreen.c | 50 +++++++++++++++++++++-----------------------------
 1 file changed, 21 insertions(+), 29 deletions(-)

diff --git a/cogl/cogl-onscreen.c b/cogl/cogl-onscreen.c
index 3887a1a..2f05001 100644
--- a/cogl/cogl-onscreen.c
+++ b/cogl/cogl-onscreen.c
@@ -468,6 +468,24 @@ cogl_onscreen_hide (CoglOnscreen *onscreen)
         winsys->onscreen_set_visibility (onscreen, FALSE);
     }
 }
+
+static void
+notify_event (CoglOnscreen *onscreen,
+              CoglFrameEvent event,
+              CoglFrameInfo *info)
+{
+  CoglFrameClosure *entry, *tmp;
+
+  COGL_TAILQ_FOREACH_SAFE (entry,
+                           &onscreen->frame_closures,
+                           list_node,
+                           tmp)
+    {
+      entry->callback (onscreen, event, info,
+                       entry->user_data);
+    }
+}
+
 void
 _cogl_dispatch_onscreen_events (CoglContext *context)
 {
@@ -481,15 +499,7 @@ _cogl_dispatch_onscreen_events (CoglContext *context)
       CoglOnscreen *onscreen = event->onscreen;
       CoglFrameInfo *info = event->info;
 
-      switch (event->type)
-        {
-        case COGL_FRAME_EVENT_SYNC:
-          _cogl_onscreen_notify_frame_sync (onscreen, info);
-          break;
-        case COGL_FRAME_EVENT_COMPLETE:
-          _cogl_onscreen_notify_complete (onscreen, info);
-          break;
-        }
+      notify_event (onscreen, event->type, info);
 
       cogl_object_unref (onscreen);
       cogl_object_unref (info);
@@ -502,31 +512,13 @@ _cogl_dispatch_onscreen_events (CoglContext *context)
 void
 _cogl_onscreen_notify_frame_sync (CoglOnscreen *onscreen, CoglFrameInfo *info)
 {
-  CoglFrameClosure *entry, *tmp;
-
-  COGL_TAILQ_FOREACH_SAFE (entry,
-                           &onscreen->frame_closures,
-                           list_node,
-                           tmp)
-    {
-      entry->callback (onscreen, COGL_FRAME_EVENT_SYNC, info,
-                       entry->user_data);
-    }
+  notify_event (onscreen, COGL_FRAME_EVENT_SYNC, info);
 }
 
 void
 _cogl_onscreen_notify_complete (CoglOnscreen *onscreen, CoglFrameInfo *info)
 {
-  CoglFrameClosure *entry, *tmp;
-
-  COGL_TAILQ_FOREACH_SAFE (entry,
-                           &onscreen->frame_closures,
-                           list_node,
-                           tmp)
-    {
-      entry->callback (onscreen, COGL_FRAME_EVENT_COMPLETE, info,
-                       entry->user_data);
-    }
+  notify_event (onscreen, COGL_FRAME_EVENT_COMPLETE, info);
 }
 
 void
-- 
1.7.11.3.g3c3efa5



More information about the Cogl mailing list