wgl: Store current HDC/HGLRC in stw_context.
authorJosé Fonseca <jfonseca@vmware.com>
Mon, 27 Apr 2009 19:24:55 +0000 (20:24 +0100)
committerKeith Whitwell <keithw@vmware.com>
Tue, 28 Apr 2009 17:15:16 +0000 (18:15 +0100)
Less TLS lookups.

src/gallium/state_trackers/wgl/shared/stw_context.c
src/gallium/state_trackers/wgl/shared/stw_context.h
src/gallium/state_trackers/wgl/shared/stw_tls.h

index f3c7af93f503aa99e97c33da1e99f04277b5828a..0b5dd78ec6321ab748eefc002af66bc1d154084b 100644 (file)
@@ -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;
 
index bc3b1dc880dcd45fc8bc848562f570e95dea0474..e276737e85a421408134625afc5ce92e4a65104e 100644 (file)
@@ -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;
index f5a6bdf4b1a6068367f2aeb98536d70c72f71262..6cfb0899f2dbb851bc59352512717a6181ffb67f 100644 (file)
@@ -33,8 +33,6 @@
 struct stw_tls_data
 {
    uint currentPixelFormat;
-   HDC currentDC;
-   UINT_PTR currentGLRC;
    HHOOK hCallWndProcHook;
 };