From: Rémi Bernon <rbernon@codeweavers.com> --- dlls/win32u/opengl.c | 21 +++++++++++++-------- dlls/wineandroid.drv/opengl.c | 13 ++++--------- dlls/winemac.drv/opengl.c | 13 ++++--------- dlls/winewayland.drv/opengl.c | 18 +++++------------- dlls/winex11.drv/opengl.c | 29 ++++++----------------------- include/wine/opengl_driver.h | 4 ++-- 6 files changed, 34 insertions(+), 64 deletions(-) diff --git a/dlls/win32u/opengl.c b/dlls/win32u/opengl.c index 089452198de..5e09b7ced13 100644 --- a/dlls/win32u/opengl.c +++ b/dlls/win32u/opengl.c @@ -660,14 +660,9 @@ static void egldrv_init_extensions( struct opengl_funcs *funcs, BOOLEAN extensio { } -static BOOL egldrv_surface_create( HWND hwnd, int format, struct opengl_drawable **drawable ) +static BOOL egldrv_surface_create( struct client_surface *client, int format, struct opengl_drawable **drawable ) { - struct client_surface *client; - - if (!(client = user_driver->pCreateClientSurface( hwnd, format ))) return FALSE; *drawable = framebuffer_surface_create( format, client ); - client_surface_release( client ); - return !!*drawable; } @@ -1276,7 +1271,7 @@ static void nulldrv_init_extensions( struct opengl_funcs *funcs, BOOLEAN extensi { } -static BOOL nulldrv_surface_create( HWND hwnd, int format, struct opengl_drawable **drawable ) +static BOOL nulldrv_surface_create( struct client_surface *client, int format, struct opengl_drawable **drawable ) { return TRUE; } @@ -1407,7 +1402,17 @@ static struct opengl_drawable *get_window_unused_drawable( HWND hwnd, int format */ if (!drawable) { - driver_funcs->p_surface_create( hwnd, format, &drawable ); + struct client_surface *client; + + if (!(client = user_driver->pCreateClientSurface( hwnd, format ))) + WARN( "Failed to create a surface for window %p, format %d\n", hwnd, format ); + else + { + if (!(driver_funcs->p_surface_create( client, format, &drawable ))) + WARN( "Failed to create a drawable for window %p, format %d\n", hwnd, format ); + client_surface_release( client ); + } + if (drawable && drawable->client) add_window_client_surface( hwnd, drawable->client ); } diff --git a/dlls/wineandroid.drv/opengl.c b/dlls/wineandroid.drv/opengl.c index 1cec107420d..fc145d33184 100644 --- a/dlls/wineandroid.drv/opengl.c +++ b/dlls/wineandroid.drv/opengl.c @@ -47,7 +47,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(android); static const struct egl_platform *egl; static const struct opengl_funcs *funcs; -static const struct client_surface_funcs android_client_surface_funcs; static const struct opengl_drawable_funcs android_drawable_funcs; struct gl_drawable @@ -82,11 +81,11 @@ void update_gl_drawable( HWND hwnd ) NtUserRedrawWindow( hwnd, NULL, 0, RDW_INVALIDATE | RDW_ERASE ); } -static BOOL android_surface_create( HWND hwnd, int format, struct opengl_drawable **drawable ) +static BOOL android_surface_create( struct client_surface *client, int format, struct opengl_drawable **drawable ) { struct gl_drawable *gl; - TRACE( "hwnd %p, format %d, drawable %p\n", hwnd, format, drawable ); + TRACE( "hwnd %p, format %d, drawable %p\n", client->hwnd, format, drawable ); if (*drawable) { @@ -106,14 +105,10 @@ static BOOL android_surface_create( HWND hwnd, int format, struct opengl_drawabl { static const int attribs[] = { EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE }; EGLConfig config = egl_config_for_format( format ); - struct client_surface *client; - - if (!(client = ANDROID_ClientSurfaceCreate( hwnd, format ))) return FALSE; - gl = opengl_drawable_create( sizeof(*gl), &android_drawable_funcs, format, client ); - client_surface_release( client ); - if (!gl) return FALSE; + if (!(gl = opengl_drawable_create( sizeof(*gl), &android_drawable_funcs, format, client ))) return FALSE; gl->window = get_client_window( client->hwnd ); + if (!has_client_surface( client->hwnd )) gl->base.surface = funcs->p_eglCreatePbufferSurface( egl->display, config, attribs ); else gl->base.surface = funcs->p_eglCreateWindowSurface( egl->display, config, gl->window, NULL ); diff --git a/dlls/winemac.drv/opengl.c b/dlls/winemac.drv/opengl.c index 86830bffc80..37e63a449b7 100644 --- a/dlls/winemac.drv/opengl.c +++ b/dlls/winemac.drv/opengl.c @@ -1455,28 +1455,23 @@ static BOOL create_context(struct macdrv_context *context, CGLContextObj share, return TRUE; } -static BOOL macdrv_surface_create(HWND hwnd, int format, struct opengl_drawable **drawable) +static BOOL macdrv_surface_create(struct client_surface *client, int format, struct opengl_drawable **drawable) { - struct client_surface *client; struct macdrv_win_data *data; + HWND hwnd = client->hwnd; struct gl_drawable *gl; - TRACE("hwnd %p, format %d, drawable %p\n", hwnd, format, drawable); + TRACE("client %s, format %d, drawable %p\n", debugstr_client_surface(client), format, drawable); if (!(data = get_win_data(hwnd))) { FIXME("DC for window %p of other process: not implemented\n", hwnd); return FALSE; } - data->pixel_format = format; release_win_data(data); - if (!(client = macdrv_CreateClientSurface(hwnd, format))) return FALSE; - gl = opengl_drawable_create(sizeof(*gl), &macdrv_surface_funcs, format, client); - client_surface_release(client); - if (!gl) return FALSE; - + if (!(gl = opengl_drawable_create(sizeof(*gl), &macdrv_surface_funcs, format, client))) return FALSE; *drawable = &gl->base; return TRUE; } diff --git a/dlls/winewayland.drv/opengl.c b/dlls/winewayland.drv/opengl.c index 9719c63719d..14cb4ce5a25 100644 --- a/dlls/winewayland.drv/opengl.c +++ b/dlls/winewayland.drv/opengl.c @@ -80,19 +80,16 @@ static void wayland_gl_drawable_sync_size(struct wayland_gl_drawable *gl) wl_egl_window_resize(gl->wl_egl_window, client_width, client_height, 0, 0); } -static BOOL wayland_opengl_surface_create(HWND hwnd, int format, struct opengl_drawable **drawable) +static BOOL wayland_opengl_surface_create(struct client_surface *client, int format, struct opengl_drawable **drawable) { + struct wayland_client_surface *surface = impl_from_client_surface(client); EGLConfig config = egl_config_for_format(format); - struct wayland_client_surface *surface; EGLint attribs[4], *attrib = attribs; - struct opengl_drawable *previous; struct wayland_gl_drawable *gl; - struct client_surface *client; + HWND hwnd = client->hwnd; RECT rect; - TRACE("hwnd=%p format=%d\n", hwnd, format); - - if ((previous = *drawable) && previous->format == format) return TRUE; + TRACE("client=%s format=%d\n", debugstr_client_surface(client), format); NtUserGetClientRect(hwnd, &rect, NtUserGetDpiForWindow(hwnd)); if (rect.right == rect.left) rect.right = rect.left + 1; @@ -107,11 +104,7 @@ static BOOL wayland_opengl_surface_create(HWND hwnd, int format, struct opengl_d } *attrib++ = EGL_NONE; - if (!(client = WAYLAND_CreateClientSurface(hwnd, format))) return FALSE; - gl = opengl_drawable_create(sizeof(*gl), &wayland_drawable_funcs, format, client); - surface = impl_from_client_surface(client); /* reference held by gl */ - client_surface_release(client); - if (!gl) return FALSE; + if (!(gl = opengl_drawable_create(sizeof(*gl), &wayland_drawable_funcs, format, client))) return FALSE; opengl_drawable_map_buffer(&gl->base, GL_FRONT_LEFT, GL_BACK_LEFT); opengl_drawable_map_buffer(&gl->base, GL_FRONT, GL_BACK); @@ -124,7 +117,6 @@ static BOOL wayland_opengl_surface_create(HWND hwnd, int format, struct opengl_d TRACE("Created drawable %s with egl_surface %p\n", debugstr_opengl_drawable(&gl->base), gl->base.surface); - if (previous) opengl_drawable_release( previous ); *drawable = &gl->base; return TRUE; diff --git a/dlls/winex11.drv/opengl.c b/dlls/winex11.drv/opengl.c index 2b6e1145e47..f080d5dddca 100644 --- a/dlls/winex11.drv/opengl.c +++ b/dlls/winex11.drv/opengl.c @@ -519,19 +519,12 @@ static BOOL x11drv_egl_describe_pixel_format( int format, struct wgl_pixel_forma return TRUE; } -static BOOL x11drv_egl_surface_create( HWND hwnd, int format, struct opengl_drawable **drawable ) +static BOOL x11drv_egl_surface_create( struct client_surface *client, int format, struct opengl_drawable **drawable ) { - struct x11drv_client_surface *surface; - struct opengl_drawable *previous; - struct client_surface *client; + struct x11drv_client_surface *surface = impl_from_client_surface( client ); struct gl_drawable *gl; - if ((previous = *drawable) && previous->format == format) return TRUE; - if (!(client = X11DRV_CreateClientSurface( hwnd, format ))) return FALSE; - gl = opengl_drawable_create( sizeof(*gl), &x11drv_egl_surface_funcs, format, client ); - surface = impl_from_client_surface( client ); /* reference held by gl */ - client_surface_release( client ); - if (!gl) return FALSE; + if (!(gl = opengl_drawable_create( sizeof(*gl), &x11drv_egl_surface_funcs, format, client ))) return FALSE; opengl_drawable_map_buffer( &gl->base, GL_FRONT_LEFT, GL_BACK_LEFT ); opengl_drawable_map_buffer( &gl->base, GL_FRONT, GL_BACK ); @@ -548,7 +541,6 @@ static BOOL x11drv_egl_surface_create( HWND hwnd, int format, struct opengl_draw TRACE( "Created drawable %s with client window %lx\n", debugstr_opengl_drawable( &gl->base ), surface->window ); XFlush( gdi_display ); - if (previous) opengl_drawable_release( previous ); *drawable = &gl->base; return TRUE; } @@ -957,21 +949,13 @@ static GLXContext create_glxcontext( int format, GLXContext share, const int *at return ctx; } -static BOOL x11drv_surface_create( HWND hwnd, int format, struct opengl_drawable **drawable ) +static BOOL x11drv_surface_create( struct client_surface *client, int format, struct opengl_drawable **drawable ) { + struct x11drv_client_surface *surface = impl_from_client_surface( client ); struct glx_pixel_format *fmt = glx_pixel_format_from_format( format ); - struct x11drv_client_surface *surface; - struct opengl_drawable *previous; - struct client_surface *client; struct gl_drawable *gl; - if ((previous = *drawable) && previous->format == format) return TRUE; - if (!(client = X11DRV_CreateClientSurface( hwnd, format ))) return FALSE; - gl = opengl_drawable_create( sizeof(*gl), &x11drv_surface_funcs, format, client ); - surface = impl_from_client_surface( client ); /* reference held by gl */ - client_surface_release( client ); - if (!gl) return FALSE; - + if (!(gl = opengl_drawable_create( sizeof(*gl), &x11drv_surface_funcs, format, client ))) return FALSE; if (!(gl->drawable = pglXCreateWindow( gdi_display, fmt->fbconfig, surface->window, NULL ))) { opengl_drawable_release( &gl->base ); @@ -981,7 +965,6 @@ static BOOL x11drv_surface_create( HWND hwnd, int format, struct opengl_drawable TRACE( "Created drawable %s with client window %lx\n", debugstr_opengl_drawable( &gl->base ), surface->window ); XFlush( gdi_display ); - if (previous) opengl_drawable_release( previous ); *drawable = &gl->base; return TRUE; } diff --git a/include/wine/opengl_driver.h b/include/wine/opengl_driver.h index af745e038a6..3fa0aa91d97 100644 --- a/include/wine/opengl_driver.h +++ b/include/wine/opengl_driver.h @@ -111,7 +111,7 @@ struct __GLsync #include "wine/gdi_driver.h" /* Wine internal opengl driver version, needs to be bumped upon opengl_funcs changes. */ -#define WINE_OPENGL_DRIVER_VERSION 37 +#define WINE_OPENGL_DRIVER_VERSION 38 struct opengl_drawable; @@ -244,7 +244,7 @@ struct opengl_driver_funcs UINT (*p_init_pixel_formats)(UINT*); BOOL (*p_describe_pixel_format)(int,struct wgl_pixel_format*); void (*p_init_extensions)( struct opengl_funcs *funcs, BOOLEAN extensions[GL_EXTENSION_COUNT] ); - BOOL (*p_surface_create)( HWND hwnd, int format, struct opengl_drawable **drawable ); + BOOL (*p_surface_create)( struct client_surface *client, int format, struct opengl_drawable **drawable ); BOOL (*p_context_create)( int format, void *share, const int *attribs, void **context ); BOOL (*p_context_destroy)(void*); BOOL (*p_make_current)( struct opengl_drawable *draw, struct opengl_drawable *read, void *private ); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/11093