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 <bhenden@vmware.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4307>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4307>
This commit is contained in:
Erik Faye-Lund 2019-05-26 10:42:58 +02:00 committed by Marge Bot
parent 99a0864b48
commit 7b7dbd4fc8
3 changed files with 31 additions and 7 deletions

View File

@ -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);

View File

@ -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 )

View File

@ -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;
}