X-Git-Url: https://git.libre-soc.org/?p=mesa.git;a=blobdiff_plain;f=src%2Fglx%2Fglxcurrent.c;h=a388df7a78dc9017f47448daa191ed1cb72a7bb8;hp=36317383544240ce1cbad2a423473dd126d30cd4;hb=22406da75671438bf9de68bc47e2b8871e5fa3e6;hpb=1218430e1200a08cd64b6555d3fd1fd0274ad9e5 diff --git a/src/glx/glxcurrent.c b/src/glx/glxcurrent.c index 36317383544..a388df7a78d 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 +#include "glx_error.h" /* ** We setup some dummy structures here so that the API can be used @@ -73,11 +65,9 @@ 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 ) +# if defined( USE_ELF_TLS ) /** * Per-thread GLX context pointer. @@ -142,33 +132,20 @@ __glXGetCurrentContext(void) return (v == NULL) ? &dummyContext : (struct glx_context *) v; } -# 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 +# endif /* defined( USE_ELF_TLS ) */ _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,28 +158,13 @@ glXGetCurrentContext(void) } } -_X_EXPORT GLXDrawable +_GLX_PUBLIC GLXDrawable glXGetCurrentDrawable(void) { struct glx_context *gc = __glXGetCurrentContext(); return gc->currentDrawable; } -static void -__glXGenerateError(Display * dpy, struct glx_context *gc, XID resource, - BYTE errorCode, CARD16 minorCode) -{ - xError error; - - error.errorCode = errorCode; - error.resourceID = resource; - error.sequenceNumber = dpy->request; - error.type = X_Error; - error.majorCode = gc->majorOpcode; - error.minorCode = minorCode; - _XError(dpy, &error); -} - /** * Make a particular context current. * @@ -214,7 +176,6 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw, { struct glx_context *gc = (struct glx_context *) gc_user; struct glx_context *oldGC = __glXGetCurrentContext(); - int ret = Success; /* 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 @@ -224,75 +185,82 @@ 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(); - if (gc != NULL && gc->thread_id != 0 && gc->thread_id != _glthread_GetID()) { - __glXGenerateError(dpy, gc, gc->xid, - BadAccess, X_GLXMakeContextCurrent); - return False; - } - + __glXLock(); if (oldGC == gc && - gc->currentDrawable == draw && gc->currentReadable == read) + gc->currentDrawable == draw && gc->currentReadable == read) { + __glXUnlock(); return True; + } + + /* can't have only one be 0 */ + if (!!draw != !!read) { + __glXUnlock(); + __glXSendError(dpy, BadMatch, None, X_GLXMakeContextCurrent, True); + return False; + } if (oldGC != &dummyContext) { - oldGC->vtable->unbind(oldGC, gc); - oldGC->currentDpy = 0; - oldGC->currentDrawable = None; - oldGC->currentReadable = None; - oldGC->thread_id = 0; + if (--oldGC->thread_refcount == 0) { + oldGC->vtable->unbind(oldGC, gc); + oldGC->currentDpy = 0; + } } if (gc) { - gc->currentDpy = dpy; - gc->currentDrawable = draw; - gc->currentReadable = read; - gc->thread_id = _glthread_GetID(); + /* 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(); + __glXSendError(dpy, GLXBadContext, None, X_GLXMakeContextCurrent, + False); + 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 != &dummyContext && oldGC->xid == None && oldGC != gc) { + 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); } - if (ret) { - __glXGenerateError(dpy, gc, None, ret, X_GLXMakeContextCurrent); - return GL_FALSE; - } + __glXUnlock(); 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)