summaryrefslogtreecommitdiff
path: root/src/glx
diff options
context:
space:
mode:
authorPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>2021-12-13 15:07:13 +0100
committerMarge Bot <emma+marge@anholt.net>2021-12-16 01:21:36 +0000
commit1cb5c1775b0a647600d3159c287063bccd0cc38c (patch)
treeb9bd63325b8b8c66938b5143a06bc334d9b5a354 /src/glx
parent6c5b3c6bb56b12ae1e0f04e7bb62e2e60abe991d (diff)
glx: fix querying GLX_FBCONFIG_ID for Window
This commit fixes apps using the following sequence: 1. XCreateWindow(dpy) -> win 2. glXCreateContextAttribsARB(dpy, ...) -> ctx 3. glXMakeCurrent(dpy, win, ctx) 4. glXQueryDrawable(dpy, win, GLX_FBCONFIG_ID, ...) glXQueryDrawable returned 0 (while correctly returning a valid GLXFCONFIG_ID for other types of drawables). This commit adds the same dance as driInferDrawableConfig to get the GLX visual from the Window, and then the GLXFBCONFIG_ID of this visual. This fixes: * piglit: glx-query-drawable --attr=GLX_FBCONFIG_ID --type=WINDOW * Maya which uses the config ID from step 4 as an input to glXChooseFBConfig. Reviewed-by: Adam Jackson <ajax@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14174>
Diffstat (limited to 'src/glx')
-rw-r--r--src/glx/glx_pbuffer.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/glx/glx_pbuffer.c b/src/glx/glx_pbuffer.c
index 7500651529e..f7d9a631377 100644
--- a/src/glx/glx_pbuffer.c
+++ b/src/glx/glx_pbuffer.c
@@ -38,6 +38,9 @@
#include <limits.h>
#include "glxextensions.h"
+#include <X11/Xlib-xcb.h>
+#include <xcb/xproto.h>
+
#ifdef GLX_USE_APPLEGL
#include <pthread.h>
#include "apple/apple_glx_drawable.h"
@@ -387,6 +390,44 @@ __glXGetDrawableAttribute(Display * dpy, GLXDrawable drawable,
UnlockDisplay(dpy);
SyncHandle();
+#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
+ if (pdraw && attribute == GLX_FBCONFIG_ID && !found && priv && priv->screens != NULL) {
+ /* If we failed to lookup the GLX_FBCONFIG_ID, it may be because the drawable is
+ * a bare Window, so try differently by first figure out its visual, then GLX
+ * visual like driInferDrawableConfig does.
+ */
+ xcb_get_window_attributes_cookie_t cookie = { 0 };
+ xcb_get_window_attributes_reply_t *attr = NULL;
+
+ xcb_connection_t *conn = XGetXCBConnection(dpy);
+
+ if (conn) {
+ cookie = xcb_get_window_attributes(conn, drawable);
+ attr = xcb_get_window_attributes_reply(conn, cookie, NULL);
+ if (attr) {
+ /* Find the Window's GLX Visual */
+ struct glx_config *conf = glx_config_find_visual(pdraw->psc->visuals, attr->visual);
+ free(attr);
+
+ if (conf && conf->screen >= 0 && conf->screen < ScreenCount(dpy)) {
+ /* Then find the GLXFBConfig of the GLX Visual */
+ struct glx_config *c;
+ for (c = priv->screens[conf->screen]->configs; c != NULL;
+ c = c->next) {
+ if (!c->visualID)
+ continue;
+ if (c->visualID == conf->visualID) {
+ *value = c->fbconfigID;
+ found = 1;
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+#endif
+
return found;
}