diff --git a/gdk/gdk.c b/gdk/gdk.c index b3a569d34d..c6b5b7b8ce 100644 --- a/gdk/gdk.c +++ b/gdk/gdk.c @@ -127,6 +127,7 @@ static const GdkDebugKey gdk_debug_keys[] = { { "gl-legacy", GDK_DEBUG_GL_LEGACY, "Use a legacy OpenGL context" }, { "gl-gles", GDK_DEBUG_GL_GLES, "Use a GLES OpenGL context" }, { "gl-debug", GDK_DEBUG_GL_DEBUG, "Insert debugging information in OpenGL" }, + { "gl-egl", GDK_DEBUG_GL_EGL, "Use EGL on X11" }, { "gl-glx", GDK_DEBUG_GL_GLX, "Use GLX on X11" }, { "vulkan-disable", GDK_DEBUG_VULKAN_DISABLE, "Disable Vulkan support" }, { "vulkan-validate", GDK_DEBUG_VULKAN_VALIDATE, "Load the Vulkan validation layer" }, diff --git a/gdk/gdkdebug.h b/gdk/gdkdebug.h index e03b904ce4..111cc2f28a 100644 --- a/gdk/gdkdebug.h +++ b/gdk/gdkdebug.h @@ -41,10 +41,11 @@ typedef enum { GDK_DEBUG_GL_LEGACY = 1 << 15, GDK_DEBUG_GL_GLES = 1 << 16, GDK_DEBUG_GL_DEBUG = 1 << 17, - GDK_DEBUG_GL_GLX = 1 << 18, - GDK_DEBUG_VULKAN_DISABLE = 1 << 19, - GDK_DEBUG_VULKAN_VALIDATE = 1 << 20, - GDK_DEBUG_DEFAULT_SETTINGS= 1 << 21 + GDK_DEBUG_GL_EGL = 1 << 18, + GDK_DEBUG_GL_GLX = 1 << 19, + GDK_DEBUG_VULKAN_DISABLE = 1 << 20, + GDK_DEBUG_VULKAN_VALIDATE = 1 << 21, + GDK_DEBUG_DEFAULT_SETTINGS= 1 << 22 } GdkDebugFlags; extern guint _gdk_debug_flags; diff --git a/gdk/x11/gdkglcontext-egl.c b/gdk/x11/gdkglcontext-egl.c index 3df0919738..56a17168b1 100644 --- a/gdk/x11/gdkglcontext-egl.c +++ b/gdk/x11/gdkglcontext-egl.c @@ -134,6 +134,7 @@ visual_is_rgba (XVisualInfo *visinfo) static gboolean gdk_x11_display_create_egl_config (GdkX11Display *display, + gboolean force, Visual **out_visual, int *out_depth, GError **error) @@ -263,6 +264,13 @@ gdk_x11_display_create_egl_config (GdkX11Display *display, _("No EGL configuration with required features found")); return FALSE; } + else if (!force && best_features != PERFECT) + { + g_set_error_literal (error, GDK_GL_ERROR, + GDK_GL_ERROR_NOT_AVAILABLE, + _("No perfect EGL configuration found")); + return FALSE; + } return TRUE; } @@ -589,6 +597,7 @@ gdk_x11_gl_context_egl_init (GdkX11GLContextEGL *self) gboolean gdk_x11_display_init_egl (GdkX11Display *self, + gboolean force, Visual **out_visual, int *out_depth, GError **error) @@ -625,7 +634,7 @@ gdk_x11_display_init_egl (GdkX11Display *self, return FALSE; } - if (!gdk_x11_display_create_egl_config (self, out_visual, out_depth, error)) + if (!gdk_x11_display_create_egl_config (self, force, out_visual, out_depth, error)) { eglTerminate (self->egl_display); self->egl_display = NULL; diff --git a/gdk/x11/gdkglcontext-x11.c b/gdk/x11/gdkglcontext-x11.c index 389faf6292..c74a994c70 100644 --- a/gdk/x11/gdkglcontext-x11.c +++ b/gdk/x11/gdkglcontext-x11.c @@ -109,8 +109,6 @@ gdk_x11_display_init_gl (GdkX11Display *self, GError **error) { GdkDisplay *display G_GNUC_UNUSED = GDK_DISPLAY (self); - GError *egl_error = NULL; - GError *glx_error = NULL; if (GDK_DISPLAY_DEBUG_CHECK (display, GL_DISABLE)) { @@ -120,27 +118,30 @@ gdk_x11_display_init_gl (GdkX11Display *self, return FALSE; } - if (!GDK_DISPLAY_DEBUG_CHECK (display, GL_GLX)) - { - /* We favour EGL */ - if (gdk_x11_display_init_egl (self, out_visual, out_depth, &egl_error)) - return TRUE; - } + if (GDK_DISPLAY_DEBUG_CHECK (display, GL_EGL)) + return gdk_x11_display_init_egl (self, TRUE, out_visual, out_depth, error); + if (GDK_DISPLAY_DEBUG_CHECK (display, GL_GLX)) + return gdk_x11_display_init_glx (self, out_visual, out_depth, error); - if (gdk_x11_display_init_glx (self, out_visual, out_depth, &glx_error)) - { - g_clear_error (&egl_error); - return TRUE; - } + /* No env vars set, do the regular GL initialization. + * + * We try EGL first, but are very picky about what we accept. + * If that fails, we try to go with GLX instead. + * And if that also fails, we try EGL again, but this time accept anything. + * + * The idea here is that EGL is the preferred method going forward, but GLX is + * the tried and tested method that we know works. So if we detect issues with + * EGL, we want to avoid using it in favor of GLX. + */ - if (egl_error) - { - *error = egl_error; - g_clear_error (&glx_error); - } - else - *error = glx_error; + if (gdk_x11_display_init_egl (self, FALSE, out_visual, out_depth, error)) + return TRUE; + g_clear_error (error); - return FALSE; + if (gdk_x11_display_init_glx (self, out_visual, out_depth, error)) + return TRUE; + g_clear_error (error); + + return gdk_x11_display_init_egl (self, TRUE, out_visual, out_depth, error); } diff --git a/gdk/x11/gdkglcontext-x11.h b/gdk/x11/gdkglcontext-x11.h index 1aa7fbe545..5cc2ebf5d6 100644 --- a/gdk/x11/gdkglcontext-x11.h +++ b/gdk/x11/gdkglcontext-x11.h @@ -101,6 +101,7 @@ gboolean gdk_x11_gl_context_glx_make_current (GdkDisplay * typedef struct _GdkX11GLContextEGL GdkX11GLContextEGL; gboolean gdk_x11_display_init_egl (GdkX11Display *display_x11, + gboolean force, Visual **out_visual, int *out_depth, GError **error);