From 19068d93c8f0f1d2b8809248266bf6da3dc6abd7 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Thu, 9 Apr 2009 11:09:42 +0100 Subject: stw: Normalize symbols prefix. --- src/gallium/state_trackers/wgl/shared/stw_device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gallium/state_trackers/wgl/shared/stw_device.c') diff --git a/src/gallium/state_trackers/wgl/shared/stw_device.c b/src/gallium/state_trackers/wgl/shared/stw_device.c index 51936c2bdd..78d3ac8313 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_device.c +++ b/src/gallium/state_trackers/wgl/shared/stw_device.c @@ -119,7 +119,7 @@ st_init(const struct stw_winsys *stw_winsys) goto error1; } - pixelformat_init(); + stw_pixelformat_init(); return TRUE; -- cgit v1.2.3 From 858d3da441d3548eae23c91b3bc888c3b0233797 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Thu, 9 Apr 2009 14:58:17 +0100 Subject: wgl: Move the framebuffer list to the device. Avoid recursive locking. --- .../state_trackers/wgl/shared/stw_context.c | 58 ++++++++------------ src/gallium/state_trackers/wgl/shared/stw_device.c | 2 +- src/gallium/state_trackers/wgl/shared/stw_device.h | 5 +- .../state_trackers/wgl/shared/stw_framebuffer.c | 63 ++++++++++++---------- 4 files changed, 62 insertions(+), 66 deletions(-) (limited to 'src/gallium/state_trackers/wgl/shared/stw_device.c') diff --git a/src/gallium/state_trackers/wgl/shared/stw_context.c b/src/gallium/state_trackers/wgl/shared/stw_context.c index f01151ba53..07d7452eb5 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_context.c +++ b/src/gallium/state_trackers/wgl/shared/stw_context.c @@ -59,8 +59,8 @@ stw_copy_context( pipe_mutex_lock( stw_dev->mutex ); - src = stw_lookup_context( hglrcSrc ); - dst = stw_lookup_context( hglrcDst ); + src = stw_lookup_context_locked( hglrcSrc ); + dst = stw_lookup_context_locked( hglrcDst ); if (src && dst) { /* FIXME */ @@ -155,9 +155,7 @@ stw_create_layer_context( ctx->st->ctx->DriverCtx = ctx; pipe_mutex_lock( stw_dev->mutex ); - { - hglrc = handle_table_add(stw_dev->ctx_table, ctx); - } + hglrc = handle_table_add(stw_dev->ctx_table, ctx); pipe_mutex_unlock( stw_dev->mutex ); /* Success? @@ -187,8 +185,10 @@ stw_delete_context( return FALSE; pipe_mutex_lock( stw_dev->mutex ); + ctx = stw_lookup_context_locked(hglrc); + handle_table_remove(stw_dev->ctx_table, hglrc); + pipe_mutex_unlock( stw_dev->mutex ); - ctx = stw_lookup_context(hglrc); if (ctx) { GLcontext *glctx = ctx->st->ctx; GET_CURRENT_CONTEXT( glcurctx ); @@ -206,19 +206,12 @@ stw_delete_context( if (WindowFromDC( ctx->hdc ) != NULL) ReleaseDC( WindowFromDC( ctx->hdc ), ctx->hdc ); - pipe_mutex_lock(stw_dev->mutex); - { - st_destroy_context(ctx->st); - FREE(ctx); - handle_table_remove(stw_dev->ctx_table, hglrc); - } - pipe_mutex_unlock(stw_dev->mutex); + st_destroy_context(ctx->st); + FREE(ctx); ret = TRUE; } - pipe_mutex_unlock( stw_dev->mutex ); - return ret; } @@ -226,32 +219,27 @@ BOOL stw_release_context( UINT_PTR hglrc ) { - BOOL ret = FALSE; + struct stw_context *ctx; if (!stw_dev) - return ret; + return FALSE; pipe_mutex_lock( stw_dev->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 = stw_lookup_context( hglrc ); - if (ctx == NULL) - goto done; + ctx = stw_lookup_context_locked( hglrc ); + pipe_mutex_unlock( stw_dev->mutex ); - if (stw_make_current( NULL, 0 ) == FALSE) - goto done; + if (!ctx) + return 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. + */ - ret = TRUE; - } -done: - pipe_mutex_unlock( stw_dev->mutex ); + if (stw_make_current( NULL, 0 ) == FALSE) + return FALSE; - return ret; + return TRUE; } /* Find the width and height of the window named by hdc. @@ -300,7 +288,7 @@ stw_make_current( return FALSE; pipe_mutex_lock( stw_dev->mutex ); - ctx = stw_lookup_context( hglrc ); + ctx = stw_lookup_context_locked( hglrc ); pipe_mutex_unlock( stw_dev->mutex ); stw_tls_get_data()->currentDC = hdc; diff --git a/src/gallium/state_trackers/wgl/shared/stw_device.c b/src/gallium/state_trackers/wgl/shared/stw_device.c index 78d3ac8313..c6d59afa03 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_device.c +++ b/src/gallium/state_trackers/wgl/shared/stw_device.c @@ -189,7 +189,7 @@ st_cleanup(void) struct stw_context * -stw_lookup_context( UINT_PTR dhglrc ) +stw_lookup_context_locked( UINT_PTR dhglrc ) { if (dhglrc == 0) return NULL; diff --git a/src/gallium/state_trackers/wgl/shared/stw_device.h b/src/gallium/state_trackers/wgl/shared/stw_device.h index 703cb67081..0ce0d54cac 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_device.h +++ b/src/gallium/state_trackers/wgl/shared/stw_device.h @@ -35,6 +35,7 @@ struct pipe_screen; +struct stw_framebuffer; struct stw_device { @@ -50,13 +51,15 @@ struct stw_device struct handle_table *ctx_table; + struct stw_framebuffer *fb_head; + #ifdef DEBUG unsigned long memdbg_no; #endif }; struct stw_context * -stw_lookup_context( UINT_PTR hglrc ); +stw_lookup_context_locked( UINT_PTR hglrc ); extern struct stw_device *stw_dev; diff --git a/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c b/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c index a1202ab14d..d6cf6fb534 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c +++ b/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c @@ -53,8 +53,6 @@ stw_framebuffer_resize( st_resize_framebuffer( fb->stfb, width, height ); } -static struct stw_framebuffer *fb_head = NULL; - static LRESULT CALLBACK stw_window_proc( HWND hWnd, @@ -64,9 +62,11 @@ stw_window_proc( { struct stw_framebuffer *fb; - for (fb = fb_head; fb != NULL; fb = fb->next) + pipe_mutex_lock( stw_dev->mutex ); + for (fb = stw_dev->fb_head; fb != NULL; fb = fb->next) if (fb->hWnd == hWnd) break; + pipe_mutex_unlock( stw_dev->mutex ); assert( fb != NULL ); if (uMsg == WM_SIZE && wParam != SIZE_MINIMIZED) @@ -201,8 +201,11 @@ stw_framebuffer_create( (LONG_PTR) stw_window_proc ); } - fb->next = fb_head; - fb_head = fb; + pipe_mutex_lock( stw_dev->mutex ); + fb->next = stw_dev->fb_head; + stw_dev->fb_head = fb; + pipe_mutex_unlock( stw_dev->mutex ); + return fb; } @@ -210,29 +213,28 @@ void stw_framebuffer_destroy( struct stw_framebuffer *fb ) { - struct stw_framebuffer **link = &fb_head; - struct stw_framebuffer *pfb = fb_head; - - while (pfb != NULL) { - if (pfb == fb) { - if (fb->hWnd != NULL) { - SetWindowLongPtr( - fb->hWnd, - GWLP_WNDPROC, - (LONG_PTR) fb->WndProc ); - } - - *link = fb->next; - FREE( fb ); - return; - } - - link = &pfb->next; - pfb = pfb->next; - } + struct stw_framebuffer **link; + + pipe_mutex_lock( stw_dev->mutex ); + + link = &stw_dev->fb_head; + while (link && *link != fb) + link = &(*link)->next; + assert(*link); + if (link) + *link = fb->next; + fb->next = NULL; + + pipe_mutex_unlock( stw_dev->mutex ); + + if (fb->hWnd) + SetWindowLongPtr( fb->hWnd, GWLP_WNDPROC, (LONG_PTR)fb->WndProc ); + + FREE( fb ); } -/* Given an hdc, return the corresponding stw_framebuffer. +/** + * Given an hdc, return the corresponding stw_framebuffer. */ struct stw_framebuffer * stw_framebuffer_from_hdc( @@ -240,10 +242,13 @@ stw_framebuffer_from_hdc( { struct stw_framebuffer *fb; - for (fb = fb_head; fb != NULL; fb = fb->next) + pipe_mutex_lock( stw_dev->mutex ); + for (fb = stw_dev->fb_head; fb != NULL; fb = fb->next) if (fb->hDC == hdc) - return fb; - return NULL; + break; + pipe_mutex_unlock( stw_dev->mutex ); + + return fb; } -- cgit v1.2.3 From 4bbb5eb96ad9f2e5b6e064854eeb5f5cb1498f9d Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Thu, 9 Apr 2009 20:35:55 +0100 Subject: wgl: Use hooks instead of subclassing the window. Subclassing the window is invasive: we might call an old window proc even after it was removed. Glut and another bug just in the wrong time was provoking this. Hooks don't have this problem. --- src/gallium/state_trackers/wgl/shared/stw_device.c | 8 +- .../state_trackers/wgl/shared/stw_framebuffer.c | 95 ++++++++++++++++------ .../state_trackers/wgl/shared/stw_framebuffer.h | 7 +- src/gallium/state_trackers/wgl/shared/stw_tls.h | 3 + 4 files changed, 83 insertions(+), 30 deletions(-) (limited to 'src/gallium/state_trackers/wgl/shared/stw_device.c') diff --git a/src/gallium/state_trackers/wgl/shared/stw_device.c b/src/gallium/state_trackers/wgl/shared/stw_device.c index c6d59afa03..8e0193d7be 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_device.c +++ b/src/gallium/state_trackers/wgl/shared/stw_device.c @@ -41,6 +41,7 @@ #include "shared/stw_pixelformat.h" #include "shared/stw_public.h" #include "shared/stw_tls.h" +#include "shared/stw_framebuffer.h" #ifdef WIN32_THREADS extern _glthread_Mutex OneTimeLock; @@ -132,9 +133,11 @@ error1: boolean st_init_thread(void) { - if (!stw_tls_init_thread()) { + if (!stw_tls_init_thread()) + return FALSE; + + if (!stw_framebuffer_init_thread()) return FALSE; - } return TRUE; } @@ -143,6 +146,7 @@ st_init_thread(void) void st_cleanup_thread(void) { + stw_framebuffer_cleanup_thread(); stw_tls_cleanup_thread(); } diff --git a/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c b/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c index d6cf6fb534..053f741e7b 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c +++ b/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c @@ -42,6 +42,7 @@ #include "stw_device.h" #include "stw_public.h" #include "stw_winsys.h" +#include "stw_tls.h" void @@ -53,26 +54,43 @@ stw_framebuffer_resize( st_resize_framebuffer( fb->stfb, width, height ); } +/** + * @sa http://msdn.microsoft.com/en-us/library/ms644975(VS.85).aspx + * @sa http://msdn.microsoft.com/en-us/library/ms644960(VS.85).aspx + */ static LRESULT CALLBACK -stw_window_proc( - HWND hWnd, - UINT uMsg, +stw_call_window_proc( + int nCode, WPARAM wParam, LPARAM lParam ) { - struct stw_framebuffer *fb; - - pipe_mutex_lock( stw_dev->mutex ); - for (fb = stw_dev->fb_head; fb != NULL; fb = fb->next) - if (fb->hWnd == hWnd) - break; - pipe_mutex_unlock( stw_dev->mutex ); - assert( fb != NULL ); - - if (uMsg == WM_SIZE && wParam != SIZE_MINIMIZED) - stw_framebuffer_resize( fb, LOWORD( lParam ), HIWORD( lParam ) ); + struct stw_tls_data *tls_data; + PCWPSTRUCT pParams = (PCWPSTRUCT)lParam; + + tls_data = stw_tls_get_data(); + if(!tls_data) + return 0; + + if (nCode < 0) + return CallNextHookEx(tls_data->hCallWndProcHook, nCode, wParam, lParam); + + if (pParams->message == WM_SIZE && pParams->wParam != SIZE_MINIMIZED) { + struct stw_framebuffer *fb; + + pipe_mutex_lock( stw_dev->mutex ); + for (fb = stw_dev->fb_head; fb != NULL; fb = fb->next) + if (fb->hWnd == pParams->hwnd) + break; + pipe_mutex_unlock( stw_dev->mutex ); + + if(fb) { + unsigned width = LOWORD( pParams->lParam ); + unsigned height = HIWORD( pParams->lParam ); + stw_framebuffer_resize( fb, width, height ); + } + } - return CallWindowProc( fb->WndProc, hWnd, uMsg, wParam, lParam ); + return CallNextHookEx(tls_data->hCallWndProcHook, nCode, wParam, lParam); } static INLINE boolean @@ -190,16 +208,7 @@ stw_framebuffer_create( fb->cColorBits = GetDeviceCaps( hdc, BITSPIXEL ); fb->hDC = hdc; - - /* Subclass a window associated with the device context. - */ fb->hWnd = WindowFromDC( hdc ); - if (fb->hWnd != NULL) { - fb->WndProc = (WNDPROC) SetWindowLongPtr( - fb->hWnd, - GWLP_WNDPROC, - (LONG_PTR) stw_window_proc ); - } pipe_mutex_lock( stw_dev->mutex ); fb->next = stw_dev->fb_head; @@ -227,9 +236,6 @@ stw_framebuffer_destroy( pipe_mutex_unlock( stw_dev->mutex ); - if (fb->hWnd) - SetWindowLongPtr( fb->hWnd, GWLP_WNDPROC, (LONG_PTR)fb->WndProc ); - FREE( fb ); } @@ -286,3 +292,38 @@ stw_swap_buffers( return TRUE; } + + +boolean +stw_framebuffer_init_thread(void) +{ + struct stw_tls_data *tls_data; + + tls_data = stw_tls_get_data(); + if(!tls_data) + return FALSE; + + tls_data->hCallWndProcHook = SetWindowsHookEx(WH_CALLWNDPROC, + stw_call_window_proc, + NULL, + GetCurrentThreadId()); + if(tls_data->hCallWndProcHook == NULL) + return FALSE; + + return TRUE; +} + +void +stw_framebuffer_cleanup_thread(void) +{ + struct stw_tls_data *tls_data; + + tls_data = stw_tls_get_data(); + if(!tls_data) + return; + + if(tls_data->hCallWndProcHook) { + UnhookWindowsHookEx(tls_data->hCallWndProcHook); + tls_data->hCallWndProcHook = NULL; + } +} diff --git a/src/gallium/state_trackers/wgl/shared/stw_framebuffer.h b/src/gallium/state_trackers/wgl/shared/stw_framebuffer.h index c2822f6d6d..245fdc5fc9 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_framebuffer.h +++ b/src/gallium/state_trackers/wgl/shared/stw_framebuffer.h @@ -39,7 +39,6 @@ struct stw_framebuffer HDC hDC; BYTE cColorBits; HWND hWnd; - WNDPROC WndProc; struct stw_framebuffer *next; }; @@ -64,4 +63,10 @@ struct stw_framebuffer * stw_framebuffer_from_hdc( HDC hdc ); +boolean +stw_framebuffer_init_thread(void); + +void +stw_framebuffer_cleanup_thread(void); + #endif /* STW_FRAMEBUFFER_H */ diff --git a/src/gallium/state_trackers/wgl/shared/stw_tls.h b/src/gallium/state_trackers/wgl/shared/stw_tls.h index 23b61e68ff..f5a6bdf4b1 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_tls.h +++ b/src/gallium/state_trackers/wgl/shared/stw_tls.h @@ -28,11 +28,14 @@ #ifndef STW_TLS_H #define STW_TLS_H +#include + struct stw_tls_data { uint currentPixelFormat; HDC currentDC; UINT_PTR currentGLRC; + HHOOK hCallWndProcHook; }; boolean -- cgit v1.2.3 From 81660a44dc25648659ac590a37854103c36f9ce4 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Thu, 9 Apr 2009 20:41:59 +0100 Subject: wgl: Use more stw_* names. --- src/gallium/state_trackers/wgl/shared/stw_device.c | 8 ++++---- src/gallium/state_trackers/wgl/shared/stw_winsys.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/gallium/state_trackers/wgl/shared/stw_device.c') diff --git a/src/gallium/state_trackers/wgl/shared/stw_device.c b/src/gallium/state_trackers/wgl/shared/stw_device.c index 8e0193d7be..eef848988c 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_device.c +++ b/src/gallium/state_trackers/wgl/shared/stw_device.c @@ -76,7 +76,7 @@ st_flush_frontbuffer(struct pipe_screen *screen, boolean -st_init(const struct stw_winsys *stw_winsys) +stw_init(const struct stw_winsys *stw_winsys) { static struct stw_device stw_dev_storage; struct pipe_screen *screen; @@ -131,7 +131,7 @@ error1: boolean -st_init_thread(void) +stw_init_thread(void) { if (!stw_tls_init_thread()) return FALSE; @@ -144,7 +144,7 @@ st_init_thread(void) void -st_cleanup_thread(void) +stw_cleanup_thread(void) { stw_framebuffer_cleanup_thread(); stw_tls_cleanup_thread(); @@ -152,7 +152,7 @@ st_cleanup_thread(void) void -st_cleanup(void) +stw_cleanup(void) { unsigned i; diff --git a/src/gallium/state_trackers/wgl/shared/stw_winsys.h b/src/gallium/state_trackers/wgl/shared/stw_winsys.h index e4a1d4f979..c0bf82c9ed 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_winsys.h +++ b/src/gallium/state_trackers/wgl/shared/stw_winsys.h @@ -51,15 +51,15 @@ struct stw_winsys }; boolean -st_init(const struct stw_winsys *stw_winsys); +stw_init(const struct stw_winsys *stw_winsys); boolean -st_init_thread(void); +stw_init_thread(void); void -st_cleanup_thread(void); +stw_cleanup_thread(void); void -st_cleanup(void); +stw_cleanup(void); #endif /* STW_WINSYS_H */ -- cgit v1.2.3