xserver-multidpi/glx/glxext.c

598 lines
15 KiB
C
Raw Normal View History

2006-07-22 19:36:47 +02: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.
*/
2003-11-14 17:48:57 +01:00
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
2006-03-12 01:11:34 +01:00
#include <string.h>
2003-11-14 17:48:57 +01:00
#include "glxserver.h"
#include <windowstr.h>
#include <propertyst.h>
#include <registry.h>
#include "privates.h"
2003-11-14 17:48:57 +01:00
#include <os.h>
#include "extinit.h"
#include "glx_extinit.h"
2003-11-14 17:48:57 +01:00
#include "unpack.h"
#include "glxutil.h"
#include "glxext.h"
#include "indirect_table.h"
#include "indirect_util.h"
2003-11-14 17:48:57 +01:00
/*
** X resources.
*/
RESTYPE __glXContextRes;
RESTYPE __glXDrawableRes;
/*
** Reply for most singles.
*/
xGLXSingleReply __glXReply;
static DevPrivateKeyRec glxClientPrivateKeyRec;
#define glxClientPrivateKey (&glxClientPrivateKeyRec)
2003-11-14 17:48:57 +01:00
/*
** Forward declarations.
*/
static int __glXDispatch(ClientPtr);
static GLboolean __glXFreeContext(__GLXcontext * cx);
2003-11-14 17:48:57 +01:00
/*
** Called when the extension is reset.
*/
static void
ResetExtension(ExtensionEntry * extEntry)
2003-11-14 17:48:57 +01:00
{
lastGLContext = NULL;
2003-11-14 17:48:57 +01:00
}
/*
** Reset state used to keep track of large (multi-request) commands.
*/
void
__glXResetLargeCommandStatus(__GLXclientState * cl)
2003-11-14 17:48:57 +01:00
{
cl->largeCmdBytesSoFar = 0;
cl->largeCmdBytesTotal = 0;
cl->largeCmdRequestsSoFar = 0;
cl->largeCmdRequestsTotal = 0;
}
/*
glx: Fix memory leak in context garbage collection (v2) I broke this, back in: commit a48dadc98a28c969741979b70b7a639f24f4cbbd Author: Adam Jackson <ajax@redhat.com> Date: Mon Mar 21 11:59:29 2011 -0400 glx: Reimplement context tags In that, I changed the glx client state to not explicitly track the list of current contexts for the client (since that was what we were deriving tags from). The bug was that I removed the code for same from glxClientCallback without noticing that it had the side effect of effectively de-currenting those contexts, so that ContextGone could free them. So, if you had a client exit with a context still current, the context's memory would leak. Not a huge deal for direct clients, but viciously bad for indirect, since the swrast context state at the bottom of Mesa is like 15M. Fix this by promoting Bool isCurrent to ClientPtr currentClient, so that we have a back-pointer to chase when walking the list of contexts when ClientStateGone happens. v2: Explicitly call __glXFreeContext on the ClientStateGone path. Our current context might be one we got from EXT_import_context and whose creating client has since died. Without the explicit call, the creating client's FreeClientResources would not free the context because it's still current, and the using client's FreeClientResources would not free the context because it's not an XID it created. This matches the logic from a48dadc. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Signed-off-by: Adam Jackson <ajax@redhat.com>
2013-08-03 15:47:55 +02: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.
*/
static int
ContextGone(__GLXcontext * cx, XID id)
2003-11-14 17:48:57 +01:00
{
cx->idExists = GL_FALSE;
glx: Fix memory leak in context garbage collection (v2) I broke this, back in: commit a48dadc98a28c969741979b70b7a639f24f4cbbd Author: Adam Jackson <ajax@redhat.com> Date: Mon Mar 21 11:59:29 2011 -0400 glx: Reimplement context tags In that, I changed the glx client state to not explicitly track the list of current contexts for the client (since that was what we were deriving tags from). The bug was that I removed the code for same from glxClientCallback without noticing that it had the side effect of effectively de-currenting those contexts, so that ContextGone could free them. So, if you had a client exit with a context still current, the context's memory would leak. Not a huge deal for direct clients, but viciously bad for indirect, since the swrast context state at the bottom of Mesa is like 15M. Fix this by promoting Bool isCurrent to ClientPtr currentClient, so that we have a back-pointer to chase when walking the list of contexts when ClientStateGone happens. v2: Explicitly call __glXFreeContext on the ClientStateGone path. Our current context might be one we got from EXT_import_context and whose creating client has since died. Without the explicit call, the creating client's FreeClientResources would not free the context because it's still current, and the using client's FreeClientResources would not free the context because it's not an XID it created. This matches the logic from a48dadc. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Signed-off-by: Adam Jackson <ajax@redhat.com>
2013-08-03 15:47:55 +02:00
if (!cx->currentClient) {
__glXFreeContext(cx);
2003-11-14 17:48:57 +01:00
}
return True;
}
static __GLXcontext *glxPendingDestroyContexts;
static __GLXcontext *glxAllContexts;
static int glxBlockClients;
2006-03-12 01:11:34 +01:00
/*
** Destroy routine that gets called when a drawable is freed. A drawable
** contains the ancillary buffers needed for rendering.
*/
static Bool
DrawableGone(__GLXdrawable * glxPriv, XID xid)
2006-03-12 01:11:34 +01:00
{
__GLXcontext *c, *next;
2008-07-21 21:28:50 +02: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 */
}
for (c = glxAllContexts; c; c = next) {
next = c->next;
glx: Fix memory leak in context garbage collection (v2) I broke this, back in: commit a48dadc98a28c969741979b70b7a639f24f4cbbd Author: Adam Jackson <ajax@redhat.com> Date: Mon Mar 21 11:59:29 2011 -0400 glx: Reimplement context tags In that, I changed the glx client state to not explicitly track the list of current contexts for the client (since that was what we were deriving tags from). The bug was that I removed the code for same from glxClientCallback without noticing that it had the side effect of effectively de-currenting those contexts, so that ContextGone could free them. So, if you had a client exit with a context still current, the context's memory would leak. Not a huge deal for direct clients, but viciously bad for indirect, since the swrast context state at the bottom of Mesa is like 15M. Fix this by promoting Bool isCurrent to ClientPtr currentClient, so that we have a back-pointer to chase when walking the list of contexts when ClientStateGone happens. v2: Explicitly call __glXFreeContext on the ClientStateGone path. Our current context might be one we got from EXT_import_context and whose creating client has since died. Without the explicit call, the creating client's FreeClientResources would not free the context because it's still current, and the using client's FreeClientResources would not free the context because it's not an XID it created. This matches the logic from a48dadc. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Signed-off-by: Adam Jackson <ajax@redhat.com>
2013-08-03 15:47:55 +02:00
if (c->currentClient &&
(c->drawPriv == glxPriv || c->readPriv == glxPriv)) {
/* flush the context */
glFlush();
/* just force a re-bind the next time through */
(*c->loseCurrent) (c);
lastGLContext = NULL;
}
if (c->drawPriv == glxPriv)
c->drawPriv = NULL;
if (c->readPriv == glxPriv)
c->readPriv = NULL;
}
2008-07-21 21:28:50 +02:00
/* drop our reference to any backing pixmap */
if (glxPriv->type == GLX_DRAWABLE_PIXMAP)
glxPriv->pDraw->pScreen->DestroyPixmap((PixmapPtr) glxPriv->pDraw);
glxPriv->destroy(glxPriv);
2006-03-12 01:11:34 +01:00
return True;
}
Bool
__glXAddContext(__GLXcontext * cx)
{
/* Register this context as a resource.
*/
if (!AddResource(cx->id, __glXContextRes, (void *)cx)) {
return False;
}
cx->next = glxAllContexts;
glxAllContexts = cx;
return True;
}
static void
__glXRemoveFromContextList(__GLXcontext * cx)
{
__GLXcontext *c, *prev;
if (cx == glxAllContexts)
glxAllContexts = cx->next;
else {
prev = glxAllContexts;
for (c = glxAllContexts; c; c = c->next) {
if (c == cx)
prev->next = c->next;
prev = c;
}
}
}
2003-11-14 17:48:57 +01:00
/*
** Free a context.
*/
static GLboolean
__glXFreeContext(__GLXcontext * cx)
2003-11-14 17:48:57 +01:00
{
glx: Fix memory leak in context garbage collection (v2) I broke this, back in: commit a48dadc98a28c969741979b70b7a639f24f4cbbd Author: Adam Jackson <ajax@redhat.com> Date: Mon Mar 21 11:59:29 2011 -0400 glx: Reimplement context tags In that, I changed the glx client state to not explicitly track the list of current contexts for the client (since that was what we were deriving tags from). The bug was that I removed the code for same from glxClientCallback without noticing that it had the side effect of effectively de-currenting those contexts, so that ContextGone could free them. So, if you had a client exit with a context still current, the context's memory would leak. Not a huge deal for direct clients, but viciously bad for indirect, since the swrast context state at the bottom of Mesa is like 15M. Fix this by promoting Bool isCurrent to ClientPtr currentClient, so that we have a back-pointer to chase when walking the list of contexts when ClientStateGone happens. v2: Explicitly call __glXFreeContext on the ClientStateGone path. Our current context might be one we got from EXT_import_context and whose creating client has since died. Without the explicit call, the creating client's FreeClientResources would not free the context because it's still current, and the using client's FreeClientResources would not free the context because it's not an XID it created. This matches the logic from a48dadc. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Signed-off-by: Adam Jackson <ajax@redhat.com>
2013-08-03 15:47:55 +02:00
if (cx->idExists || cx->currentClient)
return GL_FALSE;
glx: Fix memory leak in context garbage collection (v2) I broke this, back in: commit a48dadc98a28c969741979b70b7a639f24f4cbbd Author: Adam Jackson <ajax@redhat.com> Date: Mon Mar 21 11:59:29 2011 -0400 glx: Reimplement context tags In that, I changed the glx client state to not explicitly track the list of current contexts for the client (since that was what we were deriving tags from). The bug was that I removed the code for same from glxClientCallback without noticing that it had the side effect of effectively de-currenting those contexts, so that ContextGone could free them. So, if you had a client exit with a context still current, the context's memory would leak. Not a huge deal for direct clients, but viciously bad for indirect, since the swrast context state at the bottom of Mesa is like 15M. Fix this by promoting Bool isCurrent to ClientPtr currentClient, so that we have a back-pointer to chase when walking the list of contexts when ClientStateGone happens. v2: Explicitly call __glXFreeContext on the ClientStateGone path. Our current context might be one we got from EXT_import_context and whose creating client has since died. Without the explicit call, the creating client's FreeClientResources would not free the context because it's still current, and the using client's FreeClientResources would not free the context because it's not an XID it created. This matches the logic from a48dadc. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Signed-off-by: Adam Jackson <ajax@redhat.com>
2013-08-03 15:47:55 +02:00
__glXRemoveFromContextList(cx);
free(cx->feedbackBuf);
free(cx->selectBuf);
if (cx == lastGLContext) {
lastGLContext = NULL;
2003-11-14 17:48:57 +01:00
}
2006-03-12 01:11:34 +01: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. */
if (!glxBlockClients) {
cx->destroy(cx);
}
else {
cx->next = glxPendingDestroyContexts;
glxPendingDestroyContexts = cx;
}
2006-03-12 01:11:34 +01:00
2003-11-14 17:48:57 +01: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.
*/
void
__glXErrorCallBack(GLenum code)
2003-11-14 17:48:57 +01:00
{
errorOccured = GL_TRUE;
}
/*
** Clear the error flag before calling the GL command.
*/
void
__glXClearErrorOccured(void)
2003-11-14 17:48:57 +01:00
{
errorOccured = GL_FALSE;
}
/*
** Check if the GL command caused an error.
*/
GLboolean
__glXErrorOccured(void)
2003-11-14 17:48:57 +01:00
{
return errorOccured;
}
static int __glXErrorBase;
int __glXEventBase;
int
__glXError(int error)
{
return __glXErrorBase + error;
}
__GLXclientState *
glxGetClient(ClientPtr pClient)
{
return dixLookupPrivate(&pClient->devPrivates, glxClientPrivateKey);
}
static void
glxClientCallback(CallbackListPtr *list, void *closure, void *data)
{
NewClientInfoRec *clientinfo = (NewClientInfoRec *) data;
ClientPtr pClient = clientinfo->client;
__GLXclientState *cl = glxGetClient(pClient);
glx: Fix memory leak in context garbage collection (v2) I broke this, back in: commit a48dadc98a28c969741979b70b7a639f24f4cbbd Author: Adam Jackson <ajax@redhat.com> Date: Mon Mar 21 11:59:29 2011 -0400 glx: Reimplement context tags In that, I changed the glx client state to not explicitly track the list of current contexts for the client (since that was what we were deriving tags from). The bug was that I removed the code for same from glxClientCallback without noticing that it had the side effect of effectively de-currenting those contexts, so that ContextGone could free them. So, if you had a client exit with a context still current, the context's memory would leak. Not a huge deal for direct clients, but viciously bad for indirect, since the swrast context state at the bottom of Mesa is like 15M. Fix this by promoting Bool isCurrent to ClientPtr currentClient, so that we have a back-pointer to chase when walking the list of contexts when ClientStateGone happens. v2: Explicitly call __glXFreeContext on the ClientStateGone path. Our current context might be one we got from EXT_import_context and whose creating client has since died. Without the explicit call, the creating client's FreeClientResources would not free the context because it's still current, and the using client's FreeClientResources would not free the context because it's not an XID it created. This matches the logic from a48dadc. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Signed-off-by: Adam Jackson <ajax@redhat.com>
2013-08-03 15:47:55 +02:00
__GLXcontext *c, *next;
switch (pClient->clientState) {
case ClientStateRunning:
cl->client = pClient;
break;
case ClientStateGone:
glx: Fix memory leak in context garbage collection (v2) I broke this, back in: commit a48dadc98a28c969741979b70b7a639f24f4cbbd Author: Adam Jackson <ajax@redhat.com> Date: Mon Mar 21 11:59:29 2011 -0400 glx: Reimplement context tags In that, I changed the glx client state to not explicitly track the list of current contexts for the client (since that was what we were deriving tags from). The bug was that I removed the code for same from glxClientCallback without noticing that it had the side effect of effectively de-currenting those contexts, so that ContextGone could free them. So, if you had a client exit with a context still current, the context's memory would leak. Not a huge deal for direct clients, but viciously bad for indirect, since the swrast context state at the bottom of Mesa is like 15M. Fix this by promoting Bool isCurrent to ClientPtr currentClient, so that we have a back-pointer to chase when walking the list of contexts when ClientStateGone happens. v2: Explicitly call __glXFreeContext on the ClientStateGone path. Our current context might be one we got from EXT_import_context and whose creating client has since died. Without the explicit call, the creating client's FreeClientResources would not free the context because it's still current, and the using client's FreeClientResources would not free the context because it's not an XID it created. This matches the logic from a48dadc. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Signed-off-by: Adam Jackson <ajax@redhat.com>
2013-08-03 15:47:55 +02:00
/* detach from all current contexts */
for (c = glxAllContexts; c; c = next) {
next = c->next;
if (c->currentClient == pClient) {
c->loseCurrent(c);
lastGLContext = NULL;
glx: Fix memory leak in context garbage collection (v2) I broke this, back in: commit a48dadc98a28c969741979b70b7a639f24f4cbbd Author: Adam Jackson <ajax@redhat.com> Date: Mon Mar 21 11:59:29 2011 -0400 glx: Reimplement context tags In that, I changed the glx client state to not explicitly track the list of current contexts for the client (since that was what we were deriving tags from). The bug was that I removed the code for same from glxClientCallback without noticing that it had the side effect of effectively de-currenting those contexts, so that ContextGone could free them. So, if you had a client exit with a context still current, the context's memory would leak. Not a huge deal for direct clients, but viciously bad for indirect, since the swrast context state at the bottom of Mesa is like 15M. Fix this by promoting Bool isCurrent to ClientPtr currentClient, so that we have a back-pointer to chase when walking the list of contexts when ClientStateGone happens. v2: Explicitly call __glXFreeContext on the ClientStateGone path. Our current context might be one we got from EXT_import_context and whose creating client has since died. Without the explicit call, the creating client's FreeClientResources would not free the context because it's still current, and the using client's FreeClientResources would not free the context because it's not an XID it created. This matches the logic from a48dadc. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Signed-off-by: Adam Jackson <ajax@redhat.com>
2013-08-03 15:47:55 +02:00
c->currentClient = NULL;
FreeResourceByType(c->id, __glXContextRes, FALSE);
glx: Fix memory leak in context garbage collection (v2) I broke this, back in: commit a48dadc98a28c969741979b70b7a639f24f4cbbd Author: Adam Jackson <ajax@redhat.com> Date: Mon Mar 21 11:59:29 2011 -0400 glx: Reimplement context tags In that, I changed the glx client state to not explicitly track the list of current contexts for the client (since that was what we were deriving tags from). The bug was that I removed the code for same from glxClientCallback without noticing that it had the side effect of effectively de-currenting those contexts, so that ContextGone could free them. So, if you had a client exit with a context still current, the context's memory would leak. Not a huge deal for direct clients, but viciously bad for indirect, since the swrast context state at the bottom of Mesa is like 15M. Fix this by promoting Bool isCurrent to ClientPtr currentClient, so that we have a back-pointer to chase when walking the list of contexts when ClientStateGone happens. v2: Explicitly call __glXFreeContext on the ClientStateGone path. Our current context might be one we got from EXT_import_context and whose creating client has since died. Without the explicit call, the creating client's FreeClientResources would not free the context because it's still current, and the using client's FreeClientResources would not free the context because it's not an XID it created. This matches the logic from a48dadc. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Signed-off-by: Adam Jackson <ajax@redhat.com>
2013-08-03 15:47:55 +02:00
}
}
free(cl->returnBuf);
free(cl->largeCmdBuf);
free(cl->GLClientextensions);
break;
default:
break;
}
}
2003-11-14 17:48:57 +01:00
/************************************************************************/
static __GLXprovider *__glXProviderStack;
void
GlxPushProvider(__GLXprovider * provider)
{
provider->next = __glXProviderStack;
__glXProviderStack = provider;
}
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;
}
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;
}
}
2003-11-14 17:48:57 +01:00
/*
** Initialize the GLX extension.
*/
void
GlxExtensionInit(void)
2003-11-14 17:48:57 +01:00
{
ExtensionEntry *extEntry;
ScreenPtr pScreen;
2003-11-14 17:48:57 +01:00
int i;
__GLXprovider *p, **stack;
Bool glx_provided = False;
if (serverGeneration == 1) {
for (stack = &__glXProviderStack; *stack; stack = &(*stack)->next)
;
*stack = &__glXDRISWRastProvider;
}
/* Mesa requires at least one True/DirectColor visual */
if (!checkScreenVisuals())
return;
__glXContextRes = CreateNewResourceType((DeleteType) ContextGone,
"GLXContext");
__glXDrawableRes = CreateNewResourceType((DeleteType) DrawableGone,
"GLXDrawable");
if (!__glXContextRes || !__glXDrawableRes)
return;
SetResourceTypeSizeFunc(__glXDrawableRes, GetGLXDrawableBytes);
if (!dixRegisterPrivateKey
(&glxClientPrivateKeyRec, PRIVATE_CLIENT, sizeof(__GLXclientState)))
return;
if (!AddCallback(&ClientStateCallback, glxClientCallback, 0))
return;
for (i = 0; i < screenInfo.numScreens; i++) {
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;
}
/* don't register extension if GL is not provided on any screen */
if (!glx_provided)
return;
2003-11-14 17:48:57 +01:00
/*
** Add extension to server extensions.
*/
2003-11-14 17:48:57 +01:00
extEntry = AddExtension(GLX_EXTENSION_NAME, __GLX_NUMBER_EVENTS,
__GLX_NUMBER_ERRORS, __glXDispatch,
__glXDispatch, ResetExtension, StandardMinorOpcode);
2003-11-14 17:48:57 +01:00
if (!extEntry) {
FatalError("__glXExtensionInit: AddExtensions failed\n");
return;
2003-11-14 17:48:57 +01:00
}
__glXErrorBase = extEntry->errorBase;
__glXEventBase = extEntry->eventBase;
#if PRESENT
__glXregisterPresentCompleteNotify();
#endif
2003-11-14 17:48:57 +01: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 *).
*/
__GLXcontext *
__glXForceCurrent(__GLXclientState * cl, GLXContextTag tag, int *error)
2003-11-14 17:48:57 +01:00
{
__GLXcontext *cx;
/*
** See if the context tag is legal; it is managed by the extension,
** so if it's invalid, we have an implementation error.
*/
cx = __glXLookupContextByTag(cl, tag);
2003-11-14 17:48:57 +01:00
if (!cx) {
cl->client->errorValue = tag;
*error = __glXError(GLXBadContextTag);
return 0;
2003-11-14 17:48:57 +01:00
}
if (!cx->isDirect) {
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;
}
2003-11-14 17:48:57 +01:00
}
if (cx->wait && (*cx->wait) (cx, cl, error))
return NULL;
if (cx == lastGLContext) {
/* No need to re-bind */
return cx;
2003-11-14 17:48:57 +01:00
}
/* Make this context the current one for the GL. */
if (!cx->isDirect) {
/*
* 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);
lastGLContext = cx;
if (!(*cx->makeCurrent) (cx)) {
/* Bind failed, and set the error code. Bummer */
lastGLContext = NULL;
cl->client->errorValue = cx->id;
*error = __glXError(GLXBadContextState);
return 0;
}
2003-11-14 17:48:57 +01:00
}
return cx;
}
/************************************************************************/
void
glxSuspendClients(void)
{
int i;
2006-03-12 01:11:34 +01:00
for (i = 1; i < currentMaxClients; i++) {
if (clients[i] && glxGetClient(clients[i])->inUse)
IgnoreClient(clients[i]);
}
glxBlockClients = TRUE;
}
void
glxResumeClients(void)
{
__GLXcontext *cx, *next;
int i;
glxBlockClients = FALSE;
for (i = 1; i < currentMaxClients; i++) {
if (clients[i] && glxGetClient(clients[i])->inUse)
AttendClient(clients[i]);
}
for (cx = glxPendingDestroyContexts; cx != NULL; cx = next) {
next = cx->next;
cx->destroy(cx);
}
glxPendingDestroyContexts = NULL;
}
2006-03-12 01:11:34 +01: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)
{
void *ret = (void *) _get_proc_address(proc);
return ret ? ret : (void *) NoopDDA;
}
2003-11-14 17:48:57 +01:00
/*
** Top level dispatcher; all commands are executed from here down.
*/
static int
__glXDispatch(ClientPtr client)
2003-11-14 17:48:57 +01:00
{
REQUEST(xGLXSingleReq);
CARD8 opcode;
__GLXdispatchSingleProcPtr proc;
2003-11-14 17:48:57 +01:00
__GLXclientState *cl;
2006-03-12 01:11:34 +01:00
int retval;
2003-11-14 17:48:57 +01:00
opcode = stuff->glxCode;
cl = glxGetClient(client);
/* Mark it in use so we suspend it on VT switch. */
cl->inUse = TRUE;
2003-11-14 17:48:57 +01:00
/*
** If we're expecting a glXRenderLarge request, this better be one.
*/
2003-11-14 17:48:57 +01:00
if ((cl->largeCmdRequestsSoFar != 0) && (opcode != X_GLXRenderLarge)) {
client->errorValue = stuff->glxCode;
return __glXError(GLXBadLargeRequest);
2003-11-14 17:48:57 +01:00
}
/* If we're currently blocking GLX clients, just put this guy to
* sleep, reset the request and return. */
if (glxBlockClients) {
ResetCurrentRequest(client);
client->sequence--;
IgnoreClient(client);
return Success;
}
2003-11-14 17:48:57 +01:00
/*
** Use the opcode to index into the procedure table.
*/
proc = __glXGetProtocolDecodeFunction(&Single_dispatch_info, opcode,
client->swapped);
if (proc != NULL) {
retval = (*proc) (cl, (GLbyte *) stuff);
}
else {
retval = BadRequest;
}
2006-03-12 01:11:34 +01:00
return retval;
2003-11-14 17:48:57 +01:00
}