[gtk/wip/otte/gleanup: 6/12] x11: Don't share cached GLX visuals with GTK3




commit 7c032da59f821e11854cf501de995c5796d7cfb4
Author: Benjamin Otte <otte redhat com>
Date:   Thu Jun 3 19:20:51 2021 +0200

    x11: Don't share cached GLX visuals with GTK3
    
    We don't want to bind ourselves to GTK3 - both because we don't want to
    accidentally cause bugs in a different codebase and because we want to
    deviate from it.
    
    While doing so, also store visuals as visuals and not as integers.
    And only store one Visual because GTK4 only uses one visual.
    
    And then remove the code that is leftover for dealing with the
    compatibility Visual for GTK3.
    
    PS: I'm kinda proud of my STRINGIFY_WITHOUT_BRACKETS hack.

 gdk/x11/gdkglcontext-glx.c | 67 +++++++++++++++++++++-------------------------
 gdk/x11/gdkscreen-x11.h    |  1 -
 gdk/x11/gdkvisual-x11.c    |  6 -----
 3 files changed, 30 insertions(+), 44 deletions(-)
---
diff --git a/gdk/x11/gdkglcontext-glx.c b/gdk/x11/gdkglcontext-glx.c
index eece4ce360..f18b63f814 100644
--- a/gdk/x11/gdkglcontext-glx.c
+++ b/gdk/x11/gdkglcontext-glx.c
@@ -947,38 +947,36 @@ pick_better_visual_for_gl (GdkX11Screen *x11_screen,
   return compatible;
 }
 
-static gboolean
-get_cached_gl_visuals (GdkDisplay *display, int *system, int *rgba)
+#define STRINGIFY_WITHOUT_BRACKETS(x) G_STRINGIFY x
+#define CACHED_VISUAL_ATOM_NAME "GDK" STRINGIFY_WITHOUT_BRACKETS(GDK_MAJOR_VERSION) "_GLX_VISUAL"
+
+static VisualID
+get_cached_gl_visual (GdkDisplay *display)
 {
-  gboolean found;
   Atom type_return;
   int format_return;
   gulong nitems_return;
   gulong bytes_after_return;
   guchar *data = NULL;
   Display *dpy;
+  VisualID result;
 
   dpy = gdk_x11_display_get_xdisplay (display);
-
-  found = FALSE;
+  result = 0;
 
   gdk_x11_display_error_trap_push (display);
   if (XGetWindowProperty (dpy, DefaultRootWindow (dpy),
-                          gdk_x11_get_xatom_by_name_for_display (display, "GDK_VISUALS"),
-                          0, 2, False, XA_INTEGER, &type_return,
+                          gdk_x11_get_xatom_by_name_for_display (display, CACHED_VISUAL_ATOM_NAME),
+                          0, 1, False, XA_VISUALID, &type_return,
                           &format_return, &nitems_return,
                           &bytes_after_return, &data) == Success)
     {
-      if (type_return == XA_INTEGER &&
+      if (type_return == XA_VISUALID &&
           format_return == 32 &&
-          nitems_return == 2 &&
+          nitems_return == 1 &&
           data != NULL)
         {
-          long *visuals = (long *) data;
-
-          *system = (int)visuals[0];
-          *rgba = (int)visuals[1];
-          found = TRUE;
+          result = *(unsigned long *) data;
         }
     }
   gdk_x11_display_error_trap_pop_ignored (display);
@@ -986,25 +984,24 @@ get_cached_gl_visuals (GdkDisplay *display, int *system, int *rgba)
   if (data)
     XFree (data);
 
-  return found;
+  return result;
 }
 
 static void
-save_cached_gl_visuals (GdkDisplay *display, int system, int rgba)
+save_cached_gl_visual (GdkDisplay *display, VisualID visual)
 {
-  long visualdata[2];
+  unsigned long visualdata[1];
   Display *dpy;
 
   dpy = gdk_x11_display_get_xdisplay (display);
 
-  visualdata[0] = system;
-  visualdata[1] = rgba;
+  visualdata[0] = visual;
 
   gdk_x11_display_error_trap_push (display);
   XChangeProperty (dpy, DefaultRootWindow (dpy),
-                   gdk_x11_get_xatom_by_name_for_display (display, "GDK_VISUALS"),
-                   XA_INTEGER, 32, PropModeReplace,
-                   (unsigned char *)visualdata, 2);
+                   gdk_x11_get_xatom_by_name_for_display (display, CACHED_VISUAL_ATOM_NAME),
+                   XA_VISUALID, 32, PropModeReplace,
+                   (unsigned char *) visualdata, 2);
   gdk_x11_display_error_trap_pop_ignored (display);
 }
 
@@ -1016,7 +1013,7 @@ gdk_x11_screen_update_visuals_for_glx (GdkX11Screen *x11_screen)
   Display *dpy;
   struct glvisualinfo *gl_info;
   int i;
-  int system_visual_id, rgba_visual_id;
+  int rgba_visual_id;
 
   display = x11_screen->display;
   display_x11 = GDK_X11_DISPLAY (display);
@@ -1027,20 +1024,20 @@ gdk_x11_screen_update_visuals_for_glx (GdkX11Screen *x11_screen)
 
   /* We save the default visuals as a property on the root window to avoid
      having to initialize GL each time, as it may not be used later. */
-  if (get_cached_gl_visuals (display, &system_visual_id, &rgba_visual_id))
+  rgba_visual_id = get_cached_gl_visual (display);
+  if (rgba_visual_id)
     {
       for (i = 0; i < x11_screen->nvisuals; i++)
         {
           GdkX11Visual *visual = x11_screen->visuals[i];
           int visual_id = gdk_x11_visual_get_xvisual (visual)->visualid;
 
-          if (visual_id == system_visual_id)
-            x11_screen->system_visual = visual;
           if (visual_id == rgba_visual_id)
-            x11_screen->rgba_visual = visual;
+            {
+              x11_screen->rgba_visual = visual;
+              return;
+            }
         }
-
-      return;
     }
 
   if (!gdk_x11_screen_init_glx (x11_screen))
@@ -1079,17 +1076,13 @@ gdk_x11_screen_update_visuals_for_glx (GdkX11Screen *x11_screen)
       XFree (visual_list);
     }
 
-  x11_screen->system_visual = pick_better_visual_for_gl (x11_screen, gl_info, x11_screen->system_visual);
   if (x11_screen->rgba_visual)
-    x11_screen->rgba_visual = pick_better_visual_for_gl (x11_screen, gl_info, x11_screen->rgba_visual);
+    {
+      x11_screen->rgba_visual = pick_better_visual_for_gl (x11_screen, gl_info, x11_screen->rgba_visual);
+      save_cached_gl_visual (display, gdk_x11_visual_get_xvisual (x11_screen->rgba_visual)->visualid);
+    }
 
   g_free (gl_info);
-
-  save_cached_gl_visuals (display,
-                          gdk_x11_visual_get_xvisual (x11_screen->system_visual)->visualid,
-                          x11_screen->rgba_visual
-                            ? gdk_x11_visual_get_xvisual (x11_screen->rgba_visual)->visualid
-                            : 0);
 }
 
 GdkX11GLContext *
diff --git a/gdk/x11/gdkscreen-x11.h b/gdk/x11/gdkscreen-x11.h
index 2965385d2f..03cbee6678 100644
--- a/gdk/x11/gdkscreen-x11.h
+++ b/gdk/x11/gdkscreen-x11.h
@@ -74,7 +74,6 @@ struct _GdkX11Screen
   /* Visual Part */
   int nvisuals;
   GdkX11Visual **visuals;
-  GdkX11Visual *system_visual;
   int available_depths[7];
   GdkVisualType available_types[6];
   gint16 navailable_depths;
diff --git a/gdk/x11/gdkvisual-x11.c b/gdk/x11/gdkvisual-x11.c
index c97913ad1f..d8dba33c2d 100644
--- a/gdk/x11/gdkvisual-x11.c
+++ b/gdk/x11/gdkvisual-x11.c
@@ -65,7 +65,6 @@ _gdk_x11_screen_init_visuals (GdkX11Screen *x11_screen)
 
   XVisualInfo *visual_list;
   XVisualInfo visual_template;
-  Visual *default_xvisual;
   GdkX11Visual **visuals;
   int nxvisuals;
   int nvisuals;
@@ -79,8 +78,6 @@ _gdk_x11_screen_init_visuals (GdkX11Screen *x11_screen)
   for (i = 0; i < nxvisuals; i++)
     visuals[i] = g_object_new (GDK_TYPE_X11_VISUAL, NULL);
 
-  default_xvisual = DefaultVisual (x11_screen->xdisplay, x11_screen->screen_num);
-
   nvisuals = 0;
   for (i = 0; i < nxvisuals; i++)
     {
@@ -143,9 +140,6 @@ _gdk_x11_screen_init_visuals (GdkX11Screen *x11_screen)
 
   for (i = 0; i < nvisuals; i++)
     {
-      if (default_xvisual->visualid == GDK_X11_VISUAL (visuals[i])->xvisual->visualid)
-        x11_screen->system_visual = visuals[i];
-
       /* For now, we only support 8888 ARGB for the "rgba visual".
        * Additional formats (like ABGR) could be added later if they
        * turn up.


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