[gtk/wip/otte/gleanup: 7/12] x11: Initialize GL at startup




commit 7ce3e932137dbe272a7feb448d21ad0d8aaff3fc
Author: Benjamin Otte <otte redhat com>
Date:   Sun Jun 6 17:07:05 2021 +0200

    x11: Initialize GL at startup
    
    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   | 20 ++++++++++++++++++++
 gdk/x11/gdkglcontext-x11.c | 36 ++++++------------------------------
 gdk/x11/gdkglcontext-x11.h |  2 --
 3 files changed, 26 insertions(+), 32 deletions(-)
---
diff --git a/gdk/x11/gdkdisplay-x11.c b/gdk/x11/gdkdisplay-x11.c
index ae7a87c9a0..a1fe68e230 100644
--- a/gdk/x11/gdkdisplay-x11.c
+++ b/gdk/x11/gdkdisplay-x11.c
@@ -1339,6 +1339,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.
@@ -1410,6 +1429,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)
diff --git a/gdk/x11/gdkglcontext-x11.c b/gdk/x11/gdkglcontext-x11.c
index cb87cf8425..b97a77464a 100644
--- a/gdk/x11/gdkglcontext-x11.c
+++ b/gdk/x11/gdkglcontext-x11.c
@@ -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;
 
diff --git a/gdk/x11/gdkglcontext-x11.h b/gdk/x11/gdkglcontext-x11.h
index dc6048b3fe..991c361cc5 100644
--- a/gdk/x11/gdkglcontext-x11.h
+++ b/gdk/x11/gdkglcontext-x11.h
@@ -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,


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