summaryrefslogtreecommitdiff
path: root/gdk/gdkglcontext.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2021-09-24 01:47:03 +0200
committerBenjamin Otte <otte@redhat.com>2021-09-24 01:59:37 +0200
commit23acc993cced48fa1f21ac9f4881338100b1a15a (patch)
tree50f1708b91e4ec16d532e8631edf501a5d314299 /gdk/gdkglcontext.c
parentd7db3f1546156f406509e5bfbf076cd575c5628d (diff)
downloadgtk+-23acc993cced48fa1f21ac9f4881338100b1a15a.tar.gz
gdk: Make sure only one GL backend is usedwip/otte/shittymorph
Creative people managed to create an X11 display and a Wayland display at once, thereby getting EGL and GLX involved in a fight to the death over the ownership of the glFoo() symbolspace. A way to force such a fight with available tools here is (on Wayland) running something like: GTK_INSPECTOR_DISPLAY=:1 GTK_DEBUG=interactive gtk4-demo Related: xdg-desktop-portal-gnome#5
Diffstat (limited to 'gdk/gdkglcontext.c')
-rw-r--r--gdk/gdkglcontext.c71
1 files changed, 69 insertions, 2 deletions
diff --git a/gdk/gdkglcontext.c b/gdk/gdkglcontext.c
index 76be3c7ef9..9f8673627f 100644
--- a/gdk/gdkglcontext.c
+++ b/gdk/gdkglcontext.c
@@ -75,11 +75,13 @@
#include "config.h"
#include "gdkglcontextprivate.h"
+
+#include "gdkdebug.h"
#include "gdkdisplayprivate.h"
-#include "gdkmemorytextureprivate.h"
#include "gdkinternals.h"
-
#include "gdkintl.h"
+#include "gdkmemorytextureprivate.h"
+
#include "gdk-private.h"
#ifdef GDK_WINDOWING_WIN32
@@ -1354,3 +1356,68 @@ gdk_gl_context_use_es_bgra (GdkGLContext *context)
return FALSE;
}
+
+static GdkGLBackend the_gl_backend_type = GDK_GL_NONE;
+
+static const char *gl_backend_names[] = {
+ [GDK_GL_NONE] = "No GL (You should never read this)",
+ [GDK_GL_EGL] = "EGL",
+ [GDK_GL_GLX] = "X11 GLX",
+ [GDK_GL_WGL] = "Windows WGL",
+ [GDK_GL_CGL] = "Apple CGL"
+};
+
+/*<private>
+ * gdk_gl_backend_can_be_used:
+ * @backend_type: Type of backend to check
+ * @error: Return location for an error
+ *
+ * Checks if this backend type can be used. When multiple displays
+ * are opened that use different GL backends, conflicts can arise,
+ * so this function checks that all displays use compatible GL
+ * backends.
+ *
+ * Returns: %TRUE if the backend can still be used
+ */
+gboolean
+gdk_gl_backend_can_be_used (GdkGLBackend backend_type,
+ GError **error)
+{
+ if (the_gl_backend_type == GDK_GL_NONE ||
+ the_gl_backend_type == backend_type)
+ return TRUE;
+
+ g_set_error (error, GDK_GL_ERROR, GDK_GL_ERROR_NOT_AVAILABLE,
+ /* translators: This is about OpenGL backend names, like
+ * "Trying to use X11 GLX, but EGL is already in use" */
+ _("Trying to use %s, but %s is already in use"),
+ gl_backend_names[backend_type],
+ gl_backend_names[the_gl_backend_type]);
+ return FALSE;
+}
+
+/*<private>
+ * gdk_gl_backend_use:
+ * @backend_type: Type of backend
+ *
+ * Ensures that the backend in use is the given one. If another backend
+ * is already in use, this function will abort the program. It should
+ * have previously checked via gdk_gl_backend_can_be_used().
+ **/
+void
+gdk_gl_backend_use (GdkGLBackend backend_type)
+{
+ /* Check that the context class is properly initializing its backend type */
+ g_assert (backend_type != GDK_GL_NONE);
+
+ if (the_gl_backend_type == GDK_GL_NONE)
+ {
+ the_gl_backend_type = backend_type;
+ /* This is important!!!11eleven
+ * (But really: How do I print a message in 2 categories?) */
+ GDK_NOTE (OPENGL, g_print ("Using OpenGL backend %s\n", gl_backend_names[the_gl_backend_type]));
+ GDK_NOTE (MISC, g_message ("Using Opengl backend %s", gl_backend_names[the_gl_backend_type]));
+ }
+
+ g_assert (the_gl_backend_type == backend_type);
+}