From 42523a83b332c9a0b128ba5ceca7c5fcd5a1d6c6 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 9 Feb 2009 21:08:49 +0000 Subject: wgl: s/0x%p/%p/g Rather not have 0x prefix, than 0x0x in certain platforms. --- src/gallium/state_trackers/wgl/icd/stw_icd.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/gallium/state_trackers') diff --git a/src/gallium/state_trackers/wgl/icd/stw_icd.c b/src/gallium/state_trackers/wgl/icd/stw_icd.c index 70e346a5394..5c78c19f926 100644 --- a/src/gallium/state_trackers/wgl/icd/stw_icd.c +++ b/src/gallium/state_trackers/wgl/icd/stw_icd.c @@ -183,7 +183,7 @@ DrvDescribePixelFormat( r = stw_pixelformat_describe( hdc, iPixelFormat, cjpfd, ppfd ); - debug_printf( "%s( 0x%p, %d, %u, 0x%p ) = %d\n", + debug_printf( "%s( %p, %d, %u, %p ) = %d\n", __FUNCTION__, hdc, iPixelFormat, cjpfd, ppfd, r ); return r; @@ -210,7 +210,7 @@ DrvGetProcAddress( r = stw_get_proc_address( lpszProc ); - debug_printf( "%s( \", __FUNCTION__%s\" ) = 0x%p\n", lpszProc, r ); + debug_printf( "%s( \", __FUNCTION__%s\" ) = %p\n", lpszProc, r ); return r; } @@ -254,7 +254,7 @@ DrvSetCallbackProcs( INT nProcs, PROC *pProcs ) { - debug_printf( "%s( %d, 0x%p )\n", __FUNCTION__, nProcs, pProcs ); + debug_printf( "%s( %d, %p )\n", __FUNCTION__, nProcs, pProcs ); return; } @@ -272,7 +272,7 @@ DrvSetContext( struct stw_context *ctx; GLDISPATCHTABLE *disp = &cpt.glDispatchTable; - debug_printf( "%s( 0x%p, %u, 0x%p )\n", __FUNCTION__, hdc, dhglrc, pfnSetProcTable ); + debug_printf( "%s( %p, %u, %p )\n", __FUNCTION__, hdc, dhglrc, pfnSetProcTable ); ctx = lookup_context( dhglrc ); if (ctx == NULL) @@ -646,7 +646,7 @@ DrvSetPixelFormat( r = stw_pixelformat_set( hdc, iPixelFormat ); - debug_printf( "%s( 0x%p, %d ) = %s\n", __FUNCTION__, hdc, iPixelFormat, r ? "TRUE" : "FALSE" ); + debug_printf( "%s( %p, %d ) = %s\n", __FUNCTION__, hdc, iPixelFormat, r ? "TRUE" : "FALSE" ); return r; } @@ -665,7 +665,7 @@ BOOL APIENTRY DrvSwapBuffers( HDC hdc ) { - debug_printf( "%s( 0x%p )\n", __FUNCTION__, hdc ); + debug_printf( "%s( %p )\n", __FUNCTION__, hdc ); return stw_swap_buffers( hdc ); } @@ -686,5 +686,7 @@ DrvValidateVersion( { debug_printf( "%s( %u )\n", __FUNCTION__, ulVersion ); + /* TODO: get the expected version from the winsys */ + return ulVersion == 1; } -- cgit v1.2.3 From 9fb9ee9d241c99a76e15af2db328332dfecf586d Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Tue, 10 Feb 2009 11:37:23 +0000 Subject: stw: Hack for applications which use wglSetPixelFormat instead of SetPixelFormat. --- src/gallium/state_trackers/wgl/shared/stw_pixelformat.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/gallium/state_trackers') diff --git a/src/gallium/state_trackers/wgl/shared/stw_pixelformat.c b/src/gallium/state_trackers/wgl/shared/stw_pixelformat.c index 12b5ac6d91e..84b7b287b91 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_pixelformat.c +++ b/src/gallium/state_trackers/wgl/shared/stw_pixelformat.c @@ -256,6 +256,14 @@ stw_pixelformat_set( return FALSE; currentpixelformat = iPixelFormat; + + /* Some applications mistakenly use the undocumented wglSetPixelFormat + * function instead of SetPixelFormat, so we call SetPixelFormat here to + * avoid opengl32.dll's wglCreateContext to fail */ + if (GetPixelFormat(hdc) == 0) { + SetPixelFormat(hdc, iPixelFormat, NULL); + } + return TRUE; } -- cgit v1.2.3 From 67e988a06c8ff5896da9df7ce1c7fc118352c8a3 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Tue, 10 Feb 2009 11:50:54 +0000 Subject: wgl: Fix null pointer reference. --- src/gallium/state_trackers/wgl/icd/stw_icd.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/gallium/state_trackers') diff --git a/src/gallium/state_trackers/wgl/icd/stw_icd.c b/src/gallium/state_trackers/wgl/icd/stw_icd.c index 5c78c19f926..8fa9f4e667f 100644 --- a/src/gallium/state_trackers/wgl/icd/stw_icd.c +++ b/src/gallium/state_trackers/wgl/icd/stw_icd.c @@ -89,6 +89,9 @@ lookup_context( DHGLRC dhglrc ) dhglrc >= DRV_CONTEXT_MAX) return NULL; + if(!stw_icd) + return NULL; + return stw_icd->ctx_array[dhglrc - 1].ctx; } -- cgit v1.2.3 From a88e2544eeb0a93b23ab2383905fef44c056040c Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Tue, 10 Feb 2009 14:03:43 +0000 Subject: vmw/icd: remove bogus current_context value --- src/gallium/state_trackers/wgl/icd/stw_icd.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/gallium/state_trackers') diff --git a/src/gallium/state_trackers/wgl/icd/stw_icd.c b/src/gallium/state_trackers/wgl/icd/stw_icd.c index 70e346a5394..e160004aea4 100644 --- a/src/gallium/state_trackers/wgl/icd/stw_icd.c +++ b/src/gallium/state_trackers/wgl/icd/stw_icd.c @@ -44,8 +44,6 @@ struct stw_icd struct { struct stw_context *ctx; } ctx_array[DRV_CONTEXT_MAX]; - - DHGLRC ctx_current; }; @@ -232,9 +230,10 @@ DrvReleaseContext( { struct stw_context *ctx; - if (dhglrc != stw_icd->ctx_current) - goto fail; - + /* 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( dhglrc ); if (ctx == NULL) goto fail; @@ -242,7 +241,6 @@ DrvReleaseContext( if (stw_make_current( NULL, NULL ) == FALSE) goto fail; - stw_icd->ctx_current = 0; return TRUE; fail: -- cgit v1.2.3 From ebb864da9e98003be9ea388013ae4385d341e46f Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Tue, 10 Feb 2009 18:11:44 +0000 Subject: wgl: mutex-protect the shared stw_icd struct --- src/gallium/state_trackers/wgl/icd/stw_icd.c | 211 ++++++++++++++++++--------- 1 file changed, 138 insertions(+), 73 deletions(-) (limited to 'src/gallium/state_trackers') diff --git a/src/gallium/state_trackers/wgl/icd/stw_icd.c b/src/gallium/state_trackers/wgl/icd/stw_icd.c index e160004aea4..2cefc5c812c 100644 --- a/src/gallium/state_trackers/wgl/icd/stw_icd.c +++ b/src/gallium/state_trackers/wgl/icd/stw_icd.c @@ -31,6 +31,7 @@ #include "GL/gl.h" #include "pipe/p_debug.h" +#include "pipe/p_thread.h" #include "shared/stw_public.h" #include "icd/stw_icd.h" @@ -41,6 +42,11 @@ struct stw_icd { + pipe_mutex mutex; + + GLCLTPROCTABLE cpt; + boolean cpt_initialized; + struct { struct stw_context *ctx; } ctx_array[DRV_CONTEXT_MAX]; @@ -60,6 +66,8 @@ stw_icd_init( void ) stw_icd = &stw_icd_storage; memset(stw_icd, 0, sizeof *stw_icd); + pipe_mutex_init( stw_icd->mutex ); + return TRUE; } @@ -70,24 +78,30 @@ stw_icd_cleanup(void) 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 ); - /* 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_init( stw_icd->mutex ); stw_icd = NULL; } static struct stw_context * -lookup_context( DHGLRC dhglrc ) +lookup_context( struct stw_icd *icd, + DHGLRC dhglrc ) { if (dhglrc == 0 || dhglrc >= DRV_CONTEXT_MAX) return NULL; - return stw_icd->ctx_array[dhglrc - 1].ctx; + return icd->ctx_array[dhglrc - 1].ctx; } BOOL APIENTRY @@ -96,14 +110,22 @@ DrvCopyContext( DHGLRC dhrcDest, UINT fuMask ) { - struct stw_context *src = lookup_context( dhrcSource ); - struct stw_context *dst = lookup_context( dhrcDest ); + BOOL ret = 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) - return FALSE; + if (src == NULL || dst == NULL) + goto done; - return stw_copy_context( src, dst, fuMask ); + ret = stw_copy_context( src, dst, fuMask ); + } +done: + pipe_mutex_unlock( stw_icd->mutex ); + + return ret; } DHGLRC APIENTRY @@ -111,23 +133,34 @@ DrvCreateLayerContext( HDC hdc, INT iLayerPlane ) { - DWORD i; + DHGLRC handle = 0;; + + 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; + } - for (i = 0; i < DRV_CONTEXT_MAX; i++) { - if (stw_icd->ctx_array[i].ctx == NULL) - goto found_slot; + /* 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; } - - /* No slot available, fail: - */ - return 0; - -found_slot: - stw_icd->ctx_array[i].ctx = stw_create_context( hdc, iLayerPlane ); - if (stw_icd->ctx_array[i].ctx == NULL) - return 0; +done: + pipe_mutex_unlock( stw_icd->mutex ); - return (DHGLRC) i + 1; + return handle; } DHGLRC APIENTRY @@ -141,20 +174,27 @@ BOOL APIENTRY DrvDeleteContext( DHGLRC dhglrc ) { - struct stw_context *ctx; + BOOL ret = FALSE; - ctx = lookup_context( dhglrc ); - if (ctx == NULL) - goto fail; + pipe_mutex_lock( stw_icd->mutex ); + { + struct stw_context *ctx; - if (stw_delete_context( ctx ) == FALSE) - goto fail; + 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; - stw_icd->ctx_array[dhglrc - 1].ctx = NULL; - return TRUE; + } +done: + pipe_mutex_unlock( stw_icd->mutex ); -fail: - return FALSE; + return ret; } BOOL APIENTRY @@ -228,23 +268,29 @@ BOOL APIENTRY DrvReleaseContext( DHGLRC dhglrc ) { - struct stw_context *ctx; + BOOL ret = FALSE; - /* 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( dhglrc ); - if (ctx == NULL) - goto fail; + pipe_mutex_lock( stw_icd->mutex ); + { + struct stw_context *ctx; - if (stw_make_current( NULL, NULL ) == FALSE) - goto fail; + /* 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; - return TRUE; + if (stw_make_current( NULL, NULL ) == FALSE) + goto done; -fail: - return FALSE; + ret = TRUE; + } +done: + pipe_mutex_unlock( stw_icd->mutex ); + + return ret; } void APIENTRY @@ -257,31 +303,15 @@ DrvSetCallbackProcs( return; } -#define GPA_GL( NAME ) disp->NAME = gl##NAME -static GLCLTPROCTABLE cpt; +static void init_proc_table( GLCLTPROCTABLE *cpt ) +{ + GLDISPATCHTABLE *disp = &cpt->glDispatchTable; -PGLCLTPROCTABLE APIENTRY -DrvSetContext( - HDC hdc, - DHGLRC dhglrc, - PFN_SETPROCTABLE pfnSetProcTable ) -{ - struct stw_context *ctx; - GLDISPATCHTABLE *disp = &cpt.glDispatchTable; - - debug_printf( "%s( 0x%p, %u, 0x%p )\n", __FUNCTION__, hdc, dhglrc, pfnSetProcTable ); - - ctx = lookup_context( dhglrc ); - if (ctx == NULL) - return NULL; - - if (!stw_make_current( hdc, ctx )) - return NULL; - - memset( &cpt, 0, sizeof( cpt ) ); - cpt.cEntries = OPENGL_VERSION_110_ENTRIES; + memset( cpt, 0, sizeof *cpt ); + cpt->cEntries = OPENGL_VERSION_110_ENTRIES; +#define GPA_GL( NAME ) disp->NAME = gl##NAME GPA_GL( NewList ); GPA_GL( EndList ); GPA_GL( CallList ); @@ -618,8 +648,43 @@ DrvSetContext( GPA_GL( TexSubImage2D ); GPA_GL( PopClientAttrib ); GPA_GL( PushClientAttrib ); +} + +PGLCLTPROCTABLE APIENTRY +DrvSetContext( + HDC hdc, + DHGLRC dhglrc, + PFN_SETPROCTABLE pfnSetProcTable ) +{ + PGLCLTPROCTABLE result = NULL; + + 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; + } +done: + pipe_mutex_unlock( stw_icd->mutex ); - return &cpt; + return result; } int APIENTRY -- cgit v1.2.3 From f54149a3a3dde8056a8db9b9ac7cef32885946d7 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Tue, 10 Feb 2009 18:21:41 +0000 Subject: wgl: return before locking if stw_icd is NULL --- src/gallium/state_trackers/wgl/icd/stw_icd.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/gallium/state_trackers') diff --git a/src/gallium/state_trackers/wgl/icd/stw_icd.c b/src/gallium/state_trackers/wgl/icd/stw_icd.c index e4f3c669e20..1aa4b8a6e22 100644 --- a/src/gallium/state_trackers/wgl/icd/stw_icd.c +++ b/src/gallium/state_trackers/wgl/icd/stw_icd.c @@ -76,7 +76,7 @@ stw_icd_cleanup(void) { int i; - if(!stw_icd) + if (!stw_icd) return; pipe_mutex_lock( stw_icd->mutex ); @@ -115,6 +115,9 @@ DrvCopyContext( { BOOL ret = FALSE; + if (!stw_icd) + return FALSE; + pipe_mutex_lock( stw_icd->mutex ); { struct stw_context *src = lookup_context( stw_icd, dhrcSource ); @@ -136,7 +139,10 @@ DrvCreateLayerContext( HDC hdc, INT iLayerPlane ) { - DHGLRC handle = 0;; + DHGLRC handle = 0; + + if (!stw_icd) + return handle; pipe_mutex_lock( stw_icd->mutex ); { @@ -179,6 +185,9 @@ DrvDeleteContext( { BOOL ret = FALSE; + if (!stw_icd) + return ret; + pipe_mutex_lock( stw_icd->mutex ); { struct stw_context *ctx; @@ -273,6 +282,9 @@ DrvReleaseContext( { BOOL ret = FALSE; + if (!stw_icd) + return ret; + pipe_mutex_lock( stw_icd->mutex ); { struct stw_context *ctx; @@ -661,6 +673,9 @@ DrvSetContext( { PGLCLTPROCTABLE result = NULL; + if (!stw_icd) + return result; + pipe_mutex_lock( stw_icd->mutex ); { struct stw_context *ctx; -- cgit v1.2.3