From: Rémi Bernon rbernon@codeweavers.com
--- dlls/win32u/opengl.c | 76 +++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 32 deletions(-)
diff --git a/dlls/win32u/opengl.c b/dlls/win32u/opengl.c index 1e9d60bbebd..3073f3ee4e7 100644 --- a/dlls/win32u/opengl.c +++ b/dlls/win32u/opengl.c @@ -73,20 +73,16 @@ static GLboolean (*pOSMesaMakeCurrent)( OSMesaContext ctx, void *buffer, GLenum GLsizei width, GLsizei height ); static void (*pOSMesaPixelStore)( GLint pname, GLint value );
-static BOOL init_opengl(void) +static struct opengl_funcs *osmesa_get_wgl_driver(void) { - static BOOL init_done = FALSE; static void *osmesa_handle; unsigned int i;
- if (init_done) return (osmesa_handle != NULL); - init_done = TRUE; - osmesa_handle = dlopen( SONAME_LIBOSMESA, RTLD_NOW ); if (osmesa_handle == NULL) { ERR( "Failed to load OSMesa: %s\n", dlerror() ); - return FALSE; + return NULL; }
#define LOAD_FUNCPTR(f) do if (!(p##f = dlsym( osmesa_handle, #f ))) \ @@ -111,12 +107,12 @@ static BOOL init_opengl(void) } }
- return TRUE; + return &osmesa_opengl_funcs;
failed: dlclose( osmesa_handle ); osmesa_handle = NULL; - return FALSE; + return NULL; }
static struct wgl_context *osmesa_create_context( HDC hdc, const PIXELFORMATDESCRIPTOR *descr ) @@ -353,35 +349,60 @@ static struct opengl_funcs osmesa_opengl_funcs = .wgl.p_get_pixel_formats = osmesa_get_pixel_formats, };
+#else /* SONAME_LIBOSMESA */ + static struct opengl_funcs *osmesa_get_wgl_driver(void) { - if (!init_opengl()) - { - static int warned; - if (!warned++) ERR( "OSMesa not available, no OpenGL bitmap support\n" ); - return (void *)-1; - } + return NULL; +}
- return &osmesa_opengl_funcs; +#endif /* SONAME_LIBOSMESA */ + +static struct opengl_funcs *display_funcs; +static struct opengl_funcs *memory_funcs; + +static void memory_funcs_init(void) +{ + memory_funcs = osmesa_get_wgl_driver(); }
-#else /* SONAME_LIBOSMESA */ +static void display_funcs_init(void) +{ + display_funcs = user_driver->pwine_get_wgl_driver( WINE_WGL_DRIVER_VERSION ); +}
-static struct opengl_funcs *osmesa_get_wgl_driver(void) +static struct opengl_funcs *get_dc_funcs( HDC hdc, void *null_funcs ) { + DWORD is_disabled, is_display, is_memdc; + DC *dc; + + 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) + { + static pthread_once_t display_init_once = PTHREAD_ONCE_INIT; + pthread_once( &display_init_once, display_funcs_init ); + return display_funcs ? display_funcs : null_funcs; + } + if (is_memdc) + { + static pthread_once_t memory_init_once = PTHREAD_ONCE_INIT; + pthread_once( &memory_init_once, memory_funcs_init ); + return memory_funcs ? memory_funcs : null_funcs; + } return NULL; }
-#endif /* SONAME_LIBOSMESA */ - /*********************************************************************** * __wine_get_wgl_driver (win32u.@) */ const struct opengl_funcs *__wine_get_wgl_driver( HDC hdc, UINT version ) { - DWORD is_disabled, is_display, is_memdc; - DC *dc; - if (version != WINE_WGL_DRIVER_VERSION) { ERR( "version mismatch, opengl32 wants %u but dibdrv has %u\n", @@ -389,14 +410,5 @@ 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) return user_driver->pwine_get_wgl_driver( version ); - if (is_memdc) return osmesa_get_wgl_driver(); - return (void *)-1; + return get_dc_funcs( hdc, (void *)-1 ); }
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/wineandroid.drv/android.h | 2 +- dlls/wineandroid.drv/init.c | 9 --------- dlls/wineandroid.drv/opengl.c | 32 ++++++++++++-------------------- 3 files changed, 13 insertions(+), 30 deletions(-)
diff --git a/dlls/wineandroid.drv/android.h b/dlls/wineandroid.drv/android.h index 26c6cd9ad20..e3b5467ced1 100644 --- a/dlls/wineandroid.drv/android.h +++ b/dlls/wineandroid.drv/android.h @@ -56,7 +56,7 @@ DECL_FUNCPTR( ANativeWindow_release ); extern pthread_mutex_t drawable_mutex; extern void update_gl_drawable( HWND hwnd ); extern void destroy_gl_drawable( HWND hwnd ); -extern struct opengl_funcs *get_wgl_driver( UINT version ); +extern struct opengl_funcs *ANDROID_wine_get_wgl_driver( UINT version );
/************************************************************************** diff --git a/dlls/wineandroid.drv/init.c b/dlls/wineandroid.drv/init.c index dbc3de1d933..1211ccd102b 100644 --- a/dlls/wineandroid.drv/init.c +++ b/dlls/wineandroid.drv/init.c @@ -294,15 +294,6 @@ UINT ANDROID_UpdateDisplayDevices( const struct gdi_device_manager *device_manag }
-/********************************************************************** - * ANDROID_wine_get_wgl_driver - */ -static struct opengl_funcs *ANDROID_wine_get_wgl_driver( UINT version ) -{ - return get_wgl_driver( version ); -} - - static const struct user_driver_funcs android_drv_funcs = { .dc_funcs.pCreateCompatibleDC = ANDROID_CreateCompatibleDC, diff --git a/dlls/wineandroid.drv/opengl.c b/dlls/wineandroid.drv/opengl.c index 7981b9be9ee..e3315fc805c 100644 --- a/dlls/wineandroid.drv/opengl.c +++ b/dlls/wineandroid.drv/opengl.c @@ -958,24 +958,28 @@ static void init_extensions(void) #undef REDIRECT }
-static BOOL egl_init(void) +/********************************************************************** + * ANDROID_wine_get_wgl_driver + */ +struct opengl_funcs *ANDROID_wine_get_wgl_driver( UINT version ) { - static int retval = -1; EGLConfig *configs; EGLint major, minor, count, i, pass;
- if (retval != -1) return retval; - retval = 0; - + if (version != WINE_WGL_DRIVER_VERSION) + { + ERR( "version mismatch, opengl32 wants %u but driver has %u\n", version, WINE_WGL_DRIVER_VERSION ); + return NULL; + } if (!(egl_handle = dlopen( SONAME_LIBEGL, RTLD_NOW|RTLD_GLOBAL ))) { ERR( "failed to load %s: %s\n", SONAME_LIBEGL, dlerror() ); - return FALSE; + return NULL; } if (!(opengl_handle = dlopen( SONAME_LIBGLESV2, RTLD_NOW|RTLD_GLOBAL ))) { ERR( "failed to load %s: %s\n", SONAME_LIBGLESV2, dlerror() ); - return FALSE; + return NULL; }
#define LOAD_FUNCPTR(func) do { \ @@ -1042,8 +1046,7 @@ static BOOL egl_init(void) }
init_extensions(); - retval = 1; - return TRUE; + return &egl_funcs; }
@@ -1078,14 +1081,3 @@ static struct opengl_funcs egl_funcs = { ALL_WGL_FUNCS } #undef USE_GL_FUNC }; - -struct opengl_funcs *get_wgl_driver( UINT version ) -{ - if (version != WINE_WGL_DRIVER_VERSION) - { - ERR( "version mismatch, opengl32 wants %u but driver has %u\n", version, WINE_WGL_DRIVER_VERSION ); - return NULL; - } - if (!egl_init()) return NULL; - return &egl_funcs; -}
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/winemac.drv/opengl.c | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-)
diff --git a/dlls/winemac.drv/opengl.c b/dlls/winemac.drv/opengl.c index 94f1915d62b..4e1202a0e17 100644 --- a/dlls/winemac.drv/opengl.c +++ b/dlls/winemac.drv/opengl.c @@ -4170,17 +4170,26 @@ static void load_extensions(void) }
-static void init_opengl(void) +/********************************************************************** + * macdrv_wine_get_wgl_driver + */ +struct opengl_funcs *macdrv_wine_get_wgl_driver(UINT version) { unsigned int i;
TRACE("()\n");
+ if (version != WINE_WGL_DRIVER_VERSION) + { + ERR("version mismatch, opengl32 wants %u but macdrv has %u\n", version, WINE_WGL_DRIVER_VERSION); + return NULL; + } + dc_pbuffers = CFDictionaryCreateMutable(NULL, 0, NULL, NULL); if (!dc_pbuffers) { WARN("CFDictionaryCreateMutable failed\n"); - return; + return NULL; }
opengl_handle = dlopen("/System/Library/Frameworks/OpenGL.framework/OpenGL", RTLD_LAZY|RTLD_LOCAL|RTLD_NOLOAD); @@ -4188,7 +4197,7 @@ static void init_opengl(void) { ERR("Failed to load OpenGL: %s\n", dlerror()); ERR("OpenGL support is disabled.\n"); - return; + return NULL; }
for (i = 0; i < ARRAY_SIZE(opengl_func_names); i++) @@ -4229,11 +4238,12 @@ static void init_opengl(void) if (!init_pixel_formats()) goto failed;
- return; + return &opengl_funcs;
failed: dlclose(opengl_handle); opengl_handle = NULL; + return NULL; }
@@ -4580,20 +4590,3 @@ static struct opengl_funcs opengl_funcs = macdrv_get_pixel_formats, /* p_get_pixel_formats */ } }; - -/********************************************************************** - * macdrv_wine_get_wgl_driver - */ -struct opengl_funcs *macdrv_wine_get_wgl_driver(UINT version) -{ - static pthread_once_t init_once = PTHREAD_ONCE_INIT; - - if (version != WINE_WGL_DRIVER_VERSION) - { - ERR("version mismatch, opengl32 wants %u but macdrv has %u\n", version, WINE_WGL_DRIVER_VERSION); - return NULL; - } - - pthread_once(&init_once, init_opengl); - return opengl_handle ? &opengl_funcs : (void *)-1; -}
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/winex11.drv/init.c | 8 ------- dlls/winex11.drv/opengl.c | 47 +++++++++++++++------------------------ dlls/winex11.drv/x11drv.h | 2 +- 3 files changed, 19 insertions(+), 38 deletions(-)
diff --git a/dlls/winex11.drv/init.c b/dlls/winex11.drv/init.c index a0bfab2fb46..70da9b8c094 100644 --- a/dlls/winex11.drv/init.c +++ b/dlls/winex11.drv/init.c @@ -371,14 +371,6 @@ static INT X11DRV_ExtEscape( PHYSDEV dev, INT escape, INT in_count, LPCVOID in_d return 0; }
-/********************************************************************** - * X11DRV_wine_get_wgl_driver - */ -static struct opengl_funcs *X11DRV_wine_get_wgl_driver( UINT version ) -{ - return get_glx_driver( version ); -} -
static const struct user_driver_funcs x11drv_funcs = { diff --git a/dlls/winex11.drv/opengl.c b/dlls/winex11.drv/opengl.c index 78b00677099..b661424de76 100644 --- a/dlls/winex11.drv/opengl.c +++ b/dlls/winex11.drv/opengl.c @@ -540,11 +540,20 @@ done:
static void *opengl_handle;
-static void init_opengl(void) +/********************************************************************** + * X11DRV_wine_get_wgl_driver + */ +struct opengl_funcs *X11DRV_wine_get_wgl_driver(UINT version) { int error_base, event_base; unsigned int i;
+ if (version != WINE_WGL_DRIVER_VERSION) + { + ERR( "version mismatch, opengl32 wants %u but driver has %u\n", version, WINE_WGL_DRIVER_VERSION ); + return NULL; + } + /* No need to load any other libraries as according to the ABI, libGL should be self-sufficient and include all dependencies */ opengl_handle = dlopen( SONAME_LIBGL, RTLD_NOW | RTLD_GLOBAL ); @@ -552,7 +561,7 @@ static void init_opengl(void) { ERR( "Failed to load libGL: %s\n", dlerror() ); ERR( "OpenGL support is disabled.\n"); - return; + return NULL; }
for (i = 0; i < ARRAY_SIZE( opengl_func_names ); i++) @@ -720,18 +729,13 @@ static void init_opengl(void)
X11DRV_WineGL_LoadExtensions(); init_pixel_formats( gdi_display ); - return; + + return &opengl_funcs;
failed: dlclose(opengl_handle); opengl_handle = NULL; -} - -static BOOL has_opengl(void) -{ - static pthread_once_t init_once = PTHREAD_ONCE_INIT; - - return !pthread_once( &init_once, init_opengl ); + return NULL; }
static const char *debugstr_fbconfig( GLXFBConfig fbconfig ) @@ -1402,8 +1406,6 @@ static int describe_pixel_format( int iPixelFormat, struct wgl_pixel_format *pf int rb, gb, bb, ab; const struct glx_pixel_format *fmt;
- if (!has_opengl()) return 0; - /* Look for the iPixelFormat in our list of supported formats. If it is * supported we get the index in the FBConfig table and the number of * supported formats back */ @@ -2883,11 +2885,6 @@ static void glxdrv_get_pixel_formats( struct wgl_pixel_format *formats, { UINT i;
- if (!has_opengl()) - { - *num_formats = *num_onscreen_formats = 0; - return; - } if (formats) { for (i = 0; i < min( max_formats, nb_pixel_formats ); ++i) @@ -2913,20 +2910,12 @@ static struct opengl_funcs opengl_funcs = } };
-struct opengl_funcs *get_glx_driver( UINT version ) -{ - if (version != WINE_WGL_DRIVER_VERSION) - { - ERR( "version mismatch, opengl32 wants %u but driver has %u\n", version, WINE_WGL_DRIVER_VERSION ); - return NULL; - } - if (has_opengl()) return &opengl_funcs; - return NULL; -} - #else /* no OpenGL includes */
-struct opengl_funcs *get_glx_driver( UINT version ) +/********************************************************************** + * X11DRV_wine_get_wgl_driver + */ +struct opengl_funcs *X11DRV_wine_get_wgl_driver(UINT version) { return NULL; } diff --git a/dlls/winex11.drv/x11drv.h b/dlls/winex11.drv/x11drv.h index 8e383ae4c48..91811cfd766 100644 --- a/dlls/winex11.drv/x11drv.h +++ b/dlls/winex11.drv/x11drv.h @@ -282,7 +282,7 @@ extern BOOL client_side_with_render; extern BOOL shape_layered_windows; extern const struct gdi_dc_funcs *X11DRV_XRender_Init(void);
-extern struct opengl_funcs *get_glx_driver(UINT); +extern struct opengl_funcs *X11DRV_wine_get_wgl_driver( UINT version ); extern UINT X11DRV_VulkanInit( UINT, void *, const struct vulkan_driver_funcs ** );
extern struct format_entry *import_xdnd_selection( Display *display, Window win, Atom selection,
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/winewayland.drv/opengl.c | 47 +++++++++++------------------------ 1 file changed, 14 insertions(+), 33 deletions(-)
diff --git a/dlls/winewayland.drv/opengl.c b/dlls/winewayland.drv/opengl.c index b8b673f398a..18d304c2754 100644 --- a/dlls/winewayland.drv/opengl.c +++ b/dlls/winewayland.drv/opengl.c @@ -1155,19 +1155,12 @@ static void describe_pixel_format(EGLConfig config, struct wgl_pixel_format *fmt #undef SET_ATTRIB_ARB }
-static BOOL has_opengl(void); - static void wayland_get_pixel_formats(struct wgl_pixel_format *formats, UINT max_formats, UINT *num_formats, UINT *num_onscreen_formats) { UINT i;
- if (!has_opengl()) - { - *num_formats = *num_onscreen_formats = 0; - return; - } if (formats) { for (i = 0; i < min(max_formats, num_egl_configs); ++i) @@ -1320,15 +1313,25 @@ static BOOL init_egl_configs(void) return TRUE; }
-static void init_opengl(void) +/********************************************************************** + * WAYLAND_wine_get_wgl_driver + */ +struct opengl_funcs *WAYLAND_wine_get_wgl_driver(UINT version) { EGLint egl_version[2]; const char *egl_client_exts, *egl_exts;
+ if (version != WINE_WGL_DRIVER_VERSION) + { + ERR("Version mismatch, opengl32 wants %u but driver has %u\n", + version, WINE_WGL_DRIVER_VERSION); + return NULL; + } + if (!(egl_handle = dlopen(SONAME_LIBEGL, RTLD_NOW|RTLD_GLOBAL))) { ERR("Failed to load %s: %s\n", SONAME_LIBEGL, dlerror()); - return; + return NULL; }
#define LOAD_FUNCPTR_DLSYM(func) \ @@ -1403,19 +1406,12 @@ static void init_opengl(void)
if (!init_opengl_funcs()) goto err; if (!init_egl_configs()) goto err; - - return; + return &opengl_funcs;
err: dlclose(egl_handle); egl_handle = NULL; -} - -static BOOL has_opengl(void) -{ - static pthread_once_t init_once = PTHREAD_ONCE_INIT; - - return !pthread_once(&init_once, init_opengl) && egl_handle; + return NULL; }
static struct opengl_funcs opengl_funcs = @@ -1434,21 +1430,6 @@ static struct opengl_funcs opengl_funcs = } };
-/********************************************************************** - * WAYLAND_wine_get_wgl_driver - */ -struct opengl_funcs *WAYLAND_wine_get_wgl_driver(UINT version) -{ - if (version != WINE_WGL_DRIVER_VERSION) - { - ERR("Version mismatch, opengl32 wants %u but driver has %u\n", - version, WINE_WGL_DRIVER_VERSION); - return NULL; - } - if (!has_opengl()) return NULL; - return &opengl_funcs; -} - /********************************************************************** * wayland_destroy_gl_drawable */