[PATCH xserver 4/5] glx: Use vnd layer for dispatch
Adam Jackson
ajax at redhat.com
Wed Aug 30 18:58:27 UTC 2017
The big change here is MakeCurrent and context tag tracking. We now
delegate context tags entirely to the vnd layer, and simply store a
pointer to the context state as the tag data. If a context is deleted
while it's current, we allocate a fake ID for the context and move the
context state there, so the tag data still points to a real context. As
a result we can stop trying to hard to detach the client from contexts
at disconnect time and just let resource destruction handle it.
Since vnd handles all the MakeCurrent protocol now, our request handlers
for it can just be return BadImplementation.
We also remove a bunch of LEGAL_NEW_RESOURCE, because now by the time
we're called vnd has already allocated its tracking resource on that
XID. Note that we only do this for core GLX requests, for vendor private
requests we still need to call LEGAL_NEW_RESOURCE and in addition need
to call up to addXIDMap and friends.
Signed-off-by: Adam Jackson <ajax at redhat.com>
---
glx/createcontext.c | 2 -
glx/glxcmds.c | 230 +++++++++++++--------------------
glx/glxcmdsswap.c | 44 +------
glx/glxext.c | 295 ++++++++++++++++++++++++++++++-------------
glx/glxext.h | 6 +
glx/glxscreens.h | 2 +
hw/kdrive/ephyr/ephyr.c | 6 +-
hw/kdrive/ephyr/meson.build | 1 +
hw/vfb/InitOutput.c | 5 +
hw/vfb/meson.build | 3 +-
hw/xfree86/common/xf86Init.c | 2 +-
hw/xquartz/darwin.c | 4 +
hw/xwayland/meson.build | 1 +
hw/xwayland/xwayland.c | 5 +
hw/xwin/winscrinit.c | 9 ++
include/glx_extinit.h | 2 +-
16 files changed, 343 insertions(+), 274 deletions(-)
diff --git a/glx/createcontext.c b/glx/createcontext.c
index 1216f9412b..b1b05bb7f9 100644
--- a/glx/createcontext.c
+++ b/glx/createcontext.c
@@ -123,8 +123,6 @@ __glXDisp_CreateContextAttribsARB(__GLXclientState * cl, GLbyte * pc)
if (req->length != expected_size)
return BadLength;
- LEGAL_NEW_RESOURCE(req->context, client);
-
/* The GLX_ARB_create_context spec says:
*
* "* If <config> is not a valid GLXFBConfig, GLXBadFBConfig is
diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index 241abc6a58..544fd284dc 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -46,6 +46,7 @@
#include "indirect_table.h"
#include "indirect_util.h"
#include "protocol-versions.h"
+#include "glxvndabi.h"
static char GLXServerVendorName[] = "SGI";
@@ -134,6 +135,10 @@ _X_HIDDEN int
validGlxContext(ClientPtr client, XID id, int access_mode,
__GLXcontext ** context, int *err)
{
+ /* no ghost contexts */
+ if (id & SERVER_BIT)
+ return FALSE;
+
*err = dixLookupResourceByType((void **) context, id,
__glXContextRes, client, access_mode);
if (*err != Success || (*context)->idExists == GL_FALSE) {
@@ -238,8 +243,6 @@ DoCreateContext(__GLXclientState * cl, GLXContextID gcId,
__GLXcontext *glxc, *shareglxc;
int err;
- LEGAL_NEW_RESOURCE(gcId, client);
-
/*
** Find the display list space that we want to share.
**
@@ -402,14 +405,22 @@ __glXDisp_CreateContextWithConfigSGIX(__GLXclientState * cl, GLbyte * pc)
int err;
REQUEST_SIZE_MATCH(xGLXCreateContextWithConfigSGIXReq);
+ LEGAL_NEW_RESOURCE(req->context, client);
if (!validGlxScreen(cl->client, req->screen, &pGlxScreen, &err))
return err;
if (!validGlxFBConfig(cl->client, pGlxScreen, req->fbconfig, &config, &err))
return err;
- return DoCreateContext(cl, req->context, req->shareList,
- config, pGlxScreen, req->isDirect);
+ if (!glxServer.addXIDMap(req->context, pGlxScreen->vendor))
+ return BadAlloc;
+
+ err = DoCreateContext(cl, req->context, req->shareList,
+ config, pGlxScreen, req->isDirect);
+ if (err != Success)
+ glxServer.removeXIDMap(req->context);
+
+ return err;
}
int
@@ -427,50 +438,25 @@ __glXDisp_DestroyContext(__GLXclientState * cl, GLbyte * pc)
return err;
glxc->idExists = GL_FALSE;
- if (!glxc->currentClient)
- FreeResourceByType(req->context, __glXContextRes, FALSE);
+ if (glxc->currentClient) {
+ XID ghost = FakeClientID(glxc->currentClient->index);
+
+ if (!AddResource(ghost, __glXContextRes, glxc))
+ return BadAlloc;
+ ChangeResourceValue(glxc->id, __glXContextRes, NULL);
+ }
+
+ FreeResourceByType(req->context, __glXContextRes, FALSE);
return Success;
}
-/*
- * This will return "deleted" contexts, ie, where idExists is GL_FALSE.
- * Contrast validGlxContext, which will not. We're cheating here and
- * using the XID as the context tag, which is fine as long as we defer
- * actually destroying the context until it's no longer referenced, and
- * block clients from trying to MakeCurrent on contexts that are on the
- * way to destruction. Notice that DoMakeCurrent calls validGlxContext
- * for new contexts but __glXLookupContextByTag for previous contexts.
- */
__GLXcontext *
__glXLookupContextByTag(__GLXclientState * cl, GLXContextTag tag)
{
- __GLXcontext *ret;
-
- if (dixLookupResourceByType((void **) &ret, tag, __glXContextRes,
- cl->client, DixUseAccess) == Success)
- return ret;
-
- return NULL;
-}
-
-/*****************************************************************************/
-
-static void
-StopUsingContext(__GLXcontext * glxc)
-{
- if (glxc) {
- glxc->currentClient = NULL;
- if (!glxc->idExists) {
- FreeResourceByType(glxc->id, __glXContextRes, FALSE);
- }
- }
-}
-
-static void
-StartUsingContext(__GLXclientState * cl, __GLXcontext * glxc)
-{
- glxc->currentClient = cl->client;
+ __GLXcontext *ret = NULL;
+ glxServer.getContextTag(cl->client, tag, NULL, (void **)&ret);
+ return ret;
}
/**
@@ -549,14 +535,14 @@ __glXGetDrawable(__GLXcontext * glxc, GLXDrawable drawId, ClientPtr client,
** Make an OpenGL context and drawable current.
*/
-static int
-DoMakeCurrent(__GLXclientState * cl,
- GLXDrawable drawId, GLXDrawable readId,
- GLXContextID contextId, GLXContextTag tag)
+int
+xorgGlxMakeCurrent(ClientPtr client, GLXContextTag tag,
+ void *oldContextTagData, XID drawId, XID readId,
+ XID contextId, GLXContextTag newContextTag,
+ void **newContextTagData)
{
- ClientPtr client = cl->client;
- xGLXMakeCurrentReply reply;
- __GLXcontext *glxc, *prevglxc;
+ __GLXclientState *cl = glxGetClient(client);
+ __GLXcontext *glxc = NULL, *prevglxc = oldContextTagData;
__GLXdrawable *drawPriv = NULL;
__GLXdrawable *readPriv = NULL;
int error;
@@ -569,39 +555,27 @@ DoMakeCurrent(__GLXclientState * cl,
if ((drawId == None) != (readId == None))
return BadMatch;
- /*
- ** Lookup old context. If we have one, it must be in a usable state.
- */
+ /* Look up old context. If we have one, it must be in a usable state. */
if (tag != 0) {
- prevglxc = __glXLookupContextByTag(cl, tag);
- if (!prevglxc) {
- /*
- ** Tag for previous context is invalid.
- */
+ if (!prevglxc)
return __glXError(GLXBadContextTag);
- }
+
if (prevglxc->renderMode != GL_RENDER) {
/* Oops. Not in render mode render. */
client->errorValue = prevglxc->id;
return __glXError(GLXBadContextState);
}
}
- else {
- prevglxc = 0;
- }
- /*
- ** Lookup new context. It must not be current for someone else.
- */
+ /* Look up new context. It must not be current for someone else. */
if (contextId != None) {
int status;
if (!validGlxContext(client, contextId, DixUseAccess, &glxc, &error))
return error;
- if ((glxc != prevglxc) && glxc->currentClient) {
- /* Context is current to somebody else */
+
+ if ((glxc != prevglxc) && glxc->currentClient)
return BadAccess;
- }
if (drawId) {
drawPriv = __glXGetDrawable(glxc, drawId, client, &status);
@@ -614,38 +588,25 @@ DoMakeCurrent(__GLXclientState * cl,
if (readPriv == NULL)
return status;
}
- } else {
- /* Switching to no context. Ignore new drawable. */
-
- glxc = 0;
- drawPriv = 0;
- readPriv = 0;
}
if (prevglxc) {
- /*
- ** Flush the previous context if needed.
- */
+ /* Flush the previous context if needed. */
Bool need_flush = GL_TRUE;
#ifdef GLX_CONTEXT_RELEASE_BEHAVIOR_ARB
if (prevglxc->releaseBehavior == GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB)
need_flush = GL_FALSE;
#endif
if (need_flush) {
- if (__glXForceCurrent(cl, tag, (int *) &error)) {
- glFlush();
- }
- else {
+ if (!__glXForceCurrent(cl, tag, (int *) &error))
return error;
- }
+ glFlush();
}
- /*
- ** Make the previous context not current.
- */
- if (!(*prevglxc->loseCurrent) (prevglxc)) {
+ /* Make the previous context not current. */
+ if (!(*prevglxc->loseCurrent) (prevglxc))
return __glXError(GLXBadContext);
- }
+
lastGLContext = NULL;
if (!prevglxc->isDirect) {
prevglxc->drawPriv = NULL;
@@ -653,8 +614,7 @@ DoMakeCurrent(__GLXclientState * cl,
}
}
- if ((glxc != 0) && !glxc->isDirect) {
-
+ if (glxc && !glxc->isDirect) {
glxc->drawPriv = drawPriv;
glxc->readPriv = readPriv;
@@ -668,66 +628,36 @@ DoMakeCurrent(__GLXclientState * cl,
}
glxc->currentClient = client;
+ if (newContextTagData)
+ *newContextTagData = glxc;
}
- StopUsingContext(prevglxc);
-
- reply = (xGLXMakeCurrentReply) {
- .type = X_Reply,
- .sequenceNumber = client->sequence,
- .length = 0,
- .contextTag = 0
- };
-
- if (glxc) {
- StartUsingContext(cl, glxc);
- reply.contextTag = glxc->id;
+ if (prevglxc) {
+ prevglxc->currentClient = NULL;
+ if (!prevglxc->idExists) {
+ FreeResourceByType(prevglxc->id, __glXContextRes, FALSE);
+ }
}
- if (client->swapped) {
- __GLX_DECLARE_SWAP_VARIABLES;
- __GLX_SWAP_SHORT(&reply.sequenceNumber);
- __GLX_SWAP_INT(&reply.length);
- __GLX_SWAP_INT(&reply.contextTag);
- }
- WriteToClient(client, sz_xGLXMakeCurrentReply, &reply);
return Success;
}
int
__glXDisp_MakeCurrent(__GLXclientState * cl, GLbyte * pc)
{
- ClientPtr client = cl->client;
- xGLXMakeCurrentReq *req = (xGLXMakeCurrentReq *) pc;
-
- REQUEST_SIZE_MATCH(xGLXMakeCurrentReq);
-
- return DoMakeCurrent(cl, req->drawable, req->drawable,
- req->context, req->oldContextTag);
+ return BadImplementation;
}
int
__glXDisp_MakeContextCurrent(__GLXclientState * cl, GLbyte * pc)
{
- ClientPtr client = cl->client;
- xGLXMakeContextCurrentReq *req = (xGLXMakeContextCurrentReq *) pc;
-
- REQUEST_SIZE_MATCH(xGLXMakeContextCurrentReq);
-
- return DoMakeCurrent(cl, req->drawable, req->readdrawable,
- req->context, req->oldContextTag);
+ return BadImplementation;
}
int
__glXDisp_MakeCurrentReadSGI(__GLXclientState * cl, GLbyte * pc)
{
- ClientPtr client = cl->client;
- xGLXMakeCurrentReadSGIReq *req = (xGLXMakeCurrentReadSGIReq *) pc;
-
- REQUEST_SIZE_MATCH(xGLXMakeCurrentReadSGIReq);
-
- return DoMakeCurrent(cl, req->drawable, req->readable,
- req->context, req->oldContextTag);
+ return BadImplementation;
}
int
@@ -1253,8 +1183,6 @@ DoCreateGLXPixmap(ClientPtr client, __GLXscreen * pGlxScreen,
DrawablePtr pDraw;
int err;
- LEGAL_NEW_RESOURCE(glxDrawableId, client);
-
err = dixLookupDrawable(&pDraw, drawableId, client, 0, DixAddAccess);
if (err != Success) {
client->errorValue = drawableId;
@@ -1380,14 +1308,22 @@ __glXDisp_CreateGLXPixmapWithConfigSGIX(__GLXclientState * cl, GLbyte * pc)
int err;
REQUEST_SIZE_MATCH(xGLXCreateGLXPixmapWithConfigSGIXReq);
+ LEGAL_NEW_RESOURCE(req->glxpixmap, client);
if (!validGlxScreen(cl->client, req->screen, &pGlxScreen, &err))
return err;
if (!validGlxFBConfig(cl->client, pGlxScreen, req->fbconfig, &config, &err))
return err;
- return DoCreateGLXPixmap(cl->client, pGlxScreen,
- config, req->pixmap, req->glxpixmap);
+ if (!glxServer.addXIDMap(req->glxpixmap, pGlxScreen->vendor))
+ return BadAlloc;
+
+ err = DoCreateGLXPixmap(cl->client, pGlxScreen,
+ config, req->pixmap, req->glxpixmap);
+ if (err != Success)
+ glxServer.removeXIDMap(req->glxpixmap);
+
+ return err;
}
static int
@@ -1430,18 +1366,13 @@ __glXDisp_DestroyPixmap(__GLXclientState * cl, GLbyte * pc)
}
static int
-DoCreatePbuffer(ClientPtr client, int screenNum, XID fbconfigId,
+DoCreatePbuffer(ClientPtr client, __GLXscreen *pGlxScreen, XID fbconfigId,
int width, int height, XID glxDrawableId)
{
__GLXconfig *config;
- __GLXscreen *pGlxScreen;
PixmapPtr pPixmap;
int err;
- LEGAL_NEW_RESOURCE(glxDrawableId, client);
-
- if (!validGlxScreen(client, screenNum, &pGlxScreen, &err))
- return err;
if (!validGlxFBConfig(client, pGlxScreen, fbconfigId, &config, &err))
return err;
@@ -1470,6 +1401,7 @@ __glXDisp_CreatePbuffer(__GLXclientState * cl, GLbyte * pc)
xGLXCreatePbufferReq *req = (xGLXCreatePbufferReq *) pc;
CARD32 *attrs;
int width, height, i;
+ __GLXscreen *pGlxScreen;
REQUEST_AT_LEAST_SIZE(xGLXCreatePbufferReq);
if (req->numAttribs > (UINT32_MAX >> 3)) {
@@ -1496,7 +1428,10 @@ __glXDisp_CreatePbuffer(__GLXclientState * cl, GLbyte * pc)
}
}
- return DoCreatePbuffer(cl->client, req->screen, req->fbconfig,
+ if (!validGlxScreen(client, req->screen, &pGlxScreen, &i))
+ return i;
+
+ return DoCreatePbuffer(cl->client, pGlxScreen, req->fbconfig,
width, height, req->pbuffer);
}
@@ -1505,15 +1440,30 @@ __glXDisp_CreateGLXPbufferSGIX(__GLXclientState * cl, GLbyte * pc)
{
ClientPtr client = cl->client;
xGLXCreateGLXPbufferSGIXReq *req = (xGLXCreateGLXPbufferSGIXReq *) pc;
+ __GLXscreen *pGlxScreen;
+ int ret;
REQUEST_AT_LEAST_SIZE(xGLXCreateGLXPbufferSGIXReq);
+ LEGAL_NEW_RESOURCE(req->pbuffer, client);
/*
* We should really handle attributes correctly, but this extension
* is so rare I have difficulty caring.
*/
- return DoCreatePbuffer(cl->client, req->screen, req->fbconfig,
+
+ if (!validGlxScreen(client, req->screen, &pGlxScreen, &ret))
+ return ret;
+
+ if (!glxServer.addXIDMap(req->pbuffer, pGlxScreen->vendor))
+ return BadAlloc;
+
+ ret = DoCreatePbuffer(cl->client, pGlxScreen, req->fbconfig,
req->width, req->height, req->pbuffer);
+
+ if (ret != Success)
+ glxServer.removeXIDMap(req->pbuffer);
+
+ return ret;
}
int
@@ -1624,8 +1574,6 @@ __glXDisp_CreateWindow(__GLXclientState * cl, GLbyte * pc)
}
REQUEST_FIXED_SIZE(xGLXCreateWindowReq, req->numAttribs << 3);
- LEGAL_NEW_RESOURCE(req->glxwindow, client);
-
if (!validGlxScreen(client, req->screen, &pGlxScreen, &err))
return err;
if (!validGlxFBConfig(client, pGlxScreen, req->fbconfig, &config, &err))
diff --git a/glx/glxcmdsswap.c b/glx/glxcmdsswap.c
index 10d84062ed..4874be2635 100644
--- a/glx/glxcmdsswap.c
+++ b/glx/glxcmdsswap.c
@@ -131,57 +131,19 @@ __glXDispSwap_DestroyContext(__GLXclientState * cl, GLbyte * pc)
int
__glXDispSwap_MakeCurrent(__GLXclientState * cl, GLbyte * pc)
{
- ClientPtr client = cl->client;
- xGLXMakeCurrentReq *req = (xGLXMakeCurrentReq *) pc;
-
- __GLX_DECLARE_SWAP_VARIABLES;
-
- REQUEST_SIZE_MATCH(xGLXMakeCurrentReq);
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->drawable);
- __GLX_SWAP_INT(&req->context);
- __GLX_SWAP_INT(&req->oldContextTag);
-
- return __glXDisp_MakeCurrent(cl, pc);
+ return BadImplementation;
}
int
__glXDispSwap_MakeContextCurrent(__GLXclientState * cl, GLbyte * pc)
{
- ClientPtr client = cl->client;
- xGLXMakeContextCurrentReq *req = (xGLXMakeContextCurrentReq *) pc;
-
- __GLX_DECLARE_SWAP_VARIABLES;
-
- REQUEST_SIZE_MATCH(xGLXMakeContextCurrentReq);
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->drawable);
- __GLX_SWAP_INT(&req->readdrawable);
- __GLX_SWAP_INT(&req->context);
- __GLX_SWAP_INT(&req->oldContextTag);
-
- return __glXDisp_MakeContextCurrent(cl, pc);
+ return BadImplementation;
}
int
__glXDispSwap_MakeCurrentReadSGI(__GLXclientState * cl, GLbyte * pc)
{
- ClientPtr client = cl->client;
- xGLXMakeCurrentReadSGIReq *req = (xGLXMakeCurrentReadSGIReq *) pc;
-
- __GLX_DECLARE_SWAP_VARIABLES;
-
- REQUEST_SIZE_MATCH(xGLXMakeCurrentReadSGIReq);
-
- __GLX_SWAP_SHORT(&req->length);
- __GLX_SWAP_INT(&req->drawable);
- __GLX_SWAP_INT(&req->readable);
- __GLX_SWAP_INT(&req->context);
- __GLX_SWAP_INT(&req->oldContextTag);
-
- return __glXDisp_MakeCurrentReadSGI(cl, pc);
+ return BadImplementation;
}
int
diff --git a/glx/glxext.c b/glx/glxext.c
index d39fe6d8e0..19d83f43a2 100644
--- a/glx/glxext.c
+++ b/glx/glxext.c
@@ -46,10 +46,12 @@
#include "glxext.h"
#include "indirect_table.h"
#include "indirect_util.h"
+#include "glxvndabi.h"
/*
** X resources.
*/
+static int glxGeneration;
RESTYPE __glXContextRes;
RESTYPE __glXDrawableRes;
@@ -64,15 +66,6 @@ static int __glXDispatch(ClientPtr);
static GLboolean __glXFreeContext(__GLXcontext * cx);
/*
-** Called when the extension is reset.
-*/
-static void
-ResetExtension(ExtensionEntry * extEntry)
-{
- lastGLContext = NULL;
-}
-
-/*
** Reset state used to keep track of large (multi-request) commands.
*/
void
@@ -86,16 +79,18 @@ __glXResetLargeCommandStatus(__GLXclientState * cl)
/*
* 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.
+ * OR when glXDestroyContext is called. If the context is current for a client
+ * the dispatch layer will have moved the context struct to a fake resource ID
+ * and cx here will be NULL. Otherwise we really free the context.
*/
static int
ContextGone(__GLXcontext * cx, XID id)
{
- cx->idExists = GL_FALSE;
- if (!cx->currentClient) {
+ if (!cx)
+ return TRUE;
+
+ if (!cx->currentClient)
__glXFreeContext(cx);
- }
return TRUE;
}
@@ -286,7 +281,6 @@ glxClientCallback(CallbackListPtr *list, void *closure, void *data)
c->loseCurrent(c);
lastGLContext = NULL;
c->currentClient = NULL;
- FreeResourceByType(c->id, __glXContextRes, FALSE);
}
}
@@ -303,15 +297,6 @@ glxClientCallback(CallbackListPtr *list, void *closure, void *data)
/************************************************************************/
-static __GLXprovider *__glXProviderStack;
-
-void
-GlxPushProvider(__GLXprovider * provider)
-{
- provider->next = __glXProviderStack;
- __glXProviderStack = provider;
-}
-
static Bool
checkScreenVisuals(void)
{
@@ -346,86 +331,224 @@ GetGLXDrawableBytes(void *value, XID id, ResourceSizePtr size)
}
}
-/*
-** Initialize the GLX extension.
-*/
-void
-GlxExtensionInit(void)
+typedef struct xorgVendorInitClosure {
+ ScreenPtr screen;
+ __GLXprovider *provider;
+ GlxServerVendor *vendor;
+} xorgVendorInitClosure;
+
+static void
+xorgGlxCloseExtension(const ExtensionEntry *extEntry)
{
- ExtensionEntry *extEntry;
- ScreenPtr pScreen;
- int i;
- __GLXprovider *p, **stack;
- Bool glx_provided = FALSE;
+ lastGLContext = NULL;
+}
- if (serverGeneration == 1) {
- for (stack = &__glXProviderStack; *stack; stack = &(*stack)->next)
- ;
- *stack = &__glXDRISWRastProvider;
- }
+static int
+xorgGlxHandleRequest(ClientPtr client)
+{
+ return __glXDispatch(client);
+}
- /* Mesa requires at least one True/DirectColor visual */
- if (!checkScreenVisuals())
- return;
+static ScreenPtr
+screenNumToScreen(int screen)
+{
+ if (screen < 0 || screen >= screenInfo.numScreens)
+ return NULL;
- __glXContextRes = CreateNewResourceType((DeleteType) ContextGone,
- "GLXContext");
- __glXDrawableRes = CreateNewResourceType((DeleteType) DrawableGone,
- "GLXDrawable");
- if (!__glXContextRes || !__glXDrawableRes)
- return;
+ return screenInfo.screens[screen];
+}
- SetResourceTypeSizeFunc(__glXDrawableRes, GetGLXDrawableBytes);
+static int
+maybe_swap32(ClientPtr client, int x)
+{
+ return client->swapped ? bswap_32(x) : x;
+}
- if (!dixRegisterPrivateKey
- (&glxClientPrivateKeyRec, PRIVATE_CLIENT, sizeof(__GLXclientState)))
- return;
- if (!AddCallback(&ClientStateCallback, glxClientCallback, 0))
- return;
+static GlxServerVendor *
+vendorForScreen(ClientPtr client, int screen)
+{
+ screen = maybe_swap32(client, screen);
- for (i = 0; i < screenInfo.numScreens; i++) {
- pScreen = screenInfo.screens[i];
+ return glxServer.getVendorForScreen(client, screenNumToScreen(screen));
+}
- for (p = __glXProviderStack; p != NULL; p = p->next) {
- __GLXscreen *glxScreen;
+/* could this be generated? */
+static int
+xorgGlxThunkRequest(ClientPtr client)
+{
+ REQUEST(xGLXVendorPrivateReq);
+ CARD32 vendorCode = maybe_swap32(client, stuff->vendorCode);
+ GlxServerVendor *vendor = NULL;
+
+ switch (vendorCode) {
+ case X_GLXvop_QueryContextInfoEXT: {
+ xGLXQueryContextInfoEXTReq *req = (void *)stuff;
+ if (!(vendor = glxServer.getXIDMap(maybe_swap32(client, req->context))))
+ return __glXError(GLXBadContext);
+ break;
+ }
- glxScreen = p->screenProbe(pScreen);
- if (glxScreen != NULL) {
- LogMessage(X_INFO,
- "GLX: Initialized %s GL provider for screen %d\n",
- p->name, i);
- break;
- }
+ case X_GLXvop_GetFBConfigsSGIX: {
+ xGLXGetFBConfigsSGIXReq *req = (void *)stuff;
+ if (!(vendor = vendorForScreen(client, req->screen)))
+ return BadValue;
+ break;
+ }
+ case X_GLXvop_CreateContextWithConfigSGIX: {
+ xGLXCreateContextWithConfigSGIXReq *req = (void *)stuff;
+ if (!(vendor = vendorForScreen(client, req->screen)))
+ return BadValue;
+ break;
}
- if (!p)
- LogMessage(X_INFO,
- "GLX: no usable GL providers found for screen %d\n", i);
- else
- glx_provided = TRUE;
- }
+ case X_GLXvop_CreateGLXPixmapWithConfigSGIX: {
+ xGLXCreateGLXPixmapWithConfigSGIXReq *req = (void *)stuff;
+ if (!(vendor = vendorForScreen(client, req->screen)))
+ return BadValue;
+ break;
+ }
- /* don't register extension if GL is not provided on any screen */
- if (!glx_provided)
- return;
+ case X_GLXvop_CreateGLXPbufferSGIX: {
+ xGLXCreateGLXPbufferSGIXReq *req = (void *)stuff;
+ if (!(vendor = vendorForScreen(client, req->screen)))
+ return BadValue;
+ break;
+ }
- /*
- ** Add extension to server extensions.
- */
- extEntry = AddExtension(GLX_EXTENSION_NAME, __GLX_NUMBER_EVENTS,
- __GLX_NUMBER_ERRORS, __glXDispatch,
- __glXDispatch, ResetExtension, StandardMinorOpcode);
- if (!extEntry) {
- FatalError("__glXExtensionInit: AddExtensions failed\n");
- return;
+ /* same offset for the drawable for these three */
+ case X_GLXvop_DestroyGLXPbufferSGIX:
+ case X_GLXvop_ChangeDrawableAttributesSGIX:
+ case X_GLXvop_GetDrawableAttributesSGIX: {
+ xGLXGetDrawableAttributesSGIXReq *req = (void *)stuff;
+ if (!(vendor = glxServer.getXIDMap(maybe_swap32(client,
+ req->drawable))))
+ return __glXError(GLXBadDrawable);
+ break;
+ }
+
+ /* most things just use the standard context tag */
+ default:
+ if (!glxServer.getContextTag(client,
+ maybe_swap32(client, stuff->contextTag),
+ &vendor, NULL))
+ return __glXError(GLXBadContextTag);
+ break;
}
- __glXErrorBase = extEntry->errorBase;
- __glXEventBase = extEntry->eventBase;
+ if (!vendor)
+ return BadImplementation;
+
+ return glxServer.forwardRequest(vendor, client);
+}
+
+static GlxServerDispatchProc
+xorgGlxGetDispatchAddress(CARD8 minorOpcode, CARD32 vendorCode)
+{
+ /* we don't support any other GLX opcodes */
+ if (minorOpcode != X_GLXVendorPrivate &&
+ minorOpcode != X_GLXVendorPrivateWithReply)
+ return NULL;
+
+ /* we only support some vendor private requests */
+ if (!__glXGetProtocolDecodeFunction(&VendorPriv_dispatch_info, vendorCode,
+ FALSE))
+ return NULL;
+
+ return xorgGlxThunkRequest;
+}
+
+static Bool
+xorgGlxServerPreInit(const ExtensionEntry *extEntry)
+{
+ if (glxGeneration != serverGeneration) {
+ /* Mesa requires at least one True/DirectColor visual */
+ if (!checkScreenVisuals())
+ return FALSE;
+
+ __glXContextRes = CreateNewResourceType((DeleteType) ContextGone,
+ "GLXContext");
+ __glXDrawableRes = CreateNewResourceType((DeleteType) DrawableGone,
+ "GLXDrawable");
+ if (!__glXContextRes || !__glXDrawableRes)
+ return FALSE;
+
+ if (!dixRegisterPrivateKey
+ (&glxClientPrivateKeyRec, PRIVATE_CLIENT, sizeof(__GLXclientState)))
+ return FALSE;
+ if (!AddCallback(&ClientStateCallback, glxClientCallback, 0))
+ return FALSE;
+
+ __glXErrorBase = extEntry->errorBase;
+ __glXEventBase = extEntry->eventBase;
+
+ SetResourceTypeSizeFunc(__glXDrawableRes, GetGLXDrawableBytes);
#if PRESENT
- __glXregisterPresentCompleteNotify();
+ __glXregisterPresentCompleteNotify();
#endif
+
+ glxGeneration = serverGeneration;
+ }
+
+ return glxGeneration == serverGeneration;
+}
+
+static void
+xorgGlxServerInit(CallbackListPtr *pcbl, void *param, void *ext)
+{
+ const ExtensionEntry *extEntry = ext;
+ xorgVendorInitClosure *closure = param;
+ ScreenPtr screen = closure->screen;
+ __GLXprovider *p = closure->provider;
+ __GLXscreen *s = NULL;
+
+ if (!xorgGlxServerPreInit(extEntry))
+ goto out;
+
+ if (!(s = p->screenProbe(screen)))
+ goto out;
+
+ if (!glxServer.setScreenVendor(screen, closure->vendor))
+ goto out;
+
+out:
+ /* XXX chirp on error */
+ free(param);
+ return;
+}
+
+Bool
+xorgGlxCreateVendor(ScreenPtr pScreen, __GLXprovider *provider)
+{
+ GlxServerVendor *vendor = NULL;
+ GlxServerImports *imports = NULL;
+ xorgVendorInitClosure *closure = NULL;
+
+ /* XXX kind of an fb assumption, wrong for nest/dmx */
+ if (!provider)
+ provider = &__glXDRISWRastProvider;
+
+ imports = glxServer.allocateServerImports();
+ closure = calloc(1, sizeof(xorgVendorInitClosure));
+
+ if (imports && closure) {
+ imports->extensionCloseDown = xorgGlxCloseExtension;
+ imports->handleRequest = xorgGlxHandleRequest;
+ imports->getDispatchAddress = xorgGlxGetDispatchAddress;
+ imports->makeCurrent = xorgGlxMakeCurrent;
+ closure->screen = pScreen;
+ closure->provider = provider;
+ closure->vendor = glxServer.createVendor(imports);
+ if (closure->vendor) {
+ return AddCallback(glxServer.extensionInitCallback,
+ xorgGlxServerInit, closure);
+ }
+ } else {
+ glxServer.freeServerImports(imports);
+ free(closure);
+ }
+
+ return !!vendor;
}
/************************************************************************/
diff --git a/glx/glxext.h b/glx/glxext.h
index cde0e15199..2db5d4a7fb 100644
--- a/glx/glxext.h
+++ b/glx/glxext.h
@@ -62,4 +62,10 @@ extern void __glXResetLargeCommandStatus(__GLXclientState *);
extern const char GLServerVersion[];
extern int DoGetString(__GLXclientState * cl, GLbyte * pc, GLboolean need_swap);
+extern int
+xorgGlxMakeCurrent(ClientPtr client, GLXContextTag tag,
+ void *oldContextTagData, XID drawId, XID readId,
+ XID contextId, GLXContextTag newContextTag,
+ void **newContextTagData);
+
#endif /* _glxext_h_ */
diff --git a/glx/glxscreens.h b/glx/glxscreens.h
index 0f9a2b9afc..207e4b394d 100644
--- a/glx/glxscreens.h
+++ b/glx/glxscreens.h
@@ -36,6 +36,7 @@
*/
#include "extension_string.h"
+#include "glxvndabi.h"
typedef struct __GLXconfig __GLXconfig;
struct __GLXconfig {
@@ -131,6 +132,7 @@ struct __GLXscreen {
int (*swapInterval) (__GLXdrawable * drawable, int interval);
ScreenPtr pScreen;
+ GlxServerVendor *vendor;
/* Linked list of valid fbconfigs for this screen. */
__GLXconfig *fbconfigs;
diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index d064f51546..bead9306d5 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -40,7 +40,7 @@
#include "glamor.h"
#endif
#include "ephyr_glamor_glx.h"
-
+#include "glx_extinit.h"
#include "xkbsrv.h"
extern Bool ephyr_glamor;
@@ -696,6 +696,10 @@ ephyrFinishInitScreen(ScreenPtr pScreen)
if (!ephyrRandRInit(pScreen))
return FALSE;
#endif
+#ifdef GLXEXT
+ if (!noGlxExtension)
+ xorgGlxCreateVendor(pScreen, NULL);
+#endif
scrpriv->BlockHandler = pScreen->BlockHandler;
pScreen->BlockHandler = ephyrScreenBlockHandler;
diff --git a/hw/kdrive/ephyr/meson.build b/hw/kdrive/ephyr/meson.build
index 615649865c..7b9225f26c 100644
--- a/hw/kdrive/ephyr/meson.build
+++ b/hw/kdrive/ephyr/meson.build
@@ -56,6 +56,7 @@ executable(
libxserver_xkb_stubs,
libxserver_xi_stubs,
libxserver_glx,
+ libglxvnd,
],
install: true,
)
diff --git a/hw/vfb/InitOutput.c b/hw/vfb/InitOutput.c
index 6d386ee2f1..819bbf3efb 100644
--- a/hw/vfb/InitOutput.c
+++ b/hw/vfb/InitOutput.c
@@ -934,6 +934,11 @@ vfbScreenInit(ScreenPtr pScreen, int argc, char **argv)
if (!vfbRandRInit(pScreen))
return FALSE;
+#ifdef GLXEXT
+ if (!noGlxExtension)
+ xorgGlxCreateVendor(pScreen, NULL);
+#endif
+
pScreen->InstallColormap = vfbInstallColormap;
pScreen->SaveScreen = vfbSaveScreen;
diff --git a/hw/vfb/meson.build b/hw/vfb/meson.build
index 6566b45907..75a9ca5082 100644
--- a/hw/vfb/meson.build
+++ b/hw/vfb/meson.build
@@ -15,7 +15,8 @@ executable(
libxserver,
libxserver_xkb_stubs,
libxserver_xi_stubs,
- libxserver_glx
+ libxserver_glx,
+ libglxvnd,
],
install: true,
)
diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index 994b63b430..df0d853298 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -77,7 +77,7 @@
#include "xf86Xinput.h"
#include "xf86InPriv.h"
#include "picturestr.h"
-
+#include "glxvndabi.h"
#include "xf86Bus.h"
#ifdef XSERVER_LIBPCIACCESS
#include "xf86VGAarbiter.h"
diff --git a/hw/xquartz/darwin.c b/hw/xquartz/darwin.c
index 36c149cbab..bf7e249b22 100644
--- a/hw/xquartz/darwin.c
+++ b/hw/xquartz/darwin.c
@@ -271,6 +271,10 @@ DarwinScreenInit(ScreenPtr pScreen, int argc, char **argv)
#ifdef MITSHM
ShmRegisterFbFuncs(pScreen);
#endif
+#ifdef GLXEXT
+ if (!noGlxExtension)
+ xorgGlxCreateVendor(pScreen, NULL);
+#endif
// this must be initialized (why doesn't X have a default?)
pScreen->SaveScreen = DarwinSaveScreen;
diff --git a/hw/xwayland/meson.build b/hw/xwayland/meson.build
index b619a66a7c..32ee65e68c 100644
--- a/hw/xwayland/meson.build
+++ b/hw/xwayland/meson.build
@@ -67,6 +67,7 @@ executable(
libxserver_xkb_stubs,
libxserver_xi_stubs,
libxserver_glx,
+ libglxvnd,
],
install: true,
)
diff --git a/hw/xwayland/xwayland.c b/hw/xwayland/xwayland.c
index cb929cad5c..207edcde1e 100644
--- a/hw/xwayland/xwayland.c
+++ b/hw/xwayland/xwayland.c
@@ -983,6 +983,11 @@ xwl_screen_init(ScreenPtr pScreen, int argc, char **argv)
pScreen->DestroyPixmap = xwl_shm_destroy_pixmap;
}
+#ifdef GLXEXT
+ if (!noGlxExtension)
+ xorgGlxCreateVendor(pScreen, NULL);
+#endif
+
xwl_screen->RealizeWindow = pScreen->RealizeWindow;
pScreen->RealizeWindow = xwl_realize_window;
diff --git a/hw/xwin/winscrinit.c b/hw/xwin/winscrinit.c
index a44e21fbd6..179cd8234d 100644
--- a/hw/xwin/winscrinit.c
+++ b/hw/xwin/winscrinit.c
@@ -366,6 +366,15 @@ winFinishScreenInitFB(int i, ScreenPtr pScreen, int argc, char **argv)
}
#endif
+#ifdef GLXEXT
+ if (!noGlxExtension) {
+ __GLXprovider *provider = NULL;
+ if (g_fNativeGl)
+ __GLXprovider = &__glXWGLProvider;
+ xorgGlxCreateVendor(pScreen, provider);
+ }
+#endif
+
/* Setup the cursor routines */
#if CYGDEBUG
winDebug("winFinishScreenInitFB - Calling miDCInitialize ()\n");
diff --git a/include/glx_extinit.h b/include/glx_extinit.h
index 710ca6e3e6..a57da764db 100644
--- a/include/glx_extinit.h
+++ b/include/glx_extinit.h
@@ -40,7 +40,7 @@ struct __GLXprovider {
extern __GLXprovider __glXDRISWRastProvider;
void GlxPushProvider(__GLXprovider * provider);
-
+Bool xorgGlxCreateVendor(ScreenPtr pScreen, __GLXprovider *provider);
#endif
#endif
--
2.13.5
More information about the xorg-devel
mailing list