2006-11-26 11:13:41 -07:00
|
|
|
/*
|
2009-09-06 13:44:18 -06:00
|
|
|
* SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
|
|
|
|
* Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice including the dates of first publication and
|
|
|
|
* either this permission notice or a reference to
|
|
|
|
* http://oss.sgi.com/projects/FreeB/
|
|
|
|
* shall be included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*
|
|
|
|
* Except as contained in this notice, the name of Silicon Graphics, Inc.
|
|
|
|
* shall not be used in advertising or otherwise to promote the sale, use or
|
|
|
|
* other dealings in this Software without prior written authorization from
|
|
|
|
* Silicon Graphics, Inc.
|
|
|
|
*/
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include "glxserver.h"
|
|
|
|
#include <windowstr.h>
|
|
|
|
#include <propertyst.h>
|
2010-07-27 13:02:24 -06:00
|
|
|
#include <registry.h>
|
2008-11-02 08:26:08 -07:00
|
|
|
#include "privates.h"
|
2006-11-26 11:13:41 -07:00
|
|
|
#include <os.h>
|
2013-06-07 11:28:45 -06:00
|
|
|
#include "extinit.h"
|
|
|
|
#include "glx_extinit.h"
|
2006-11-26 11:13:41 -07:00
|
|
|
#include "unpack.h"
|
|
|
|
#include "glxutil.h"
|
|
|
|
#include "glxext.h"
|
|
|
|
#include "indirect_table.h"
|
|
|
|
#include "indirect_util.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
** X resources.
|
|
|
|
*/
|
|
|
|
RESTYPE __glXContextRes;
|
|
|
|
RESTYPE __glXDrawableRes;
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Reply for most singles.
|
|
|
|
*/
|
|
|
|
xGLXSingleReply __glXReply;
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
static DevPrivateKeyRec glxClientPrivateKeyRec;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
#define glxClientPrivateKey (&glxClientPrivateKeyRec)
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Forward declarations.
|
|
|
|
*/
|
|
|
|
static int __glXDispatch(ClientPtr);
|
2015-09-16 13:10:19 -06:00
|
|
|
static GLboolean __glXFreeContext(__GLXcontext * cx);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Called when the extension is reset.
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
static void
|
|
|
|
ResetExtension(ExtensionEntry * extEntry)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2014-09-27 11:52:59 -06:00
|
|
|
lastGLContext = NULL;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Reset state used to keep track of large (multi-request) commands.
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
__glXResetLargeCommandStatus(__GLXclientState * cl)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
cl->largeCmdBytesSoFar = 0;
|
|
|
|
cl->largeCmdBytesTotal = 0;
|
|
|
|
cl->largeCmdRequestsSoFar = 0;
|
|
|
|
cl->largeCmdRequestsTotal = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-05-02 13:27:46 -06:00
|
|
|
* This procedure is called when the client who created the context goes away
|
|
|
|
* OR when glXDestroyContext is called. In either case, all we do is flag that
|
|
|
|
* the ID is no longer valid, and (maybe) free the context.
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
static int
|
|
|
|
ContextGone(__GLXcontext * cx, XID id)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
cx->idExists = GL_FALSE;
|
2014-05-02 13:27:46 -06:00
|
|
|
if (!cx->currentClient) {
|
2012-06-10 07:21:05 -06:00
|
|
|
__glXFreeContext(cx);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
static __GLXcontext *glxPendingDestroyContexts;
|
|
|
|
static __GLXcontext *glxAllContexts;
|
|
|
|
static int glxServerLeaveCount;
|
|
|
|
static int glxBlockClients;
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
/*
|
|
|
|
** Destroy routine that gets called when a drawable is freed. A drawable
|
|
|
|
** contains the ancillary buffers needed for rendering.
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
static Bool
|
|
|
|
DrawableGone(__GLXdrawable * glxPriv, XID xid)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2010-12-05 08:36:02 -07:00
|
|
|
__GLXcontext *c, *next;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
if (glxPriv->type == GLX_DRAWABLE_WINDOW) {
|
|
|
|
/* If this was created by glXCreateWindow, free the matching resource */
|
|
|
|
if (glxPriv->drawId != glxPriv->pDraw->id) {
|
|
|
|
if (xid == glxPriv->drawId)
|
|
|
|
FreeResourceByType(glxPriv->pDraw->id, __glXDrawableRes, TRUE);
|
|
|
|
else
|
|
|
|
FreeResourceByType(glxPriv->drawId, __glXDrawableRes, TRUE);
|
|
|
|
}
|
|
|
|
/* otherwise this window was implicitly created by MakeCurrent */
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
for (c = glxAllContexts; c; c = next) {
|
2012-06-10 07:21:05 -06:00
|
|
|
next = c->next;
|
2014-05-02 13:27:46 -06:00
|
|
|
if (c->currentClient &&
|
|
|
|
(c->drawPriv == glxPriv || c->readPriv == glxPriv)) {
|
2015-09-16 13:10:19 -06:00
|
|
|
/* flush the context */
|
|
|
|
glFlush();
|
2014-05-02 13:27:46 -06:00
|
|
|
/* just force a re-bind the next time through */
|
2012-06-10 07:21:05 -06:00
|
|
|
(*c->loseCurrent) (c);
|
2014-09-27 11:52:59 -06:00
|
|
|
lastGLContext = NULL;
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
if (c->drawPriv == glxPriv)
|
|
|
|
c->drawPriv = NULL;
|
|
|
|
if (c->readPriv == glxPriv)
|
|
|
|
c->readPriv = NULL;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
/* drop our reference to any backing pixmap */
|
|
|
|
if (glxPriv->type == GLX_DRAWABLE_PIXMAP)
|
2012-06-10 07:21:05 -06:00
|
|
|
glxPriv->pDraw->pScreen->DestroyPixmap((PixmapPtr) glxPriv->pDraw);
|
2011-11-05 07:32:40 -06:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
glxPriv->destroy(glxPriv);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
Bool
|
|
|
|
__glXAddContext(__GLXcontext * cx)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2013-06-07 11:28:45 -06:00
|
|
|
/* Register this context as a resource.
|
|
|
|
*/
|
2014-09-27 11:52:59 -06:00
|
|
|
if (!AddResource(cx->id, __glXContextRes, (void *)cx)) {
|
2013-06-07 11:28:45 -06:00
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
cx->next = glxAllContexts;
|
|
|
|
glxAllContexts = cx;
|
2013-06-07 11:28:45 -06:00
|
|
|
return True;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static void
|
|
|
|
__glXRemoveFromContextList(__GLXcontext * cx)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
__GLXcontext *c, *prev;
|
|
|
|
|
|
|
|
if (cx == glxAllContexts)
|
2012-06-10 07:21:05 -06:00
|
|
|
glxAllContexts = cx->next;
|
2010-07-27 13:02:24 -06:00
|
|
|
else {
|
2012-06-10 07:21:05 -06:00
|
|
|
prev = glxAllContexts;
|
|
|
|
for (c = glxAllContexts; c; c = c->next) {
|
|
|
|
if (c == cx)
|
|
|
|
prev->next = c->next;
|
|
|
|
prev = c;
|
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Free a context.
|
|
|
|
*/
|
2015-09-16 13:10:19 -06:00
|
|
|
static GLboolean
|
2012-06-10 07:21:05 -06:00
|
|
|
__glXFreeContext(__GLXcontext * cx)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2014-05-02 13:27:46 -06:00
|
|
|
if (cx->idExists || cx->currentClient)
|
2012-06-10 07:21:05 -06:00
|
|
|
return GL_FALSE;
|
|
|
|
|
2014-05-02 13:27:46 -06:00
|
|
|
__glXRemoveFromContextList(cx);
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
free(cx->feedbackBuf);
|
|
|
|
free(cx->selectBuf);
|
2014-09-27 11:52:59 -06:00
|
|
|
if (cx == lastGLContext) {
|
|
|
|
lastGLContext = NULL;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We can get here through both regular dispatching from
|
|
|
|
* __glXDispatch() or as a callback from the resource manager. In
|
|
|
|
* the latter case we need to lift the DRI lock manually. */
|
|
|
|
|
2006-12-16 13:09:36 -07:00
|
|
|
if (!glxBlockClients) {
|
2012-06-10 07:21:05 -06:00
|
|
|
__glXleaveServer(GL_FALSE);
|
|
|
|
cx->destroy(cx);
|
|
|
|
__glXenterServer(GL_FALSE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cx->next = glxPendingDestroyContexts;
|
|
|
|
glxPendingDestroyContexts = cx;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
** These routines can be used to check whether a particular GL command
|
|
|
|
** has caused an error. Specifically, we use them to check whether a
|
|
|
|
** given query has caused an error, in which case a zero-length data
|
|
|
|
** reply is sent to the client.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static GLboolean errorOccured = GL_FALSE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
** The GL was will call this routine if an error occurs.
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
__glXErrorCallBack(GLenum code)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
errorOccured = GL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Clear the error flag before calling the GL command.
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
__glXClearErrorOccured(void)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
errorOccured = GL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Check if the GL command caused an error.
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
GLboolean
|
|
|
|
__glXErrorOccured(void)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
return errorOccured;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __glXErrorBase;
|
2010-07-27 13:02:24 -06:00
|
|
|
int __glXEventBase;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
int
|
|
|
|
__glXError(int error)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
return __glXErrorBase + error;
|
|
|
|
}
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
__GLXclientState *
|
|
|
|
glxGetClient(ClientPtr pClient)
|
|
|
|
{
|
|
|
|
return dixLookupPrivate(&pClient->devPrivates, glxClientPrivateKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-09-27 11:52:59 -06:00
|
|
|
glxClientCallback(CallbackListPtr *list, void *closure, void *data)
|
2008-11-02 08:26:08 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
NewClientInfoRec *clientinfo = (NewClientInfoRec *) data;
|
|
|
|
ClientPtr pClient = clientinfo->client;
|
|
|
|
__GLXclientState *cl = glxGetClient(pClient);
|
2014-05-02 13:27:46 -06:00
|
|
|
__GLXcontext *c, *next;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
switch (pClient->clientState) {
|
|
|
|
case ClientStateRunning:
|
2012-06-10 07:21:05 -06:00
|
|
|
cl->client = pClient;
|
|
|
|
break;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
case ClientStateGone:
|
2014-05-02 13:27:46 -06:00
|
|
|
/* detach from all current contexts */
|
|
|
|
for (c = glxAllContexts; c; c = next) {
|
|
|
|
next = c->next;
|
|
|
|
if (c->currentClient == pClient) {
|
|
|
|
c->loseCurrent(c);
|
2014-09-27 11:52:59 -06:00
|
|
|
lastGLContext = NULL;
|
2014-05-02 13:27:46 -06:00
|
|
|
c->currentClient = NULL;
|
2015-09-16 13:10:19 -06:00
|
|
|
FreeResourceByType(c->id, __glXContextRes, FALSE);
|
2014-05-02 13:27:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
free(cl->returnBuf);
|
|
|
|
free(cl->largeCmdBuf);
|
|
|
|
free(cl->GLClientextensions);
|
|
|
|
break;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
default:
|
2012-06-10 07:21:05 -06:00
|
|
|
break;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
/************************************************************************/
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
static __GLXprovider *__glXProviderStack;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
GlxPushProvider(__GLXprovider * provider)
|
2008-11-02 08:26:08 -07:00
|
|
|
{
|
|
|
|
provider->next = __glXProviderStack;
|
|
|
|
__glXProviderStack = provider;
|
|
|
|
}
|
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
static Bool
|
|
|
|
checkScreenVisuals(void)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < screenInfo.numScreens; i++) {
|
|
|
|
ScreenPtr screen = screenInfo.screens[i];
|
|
|
|
for (j = 0; j < screen->numVisuals; j++) {
|
|
|
|
if (screen->visuals[j].class == TrueColor ||
|
|
|
|
screen->visuals[j].class == DirectColor)
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
2017-12-08 08:01:59 -07:00
|
|
|
static void
|
|
|
|
GetGLXDrawableBytes(void *value, XID id, ResourceSizePtr size)
|
|
|
|
{
|
|
|
|
__GLXdrawable *draw = value;
|
|
|
|
|
|
|
|
size->resourceSize = 0;
|
|
|
|
size->pixmapRefSize = 0;
|
|
|
|
size->refCnt = 1;
|
|
|
|
|
|
|
|
if (draw->type == GLX_DRAWABLE_PIXMAP) {
|
|
|
|
SizeType pixmapSizeFunc = GetResourceTypeSizeFunc(RT_PIXMAP);
|
|
|
|
ResourceSizeRec pixmapSize = { 0, };
|
|
|
|
pixmapSizeFunc((PixmapPtr)draw->pDraw, draw->pDraw->id, &pixmapSize);
|
|
|
|
size->pixmapRefSize += pixmapSize.pixmapRefSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
/*
|
|
|
|
** Initialize the GLX extension.
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
GlxExtensionInit(void)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
ExtensionEntry *extEntry;
|
2008-11-02 08:26:08 -07:00
|
|
|
ScreenPtr pScreen;
|
2006-11-26 11:13:41 -07:00
|
|
|
int i;
|
2013-06-07 11:28:45 -06:00
|
|
|
__GLXprovider *p, **stack;
|
2008-11-02 08:26:08 -07:00
|
|
|
Bool glx_provided = False;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
if (serverGeneration == 1) {
|
|
|
|
for (stack = &__glXProviderStack; *stack; stack = &(*stack)->next)
|
|
|
|
;
|
|
|
|
*stack = &__glXDRISWRastProvider;
|
|
|
|
}
|
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
/* Mesa requires at least one True/DirectColor visual */
|
|
|
|
if (!checkScreenVisuals())
|
|
|
|
return;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
__glXContextRes = CreateNewResourceType((DeleteType) ContextGone,
|
|
|
|
"GLXContext");
|
|
|
|
__glXDrawableRes = CreateNewResourceType((DeleteType) DrawableGone,
|
|
|
|
"GLXDrawable");
|
2011-11-05 07:32:40 -06:00
|
|
|
if (!__glXContextRes || !__glXDrawableRes)
|
2012-06-10 07:21:05 -06:00
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2017-12-08 08:01:59 -07:00
|
|
|
SetResourceTypeSizeFunc(__glXDrawableRes, GetGLXDrawableBytes);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!dixRegisterPrivateKey
|
|
|
|
(&glxClientPrivateKeyRec, PRIVATE_CLIENT, sizeof(__GLXclientState)))
|
|
|
|
return;
|
|
|
|
if (!AddCallback(&ClientStateCallback, glxClientCallback, 0))
|
|
|
|
return;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
for (i = 0; i < screenInfo.numScreens; i++) {
|
2012-06-10 07:21:05 -06:00
|
|
|
pScreen = screenInfo.screens[i];
|
|
|
|
|
|
|
|
for (p = __glXProviderStack; p != NULL; p = p->next) {
|
|
|
|
__GLXscreen *glxScreen;
|
|
|
|
|
|
|
|
glxScreen = p->screenProbe(pScreen);
|
|
|
|
if (glxScreen != NULL) {
|
|
|
|
LogMessage(X_INFO,
|
|
|
|
"GLX: Initialized %s GL provider for screen %d\n",
|
|
|
|
p->name, i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!p)
|
|
|
|
LogMessage(X_INFO,
|
|
|
|
"GLX: no usable GL providers found for screen %d\n", i);
|
|
|
|
else
|
|
|
|
glx_provided = True;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* don't register extension if GL is not provided on any screen */
|
|
|
|
if (!glx_provided)
|
2012-06-10 07:21:05 -06:00
|
|
|
return;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
/*
|
2012-06-10 07:21:05 -06:00
|
|
|
** Add extension to server extensions.
|
|
|
|
*/
|
2006-11-26 11:13:41 -07:00
|
|
|
extEntry = AddExtension(GLX_EXTENSION_NAME, __GLX_NUMBER_EVENTS,
|
2012-06-10 07:21:05 -06:00
|
|
|
__GLX_NUMBER_ERRORS, __glXDispatch,
|
|
|
|
__glXDispatch, ResetExtension, StandardMinorOpcode);
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!extEntry) {
|
2012-06-10 07:21:05 -06:00
|
|
|
FatalError("__glXExtensionInit: AddExtensions failed\n");
|
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
if (!AddExtensionAlias(GLX_EXTENSION_ALIAS, extEntry)) {
|
2012-06-10 07:21:05 -06:00
|
|
|
ErrorF("__glXExtensionInit: AddExtensionAlias failed\n");
|
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
__glXErrorBase = extEntry->errorBase;
|
2010-07-27 13:02:24 -06:00
|
|
|
__glXEventBase = extEntry->eventBase;
|
2014-05-02 13:27:46 -06:00
|
|
|
#if PRESENT
|
|
|
|
__glXregisterPresentCompleteNotify();
|
|
|
|
#endif
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Make a context the current one for the GL (in this implementation, there
|
|
|
|
** is only one instance of the GL, and we use it to serve all GL clients by
|
|
|
|
** switching it between different contexts). While we are at it, look up
|
|
|
|
** a context by its tag and return its (__GLXcontext *).
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
__GLXcontext *
|
|
|
|
__glXForceCurrent(__GLXclientState * cl, GLXContextTag tag, int *error)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
__GLXcontext *cx;
|
|
|
|
|
|
|
|
/*
|
2012-06-10 07:21:05 -06:00
|
|
|
** See if the context tag is legal; it is managed by the extension,
|
|
|
|
** so if it's invalid, we have an implementation error.
|
|
|
|
*/
|
2011-11-05 07:32:40 -06:00
|
|
|
cx = __glXLookupContextByTag(cl, tag);
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!cx) {
|
2012-06-10 07:21:05 -06:00
|
|
|
cl->client->errorValue = tag;
|
|
|
|
*error = __glXError(GLXBadContextTag);
|
|
|
|
return 0;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!cx->isDirect) {
|
2012-06-10 07:21:05 -06:00
|
|
|
if (cx->drawPriv == NULL) {
|
|
|
|
/*
|
|
|
|
** The drawable has vanished. It must be a window, because only
|
|
|
|
** windows can be destroyed from under us; GLX pixmaps are
|
|
|
|
** refcounted and don't go away until no one is using them.
|
|
|
|
*/
|
|
|
|
*error = __glXError(GLXBadCurrentWindow);
|
|
|
|
return 0;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
if (cx->wait && (*cx->wait) (cx, cl, error))
|
|
|
|
return NULL;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
if (cx == lastGLContext) {
|
2012-06-10 07:21:05 -06:00
|
|
|
/* No need to re-bind */
|
|
|
|
return cx;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Make this context the current one for the GL. */
|
|
|
|
if (!cx->isDirect) {
|
2016-08-09 12:59:50 -06:00
|
|
|
/*
|
|
|
|
* If it is being forced, it means that this context was already made
|
|
|
|
* current. So it cannot just be made current again without decrementing
|
|
|
|
* refcount's
|
|
|
|
*/
|
|
|
|
(*cx->loseCurrent) (cx);
|
2014-09-27 11:52:59 -06:00
|
|
|
lastGLContext = cx;
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!(*cx->makeCurrent) (cx)) {
|
|
|
|
/* Bind failed, and set the error code. Bummer */
|
2014-09-27 11:52:59 -06:00
|
|
|
lastGLContext = NULL;
|
2012-06-10 07:21:05 -06:00
|
|
|
cl->client->errorValue = cx->id;
|
|
|
|
*error = __glXError(GLXBadContextState);
|
|
|
|
return 0;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
return cx;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
glxSuspendClients(void)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
for (i = 1; i < currentMaxClients; i++) {
|
2012-06-10 07:21:05 -06:00
|
|
|
if (clients[i] && glxGetClient(clients[i])->inUse)
|
|
|
|
IgnoreClient(clients[i]);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
glxBlockClients = TRUE;
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
glxResumeClients(void)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
__GLXcontext *cx, *next;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
glxBlockClients = FALSE;
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
for (i = 1; i < currentMaxClients; i++) {
|
2012-06-10 07:21:05 -06:00
|
|
|
if (clients[i] && glxGetClient(clients[i])->inUse)
|
|
|
|
AttendClient(clients[i]);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
__glXleaveServer(GL_FALSE);
|
2006-11-26 11:13:41 -07:00
|
|
|
for (cx = glxPendingDestroyContexts; cx != NULL; cx = next) {
|
2012-06-10 07:21:05 -06:00
|
|
|
next = cx->next;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
cx->destroy(cx);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
glxPendingDestroyContexts = NULL;
|
2007-11-24 10:55:21 -07:00
|
|
|
__glXenterServer(GL_FALSE);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-11-24 10:55:21 -07:00
|
|
|
__glXnopEnterServer(GLboolean rendering)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
static void
|
2007-11-24 10:55:21 -07:00
|
|
|
__glXnopLeaveServer(GLboolean rendering)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static void (*__glXenterServerFunc) (GLboolean) = __glXnopEnterServer;
|
|
|
|
static void (*__glXleaveServerFunc) (GLboolean) = __glXnopLeaveServer;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
__glXsetEnterLeaveServerFuncs(void (*enter) (GLboolean),
|
|
|
|
void (*leave) (GLboolean))
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
__glXenterServerFunc = enter;
|
|
|
|
__glXleaveServerFunc = leave;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
__glXenterServer(GLboolean rendering)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
glxServerLeaveCount--;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (glxServerLeaveCount == 0)
|
|
|
|
(*__glXenterServerFunc) (rendering);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
__glXleaveServer(GLboolean rendering)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
if (glxServerLeaveCount == 0)
|
|
|
|
(*__glXleaveServerFunc) (rendering);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
glxServerLeaveCount++;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:27:46 -06:00
|
|
|
static glx_gpa_proc _get_proc_address;
|
|
|
|
|
|
|
|
void
|
|
|
|
__glXsetGetProcAddress(glx_gpa_proc get_proc_address)
|
|
|
|
{
|
|
|
|
_get_proc_address = get_proc_address;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *__glGetProcAddress(const char *proc)
|
|
|
|
{
|
2014-09-27 11:52:59 -06:00
|
|
|
void *ret = (void *) _get_proc_address(proc);
|
2014-05-02 13:27:46 -06:00
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
return ret ? ret : (void *) NoopDDA;
|
2014-05-02 13:27:46 -06:00
|
|
|
}
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
/*
|
|
|
|
** Top level dispatcher; all commands are executed from here down.
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
static int
|
|
|
|
__glXDispatch(ClientPtr client)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
REQUEST(xGLXSingleReq);
|
|
|
|
CARD8 opcode;
|
|
|
|
__GLXdispatchSingleProcPtr proc;
|
|
|
|
__GLXclientState *cl;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
opcode = stuff->glxCode;
|
2008-11-02 08:26:08 -07:00
|
|
|
cl = glxGetClient(client);
|
|
|
|
/* Mark it in use so we suspend it on VT switch. */
|
|
|
|
cl->inUse = TRUE;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/*
|
2012-06-10 07:21:05 -06:00
|
|
|
** If we're expecting a glXRenderLarge request, this better be one.
|
|
|
|
*/
|
2006-11-26 11:13:41 -07:00
|
|
|
if ((cl->largeCmdRequestsSoFar != 0) && (opcode != X_GLXRenderLarge)) {
|
2012-06-10 07:21:05 -06:00
|
|
|
client->errorValue = stuff->glxCode;
|
|
|
|
return __glXError(GLXBadLargeRequest);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If we're currently blocking GLX clients, just put this guy to
|
|
|
|
* sleep, reset the request and return. */
|
|
|
|
if (glxBlockClients) {
|
2012-06-10 07:21:05 -06:00
|
|
|
ResetCurrentRequest(client);
|
|
|
|
client->sequence--;
|
|
|
|
IgnoreClient(client);
|
|
|
|
return Success;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-06-10 07:21:05 -06:00
|
|
|
** Use the opcode to index into the procedure table.
|
|
|
|
*/
|
|
|
|
proc = __glXGetProtocolDecodeFunction(&Single_dispatch_info, opcode,
|
2011-11-05 07:32:40 -06:00
|
|
|
client->swapped);
|
2006-11-26 11:13:41 -07:00
|
|
|
if (proc != NULL) {
|
2012-06-10 07:21:05 -06:00
|
|
|
GLboolean rendering = opcode <= X_GLXRenderLarge;
|
|
|
|
|
|
|
|
__glXleaveServer(rendering);
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
retval = (*proc) (cl, (GLbyte *) stuff);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
__glXenterServer(rendering);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
else {
|
2012-06-10 07:21:05 -06:00
|
|
|
retval = BadRequest;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|