From cf9debb6397a6c23fd6377e557e5f7ac1a19b895 Mon Sep 17 00:00:00 2001 From: Adam Jackson Date: Tue, 3 Jan 2023 18:33:34 -0500 Subject: [PATCH] glx: Clean up some funny business from context bind/unbind We always fully unbind the old context before binding the new one, so there's no point in passing both contexts to both the unbind and then the bind. Part-of: --- src/glx/applegl_glx.c | 10 +++------- src/glx/dri2_glx.c | 5 ++--- src/glx/dri3_glx.c | 5 ++--- src/glx/drisw_glx.c | 5 ++--- src/glx/driwindows_glx.c | 5 ++--- src/glx/glxclient.h | 5 ++--- src/glx/glxcurrent.c | 4 ++-- src/glx/indirect_glx.c | 28 +++++----------------------- 8 files changed, 20 insertions(+), 47 deletions(-) diff --git a/src/glx/applegl_glx.c b/src/glx/applegl_glx.c index d8b2d13dd66ce..0b2e722b66cf4 100644 --- a/src/glx/applegl_glx.c +++ b/src/glx/applegl_glx.c @@ -50,13 +50,13 @@ applegl_destroy_context(struct glx_context *gc) static int applegl_bind_context( - struct glx_context *gc, struct glx_context *old, + struct glx_context *gc, GLXDrawable draw, GLXDrawable read) { Display *dpy = gc->psc->dpy; bool error = apple_glx_make_current_context( dpy, - (old && old != &dummyContext) ? old->driContext : NULL, + NULL, gc ? gc->driContext : NULL, draw); apple_glx_diagnostic("%s: error %s\n", __func__, error ? "YES" : "NO"); @@ -69,7 +69,7 @@ applegl_bind_context( } static void -applegl_unbind_context(struct glx_context *gc, struct glx_context *new) +applegl_unbind_context(struct glx_context *gc) { Display *dpy; bool error; @@ -78,10 +78,6 @@ applegl_unbind_context(struct glx_context *gc, struct glx_context *new) if (!gc) return; - /* If we have a new context, keep this one around and remove it during bind. */ - if (new) - return; - dpy = gc->psc->dpy; error = apple_glx_make_current_context( diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c index 0399dd5cb5dc2..3b0c3ccaf3e0d 100644 --- a/src/glx/dri2_glx.c +++ b/src/glx/dri2_glx.c @@ -111,8 +111,7 @@ dri2_destroy_context(struct glx_context *context) } static Bool -dri2_bind_context(struct glx_context *context, struct glx_context *old, - GLXDrawable draw, GLXDrawable read) +dri2_bind_context(struct glx_context *context, GLXDrawable draw, GLXDrawable read) { struct dri2_screen *psc = (struct dri2_screen *) context->psc; struct dri2_drawable *pdraw, *pread; @@ -140,7 +139,7 @@ dri2_bind_context(struct glx_context *context, struct glx_context *old, } static void -dri2_unbind_context(struct glx_context *context, struct glx_context *new) +dri2_unbind_context(struct glx_context *context) { struct dri2_screen *psc = (struct dri2_screen *) context->psc; diff --git a/src/glx/dri3_glx.c b/src/glx/dri3_glx.c index f957a431dc75c..613c620d21388 100644 --- a/src/glx/dri3_glx.c +++ b/src/glx/dri3_glx.c @@ -157,8 +157,7 @@ dri3_destroy_context(struct glx_context *context) } static Bool -dri3_bind_context(struct glx_context *context, struct glx_context *old, - GLXDrawable draw, GLXDrawable read) +dri3_bind_context(struct glx_context *context, GLXDrawable draw, GLXDrawable read) { struct dri3_screen *psc = (struct dri3_screen *) context->psc; struct dri3_drawable *pdraw, *pread; @@ -191,7 +190,7 @@ dri3_bind_context(struct glx_context *context, struct glx_context *old, } static void -dri3_unbind_context(struct glx_context *context, struct glx_context *new) +dri3_unbind_context(struct glx_context *context) { struct dri3_screen *psc = (struct dri3_screen *) context->psc; diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c index d7658eaf7c1f1..0e41f8560a90e 100644 --- a/src/glx/drisw_glx.c +++ b/src/glx/drisw_glx.c @@ -431,8 +431,7 @@ drisw_destroy_context(struct glx_context *context) } static int -drisw_bind_context(struct glx_context *context, struct glx_context *old, - GLXDrawable draw, GLXDrawable read) +drisw_bind_context(struct glx_context *context, GLXDrawable draw, GLXDrawable read) { struct drisw_screen *psc = (struct drisw_screen *) context->psc; struct drisw_drawable *pdraw, *pread; @@ -457,7 +456,7 @@ drisw_bind_context(struct glx_context *context, struct glx_context *old, } static void -drisw_unbind_context(struct glx_context *context, struct glx_context *new) +drisw_unbind_context(struct glx_context *context) { struct drisw_screen *psc = (struct drisw_screen *) context->psc; diff --git a/src/glx/driwindows_glx.c b/src/glx/driwindows_glx.c index 3eb961dae3d27..0c5540f387630 100644 --- a/src/glx/driwindows_glx.c +++ b/src/glx/driwindows_glx.c @@ -79,8 +79,7 @@ driwindows_destroy_context(struct glx_context *context) } static int -driwindows_bind_context(struct glx_context *context, struct glx_context *old, - GLXDrawable draw, GLXDrawable read) +driwindows_bind_context(struct glx_context *context, GLXDrawable draw, GLXDrawable read) { struct driwindows_context *pcp = (struct driwindows_context *) context; struct driwindows_drawable *pdraw, *pread; @@ -101,7 +100,7 @@ driwindows_bind_context(struct glx_context *context, struct glx_context *old, } static void -driwindows_unbind_context(struct glx_context *context, struct glx_context *new) +driwindows_unbind_context(struct glx_context *context) { struct driwindows_context *pcp = (struct driwindows_context *) context; diff --git a/src/glx/glxclient.h b/src/glx/glxclient.h index 0b9b3e966dae4..3b3eb07d8fe44 100644 --- a/src/glx/glxclient.h +++ b/src/glx/glxclient.h @@ -210,9 +210,8 @@ struct mesa_glinterop_export_out; struct glx_context_vtable { void (*destroy)(struct glx_context *ctx); - int (*bind)(struct glx_context *context, struct glx_context *old, - GLXDrawable draw, GLXDrawable read); - void (*unbind)(struct glx_context *context, struct glx_context *new_ctx); + int (*bind)(struct glx_context *context, GLXDrawable draw, GLXDrawable read); + void (*unbind)(struct glx_context *context); void (*wait_gl)(struct glx_context *ctx); void (*wait_x)(struct glx_context *ctx); int (*interop_query_device_info)(struct glx_context *ctx, diff --git a/src/glx/glxcurrent.c b/src/glx/glxcurrent.c index 517a9e95327c1..a0a0aa3ca9a1a 100644 --- a/src/glx/glxcurrent.c +++ b/src/glx/glxcurrent.c @@ -125,7 +125,7 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw, } if (oldGC != &dummyContext) { - oldGC->vtable->unbind(oldGC, gc); + oldGC->vtable->unbind(oldGC); oldGC->currentDpy = NULL; } @@ -138,7 +138,7 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw, * blown away our old context. The caller is responsible for * figuring out how to handle setting a valid context. */ - if (gc->vtable->bind(gc, oldGC, draw, read) != Success) { + if (gc->vtable->bind(gc, draw, read) != Success) { __glXSetCurrentContextNull(); __glXUnlock(); __glXSendError(dpy, GLXBadContext, None, opcode, False); diff --git a/src/glx/indirect_glx.c b/src/glx/indirect_glx.c index 80e95f6754ebb..dc3464fc99ed4 100644 --- a/src/glx/indirect_glx.c +++ b/src/glx/indirect_glx.c @@ -123,21 +123,13 @@ SendMakeCurrentRequest(Display * dpy, GLXContextID gc_id, } static int -indirect_bind_context(struct glx_context *gc, struct glx_context *old, +indirect_bind_context(struct glx_context *gc, GLXDrawable draw, GLXDrawable read) { - GLXContextTag tag; Display *dpy = gc->psc->dpy; Bool sent; - if (old != &dummyContext && !old->isDirect && old->psc->dpy == dpy) { - tag = old->currentContextTag; - old->currentContextTag = 0; - } else { - tag = 0; - } - - sent = SendMakeCurrentRequest(dpy, gc->xid, tag, draw, read, + sent = SendMakeCurrentRequest(dpy, gc->xid, 0, draw, read, &gc->currentContextTag); if (sent) { @@ -166,22 +158,12 @@ indirect_bind_context(struct glx_context *gc, struct glx_context *old, } static void -indirect_unbind_context(struct glx_context *gc, struct glx_context *new) +indirect_unbind_context(struct glx_context *gc) { Display *dpy = gc->psc->dpy; - if (gc == new) - return; - - /* We are either switching to no context, away from an indirect - * context to a direct context or from one dpy to another and have - * to send a request to the dpy to unbind the previous context. - */ - if (!new || new->isDirect || new->psc->dpy != dpy) { - SendMakeCurrentRequest(dpy, None, gc->currentContextTag, None, None, - NULL); - gc->currentContextTag = 0; - } + SendMakeCurrentRequest(dpy, None, gc->currentContextTag, None, None, NULL); + gc->currentContextTag = 0; } static void