Merge lp:~vanvugt/gtk/fix-1698270 into lp:~ubuntu-desktop/gtk/ubuntugtk3

Proposed by Daniel van Vugt on 2017-10-05
Status: Needs review
Proposed branch: lp:~vanvugt/gtk/fix-1698270
Merge into: lp:~ubuntu-desktop/gtk/ubuntugtk3
Diff against target: 112 lines (+92/-0)
3 files modified
debian/changelog (+8/-0)
debian/patches/Fix-irregular-gdk_frame_clock_get_frame_time-v3-ubuntu.patch (+83/-0)
debian/patches/series (+1/-0)
To merge this branch: bzr merge lp:~vanvugt/gtk/fix-1698270
Reviewer Review Type Date Requested Status
Ubuntu Sponsors Team 2017-10-05 Pending
Ubuntu Desktop 2017-10-05 Pending
Review via email: mp+331846@code.launchpad.net

Commit Message

Fix irregular gdk_frame_clock_get_frame_time

This fixes stuttering in animations that rely on the regularity of
gdk_frame_clock_get_frame_time. (LP: #1698270)

BEFORE

gdkgears: 58 FPS and visibly stuttering

gnome-maps on a 59.95Hz monitor:
"paint" gdk_frame_clock_get_frame_time +17278μs
"paint" gdk_frame_clock_get_frame_time +17426μs
"paint" gdk_frame_clock_get_frame_time +17600μs
^^^ misses about 5% of frames, or stutters 3 times per sec ^^^

AFTER

gdkgears: 60 FPS and smoother

gnome-maps on a 59.95Hz monitor:
"paint" gdk_frame_clock_get_frame_time +16680μs
"paint" gdk_frame_clock_get_frame_time +16680μs
"paint" gdk_frame_clock_get_frame_time +16680μs
^^^ misses no frames ^^^

To post a comment you must log in.
lp:~vanvugt/gtk/fix-1698270 updated on 2017-11-03
579. By Daniel van Vugt on 2017-11-03

Merge latest 'ubuntugtk3' and fix changelog conflict.

Unmerged revisions

579. By Daniel van Vugt on 2017-11-03

Merge latest 'ubuntugtk3' and fix changelog conflict.

578. By Daniel van Vugt on 2017-10-05

First import

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2017-10-30 01:18:35 +0000
3+++ debian/changelog 2017-11-03 07:47:22 +0000
4@@ -1,3 +1,11 @@
5+gtk+3.0 (3.22.25-0ubuntu2) UNRELEASED; urgency=medium
6+
7+ * Fix-irregular-gdk_frame_clock_get_frame_time-v3-ubuntu.patch:
8+ This fixes stuttering in animations that rely on the regularity of
9+ gdk_frame_clock_get_frame_time. (LP: #1698270)
10+
11+ -- Daniel van Vugt <daniel.van.vugt@canonical.com> Fri, 03 Nov 2017 15:41:31 +0800
12+
13 gtk+3.0 (3.22.25-0ubuntu1) bionic; urgency=medium
14
15 [ Simon McVittie ]
16
17=== added file 'debian/patches/Fix-irregular-gdk_frame_clock_get_frame_time-v3-ubuntu.patch'
18--- debian/patches/Fix-irregular-gdk_frame_clock_get_frame_time-v3-ubuntu.patch 1970-01-01 00:00:00 +0000
19+++ debian/patches/Fix-irregular-gdk_frame_clock_get_frame_time-v3-ubuntu.patch 2017-11-03 07:47:22 +0000
20@@ -0,0 +1,83 @@
21+Description: Fix irregular gdk_frame_clock_get_frame_time
22+ This fixes stuttering in animations that rely on the regularity of
23+ gdk_frame_clock_get_frame_time.
24+ .
25+ BEFORE
26+ gdkgears:
27+ 58 FPS and visibly stuttering
28+ gnome-maps on a 59.95Hz monitor:
29+ "paint" g_get_monotonic_time +17278μs, gdk_frame_clock_get_frame_time +17278μs
30+ "paint" g_get_monotonic_time +17449μs, gdk_frame_clock_get_frame_time +17426μs
31+ "paint" g_get_monotonic_time +17620μs, gdk_frame_clock_get_frame_time +17600μs
32+ .
33+ AFTER
34+ gdkgears:
35+ 60 FPS and smoother
36+ gnome-maps on a 59.95Hz monitor:
37+ "paint" g_get_monotonic_time +18228μs, gdk_frame_clock_get_frame_time +16680μs
38+ "paint" g_get_monotonic_time +15010μs, gdk_frame_clock_get_frame_time +16680μs
39+ "paint" g_get_monotonic_time +17134μs, gdk_frame_clock_get_frame_time +16680μs
40+Author: Daniel van Vugt <daniel.van.vugt@canonical.com>
41+Bug-Ubuntu: https://bugs.launchpad.net/bugs/1698270
42+Bug: https://bugzilla.gnome.org/show_bug.cgi?id=787665
43+Forwarded: yes
44+Last-Update: 2017-09-15
45+
46+---
47+ gdk/gdkframeclockidle.c | 31 ++++++++++++++++++++++++++++++-
48+ 1 file changed, 30 insertions(+), 1 deletion(-)
49+
50+diff --git a/gdk/gdkframeclockidle.c b/gdk/gdkframeclockidle.c
51+index 12897f4236..a0ca0ca1b9 100644
52+--- a/gdk/gdkframeclockidle.c
53++++ b/gdk/gdkframeclockidle.c
54+@@ -123,6 +123,7 @@ gdk_frame_clock_idle_init (GdkFrameClockIdle *frame_clock_idle)
55+ frame_clock_idle->priv = priv =
56+ gdk_frame_clock_idle_get_instance_private (frame_clock_idle);
57+
58++ priv->frame_time = g_get_monotonic_time (); /* more sane than zero */
59+ priv->freeze_count = 0;
60+ }
61+
62+@@ -350,9 +351,37 @@ gdk_frame_clock_paint_idle (void *data)
63+ case GDK_FRAME_CLOCK_PHASE_BEFORE_PAINT:
64+ if (priv->freeze_count == 0)
65+ {
66+- priv->frame_time = compute_frame_time (clock_idle);
67++ gint64 frame_interval = FRAME_INTERVAL;
68++ gint64 reset_frame_time;
69++ gint64 smoothest_frame_time;
70++ gint64 frame_time_error;
71++ GdkFrameTimings *prev_timings =
72++ gdk_frame_clock_get_current_timings (clock);
73++
74++ if (prev_timings && prev_timings->refresh_interval)
75++ frame_interval = prev_timings->refresh_interval;
76++
77++ /* We are likely not getting precisely even callbacks in real
78++ * time, particularly if the event loop is busy.
79++ * This is a documented limitation in the precision of
80++ * gdk_threads_add_timeout_full and g_timeout_add_full.
81++ *
82++ * In order to avoid this imprecision from compounding between
83++ * frames and affecting visual smoothness, we correct frame_time
84++ * to more precisely match the even refresh interval of the
85++ * physical display. This also means we proactively avoid (most)
86++ * missed frames before they occur.
87++ */
88++ smoothest_frame_time = priv->frame_time + frame_interval;
89++ reset_frame_time = compute_frame_time (clock_idle);
90++ frame_time_error = ABS (reset_frame_time - smoothest_frame_time);
91++ if (frame_time_error >= frame_interval)
92++ priv->frame_time = reset_frame_time;
93++ else
94++ priv->frame_time = smoothest_frame_time;
95+
96+ _gdk_frame_clock_begin_frame (clock);
97++ /* Note "current" is different now so timings != prev_timings */
98+ timings = gdk_frame_clock_get_current_timings (clock);
99+
100+ timings->frame_time = priv->frame_time;
101+--
102+2.14.1
103+
104
105=== modified file 'debian/patches/series'
106--- debian/patches/series 2017-10-29 19:46:19 +0000
107+++ debian/patches/series 2017-11-03 07:47:22 +0000
108@@ -25,3 +25,4 @@
109 unity-headerbar-maximized-mode.patch
110 gtksocket-unscale-before-sending-configurenotify.patch
111 no_content_hub.patch
112+Fix-irregular-gdk_frame_clock_get_frame_time-v3-ubuntu.patch

Subscribers

People subscribed via source and target branches