From: Rémi Bernon <rbernon(a)codeweavers.com> Allowing win32u to use the OpenGL function table without requiring opengl32 module initialization. --- dlls/opengl32/unix_private.h | 8 +++++--- dlls/opengl32/unix_wgl.c | 3 +++ dlls/win32u/dc.c | 4 ++++ dlls/win32u/driver.c | 7 ++++++- dlls/win32u/opengl.c | 12 +----------- include/ntgdi.h | 3 ++- 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/dlls/opengl32/unix_private.h b/dlls/opengl32/unix_private.h index a4603d0fdf6..2e2c41d9bdc 100644 --- a/dlls/opengl32/unix_private.h +++ b/dlls/opengl32/unix_private.h @@ -45,12 +45,14 @@ extern const struct registry_entry extension_registry[]; extern const int extension_registry_size; extern struct opengl_funcs null_opengl_funcs; +extern const struct opengl_funcs *opengl_funcs; static inline const struct opengl_funcs *get_dc_funcs( HDC hdc ) { - const struct opengl_funcs *funcs = __wine_get_wgl_driver( hdc, WINE_OPENGL_DRIVER_VERSION ); - if (!funcs) RtlSetLastWin32Error( ERROR_INVALID_HANDLE ); - return funcs; + DWORD has_opengl; + if (NtGdiGetDCDword( hdc, NtGdiHasOpenGL, &has_opengl ) && has_opengl) return opengl_funcs; + RtlSetLastWin32Error( ERROR_INVALID_HANDLE ); + return &null_opengl_funcs; } #ifdef _WIN64 diff --git a/dlls/opengl32/unix_wgl.c b/dlls/opengl32/unix_wgl.c index 6b00e22c0d1..ae95a25f40d 100644 --- a/dlls/opengl32/unix_wgl.c +++ b/dlls/opengl32/unix_wgl.c @@ -53,6 +53,7 @@ static BOOL is_wow64(void) return !!NtCurrentTeb()->WowTebOffset; } +const struct opengl_funcs *opengl_funcs; static UINT64 call_gl_debug_message_callback; pthread_mutex_t wgl_lock = PTHREAD_MUTEX_INITIALIZER; @@ -2075,6 +2076,8 @@ NTSTATUS process_attach( void *args ) NtQuerySystemInformation( SystemEmulationBasicInformation, &info, sizeof(info), NULL ); zero_bits = (ULONG_PTR)info.HighestUserAddress | 0x7fffffff; } + + opengl_funcs = __wine_get_opengl_driver( WINE_OPENGL_DRIVER_VERSION ); return STATUS_SUCCESS; } diff --git a/dlls/win32u/dc.c b/dlls/win32u/dc.c index 839fd821175..ccfb3893136 100644 --- a/dlls/win32u/dc.c +++ b/dlls/win32u/dc.c @@ -1051,6 +1051,10 @@ BOOL WINAPI NtGdiGetDCDword( HDC hdc, UINT method, DWORD *result ) *result = get_gdi_object_type( hdc ) == NTGDI_OBJ_MEMDC; break; + case NtGdiHasOpenGL: + *result = get_gdi_object_type( hdc ) == NTGDI_OBJ_MEMDC || dc->is_display; + break; + default: WARN( "unknown method %u\n", method ); ret = FALSE; diff --git a/dlls/win32u/driver.c b/dlls/win32u/driver.c index 090a257b658..60aba702d1a 100644 --- a/dlls/win32u/driver.c +++ b/dlls/win32u/driver.c @@ -1235,6 +1235,11 @@ static UINT loaderdrv_VulkanInit( UINT version, void *vulkan_handle, const struc return load_driver()->pVulkanInit( version, vulkan_handle, driver_funcs ); } +static UINT loaderdrv_OpenGLInit( UINT version, const struct opengl_funcs *opengl_funcs, const struct opengl_driver_funcs **driver_funcs ) +{ + return load_driver()->pOpenGLInit( version, opengl_funcs, driver_funcs ); +} + static const struct user_driver_funcs lazy_load_driver = { { NULL }, @@ -1308,7 +1313,7 @@ static const struct user_driver_funcs lazy_load_driver = /* vulkan support */ loaderdrv_VulkanInit, /* opengl support */ - nulldrv_OpenGLInit, + loaderdrv_OpenGLInit, /* thread management */ nulldrv_ThreadDetach, }; diff --git a/dlls/win32u/opengl.c b/dlls/win32u/opengl.c index 3cafe9113b5..0a289dc9eb5 100644 --- a/dlls/win32u/opengl.c +++ b/dlls/win32u/opengl.c @@ -2551,11 +2551,9 @@ static void display_funcs_init(void) /*********************************************************************** * __wine_get_wgl_driver (win32u.@) */ -const struct opengl_funcs *__wine_get_wgl_driver( HDC hdc, UINT version ) +const struct opengl_funcs *__wine_get_opengl_driver( UINT version ) { static pthread_once_t init_once = PTHREAD_ONCE_INIT; - DWORD is_disabled, is_display, is_memdc; - DC *dc; if (version != WINE_OPENGL_DRIVER_VERSION) { @@ -2564,14 +2562,6 @@ const struct opengl_funcs *__wine_get_wgl_driver( HDC hdc, UINT version ) return NULL; } - if (!(dc = get_dc_ptr( hdc ))) return NULL; - is_memdc = get_gdi_object_type( hdc ) == NTGDI_OBJ_MEMDC; - is_display = dc->is_display; - is_disabled = dc->attr->disabled; - release_dc_ptr( dc ); - - if (is_disabled) return NULL; - if (!is_display && !is_memdc) return NULL; pthread_once( &init_once, display_funcs_init ); return &display_funcs; } diff --git a/include/ntgdi.h b/include/ntgdi.h index d97c19bdab2..8d89b318c2d 100644 --- a/include/ntgdi.h +++ b/include/ntgdi.h @@ -140,6 +140,7 @@ enum NtGdiGetROP2, NtGdiGetTextColor, NtGdiIsMemDC, + NtGdiHasOpenGL, }; /* NtGdiGetDCPoint parameter, not compatible with Windows */ @@ -565,6 +566,6 @@ W32KAPI NTSTATUS WINAPI NtGdiDdDDIWaitForSynchronizationObjectFromCpu( const D3D /* Wine extensions */ W32KAPI const struct vulkan_funcs *__wine_get_vulkan_driver( UINT version ); -W32KAPI const struct opengl_funcs *__wine_get_wgl_driver( HDC hdc, UINT version ); +W32KAPI const struct opengl_funcs *__wine_get_opengl_driver( UINT version ); #endif /* _NTGDI_ */ -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/9661