From 8b9b5cdbf4b164da08958f2e95eab139e6bb838e Mon Sep 17 00:00:00 2001 From: Jesse Natalie Date: Sat, 4 Sep 2021 07:51:59 -0700 Subject: [PATCH] wgl: Make contexts current with pointer instead of DHGLRC Reviewed-by: Charmaine Lee Reviewed By: Bill Kristiansen Acked-by: Roland Scheidegger Part-of: --- src/gallium/frontends/wgl/stw_context.c | 27 ++++++++++--------- src/gallium/frontends/wgl/stw_context.h | 4 ++- src/gallium/frontends/wgl/stw_ext_context.c | 2 +- .../frontends/wgl/stw_ext_rendertexture.c | 4 +-- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/gallium/frontends/wgl/stw_context.c b/src/gallium/frontends/wgl/stw_context.c index 4ab618bdb71..874d87f3dcc 100644 --- a/src/gallium/frontends/wgl/stw_context.c +++ b/src/gallium/frontends/wgl/stw_context.c @@ -383,7 +383,7 @@ DrvReleaseContext(DHGLRC dhglrc) if (ctx != stw_current_context()) return FALSE; - if (stw_make_current( NULL, NULL, 0 ) == FALSE) + if (stw_make_current( NULL, NULL, NULL ) == FALSE) return FALSE; return TRUE; @@ -428,10 +428,9 @@ stw_get_current_read_dc( void ) } BOOL -stw_make_current(HDC hDrawDC, HDC hReadDC, DHGLRC dhglrc) +stw_make_current(HDC hDrawDC, HDC hReadDC, struct stw_context *ctx) { struct stw_context *old_ctx = NULL; - struct stw_context *ctx = NULL; BOOL ret = FALSE; if (!stw_dev) @@ -439,7 +438,7 @@ stw_make_current(HDC hDrawDC, HDC hReadDC, DHGLRC dhglrc) old_ctx = stw_current_context(); if (old_ctx != NULL) { - if (old_ctx->dhglrc == dhglrc) { + if (old_ctx == ctx) { if (old_ctx->hDrawDC == hDrawDC && old_ctx->hReadDC == hReadDC) { /* Return if already current. */ return TRUE; @@ -465,15 +464,9 @@ stw_make_current(HDC hDrawDC, HDC hReadDC, DHGLRC dhglrc) } } - if (dhglrc) { + if (ctx) { struct stw_framebuffer *fb = NULL; struct stw_framebuffer *fbRead = NULL; - stw_lock_contexts(stw_dev); - ctx = stw_lookup_context_locked( dhglrc ); - stw_unlock_contexts(stw_dev); - if (!ctx) { - goto fail; - } /* This call locks fb's mutex */ fb = stw_framebuffer_from_hdc( hDrawDC ); @@ -592,6 +585,16 @@ fail: return ret; } +BOOL +stw_make_current_by_handles(HDC hDrawDC, HDC hReadDC, DHGLRC dhglrc) +{ + struct stw_context *ctx = stw_lookup_context(dhglrc); + if (dhglrc && !ctx) { + stw_make_current(NULL, NULL, NULL); + } + return stw_make_current(hDrawDC, hReadDC, ctx); +} + /** * Notify the current context that the framebuffer has become invalid. @@ -955,7 +958,7 @@ DrvSetContext(HDC hdc, DHGLRC dhglrc, PFN_SETPROCTABLE pfnSetProcTable) { PGLCLTPROCTABLE r = (PGLCLTPROCTABLE)&cpt; - if (!stw_make_current(hdc, hdc, dhglrc)) + if (!stw_make_current_by_handles(hdc, hdc, dhglrc)) r = NULL; return r; diff --git a/src/gallium/frontends/wgl/stw_context.h b/src/gallium/frontends/wgl/stw_context.h index 76ea75a8cb5..c3a9a5db352 100644 --- a/src/gallium/frontends/wgl/stw_context.h +++ b/src/gallium/frontends/wgl/stw_context.h @@ -65,7 +65,9 @@ HDC stw_get_current_dc( void ); HDC stw_get_current_read_dc( void ); -BOOL stw_make_current( HDC hDrawDC, HDC hReadDC, DHGLRC dhglrc ); +BOOL stw_make_current( HDC hDrawDC, HDC hReadDC, struct stw_context *ctx ); + +BOOL stw_make_current_by_handles( HDC hDrawDC, HDC hReadDC, DHGLRC dhglrc ); void stw_notify_current_locked( struct stw_framebuffer *fb ); diff --git a/src/gallium/frontends/wgl/stw_ext_context.c b/src/gallium/frontends/wgl/stw_ext_context.c index 52a8921a555..709d691f2c3 100644 --- a/src/gallium/frontends/wgl/stw_ext_context.c +++ b/src/gallium/frontends/wgl/stw_ext_context.c @@ -231,7 +231,7 @@ wglMakeContextCurrentARB(HDC hDrawDC, HDC hReadDC, HGLRC hglrc) dhglrc = stw_dev->callbacks.pfnGetDhglrc(hglrc); } - return stw_make_current(hDrawDC, hReadDC, dhglrc); + return stw_make_current_by_handles(hDrawDC, hReadDC, dhglrc); } HDC APIENTRY diff --git a/src/gallium/frontends/wgl/stw_ext_rendertexture.c b/src/gallium/frontends/wgl/stw_ext_rendertexture.c index 48b2b1f61a4..00562a3dfd4 100644 --- a/src/gallium/frontends/wgl/stw_ext_rendertexture.c +++ b/src/gallium/frontends/wgl/stw_ext_rendertexture.c @@ -173,7 +173,7 @@ wglBindTexImageARB(HPBUFFERARB hPbuffer, int iBuffer) pixelFormatSave = fb->iPixelFormat; fb->iPixelFormat = curctx->iPixelFormat; dc = wglGetPbufferDCARB(hPbuffer); - retVal = stw_make_current(dc, dc, curctx->dhglrc); + retVal = stw_make_current(dc, dc, curctx); fb->iPixelFormat = pixelFormatSave; if (!retVal) { debug_printf("stw_make_current(#1) failed in wglBindTexImageARB()\n"); @@ -186,7 +186,7 @@ wglBindTexImageARB(HPBUFFERARB hPbuffer, int iBuffer) fb->textureFace, texFormat); /* rebind previous drawing surface */ - retVal = stw_make_current(prevDrawable, prevReadable, curctx->dhglrc); + retVal = stw_make_current(prevDrawable, prevReadable, curctx); if (!retVal) { debug_printf("stw_make_current(#2) failed in wglBindTexImageARB()\n"); }