Mesa (master): dri: Try harder to infer the drawable fbconfig if needed

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Apr 22 18:42:45 UTC 2021


Module: Mesa
Branch: master
Commit: 5a613c55eba545f16228933da70ef5196680013d
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=5a613c55eba545f16228933da70ef5196680013d

Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Apr 16 13:59:29 2021 -0400

dri: Try harder to infer the drawable fbconfig if needed

This code would work for GLXWindows but not for bare Windows, which I
guess you could argue is a server bug but which we can fix on the client
side with a little effort. We change __glXGetDrawableAttribute to
additionally return false if we failed to find the requested attribute
(which is safe, all the other callers discard the return value). Then
when inferring the fbconfig, if the attribute wasn't found, we ask for
the window attributes to find the visual ID and use that to find the
fbconfig.

Reviewed-by: Eric Anholt <eric at anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10381>

---

 src/glx/dri_common.c  | 26 +++++++++++++++++++++++++-
 src/glx/glx_pbuffer.c |  4 +++-
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/src/glx/dri_common.c b/src/glx/dri_common.c
index 78bd074ea54..8d2590a8fee 100644
--- a/src/glx/dri_common.c
+++ b/src/glx/dri_common.c
@@ -41,6 +41,8 @@
 #include "glxclient.h"
 #include "dri_common.h"
 #include "loader.h"
+#include <X11/Xlib-xcb.h>
+#include <xcb/xproto.h>
 
 #ifndef RTLD_NOW
 #define RTLD_NOW 0
@@ -344,11 +346,32 @@ static struct glx_config *
 driInferDrawableConfig(struct glx_screen *psc, GLXDrawable draw)
 {
    unsigned int fbconfig = 0;
-
+   xcb_get_window_attributes_cookie_t cookie = { 0 };
+   xcb_get_window_attributes_reply_t *attr = NULL;
+   xcb_connection_t *conn = XGetXCBConnection(psc->dpy);
+
+   /* In practice here, either the XID is a bare Window or it was created
+    * by some other client. First let's see if the X server can tell us
+    * the answer. Xorg first added GLX_EXT_no_config_context in 1.20, where
+    * this usually works except for bare Windows that haven't been made
+    * current yet.
+    */
    if (__glXGetDrawableAttribute(psc->dpy, draw, GLX_FBCONFIG_ID, &fbconfig)) {
       return glx_config_find_fbconfig(psc->configs, fbconfig);
    }
 
+   /* Well this had better be a Window then. Figure out its visual and
+    * then find the corresponding GLX visual.
+    */
+   cookie = xcb_get_window_attributes(conn, draw);
+   attr = xcb_get_window_attributes_reply(conn, cookie, NULL);
+
+   if (attr) {
+      uint32_t vid = attr->visual;
+      free(attr);
+      return glx_config_find_visual(psc->visuals, vid);
+   }
+
    return NULL;
 }
 
@@ -375,6 +398,7 @@ driFetchDrawable(struct glx_context *gc, GLXDrawable glxDrawable)
       return pdraw;
    }
 
+   /* if this is a no-config context, infer the fbconfig from the drawable */
    if (config == NULL)
       config = driInferDrawableConfig(gc->psc, glxDrawable);
    if (config == NULL)
diff --git a/src/glx/glx_pbuffer.c b/src/glx/glx_pbuffer.c
index 74b9b55c718..7de6430b51a 100644
--- a/src/glx/glx_pbuffer.c
+++ b/src/glx/glx_pbuffer.c
@@ -273,6 +273,7 @@ __glXGetDrawableAttribute(Display * dpy, GLXDrawable drawable,
    unsigned int i;
    unsigned int num_attributes;
    GLboolean use_glx_1_3;
+   int found = 0;
 
 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
    __GLXDRIdrawable *pdraw;
@@ -394,6 +395,7 @@ __glXGetDrawableAttribute(Display * dpy, GLXDrawable drawable,
           */
          for (i = 0; i < num_attributes; i++) {
             if (data[i * 2] == attribute) {
+               found = 1;
                *value = data[(i * 2) + 1];
                break;
             }
@@ -417,7 +419,7 @@ __glXGetDrawableAttribute(Display * dpy, GLXDrawable drawable,
    UnlockDisplay(dpy);
    SyncHandle();
 
-   return 1;
+   return found;
 }
 
 static void



More information about the mesa-commit mailing list