From 2b4e009ed56b69b243f5cc88f490dcf8166cf729 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 4 Feb 2010 15:39:36 -0800 Subject: glx: Use wrapper macro to detect direct rendering The wrapper macro GC_IS_DIRECT is used in CreateContext and a couple other places to eliminate the need for some of the '#ifdef GLX_DIRECT_RENDERING' madness. There appear to be a *LOT* of places in glxcmds.c where '#ifdef GLX_DIRECT_RENDERING' is missing. --- src/glx/glxcmds.c | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c index c3be974ea91..49224060adb 100644 --- a/src/glx/glxcmds.c +++ b/src/glx/glxcmds.c @@ -42,6 +42,9 @@ #include #include #include "xf86dri.h" +#define GC_IS_DIRECT(gc) ((gc)->driContext != NULL) +#else +#define GC_IS_DIRECT(gc) (0) #endif #if defined(USE_XCB) @@ -431,11 +434,7 @@ CreateContext(Display * dpy, XVisualInfo * vis, req->visual = vis->visualid; req->screen = vis->screen; req->shareList = shareList ? shareList->xid : None; -#ifdef GLX_DIRECT_RENDERING - req->isDirect = gc->driContext != NULL; -#else - req->isDirect = 0; -#endif + req->isDirect = GC_IS_DIRECT(gc); } else if (use_glx_1_3) { xGLXCreateNewContextReq *req; @@ -449,11 +448,7 @@ CreateContext(Display * dpy, XVisualInfo * vis, req->screen = fbconfig->screen; req->renderType = renderType; req->shareList = shareList ? shareList->xid : None; -#ifdef GLX_DIRECT_RENDERING - req->isDirect = gc->driContext != NULL; -#else - req->isDirect = 0; -#endif + req->isDirect = GC_IS_DIRECT(gc); } else { xGLXVendorPrivateWithReplyReq *vpreq; @@ -472,11 +467,7 @@ CreateContext(Display * dpy, XVisualInfo * vis, req->screen = fbconfig->screen; req->renderType = renderType; req->shareList = shareList ? shareList->xid : None; -#ifdef GLX_DIRECT_RENDERING - req->isDirect = gc->driContext != NULL; -#else - req->isDirect = 0; -#endif + req->isDirect = GC_IS_DIRECT(gc); } UnlockDisplay(dpy); @@ -864,11 +855,9 @@ glXIsDirect(Display * dpy, GLXContext gc) { if (!gc) { return GL_FALSE; -#ifdef GLX_DIRECT_RENDERING } - else if (gc->driContext) { + else if (GC_IS_DIRECT(gc)) { return GL_TRUE; -#endif } return __glXIsDirect(dpy, gc->xid); } @@ -2874,13 +2863,8 @@ __glXReleaseTexImageEXT(Display * dpy, GLXDrawable drawable, int buffer) INT32 *buffer_ptr; CARD8 opcode; - if (gc == NULL) - return; - -#ifdef GLX_DIRECT_RENDERING - if (gc->driContext) + if ((gc == NULL) || GC_IS_DIRECT(gc)) return; -#endif opcode = __glXSetupForCommand(dpy); if (!opcode) -- cgit v1.2.3 From 26b2bee79d77b7a7b854d7300a10dce69e93d5cd Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 4 Feb 2010 15:47:54 -0800 Subject: glx: Eliminate several 'unused variable' warnings in glxcmds.c. --- src/glx/glxcmds.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c index 49224060adb..a4e626bb57f 100644 --- a/src/glx/glxcmds.c +++ b/src/glx/glxcmds.c @@ -65,6 +65,8 @@ static Bool windowExistsFlag; static int windowExistsErrorHandler(Display * dpy, XErrorEvent * xerr) { + (void) dpy; + if (xerr->error_code == BadWindow) { windowExistsFlag = GL_FALSE; } @@ -1471,6 +1473,8 @@ glXQueryExtensionsString(Display * dpy, int screen) PUBLIC const char * glXGetClientString(Display * dpy, int name) { + (void) dpy; + switch (name) { case GLX_VENDOR: return (__glXGLXClientVendorName); @@ -2379,6 +2383,8 @@ __driGetMscRateOML(__DRIdrawable * draw, int i; __GLXDRIdrawable *glxDraw = private; + (void) draw; + psc = glxDraw->psc; if (XF86VidModeQueryVersion(psc->dpy, &i, &i) && XF86VidModeGetModeLine(psc->dpy, psc->scr, &dot_clock, &mode_line)) { @@ -2425,6 +2431,11 @@ __driGetMscRateOML(__DRIdrawable * draw, else return False; #else + (void) draw; + (void) numerator; + (void) denominator; + (void) private; + return False; #endif } -- cgit v1.2.3 From 71a6fb15ceb6619d39029ff897daf2da4858b17e Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 4 Feb 2010 15:59:51 -0800 Subject: glx: Add casts to eliminate 'comparison between signed and unsigned' warnings --- src/glx/glxcmds.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c index a4e626bb57f..504d17fe173 100644 --- a/src/glx/glxcmds.c +++ b/src/glx/glxcmds.c @@ -1090,7 +1090,7 @@ init_fbconfig_for_chooser(__GLcontextModes * config, #define MATCH_DONT_CARE( param ) \ do { \ - if ( (a-> param != GLX_DONT_CARE) \ + if ( ((int) a-> param != (int) GLX_DONT_CARE) \ && (a-> param != b-> param) ) { \ return False; \ } \ @@ -1098,7 +1098,7 @@ init_fbconfig_for_chooser(__GLcontextModes * config, #define MATCH_MINIMUM( param ) \ do { \ - if ( (a-> param != GLX_DONT_CARE) \ + if ( ((int) a-> param != (int) GLX_DONT_CARE) \ && (a-> param > b-> param) ) { \ return False; \ } \ @@ -1165,7 +1165,7 @@ fbconfigs_compatible(const __GLcontextModes * const a, * the (broken) drivers. */ - if (a->transparentPixel != GLX_DONT_CARE && a->transparentPixel != 0) { + if (a->transparentPixel != (int) GLX_DONT_CARE && a->transparentPixel != 0) { if (a->transparentPixel == GLX_NONE) { if (b->transparentPixel != GLX_NONE && b->transparentPixel != 0) return False; @@ -1812,14 +1812,15 @@ glXGetFBConfigs(Display * dpy, int screen, int *nelements) if (priv && (priv->screenConfigs != NULL) && (screen >= 0) && (screen <= ScreenCount(dpy)) && (priv->screenConfigs[screen].configs != NULL) - && (priv->screenConfigs[screen].configs->fbconfigID != GLX_DONT_CARE)) { + && (priv->screenConfigs[screen].configs->fbconfigID + != (int) GLX_DONT_CARE)) { unsigned num_configs = 0; __GLcontextModes *modes; for (modes = priv->screenConfigs[screen].configs; modes != NULL; modes = modes->next) { - if (modes->fbconfigID != GLX_DONT_CARE) { + if (modes->fbconfigID != (int) GLX_DONT_CARE) { num_configs++; } } @@ -1831,7 +1832,7 @@ glXGetFBConfigs(Display * dpy, int screen, int *nelements) i = 0; for (modes = priv->screenConfigs[screen].configs; modes != NULL; modes = modes->next) { - if (modes->fbconfigID != GLX_DONT_CARE) { + if (modes->fbconfigID != (int) GLX_DONT_CARE) { config[i] = modes; i++; } @@ -2295,7 +2296,7 @@ glXGetFBConfigFromVisualSGIX(Display * dpy, XVisualInfo * vis) if ((GetGLXPrivScreenConfig(dpy, vis->screen, &priv, &psc) != Success) && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit) - && (psc->configs->fbconfigID != GLX_DONT_CARE)) { + && (psc->configs->fbconfigID != (int) GLX_DONT_CARE)) { return (GLXFBConfigSGIX) _gl_context_modes_find_visual(psc->configs, vis->visualid); } -- cgit v1.2.3 From 1add5354d0fbfb2d9b6a4a3fd6a39225bcadc098 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 4 Feb 2010 16:00:58 -0800 Subject: glx: Change type to eliminate 'comparison between signed and unsigned' warning --- src/glx/glxcmds.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c index 504d17fe173..19538f2e5c0 100644 --- a/src/glx/glxcmds.c +++ b/src/glx/glxcmds.c @@ -1636,7 +1636,6 @@ static int __glXQueryContextInfo(Display * dpy, GLXContext ctx) else { int *propList, *pProp; int nPropListBytes; - int i; nPropListBytes = numValues << 3; propList = (int *) Xmalloc(nPropListBytes); @@ -1644,6 +1643,8 @@ static int __glXQueryContextInfo(Display * dpy, GLXContext ctx) retval = 0; } else { + unsigned i; + _XRead(dpy, (char *) propList, nPropListBytes); pProp = propList; for (i = 0; i < numValues; i++) { -- cgit v1.2.3 From 68fef184390da2fd67acfd99fba0a2dbe4a3b875 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 4 Feb 2010 16:15:45 -0800 Subject: glx: Fix interval test in glXSwapIntervalMESA It appears that, in spite of what the spec says, the interval parameter to glXSwapIntervalMESA has been an unsigned int since day-1. This made the 'if (interval < 0)' test useless. The test is removed and the spec is updated to note that the interval is an unsigned value. --- docs/MESA_swap_control.spec | 7 ++----- src/glx/glxcmds.c | 4 ---- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/docs/MESA_swap_control.spec b/docs/MESA_swap_control.spec index ecc674649e2..856978b535b 100644 --- a/docs/MESA_swap_control.spec +++ b/docs/MESA_swap_control.spec @@ -43,7 +43,7 @@ Issues New Procedures and Functions - int glXSwapIntervalMESA(int interval) + int glXSwapIntervalMESA(unsigned int interval) int glXGetSwapIntervalMESA(void) New Tokens @@ -103,11 +103,8 @@ Additions to the GLX 1.3 Specification Errors - glXSwapIntervalMESA returns GLX_BAD_VALUE if parameter is - less than zero. - glXSwapIntervalMESA returns GLX_BAD_CONTEXT if there is no current - GLXContext. + GLXContext or if the current context is not a direct rendering context. GLX Protocol diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c index 19538f2e5c0..c429545f99a 100644 --- a/src/glx/glxcmds.c +++ b/src/glx/glxcmds.c @@ -1951,10 +1951,6 @@ __glXSwapIntervalMESA(unsigned int interval) { GLXContext gc = __glXGetCurrentContext(); - if (interval < 0) { - return GLX_BAD_VALUE; - } - #ifdef __DRI_SWAP_CONTROL if (gc != NULL && gc->driContext) { __GLXscreenConfigs *const psc = GetGLXScreenConfigs(gc->currentDpy, -- cgit v1.2.3 From 8bffadbc83d19ecd8be8f0107d51463e36477666 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 4 Feb 2010 16:28:52 -0800 Subject: glx: Pass opcode to CreateContext instead of use_glx_1_3 parameter Passing the opcode directly instead of having CreateContext infer it from the value of fbconfig and the use_glx_1_3 flag will simplify some changes that are coming. --- src/glx/glxcmds.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c index c429545f99a..e3f77a08410 100644 --- a/src/glx/glxcmds.c +++ b/src/glx/glxcmds.c @@ -366,7 +366,7 @@ CreateContext(Display * dpy, XVisualInfo * vis, const __GLcontextModes * const fbconfig, GLXContext shareList, Bool allowDirect, GLXContextID contextID, - Bool use_glx_1_3, int renderType) + unsigned code, int renderType) { GLXContext gc; #ifdef GLX_DIRECT_RENDERING @@ -425,7 +425,8 @@ CreateContext(Display * dpy, XVisualInfo * vis, #endif LockDisplay(dpy); - if (fbconfig == NULL) { + switch (code) { + case X_GLXCreateContext: { xGLXCreateContextReq *req; /* Send the glXCreateContext request */ @@ -437,8 +438,10 @@ CreateContext(Display * dpy, XVisualInfo * vis, req->screen = vis->screen; req->shareList = shareList ? shareList->xid : None; req->isDirect = GC_IS_DIRECT(gc); + break; } - else if (use_glx_1_3) { + + case X_GLXCreateNewContext: { xGLXCreateNewContextReq *req; /* Send the glXCreateNewContext request */ @@ -451,8 +454,10 @@ CreateContext(Display * dpy, XVisualInfo * vis, req->renderType = renderType; req->shareList = shareList ? shareList->xid : None; req->isDirect = GC_IS_DIRECT(gc); + break; } - else { + + case X_GLXvop_CreateContextWithConfigSGIX: { xGLXVendorPrivateWithReplyReq *vpreq; xGLXCreateContextWithConfigSGIXReq *req; @@ -470,6 +475,14 @@ CreateContext(Display * dpy, XVisualInfo * vis, req->renderType = renderType; req->shareList = shareList ? shareList->xid : None; req->isDirect = GC_IS_DIRECT(gc); + break; + } + + default: + /* What to do here? This case is the sign of an internal error. It + * should never be reachable. + */ + break; } UnlockDisplay(dpy); @@ -491,7 +504,7 @@ glXCreateContext(Display * dpy, XVisualInfo * vis, GLXContext shareList, Bool allowDirect) { return CreateContext(dpy, vis, NULL, shareList, allowDirect, None, - False, 0); + X_GLXCreateContext, 0); } _X_HIDDEN void @@ -1740,7 +1753,8 @@ glXImportContextEXT(Display * dpy, GLXContextID contextID) return NULL; } - ctx = CreateContext(dpy, NULL, NULL, NULL, False, contextID, False, 0); + ctx = CreateContext(dpy, NULL, NULL, NULL, False, contextID, + X_GLXCreateContext, 0); if (NULL != ctx) { if (Success != __glXQueryContextInfo(dpy, ctx)) { return NULL; @@ -1790,7 +1804,7 @@ glXCreateNewContext(Display * dpy, GLXFBConfig config, int renderType, GLXContext shareList, Bool allowDirect) { return CreateContext(dpy, NULL, (__GLcontextModes *) config, shareList, - allowDirect, None, True, renderType); + allowDirect, None, X_GLXCreateNewContext, renderType); } @@ -2278,7 +2292,8 @@ glXCreateContextWithConfigSGIX(Display * dpy, if ((psc != NULL) && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)) { gc = CreateContext(dpy, NULL, (__GLcontextModes *) config, shareList, - allowDirect, None, False, renderType); + allowDirect, None, + X_GLXvop_CreateContextWithConfigSGIX, renderType); } return gc; -- cgit v1.2.3 From 7bcfb66000557a0ef32bdc6b31949a92f95a9ff6 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 4 Feb 2010 16:37:59 -0800 Subject: glx: Pass screen number as parameter to CreateContext Passing the screen parameter to CreateContext will simplify a couple of changes that are coming. --- src/glx/glxcmds.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c index e3f77a08410..2eee005db64 100644 --- a/src/glx/glxcmds.c +++ b/src/glx/glxcmds.c @@ -366,12 +366,13 @@ CreateContext(Display * dpy, XVisualInfo * vis, const __GLcontextModes * const fbconfig, GLXContext shareList, Bool allowDirect, GLXContextID contextID, - unsigned code, int renderType) + unsigned code, int renderType, int screen) { GLXContext gc; #ifdef GLX_DIRECT_RENDERING - int screen = (fbconfig == NULL) ? vis->screen : fbconfig->screen; __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen); +#else + (void) screen; #endif if (dpy == NULL) @@ -504,7 +505,7 @@ glXCreateContext(Display * dpy, XVisualInfo * vis, GLXContext shareList, Bool allowDirect) { return CreateContext(dpy, vis, NULL, shareList, allowDirect, None, - X_GLXCreateContext, 0); + X_GLXCreateContext, 0, vis->screen); } _X_HIDDEN void @@ -1753,8 +1754,11 @@ glXImportContextEXT(Display * dpy, GLXContextID contextID) return NULL; } + /* FIXME: Why does this call CreateContext? There is no protocol sent for + * FIXME: this function. + */ ctx = CreateContext(dpy, NULL, NULL, NULL, False, contextID, - X_GLXCreateContext, 0); + X_GLXCreateContext, 0, 0); if (NULL != ctx) { if (Success != __glXQueryContextInfo(dpy, ctx)) { return NULL; @@ -1803,8 +1807,12 @@ PUBLIC GLXContext glXCreateNewContext(Display * dpy, GLXFBConfig config, int renderType, GLXContext shareList, Bool allowDirect) { - return CreateContext(dpy, NULL, (__GLcontextModes *) config, shareList, - allowDirect, None, X_GLXCreateNewContext, renderType); + const __GLcontextModes *const fbconfig = + (const __GLcontextModes *const) config; + + return CreateContext(dpy, NULL, fbconfig, shareList, + allowDirect, None, X_GLXCreateNewContext, renderType, + fbconfig->screen); } @@ -2293,7 +2301,8 @@ glXCreateContextWithConfigSGIX(Display * dpy, && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)) { gc = CreateContext(dpy, NULL, (__GLcontextModes *) config, shareList, allowDirect, None, - X_GLXvop_CreateContextWithConfigSGIX, renderType); + X_GLXvop_CreateContextWithConfigSGIX, renderType, + fbconfig->screen); } return gc; -- cgit v1.2.3 From 2243029eeec9e31b92079ff0e8fafdc0315053d6 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 4 Feb 2010 16:43:46 -0800 Subject: glx: Handle imported contexts outside of CreateContext A long time ago I was a bit over-agressive in refactoring context creation into a single function. The creation code for glXImportContextEXT does not belong in CreateContext because it does not use any GLX protocol. The big if-statement for the import case routed around almost the entire function anyway. --- src/glx/glxcmds.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c index 2eee005db64..48f7049fb49 100644 --- a/src/glx/glxcmds.c +++ b/src/glx/glxcmds.c @@ -365,7 +365,7 @@ static GLXContext CreateContext(Display * dpy, XVisualInfo * vis, const __GLcontextModes * const fbconfig, GLXContext shareList, - Bool allowDirect, GLXContextID contextID, + Bool allowDirect, unsigned code, int renderType, int screen) { GLXContext gc; @@ -382,7 +382,6 @@ CreateContext(Display * dpy, XVisualInfo * vis, if (!gc) return NULL; - if (None == contextID) { if ((vis == NULL) && (fbconfig == NULL)) return NULL; @@ -489,11 +488,6 @@ CreateContext(Display * dpy, XVisualInfo * vis, UnlockDisplay(dpy); SyncHandle(); gc->imported = GL_FALSE; - } - else { - gc->xid = contextID; - gc->imported = GL_TRUE; - } gc->renderType = renderType; @@ -504,7 +498,7 @@ PUBLIC GLXContext glXCreateContext(Display * dpy, XVisualInfo * vis, GLXContext shareList, Bool allowDirect) { - return CreateContext(dpy, vis, NULL, shareList, allowDirect, None, + return CreateContext(dpy, vis, NULL, shareList, allowDirect, X_GLXCreateContext, 0, vis->screen); } @@ -1754,14 +1748,14 @@ glXImportContextEXT(Display * dpy, GLXContextID contextID) return NULL; } - /* FIXME: Why does this call CreateContext? There is no protocol sent for - * FIXME: this function. - */ - ctx = CreateContext(dpy, NULL, NULL, NULL, False, contextID, - X_GLXCreateContext, 0, 0); + ctx = AllocateGLXContext(dpy); if (NULL != ctx) { + ctx->xid = contextID; + ctx->imported = GL_TRUE; + if (Success != __glXQueryContextInfo(dpy, ctx)) { - return NULL; + __glXFreeContext(ctx); + ctx = NULL; } } return ctx; @@ -1811,7 +1805,7 @@ glXCreateNewContext(Display * dpy, GLXFBConfig config, (const __GLcontextModes *const) config; return CreateContext(dpy, NULL, fbconfig, shareList, - allowDirect, None, X_GLXCreateNewContext, renderType, + allowDirect, X_GLXCreateNewContext, renderType, fbconfig->screen); } @@ -2300,7 +2294,7 @@ glXCreateContextWithConfigSGIX(Display * dpy, if ((psc != NULL) && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)) { gc = CreateContext(dpy, NULL, (__GLcontextModes *) config, shareList, - allowDirect, None, + allowDirect, X_GLXvop_CreateContextWithConfigSGIX, renderType, fbconfig->screen); } -- cgit v1.2.3 From bc7b2f0dc33753f6d6b55bd4058e82ddf0997967 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 4 Feb 2010 16:46:46 -0800 Subject: glx: Re-indent CreateContext after the previous commit --- src/glx/glxcmds.c | 191 +++++++++++++++++++++++++++--------------------------- 1 file changed, 95 insertions(+), 96 deletions(-) diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c index 48f7049fb49..b08cad8435c 100644 --- a/src/glx/glxcmds.c +++ b/src/glx/glxcmds.c @@ -382,113 +382,112 @@ CreateContext(Display * dpy, XVisualInfo * vis, if (!gc) return NULL; - if ((vis == NULL) && (fbconfig == NULL)) - return NULL; + if ((vis == NULL) && (fbconfig == NULL)) + return NULL; #ifdef GLX_DIRECT_RENDERING - if (allowDirect && psc->driScreen) { - const __GLcontextModes *mode; - - if (fbconfig == NULL) { - mode = _gl_context_modes_find_visual(psc->visuals, vis->visualid); - if (mode == NULL) { - xError error; - - error.errorCode = BadValue; - error.resourceID = vis->visualid; - error.sequenceNumber = dpy->request; - error.type = X_Error; - error.majorCode = gc->majorOpcode; - error.minorCode = X_GLXCreateContext; - _XError(dpy, &error); - return None; - } - if (renderType == 0) { - /* Initialize renderType now */ - renderType = mode->rgbMode ? GLX_RGBA_TYPE : GLX_COLOR_INDEX_TYPE; - } - } - else { - mode = fbconfig; - } + if (allowDirect && psc->driScreen) { + const __GLcontextModes *mode; + + if (fbconfig == NULL) { + mode = _gl_context_modes_find_visual(psc->visuals, vis->visualid); + if (mode == NULL) { + xError error; + + error.errorCode = BadValue; + error.resourceID = vis->visualid; + error.sequenceNumber = dpy->request; + error.type = X_Error; + error.majorCode = gc->majorOpcode; + error.minorCode = X_GLXCreateContext; + _XError(dpy, &error); + return None; + } + if (renderType == 0) { + /* Initialize renderType now */ + renderType = mode->rgbMode ? GLX_RGBA_TYPE : GLX_COLOR_INDEX_TYPE; + } + } + else { + mode = fbconfig; + } - gc->driContext = psc->driScreen->createContext(psc, mode, gc, - shareList, - renderType); - if (gc->driContext != NULL) { - gc->screen = mode->screen; - gc->psc = psc; - gc->mode = mode; - gc->isDirect = GL_TRUE; - } + gc->driContext = psc->driScreen->createContext(psc, mode, gc, shareList, + renderType); + if (gc->driContext != NULL) { + gc->screen = mode->screen; + gc->psc = psc; + gc->mode = mode; + gc->isDirect = GL_TRUE; } + } #endif - LockDisplay(dpy); - switch (code) { - case X_GLXCreateContext: { - xGLXCreateContextReq *req; - - /* Send the glXCreateContext request */ - GetReq(GLXCreateContext, req); - req->reqType = gc->majorOpcode; - req->glxCode = X_GLXCreateContext; - req->context = gc->xid = XAllocID(dpy); - req->visual = vis->visualid; - req->screen = vis->screen; - req->shareList = shareList ? shareList->xid : None; - req->isDirect = GC_IS_DIRECT(gc); - break; - } + LockDisplay(dpy); + switch (code) { + case X_GLXCreateContext: { + xGLXCreateContextReq *req; + + /* Send the glXCreateContext request */ + GetReq(GLXCreateContext, req); + req->reqType = gc->majorOpcode; + req->glxCode = X_GLXCreateContext; + req->context = gc->xid = XAllocID(dpy); + req->visual = vis->visualid; + req->screen = vis->screen; + req->shareList = shareList ? shareList->xid : None; + req->isDirect = GC_IS_DIRECT(gc); + break; + } - case X_GLXCreateNewContext: { - xGLXCreateNewContextReq *req; - - /* Send the glXCreateNewContext request */ - GetReq(GLXCreateNewContext, req); - req->reqType = gc->majorOpcode; - req->glxCode = X_GLXCreateNewContext; - req->context = gc->xid = XAllocID(dpy); - req->fbconfig = fbconfig->fbconfigID; - req->screen = fbconfig->screen; - req->renderType = renderType; - req->shareList = shareList ? shareList->xid : None; - req->isDirect = GC_IS_DIRECT(gc); - break; - } + case X_GLXCreateNewContext: { + xGLXCreateNewContextReq *req; - case X_GLXvop_CreateContextWithConfigSGIX: { - xGLXVendorPrivateWithReplyReq *vpreq; - xGLXCreateContextWithConfigSGIXReq *req; - - /* Send the glXCreateNewContext request */ - GetReqExtra(GLXVendorPrivateWithReply, - sz_xGLXCreateContextWithConfigSGIXReq - - sz_xGLXVendorPrivateWithReplyReq, vpreq); - req = (xGLXCreateContextWithConfigSGIXReq *) vpreq; - req->reqType = gc->majorOpcode; - req->glxCode = X_GLXVendorPrivateWithReply; - req->vendorCode = X_GLXvop_CreateContextWithConfigSGIX; - req->context = gc->xid = XAllocID(dpy); - req->fbconfig = fbconfig->fbconfigID; - req->screen = fbconfig->screen; - req->renderType = renderType; - req->shareList = shareList ? shareList->xid : None; - req->isDirect = GC_IS_DIRECT(gc); - break; - } + /* Send the glXCreateNewContext request */ + GetReq(GLXCreateNewContext, req); + req->reqType = gc->majorOpcode; + req->glxCode = X_GLXCreateNewContext; + req->context = gc->xid = XAllocID(dpy); + req->fbconfig = fbconfig->fbconfigID; + req->screen = fbconfig->screen; + req->renderType = renderType; + req->shareList = shareList ? shareList->xid : None; + req->isDirect = GC_IS_DIRECT(gc); + break; + } - default: - /* What to do here? This case is the sign of an internal error. It - * should never be reachable. - */ - break; - } + case X_GLXvop_CreateContextWithConfigSGIX: { + xGLXVendorPrivateWithReplyReq *vpreq; + xGLXCreateContextWithConfigSGIXReq *req; - UnlockDisplay(dpy); - SyncHandle(); - gc->imported = GL_FALSE; + /* Send the glXCreateNewContext request */ + GetReqExtra(GLXVendorPrivateWithReply, + sz_xGLXCreateContextWithConfigSGIXReq - + sz_xGLXVendorPrivateWithReplyReq, vpreq); + req = (xGLXCreateContextWithConfigSGIXReq *) vpreq; + req->reqType = gc->majorOpcode; + req->glxCode = X_GLXVendorPrivateWithReply; + req->vendorCode = X_GLXvop_CreateContextWithConfigSGIX; + req->context = gc->xid = XAllocID(dpy); + req->fbconfig = fbconfig->fbconfigID; + req->screen = fbconfig->screen; + req->renderType = renderType; + req->shareList = shareList ? shareList->xid : None; + req->isDirect = GC_IS_DIRECT(gc); + break; + } + + default: + /* What to do here? This case is the sign of an internal error. It + * should never be reachable. + */ + break; + } + + UnlockDisplay(dpy); + SyncHandle(); + gc->imported = GL_FALSE; gc->renderType = renderType; return gc; -- cgit v1.2.3 From 52cf8db428909156b062f17a9e6251a38178dec3 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 4 Feb 2010 16:59:10 -0800 Subject: glx: Move work of converting a visual to an fbconfig For the direct rendering case, the DRI createContext function wants an fbconfig. When glXCreateContext is called, we have to convert the visual to an fbconfig. This work was done in CreateContext, but it makes more sense for it to be done in glXCreateContext. --- src/glx/glxcmds.c | 60 +++++++++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c index b08cad8435c..1be6ff39794 100644 --- a/src/glx/glxcmds.c +++ b/src/glx/glxcmds.c @@ -387,37 +387,12 @@ CreateContext(Display * dpy, XVisualInfo * vis, #ifdef GLX_DIRECT_RENDERING if (allowDirect && psc->driScreen) { - const __GLcontextModes *mode; - - if (fbconfig == NULL) { - mode = _gl_context_modes_find_visual(psc->visuals, vis->visualid); - if (mode == NULL) { - xError error; - - error.errorCode = BadValue; - error.resourceID = vis->visualid; - error.sequenceNumber = dpy->request; - error.type = X_Error; - error.majorCode = gc->majorOpcode; - error.minorCode = X_GLXCreateContext; - _XError(dpy, &error); - return None; - } - if (renderType == 0) { - /* Initialize renderType now */ - renderType = mode->rgbMode ? GLX_RGBA_TYPE : GLX_COLOR_INDEX_TYPE; - } - } - else { - mode = fbconfig; - } - - gc->driContext = psc->driScreen->createContext(psc, mode, gc, shareList, - renderType); + gc->driContext = psc->driScreen->createContext(psc, fbconfig, gc, + shareList, renderType); if (gc->driContext != NULL) { - gc->screen = mode->screen; + gc->screen = screen; gc->psc = psc; - gc->mode = mode; + gc->mode = fbconfig; gc->isDirect = GL_TRUE; } } @@ -497,8 +472,31 @@ PUBLIC GLXContext glXCreateContext(Display * dpy, XVisualInfo * vis, GLXContext shareList, Bool allowDirect) { - return CreateContext(dpy, vis, NULL, shareList, allowDirect, - X_GLXCreateContext, 0, vis->screen); + const __GLcontextModes *mode = NULL; + int renderType = 0; + +#ifdef GLX_DIRECT_RENDERING + __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, vis->screen); + + mode = _gl_context_modes_find_visual(psc->visuals, vis->visualid); + if (mode == NULL) { + xError error; + + error.errorCode = BadValue; + error.resourceID = vis->visualid; + error.sequenceNumber = dpy->request; + error.type = X_Error; + error.majorCode = __glXSetupForCommand(dpy); + error.minorCode = X_GLXCreateContext; + _XError(dpy, &error); + return None; + } + + renderType = mode->rgbMode ? GLX_RGBA_TYPE : GLX_COLOR_INDEX_TYPE; +#endif + + return CreateContext(dpy, vis, mode, shareList, allowDirect, + X_GLXCreateContext, renderType, vis->screen); } _X_HIDDEN void -- cgit v1.2.3 From c3db1d621e1f7c73006ed76855d31b1034bc3aef Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 4 Feb 2010 17:01:42 -0800 Subject: glx: Use the screen parameter everywhere instead of vis->screen, etc. --- src/glx/glxcmds.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c index 1be6ff39794..9b4a6da065c 100644 --- a/src/glx/glxcmds.c +++ b/src/glx/glxcmds.c @@ -371,8 +371,6 @@ CreateContext(Display * dpy, XVisualInfo * vis, GLXContext gc; #ifdef GLX_DIRECT_RENDERING __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen); -#else - (void) screen; #endif if (dpy == NULL) @@ -409,7 +407,7 @@ CreateContext(Display * dpy, XVisualInfo * vis, req->glxCode = X_GLXCreateContext; req->context = gc->xid = XAllocID(dpy); req->visual = vis->visualid; - req->screen = vis->screen; + req->screen = screen; req->shareList = shareList ? shareList->xid : None; req->isDirect = GC_IS_DIRECT(gc); break; @@ -424,7 +422,7 @@ CreateContext(Display * dpy, XVisualInfo * vis, req->glxCode = X_GLXCreateNewContext; req->context = gc->xid = XAllocID(dpy); req->fbconfig = fbconfig->fbconfigID; - req->screen = fbconfig->screen; + req->screen = screen; req->renderType = renderType; req->shareList = shareList ? shareList->xid : None; req->isDirect = GC_IS_DIRECT(gc); @@ -445,7 +443,7 @@ CreateContext(Display * dpy, XVisualInfo * vis, req->vendorCode = X_GLXvop_CreateContextWithConfigSGIX; req->context = gc->xid = XAllocID(dpy); req->fbconfig = fbconfig->fbconfigID; - req->screen = fbconfig->screen; + req->screen = screen; req->renderType = renderType; req->shareList = shareList ? shareList->xid : None; req->isDirect = GC_IS_DIRECT(gc); -- cgit v1.2.3 From d46d30f997c1718217545947ca4d80ec7d18e684 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 4 Feb 2010 17:06:18 -0800 Subject: glx: Pass fbconfig ID or visual ID to CreateContext Pass either the fbconfig ID or the visual ID, as appropriate, to CreateContext. Now CreateContext does not derefernce fbconfig or vis (which no longer exists as a parameter). --- src/glx/glxcmds.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c index 9b4a6da065c..706d63b36bb 100644 --- a/src/glx/glxcmds.c +++ b/src/glx/glxcmds.c @@ -362,7 +362,7 @@ AllocateGLXContext(Display * dpy) */ static GLXContext -CreateContext(Display * dpy, XVisualInfo * vis, +CreateContext(Display * dpy, int generic_id, const __GLcontextModes * const fbconfig, GLXContext shareList, Bool allowDirect, @@ -376,11 +376,11 @@ CreateContext(Display * dpy, XVisualInfo * vis, if (dpy == NULL) return NULL; - gc = AllocateGLXContext(dpy); - if (!gc) + if (generic_id == None) return NULL; - if ((vis == NULL) && (fbconfig == NULL)) + gc = AllocateGLXContext(dpy); + if (!gc) return NULL; #ifdef GLX_DIRECT_RENDERING @@ -406,7 +406,7 @@ CreateContext(Display * dpy, XVisualInfo * vis, req->reqType = gc->majorOpcode; req->glxCode = X_GLXCreateContext; req->context = gc->xid = XAllocID(dpy); - req->visual = vis->visualid; + req->visual = generic_id; req->screen = screen; req->shareList = shareList ? shareList->xid : None; req->isDirect = GC_IS_DIRECT(gc); @@ -421,7 +421,7 @@ CreateContext(Display * dpy, XVisualInfo * vis, req->reqType = gc->majorOpcode; req->glxCode = X_GLXCreateNewContext; req->context = gc->xid = XAllocID(dpy); - req->fbconfig = fbconfig->fbconfigID; + req->fbconfig = generic_id; req->screen = screen; req->renderType = renderType; req->shareList = shareList ? shareList->xid : None; @@ -442,7 +442,7 @@ CreateContext(Display * dpy, XVisualInfo * vis, req->glxCode = X_GLXVendorPrivateWithReply; req->vendorCode = X_GLXvop_CreateContextWithConfigSGIX; req->context = gc->xid = XAllocID(dpy); - req->fbconfig = fbconfig->fbconfigID; + req->fbconfig = generic_id; req->screen = screen; req->renderType = renderType; req->shareList = shareList ? shareList->xid : None; @@ -493,7 +493,7 @@ glXCreateContext(Display * dpy, XVisualInfo * vis, renderType = mode->rgbMode ? GLX_RGBA_TYPE : GLX_COLOR_INDEX_TYPE; #endif - return CreateContext(dpy, vis, mode, shareList, allowDirect, + return CreateContext(dpy, vis->visualid, mode, shareList, allowDirect, X_GLXCreateContext, renderType, vis->screen); } @@ -1799,7 +1799,7 @@ glXCreateNewContext(Display * dpy, GLXFBConfig config, const __GLcontextModes *const fbconfig = (const __GLcontextModes *const) config; - return CreateContext(dpy, NULL, fbconfig, shareList, + return CreateContext(dpy, fbconfig->fbconfigID, fbconfig, shareList, allowDirect, X_GLXCreateNewContext, renderType, fbconfig->screen); } @@ -2288,7 +2288,7 @@ glXCreateContextWithConfigSGIX(Display * dpy, psc = GetGLXScreenConfigs(dpy, fbconfig->screen); if ((psc != NULL) && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)) { - gc = CreateContext(dpy, NULL, (__GLcontextModes *) config, shareList, + gc = CreateContext(dpy, fbconfig->fbconfigID, fbconfig, shareList, allowDirect, X_GLXvop_CreateContextWithConfigSGIX, renderType, fbconfig->screen); -- cgit v1.2.3 From 6518f6037cfcab3783e913b5275f9045799e49b2 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Fri, 5 Feb 2010 16:14:27 -0800 Subject: glxgears_fbconfig: Use GLX 1.3 name for function poiner types --- progs/xdemos/glxgears_fbconfig.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/progs/xdemos/glxgears_fbconfig.c b/progs/xdemos/glxgears_fbconfig.c index 2dac00b75d1..316480c74d5 100644 --- a/progs/xdemos/glxgears_fbconfig.c +++ b/progs/xdemos/glxgears_fbconfig.c @@ -46,13 +46,9 @@ #include #include "pbutil.h" -/* I had to use the SGIX versions of these because for some reason glxext.h - * doesn't define the core versions if GLX_VERSION_1_3 is defined, and glx.h - * doesn't define them at all. One or both header files is clearly broken. - */ -static PFNGLXCHOOSEFBCONFIGSGIXPROC choose_fbconfig = NULL; -static PFNGLXGETVISUALFROMFBCONFIGSGIXPROC get_visual_from_fbconfig = NULL; -static PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC create_new_context = NULL; +static PFNGLXCHOOSEFBCONFIGPROC choose_fbconfig = NULL; +static PFNGLXGETVISUALFROMFBCONFIGPROC get_visual_from_fbconfig = NULL; +static PFNGLXCREATENEWCONTEXTPROC create_new_context = NULL; #define BENCHMARK @@ -359,20 +355,20 @@ init_fbconfig_functions(Display *dpy, int scrnum) ext_name, (ext_version_supported) ? "" : "not " ); if ( glx_1_3_supported ) { - choose_fbconfig = (PFNGLXCHOOSEFBCONFIGSGIXPROC) glXGetProcAddressARB( - (GLubyte *) "glXChooseFBConfig"); - get_visual_from_fbconfig = (PFNGLXGETVISUALFROMFBCONFIGSGIXPROC) glXGetProcAddressARB( - (GLubyte *) "glXGetVisualFromFBConfig"); - create_new_context = (PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC) glXGetProcAddressARB( - (GLubyte *) "glXCreateNewContext"); + choose_fbconfig = (PFNGLXCHOOSEFBCONFIGPROC) + glXGetProcAddressARB((GLubyte *) "glXChooseFBConfig"); + get_visual_from_fbconfig = (PFNGLXGETVISUALFROMFBCONFIGPROC) + glXGetProcAddressARB((GLubyte *) "glXGetVisualFromFBConfig"); + create_new_context = (PFNGLXCREATENEWCONTEXTPROC) + glXGetProcAddressARB((GLubyte *) "glXCreateNewContext"); } else if ( ext_version_supported ) { - choose_fbconfig = (PFNGLXCHOOSEFBCONFIGSGIXPROC) glXGetProcAddressARB( - (GLubyte *) "glXChooseFBConfigSGIX"); - get_visual_from_fbconfig = (PFNGLXGETVISUALFROMFBCONFIGSGIXPROC) glXGetProcAddressARB( - (GLubyte *) "glXGetVisualFromFBConfigSGIX"); - create_new_context = (PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC) glXGetProcAddressARB( - (GLubyte *) "glXCreateContextWithConfigSGIX"); + choose_fbconfig = (PFNGLXCHOOSEFBCONFIGPROC) + glXGetProcAddressARB((GLubyte *) "glXChooseFBConfigSGIX"); + get_visual_from_fbconfig = (PFNGLXGETVISUALFROMFBCONFIGPROC) + glXGetProcAddressARB((GLubyte *) "glXGetVisualFromFBConfigSGIX"); + create_new_context = (PFNGLXCREATENEWCONTEXTPROC) + glXGetProcAddressARB((GLubyte *) "glXCreateContextWithConfigSGIX"); } else { printf( "This demo requires either GLX 1.3 or %s be supported.\n", -- cgit v1.2.3 From 381d5e209815235911c4aab516037c868c8f695f Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Fri, 5 Feb 2010 19:12:22 -0800 Subject: glxgears_fbconfig: Use glXCreateWindow and glXDestroyWindow --- progs/xdemos/glxgears_fbconfig.c | 44 +++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/progs/xdemos/glxgears_fbconfig.c b/progs/xdemos/glxgears_fbconfig.c index 316480c74d5..36bf73138c9 100644 --- a/progs/xdemos/glxgears_fbconfig.c +++ b/progs/xdemos/glxgears_fbconfig.c @@ -49,6 +49,8 @@ static PFNGLXCHOOSEFBCONFIGPROC choose_fbconfig = NULL; static PFNGLXGETVISUALFROMFBCONFIGPROC get_visual_from_fbconfig = NULL; static PFNGLXCREATENEWCONTEXTPROC create_new_context = NULL; +static PFNGLXCREATEWINDOWPROC create_window = NULL; +static PFNGLXDESTROYWINDOWPROC destroy_window = NULL; #define BENCHMARK @@ -320,6 +322,26 @@ init(void) } +static GLXWindow +dummy_create_window(Display *dpy, GLXFBConfig config, Window win, + const int *attrib_list) +{ + (void) dpy; + (void) config; + (void) attrib_list; + + return (GLXWindow) win; +} + + +static void +dummy_destroy_window(Display *dpy, GLXWindow win) +{ + (void) dpy; + (void) win; +} + + /** * Initialize fbconfig related function pointers. */ @@ -361,6 +383,10 @@ init_fbconfig_functions(Display *dpy, int scrnum) glXGetProcAddressARB((GLubyte *) "glXGetVisualFromFBConfig"); create_new_context = (PFNGLXCREATENEWCONTEXTPROC) glXGetProcAddressARB((GLubyte *) "glXCreateNewContext"); + create_window = (PFNGLXCREATEWINDOWPROC) + glXGetProcAddressARB((GLubyte *) "glXCreateWindow"); + destroy_window = (PFNGLXDESTROYWINDOWPROC) + glXGetProcAddressARB((GLubyte *) "glXDestroyWindow"); } else if ( ext_version_supported ) { choose_fbconfig = (PFNGLXCHOOSEFBCONFIGPROC) @@ -369,6 +395,8 @@ init_fbconfig_functions(Display *dpy, int scrnum) glXGetProcAddressARB((GLubyte *) "glXGetVisualFromFBConfigSGIX"); create_new_context = (PFNGLXCREATENEWCONTEXTPROC) glXGetProcAddressARB((GLubyte *) "glXCreateContextWithConfigSGIX"); + create_window = dummy_create_window; + destroy_window = dummy_destroy_window; } else { printf( "This demo requires either GLX 1.3 or %s be supported.\n", @@ -400,7 +428,7 @@ init_fbconfig_functions(Display *dpy, int scrnum) static void make_window( Display *dpy, const char *name, int x, int y, int width, int height, - Window *winRet, GLXContext *ctxRet) + Window *winRet, GLXWindow *glxWinRet, GLXContext *ctxRet) { int attrib[] = { GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, GLX_RENDER_TYPE, GLX_RGBA_BIT, @@ -418,6 +446,7 @@ make_window( Display *dpy, const char *name, unsigned long mask; Window root; Window win; + GLXWindow glxWin; GLXContext ctx; XVisualInfo *visinfo; @@ -463,6 +492,8 @@ make_window( Display *dpy, const char *name, None, (char **)NULL, 0, &sizehints); } + glxWin = (*create_window)(dpy, fbconfig[0], win, NULL); + ctx = (*create_new_context)(dpy, fbconfig[0], GLX_RGBA_TYPE, NULL, GL_TRUE); if (!ctx) { printf("Error: glXCreateNewContext failed\n"); @@ -471,13 +502,14 @@ make_window( Display *dpy, const char *name, XFree(fbconfig); + *glxWinRet = glxWin; *winRet = win; *ctxRet = ctx; } static void -event_loop(Display *dpy, Window win) +event_loop(Display *dpy, GLXWindow win) { while (1) { while (XPending(dpy) > 0) { @@ -554,6 +586,7 @@ main(int argc, char *argv[]) { Display *dpy; Window win; + GLXWindow glxWin; GLXContext ctx; const char *dpyName = NULL; GLboolean printInfo = GL_FALSE; @@ -575,9 +608,9 @@ main(int argc, char *argv[]) return -1; } - make_window(dpy, "glxgears", 0, 0, 300, 300, &win, &ctx); + make_window(dpy, "glxgears", 0, 0, 300, 300, &win, &glxWin, &ctx); XMapWindow(dpy, win); - glXMakeCurrent(dpy, win, ctx); + glXMakeCurrent(dpy, glxWin, ctx); if (printInfo) { printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); @@ -588,9 +621,10 @@ main(int argc, char *argv[]) init(); - event_loop(dpy, win); + event_loop(dpy, glxWin); glXDestroyContext(dpy, ctx); + destroy_window(dpy, glxWin); XDestroyWindow(dpy, win); XCloseDisplay(dpy); -- cgit v1.2.3