wayland: Disable EGL swap interval
authorCarlos Garnacho <carlosg@gnome.org>
Thu, 22 Dec 2016 18:22:07 +0000 (19:22 +0100)
committerCarlos Garnacho <carlosg@gnome.org>
Mon, 9 Jan 2017 18:04:23 +0000 (19:04 +0100)
We have a frame clock that ensures rendering is done as per the
output vsync. There is no need to have Mesa do the same for us.

This, most notably, ensures Mesa doesn't schedule frame callbacks
that will be left unattended if the compositor stops throttling
frames for its surface, this is eg. the case if the toplevel is
moved to another workspace.

Also, given a SwapInterval!=0 will always bring these unexpected
side effects, check that it's possible to disable it, and spew
a debug message if that isn't the case.

https://bugzilla.gnome.org/show_bug.cgi?id=769835

gdk/wayland/gdkdisplay-wayland.h
gdk/wayland/gdkglcontext-wayland.c

index a68940f5b8d17dde128e44bb8bea9996adbfa1a6..a9fd4831a49c15e8577c191615044ef20aac6db4 100644 (file)
@@ -120,6 +120,7 @@ struct _GdkWaylandDisplay
   guint have_egl_buffer_age : 1;
   guint have_egl_swap_buffers_with_damage : 1;
   guint have_egl_surfaceless_context : 1;
+  EGLint egl_min_swap_interval;
 };
 
 struct _GdkWaylandDisplayClass
index 657368860f592373f78c9ff43de4795f8d0276ce..254900d1afa9350178c1a93d09a94dbae470b975 100644 (file)
@@ -369,6 +369,7 @@ gdk_wayland_display_init_gl (GdkDisplay *display)
 static gboolean
 find_eglconfig_for_window (GdkWindow  *window,
                            EGLConfig  *egl_config_out,
+                           EGLint     *min_swap_interval_out,
                            GError    **error)
 {
   GdkDisplay *display = gdk_window_get_display (window);
@@ -376,7 +377,7 @@ find_eglconfig_for_window (GdkWindow  *window,
   GdkVisual *visual = gdk_window_get_visual (window);
   EGLint attrs[MAX_EGL_ATTRS];
   EGLint count;
-  EGLConfig *configs;
+  EGLConfig *configs, chosen_config;
   gboolean use_rgba;
 
   int i = 0;
@@ -429,9 +430,20 @@ find_eglconfig_for_window (GdkWindow  *window,
     }
 
   /* Pick first valid configuration i guess? */
+  chosen_config = configs[0];
+
+  if (!eglGetConfigAttrib (display_wayland->egl_display, chosen_config,
+                           EGL_MIN_SWAP_INTERVAL, min_swap_interval_out))
+    {
+      g_set_error_literal (error, GDK_GL_ERROR,
+                           GDK_GL_ERROR_NOT_AVAILABLE,
+                           "Could not retrieve the minimum swap interval");
+      g_free (configs);
+      return FALSE;
+    }
 
   if (egl_config_out != NULL)
-    *egl_config_out = configs[0];
+    *egl_config_out = chosen_config;
 
   g_free (configs);
 
@@ -465,7 +477,9 @@ gdk_wayland_window_create_gl_context (GdkWindow     *window,
       return NULL;
     }
 
-  if (!find_eglconfig_for_window (window, &config, error))
+  if (!find_eglconfig_for_window (window, &config,
+                                  &display_wayland->egl_min_swap_interval,
+                                  error))
     return NULL;
 
   context = g_object_new (GDK_TYPE_WAYLAND_GL_CONTEXT,
@@ -543,5 +557,10 @@ gdk_wayland_display_make_gl_context_current (GdkDisplay   *display,
       return FALSE;
     }
 
+  if (display_wayland->egl_min_swap_interval == 0)
+    eglSwapInterval (display_wayland->egl_display, 0);
+  else
+    g_debug ("Can't disable GL swap interval");
+
   return TRUE;
 }