wgl: Make contexts current with pointer instead of DHGLRC
authorJesse Natalie <jenatali@microsoft.com>
Sat, 4 Sep 2021 14:51:59 +0000 (07:51 -0700)
committerMarge Bot <eric+marge@anholt.net>
Wed, 15 Sep 2021 20:17:31 +0000 (20:17 +0000)
Reviewed-by: Charmaine Lee <charmainel@vmware.com>
Reviewed By: Bill Kristiansen <billkris@microsoft.com>

Acked-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12727>

src/gallium/frontends/wgl/stw_context.c
src/gallium/frontends/wgl/stw_context.h
src/gallium/frontends/wgl/stw_ext_context.c
src/gallium/frontends/wgl/stw_ext_rendertexture.c

index 4ab618b..874d87f 100644 (file)
@@ -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;
index 76ea75a..c3a9a5d 100644 (file)
@@ -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 );
 
index 52a8921..709d691 100644 (file)
@@ -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
index 48b2b1f..00562a3 100644 (file)
@@ -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");
    }