[gtk+/gtk-3-22] wayland: Disable EGL swap interval



commit ab66c3d7bfaa316fc80a19e8aae32949b80068c1
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Dec 22 19:22:07 2016 +0100

    wayland: Disable EGL swap interval
    
    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   |    1 +
 gdk/wayland/gdkglcontext-wayland.c |   25 ++++++++++++++++++++++---
 2 files changed, 23 insertions(+), 3 deletions(-)
---
diff --git a/gdk/wayland/gdkdisplay-wayland.h b/gdk/wayland/gdkdisplay-wayland.h
index a68940f..a9fd483 100644
--- a/gdk/wayland/gdkdisplay-wayland.h
+++ b/gdk/wayland/gdkdisplay-wayland.h
@@ -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
diff --git a/gdk/wayland/gdkglcontext-wayland.c b/gdk/wayland/gdkglcontext-wayland.c
index 6573688..254900d 100644
--- a/gdk/wayland/gdkglcontext-wayland.c
+++ b/gdk/wayland/gdkglcontext-wayland.c
@@ -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;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]