From cfd92a5868828e57c94753d930be65e36df3fd59 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Wed, 19 Nov 2014 22:01:51 +0000 Subject: [PATCH] glx: Allow passing a Window to GLXGetDrawableAttributes This updates __glXGetDrawable so that it does not require a context pointer to be able to create a __GLXdrawable when a vanilla Window XID is used as a GLXDrawable. Removing this restriction means that DoGetDrawableAttributes can also use this helper function allowing clients to pass Window XIDs as GLXDrawables to glXQueryDrawable(). https://bugs.freedesktop.org/show_bug.cgi?id=54080 https://forums.oculus.com/viewtopic.php?f=20&t=16201 https://forums.oculus.com/viewtopic.php?f=34&t=16664 Signed-off-by: Robert Bragg --- glx/glxcmds.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/glx/glxcmds.c b/glx/glxcmds.c index d11c667..115f9d5 100644 --- a/glx/glxcmds.c +++ b/glx/glxcmds.c @@ -470,6 +470,9 @@ __glXGetDrawable(__GLXcontext * glxc, GLXDrawable drawId, ClientPtr client, { DrawablePtr pDraw; __GLXdrawable *pGlxDraw; + __GLXscreen *pGlxScreen; + __GLXconfig *config; + XID vid; int rc; if (validGlxDrawable(client, drawId, GLX_DRAWABLE_ANY, @@ -483,13 +486,6 @@ __glXGetDrawable(__GLXcontext * glxc, GLXDrawable drawId, ClientPtr client, return pGlxDraw; } - /* No active context and an unknown drawable, bail. */ - if (glxc == NULL) { - client->errorValue = drawId; - *error = BadMatch; - return NULL; - } - /* The drawId wasn't a GLX drawable. Make sure it's a window and * create a GLXWindow for it. Check that the drawable screen * matches the context screen and that the context fbconfig is @@ -502,19 +498,30 @@ __glXGetDrawable(__GLXcontext * glxc, GLXDrawable drawId, ClientPtr client, return NULL; } - if (pDraw->pScreen != glxc->pGlxScreen->pScreen) { + pGlxScreen = glxGetScreen(pDraw->pScreen); + if (!pGlxScreen) { client->errorValue = pDraw->pScreen->myNum; *error = BadMatch; return NULL; } - if (!validGlxFBConfigForWindow(client, glxc->config, pDraw, error)) + vid = wVisual((WindowPtr) pDraw); + if (!validGlxVisual(client, pGlxScreen, vid, &config, error)) { + client->errorValue = vid; + *error = BadMatch; + return NULL; + } + + if (glxc != NULL && config != glxc->config) { + client->errorValue = drawId; + *error = BadMatch; return NULL; + } - pGlxDraw = glxc->pGlxScreen->createDrawable(client, glxc->pGlxScreen, - pDraw, drawId, - GLX_DRAWABLE_WINDOW, - drawId, glxc->config); + pGlxDraw = pGlxScreen->createDrawable(client, pGlxScreen, + pDraw, drawId, + GLX_DRAWABLE_WINDOW, + drawId, config); if (!pGlxDraw) { *error = BadAlloc; return NULL; @@ -1907,12 +1914,11 @@ DoGetDrawableAttributes(__GLXclientState * cl, XID drawId) { ClientPtr client = cl->client; xGLXGetDrawableAttributesReply reply; - __GLXdrawable *pGlxDraw; - CARD32 attributes[14]; int numAttribs = 0, error; + __GLXdrawable *pGlxDraw = __glXGetDrawable(NULL, drawId, client, &error); + CARD32 attributes[14]; - if (!validGlxDrawable(client, drawId, GLX_DRAWABLE_ANY, - DixGetAttrAccess, &pGlxDraw, &error)) + if (pGlxDraw == NULL) return error; attributes[0] = GLX_TEXTURE_TARGET_EXT; -- 2.1.3