x11: Initialize GL at startup
authorBenjamin Otte <otte@redhat.com>
Sun, 6 Jun 2021 15:07:05 +0000 (17:07 +0200)
committerBenjamin Otte <otte@redhat.com>
Thu, 22 Jul 2021 14:06:05 +0000 (16:06 +0200)
We need to initialize GL to select the Visual we are going to use for
all our Windows.

As the Visual needs to be known before we know if we are even gonna use
GL later, we can't avoid initializing it.

Note that this previously happened, too. It was just hidden behind the
GdkScreen initialization.

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

index 707abe491f865802ac661f8e81afbc71f04e91f0..5eaf09ec6b76932750662eac32e8cd5260a9ef76 100644 (file)
@@ -1335,6 +1335,25 @@ set_sm_client_id (GdkDisplay  *display,
                      gdk_x11_get_xatom_by_name_for_display (display, "SM_CLIENT_ID"));
 }
 
+static void
+gdk_x11_display_init_gl (GdkX11Display *self)
+{
+  GdkDisplay *display G_GNUC_UNUSED = GDK_DISPLAY (self);
+
+  if (GDK_DISPLAY_DEBUG_CHECK (display, GL_DISABLE))
+    return;
+
+  if (!GDK_DISPLAY_DEBUG_CHECK (display, GL_GLX))
+    {
+      /* We favour EGL */
+      if (gdk_x11_screen_init_egl (self->screen))
+        return;
+    }
+
+  if (gdk_x11_screen_init_glx (self->screen))
+    return;
+}
+
 /**
  * gdk_x11_display_open:
  * @display_name: (nullable): name of the X display.
@@ -1406,6 +1425,7 @@ gdk_x11_display_open (const char *display_name)
    * as we care about GLX details such as alpha/depth/stencil depth,
    * stereo and double buffering
    */
+  gdk_x11_display_init_gl (display_x11);
   gdk_x11_screen_update_visuals_for_glx (display_x11->screen);
 
   if (display_x11->screen->rgba_visual)
index cb87cf842553dc33b95aa60f567b3ecd60e5776b..b97a77464a00394bc530d54e7baed5132ea0c1d2 100644 (file)
@@ -54,27 +54,6 @@ gdk_x11_gl_context_init (GdkX11GLContext *self)
   self->do_frame_sync = TRUE;
 }
 
-gboolean
-gdk_x11_screen_init_gl (GdkX11Screen *screen)
-{
-  GdkDisplay *display G_GNUC_UNUSED = GDK_SCREEN_DISPLAY (screen);
-
-  if (GDK_DISPLAY_DEBUG_CHECK (display, GL_DISABLE))
-    return FALSE;
-
-  if (!GDK_DISPLAY_DEBUG_CHECK (display, GL_GLX))
-    {
-      /* We favour EGL */
-      if (gdk_x11_screen_init_egl (screen))
-        return TRUE;
-    }
-
-  if (gdk_x11_screen_init_glx (screen))
-    return TRUE;
-
-  return FALSE;
-}
-
 GdkGLContext *
 gdk_x11_surface_create_gl_context (GdkSurface    *surface,
                                    gboolean       attached,
@@ -86,8 +65,13 @@ gdk_x11_surface_create_gl_context (GdkSurface    *surface,
   GdkDisplay *display;
 
   display = gdk_surface_get_display (surface);
+  display_x11 = GDK_X11_DISPLAY (display);
 
-  if (!gdk_x11_screen_init_gl (GDK_SURFACE_SCREEN (surface)))
+  if (display_x11->have_egl)
+    context = gdk_x11_gl_context_egl_new (surface, attached, share, error);
+  else if (display_x11->have_glx)
+    context = gdk_x11_gl_context_glx_new (surface, attached, share, error);
+  else
     {
       g_set_error_literal (error, GDK_GL_ERROR,
                            GDK_GL_ERROR_NOT_AVAILABLE,
@@ -95,14 +79,6 @@ gdk_x11_surface_create_gl_context (GdkSurface    *surface,
       return NULL;
     }
 
-  display_x11 = GDK_X11_DISPLAY (display);
-  if (display_x11->have_egl)
-    context = gdk_x11_gl_context_egl_new (surface, attached, share, error);
-  else if (display_x11->have_glx)
-    context = gdk_x11_gl_context_glx_new (surface, attached, share, error);
-  else
-    g_assert_not_reached ();
-
   if (context == NULL)
     return NULL;
 
index dc6048b3fe0c8703588b1d4a6d962f0d46dc98bf..991c361cc53c619e749678e25352e4e0dc9f9c41 100644 (file)
@@ -60,8 +60,6 @@ struct _GdkX11GLContextClass
   void (* bind_for_frame_fence) (GdkX11GLContext *self);
 };
 
-gboolean        gdk_x11_screen_init_gl                  (GdkX11Screen  *screen);
-
 GdkGLContext *  gdk_x11_surface_create_gl_context       (GdkSurface    *window,
                                                          gboolean       attached,
                                                          GdkGLContext  *share,