diff options
Diffstat (limited to 'src/glx/glxcurrent.c')
-rw-r--r-- | src/glx/glxcurrent.c | 69 |
1 files changed, 56 insertions, 13 deletions
diff --git a/src/glx/glxcurrent.c b/src/glx/glxcurrent.c index c28360bdde9..691e8dfadf2 100644 --- a/src/glx/glxcurrent.c +++ b/src/glx/glxcurrent.c @@ -33,9 +33,20 @@ * Client-side GLX interface for current context management. */ +#ifdef PTHREADS +#include <pthread.h> +#endif + #include "glxclient.h" +#ifdef GLX_USE_APPLEGL +#include <stdlib.h> + +#include "apple_glx.h" +#include "apple_glx_context.h" +#else #include "glapi.h" #include "indirect_init.h" +#endif /* ** We setup some dummy structures here so that the API can be used @@ -59,11 +70,12 @@ static __GLXcontext dummyContext = { }; +#ifndef GLX_USE_APPLEGL /* ** All indirect rendering contexts will share the same indirect dispatch table. */ static __GLapi *IndirectAPI = NULL; - +#endif /* * Current context management and locking @@ -156,10 +168,12 @@ _X_HIDDEN void __glXSetCurrentContextNull(void) { __glXSetCurrentContext(&dummyContext); -#ifdef GLX_DIRECT_RENDERING +#ifndef GLX_USE_APPLEGL +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) _glapi_set_dispatch(NULL); /* no-op functions */ _glapi_set_context(NULL); #endif +#endif } @@ -186,6 +200,7 @@ glXGetCurrentDrawable(void) } +#ifndef GLX_USE_APPLEGL /************************************************************************/ /** @@ -269,7 +284,7 @@ SendMakeCurrentRequest(Display * dpy, CARD8 opcode, } -#ifdef GLX_DIRECT_RENDERING +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) static __GLXDRIdrawable * FetchDRIDrawable(Display * dpy, GLXDrawable glxDrawable, GLXContext gc) { @@ -313,6 +328,8 @@ __glXGenerateError(Display * dpy, GLXContext gc, XID resource, _XError(dpy, &error); } +#endif /* GLX_USE_APPLEGL */ + /** * Make a particular context current. * @@ -322,8 +339,17 @@ static Bool MakeContextCurrent(Display * dpy, GLXDrawable draw, GLXDrawable read, GLXContext gc) { - xGLXMakeCurrentReply reply; const GLXContext oldGC = __glXGetCurrentContext(); +#ifdef GLX_USE_APPLEGL + bool error = apple_glx_make_current_context(dpy, + (oldGC && oldGC != &dummyContext) ? oldGC->driContext : NULL, + gc ? gc->driContext : NULL, draw); + + apple_glx_diagnostic("%s: error %s\n", __func__, error ? "YES" : "NO"); + if(error) + return GL_FALSE; +#else + xGLXMakeCurrentReply reply; const CARD8 opcode = __glXSetupForCommand(dpy); const CARD8 oldOpcode = ((gc == oldGC) || (oldGC == &dummyContext)) ? opcode : __glXSetupForCommand(oldGC->currentDpy); @@ -360,7 +386,7 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw, return False; } -#ifdef GLX_DIRECT_RENDERING +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) /* Bind the direct rendering context to the drawable */ if (gc && gc->driContext) { __GLXDRIdrawable *pdraw = FetchDRIDrawable(dpy, draw, gc); @@ -395,7 +421,7 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw, return False; } -#ifdef GLX_DIRECT_RENDERING +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) if ((dpy != oldGC->currentDpy || (gc && gc->driContext)) && !oldGC->isDirect && oldGC != &dummyContext) { #else @@ -413,12 +439,13 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw, oldGC->currentContextTag, None, None, &dummy_reply); } -#ifdef GLX_DIRECT_RENDERING +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) else if (oldGC->driContext && oldGC != gc) { oldGC->driContext->unbindContext(oldGC->driContext); } #endif +#endif /* GLX_USE_APPLEGL */ /* Update our notion of what is current */ __glXLock(); @@ -428,8 +455,10 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw, * cannot be NULL, therefore if they are the same, gc is not * NULL and not the dummy. */ - gc->currentDrawable = draw; - gc->currentReadable = read; + if(gc) { + gc->currentDrawable = draw; + gc->currentReadable = read; + } } else { if (oldGC != &dummyContext) { @@ -439,13 +468,24 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw, oldGC->currentReadable = None; oldGC->currentContextTag = 0; oldGC->thread_id = 0; - +#ifdef GLX_USE_APPLEGL + + /* + * At this point we should check if the context has been + * through glXDestroyContext, and redestroy it if so. + */ + if(oldGC->do_destroy) { + __glXUnlock(); + /* glXDestroyContext uses the same global lock. */ + glXDestroyContext(dpy, oldGC); + __glXLock(); +#else if (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. */ -#ifdef GLX_DIRECT_RENDERING +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) /* Destroy the old direct rendering context */ if (oldGC->driContext) { oldGC->driContext->destroyContext(oldGC->driContext, @@ -455,6 +495,7 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw, } #endif __glXFreeContext(oldGC); +#endif /* GLX_USE_APPLEGL */ } } if (gc) { @@ -463,9 +504,10 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw, gc->currentDpy = dpy; gc->currentDrawable = draw; gc->currentReadable = read; +#ifndef GLX_USE_APPLEGL gc->thread_id = _glthread_GetID(); -#ifdef GLX_DIRECT_RENDERING +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) if (!gc->driContext) { #endif if (!IndirectAPI) @@ -480,12 +522,13 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw, (void) glGetString(GL_VERSION); __glXInitVertexArrayState(gc); } -#ifdef GLX_DIRECT_RENDERING +#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) } else { gc->currentContextTag = -1; } #endif +#endif /* GLX_USE_APPLEGL */ } else { __glXSetCurrentContextNull(); |