From: Bernard Kilarski Date: Tue, 7 Jun 2016 10:33:33 +0000 (+0300) Subject: glx: fix error code when there is no context bound X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2e3f067458e4a70da91b27fab61ef3d292ded4cf;p=mesa.git glx: fix error code when there is no context bound v2: change all related NULL checks to check against dummyContext v3: really check for dummyContext *only* when ctx was from __glXGetCurrentContext v4: cover more checks, add dummyBuffer, dummyVtable (Emil) Signed-off-by: Bernard Kilarski Signed-off-by: Matt Roper Signed-off-by: Tapani Pälli Reviewed-by: Emil Velikov Cc: "11.2" --- diff --git a/src/glx/glx_error.c b/src/glx/glx_error.c index b3860db2e37..e098682dd75 100644 --- a/src/glx/glx_error.c +++ b/src/glx/glx_error.c @@ -43,7 +43,7 @@ __glXSendError(Display * dpy, int_fast8_t errorCode, uint_fast32_t resourceID, xError error; assert(glx_dpy); - assert(gc); + assert(gc != &dummyContext); LockDisplay(dpy); diff --git a/src/glx/glx_pbuffer.c b/src/glx/glx_pbuffer.c index a0c1e3d9809..24c073cb9ba 100644 --- a/src/glx/glx_pbuffer.c +++ b/src/glx/glx_pbuffer.c @@ -328,7 +328,7 @@ GetDrawableAttribute(Display * dpy, GLXDrawable drawable, * the calling thread's current context a GLXBadDrawable error is * generated." */ - if (pdraw == NULL || gc == NULL || gc->currentDpy != dpy || + if (pdraw == NULL || gc == &dummyContext || gc->currentDpy != dpy || (gc->currentDrawable != drawable && gc->currentReadable != drawable)) { __glXSendError(dpy, GLXBadDrawable, drawable, diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c index 3856032ce68..8191da03616 100644 --- a/src/glx/glxcmds.c +++ b/src/glx/glxcmds.c @@ -524,7 +524,7 @@ glXWaitGL(void) { struct glx_context *gc = __glXGetCurrentContext(); - if (gc && gc->vtable->wait_gl) + if (gc != &dummyContext && gc->vtable->wait_gl) gc->vtable->wait_gl(gc); } @@ -537,7 +537,7 @@ glXWaitX(void) { struct glx_context *gc = __glXGetCurrentContext(); - if (gc && gc->vtable->wait_x) + if (gc != &dummyContext && gc->vtable->wait_x) gc->vtable->wait_x(gc); } @@ -546,7 +546,7 @@ glXUseXFont(Font font, int first, int count, int listBase) { struct glx_context *gc = __glXGetCurrentContext(); - if (gc && gc->vtable->use_x_font) + if (gc != &dummyContext && gc->vtable->use_x_font) gc->vtable->use_x_font(gc, font, first, count, listBase); } @@ -838,7 +838,7 @@ glXSwapBuffers(Display * dpy, GLXDrawable drawable) __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable); if (pdraw != NULL) { - Bool flush = gc && drawable == gc->currentDrawable; + Bool flush = gc != &dummyContext && drawable == gc->currentDrawable; (*pdraw->psc->driScreen->swapBuffers)(pdraw, 0, 0, 0, flush); return; @@ -855,7 +855,7 @@ glXSwapBuffers(Display * dpy, GLXDrawable drawable) ** The calling thread may or may not have a current context. If it ** does, send the context tag so the server can do a flush. */ - if ((gc != NULL) && (dpy == gc->currentDpy) && + if ((gc != &dummyContext) && (dpy == gc->currentDpy) && ((drawable == gc->currentDrawable) || (drawable == gc->currentReadable))) { tag = gc->currentContextTag; @@ -1388,7 +1388,7 @@ _GLX_PUBLIC Display * glXGetCurrentDisplay(void) { struct glx_context *gc = __glXGetCurrentContext(); - if (NULL == gc) + if (gc == &dummyContext) return NULL; return gc->currentDpy; } @@ -1751,7 +1751,7 @@ __glXSwapIntervalSGI(int interval) CARD32 *interval_ptr; CARD8 opcode; - if (gc == NULL) { + if (gc == &dummyContext) { return GLX_BAD_CONTEXT; } @@ -1805,7 +1805,7 @@ __glXSwapIntervalMESA(unsigned int interval) #ifdef GLX_DIRECT_RENDERING struct glx_context *gc = __glXGetCurrentContext(); - if (gc != NULL && gc->isDirect) { + if (gc != &dummyContext && gc->isDirect) { struct glx_screen *psc; psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen); @@ -1827,7 +1827,7 @@ __glXGetSwapIntervalMESA(void) #ifdef GLX_DIRECT_RENDERING struct glx_context *gc = __glXGetCurrentContext(); - if (gc != NULL && gc->isDirect) { + if (gc != &dummyContext && gc->isDirect) { struct glx_screen *psc; psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen); @@ -1857,7 +1857,7 @@ __glXGetVideoSyncSGI(unsigned int *count) __GLXDRIdrawable *pdraw; #endif - if (!gc) + if (gc == &dummyContext) return GLX_BAD_CONTEXT; #ifdef GLX_DIRECT_RENDERING @@ -1899,7 +1899,7 @@ __glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count) if (divisor <= 0 || remainder < 0) return GLX_BAD_VALUE; - if (!gc) + if (gc == &dummyContext) return GLX_BAD_CONTEXT; #ifdef GLX_DIRECT_RENDERING @@ -2212,7 +2212,7 @@ __glXSwapBuffersMscOML(Display * dpy, GLXDrawable drawable, struct glx_screen *psc = pdraw ? pdraw->psc : NULL; #endif - if (!gc) /* no GLX for this */ + if (gc == &dummyContext) /* no GLX for this */ return -1; #ifdef GLX_DIRECT_RENDERING @@ -2392,7 +2392,7 @@ __glXCopySubBufferMESA(Display * dpy, GLXDrawable drawable, ** does, send the context tag so the server can do a flush. */ gc = __glXGetCurrentContext(); - if ((gc != NULL) && (dpy == gc->currentDpy) && + if ((gc != &dummyContext) && (dpy == gc->currentDpy) && ((drawable == gc->currentDrawable) || (drawable == gc->currentReadable))) { tag = gc->currentContextTag; @@ -2431,7 +2431,7 @@ __glXBindTexImageEXT(Display * dpy, { struct glx_context *gc = __glXGetCurrentContext(); - if (gc == NULL || gc->vtable->bind_tex_image == NULL) + if (gc == &dummyContext || gc->vtable->bind_tex_image == NULL) return; gc->vtable->bind_tex_image(dpy, drawable, buffer, attrib_list); @@ -2442,7 +2442,7 @@ __glXReleaseTexImageEXT(Display * dpy, GLXDrawable drawable, int buffer) { struct glx_context *gc = __glXGetCurrentContext(); - if (gc == NULL || gc->vtable->release_tex_image == NULL) + if (gc == &dummyContext || gc->vtable->release_tex_image == NULL) return; gc->vtable->release_tex_image(dpy, drawable, buffer); diff --git a/src/glx/query_renderer.c b/src/glx/query_renderer.c index 9108ec23af5..4debf0665f8 100644 --- a/src/glx/query_renderer.c +++ b/src/glx/query_renderer.c @@ -106,7 +106,7 @@ glXQueryCurrentRendererIntegerMESA(int attribute, unsigned int *value) { struct glx_context *gc = __glXGetCurrentContext(); - if (gc == NULL) + if (gc == &dummyContext) return False; return __glXQueryRendererInteger(gc->psc, attribute, value); @@ -166,7 +166,7 @@ glXQueryCurrentRendererStringMESA(int attribute) { struct glx_context *gc = __glXGetCurrentContext(); - if (gc == NULL) + if (gc == &dummyContext) return False; return __glXQueryRendererString(gc->psc, attribute); diff --git a/src/glx/tests/fake_glx_screen.cpp b/src/glx/tests/fake_glx_screen.cpp index db20749505c..801f54a6faa 100644 --- a/src/glx/tests/fake_glx_screen.cpp +++ b/src/glx/tests/fake_glx_screen.cpp @@ -75,7 +75,20 @@ indirect_create_context_attribs(struct glx_screen *base, return indirect_create_context(base, config_base, shareList, 0); } -__thread void *__glX_tls_Context = NULL; +/* This is necessary so that we don't have to link with glxcurrent.c + * which would require us to link with X libraries and what not. + */ +GLubyte dummyBuffer[__GLX_BUFFER_LIMIT_SIZE]; +struct glx_context_vtable dummyVtable; +struct glx_context dummyContext = { + &dummyBuffer[0], + &dummyBuffer[0], + &dummyBuffer[0], + &dummyBuffer[__GLX_BUFFER_LIMIT_SIZE], + sizeof(dummyBuffer), + &dummyVtable +}; +__thread void *__glX_tls_Context = &dummyContext; #if !defined(GLX_USE_TLS) extern "C" struct glx_context *