[mutter/gnome-40] clutter/frame-clock: Remember the refresh interval



commit 032cda47fd28841cd89159754338d403aa6774e5
Author: Daniel van Vugt <daniel van vugt canonical com>
Date:   Wed Jul 15 17:03:27 2020 +0800

    clutter/frame-clock: Remember the refresh interval
    
    Instead of recalculating it every time we need it. The performance
    gain is not important; this is more because it will be needed in
    multiple functions soon.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1826>
    
    (cherry picked from commit ba1490ec9c8dd7b02cf082a3e4c7cc07ad9aa6a1)

 clutter/clutter/clutter-frame-clock.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
---
diff --git a/clutter/clutter/clutter-frame-clock.c b/clutter/clutter/clutter-frame-clock.c
index 05e79e6626..ab52477e3e 100644
--- a/clutter/clutter/clutter-frame-clock.c
+++ b/clutter/clutter/clutter-frame-clock.c
@@ -63,6 +63,7 @@ struct _ClutterFrameClock
   GObject parent;
 
   float refresh_rate;
+  int64_t refresh_interval_us;
   ClutterFrameListener listener;
 
   GSource *source;
@@ -93,6 +94,15 @@ clutter_frame_clock_get_refresh_rate (ClutterFrameClock *frame_clock)
   return frame_clock->refresh_rate;
 }
 
+static void
+clutter_frame_clock_set_refresh_rate (ClutterFrameClock *frame_clock,
+                                      float              refresh_rate)
+{
+  frame_clock->refresh_rate = refresh_rate;
+  frame_clock->refresh_interval_us =
+    (int64_t) (0.5 + G_USEC_PER_SEC / refresh_rate);
+}
+
 void
 clutter_frame_clock_add_timeline (ClutterFrameClock *frame_clock,
                                   ClutterTimeline   *timeline)
@@ -185,7 +195,10 @@ clutter_frame_clock_notify_presented (ClutterFrameClock *frame_clock,
   frame_clock->last_presentation_time_us = frame_info->presentation_time;
 
   if (frame_info->refresh_rate > 1)
-    frame_clock->refresh_rate = frame_info->refresh_rate;
+    {
+      clutter_frame_clock_set_refresh_rate (frame_clock,
+                                            frame_info->refresh_rate);
+    }
 
   switch (frame_clock->state)
     {
@@ -227,7 +240,6 @@ calculate_next_update_time_us (ClutterFrameClock *frame_clock,
 {
   int64_t last_presentation_time_us;
   int64_t now_us;
-  float refresh_rate;
   int64_t refresh_interval_us;
   int64_t min_render_time_allowed_us;
   int64_t max_render_time_allowed_us;
@@ -238,8 +250,7 @@ calculate_next_update_time_us (ClutterFrameClock *frame_clock,
 
   now_us = g_get_monotonic_time ();
 
-  refresh_rate = frame_clock->refresh_rate;
-  refresh_interval_us = (int64_t) (0.5 + G_USEC_PER_SEC / refresh_rate);
+  refresh_interval_us = frame_clock->refresh_interval_us;
 
   if (frame_clock->last_presentation_time_us == 0)
     {
@@ -591,7 +602,7 @@ clutter_frame_clock_new (float                            refresh_rate,
 
   init_frame_clock_source (frame_clock);
 
-  frame_clock->refresh_rate = refresh_rate;
+  clutter_frame_clock_set_refresh_rate (frame_clock, refresh_rate);
 
   return frame_clock;
 }


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