[gtk+/wip/frame-synchronization: 852/857] Merge GdkFrameHistory into GdkFrameClock



commit bc390a7e1a09ad708d276909be51fc4a7caf1754
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Tue Feb 12 15:47:38 2013 -0500

    Merge GdkFrameHistory into GdkFrameClock
    
    Now that GdkFrameClock is a  class, not interface, there's no real advantage
    to splitting the frame history into an aggregate object, so directly
    merge it into GdkFrameClock.

 gdk/Makefile.am            |    2 -
 gdk/gdkframeclock.c        |  183 +++++++++++++++++++++++++++++++++++--------
 gdk/gdkframeclock.h        |    9 ++-
 gdk/gdkframeclockidle.c    |   12 +--
 gdk/gdkframeclockprivate.h |    4 +
 gdk/gdkframehistory.c      |  187 --------------------------------------------
 gdk/gdkframehistory.h      |   49 ------------
 gdk/gdkinternals.h         |    3 -
 gdk/x11/gdkdisplay-x11.c   |   11 +--
 tests/animated-resizing.c  |   13 +--
 tests/video-timer.c        |    9 +--
 11 files changed, 178 insertions(+), 304 deletions(-)
---
diff --git a/gdk/Makefile.am b/gdk/Makefile.am
index 4ef63c0..7b40c5f 100644
--- a/gdk/Makefile.am
+++ b/gdk/Makefile.am
@@ -75,7 +75,6 @@ gdk_public_h_sources = 				\
 	gdkdisplaymanager.h			\
 	gdkdnd.h				\
 	gdkevents.h				\
-	gdkframehistory.h			\
 	gdkframetimings.h			\
 	gdkkeys.h				\
 	gdkkeysyms.h				\
@@ -126,7 +125,6 @@ gdk_c_sources = 				\
 	gdkdisplaymanager.c			\
 	gdkdnd.c				\
 	gdkevents.c     			\
-	gdkframehistory.c			\
 	gdkframetimings.c			\
 	gdkglobals.c				\
 	gdkkeys.c				\
diff --git a/gdk/gdkframeclock.c b/gdk/gdkframeclock.c
index 8cdc1d1..c77127f 100644
--- a/gdk/gdkframeclock.c
+++ b/gdk/gdkframeclock.c
@@ -27,6 +27,7 @@
 #include "config.h"
 
 #include "gdkframeclockprivate.h"
+#include "gdkinternals.h"
 
 /**
  * SECTION:frameclock
@@ -90,17 +91,25 @@ enum {
 
 static guint signals[LAST_SIGNAL];
 
+#define FRAME_HISTORY_MAX_LENGTH 16
+
 struct _GdkFrameClockPrivate
 {
-  GdkFrameHistory *history;
+  gint64 frame_counter;
+  gint n_timings;
+  gint current;
+  GdkFrameTimings *timings[FRAME_HISTORY_MAX_LENGTH];
 };
 
 static void
 gdk_frame_clock_finalize (GObject *object)
 {
   GdkFrameClockPrivate *priv = GDK_FRAME_CLOCK (object)->priv;
+  int i;
 
-  g_object_unref (priv->history);
+  for (i = 0; i < FRAME_HISTORY_MAX_LENGTH; i++)
+    if (priv->timings[i] != 0)
+      gdk_frame_timings_unref (priv->timings[i]);
 
   G_OBJECT_CLASS (gdk_frame_clock_parent_class)->finalize (object);
 }
@@ -254,7 +263,8 @@ gdk_frame_clock_init (GdkFrameClock *clock)
                                              GdkFrameClockPrivate);
   priv = clock->priv;
 
-  priv->history = gdk_frame_history_new ();
+  priv->frame_counter = -1;
+  priv->current = FRAME_HISTORY_MAX_LENGTH - 1;
 }
 
 /**
@@ -326,27 +336,6 @@ gdk_frame_clock_thaw (GdkFrameClock *clock)
 }
 
 /**
- * gdk_frame_clock_get_history:
- * @clock: the clock
- *
- * Gets the #GdkFrameHistory for the frame clock.
- *
- * Since: 3.8
- * Return value: (transfer none): the frame history object
- */
-GdkFrameHistory *
-gdk_frame_clock_get_history (GdkFrameClock *clock)
-{
-  GdkFrameClockPrivate *priv;
-
-  g_return_val_if_fail (GDK_IS_FRAME_CLOCK (clock), NULL);
-
-  priv = clock->priv;
-
-  return priv->history;
-}
-
-/**
  * gdk_frame_clock_get_requested:
  * @clock: the clock
  *
@@ -388,20 +377,150 @@ gdk_frame_clock_get_frame_time_val (GdkFrameClock *clock,
   timeval->tv_usec = (time_ms % 1000) * 1000;
 }
 
+gint64
+gdk_frame_clock_get_frame_counter (GdkFrameClock *clock)
+{
+  GdkFrameClockPrivate *priv;
+
+  g_return_val_if_fail (GDK_IS_FRAME_CLOCK (clock), 0);
+
+  priv = clock->priv;
+
+  return priv->frame_counter;
+}
+
+gint64
+gdk_frame_clock_get_start (GdkFrameClock *clock)
+{
+  GdkFrameClockPrivate *priv;
+
+  g_return_val_if_fail (GDK_IS_FRAME_CLOCK (clock), 0);
+
+  priv = clock->priv;
+
+  return priv->frame_counter + 1 - priv->n_timings;
+}
+
+void
+_gdk_frame_clock_begin_frame (GdkFrameClock *clock)
+{
+  GdkFrameClockPrivate *priv;
+
+  g_return_if_fail (GDK_IS_FRAME_CLOCK (clock));
+
+  priv = clock->priv;
+
+  priv->frame_counter++;
+  priv->current = (priv->current + 1) % FRAME_HISTORY_MAX_LENGTH;
+
+  if (priv->n_timings < FRAME_HISTORY_MAX_LENGTH)
+    priv->n_timings++;
+  else
+    {
+      gdk_frame_timings_unref(priv->timings[priv->current]);
+    }
+
+  priv->timings[priv->current] = gdk_frame_timings_new (priv->frame_counter);
+}
+
+GdkFrameTimings *
+gdk_frame_clock_get_timings (GdkFrameClock *clock,
+                             gint64         frame_counter)
+{
+  GdkFrameClockPrivate *priv;
+  gint pos;
+
+  g_return_val_if_fail (GDK_IS_FRAME_CLOCK (clock), NULL);
+
+  priv = clock->priv;
+
+  if (frame_counter > priv->frame_counter)
+    return NULL;
+
+  if (frame_counter <= priv->frame_counter - priv->n_timings)
+    return NULL;
+
+  pos = (priv->current - (priv->frame_counter - frame_counter) + FRAME_HISTORY_MAX_LENGTH) % FRAME_HISTORY_MAX_LENGTH;
+
+  return priv->timings[pos];
+}
+
 GdkFrameTimings *
 gdk_frame_clock_get_current_frame_timings (GdkFrameClock *clock)
 {
-  GdkFrameHistory *history;
-  gint64 frame_counter;
+  GdkFrameClockPrivate *priv;
 
   g_return_val_if_fail (GDK_IS_FRAME_CLOCK (clock), 0);
 
-  history = gdk_frame_clock_get_history (clock);
-  frame_counter = gdk_frame_history_get_frame_counter (history);
-  return gdk_frame_history_get_timings (history, frame_counter);
+  priv = clock->priv;
+
+  return gdk_frame_clock_get_timings (clock, priv->frame_counter);
 }
 
 
+GdkFrameTimings *
+gdk_frame_clock_get_last_complete (GdkFrameClock *clock)
+{
+  GdkFrameClockPrivate *priv;
+  gint i;
+
+  g_return_val_if_fail (GDK_IS_FRAME_CLOCK (clock), NULL);
+
+  priv = clock->priv;
+
+  for (i = 0; i < priv->n_timings; i++)
+    {
+      gint pos = ((priv->current - i) + FRAME_HISTORY_MAX_LENGTH) % FRAME_HISTORY_MAX_LENGTH;
+      if (gdk_frame_timings_get_complete (priv->timings[pos]))
+        return priv->timings[pos];
+    }
+
+  return NULL;
+}
+
+#ifdef G_ENABLE_DEBUG
+void
+_gdk_frame_clock_debug_print_timings (GdkFrameClock   *clock,
+                                      GdkFrameTimings *timings)
+{
+  gint64 frame_counter = gdk_frame_timings_get_frame_counter (timings);
+  gint64 layout_start_time = _gdk_frame_timings_get_layout_start_time (timings);
+  gint64 paint_start_time = _gdk_frame_timings_get_paint_start_time (timings);
+  gint64 frame_end_time = _gdk_frame_timings_get_frame_end_time (timings);
+  gint64 frame_time = gdk_frame_timings_get_frame_time (timings);
+  gint64 presentation_time = gdk_frame_timings_get_presentation_time (timings);
+  gint64 predicted_presentation_time = gdk_frame_timings_get_predicted_presentation_time (timings);
+  gint64 refresh_interval = gdk_frame_timings_get_refresh_interval (timings);
+  gint64 previous_frame_time = 0;
+  gboolean slept_before = gdk_frame_timings_get_slept_before (timings);
+  GdkFrameTimings *previous_timings = gdk_frame_clock_get_timings (clock,
+                                                                   frame_counter - 1);
+
+  if (previous_timings != NULL)
+    previous_frame_time = gdk_frame_timings_get_frame_time (previous_timings);
+
+  g_print ("%5" G_GINT64_FORMAT ":", frame_counter);
+  if (previous_frame_time != 0)
+    {
+      g_print (" interval=%-4.1f", (frame_time - previous_frame_time) / 1000.);
+      g_print (slept_before ?  " (sleep)" : "        ");
+    }
+  if (layout_start_time != 0)
+    g_print (" layout_start=%-4.1f", (layout_start_time - frame_time) / 1000.);
+  if (paint_start_time != 0)
+    g_print (" paint_start=%-4.1f", (paint_start_time - frame_time) / 1000.);
+  if (frame_end_time != 0)
+    g_print (" frame_end=%-4.1f", (frame_end_time - frame_time) / 1000.);
+  if (presentation_time != 0)
+    g_print (" present=%-4.1f", (presentation_time - frame_time) / 1000.);
+  if (predicted_presentation_time != 0)
+    g_print (" predicted=%-4.1f", (predicted_presentation_time - frame_time) / 1000.);
+  if (refresh_interval != 0)
+    g_print (" refresh_interval=%-4.1f", refresh_interval / 1000.);
+  g_print ("\n");
+}
+#endif /* G_ENABLE_DEBUG */
+
 #define DEFAULT_REFRESH_INTERVAL 16667 /* 16.7ms (1/60th second) */
 #define MAX_HISTORY_AGE 150000         /* 150ms */
 
@@ -411,13 +530,11 @@ gdk_frame_clock_get_refresh_info (GdkFrameClock *clock,
                                   gint64        *refresh_interval_return,
                                   gint64        *presentation_time_return)
 {
-  GdkFrameHistory *history;
   gint64 frame_counter;
 
   g_return_if_fail (GDK_IS_FRAME_CLOCK (clock));
 
-  history = gdk_frame_clock_get_history (clock);
-  frame_counter = gdk_frame_history_get_frame_counter (history);
+  frame_counter = gdk_frame_clock_get_frame_counter (clock);
 
   if (presentation_time_return)
     *presentation_time_return = 0;
@@ -426,7 +543,7 @@ gdk_frame_clock_get_refresh_info (GdkFrameClock *clock,
 
   while (TRUE)
     {
-      GdkFrameTimings *timings = gdk_frame_history_get_timings (history, frame_counter);
+      GdkFrameTimings *timings = gdk_frame_clock_get_timings (clock, frame_counter);
       gint64 presentation_time;
       gint64 refresh_interval;
 
diff --git a/gdk/gdkframeclock.h b/gdk/gdkframeclock.h
index 608d743..3780615 100644
--- a/gdk/gdkframeclock.h
+++ b/gdk/gdkframeclock.h
@@ -31,7 +31,7 @@
 #ifndef __GDK_FRAME_CLOCK_H__
 #define __GDK_FRAME_CLOCK_H__
 
-#include <gdk/gdkframehistory.h>
+#include <gdk/gdkframetimings.h>
 
 G_BEGIN_DECLS
 
@@ -68,7 +68,12 @@ GdkFrameClockPhase gdk_frame_clock_get_requested (GdkFrameClock      *clock);
 void     gdk_frame_clock_freeze              (GdkFrameClock *clock);
 void     gdk_frame_clock_thaw                (GdkFrameClock *clock);
 
-GdkFrameHistory *gdk_frame_clock_get_history (GdkFrameClock *clock);
+/* Frame history */
+gint64           gdk_frame_clock_get_frame_counter (GdkFrameClock *clock);
+gint64           gdk_frame_clock_get_start         (GdkFrameClock *clock);
+GdkFrameTimings *gdk_frame_clock_get_timings       (GdkFrameClock *clock,
+                                                    gint64         frame_counter);
+GdkFrameTimings *gdk_frame_clock_get_last_complete (GdkFrameClock *clock);
 
 /* Convenience API */
 void  gdk_frame_clock_get_frame_time_val (GdkFrameClock  *clock,
diff --git a/gdk/gdkframeclockidle.c b/gdk/gdkframeclockidle.c
index 6a35daa..da05a96 100644
--- a/gdk/gdkframeclockidle.c
+++ b/gdk/gdkframeclockidle.c
@@ -274,10 +274,8 @@ gdk_frame_clock_paint_idle (void *data)
   GdkFrameClock *clock = GDK_FRAME_CLOCK (data);
   GdkFrameClockIdle *clock_idle = GDK_FRAME_CLOCK_IDLE (clock);
   GdkFrameClockIdlePrivate *priv = clock_idle->priv;
-  GdkFrameHistory *history = gdk_frame_clock_get_history (clock);
   gboolean skip_to_resume_events;
   GdkFrameTimings *timings = NULL;
-  gint64 frame_counter = 0;
 
   priv->paint_idle_id = 0;
   priv->in_paint_idle = TRUE;
@@ -288,8 +286,7 @@ gdk_frame_clock_paint_idle (void *data)
 
   if (priv->phase > GDK_FRAME_CLOCK_PHASE_BEFORE_PAINT)
     {
-      frame_counter = gdk_frame_history_get_frame_counter (history);
-      timings = gdk_frame_history_get_timings (history, frame_counter);
+      timings = gdk_frame_clock_get_current_frame_timings (clock);
     }
 
   if (!skip_to_resume_events)
@@ -304,9 +301,8 @@ gdk_frame_clock_paint_idle (void *data)
             {
               priv->frame_time = compute_frame_time (clock_idle);
 
-              gdk_frame_history_begin_frame (history);
-              frame_counter = gdk_frame_history_get_frame_counter (history);
-              timings = gdk_frame_history_get_timings (history, frame_counter);
+              _gdk_frame_clock_begin_frame (clock);
+              timings = gdk_frame_clock_get_current_frame_timings (clock);
 
               gdk_frame_timings_set_frame_time (timings, priv->frame_time);
 
@@ -393,7 +389,7 @@ gdk_frame_clock_paint_idle (void *data)
   if ((_gdk_debug_flags & GDK_DEBUG_FRAMES) != 0)
     {
       if (gdk_frame_timings_get_complete (timings))
-        _gdk_frame_history_debug_print (history, timings);
+        _gdk_frame_clock_debug_print_timings (clock, timings);
     }
 #endif /* G_ENABLE_DEBUG */
 
diff --git a/gdk/gdkframeclockprivate.h b/gdk/gdkframeclockprivate.h
index 6c01dd2..63e2d7e 100644
--- a/gdk/gdkframeclockprivate.h
+++ b/gdk/gdkframeclockprivate.h
@@ -67,6 +67,10 @@ struct _GdkFrameClockClass
   /* void (* resume_events)      (GdkFrameClock *clock); */
 };
 
+void _gdk_frame_clock_begin_frame         (GdkFrameClock   *clock);
+void _gdk_frame_clock_debug_print_timings (GdkFrameClock   *clock,
+                                           GdkFrameTimings *timings);
+
 G_END_DECLS
 
 #endif /* __GDK_FRAME_CLOCK_PRIVATE_H__ */
diff --git a/gdk/gdkinternals.h b/gdk/gdkinternals.h
index 4239188..61ebc19 100644
--- a/gdk/gdkinternals.h
+++ b/gdk/gdkinternals.h
@@ -445,9 +445,6 @@ gint64           _gdk_frame_timings_get_frame_end_time  (GdkFrameTimings *timing
 void             _gdk_frame_timings_set_frame_end_time  (GdkFrameTimings *timings,
                                                          gint64           frame_end_time);
 
-void             _gdk_frame_history_debug_print         (GdkFrameHistory *history,
-                                                         GdkFrameTimings *timings);
-
 #endif /* G_ENABLE_DEBUG */
 
 G_END_DECLS
diff --git a/gdk/x11/gdkdisplay-x11.c b/gdk/x11/gdkdisplay-x11.c
index 466f7e5..8f6fe2b 100644
--- a/gdk/x11/gdkdisplay-x11.c
+++ b/gdk/x11/gdkdisplay-x11.c
@@ -26,6 +26,7 @@
 #include "gdkdisplay.h"
 #include "gdkeventsource.h"
 #include "gdkeventtranslator.h"
+#include "gdkframeclockprivate.h"
 #include "gdkinternals.h"
 #include "gdkscreen.h"
 #include "gdkinternals.h"
@@ -1061,14 +1062,13 @@ static GdkFrameTimings *
 find_frame_timings (GdkFrameClock *clock,
                     guint64        serial)
 {
-  GdkFrameHistory *history = gdk_frame_clock_get_history (clock);
   gint64 start_frame, end_frame, i;
 
-  start_frame = gdk_frame_history_get_start (history);
-  end_frame = gdk_frame_history_get_frame_counter (history);
+  start_frame = gdk_frame_clock_get_start (clock);
+  end_frame = gdk_frame_clock_get_frame_counter (clock);
   for (i = end_frame; i >= start_frame; i--)
     {
-      GdkFrameTimings *timings = gdk_frame_history_get_timings (history, i);
+      GdkFrameTimings *timings = gdk_frame_clock_get_timings (clock, i);
 
       if (gdk_frame_timings_get_cookie (timings) == serial)
         return timings;
@@ -1167,8 +1167,7 @@ _gdk_wm_protocols_filter (GdkXEvent *xev,
               gdk_frame_timings_set_complete (timings, TRUE);
 #ifdef G_ENABLE_DEBUG
               if ((_gdk_debug_flags & GDK_DEBUG_FRAMES) != 0)
-                _gdk_frame_history_debug_print (gdk_frame_clock_get_history (clock),
-                                                timings);
+                _gdk_frame_clock_debug_print_timings (clock, timings);
 #endif /* G_ENABLE_DEBUG */
             }
         }
diff --git a/tests/animated-resizing.c b/tests/animated-resizing.c
index 9aaa366..96aa32a 100644
--- a/tests/animated-resizing.c
+++ b/tests/animated-resizing.c
@@ -148,7 +148,7 @@ print_variable (const char *description,
 }
 
 static void
-handle_frame_stats (GdkFrameHistory *frame_history)
+handle_frame_stats (GdkFrameClock *frame_clock)
 {
   static int num_stats = 0;
   static double last_print_time = 0;
@@ -192,11 +192,11 @@ handle_frame_stats (GdkFrameHistory *frame_history)
   frames_since_last_print++;
 
   for (frame_counter = last_handled_frame;
-       frame_counter < gdk_frame_history_get_frame_counter (frame_history);
+       frame_counter < gdk_frame_clock_get_frame_counter (frame_clock);
        frame_counter++)
     {
-      GdkFrameTimings *timings = gdk_frame_history_get_timings (frame_history, frame_counter);
-      GdkFrameTimings *previous_timings = gdk_frame_history_get_timings (frame_history, frame_counter - 1);
+      GdkFrameTimings *timings = gdk_frame_clock_get_timings (frame_clock, frame_counter);
+      GdkFrameTimings *previous_timings = gdk_frame_clock_get_timings (frame_clock, frame_counter - 1);
 
       if (!timings || gdk_frame_timings_get_complete (timings))
         last_handled_frame = frame_counter;
@@ -220,10 +220,7 @@ on_frame (double progress)
   int jitter;
 
   if (frame_clock)
-    {
-      GdkFrameHistory *history = gdk_frame_clock_get_history (frame_clock);
-      handle_frame_stats (history);
-    }
+    handle_frame_stats (clock);
 
   angle = 2 * M_PI * progress;
   jitter = WINDOW_SIZE_JITTER * sin(angle);
diff --git a/tests/video-timer.c b/tests/video-timer.c
index 32d8880..69ae562 100644
--- a/tests/video-timer.c
+++ b/tests/video-timer.c
@@ -221,9 +221,7 @@ on_window_draw (GtkWidget *widget,
       if (displayed_frame->frame_counter == 0)
         {
           GdkFrameClock *frame_clock = gtk_widget_get_frame_clock (window);
-          GdkFrameHistory *history = gdk_frame_clock_get_history (frame_clock);
-
-          displayed_frame->frame_counter = gdk_frame_history_get_frame_counter (history);
+          displayed_frame->frame_counter = gdk_frame_clock_get_frame_counter (clock);
         }
     }
 }
@@ -232,7 +230,6 @@ static void
 collect_old_frames (void)
 {
   GdkFrameClock *frame_clock = gtk_widget_get_frame_clock (window);
-  GdkFrameHistory *history = gdk_frame_clock_get_history (frame_clock);
   GList *l, *l_next;
 
   for (l = past_frames; l; l = l_next)
@@ -241,8 +238,8 @@ collect_old_frames (void)
       gboolean remove = FALSE;
       l_next = l->next;
 
-      GdkFrameTimings *timings = gdk_frame_history_get_timings (history,
-                                                                frame_data->frame_counter);
+      GdkFrameTimings *timings = gdk_frame_clock_get_timings (clock,
+                                                              frame_data->frame_counter);
       if (timings == NULL)
         {
           remove = TRUE;


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