glx: Make sure that DRI2/swrast calls haven't changed the GL context.
These functions are called from the GL driver, in some series of GL calls by GLX. If some server component (like glamor CreatePixmap for GetBuffers()) changes the GL context on us, we need to set it back or the later GL calls will land in the glamor context instead of the GLX context. Signed-off-by: Eric Anholt <eric@anholt.net> Reviewed-by: Michel Dänzer <michel.daenzer@amd.com> Reviewed-by: Adam Jackson <ajax@redhat.com>
This commit is contained in:
parent
f3f2fb6baa
commit
ab6e958a2e
|
@ -121,6 +121,7 @@ copy_box(__GLXdrawable * drawable,
|
||||||
{
|
{
|
||||||
BoxRec box;
|
BoxRec box;
|
||||||
RegionRec region;
|
RegionRec region;
|
||||||
|
__GLXcontext *cx = lastGLContext;
|
||||||
|
|
||||||
box.x1 = x;
|
box.x1 = x;
|
||||||
box.y1 = y;
|
box.y1 = y;
|
||||||
|
@ -129,6 +130,10 @@ copy_box(__GLXdrawable * drawable,
|
||||||
RegionInit(®ion, &box, 0);
|
RegionInit(®ion, &box, 0);
|
||||||
|
|
||||||
DRI2CopyRegion(drawable->pDraw, ®ion, dst, src);
|
DRI2CopyRegion(drawable->pDraw, ®ion, dst, src);
|
||||||
|
if (cx != lastGLContext) {
|
||||||
|
lastGLContext = cx;
|
||||||
|
cx->makeCurrent(cx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -198,26 +203,37 @@ __glXDRIdrawableSwapBuffers(ClientPtr client, __GLXdrawable * drawable)
|
||||||
__GLXDRIdrawable *priv = (__GLXDRIdrawable *) drawable;
|
__GLXDRIdrawable *priv = (__GLXDRIdrawable *) drawable;
|
||||||
__GLXDRIscreen *screen = priv->screen;
|
__GLXDRIscreen *screen = priv->screen;
|
||||||
CARD64 unused;
|
CARD64 unused;
|
||||||
|
__GLXcontext *cx = lastGLContext;
|
||||||
|
int status;
|
||||||
|
|
||||||
if (screen->flush) {
|
if (screen->flush) {
|
||||||
(*screen->flush->flush) (priv->driDrawable);
|
(*screen->flush->flush) (priv->driDrawable);
|
||||||
(*screen->flush->invalidate) (priv->driDrawable);
|
(*screen->flush->invalidate) (priv->driDrawable);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DRI2SwapBuffers(client, drawable->pDraw, 0, 0, 0, &unused,
|
status = DRI2SwapBuffers(client, drawable->pDraw, 0, 0, 0, &unused,
|
||||||
__glXdriSwapEvent, drawable) != Success)
|
__glXdriSwapEvent, drawable);
|
||||||
return FALSE;
|
if (cx != lastGLContext) {
|
||||||
|
lastGLContext = cx;
|
||||||
|
cx->makeCurrent(cx);
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return status == Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
__glXDRIdrawableSwapInterval(__GLXdrawable * drawable, int interval)
|
__glXDRIdrawableSwapInterval(__GLXdrawable * drawable, int interval)
|
||||||
{
|
{
|
||||||
|
__GLXcontext *cx = lastGLContext;
|
||||||
|
|
||||||
if (interval <= 0) /* || interval > BIGNUM? */
|
if (interval <= 0) /* || interval > BIGNUM? */
|
||||||
return GLX_BAD_VALUE;
|
return GLX_BAD_VALUE;
|
||||||
|
|
||||||
DRI2SwapInterval(drawable->pDraw, interval);
|
DRI2SwapInterval(drawable->pDraw, interval);
|
||||||
|
if (cx != lastGLContext) {
|
||||||
|
lastGLContext = cx;
|
||||||
|
cx->makeCurrent(cx);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -270,7 +286,16 @@ static Bool
|
||||||
__glXDRIcontextWait(__GLXcontext * baseContext,
|
__glXDRIcontextWait(__GLXcontext * baseContext,
|
||||||
__GLXclientState * cl, int *error)
|
__GLXclientState * cl, int *error)
|
||||||
{
|
{
|
||||||
if (DRI2WaitSwap(cl->client, baseContext->drawPriv->pDraw)) {
|
__GLXcontext *cx = lastGLContext;
|
||||||
|
Bool ret;
|
||||||
|
|
||||||
|
ret = DRI2WaitSwap(cl->client, baseContext->drawPriv->pDraw);
|
||||||
|
if (cx != lastGLContext) {
|
||||||
|
lastGLContext = cx;
|
||||||
|
cx->makeCurrent(cx);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret) {
|
||||||
*error = cl->client->noClientException;
|
*error = cl->client->noClientException;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -594,6 +619,8 @@ __glXDRIscreenCreateDrawable(ClientPtr client,
|
||||||
__GLXDRIscreen *driScreen = (__GLXDRIscreen *) screen;
|
__GLXDRIscreen *driScreen = (__GLXDRIscreen *) screen;
|
||||||
__GLXDRIconfig *config = (__GLXDRIconfig *) glxConfig;
|
__GLXDRIconfig *config = (__GLXDRIconfig *) glxConfig;
|
||||||
__GLXDRIdrawable *private;
|
__GLXDRIdrawable *private;
|
||||||
|
__GLXcontext *cx = lastGLContext;
|
||||||
|
Bool ret;
|
||||||
|
|
||||||
private = calloc(1, sizeof *private);
|
private = calloc(1, sizeof *private);
|
||||||
if (private == NULL)
|
if (private == NULL)
|
||||||
|
@ -612,9 +639,15 @@ __glXDRIscreenCreateDrawable(ClientPtr client,
|
||||||
private->base.waitGL = __glXDRIdrawableWaitGL;
|
private->base.waitGL = __glXDRIdrawableWaitGL;
|
||||||
private->base.waitX = __glXDRIdrawableWaitX;
|
private->base.waitX = __glXDRIdrawableWaitX;
|
||||||
|
|
||||||
if (DRI2CreateDrawable2(client, pDraw, drawId,
|
ret = DRI2CreateDrawable2(client, pDraw, drawId,
|
||||||
__glXDRIinvalidateBuffers, private,
|
__glXDRIinvalidateBuffers, private,
|
||||||
&private->dri2_id)) {
|
&private->dri2_id);
|
||||||
|
if (cx != lastGLContext) {
|
||||||
|
lastGLContext = cx;
|
||||||
|
cx->makeCurrent(cx);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret) {
|
||||||
free(private);
|
free(private);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -636,9 +669,15 @@ dri2GetBuffers(__DRIdrawable * driDrawable,
|
||||||
DRI2BufferPtr *buffers;
|
DRI2BufferPtr *buffers;
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
|
__GLXcontext *cx = lastGLContext;
|
||||||
|
|
||||||
buffers = DRI2GetBuffers(private->base.pDraw,
|
buffers = DRI2GetBuffers(private->base.pDraw,
|
||||||
width, height, attachments, count, out_count);
|
width, height, attachments, count, out_count);
|
||||||
|
if (cx != lastGLContext) {
|
||||||
|
lastGLContext = cx;
|
||||||
|
cx->makeCurrent(cx);
|
||||||
|
}
|
||||||
|
|
||||||
if (*out_count > MAX_DRAWABLE_BUFFERS) {
|
if (*out_count > MAX_DRAWABLE_BUFFERS) {
|
||||||
*out_count = 0;
|
*out_count = 0;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -680,10 +719,16 @@ dri2GetBuffersWithFormat(__DRIdrawable * driDrawable,
|
||||||
DRI2BufferPtr *buffers;
|
DRI2BufferPtr *buffers;
|
||||||
int i;
|
int i;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
__GLXcontext *cx = lastGLContext;
|
||||||
|
|
||||||
buffers = DRI2GetBuffersWithFormat(private->base.pDraw,
|
buffers = DRI2GetBuffersWithFormat(private->base.pDraw,
|
||||||
width, height, attachments, count,
|
width, height, attachments, count,
|
||||||
out_count);
|
out_count);
|
||||||
|
if (cx != lastGLContext) {
|
||||||
|
lastGLContext = cx;
|
||||||
|
cx->makeCurrent(cx);
|
||||||
|
}
|
||||||
|
|
||||||
if (*out_count > MAX_DRAWABLE_BUFFERS) {
|
if (*out_count > MAX_DRAWABLE_BUFFERS) {
|
||||||
*out_count = 0;
|
*out_count = 0;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -337,6 +337,7 @@ swrastPutImage(__DRIdrawable * draw, int op,
|
||||||
__GLXDRIdrawable *drawable = loaderPrivate;
|
__GLXDRIdrawable *drawable = loaderPrivate;
|
||||||
DrawablePtr pDraw = drawable->base.pDraw;
|
DrawablePtr pDraw = drawable->base.pDraw;
|
||||||
GCPtr gc;
|
GCPtr gc;
|
||||||
|
__GLXcontext *cx = lastGLContext;
|
||||||
|
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case __DRI_SWRAST_IMAGE_OP_DRAW:
|
case __DRI_SWRAST_IMAGE_OP_DRAW:
|
||||||
|
@ -352,6 +353,10 @@ swrastPutImage(__DRIdrawable * draw, int op,
|
||||||
ValidateGC(pDraw, gc);
|
ValidateGC(pDraw, gc);
|
||||||
|
|
||||||
gc->ops->PutImage(pDraw, gc, pDraw->depth, x, y, w, h, 0, ZPixmap, data);
|
gc->ops->PutImage(pDraw, gc, pDraw->depth, x, y, w, h, 0, ZPixmap, data);
|
||||||
|
if (cx != lastGLContext) {
|
||||||
|
lastGLContext = cx;
|
||||||
|
cx->makeCurrent(cx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -361,8 +366,13 @@ swrastGetImage(__DRIdrawable * draw,
|
||||||
__GLXDRIdrawable *drawable = loaderPrivate;
|
__GLXDRIdrawable *drawable = loaderPrivate;
|
||||||
DrawablePtr pDraw = drawable->base.pDraw;
|
DrawablePtr pDraw = drawable->base.pDraw;
|
||||||
ScreenPtr pScreen = pDraw->pScreen;
|
ScreenPtr pScreen = pDraw->pScreen;
|
||||||
|
__GLXcontext *cx = lastGLContext;
|
||||||
|
|
||||||
pScreen->GetImage(pDraw, x, y, w, h, ZPixmap, ~0L, data);
|
pScreen->GetImage(pDraw, x, y, w, h, ZPixmap, ~0L, data);
|
||||||
|
if (cx != lastGLContext) {
|
||||||
|
lastGLContext = cx;
|
||||||
|
cx->makeCurrent(cx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const __DRIswrastLoaderExtension swrastLoaderExtension = {
|
static const __DRIswrastLoaderExtension swrastLoaderExtension = {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user