diff options
Diffstat (limited to 'src/gallium/state_trackers/wgl/shared/stw_device.c')
-rw-r--r-- | src/gallium/state_trackers/wgl/shared/stw_device.c | 69 |
1 files changed, 65 insertions, 4 deletions
diff --git a/src/gallium/state_trackers/wgl/shared/stw_device.c b/src/gallium/state_trackers/wgl/shared/stw_device.c index 6873e813ee..0dca856d73 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_device.c +++ b/src/gallium/state_trackers/wgl/shared/stw_device.c @@ -27,14 +27,19 @@ #include <windows.h> -#include "pipe/p_debug.h" +#include "glapi/glthread.h" +#include "util/u_debug.h" #include "pipe/p_screen.h" #include "shared/stw_device.h" #include "shared/stw_winsys.h" #include "shared/stw_pixelformat.h" #include "shared/stw_public.h" -#include "stw.h" + +#ifdef WIN32_THREADS +extern _glthread_Mutex OneTimeLock; +extern void FreeAllTSD(void); +#endif struct stw_device *stw_dev = NULL; @@ -57,23 +62,35 @@ st_flush_frontbuffer(struct pipe_screen *screen, boolean -stw_shared_init(const struct stw_winsys *stw_winsys) +st_init(const struct stw_winsys *stw_winsys) { static struct stw_device stw_dev_storage; + debug_printf("%s\n", __FUNCTION__); + assert(!stw_dev); stw_dev = &stw_dev_storage; memset(stw_dev, 0, sizeof(*stw_dev)); +#ifdef DEBUG + stw_dev->memdbg_no = debug_memory_begin(); +#endif + stw_dev->stw_winsys = stw_winsys; +#ifdef WIN32_THREADS + _glthread_INIT_MUTEX(OneTimeLock); +#endif + stw_dev->screen = stw_winsys->create_screen(); if(!stw_dev->screen) goto error1; stw_dev->screen->flush_frontbuffer = st_flush_frontbuffer; + pipe_mutex_init( stw_dev->mutex ); + pixelformat_init(); return TRUE; @@ -85,7 +102,51 @@ error1: void -stw_shared_cleanup(void) +st_cleanup(void) { + UINT_PTR i; + + debug_printf("%s\n", __FUNCTION__); + + if (!stw_dev) + return; + + pipe_mutex_lock( stw_dev->mutex ); + { + /* Ensure all contexts are destroyed */ + for (i = 0; i < STW_CONTEXT_MAX; i++) + if (stw_dev->ctx_array[i].ctx) + stw_delete_context( i + 1 ); + } + pipe_mutex_unlock( stw_dev->mutex ); + + pipe_mutex_destroy( stw_dev->mutex ); + + stw_dev->screen->destroy(stw_dev->screen); + +#ifdef WIN32_THREADS + _glthread_DESTROY_MUTEX(OneTimeLock); + FreeAllTSD(); +#endif + +#ifdef DEBUG + debug_memory_end(stw_dev->memdbg_no); +#endif + stw_dev = NULL; } + + +struct stw_context * +stw_lookup_context( UINT_PTR dhglrc ) +{ + if (dhglrc == 0 || + dhglrc >= STW_CONTEXT_MAX) + return NULL; + + if (stw_dev == NULL) + return NULL; + + return stw_dev->ctx_array[dhglrc - 1].ctx; +} + |