frame-clock: New approach in smoothing frame clock

In commit c6901a8b, the frame clock reported time was changed from
simply reporting the time we ran the frame clock cycle to reporting a
smoothed value that increased by the frame interval each time it was
called.

However, this change caused some problems, such as:
 https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/1415
 https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/1416
 https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/1482

I think a lot of this is caused by the fact that we just overwrote the
old frame time with the smoothed, monotonous timestamp, breaking
some things that relied on knowing the actual time something happened.

This is a new approach to doing the smoothing that is more explicit.
The "frame_time" we store is the actual time we ran the update cycle,
and then we separately compute and store the derived smoothed time and
its period, allowing us to easily return a smoothed time at any time
by rounding the time difference to an integer number of frames.

The initial frame_time can be somewhat arbitrary, as it depends on the
first cycle which is not driven by the frame clock. But follow-up
cycles are typically tied to the the compositor sending the drawn
signal. It may happen that the initial frame is exactly in the middle
between two frames where jitter causes us to randomly round in
different directions when rounding to nearest frame. To fix this we
additionally do a quadratic convergence towards the "real" time,
during presentation driven clock cycles (i.e. when the frame times are
small).

(cherry picked from commit 9ef3e700400d5d4d4fcfeb37cfe757566658b456)
This commit is contained in:
Alexander Larsson
2020-05-18 15:48:03 +02:00
parent ac30f9b4cc
commit 687b49c18a
3 changed files with 110 additions and 47 deletions

View File

@ -505,11 +505,15 @@ _gdk_frame_clock_debug_print_timings (GdkFrameClock *clock,
GString *str;
gint64 previous_frame_time = 0;
gint64 previous_smoothed_frame_time = 0;
GdkFrameTimings *previous_timings = gdk_frame_clock_get_timings (clock,
timings->frame_counter - 1);
if (previous_timings != NULL)
previous_frame_time = previous_timings->frame_time;
{
previous_frame_time = previous_timings->frame_time;
previous_smoothed_frame_time = previous_timings->smoothed_frame_time;
}
str = g_string_new ("");
@ -518,6 +522,9 @@ _gdk_frame_clock_debug_print_timings (GdkFrameClock *clock,
{
g_string_append_printf (str, " interval=%-4.1f", (timings->frame_time - previous_frame_time) / 1000.);
g_string_append_printf (str, timings->slept_before ? " (sleep)" : " ");
g_string_append_printf (str, " smoothed=%4.1f / %-4.1f",
(timings->smoothed_frame_time - timings->frame_time) / 1000.,
(timings->smoothed_frame_time - previous_smoothed_frame_time) / 1000.);
}
if (timings->layout_start_time != 0)
g_string_append_printf (str, " layout_start=%-4.1f", (timings->layout_start_time - timings->frame_time) / 1000.);