[gtk/wip/otte/gleanup] x11: Return the Visual from EGL initialization



commit 9b5a261a01eb319822ac35d3a53d7baf4fe6058f
Author: Benjamin Otte <otte redhat com>
Date:   Fri Jun 11 04:42:47 2021 +0200

    x11: Return the Visual from EGL initialization
    
    This is the first step towards cleaning up the Visual handling during GL
    init.
    
    EGL now computes the Visual and does so without the help of GdkVisual.
    GLX and the non-GL codepath do not, but will follow.

 gdk/x11/gdkdisplay-x11.c   |  26 +++++++----
 gdk/x11/gdkglcontext-egl.c | 111 ++++++++++++++++++++++++---------------------
 gdk/x11/gdkglcontext-x11.h |   1 +
 3 files changed, 79 insertions(+), 59 deletions(-)
---
diff --git a/gdk/x11/gdkdisplay-x11.c b/gdk/x11/gdkdisplay-x11.c
index d1a15402bd..5225b45547 100644
--- a/gdk/x11/gdkdisplay-x11.c
+++ b/gdk/x11/gdkdisplay-x11.c
@@ -1339,23 +1339,29 @@ set_sm_client_id (GdkDisplay  *display,
                      gdk_x11_get_xatom_by_name_for_display (display, "SM_CLIENT_ID"));
 }
 
-static void
+static XVisualInfo *
 gdk_x11_display_init_gl (GdkX11Display *self)
 {
-  GdkDisplay *display G_GNUC_UNUSED = GDK_DISPLAY (self);
+  GdkDisplay *display = GDK_DISPLAY (self);
+  XVisualInfo *visinfo = NULL;
 
   if (GDK_DISPLAY_DEBUG_CHECK (display, GL_DISABLE))
-    return;
+    return NULL;
 
   if (!GDK_DISPLAY_DEBUG_CHECK (display, GL_GLX))
     {
       /* We favour EGL */
       if (gdk_x11_display_init_egl (self))
-        return;
+        {
+          visinfo = gdk_x11_display_init_egl_visual (self);
+          if (visinfo)
+            return visinfo;
+        }
     }
 
-  if (gdk_x11_display_init_glx (self))
-    return;
+  /* XXX: Make this return a visinfo */
+  gdk_x11_display_init_glx (self);
+  return NULL;
 }
 
 /**
@@ -1381,6 +1387,7 @@ gdk_x11_display_open (const char *display_name)
   int ignore;
   int maj, min;
   char *cm_name;
+  XVisualInfo *visinfo;
 
   XInitThreads ();
 
@@ -1429,9 +1436,12 @@ 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);
+  visinfo = gdk_x11_display_init_gl (display_x11);
 
-  if (display_x11->screen->rgba_visual)
+  if (visinfo)
+    {
+    }
+  else if (display_x11->screen->rgba_visual)
     {
       Visual *xvisual = GDK_X11_VISUAL (display_x11->screen->rgba_visual)->xvisual;
 
diff --git a/gdk/x11/gdkglcontext-egl.c b/gdk/x11/gdkglcontext-egl.c
index a28d67e1d9..9a86864124 100644
--- a/gdk/x11/gdkglcontext-egl.c
+++ b/gdk/x11/gdkglcontext-egl.c
@@ -153,55 +153,9 @@ gdk_x11_surface_destroy_egl_surface (GdkX11Surface *self)
   self->egl_surface = NULL;
 }
 
-static XVisualInfo *
-get_visual_info_for_egl_config (GdkDisplay *display,
-                                EGLConfig   egl_config)
-{
-  XVisualInfo visinfo_template;
-  int template_mask = 0;
-  XVisualInfo *visinfo = NULL;
-  int visinfos_count;
-  EGLint visualid, red_size, green_size, blue_size, alpha_size;
-  EGLDisplay egl_display = gdk_x11_display_get_egl_display (display);
-
-  eglGetConfigAttrib (egl_display, egl_config, EGL_NATIVE_VISUAL_ID, &visualid);
-
-  if (visualid != 0)
-    {
-      visinfo_template.visualid = visualid;
-      template_mask |= VisualIDMask;
-    }
-  else
-    {
-      /* some EGL drivers don't implement the EGL_NATIVE_VISUAL_ID
-       * attribute, so attempt to find the closest match.
-       */
-      eglGetConfigAttrib (egl_display, egl_config, EGL_RED_SIZE, &red_size);
-      eglGetConfigAttrib (egl_display, egl_config, EGL_GREEN_SIZE, &green_size);
-      eglGetConfigAttrib (egl_display, egl_config, EGL_BLUE_SIZE, &blue_size);
-      eglGetConfigAttrib (egl_display, egl_config, EGL_ALPHA_SIZE, &alpha_size);
-
-      visinfo_template.depth = red_size + green_size + blue_size + alpha_size;
-      template_mask |= VisualDepthMask;
-
-      visinfo_template.screen = DefaultScreen (gdk_x11_display_get_xdisplay (display));
-      template_mask |= VisualScreenMask;
-    }
-
-  visinfo = XGetVisualInfo (gdk_x11_display_get_xdisplay (display),
-                            template_mask,
-                            &visinfo_template,
-                            &visinfos_count);
-
-  if (visinfos_count < 1)
-    return NULL;
-
-  return visinfo;
-}
-
+static EGLConfig gdk_x11_display_get_egl_config (GdkX11Display *);
 static EGLSurface
-gdk_x11_display_get_egl_dummy_surface (GdkDisplay *display,
-                                       EGLConfig   egl_config)
+gdk_x11_display_get_egl_dummy_surface (GdkDisplay *display)
 {
   GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
   DrawableInfo *info;
@@ -212,7 +166,7 @@ gdk_x11_display_get_egl_dummy_surface (GdkDisplay *display,
   if (info != NULL)
     return info->egl_surface;
 
-  xvisinfo = get_visual_info_for_egl_config (display, egl_config);
+  xvisinfo = gdk_x11_display_init_egl_visual (display_x11);
   if (xvisinfo == NULL)
     return NULL;
 
@@ -220,7 +174,7 @@ gdk_x11_display_get_egl_dummy_surface (GdkDisplay *display,
   info->xdisplay = gdk_x11_display_get_xdisplay (display);
   info->xvisinfo = xvisinfo;
   info->egl_display = gdk_x11_display_get_egl_display (display);
-  info->egl_config = egl_config;
+  info->egl_config = gdk_x11_display_get_egl_config (display_x11);
 
   attrs.override_redirect = True;
   attrs.colormap = gdk_x11_display_get_window_colormap (display_x11);
@@ -671,6 +625,61 @@ gdk_x11_display_get_egl_config (GdkX11Display *display)
 
 #undef MAX_EGL_ATTRS
 
+/* Return value must be freed with XFree() */
+XVisualInfo *
+gdk_x11_display_init_egl_visual (GdkX11Display *self)
+{
+  GdkDisplay *display = GDK_DISPLAY (self);
+  XVisualInfo visinfo_template;
+  int template_mask = 0;
+  XVisualInfo *visinfo = NULL;
+  int visinfos_count;
+  EGLint visualid, red_size, green_size, blue_size, alpha_size;
+  EGLDisplay egl_display;
+  EGLConfig egl_config;
+
+  egl_display = gdk_x11_display_get_egl_display (display);
+  if (egl_display == NULL)
+    return NULL;
+  egl_config = gdk_x11_display_get_egl_config (self);
+  if (egl_config == NULL)
+    return NULL;
+
+  eglGetConfigAttrib (egl_display, egl_config, EGL_NATIVE_VISUAL_ID, &visualid);
+
+  if (visualid != 0)
+    {
+      visinfo_template.visualid = visualid;
+      template_mask |= VisualIDMask;
+    }
+  else
+    {
+      /* some EGL drivers don't implement the EGL_NATIVE_VISUAL_ID
+       * attribute, so attempt to find the closest match.
+       */
+      eglGetConfigAttrib (egl_display, egl_config, EGL_RED_SIZE, &red_size);
+      eglGetConfigAttrib (egl_display, egl_config, EGL_GREEN_SIZE, &green_size);
+      eglGetConfigAttrib (egl_display, egl_config, EGL_BLUE_SIZE, &blue_size);
+      eglGetConfigAttrib (egl_display, egl_config, EGL_ALPHA_SIZE, &alpha_size);
+
+      visinfo_template.depth = red_size + green_size + blue_size + alpha_size;
+      template_mask |= VisualDepthMask;
+
+      visinfo_template.screen = DefaultScreen (gdk_x11_display_get_xdisplay (display));
+      template_mask |= VisualScreenMask;
+    }
+
+  visinfo = XGetVisualInfo (gdk_x11_display_get_xdisplay (display),
+                            template_mask,
+                            &visinfo_template,
+                            &visinfos_count);
+
+  if (visinfos_count < 1)
+    return NULL;
+
+  return visinfo;
+}
+
 GdkX11GLContext *
 gdk_x11_gl_context_egl_new (GdkSurface    *surface,
                             gboolean       attached,
@@ -735,7 +744,7 @@ gdk_x11_gl_context_egl_make_current (GdkDisplay   *display,
       if (display_x11->has_egl_surfaceless_context)
         egl_surface = EGL_NO_SURFACE;
       else
-        egl_surface = gdk_x11_display_get_egl_dummy_surface (display, display_x11->egl_config);
+        egl_surface = gdk_x11_display_get_egl_dummy_surface (display);
     }
 
   GDK_DISPLAY_NOTE (display, OPENGL,
diff --git a/gdk/x11/gdkglcontext-x11.h b/gdk/x11/gdkglcontext-x11.h
index ca296a2c97..11a3babd72 100644
--- a/gdk/x11/gdkglcontext-x11.h
+++ b/gdk/x11/gdkglcontext-x11.h
@@ -93,6 +93,7 @@ gboolean                gdk_x11_gl_context_glx_make_current     (GdkDisplay    *
 typedef struct _GdkX11GLContextEGL      GdkX11GLContextEGL;
 
 gboolean                gdk_x11_display_init_egl                (GdkX11Display *display_x11);
+XVisualInfo *           gdk_x11_display_init_egl_visual         (GdkX11Display *self);
 void                    gdk_x11_surface_destroy_egl_surface     (GdkX11Surface *self);
 
 GType                   gdk_x11_gl_context_egl_get_type         (void) G_GNUC_CONST;


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