From c624230a8a125ae6a06e9139151b0d292aa87915 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Mon, 25 Jan 2016 18:48:49 +0000 Subject: [PATCH] gdk: Enable swap throttling on full screen windows Since commit 6183eb363282e5143bfd52aa36b5e6a318c4c992 we disabled swap throttling in favour of being driven by the GDK frame clock (and thus by the compositor). Compositors may decide to unredirect full screen windows to avoid the performance penalty of the additional copy, especially on X11, which means that a Clutter application marked as full screen is not going to be driven by the compositor, and it's not going to be throttled by the underlying GL machinery. This has a performance impact on constrained platforms. For this reason, we should re-enable swap throttling when the window is full screen. As the change was introduced especially because of Wayland, we should check that we're not running as clients under a Wayland compositor; if we do, we always keep swap throttling disabled, as the compositor will always manage our output, even when full screen. --- clutter/gdk/clutter-stage-gdk.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/clutter/gdk/clutter-stage-gdk.c b/clutter/gdk/clutter-stage-gdk.c index 10b555043..742de5867 100644 --- a/clutter/gdk/clutter-stage-gdk.c +++ b/clutter/gdk/clutter-stage-gdk.c @@ -485,7 +485,9 @@ clutter_stage_gdk_set_fullscreen (ClutterStageWindow *stage_window, gboolean is_fullscreen) { ClutterStageGdk *stage_gdk = CLUTTER_STAGE_GDK (stage_window); + ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_window); ClutterStage *stage = CLUTTER_STAGE_COGL (stage_window)->wrapper; + gboolean swap_throttle; if (stage == NULL || CLUTTER_ACTOR_IN_DESTRUCTION (stage)) return; @@ -499,6 +501,26 @@ clutter_stage_gdk_set_fullscreen (ClutterStageWindow *stage_window, gdk_window_fullscreen (stage_gdk->window); else gdk_window_unfullscreen (stage_gdk->window); + + /* Full-screen stages are usually unredirected to improve performance + * by avoiding a copy; when that happens, we need to turn back swap + * throttling because we won't be managed by the compositor any more, + */ + swap_throttle = is_fullscreen; + +#ifdef GDK_WINDOWING_WAYLAND + { + /* Except on Wayland, where there's a deadlock due to both Cogl + * and GDK attempting to consume the throttling event; see bug + * https://bugzilla.gnome.org/show_bug.cgi?id=754671#c1 + */ + GdkDisplay *display = clutter_gdk_get_default_display (); + if (GDK_IS_WAYLAND_DISPLAY (display)) + swap_throttle = FALSE; + } +#endif + + cogl_onscreen_set_swap_throttled (stage_cogl->onscreen, swap_throttle); } static void