summaryrefslogtreecommitdiff
path: root/gdk/gdkframeclock.c
diff options
context:
space:
mode:
authorOwen W. Taylor <otaylor@fishsoup.net>2012-11-15 14:11:41 -0500
committerOwen W. Taylor <otaylor@fishsoup.net>2013-02-14 17:19:51 -0500
commitfb44ea8a85db3e41f10304f559772f2c10d28c29 (patch)
treee05881074a4aa92e186fe25ffa756fb5d16391b4 /gdk/gdkframeclock.c
parent8855bf052d8bbbd8fdfce1cd5f4a3540661a9c8e (diff)
downloadgtk+-fb44ea8a85db3e41f10304f559772f2c10d28c29.tar.gz
Add gdk_frame_timings_get_predicted_presentation_time()
For an operation like synchronizing audio to video playback, we need to be able to predict the time that a frame will be presented. The details of this depend on the windowing system, so make the backend predict a presentation time for ::begin-frame and set it on the GdkFrameTimings. The timing algorithm of GdkFrameClockIdle is adjusted to give predictable presentation times for frames that are not throttled by the windowing system. Helper functions: gdk_frame_clock_get_current_frame_timings() gdk_frame_clock_get_refresh_info() are added for operations that would otherwise be needed multiple times in different locations. https://bugzilla.gnome.org/show_bug.cgi?id=685460
Diffstat (limited to 'gdk/gdkframeclock.c')
-rw-r--r--gdk/gdkframeclock.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/gdk/gdkframeclock.c b/gdk/gdkframeclock.c
index ecb84bd8aa..fd41d94533 100644
--- a/gdk/gdkframeclock.c
+++ b/gdk/gdkframeclock.c
@@ -378,3 +378,76 @@ gdk_frame_clock_frame_requested (GdkFrameClock *clock)
g_signal_emit (G_OBJECT (clock),
signals[FRAME_REQUESTED], 0);
}
+
+GdkFrameTimings *
+gdk_frame_clock_get_current_frame_timings (GdkFrameClock *clock)
+{
+ GdkFrameHistory *history;
+ gint64 frame_counter;
+
+ 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);
+}
+
+
+#define DEFAULT_REFRESH_INTERVAL 16667 /* 16.7ms (1/60th second) */
+#define MAX_HISTORY_AGE 150000 /* 150ms */
+
+void
+gdk_frame_clock_get_refresh_info (GdkFrameClock *clock,
+ gint64 base_time,
+ 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);
+
+ if (presentation_time_return)
+ *presentation_time_return = 0;
+ if (refresh_interval_return)
+ *refresh_interval_return = DEFAULT_REFRESH_INTERVAL;
+
+ while (TRUE)
+ {
+ GdkFrameTimings *timings = gdk_frame_history_get_timings (history, frame_counter);
+ gint64 presentation_time;
+ gint64 refresh_interval;
+
+ if (timings == NULL)
+ return;
+
+ refresh_interval = gdk_frame_timings_get_refresh_interval (timings);
+ presentation_time = gdk_frame_timings_get_presentation_time (timings);
+
+ if (presentation_time != 0)
+ {
+ if (presentation_time > base_time - MAX_HISTORY_AGE &&
+ presentation_time_return)
+ {
+ if (refresh_interval == 0)
+ refresh_interval = DEFAULT_REFRESH_INTERVAL;
+
+ if (refresh_interval_return)
+ *refresh_interval_return = refresh_interval;
+
+ while (presentation_time < base_time)
+ presentation_time += refresh_interval;
+
+ if (presentation_time_return)
+ *presentation_time_return = presentation_time;
+ }
+
+ return;
+ }
+
+ frame_counter--;
+ }
+}