Merge ~vanvugt/ubuntu/+source/mutter:fix-lp1763892-cosmic into ~ubuntu-desktop/ubuntu/+source/mutter:ubuntu/cosmic

Proposed by Daniel van Vugt on 2019-02-25
Status: Merged
Merged at revision: f058b168a38ac3919528f7f5725c666ba708a424
Proposed branch: ~vanvugt/ubuntu/+source/mutter:fix-lp1763892-cosmic
Merge into: ~ubuntu-desktop/ubuntu/+source/mutter:ubuntu/cosmic
Diff against target: 700 lines (+423/-226)
6 files modified
debian/changelog (+9/-0)
debian/libmutter-3-0.symbols (+1/-0)
debian/patches/lp1763892-a-renderer-native-Add-hardware-presentation-timing.patch (+362/-0)
debian/patches/lp1763892-b-renderer-native-Advertise-_FEATURE_SWAP_THROTTLE.patch (+49/-0)
debian/patches/series (+2/-1)
dev/null (+0/-225)
Reviewer Review Type Date Requested Status
Iain Lane 2019-02-25 Approve on 2019-02-28
Ubuntu Server Dev import team 2019-02-25 Pending
Review via email: mp+363599@code.launchpad.net

This proposal supersedes a proposal from 2019-02-25.

Commit message

Remove 60 FPS limitation, thus supporting high frame rates

For Xorg the only fix required was to remove the spurious patch:

  clutter-Smooth-out-master-clock-to-smooth-visuals.patch

which had the effect of imposing a 60 FPS limitation. That patch
never landed upstream.

For Wayland you need both the above fix and the introduction of
hardware vsync support which was upstreamed in mutter 3.32 and is
backported to 3.30 in two commits/patches:

  lp1763892-a-renderer-native-Add-hardware-presentation-timing.patch
  lp1763892-b-renderer-native-Advertise-_FEATURE_SWAP_THROTTLE.patch

https://bugs.launchpad.net/bugs/1763892

To post a comment you must log in.
Iain Lane (laney) wrote :

Thanks. Some comments inline on the packaging. No objection on the content of the change as it's just cherry-picks.

It would be good to get 3.30.2-1~ubuntu18.10.3 released before uploading this.

review: Needs Fixing
Daniel van Vugt (vanvugt) wrote :

All done. (?)

Iain Lane (laney) wrote :

Thanks. It's in the queue now.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index 564d95f..c41e7b8 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,12 @@
6+mutter (3.30.2-1~ubuntu18.10.4) UNRELEASED; urgency=medium
7+
8+ * Add support for high frame rate displays (LP: #1763892):
9+ - Drop clutter-Smooth-out-master-clock-to-smooth-visuals.patch
10+ - Add lp1763892-a-renderer-native-Add-hardware-presentation-timing.patch
11+ - Add lp1763892-b-renderer-native-Advertise-_FEATURE_SWAP_THROTTLE.patch
12+
13+ -- Daniel van Vugt <daniel.van.vugt@canonical.com> Fri, 22 Feb 2019 17:42:49 +0800
14+
15 mutter (3.30.2-1~ubuntu18.10.3) cosmic; urgency=medium
16
17 * d/p/clutter-Avoid-rounding-compensation-when-invalidating-2D-.patch,
18diff --git a/debian/libmutter-3-0.symbols b/debian/libmutter-3-0.symbols
19index 81ebd76..3945a83 100644
20--- a/debian/libmutter-3-0.symbols
21+++ b/debian/libmutter-3-0.symbols
22@@ -699,6 +699,7 @@ libmutter-3.so.0 libmutter-3-0 #MINVER#
23 (arch=linux-any)meta_gpu_kms_can_have_outputs@Base 3.29.92
24 (arch=linux-any)meta_gpu_kms_flip_closure_container_free@Base 3.29.4
25 (arch=linux-any)meta_gpu_kms_flip_crtc@Base 3.28.2
26+ (arch=linux-any)meta_gpu_kms_get_current_time_ns@Base 3.30.2-1~ubuntu18.10.4
27 (arch=linux-any)meta_gpu_kms_get_fd@Base 3.28.2
28 (arch=linux-any)meta_gpu_kms_get_file_path@Base 3.28.2
29 (arch=linux-any)meta_gpu_kms_get_max_buffer_size@Base 3.28.2
30diff --git a/debian/patches/clutter-Smooth-out-master-clock-to-smooth-visuals.patch b/debian/patches/clutter-Smooth-out-master-clock-to-smooth-visuals.patch
31deleted file mode 100644
32index 2239837..0000000
33--- a/debian/patches/clutter-Smooth-out-master-clock-to-smooth-visuals.patch
34+++ /dev/null
35@@ -1,225 +0,0 @@
36-From: Daniel van Vugt <daniel.van.vugt@canonical.com>
37-Date: Fri, 16 Feb 2018 02:50:59 -0600
38-Subject: clutter: Smooth out master clock to smooth visuals
39-
40-Clutter's master clock was jittery because it included errors in cur_tick
41-such as dispatch delays due to other sources. Dispatch could also occur up
42-to 1ms early since GSource can only be timed to the millisecond. All of this
43-could impact the visual smoothness of animations as they are displayed on
44-the steady interval of the monitor, but spacially moving in less regular
45-steps derived from the dispatch times.
46-
47-The simple fix is to ignore any jitter in dispatch timing. Try a little
48-bit harder to use a precise interval that will better match the display
49-hardware, and smoother visuals will follow.
50-
51-Bug: https://gitlab.gnome.org/GNOME/mutter/issues/25
52-Forwarded: https://gitlab.gnome.org/GNOME/mutter/merge_requests/70
53----
54- clutter/clutter/clutter-master-clock-default.c | 134 +++++++++++++++++--------
55- 1 file changed, 93 insertions(+), 41 deletions(-)
56-
57-diff --git a/clutter/clutter/clutter-master-clock-default.c b/clutter/clutter/clutter-master-clock-default.c
58-index 7b2df0d..97b6d13 100644
59---- a/clutter/clutter/clutter-master-clock-default.c
60-+++ b/clutter/clutter/clutter-master-clock-default.c
61-@@ -69,8 +69,10 @@ struct _ClutterMasterClockDefault
62- /* the previous state of the clock, in usecs, used to compute the delta */
63- gint64 prev_tick;
64-
65-+ /* the ideal frame interval in usecs (inverse of your max refresh rate) */
66-+ gint64 frame_interval;
67-+
68- #ifdef CLUTTER_ENABLE_DEBUG
69-- gint64 frame_budget;
70- gint64 remaining_budget;
71- #endif
72-
73-@@ -264,6 +266,41 @@ master_clock_reschedule_stage_updates (ClutterMasterClockDefault *master_clock,
74- }
75- }
76-
77-+static gint64
78-+estimate_next_presentation_time (ClutterMasterClockDefault *master_clock)
79-+{
80-+ gint64 frame_phase, now, now_phase, undershoot;
81-+
82-+ /* In future if this was updated from the backend's (maximum) refresh rate
83-+ * then that would fix: https://bugzilla.gnome.org/show_bug.cgi?id=781296
84-+ */
85-+ master_clock->frame_interval = G_USEC_PER_SEC /
86-+ clutter_get_default_frame_rate ();
87-+
88-+ now = g_source_get_time (master_clock->source);
89-+ now_phase = now % master_clock->frame_interval;
90-+
91-+ /* To be precise we would like to use:
92-+ * frame_phase = a_recent_hardware_presentation_time % frame_interval;
93-+ * where hardware_presentation_time must be using the same clock as
94-+ * g_source_get_time. Unfortunately they're different clocks right now
95-+ * so we can't.
96-+ * Alternatively, we could replace g_source_get_time in future with the
97-+ * current time in the clutter/cogl presentation clock, but that function
98-+ * also doesn't exist yet.
99-+ * Until we can get either of those, zero is fine. It just means latency
100-+ * will be suboptimal by half a frame on average. We still get maximum
101-+ * smoothness this way...
102-+ */
103-+ frame_phase = 0;
104-+
105-+ undershoot = frame_phase - now_phase;
106-+ if (undershoot < 0)
107-+ undershoot += master_clock->frame_interval;
108-+
109-+ return now + undershoot;
110-+}
111-+
112- /*
113- * master_clock_next_frame_delay:
114- * @master_clock: a #ClutterMasterClock
115-@@ -276,7 +313,8 @@ master_clock_reschedule_stage_updates (ClutterMasterClockDefault *master_clock,
116- static gint
117- master_clock_next_frame_delay (ClutterMasterClockDefault *master_clock)
118- {
119-- gint64 now, next;
120-+ gint64 now, target_presentation_time, ideal_render_start; /* timestamps */
121-+ gint64 ideal_prerender_time, lateness; /* deltas */
122- gint swap_delay;
123-
124- if (!master_clock_is_running (master_clock))
125-@@ -307,46 +345,45 @@ master_clock_next_frame_delay (ClutterMasterClockDefault *master_clock)
126- return 0;
127- }
128-
129-- if (master_clock->prev_tick == 0)
130-- {
131-- /* If we weren't previously running, then draw the next frame
132-- * immediately
133-- */
134-- CLUTTER_NOTE (SCHEDULER, "draw the first frame immediately");
135-- return 0;
136-- }
137--
138-- /* Otherwise, wait at least 1/frame_rate seconds since we last
139-- * started a frame
140-- */
141- now = g_source_get_time (master_clock->source);
142-
143-- next = master_clock->prev_tick;
144--
145-- /* If time has gone backwards then there's no way of knowing how
146-- long we should wait so let's just dispatch immediately */
147-- if (now <= next)
148-+ /* As first preference, try to carry on smoothly from the previous frame,
149-+ * even if that means we start rendering frame 2 before frame 1 has been
150-+ * presented. This is why we ignore estimate_next_presentation_time here...
151-+ */
152-+ target_presentation_time = master_clock->prev_tick +
153-+ master_clock->frame_interval;
154-+ ideal_prerender_time = master_clock->frame_interval;
155-+ ideal_render_start = target_presentation_time - ideal_prerender_time;
156-+ lateness = now - ideal_render_start;
157-+
158-+ /* If we just woke from idle then try to improve the smoothness of the first
159-+ * two frames some more. Otherwise the first frame would appear too old
160-+ * relative to the second frame.
161-+ */
162-+ if (lateness >= master_clock->frame_interval)
163- {
164-- CLUTTER_NOTE (SCHEDULER, "Time has gone backwards");
165--
166-- return 0;
167-+ target_presentation_time = estimate_next_presentation_time (master_clock);
168-+ ideal_render_start = target_presentation_time - ideal_prerender_time;
169-+ lateness = now - ideal_render_start;
170- }
171-
172-- next += (1000000L / clutter_get_default_frame_rate ());
173--
174-- if (next <= now)
175-+ if (lateness > 0)
176- {
177-- CLUTTER_NOTE (SCHEDULER, "Less than %lu microsecs",
178-- 1000000L / (gulong) clutter_get_default_frame_rate ());
179--
180-+ CLUTTER_NOTE (SCHEDULER, "No wait required. We're already late.");
181- return 0;
182- }
183- else
184- {
185-- CLUTTER_NOTE (SCHEDULER, "Waiting %" G_GINT64_FORMAT " msecs",
186-- (next - now) / 1000);
187--
188-- return (next - now) / 1000;
189-+ /* We +1 here to avoid premature dispatches that would otherwise occur
190-+ * repeatedly during the 1ms before 'ideal_render_start'. We don't care
191-+ * if this makes the final dispatch 1ms late because the smoothing
192-+ * algorithm corrects that, and it's much better than attempting to
193-+ * render more frames than the hardware can physically display...
194-+ */
195-+ gint millisec_delay = -lateness / 1000 + 1;
196-+ CLUTTER_NOTE (SCHEDULER, "Waiting %dms", millisec_delay);
197-+ return millisec_delay;
198- }
199- }
200-
201-@@ -532,16 +569,34 @@ clutter_clock_dispatch (GSource *source,
202- ClutterMasterClockDefault *master_clock = clock_source->master_clock;
203- gboolean stages_updated = FALSE;
204- GSList *stages;
205--
206-- CLUTTER_NOTE (SCHEDULER, "Master clock [tick]");
207-+ gint64 smooth_tick;
208-
209- _clutter_threads_acquire_lock ();
210-
211- /* Get the time to use for this frame */
212-- master_clock->cur_tick = g_source_get_time (source);
213-+ smooth_tick = estimate_next_presentation_time (master_clock);
214-+ if (smooth_tick <= master_clock->prev_tick)
215-+ {
216-+ /* Ordinarily this will never happen. But after we fix bug 781296, it
217-+ * could happen in the rare case when the ideal frame_interval changes,
218-+ * such as video mode switching or hotplugging monitors. As such it is
219-+ * not considered a bug (unless it's happening without mode switching
220-+ * or hotplugging).
221-+ */
222-+ CLUTTER_NOTE (SCHEDULER, "Master clock [tick] was premature (skipped)");
223-+ _clutter_threads_release_lock ();
224-+ return G_SOURCE_CONTINUE;
225-+ }
226-+
227-+ master_clock->cur_tick = smooth_tick;
228-+ if (master_clock->prev_tick)
229-+ CLUTTER_NOTE (SCHEDULER, "Master clock [tick] %+ldus",
230-+ (long) (master_clock->cur_tick - master_clock->prev_tick));
231-+ else
232-+ CLUTTER_NOTE (SCHEDULER, "Master clock [tick] startup");
233-
234- #ifdef CLUTTER_ENABLE_DEBUG
235-- master_clock->remaining_budget = master_clock->frame_budget;
236-+ master_clock->remaining_budget = master_clock->frame_interval;
237- #endif
238-
239- /* We need to protect ourselves against stages being destroyed during
240-@@ -580,7 +635,7 @@ clutter_clock_dispatch (GSource *source,
241-
242- _clutter_threads_release_lock ();
243-
244-- return TRUE;
245-+ return G_SOURCE_CONTINUE;
246- }
247-
248- static void
249-@@ -612,10 +667,7 @@ clutter_master_clock_default_init (ClutterMasterClockDefault *self)
250- self->idle = FALSE;
251- self->ensure_next_iteration = FALSE;
252- self->paused = FALSE;
253--
254--#ifdef CLUTTER_ENABLE_DEBUG
255-- self->frame_budget = G_USEC_PER_SEC / 60;
256--#endif
257-+ self->frame_interval = G_USEC_PER_SEC / 60; /* Will be refined at runtime */
258-
259- g_source_set_priority (source, CLUTTER_PRIORITY_REDRAW);
260- g_source_set_can_recurse (source, FALSE);
261diff --git a/debian/patches/lp1763892-a-renderer-native-Add-hardware-presentation-timing.patch b/debian/patches/lp1763892-a-renderer-native-Add-hardware-presentation-timing.patch
262new file mode 100644
263index 0000000..34edc61
264--- /dev/null
265+++ b/debian/patches/lp1763892-a-renderer-native-Add-hardware-presentation-timing.patch
266@@ -0,0 +1,362 @@
267+Description: renderer-native: Add hardware presentation timing
268+ Add support for getting hardware presentation times from KMS (Wayland
269+ sessions). Also implement cogl_get_clock_time which is required to compare
270+ and judge the age of presentation timestamps.
271+ .
272+ For single monitor systems this is straightforward. For multi-monitor
273+ systems though we have to choose a display to sync to. The compositor
274+ already partially solves this for us in the case of only one display
275+ updating because it will only use the subset of monitors that are
276+ changing. In the case of multiple monitors consuming the same frame
277+ concurrently however, we choose the fastest one (in use at the time).
278+ .
279+ Patch 1 of 2.
280+Author: Daniel van Vugt <daniel.van.vugt@canonical.com>
281+Origin: https://gitlab.gnome.org/GNOME/mutter/merge_requests/171 via backport https://gitlab.gnome.org/GNOME/mutter/merge_requests/318
282+Bug: https://bugzilla.gnome.org/show_bug.cgi?id=781296
283+Bug-Ubuntu: https://bugs.launchpad.net/bugs/1763892
284+Forwarded: yes
285+Last-Update: 2019-02-27
286+
287+diff --git a/src/Makefile.am b/src/Makefile.am
288+index 811e2b86b..56d539836 100644
289+--- a/src/Makefile.am
290++++ b/src/Makefile.am
291+@@ -51,6 +51,8 @@ mutter_built_sources = \
292+ $(dbus_login1_built_sources) \
293+ meta/meta-enum-types.h \
294+ meta-enum-types.c \
295++ meta-marshal.c \
296++ meta-marshal.h \
297+ $(NULL)
298+
299+ if HAVE_REMOTE_DESKTOP
300+@@ -677,6 +679,7 @@ EXTRA_DIST += \
301+ libmutter.pc.in \
302+ meta-enum-types.h.in \
303+ meta-enum-types.c.in \
304++ meta-marshal.list \
305+ org.freedesktop.login1.xml \
306+ org.gnome.Mutter.DisplayConfig.xml \
307+ org.gnome.Mutter.IdleMonitor.xml \
308+@@ -690,7 +693,10 @@ BUILT_SOURCES = \
309+ $(libmutterinclude_built_headers)
310+
311+ MUTTER_STAMP_FILES = stamp-meta-enum-types.h
312+-CLEANFILES += $(MUTTER_STAMP_FILES)
313++CLEANFILES += \
314++ $(MUTTER_STAMP_FILES) \
315++ meta-marshal.c \
316++ meta-marshal.h
317+
318+ meta/meta-enum-types.h: stamp-meta-enum-types.h Makefile
319+ @true
320+@@ -786,3 +792,20 @@ endef
321+ $(AM_V_GEN)$(WAYLAND_SCANNER) server-header $< $@
322+ %-server-protocol.h : $(WAYLAND_EGLSTREAM_DATADIR)/%.xml
323+ $(AM_V_GEN)$(WAYLAND_SCANNER) server-header $< $@
324++
325++meta_marshal_opts = --prefix=meta_marshal --internal
326++
327++meta-marshal.h: meta-marshal.list
328++ $(AM_V_GEN)$(GLIB_GENMARSHAL) \
329++ --header \
330++ $(meta_marshal_opts) \
331++ --output=$@ \
332++ $<
333++
334++meta-marshal.c: meta-marshal.list meta-marshal.h
335++ $(AM_V_GEN)$(GLIB_GENMARSHAL) \
336++ --include-header=meta-marshal.h \
337++ $(meta_marshal_opts) \
338++ --body \
339++ --output=$@ \
340++ $<
341+diff --git a/src/backends/native/meta-gpu-kms.c b/src/backends/native/meta-gpu-kms.c
342+index c3c5d0d68..26c759031 100644
343+--- a/src/backends/native/meta-gpu-kms.c
344++++ b/src/backends/native/meta-gpu-kms.c
345+@@ -27,6 +27,7 @@
346+ #include <errno.h>
347+ #include <poll.h>
348+ #include <string.h>
349++#include <time.h>
350+ #include <xf86drm.h>
351+ #include <xf86drmMode.h>
352+
353+@@ -51,6 +52,7 @@ typedef struct _MetaGpuKmsFlipClosureContainer
354+ {
355+ GClosure *flip_closure;
356+ MetaGpuKms *gpu_kms;
357++ MetaCrtc *crtc;
358+ } MetaGpuKmsFlipClosureContainer;
359+
360+ struct _MetaGpuKms
361+@@ -61,6 +63,8 @@ struct _MetaGpuKms
362+ char *file_path;
363+ GSource *source;
364+
365++ clockid_t clock_id;
366++
367+ drmModeConnector **connectors;
368+ unsigned int n_connectors;
369+
370+@@ -165,18 +169,26 @@ meta_gpu_kms_apply_crtc_mode (MetaGpuKms *gpu_kms,
371+
372+ static void
373+ invoke_flip_closure (GClosure *flip_closure,
374+- MetaGpuKms *gpu_kms)
375++ MetaGpuKms *gpu_kms,
376++ MetaCrtc *crtc,
377++ int64_t page_flip_time_ns)
378+ {
379+ GValue params[] = {
380+ G_VALUE_INIT,
381+- G_VALUE_INIT
382++ G_VALUE_INIT,
383++ G_VALUE_INIT,
384++ G_VALUE_INIT,
385+ };
386+
387+ g_value_init (&params[0], G_TYPE_POINTER);
388+ g_value_set_pointer (&params[0], flip_closure);
389+ g_value_init (&params[1], G_TYPE_OBJECT);
390+ g_value_set_object (&params[1], gpu_kms);
391+- g_closure_invoke (flip_closure, NULL, 2, params, NULL);
392++ g_value_init (&params[2], G_TYPE_OBJECT);
393++ g_value_set_object (&params[2], crtc);
394++ g_value_init (&params[3], G_TYPE_INT64);
395++ g_value_set_int64 (&params[3], page_flip_time_ns);
396++ g_closure_invoke (flip_closure, NULL, 4, params, NULL);
397+ g_closure_unref (flip_closure);
398+ }
399+
400+@@ -216,6 +228,7 @@ meta_gpu_kms_is_crtc_active (MetaGpuKms *gpu_kms,
401+
402+ MetaGpuKmsFlipClosureContainer *
403+ meta_gpu_kms_wrap_flip_closure (MetaGpuKms *gpu_kms,
404++ MetaCrtc *crtc,
405+ GClosure *flip_closure)
406+ {
407+ MetaGpuKmsFlipClosureContainer *closure_container;
408+@@ -223,7 +236,8 @@ meta_gpu_kms_wrap_flip_closure (MetaGpuKms *gpu_kms,
409+ closure_container = g_new0 (MetaGpuKmsFlipClosureContainer, 1);
410+ *closure_container = (MetaGpuKmsFlipClosureContainer) {
411+ .flip_closure = flip_closure,
412+- .gpu_kms = gpu_kms
413++ .gpu_kms = gpu_kms,
414++ .crtc = crtc
415+ };
416+
417+ return closure_container;
418+@@ -263,6 +277,7 @@ meta_gpu_kms_flip_crtc (MetaGpuKms *gpu_kms,
419+ int kms_fd = meta_gpu_kms_get_fd (gpu_kms);
420+
421+ closure_container = meta_gpu_kms_wrap_flip_closure (gpu_kms,
422++ crtc,
423+ flip_closure);
424+
425+ ret = drmModePageFlip (kms_fd,
426+@@ -296,6 +311,23 @@ meta_gpu_kms_flip_crtc (MetaGpuKms *gpu_kms,
427+ return TRUE;
428+ }
429+
430++static int64_t
431++timespec_to_nanoseconds (const struct timespec *ts)
432++{
433++ const int64_t one_billion = 1000000000;
434++
435++ return ((int64_t) ts->tv_sec) * one_billion + ts->tv_nsec;
436++}
437++
438++static int64_t
439++timeval_to_nanoseconds (const struct timeval *tv)
440++{
441++ int64_t usec = ((int64_t) tv->tv_sec) * G_USEC_PER_SEC + tv->tv_usec;
442++ int64_t nsec = usec * 1000;
443++
444++ return nsec;
445++}
446++
447+ static void
448+ page_flip_handler (int fd,
449+ unsigned int frame,
450+@@ -306,8 +338,12 @@ page_flip_handler (int fd,
451+ MetaGpuKmsFlipClosureContainer *closure_container = user_data;
452+ GClosure *flip_closure = closure_container->flip_closure;
453+ MetaGpuKms *gpu_kms = closure_container->gpu_kms;
454++ struct timeval page_flip_time = {sec, usec};
455+
456+- invoke_flip_closure (flip_closure, gpu_kms);
457++ invoke_flip_closure (flip_closure,
458++ gpu_kms,
459++ closure_container->crtc,
460++ timeval_to_nanoseconds (&page_flip_time));
461+ meta_gpu_kms_flip_closure_container_free (closure_container);
462+ }
463+
464+@@ -380,6 +416,17 @@ meta_gpu_kms_get_file_path (MetaGpuKms *gpu_kms)
465+ return gpu_kms->file_path;
466+ }
467+
468++int64_t
469++meta_gpu_kms_get_current_time_ns (MetaGpuKms *gpu_kms)
470++{
471++ struct timespec ts;
472++
473++ if (clock_gettime (gpu_kms->clock_id, &ts))
474++ return 0;
475++
476++ return timespec_to_nanoseconds (&ts);
477++}
478++
479+ void
480+ meta_gpu_kms_set_power_save_mode (MetaGpuKms *gpu_kms,
481+ uint64_t state)
482+@@ -679,6 +726,17 @@ init_crtcs (MetaGpuKms *gpu_kms,
483+ meta_gpu_take_crtcs (gpu, crtcs);
484+ }
485+
486++static void
487++init_frame_clock (MetaGpuKms *gpu_kms)
488++{
489++ uint64_t uses_monotonic;
490++
491++ if (drmGetCap (gpu_kms->fd, DRM_CAP_TIMESTAMP_MONOTONIC, &uses_monotonic) != 0)
492++ uses_monotonic = 0;
493++
494++ gpu_kms->clock_id = uses_monotonic ? CLOCK_MONOTONIC : CLOCK_REALTIME;
495++}
496++
497+ static void
498+ init_outputs (MetaGpuKms *gpu_kms,
499+ MetaKmsResources *resources)
500+@@ -806,6 +864,7 @@ meta_gpu_kms_read_current (MetaGpu *gpu,
501+ init_modes (gpu_kms, resources.resources);
502+ init_crtcs (gpu_kms, &resources);
503+ init_outputs (gpu_kms, &resources);
504++ init_frame_clock (gpu_kms);
505+
506+ meta_kms_resources_release (&resources);
507+
508+diff --git a/src/backends/native/meta-gpu-kms.h b/src/backends/native/meta-gpu-kms.h
509+index 5f77f191a..3e3f45c7e 100644
510+--- a/src/backends/native/meta-gpu-kms.h
511++++ b/src/backends/native/meta-gpu-kms.h
512+@@ -73,6 +73,8 @@ int meta_gpu_kms_get_fd (MetaGpuKms *gpu_kms);
513+
514+ const char * meta_gpu_kms_get_file_path (MetaGpuKms *gpu_kms);
515+
516++int64_t meta_gpu_kms_get_current_time_ns (MetaGpuKms *gpu_kms);
517++
518+ void meta_gpu_kms_get_max_buffer_size (MetaGpuKms *gpu_kms,
519+ int *max_width,
520+ int *max_height);
521+@@ -89,6 +91,7 @@ gboolean meta_drm_mode_equal (const drmModeModeInfo *one,
522+ float meta_calculate_drm_mode_refresh_rate (const drmModeModeInfo *mode);
523+
524+ MetaGpuKmsFlipClosureContainer * meta_gpu_kms_wrap_flip_closure (MetaGpuKms *gpu_kms,
525++ MetaCrtc *crtc,
526+ GClosure *flip_closure);
527+
528+ void meta_gpu_kms_flip_closure_container_free (MetaGpuKmsFlipClosureContainer *closure_container);
529+diff --git a/src/backends/native/meta-renderer-native.c b/src/backends/native/meta-renderer-native.c
530+index f58e6b3e0..b192c3641 100644
531+--- a/src/backends/native/meta-renderer-native.c
532++++ b/src/backends/native/meta-renderer-native.c
533+@@ -62,6 +62,7 @@
534+ #include "backends/native/meta-monitor-manager-kms.h"
535+ #include "backends/native/meta-renderer-native.h"
536+ #include "backends/native/meta-renderer-native-gles3.h"
537++#include "meta-marshal.h"
538+ #include "cogl/cogl.h"
539+ #include "core/boxes-private.h"
540+
541+@@ -1159,6 +1160,8 @@ meta_onscreen_native_swap_drm_fb (CoglOnscreen *onscreen)
542+ static void
543+ on_crtc_flipped (GClosure *closure,
544+ MetaGpuKms *gpu_kms,
545++ MetaCrtc *crtc,
546++ int64_t page_flip_time_ns,
547+ MetaRendererView *view)
548+ {
549+ ClutterStageView *stage_view = CLUTTER_STAGE_VIEW (view);
550+@@ -1169,6 +1172,24 @@ on_crtc_flipped (GClosure *closure,
551+ MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
552+ MetaRendererNative *renderer_native = onscreen_native->renderer_native;
553+ MetaGpuKms *render_gpu = onscreen_native->render_gpu;
554++ CoglFrameInfo *frame_info;
555++ float refresh_rate;
556++
557++ frame_info = g_queue_peek_tail (&onscreen->pending_frame_infos);
558++ refresh_rate = crtc && crtc->current_mode ?
559++ crtc->current_mode->refresh_rate :
560++ 0.0f;
561++
562++ /* Only keep the frame info for the fastest CRTC in use, which may not be
563++ * the first one to complete a flip. By only telling the compositor about the
564++ * fastest monitor(s) we direct it to produce new frames fast enough to
565++ * satisfy all monitors.
566++ */
567++ if (refresh_rate >= frame_info->refresh_rate)
568++ {
569++ frame_info->presentation_time = page_flip_time_ns;
570++ frame_info->refresh_rate = refresh_rate;
571++ }
572+
573+ if (gpu_kms != render_gpu)
574+ {
575+@@ -1299,7 +1320,9 @@ flip_egl_stream (MetaOnscreenNative *onscreen_native,
576+ return FALSE;
577+
578+ closure_container =
579+- meta_gpu_kms_wrap_flip_closure (onscreen_native->render_gpu, flip_closure);
580++ meta_gpu_kms_wrap_flip_closure (onscreen_native->render_gpu,
581++ NULL,
582++ flip_closure);
583+
584+ acquire_attribs = (EGLAttrib[]) {
585+ EGL_DRM_FLIP_EVENT_DATA_NV,
586+@@ -1542,7 +1565,7 @@ meta_onscreen_native_flip_crtcs (CoglOnscreen *onscreen)
587+ flip_closure = g_cclosure_new (G_CALLBACK (on_crtc_flipped),
588+ g_object_ref (view),
589+ (GClosureNotify) flip_closure_destroyed);
590+- g_closure_set_marshal (flip_closure, g_cclosure_marshal_VOID__OBJECT);
591++ g_closure_set_marshal (flip_closure, meta_marshal_VOID__OBJECT_OBJECT_INT64);
592+
593+ /* Either flip the CRTC's of the monitor info, if we are drawing just part
594+ * of the stage, or all of the CRTC's if we are drawing the whole stage.
595+@@ -2687,6 +2710,15 @@ meta_renderer_native_create_offscreen (MetaRendererNative *renderer,
596+ return fb;
597+ }
598+
599++static int64_t
600++meta_renderer_native_get_clock_time (CoglContext *context)
601++{
602++ CoglRenderer *cogl_renderer = cogl_context_get_renderer (context);
603++ MetaGpuKms *gpu_kms = cogl_renderer->custom_winsys_user_data;
604++
605++ return meta_gpu_kms_get_current_time_ns (gpu_kms);
606++}
607++
608+ static const CoglWinsysVtable *
609+ get_native_cogl_winsys_vtable (CoglRenderer *cogl_renderer)
610+ {
611+@@ -2715,6 +2747,8 @@ get_native_cogl_winsys_vtable (CoglRenderer *cogl_renderer)
612+ vtable.onscreen_swap_buffers_with_damage =
613+ meta_onscreen_native_swap_buffers_with_damage;
614+
615++ vtable.context_get_clock_time = meta_renderer_native_get_clock_time;
616++
617+ vtable_inited = TRUE;
618+ }
619+
620+diff --git a/src/meta-marshal.list b/src/meta-marshal.list
621+new file mode 100644
622+index 000000000..c1f4781d2
623+--- /dev/null
624++++ b/src/meta-marshal.list
625+@@ -0,0 +1 @@
626++VOID:OBJECT,OBJECT,INT64
627+--
628+2.18.1
629diff --git a/debian/patches/lp1763892-b-renderer-native-Advertise-_FEATURE_SWAP_THROTTLE.patch b/debian/patches/lp1763892-b-renderer-native-Advertise-_FEATURE_SWAP_THROTTLE.patch
630new file mode 100644
631index 0000000..7238824
632--- /dev/null
633+++ b/debian/patches/lp1763892-b-renderer-native-Advertise-_FEATURE_SWAP_THROTTLE.patch
634@@ -0,0 +1,49 @@
635+Description: renderer-native: Advertise _FEATURE_SWAP_THROTTLE
636+ Because it is implemented and always on. By advertising this fact
637+ the master clock is able to sync to the native refresh rate instead
638+ of always using the fallback of 60.00Hz.
639+ .
640+ Patch 2 of 2.
641+Author: Daniel van Vugt <daniel.van.vugt@canonical.com>
642+Origin: https://gitlab.gnome.org/GNOME/mutter/merge_requests/171 via backport https://gitlab.gnome.org/GNOME/mutter/merge_requests/318
643+Bug: https://bugzilla.gnome.org/show_bug.cgi?id=781296
644+Bug-Ubuntu: https://bugs.launchpad.net/bugs/1763892
645+Forwarded: yes
646+Last-Update: 2019-02-27
647+
648+diff --git a/src/backends/native/meta-renderer-native.c b/src/backends/native/meta-renderer-native.c
649+index b192c3641..929e9ca90 100644
650+--- a/src/backends/native/meta-renderer-native.c
651++++ b/src/backends/native/meta-renderer-native.c
652+@@ -2005,6 +2005,13 @@ meta_renderer_native_init_egl_context (CoglContext *cogl_context,
653+ COGL_WINSYS_FEATURE_MULTIPLE_ONSCREEN,
654+ TRUE);
655+
656++ /* COGL_WINSYS_FEATURE_SWAP_THROTTLE is always true for this renderer
657++ * because we have the call to wait_for_pending_flips on every frame.
658++ */
659++ COGL_FLAGS_SET (cogl_context->winsys_features,
660++ COGL_WINSYS_FEATURE_SWAP_THROTTLE,
661++ TRUE);
662++
663+ #ifdef HAVE_EGL_DEVICE
664+ if (renderer_gpu_data->mode == META_RENDERER_NATIVE_MODE_EGL_DEVICE)
665+ COGL_FLAGS_SET (cogl_context->features,
666+@@ -2639,8 +2646,12 @@ meta_renderer_native_create_onscreen (MetaRendererNative *renderer_native,
667+ }
668+
669+ onscreen = cogl_onscreen_new (context, width, height);
670+- cogl_onscreen_set_swap_throttled (onscreen,
671+- _clutter_get_sync_to_vblank ());
672++
673++ /* We have wait_for_pending_flips hardcoded, so throttling always. */
674++ cogl_onscreen_set_swap_throttled (onscreen, TRUE);
675++ if (!_clutter_get_sync_to_vblank ())
676++ g_warning ("Request to disable sync-to-vblank is being ignored. "
677++ "MetaRendererNative does not support disabling it.");
678+
679+ if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (onscreen), error))
680+ {
681+--
682+2.18.1
683+
684diff --git a/debian/patches/series b/debian/patches/series
685index 0f14e78..956b657 100644
686--- a/debian/patches/series
687+++ b/debian/patches/series
688@@ -1,10 +1,11 @@
689 theme-use-gtk_render_icon_suface-to-paint-button-icon.patch
690 theme-load-icons-as-Gtk-does-with-fallback-and-RTL-suppor.patch
691-clutter-Smooth-out-master-clock-to-smooth-visuals.patch
692 bgo768531_workaround-startup-notifications.patch
693 clutter-Avoid-rounding-compensation-when-invalidating-2D-.patch
694 clutter-Fix-offscreen-effect-painting-of-clones.patch
695 cogl-auto-texture-Avoid-a-double-free-crash.patch
696 clutter-offscreen-effect-Disable-if-no-texture.patch
697+lp1763892-a-renderer-native-Add-hardware-presentation-timing.patch
698+lp1763892-b-renderer-native-Advertise-_FEATURE_SWAP_THROTTLE.patch
699 debian/synaptics-support.patch
700 debian/skip-texture-test.patch

Subscribers

People subscribed via source and target branches