[gtk/wip/alexl/broadway7: 15/16] broadway: Report some level of frame timings



commit c22986fd257ed3538bc89ff80cca3278dc81332d
Author: Alexander Larsson <alexl redhat com>
Date:   Fri Mar 29 12:31:42 2019 +0100

    broadway: Report some level of frame timings
    
    This is not ideal because we report the time of a full roundtrip, rather
    than the presentation time, but its better than nothing, and i'm not sure
    how the browser time should be reconciled.

 gdk/broadway/gdksurface-broadway.c | 46 ++++++++++++++++++++++++++++++++++++++
 gdk/broadway/gdksurface-broadway.h |  2 ++
 2 files changed, 48 insertions(+)
---
diff --git a/gdk/broadway/gdksurface-broadway.c b/gdk/broadway/gdksurface-broadway.c
index 580f1fecf3..732d2a7fd6 100644
--- a/gdk/broadway/gdksurface-broadway.c
+++ b/gdk/broadway/gdksurface-broadway.c
@@ -128,13 +128,32 @@ _gdk_broadway_roundtrip_notify (GdkSurface  *surface,
                                 guint32 tag,
                                 gboolean local_reply)
 {
+  GdkSurfaceImplBroadway *impl = GDK_SURFACE_IMPL_BROADWAY (surface->impl);
   GdkFrameClock *clock = gdk_surface_get_frame_clock (surface);
+  GdkFrameTimings *timings;
+
+  timings = gdk_frame_clock_get_timings (clock, impl->pending_frame_counter);
+  impl->pending_frame_counter = 0;
 
   /* If there is no remove web client, rate limit update to once a second */
   if (local_reply)
     g_timeout_add_seconds (1, (GSourceFunc)thaw_clock_cb, g_object_ref (clock));
   else
     _gdk_frame_clock_thaw (clock);
+
+  if (timings)
+    {
+      timings->refresh_interval = 33333; /* default to 1/30th of a second */
+      // This isn't quite right, since we've done a rountrip back too, can we do better?
+      timings->presentation_time = g_get_monotonic_time ();
+      timings->complete = TRUE;
+
+
+#ifdef G_ENABLE_DEBUG
+      if ((_gdk_debug_flags & GDK_DEBUG_FRAMES) != 0)
+        _gdk_frame_clock_debug_print_timings (clock, timings);
+#endif
+    }
 }
 
 static void
@@ -145,6 +164,7 @@ on_frame_clock_after_paint (GdkFrameClock *clock,
   GdkSurfaceImplBroadway *impl = GDK_SURFACE_IMPL_BROADWAY (surface->impl);
   GdkBroadwayDisplay *broadway_display;
 
+  impl->pending_frame_counter = gdk_frame_clock_get_frame_counter (clock);
   _gdk_frame_clock_freeze (gdk_surface_get_frame_clock (surface));
 
   broadway_display = GDK_BROADWAY_DISPLAY (display);
@@ -154,6 +174,30 @@ on_frame_clock_after_paint (GdkFrameClock *clock,
   gdk_display_flush (display);
 }
 
+static void
+on_frame_clock_before_paint (GdkFrameClock *clock,
+                             GdkSurface     *surface)
+{
+  GdkFrameTimings *timings = gdk_frame_clock_get_current_timings (clock);
+  gint64 presentation_time;
+  gint64 refresh_interval;
+
+  if (surface->update_freeze_count > 0)
+    return;
+
+  gdk_frame_clock_get_refresh_info (clock,
+                                    timings->frame_time,
+                                    &refresh_interval, &presentation_time);
+  if (presentation_time != 0)
+    {
+      timings->predicted_presentation_time = presentation_time + refresh_interval;
+    }
+  else
+    {
+      timings->predicted_presentation_time = timings->frame_time + refresh_interval / 2 + refresh_interval;
+    }
+}
+
 static void
 connect_frame_clock (GdkSurface *surface)
 {
@@ -161,6 +205,8 @@ connect_frame_clock (GdkSurface *surface)
     {
       GdkFrameClock *frame_clock = gdk_surface_get_frame_clock (surface);
 
+      g_signal_connect (frame_clock, "before-paint",
+                        G_CALLBACK (on_frame_clock_before_paint), surface);
       g_signal_connect (frame_clock, "after-paint",
                         G_CALLBACK (on_frame_clock_after_paint), surface);
     }
diff --git a/gdk/broadway/gdksurface-broadway.h b/gdk/broadway/gdksurface-broadway.h
index a89042e17a..9be2da92df 100644
--- a/gdk/broadway/gdksurface-broadway.h
+++ b/gdk/broadway/gdksurface-broadway.h
@@ -61,6 +61,8 @@ struct _GdkSurfaceImplBroadway
   int pre_maximize_width;
   int pre_maximize_height;
 
+  gint64 pending_frame_counter;
+
   gboolean dirty;
   gboolean last_synced;
 


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