From: Erik Faye-Lund Date: Sun, 26 May 2019 08:42:58 +0000 (+0200) Subject: wgl: do not create screen from DllMain X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7b7dbd4fc832eb67a4afd013f8cb623cedcf0d51;p=mesa.git wgl: do not create screen from DllMain There's a lot of operations that aren't allowed from DllMain, so we shouldn't create a driver-screen from there. So let's instead delay this until it's needed from a normal function call. See https://docs.microsoft.com/en-us/windows/win32/dlls/dllmain for details about what is allowed and isn't from DllMain. Reviewed-by: Neha Bhende Tested-by: Marge Bot Part-of: --- diff --git a/src/gallium/state_trackers/wgl/stw_device.c b/src/gallium/state_trackers/wgl/stw_device.c index 86906ececc0..b4cf7b7d667 100644 --- a/src/gallium/state_trackers/wgl/stw_device.c +++ b/src/gallium/state_trackers/wgl/stw_device.c @@ -125,9 +125,7 @@ stw_init(const struct stw_winsys *stw_winsys) stw_dev->smapi->get_param = stw_get_param; - if (!init_screen(stw_winsys)) - goto error1; - + InitializeCriticalSection(&stw_dev->screen_mutex); InitializeCriticalSection(&stw_dev->ctx_mutex); InitializeCriticalSection(&stw_dev->fb_mutex); @@ -136,8 +134,6 @@ stw_init(const struct stw_winsys *stw_winsys) goto error1; } - stw_pixelformat_init(); - /* env var override for WGL_EXT_swap_control, useful for testing/debugging */ const char *s = os_get_option("WGL_SWAP_INTERVAL"); if (s) { @@ -158,6 +154,23 @@ error1: return FALSE; } +boolean +stw_init_screen() +{ + EnterCriticalSection(&stw_dev->screen_mutex); + + if (!stw_dev->screen_initialized) { + stw_dev->screen_initialized = true; + if (!init_screen(stw_dev->stw_winsys)) { + LeaveCriticalSection(&stw_dev->screen_mutex); + return false; + } + stw_pixelformat_init(); + } + + LeaveCriticalSection(&stw_dev->screen_mutex); + return stw_dev->screen != NULL; +} boolean stw_init_thread(void) @@ -202,6 +215,7 @@ stw_cleanup(void) DeleteCriticalSection(&stw_dev->fb_mutex); DeleteCriticalSection(&stw_dev->ctx_mutex); + DeleteCriticalSection(&stw_dev->screen_mutex); if (stw_dev->smapi->destroy) stw_dev->smapi->destroy(stw_dev->smapi); diff --git a/src/gallium/state_trackers/wgl/stw_device.h b/src/gallium/state_trackers/wgl/stw_device.h index 3e1ffebe708..a2cd6c7487c 100644 --- a/src/gallium/state_trackers/wgl/stw_device.h +++ b/src/gallium/state_trackers/wgl/stw_device.h @@ -47,9 +47,11 @@ struct stw_framebuffer; struct stw_device { const struct stw_winsys *stw_winsys; - + + CRITICAL_SECTION screen_mutex; + bool screen_initialized; struct pipe_screen *screen; - + /* Cache some PIPE_CAP_* */ unsigned max_2d_length; @@ -88,6 +90,8 @@ struct stw_device extern struct stw_device *stw_dev; +boolean +stw_init_screen(void); static inline struct stw_context * stw_lookup_context_locked( DHGLRC dhglrc ) diff --git a/src/gallium/state_trackers/wgl/stw_pixelformat.c b/src/gallium/state_trackers/wgl/stw_pixelformat.c index fe54e26845d..8696300f3e0 100644 --- a/src/gallium/state_trackers/wgl/stw_pixelformat.c +++ b/src/gallium/state_trackers/wgl/stw_pixelformat.c @@ -313,6 +313,9 @@ stw_pixelformat_init(void) uint stw_pixelformat_get_count(void) { + if (!stw_init_screen()) + return 0; + return stw_dev->pixelformat_count; } @@ -320,6 +323,9 @@ stw_pixelformat_get_count(void) uint stw_pixelformat_get_extended_count(void) { + if (!stw_init_screen()) + return 0; + return stw_dev->pixelformat_extended_count; }