summaryrefslogtreecommitdiff
path: root/src/glx/glxcurrent.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/glx/glxcurrent.c')
-rw-r--r--src/glx/glxcurrent.c329
1 files changed, 43 insertions, 286 deletions
diff --git a/src/glx/glxcurrent.c b/src/glx/glxcurrent.c
index e8649b6765..e2569974c2 100644
--- a/src/glx/glxcurrent.c
+++ b/src/glx/glxcurrent.c
@@ -45,7 +45,6 @@
#include "apple_glx_context.h"
#else
#include "glapi.h"
-#include "indirect_init.h"
#endif
/*
@@ -61,7 +60,7 @@ static GLubyte dummyBuffer[__GLX_BUFFER_LIMIT_SIZE];
** gl and glx entry points are designed to operate as nop's when using
** the dummy context structure.
*/
-static __GLXcontext dummyContext = {
+struct glx_context dummyContext = {
&dummyBuffer[0],
&dummyBuffer[0],
&dummyBuffer[0],
@@ -69,14 +68,6 @@ static __GLXcontext dummyContext = {
sizeof(dummyBuffer),
};
-
-#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
*/
@@ -98,7 +89,7 @@ __thread void *__glX_tls_Context __attribute__ ((tls_model("initial-exec")))
= &dummyContext;
_X_HIDDEN void
-__glXSetCurrentContext(__GLXcontext * c)
+__glXSetCurrentContext(struct glx_context * c)
{
__glX_tls_Context = (c != NULL) ? c : &dummyContext;
}
@@ -133,13 +124,13 @@ init_thread_data(void)
}
_X_HIDDEN void
-__glXSetCurrentContext(__GLXcontext * c)
+__glXSetCurrentContext(struct glx_context * c)
{
pthread_once(&once_control, init_thread_data);
pthread_setspecific(ContextTSD, c);
}
-_X_HIDDEN __GLXcontext *
+_X_HIDDEN struct glx_context *
__glXGetCurrentContext(void)
{
void *v;
@@ -147,7 +138,7 @@ __glXGetCurrentContext(void)
pthread_once(&once_control, init_thread_data);
v = pthread_getspecific(ContextTSD);
- return (v == NULL) ? &dummyContext : (__GLXcontext *) v;
+ return (v == NULL) ? &dummyContext : (struct glx_context *) v;
}
# endif /* defined( GLX_USE_TLS ) */
@@ -159,7 +150,7 @@ __glXGetCurrentContext(void)
#else
/* not thread safe */
-_X_HIDDEN __GLXcontext *__glXcurrentContext = &dummyContext;
+_X_HIDDEN struct glx_context *__glXcurrentContext = &dummyContext;
#endif
@@ -176,145 +167,28 @@ __glXSetCurrentContextNull(void)
#endif
}
-
-/************************************************************************/
-
-PUBLIC GLXContext
+_X_EXPORT GLXContext
glXGetCurrentContext(void)
{
- GLXContext cx = __glXGetCurrentContext();
+ struct glx_context *cx = __glXGetCurrentContext();
if (cx == &dummyContext) {
return NULL;
}
else {
- return cx;
+ return (GLXContext) cx;
}
}
-PUBLIC GLXDrawable
+_X_EXPORT GLXDrawable
glXGetCurrentDrawable(void)
{
- GLXContext gc = __glXGetCurrentContext();
+ struct glx_context *gc = __glXGetCurrentContext();
return gc->currentDrawable;
}
-
-#ifndef GLX_USE_APPLEGL
-/************************************************************************/
-
-/**
- * Sends a GLX protocol message to the specified display to make the context
- * and the drawables current.
- *
- * \param dpy Display to send the message to.
- * \param opcode Major opcode value for the display.
- * \param gc_id Context tag for the context to be made current.
- * \param draw Drawable ID for the "draw" drawable.
- * \param read Drawable ID for the "read" drawable.
- * \param reply Space to store the X-server's reply.
- *
- * \warning
- * This function assumes that \c dpy is locked with \c LockDisplay on entry.
- */
-static Bool
-SendMakeCurrentRequest(Display * dpy, CARD8 opcode,
- GLXContextID gc_id, GLXContextTag gc_tag,
- GLXDrawable draw, GLXDrawable read,
- xGLXMakeCurrentReply * reply)
-{
- Bool ret;
-
-
- LockDisplay(dpy);
-
- if (draw == read) {
- xGLXMakeCurrentReq *req;
-
- GetReq(GLXMakeCurrent, req);
- req->reqType = opcode;
- req->glxCode = X_GLXMakeCurrent;
- req->drawable = draw;
- req->context = gc_id;
- req->oldContextTag = gc_tag;
- }
- else {
- __GLXdisplayPrivate *priv = __glXInitialize(dpy);
-
- /* If the server can support the GLX 1.3 version, we should
- * perfer that. Not only that, some servers support GLX 1.3 but
- * not the SGI extension.
- */
-
- if ((priv->majorVersion > 1) || (priv->minorVersion >= 3)) {
- xGLXMakeContextCurrentReq *req;
-
- GetReq(GLXMakeContextCurrent, req);
- req->reqType = opcode;
- req->glxCode = X_GLXMakeContextCurrent;
- req->drawable = draw;
- req->readdrawable = read;
- req->context = gc_id;
- req->oldContextTag = gc_tag;
- }
- else {
- xGLXVendorPrivateWithReplyReq *vpreq;
- xGLXMakeCurrentReadSGIReq *req;
-
- GetReqExtra(GLXVendorPrivateWithReply,
- sz_xGLXMakeCurrentReadSGIReq -
- sz_xGLXVendorPrivateWithReplyReq, vpreq);
- req = (xGLXMakeCurrentReadSGIReq *) vpreq;
- req->reqType = opcode;
- req->glxCode = X_GLXVendorPrivateWithReply;
- req->vendorCode = X_GLXvop_MakeCurrentReadSGI;
- req->drawable = draw;
- req->readable = read;
- req->context = gc_id;
- req->oldContextTag = gc_tag;
- }
- }
-
- ret = _XReply(dpy, (xReply *) reply, 0, False);
-
- UnlockDisplay(dpy);
- SyncHandle();
-
- return ret;
-}
-
-
-#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
-static __GLXDRIdrawable *
-FetchDRIDrawable(Display * dpy, GLXDrawable glxDrawable, GLXContext gc)
-{
- __GLXdisplayPrivate *const priv = __glXInitialize(dpy);
- __GLXDRIdrawable *pdraw;
- __GLXscreenConfigs *psc;
-
- if (priv == NULL)
- return NULL;
-
- psc = priv->screenConfigs[gc->screen];
- if (priv->drawHash == NULL)
- return NULL;
-
- if (__glxHashLookup(priv->drawHash, glxDrawable, (void *) &pdraw) == 0)
- return pdraw;
-
- pdraw = psc->driScreen->createDrawable(psc, glxDrawable,
- glxDrawable, gc->mode);
- if (__glxHashInsert(priv->drawHash, glxDrawable, pdraw)) {
- (*pdraw->destroyDrawable) (pdraw);
- return NULL;
- }
-
- return pdraw;
-}
-#endif /* GLX_DIRECT_RENDERING */
-
static void
-__glXGenerateError(Display * dpy, GLXContext gc, XID resource,
+__glXGenerateError(Display * dpy, struct glx_context *gc, XID resource,
BYTE errorCode, CARD16 minorCode)
{
xError error;
@@ -328,8 +202,6 @@ __glXGenerateError(Display * dpy, GLXContext gc, XID resource,
_XError(dpy, &error);
}
-#endif /* GLX_USE_APPLEGL */
-
/**
* Make a particular context current.
*
@@ -337,28 +209,11 @@ __glXGenerateError(Display * dpy, GLXContext gc, XID resource,
*/
static Bool
MakeContextCurrent(Display * dpy, GLXDrawable draw,
- GLXDrawable read, GLXContext gc)
+ GLXDrawable read, GLXContext gc_user)
{
- 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);
- Bool bindReturnValue;
- __GLXattribute *state;
-
- if (!opcode || !oldOpcode) {
- return GL_FALSE;
- }
+ 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
@@ -386,150 +241,52 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw,
return False;
}
-#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);
- __GLXDRIdrawable *pread = FetchDRIDrawable(dpy, read, gc);
-
- if ((pdraw == NULL) || (pread == NULL)) {
- __glXGenerateError(dpy, gc, (pdraw == NULL) ? draw : read,
- GLXBadDrawable, X_GLXMakeContextCurrent);
- return False;
- }
-
- bindReturnValue =
- (gc->driContext->bindContext) (gc, pdraw, pread);
+ if (oldGC != &dummyContext && oldGC != gc) {
+ oldGC->vtable->unbind(oldGC, gc);
+ oldGC->currentDpy = 0;
+ oldGC->currentDrawable = None;
+ oldGC->currentReadable = None;
+ oldGC->thread_id = 0;
+ 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.
+ */
+ oldGC->vtable->destroy(oldGC);
}
- else if (!gc && oldGC && oldGC->driContext) {
- bindReturnValue = True;
- }
- else
-#endif
- {
- /* Send a glXMakeCurrent request to bind the new context. */
- bindReturnValue =
- SendMakeCurrentRequest(dpy, opcode, gc ? gc->xid : None,
- ((dpy != oldGC->currentDpy)
- || oldGC->isDirect)
- ? None : oldGC->currentContextTag, draw, read,
- &reply);
- }
-
- if (!bindReturnValue) {
- return False;
+ if (gc) {
+ ret = gc->vtable->bind(gc, oldGC, draw, read);
+ gc->currentDpy = dpy;
+ gc->currentDrawable = draw;
+ gc->currentReadable = read;
+ gc->thread_id = _glthread_GetID();
+ __glXSetCurrentContext(gc);
+ } else {
+ __glXSetCurrentContextNull();
}
-#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
- if ((dpy != oldGC->currentDpy || (gc && gc->driContext)) &&
- !oldGC->isDirect && oldGC != &dummyContext) {
-#else
- if ((dpy != oldGC->currentDpy) && oldGC != &dummyContext) {
-#endif
- xGLXMakeCurrentReply dummy_reply;
-
- /* We are either switching from one dpy to another and have to
- * send a request to the previous dpy to unbind the previous
- * context, or we are switching away from a indirect context to
- * a direct context and have to send a request to the dpy to
- * unbind the previous context.
- */
- (void) SendMakeCurrentRequest(oldGC->currentDpy, oldOpcode, None,
- oldGC->currentContextTag, None, None,
- &dummy_reply);
- }
-#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
- else if (oldGC->driContext && oldGC != gc) {
- oldGC->driContext->unbindContext(oldGC);
- }
-#endif
-
-#endif /* GLX_USE_APPLEGL */
-
- /* Update our notion of what is current */
- __glXLock();
- if (gc == oldGC) {
- /* Even though the contexts are the same the drawable might have
- * changed. Note that gc cannot be the dummy, and that oldGC
- * cannot be NULL, therefore if they are the same, gc is not
- * NULL and not the dummy.
- */
- if(gc) {
- gc->currentDrawable = draw;
- gc->currentReadable = read;
- }
+ if (ret) {
+ __glXGenerateError(dpy, gc, None, ret, X_GLXMakeContextCurrent);
+ return GL_FALSE;
}
- else {
- if (oldGC != &dummyContext) {
- /* Old current context is no longer current to anybody */
- oldGC->currentDpy = 0;
- oldGC->currentDrawable = None;
- oldGC->currentReadable = None;
- oldGC->currentContextTag = 0;
- oldGC->thread_id = 0;
-
- 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.
- */
- oldGC->vtable->destroy(oldGC);
- }
- }
- if (gc) {
- __glXSetCurrentContext(gc);
-
- gc->currentDpy = dpy;
- gc->currentDrawable = draw;
- gc->currentReadable = read;
-#ifndef GLX_USE_APPLEGL
- gc->thread_id = _glthread_GetID();
-#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
- if (!gc->driContext) {
-#endif
- if (!IndirectAPI)
- IndirectAPI = __glXNewIndirectAPI();
- _glapi_set_dispatch(IndirectAPI);
-
- state = (__GLXattribute *) (gc->client_state_private);
-
- gc->currentContextTag = reply.contextTag;
- if (state->array_state == NULL) {
- (void) glGetString(GL_EXTENSIONS);
- (void) glGetString(GL_VERSION);
- __glXInitVertexArrayState(gc);
- }
-#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
- }
- else {
- gc->currentContextTag = -1;
- }
-#endif
-#endif /* GLX_USE_APPLEGL */
- }
- else {
- __glXSetCurrentContextNull();
- }
- }
- __glXUnlock();
return GL_TRUE;
}
-PUBLIC Bool
+_X_EXPORT Bool
glXMakeCurrent(Display * dpy, GLXDrawable draw, GLXContext gc)
{
return MakeContextCurrent(dpy, draw, draw, gc);
}
-PUBLIC
+_X_EXPORT
GLX_ALIAS(Bool, glXMakeCurrentReadSGI,
(Display * dpy, GLXDrawable d, GLXDrawable r, GLXContext ctx),
(dpy, d, r, ctx), MakeContextCurrent)
-PUBLIC
+_X_EXPORT
GLX_ALIAS(Bool, glXMakeContextCurrent,
(Display * dpy, GLXDrawable d, GLXDrawable r,
GLXContext ctx), (dpy, d, r, ctx), MakeContextCurrent)