[mutter] frame-clock: Pass timestamp to frame callback



commit 3c4efd13c12547b95da750b87af03d90f7f34261
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Wed Mar 25 18:14:05 2020 +0100

    frame-clock: Pass timestamp to frame callback
    
    The timestamp comes from the GSource, meaning it's a more accurate
    representation of when the frame started to be dispatched compared to
    getting the current time in any callback.
    
    Currently unused.
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1285

 clutter/clutter/clutter-frame-clock.c   | 19 ++++++++++++-------
 clutter/clutter/clutter-frame-clock.h   |  1 +
 src/tests/clutter/conform/frame-clock.c |  7 +++++++
 3 files changed, 20 insertions(+), 7 deletions(-)
---
diff --git a/clutter/clutter/clutter-frame-clock.c b/clutter/clutter/clutter-frame-clock.c
index 44da0c0222..95b6249550 100644
--- a/clutter/clutter/clutter-frame-clock.c
+++ b/clutter/clutter/clutter-frame-clock.c
@@ -307,10 +307,10 @@ clutter_frame_clock_schedule_update (ClutterFrameClock *frame_clock)
   frame_clock->state = CLUTTER_FRAME_CLOCK_STATE_SCHEDULED;
 }
 
-static gboolean
-clutter_frame_clock_dispatch (gpointer user_data)
+static void
+clutter_frame_clock_dispatch (ClutterFrameClock *frame_clock,
+                              int64_t            time_us)
 {
-  ClutterFrameClock *frame_clock = user_data;
   int64_t frame_count;
   ClutterFrameResult result;
 
@@ -334,6 +334,7 @@ clutter_frame_clock_dispatch (gpointer user_data)
   COGL_TRACE_BEGIN (ClutterFrameClockFrame, "Frame Clock (frame)");
   result = frame_clock->listener.iface->frame (frame_clock,
                                                frame_count,
+                                               time_us,
                                                frame_clock->listener.user_data);
   COGL_TRACE_END (ClutterFrameClockFrame);
 
@@ -358,8 +359,6 @@ clutter_frame_clock_dispatch (gpointer user_data)
         }
       break;
     }
-
-  return G_SOURCE_CONTINUE;
 }
 
 static gboolean
@@ -367,7 +366,14 @@ frame_clock_source_dispatch (GSource     *source,
                              GSourceFunc  callback,
                              gpointer     user_data)
 {
-  return callback (user_data);
+  ClutterClockSource *clock_source = (ClutterClockSource *) source;
+  ClutterFrameClock *frame_clock = clock_source->frame_clock;
+  int64_t dispatch_time_us;
+
+  dispatch_time_us = g_source_get_time (source);
+  clutter_frame_clock_dispatch (frame_clock, dispatch_time_us);
+
+  return G_SOURCE_CONTINUE;
 }
 
 static GSourceFuncs frame_clock_source_funcs = {
@@ -391,7 +397,6 @@ init_frame_clock_source (ClutterFrameClock *frame_clock)
   g_source_set_name (source, name);
   g_source_set_priority (source, CLUTTER_PRIORITY_REDRAW);
   g_source_set_can_recurse (source, FALSE);
-  g_source_set_callback (source, clutter_frame_clock_dispatch, frame_clock, NULL);
   clock_source->frame_clock = frame_clock;
 
   frame_clock->source = source;
diff --git a/clutter/clutter/clutter-frame-clock.h b/clutter/clutter/clutter-frame-clock.h
index 217cf771aa..221c393f4a 100644
--- a/clutter/clutter/clutter-frame-clock.h
+++ b/clutter/clutter/clutter-frame-clock.h
@@ -43,6 +43,7 @@ typedef struct _ClutterFrameListenerIface
                          gpointer           user_data);
   ClutterFrameResult (* frame) (ClutterFrameClock *frame_clock,
                                 int64_t            frame_count,
+                                int64_t            time_us,
                                 gpointer           user_data);
 } ClutterFrameListenerIface;
 
diff --git a/src/tests/clutter/conform/frame-clock.c b/src/tests/clutter/conform/frame-clock.c
index a7407e1b63..d99cfa5dfd 100644
--- a/src/tests/clutter/conform/frame-clock.c
+++ b/src/tests/clutter/conform/frame-clock.c
@@ -78,6 +78,7 @@ fake_hw_clock_new (ClutterFrameClock *frame_clock,
 static ClutterFrameResult
 frame_clock_frame (ClutterFrameClock *frame_clock,
                    int64_t            frame_count,
+                   int64_t            time_us,
                    gpointer           user_data)
 {
   FrameClockTest *test = user_data;
@@ -171,6 +172,7 @@ schedule_update_idle (gpointer user_data)
 static ClutterFrameResult
 immediate_frame_clock_frame (ClutterFrameClock *frame_clock,
                              int64_t            frame_count,
+                             int64_t            time_us,
                              gpointer           user_data)
 {
   GMainLoop *main_loop = user_data;
@@ -242,6 +244,7 @@ schedule_update_timeout (gpointer user_data)
 static ClutterFrameResult
 delayed_damage_frame_clock_frame (ClutterFrameClock *frame_clock,
                                   int64_t            frame_count,
+                                  int64_t            time_us,
                                   gpointer           user_data)
 {
   FrameClockTest *test = user_data;
@@ -314,6 +317,7 @@ frame_clock_delayed_damage (void)
 static ClutterFrameResult
 no_damage_frame_clock_frame (ClutterFrameClock *frame_clock,
                              int64_t            frame_count,
+                             int64_t            time_us,
                              gpointer           user_data)
 {
   g_assert_not_reached ();
@@ -366,6 +370,7 @@ typedef struct _UpdateNowFrameClockTest
 static ClutterFrameResult
 update_now_frame_clock_frame (ClutterFrameClock *frame_clock,
                               int64_t            frame_count,
+                              int64_t            time_us,
                               gpointer           user_data)
 {
   UpdateNowFrameClockTest *test = user_data;
@@ -471,6 +476,7 @@ before_frame_frame_clock_before_frame (ClutterFrameClock *frame_clock,
 static ClutterFrameResult
 before_frame_frame_clock_frame (ClutterFrameClock *frame_clock,
                                 int64_t            frame_count,
+                                int64_t            time_us,
                                 gpointer           user_data)
 {
   int64_t *expected_frame_count = user_data;
@@ -537,6 +543,7 @@ typedef struct _InhibitTest
 static ClutterFrameResult
 inhibit_frame_clock_frame (ClutterFrameClock *frame_clock,
                            int64_t            frame_count,
+                           int64_t            time_us,
                            gpointer           user_data)
 {
   InhibitTest *test = user_data;


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