2008-04-18 17:28:34 +03:00
|
|
|
/*
|
Update to SGI FreeB 2.0.
Under the terms of version 1.1, "once Covered Code has been published
under a particular version of the License, Recipient may, for the
duration of the License, continue to use it under the terms of that
version, or choose to use such Covered Code under the terms of any
subsequent version published by SGI."
FreeB 2.0 license refers to "dates of first publication". They are here
taken to be 1991-2000, as noted in the original license text:
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
Official FreeB 2.0 text:
http://oss.sgi.com/projects/FreeB/SGIFreeSWLicB.2.0.pdf
As always, this code has not been tested for conformance with the OpenGL
specification. OpenGL conformance testing is available from
http://khronos.org/ and is required for use of the OpenGL logo in
product advertising and promotion.
2008-09-19 17:16:53 -04:00
|
|
|
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
|
|
|
|
|
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
|
|
|
|
|
*
|
2022-12-14 13:27:16 -05:00
|
|
|
* SPDX-License-Identifier: SGI-B-2.0
|
Update to SGI FreeB 2.0.
Under the terms of version 1.1, "once Covered Code has been published
under a particular version of the License, Recipient may, for the
duration of the License, continue to use it under the terms of that
version, or choose to use such Covered Code under the terms of any
subsequent version published by SGI."
FreeB 2.0 license refers to "dates of first publication". They are here
taken to be 1991-2000, as noted in the original license text:
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
Official FreeB 2.0 text:
http://oss.sgi.com/projects/FreeB/SGIFreeSWLicB.2.0.pdf
As always, this code has not been tested for conformance with the OpenGL
specification. OpenGL conformance testing is available from
http://khronos.org/ and is required for use of the OpenGL logo in
product advertising and promotion.
2008-09-19 17:16:53 -04:00
|
|
|
*/
|
2008-04-18 17:28:34 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \file glxcurrent.c
|
|
|
|
|
* Client-side GLX interface for current context management.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-04-01 11:01:31 -07:00
|
|
|
#include <pthread.h>
|
|
|
|
|
|
2008-04-18 17:28:34 +03:00
|
|
|
#include "glxclient.h"
|
2011-06-08 12:03:10 -07:00
|
|
|
#include "glapi.h"
|
2017-11-14 15:13:02 -05:00
|
|
|
#include "glx_error.h"
|
2011-06-08 12:03:10 -07:00
|
|
|
|
2008-04-18 17:28:34 +03:00
|
|
|
/*
|
|
|
|
|
** We setup some dummy structures here so that the API can be used
|
|
|
|
|
** even if no context is current.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static GLubyte dummyBuffer[__GLX_BUFFER_LIMIT_SIZE];
|
2010-09-07 14:32:28 -04:00
|
|
|
static struct glx_context_vtable dummyVtable;
|
2008-04-18 17:28:34 +03:00
|
|
|
/*
|
|
|
|
|
** Dummy context used by small commands when there is no current context.
|
|
|
|
|
** All the
|
|
|
|
|
** gl and glx entry points are designed to operate as nop's when using
|
|
|
|
|
** the dummy context structure.
|
|
|
|
|
*/
|
2010-07-29 18:44:26 -04:00
|
|
|
struct glx_context dummyContext = {
|
2008-10-13 14:07:07 +02:00
|
|
|
&dummyBuffer[0],
|
|
|
|
|
&dummyBuffer[0],
|
|
|
|
|
&dummyBuffer[0],
|
|
|
|
|
&dummyBuffer[__GLX_BUFFER_LIMIT_SIZE],
|
|
|
|
|
sizeof(dummyBuffer),
|
2010-09-07 14:32:28 -04:00
|
|
|
&dummyVtable
|
2008-04-18 17:28:34 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Current context management and locking
|
|
|
|
|
*/
|
|
|
|
|
|
2025-02-18 11:17:24 -05:00
|
|
|
pthread_mutex_t __glXmutex = PTHREAD_MUTEX_INITIALIZER;
|
2008-04-18 17:28:34 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Per-thread GLX context pointer.
|
2009-08-12 12:41:22 +02:00
|
|
|
*
|
2008-04-18 17:28:34 +03:00
|
|
|
* \c __glXSetCurrentContext is written is such a way that this pointer can
|
|
|
|
|
* \b never be \c NULL. This is important! Because of this
|
|
|
|
|
* \c __glXGetCurrentContext can be implemented as trivial macro.
|
|
|
|
|
*/
|
2021-05-21 13:23:07 -07:00
|
|
|
__THREAD_INITIAL_EXEC void *__glX_tls_Context = &dummyContext;
|
2008-04-18 17:28:34 +03:00
|
|
|
|
2025-02-18 11:17:24 -05:00
|
|
|
void
|
2010-07-28 11:16:00 -04:00
|
|
|
__glXSetCurrentContext(struct glx_context * c)
|
2008-04-18 17:28:34 +03:00
|
|
|
{
|
2008-10-13 14:07:07 +02:00
|
|
|
__glX_tls_Context = (c != NULL) ? c : &dummyContext;
|
2008-04-18 17:28:34 +03:00
|
|
|
}
|
|
|
|
|
|
2025-02-18 11:17:24 -05:00
|
|
|
void
|
2008-10-13 14:07:07 +02:00
|
|
|
__glXSetCurrentContextNull(void)
|
2008-04-18 17:28:34 +03:00
|
|
|
{
|
2008-10-13 14:07:07 +02:00
|
|
|
__glXSetCurrentContext(&dummyContext);
|
2011-06-08 12:03:10 -07:00
|
|
|
#if defined(GLX_DIRECT_RENDERING)
|
2025-01-22 09:44:30 -05:00
|
|
|
_mesa_glapi_set_dispatch(NULL); /* no-op functions */
|
|
|
|
|
_mesa_glapi_set_context(NULL);
|
2008-04-18 17:28:34 +03:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-11 14:01:53 -04:00
|
|
|
_GLX_PUBLIC GLXContext
|
2008-10-13 14:07:07 +02:00
|
|
|
glXGetCurrentContext(void)
|
2008-04-18 17:28:34 +03:00
|
|
|
{
|
2010-07-28 11:16:00 -04:00
|
|
|
struct glx_context *cx = __glXGetCurrentContext();
|
2008-10-13 14:07:07 +02:00
|
|
|
|
|
|
|
|
if (cx == &dummyContext) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2010-07-28 11:16:00 -04:00
|
|
|
return (GLXContext) cx;
|
2008-10-13 14:07:07 +02:00
|
|
|
}
|
2008-04-18 17:28:34 +03:00
|
|
|
}
|
|
|
|
|
|
2016-05-11 14:01:53 -04:00
|
|
|
_GLX_PUBLIC GLXDrawable
|
2008-10-13 14:07:07 +02:00
|
|
|
glXGetCurrentDrawable(void)
|
2008-04-18 17:28:34 +03:00
|
|
|
{
|
2010-07-28 11:16:00 -04:00
|
|
|
struct glx_context *gc = __glXGetCurrentContext();
|
2008-10-13 14:07:07 +02:00
|
|
|
return gc->currentDrawable;
|
2008-04-18 17:28:34 +03:00
|
|
|
}
|
|
|
|
|
|
2021-04-15 14:25:09 -04:00
|
|
|
/**
|
|
|
|
|
* Make a particular context current.
|
|
|
|
|
*
|
|
|
|
|
* \note This is in this file so that it can access dummyContext.
|
|
|
|
|
*/
|
2008-10-13 14:07:07 +02:00
|
|
|
static Bool
|
|
|
|
|
MakeContextCurrent(Display * dpy, GLXDrawable draw,
|
2021-04-16 14:25:16 -04:00
|
|
|
GLXDrawable read, GLXContext gc_user,
|
|
|
|
|
int opcode)
|
2008-04-18 17:28:34 +03:00
|
|
|
{
|
2010-07-28 11:16:00 -04:00
|
|
|
struct glx_context *gc = (struct glx_context *) gc_user;
|
|
|
|
|
struct glx_context *oldGC = __glXGetCurrentContext();
|
2023-01-03 18:58:03 -05:00
|
|
|
int ret = GL_TRUE;
|
2008-04-18 17:28:34 +03:00
|
|
|
|
2008-10-13 14:07:07 +02:00
|
|
|
/* 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
|
|
|
|
|
* context.
|
|
|
|
|
*/
|
|
|
|
|
if ((gc != NULL) && (gc->xid == None)) {
|
|
|
|
|
return GL_FALSE;
|
2009-04-02 11:00:41 +02:00
|
|
|
}
|
|
|
|
|
|
2021-04-15 14:25:09 -04:00
|
|
|
/* can't have only one be 0 */
|
|
|
|
|
if (!!draw != !!read) {
|
2021-04-16 14:25:16 -04:00
|
|
|
__glXSendError(dpy, BadMatch, None, opcode, True);
|
2021-04-15 14:25:09 -04:00
|
|
|
return False;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-03 18:58:03 -05:00
|
|
|
if (oldGC == gc &&
|
|
|
|
|
gc->currentDrawable == draw && gc->currentReadable == read)
|
|
|
|
|
return True;
|
|
|
|
|
|
|
|
|
|
__glXLock();
|
|
|
|
|
|
2021-04-15 14:25:09 -04:00
|
|
|
if (oldGC != &dummyContext) {
|
2023-01-03 18:33:34 -05:00
|
|
|
oldGC->vtable->unbind(oldGC);
|
2022-07-11 16:11:53 -04:00
|
|
|
oldGC->currentDpy = NULL;
|
2023-01-03 18:58:03 -05:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
2021-04-15 14:25:09 -04:00
|
|
|
}
|
2008-04-18 17:28:34 +03:00
|
|
|
|
2023-01-03 18:58:03 -05:00
|
|
|
__glXSetCurrentContextNull();
|
|
|
|
|
|
2021-04-15 14:25:09 -04:00
|
|
|
if (gc) {
|
2023-04-25 11:42:20 +03:00
|
|
|
/* GLX spec 3.3: If ctx is current to some other thread, then
|
|
|
|
|
* glXMakeContextCurrent will generate a BadAccess error
|
|
|
|
|
*/
|
|
|
|
|
if (gc->currentDpy)
|
|
|
|
|
{
|
|
|
|
|
__glXUnlock();
|
|
|
|
|
__glXSendError(dpy, BadAccess, None, opcode, True);
|
|
|
|
|
return False;
|
|
|
|
|
}
|
2021-04-15 14:25:09 -04:00
|
|
|
/* 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.
|
|
|
|
|
*/
|
2023-01-03 18:33:34 -05:00
|
|
|
if (gc->vtable->bind(gc, draw, read) != Success) {
|
2023-01-03 18:58:03 -05:00
|
|
|
ret = GL_FALSE;
|
|
|
|
|
} else {
|
|
|
|
|
gc->currentDpy = dpy;
|
|
|
|
|
gc->currentDrawable = draw;
|
|
|
|
|
gc->currentReadable = read;
|
|
|
|
|
__glXSetCurrentContext(gc);
|
2011-06-17 12:24:55 -07:00
|
|
|
}
|
2011-06-17 12:28:05 -07:00
|
|
|
}
|
|
|
|
|
|
2011-02-03 17:26:02 -08:00
|
|
|
__glXUnlock();
|
2021-04-15 14:25:09 -04:00
|
|
|
|
2023-01-03 18:58:03 -05:00
|
|
|
if (!ret)
|
|
|
|
|
__glXSendError(dpy, GLXBadContext, None, opcode, False);
|
|
|
|
|
|
|
|
|
|
return ret;
|
2008-04-18 17:28:34 +03:00
|
|
|
}
|
|
|
|
|
|
2016-05-11 14:01:53 -04:00
|
|
|
_GLX_PUBLIC Bool
|
2008-10-13 14:07:07 +02:00
|
|
|
glXMakeCurrent(Display * dpy, GLXDrawable draw, GLXContext gc)
|
2008-04-18 17:28:34 +03:00
|
|
|
{
|
2021-04-16 14:25:16 -04:00
|
|
|
return MakeContextCurrent(dpy, draw, draw, gc, X_GLXMakeCurrent);
|
2008-04-18 17:28:34 +03:00
|
|
|
}
|
|
|
|
|
|
2021-04-16 14:25:16 -04:00
|
|
|
_GLX_PUBLIC Bool
|
|
|
|
|
glXMakeContextCurrent(Display *dpy, GLXDrawable d, GLXDrawable r,
|
|
|
|
|
GLXContext ctx)
|
|
|
|
|
{
|
|
|
|
|
return MakeContextCurrent(dpy, d, r, ctx, X_GLXMakeContextCurrent);
|
|
|
|
|
}
|
2008-04-18 17:28:34 +03:00
|
|
|
|
2021-04-16 14:25:16 -04:00
|
|
|
_GLX_PUBLIC Bool
|
|
|
|
|
glXMakeCurrentReadSGI(Display *dpy, GLXDrawable d, GLXDrawable r,
|
|
|
|
|
GLXContext ctx)
|
|
|
|
|
{
|
|
|
|
|
return MakeContextCurrent(dpy, d, r, ctx, X_GLXvop_MakeCurrentReadSGI);
|
|
|
|
|
}
|