Mesa (master): wgl: Store current HDC/HGLRC in stw_context.

Keith Whitwell keithw at kemper.freedesktop.org
Tue Apr 28 17:17:39 UTC 2009


Module: Mesa
Branch: master
Commit: 43e24a5928aaf6a00f7d9e55e92abfb1b3e20166
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=43e24a5928aaf6a00f7d9e55e92abfb1b3e20166

Author: José Fonseca <jfonseca at vmware.com>
Date:   Mon Apr 27 20:24:55 2009 +0100

wgl: Store current HDC/HGLRC in stw_context.

Less TLS lookups.

---

 .../state_trackers/wgl/shared/stw_context.c        |   66 +++++++++++++-------
 .../state_trackers/wgl/shared/stw_context.h        |    1 +
 src/gallium/state_trackers/wgl/shared/stw_tls.h    |    2 -
 3 files changed, 44 insertions(+), 25 deletions(-)

diff --git a/src/gallium/state_trackers/wgl/shared/stw_context.c b/src/gallium/state_trackers/wgl/shared/stw_context.c
index f3c7af9..0b5dd78 100644
--- a/src/gallium/state_trackers/wgl/shared/stw_context.c
+++ b/src/gallium/state_trackers/wgl/shared/stw_context.c
@@ -101,7 +101,7 @@ stw_create_layer_context(
 
    ctx = CALLOC_STRUCT( stw_context );
    if (ctx == NULL)
-      return 0;
+      goto no_ctx;
 
    ctx->hdc = hdc;
    ctx->color_bits = GetDeviceCaps( ctx->hdc, BITSPIXEL );
@@ -125,7 +125,7 @@ stw_create_layer_context(
       pf->pfd.cAccumAlphaBits,
       pf->numSamples );
    if (visual == NULL) 
-      goto fail;
+      goto no_visual;
 
    screen = stw_dev->screen;
 
@@ -137,7 +137,7 @@ stw_create_layer_context(
 
    pipe = stw_dev->stw_winsys->create_context( screen );
    if (pipe == NULL) 
-      goto fail;
+      goto no_pipe;
 
 #ifdef DEBUG
    /* Wrap context */
@@ -150,28 +150,29 @@ stw_create_layer_context(
 
    ctx->st = st_create_context( pipe, visual, NULL );
    if (ctx->st == NULL) 
-      goto fail;
+      goto no_st_ctx;
 
    ctx->st->ctx->DriverCtx = ctx;
    ctx->pfi = pf;
 
    pipe_mutex_lock( stw_dev->mutex );
-   hglrc = handle_table_add(stw_dev->ctx_table, ctx);
+   ctx->hglrc = handle_table_add(stw_dev->ctx_table, ctx);
    pipe_mutex_unlock( stw_dev->mutex );
-
-   /* Success?
-    */
-   if (hglrc != 0)
-      return hglrc;
-
-fail:
-   if (visual)
-      _mesa_destroy_visual( visual );
-   
-   if (pipe)
-      pipe->destroy( pipe );
-      
+   if (!ctx->hglrc)
+      goto no_hglrc;
+
+   return ctx->hglrc;
+
+no_hglrc:
+   st_destroy_context(ctx->st);
+   goto no_pipe; /* st_context_destroy already destroys pipe */
+no_st_ctx:
+   pipe->destroy( pipe );
+no_pipe:
+   _mesa_destroy_visual( visual );
+no_visual:
    FREE( ctx );
+no_ctx:
    return 0;
 }
 
@@ -271,13 +272,35 @@ stw_get_window_size( HDC hdc, GLuint *width, GLuint *height )
 UINT_PTR
 stw_get_current_context( void )
 {
-   return stw_tls_get_data()->currentGLRC;
+   GET_CURRENT_CONTEXT( glcurctx );
+   struct stw_context *ctx;
+
+   if(!glcurctx)
+      return NULL;
+   
+   ctx = (struct stw_context *)glcurctx->DriverCtx;
+   assert(ctx);
+   if(!ctx)
+      return NULL;
+   
+   return ctx->hglrc;
 }
 
 HDC
 stw_get_current_dc( void )
 {
-    return stw_tls_get_data()->currentDC;
+   GET_CURRENT_CONTEXT( glcurctx );
+   struct stw_context *ctx;
+
+   if(!glcurctx)
+      return NULL;
+   
+   ctx = (struct stw_context *)glcurctx->DriverCtx;
+   assert(ctx);
+   if(!ctx)
+      return NULL;
+   
+   return ctx->hdc;
 }
 
 BOOL
@@ -299,9 +322,6 @@ stw_make_current(
    ctx = stw_lookup_context_locked( hglrc );
    pipe_mutex_unlock( stw_dev->mutex );
 
-   stw_tls_get_data()->currentDC = hdc;
-   stw_tls_get_data()->currentGLRC = hglrc;
-
    if (glcurctx != NULL) {
       curctx = (struct stw_context *) glcurctx->DriverCtx;
 
diff --git a/src/gallium/state_trackers/wgl/shared/stw_context.h b/src/gallium/state_trackers/wgl/shared/stw_context.h
index bc3b1dc..e276737 100644
--- a/src/gallium/state_trackers/wgl/shared/stw_context.h
+++ b/src/gallium/state_trackers/wgl/shared/stw_context.h
@@ -36,6 +36,7 @@ struct stw_pixelformat_info;
 struct stw_context
 {
    struct st_context *st;
+   UINT_PTR hglrc;
    HDC hdc;
    DWORD color_bits;
    const struct stw_pixelformat_info *pfi;
diff --git a/src/gallium/state_trackers/wgl/shared/stw_tls.h b/src/gallium/state_trackers/wgl/shared/stw_tls.h
index f5a6bdf..6cfb089 100644
--- a/src/gallium/state_trackers/wgl/shared/stw_tls.h
+++ b/src/gallium/state_trackers/wgl/shared/stw_tls.h
@@ -33,8 +33,6 @@
 struct stw_tls_data
 {
    uint currentPixelFormat;
-   HDC currentDC;
-   UINT_PTR currentGLRC;
    HHOOK hCallWndProcHook;
 };
 




More information about the mesa-commit mailing list