From d32ae764e930abb70ca2cc79ad18fdb32141ca0d Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Thu, 19 Feb 2009 10:52:08 +0000 Subject: wgl: Share more code between icd and standalone driver. --- src/gallium/state_trackers/wgl/icd/stw_icd.c | 217 +++------------------------ 1 file changed, 19 insertions(+), 198 deletions(-) (limited to 'src/gallium/state_trackers/wgl/icd') diff --git a/src/gallium/state_trackers/wgl/icd/stw_icd.c b/src/gallium/state_trackers/wgl/icd/stw_icd.c index 5ac871da81..8ae6aa1f3e 100644 --- a/src/gallium/state_trackers/wgl/icd/stw_icd.c +++ b/src/gallium/state_trackers/wgl/icd/stw_icd.c @@ -35,77 +35,11 @@ #include "shared/stw_public.h" #include "icd/stw_icd.h" -#include "stw.h" -#define DRV_CONTEXT_MAX 32 +static GLCLTPROCTABLE cpt; +static boolean cpt_initialized = FALSE; -struct stw_icd -{ - pipe_mutex mutex; - - GLCLTPROCTABLE cpt; - boolean cpt_initialized; - - struct { - struct stw_context *ctx; - } ctx_array[DRV_CONTEXT_MAX]; -}; - - -static struct stw_icd *stw_icd = NULL; - - -boolean -stw_icd_init( void ) -{ - static struct stw_icd stw_icd_storage; - - assert(!stw_icd); - - stw_icd = &stw_icd_storage; - memset(stw_icd, 0, sizeof *stw_icd); - - pipe_mutex_init( stw_icd->mutex ); - - return TRUE; -} - -void -stw_icd_cleanup(void) -{ - int i; - - if (!stw_icd) - return; - - pipe_mutex_lock( stw_icd->mutex ); - { - /* Ensure all contexts are destroyed */ - for (i = 0; i < DRV_CONTEXT_MAX; i++) - if (stw_icd->ctx_array[i].ctx) - stw_delete_context( stw_icd->ctx_array[i].ctx ); - } - pipe_mutex_unlock( stw_icd->mutex ); - - pipe_mutex_init( stw_icd->mutex ); - stw_icd = NULL; -} - - -static struct stw_context * -lookup_context( struct stw_icd *icd, - DHGLRC dhglrc ) -{ - if (dhglrc == 0 || - dhglrc >= DRV_CONTEXT_MAX) - return NULL; - - if (icd == NULL) - return NULL; - - return icd->ctx_array[dhglrc - 1].ctx; -} BOOL APIENTRY DrvCopyContext( @@ -113,63 +47,16 @@ DrvCopyContext( DHGLRC dhrcDest, UINT fuMask ) { - BOOL ret = FALSE; - - if (!stw_icd) - return FALSE; - - pipe_mutex_lock( stw_icd->mutex ); - { - struct stw_context *src = lookup_context( stw_icd, dhrcSource ); - struct stw_context *dst = lookup_context( stw_icd, dhrcDest ); - - if (src == NULL || dst == NULL) - goto done; - - ret = stw_copy_context( src, dst, fuMask ); - } -done: - pipe_mutex_unlock( stw_icd->mutex ); - - return ret; + return stw_copy_context(dhrcSource, dhrcDest, fuMask); } + DHGLRC APIENTRY DrvCreateLayerContext( HDC hdc, INT iLayerPlane ) { - DHGLRC handle = 0; - - if (!stw_icd) - return handle; - - pipe_mutex_lock( stw_icd->mutex ); - { - int i; - - for (i = 0; i < DRV_CONTEXT_MAX; i++) { - if (stw_icd->ctx_array[i].ctx == NULL) - break; - } - - /* No slot available, fail: - */ - if (i == DRV_CONTEXT_MAX) - goto done; - - stw_icd->ctx_array[i].ctx = stw_create_context( hdc, iLayerPlane ); - if (stw_icd->ctx_array[i].ctx == NULL) - goto done; - - /* success: - */ - handle = (DHGLRC) i + 1; - } -done: - pipe_mutex_unlock( stw_icd->mutex ); - - return handle; + return stw_create_layer_context( hdc, iLayerPlane ); } DHGLRC APIENTRY @@ -183,30 +70,7 @@ BOOL APIENTRY DrvDeleteContext( DHGLRC dhglrc ) { - BOOL ret = FALSE; - - if (!stw_icd) - return ret; - - pipe_mutex_lock( stw_icd->mutex ); - { - struct stw_context *ctx; - - ctx = lookup_context( stw_icd, dhglrc ); - if (ctx == NULL) - goto done; - - if (stw_delete_context( ctx ) == FALSE) - goto done; - - stw_icd->ctx_array[dhglrc - 1].ctx = NULL; - ret = TRUE; - - } -done: - pipe_mutex_unlock( stw_icd->mutex ); - - return ret; + return stw_delete_context( dhglrc ); } BOOL APIENTRY @@ -280,32 +144,7 @@ BOOL APIENTRY DrvReleaseContext( DHGLRC dhglrc ) { - BOOL ret = FALSE; - - if (!stw_icd) - return ret; - - pipe_mutex_lock( stw_icd->mutex ); - { - struct stw_context *ctx; - - /* XXX: The expectation is that ctx is the same context which is - * current for this thread. We should check that and return False - * if not the case. - */ - ctx = lookup_context( stw_icd, dhglrc ); - if (ctx == NULL) - goto done; - - if (stw_make_current( NULL, NULL ) == FALSE) - goto done; - - ret = TRUE; - } -done: - pipe_mutex_unlock( stw_icd->mutex ); - - return ret; + return stw_release_context(dhglrc); } void APIENTRY @@ -671,38 +510,20 @@ DrvSetContext( DHGLRC dhglrc, PFN_SETPROCTABLE pfnSetProcTable ) { - PGLCLTPROCTABLE result = NULL; - - if (!stw_icd) - return result; - - pipe_mutex_lock( stw_icd->mutex ); - { - struct stw_context *ctx; - - debug_printf( "%s( 0x%p, %u, 0x%p )\n", - __FUNCTION__, hdc, dhglrc, pfnSetProcTable ); - - /* Although WGL allows different dispatch entrypoints per - */ - if (!stw_icd->cpt_initialized) { - init_proc_table( &stw_icd->cpt ); - stw_icd->cpt_initialized = TRUE; - } - - ctx = lookup_context( stw_icd, dhglrc ); - if (ctx == NULL) - goto done; - - if (!stw_make_current( hdc, ctx )) - goto done; - - result = &stw_icd->cpt; + debug_printf( "%s( 0x%p, %u, 0x%p )\n", + __FUNCTION__, hdc, dhglrc, pfnSetProcTable ); + + /* Although WGL allows different dispatch entrypoints per + */ + if (!cpt_initialized) { + init_proc_table( &cpt ); + cpt_initialized = TRUE; } -done: - pipe_mutex_unlock( stw_icd->mutex ); - return result; + if (!stw_make_current( hdc, dhglrc )) + return NULL; + + return &cpt; } int APIENTRY -- cgit v1.2.3