X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fglx%2Fglxcurrent.c;h=d1193265f904986ea88f681a9f63545aa6c68eae;hb=b2c6290b0140797d0e12dd5b358292289d43edc4;hp=9a6499037b17dd8fa56727ee0c54480c08891ce2;hpb=49d7e48b33264d94e30af6129c281b6acafa9427;p=mesa.git diff --git a/src/glx/glxcurrent.c b/src/glx/glxcurrent.c index 9a6499037b1..d1193265f90 100644 --- a/src/glx/glxcurrent.c +++ b/src/glx/glxcurrent.c @@ -33,19 +33,11 @@ * Client-side GLX interface for current context management. */ -#ifdef PTHREADS #include -#endif #include "glxclient.h" -#ifdef GLX_USE_APPLEGL -#include -#include "apple_glx.h" -#include "apple_glx_context.h" -#else #include "glapi.h" -#endif /* ** We setup some dummy structures here so that the API can be used @@ -73,8 +65,6 @@ struct glx_context dummyContext = { * Current context management and locking */ -#if defined( PTHREADS ) - _X_HIDDEN pthread_mutex_t __glXmutex = PTHREAD_MUTEX_INITIALIZER; # if defined( GLX_USE_TLS ) @@ -144,31 +134,18 @@ __glXGetCurrentContext(void) # endif /* defined( GLX_USE_TLS ) */ -#elif defined( THREADS ) - -#error Unknown threading method specified. - -#else - -/* not thread safe */ -_X_HIDDEN struct glx_context *__glXcurrentContext = &dummyContext; - -#endif - _X_HIDDEN void __glXSetCurrentContextNull(void) { __glXSetCurrentContext(&dummyContext); -#ifndef GLX_USE_APPLEGL -#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) +#if defined(GLX_DIRECT_RENDERING) _glapi_set_dispatch(NULL); /* no-op functions */ _glapi_set_context(NULL); #endif -#endif } -_X_EXPORT GLXContext +_GLX_PUBLIC GLXContext glXGetCurrentContext(void) { struct glx_context *cx = __glXGetCurrentContext(); @@ -181,7 +158,7 @@ glXGetCurrentContext(void) } } -_X_EXPORT GLXDrawable +_GLX_PUBLIC GLXDrawable glXGetCurrentDrawable(void) { struct glx_context *gc = __glXGetCurrentContext(); @@ -189,7 +166,7 @@ glXGetCurrentDrawable(void) } static void -__glXGenerateError(Display * dpy, struct glx_context *gc, XID resource, +__glXGenerateError(Display * dpy, XID resource, BYTE errorCode, CARD16 minorCode) { xError error; @@ -198,7 +175,7 @@ __glXGenerateError(Display * dpy, struct glx_context *gc, XID resource, error.resourceID = resource; error.sequenceNumber = dpy->request; error.type = X_Error; - error.majorCode = gc->majorOpcode; + error.majorCode = __glXSetupForCommand(dpy); error.minorCode = minorCode; _XError(dpy, &error); } @@ -214,17 +191,6 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw, { struct glx_context *gc = (struct glx_context *) gc_user; struct glx_context *oldGC = __glXGetCurrentContext(); - int ret = Success; - - /* XXX: If this is left out, then libGL ends up not having this - * symbol, and drivers using it fail to load. Compare the - * implementation of this symbol to _glapi_noop_enable_warnings(), - * though, which gets into the library despite no callers, the same - * prototypes, and the same compile flags to the files containing - * them. Moving the definition to glapi_nop.c gets it into the - * library, though. - */ - (void)_glthread_GetID(); /* Make sure that the new context has a nonzero ID. In the request, * a zero context ID is used only to mean that we bind to no current @@ -234,16 +200,6 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw, return GL_FALSE; } - if (gc == NULL && (draw != None || read != None)) { - __glXGenerateError(dpy, gc, (draw != None) ? draw : read, - BadMatch, X_GLXMakeContextCurrent); - return False; - } - if (gc != NULL && (draw == None || read == None)) { - __glXGenerateError(dpy, gc, None, BadMatch, X_GLXMakeContextCurrent); - return False; - } - _glapi_check_multithread(); __glXLock(); @@ -257,53 +213,73 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw, if (--oldGC->thread_refcount == 0) { oldGC->vtable->unbind(oldGC, gc); oldGC->currentDpy = 0; - oldGC->currentDrawable = None; - oldGC->currentReadable = None; - - if (oldGC->xid == None && oldGC != gc) { - /* We are switching away from a context that was - * previously destroyed, so we need to free the memory - * for the old handle. */ - oldGC->vtable->destroy(oldGC); - } } } if (gc) { - if (gc->thread_refcount++ == 0) { - gc->currentDpy = dpy; - gc->currentDrawable = draw; - gc->currentReadable = read; + /* Attempt to bind the context. We do this before mucking with + * gc and __glXSetCurrentContext to properly handle our state in + * case of an error. + * + * If an error occurs, set the Null context since we've already + * blown away our old context. The caller is responsible for + * figuring out how to handle setting a valid context. + */ + if (gc->vtable->bind(gc, oldGC, draw, read) != Success) { + __glXSetCurrentContextNull(); + __glXUnlock(); + __glXGenerateError(dpy, None, GLXBadContext, X_GLXMakeContextCurrent); + return GL_FALSE; + } + + if (gc->thread_refcount == 0) { + gc->currentDpy = dpy; + gc->currentDrawable = draw; + gc->currentReadable = read; } + gc->thread_refcount++; __glXSetCurrentContext(gc); - ret = gc->vtable->bind(gc, oldGC, draw, read); } else { __glXSetCurrentContextNull(); } + if (oldGC->thread_refcount == 0 && oldGC != &dummyContext && oldGC->xid == None) { + /* We are switching away from a context that was + * previously destroyed, so we need to free the memory + * for the old handle. */ + oldGC->vtable->destroy(oldGC); + } + __glXUnlock(); - if (ret) { - __glXGenerateError(dpy, gc, None, ret, X_GLXMakeContextCurrent); - return GL_FALSE; + /* The indirect vertex array state must to be initialised after we + * have setup the context, as it needs to query server attributes. + */ + if (gc && !gc->isDirect) { + __GLXattribute *state = gc->client_state_private; + if (state && state->array_state == NULL) { + glGetString(GL_EXTENSIONS); + glGetString(GL_VERSION); + __glXInitVertexArrayState(gc); + } } return GL_TRUE; } -_X_EXPORT Bool +_GLX_PUBLIC Bool glXMakeCurrent(Display * dpy, GLXDrawable draw, GLXContext gc) { return MakeContextCurrent(dpy, draw, draw, gc); } -_X_EXPORT +_GLX_PUBLIC GLX_ALIAS(Bool, glXMakeCurrentReadSGI, (Display * dpy, GLXDrawable d, GLXDrawable r, GLXContext ctx), (dpy, d, r, ctx), MakeContextCurrent) -_X_EXPORT +_GLX_PUBLIC GLX_ALIAS(Bool, glXMakeContextCurrent, (Display * dpy, GLXDrawable d, GLXDrawable r, GLXContext ctx), (dpy, d, r, ctx), MakeContextCurrent)