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 <bernard.r.kilarski@intel.com>
Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
Signed-off-by: Tapani Pälli <tapani.palli@intel.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Cc: "11.2" <mesa-stable@lists.freedesktop.org>
This commit is contained in:
Bernard Kilarski
2016-06-07 13:33:33 +03:00
committed by Tapani Pälli
parent 312ece9cd7
commit 2e3f067458
5 changed files with 33 additions and 20 deletions

View File

@@ -43,7 +43,7 @@ __glXSendError(Display * dpy, int_fast8_t errorCode, uint_fast32_t resourceID,
xError error; xError error;
assert(glx_dpy); assert(glx_dpy);
assert(gc); assert(gc != &dummyContext);
LockDisplay(dpy); LockDisplay(dpy);

View File

@@ -328,7 +328,7 @@ GetDrawableAttribute(Display * dpy, GLXDrawable drawable,
* the calling thread's current context a GLXBadDrawable error is * the calling thread's current context a GLXBadDrawable error is
* generated." * generated."
*/ */
if (pdraw == NULL || gc == NULL || gc->currentDpy != dpy || if (pdraw == NULL || gc == &dummyContext || gc->currentDpy != dpy ||
(gc->currentDrawable != drawable && (gc->currentDrawable != drawable &&
gc->currentReadable != drawable)) { gc->currentReadable != drawable)) {
__glXSendError(dpy, GLXBadDrawable, drawable, __glXSendError(dpy, GLXBadDrawable, drawable,

View File

@@ -524,7 +524,7 @@ glXWaitGL(void)
{ {
struct glx_context *gc = __glXGetCurrentContext(); struct glx_context *gc = __glXGetCurrentContext();
if (gc && gc->vtable->wait_gl) if (gc != &dummyContext && gc->vtable->wait_gl)
gc->vtable->wait_gl(gc); gc->vtable->wait_gl(gc);
} }
@@ -537,7 +537,7 @@ glXWaitX(void)
{ {
struct glx_context *gc = __glXGetCurrentContext(); struct glx_context *gc = __glXGetCurrentContext();
if (gc && gc->vtable->wait_x) if (gc != &dummyContext && gc->vtable->wait_x)
gc->vtable->wait_x(gc); gc->vtable->wait_x(gc);
} }
@@ -546,7 +546,7 @@ glXUseXFont(Font font, int first, int count, int listBase)
{ {
struct glx_context *gc = __glXGetCurrentContext(); 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); gc->vtable->use_x_font(gc, font, first, count, listBase);
} }
@@ -838,7 +838,7 @@ glXSwapBuffers(Display * dpy, GLXDrawable drawable)
__GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable); __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
if (pdraw != NULL) { 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); (*pdraw->psc->driScreen->swapBuffers)(pdraw, 0, 0, 0, flush);
return; return;
@@ -855,7 +855,7 @@ glXSwapBuffers(Display * dpy, GLXDrawable drawable)
** The calling thread may or may not have a current context. If it ** 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. ** 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->currentDrawable)
|| (drawable == gc->currentReadable))) { || (drawable == gc->currentReadable))) {
tag = gc->currentContextTag; tag = gc->currentContextTag;
@@ -1388,7 +1388,7 @@ _GLX_PUBLIC Display *
glXGetCurrentDisplay(void) glXGetCurrentDisplay(void)
{ {
struct glx_context *gc = __glXGetCurrentContext(); struct glx_context *gc = __glXGetCurrentContext();
if (NULL == gc) if (gc == &dummyContext)
return NULL; return NULL;
return gc->currentDpy; return gc->currentDpy;
} }
@@ -1751,7 +1751,7 @@ __glXSwapIntervalSGI(int interval)
CARD32 *interval_ptr; CARD32 *interval_ptr;
CARD8 opcode; CARD8 opcode;
if (gc == NULL) { if (gc == &dummyContext) {
return GLX_BAD_CONTEXT; return GLX_BAD_CONTEXT;
} }
@@ -1805,7 +1805,7 @@ __glXSwapIntervalMESA(unsigned int interval)
#ifdef GLX_DIRECT_RENDERING #ifdef GLX_DIRECT_RENDERING
struct glx_context *gc = __glXGetCurrentContext(); struct glx_context *gc = __glXGetCurrentContext();
if (gc != NULL && gc->isDirect) { if (gc != &dummyContext && gc->isDirect) {
struct glx_screen *psc; struct glx_screen *psc;
psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen); psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
@@ -1827,7 +1827,7 @@ __glXGetSwapIntervalMESA(void)
#ifdef GLX_DIRECT_RENDERING #ifdef GLX_DIRECT_RENDERING
struct glx_context *gc = __glXGetCurrentContext(); struct glx_context *gc = __glXGetCurrentContext();
if (gc != NULL && gc->isDirect) { if (gc != &dummyContext && gc->isDirect) {
struct glx_screen *psc; struct glx_screen *psc;
psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen); psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
@@ -1857,7 +1857,7 @@ __glXGetVideoSyncSGI(unsigned int *count)
__GLXDRIdrawable *pdraw; __GLXDRIdrawable *pdraw;
#endif #endif
if (!gc) if (gc == &dummyContext)
return GLX_BAD_CONTEXT; return GLX_BAD_CONTEXT;
#ifdef GLX_DIRECT_RENDERING #ifdef GLX_DIRECT_RENDERING
@@ -1899,7 +1899,7 @@ __glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
if (divisor <= 0 || remainder < 0) if (divisor <= 0 || remainder < 0)
return GLX_BAD_VALUE; return GLX_BAD_VALUE;
if (!gc) if (gc == &dummyContext)
return GLX_BAD_CONTEXT; return GLX_BAD_CONTEXT;
#ifdef GLX_DIRECT_RENDERING #ifdef GLX_DIRECT_RENDERING
@@ -2212,7 +2212,7 @@ __glXSwapBuffersMscOML(Display * dpy, GLXDrawable drawable,
struct glx_screen *psc = pdraw ? pdraw->psc : NULL; struct glx_screen *psc = pdraw ? pdraw->psc : NULL;
#endif #endif
if (!gc) /* no GLX for this */ if (gc == &dummyContext) /* no GLX for this */
return -1; return -1;
#ifdef GLX_DIRECT_RENDERING #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. ** does, send the context tag so the server can do a flush.
*/ */
gc = __glXGetCurrentContext(); gc = __glXGetCurrentContext();
if ((gc != NULL) && (dpy == gc->currentDpy) && if ((gc != &dummyContext) && (dpy == gc->currentDpy) &&
((drawable == gc->currentDrawable) || ((drawable == gc->currentDrawable) ||
(drawable == gc->currentReadable))) { (drawable == gc->currentReadable))) {
tag = gc->currentContextTag; tag = gc->currentContextTag;
@@ -2431,7 +2431,7 @@ __glXBindTexImageEXT(Display * dpy,
{ {
struct glx_context *gc = __glXGetCurrentContext(); struct glx_context *gc = __glXGetCurrentContext();
if (gc == NULL || gc->vtable->bind_tex_image == NULL) if (gc == &dummyContext || gc->vtable->bind_tex_image == NULL)
return; return;
gc->vtable->bind_tex_image(dpy, drawable, buffer, attrib_list); 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(); struct glx_context *gc = __glXGetCurrentContext();
if (gc == NULL || gc->vtable->release_tex_image == NULL) if (gc == &dummyContext || gc->vtable->release_tex_image == NULL)
return; return;
gc->vtable->release_tex_image(dpy, drawable, buffer); gc->vtable->release_tex_image(dpy, drawable, buffer);

View File

@@ -106,7 +106,7 @@ glXQueryCurrentRendererIntegerMESA(int attribute, unsigned int *value)
{ {
struct glx_context *gc = __glXGetCurrentContext(); struct glx_context *gc = __glXGetCurrentContext();
if (gc == NULL) if (gc == &dummyContext)
return False; return False;
return __glXQueryRendererInteger(gc->psc, attribute, value); return __glXQueryRendererInteger(gc->psc, attribute, value);
@@ -166,7 +166,7 @@ glXQueryCurrentRendererStringMESA(int attribute)
{ {
struct glx_context *gc = __glXGetCurrentContext(); struct glx_context *gc = __glXGetCurrentContext();
if (gc == NULL) if (gc == &dummyContext)
return False; return False;
return __glXQueryRendererString(gc->psc, attribute); return __glXQueryRendererString(gc->psc, attribute);

View File

@@ -75,7 +75,20 @@ indirect_create_context_attribs(struct glx_screen *base,
return indirect_create_context(base, config_base, shareList, 0); 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) #if !defined(GLX_USE_TLS)
extern "C" struct glx_context * extern "C" struct glx_context *