From: Rémi Bernon <rbernon@codeweavers.com> --- dlls/opengl32/unix_wgl.c | 10 +++----- dlls/win32u/opengl.c | 50 ++++++++++++++++++++++++------------ include/wine/opengl_driver.h | 4 ++- 3 files changed, 41 insertions(+), 23 deletions(-) diff --git a/dlls/opengl32/unix_wgl.c b/dlls/opengl32/unix_wgl.c index 053a5e46e0a..2b05e48e726 100644 --- a/dlls/opengl32/unix_wgl.c +++ b/dlls/opengl32/unix_wgl.c @@ -122,7 +122,6 @@ struct context { struct opengl_context base; - HDC hdc; /* context creation DC */ HGLRC client; /* client-side context handle */ HGLRC share; /* context to be shared with */ int *attribs; /* creation attributes */ @@ -415,7 +414,7 @@ static struct context *update_context( TEB *teb, HGLRC client_context, struct co if (ctx->share == (HGLRC)-1) return ctx; /* not re-shared */ share = ctx->share ? get_updated_context( teb, ctx->share ) : NULL; - if (!funcs->p_context_reset( &ctx->base, ctx->hdc, share ? &share->base : NULL, ctx->attribs )) + if (!funcs->p_context_reset( &ctx->base, share ? &share->base : NULL, ctx->attribs )) { WARN( "Failed to re-create context for wglShareLists\n" ); return ctx; @@ -1339,7 +1338,7 @@ BOOL wrap_wglDeleteContext( TEB *teb, HGLRC client_context ) return FALSE; } - funcs->p_context_reset( &ctx->base, NULL, NULL, NULL ); + funcs->p_context_destroy( &ctx->base ); free_context( ctx ); return TRUE; } @@ -1502,14 +1501,13 @@ HGLRC wrap_wglCreateContextAttribsARB( TEB *teb, HDC hdc, HGLRC client_shared, c const struct opengl_funcs *funcs = get_dc_funcs( hdc ); struct context *context, *shared = get_updated_context( teb, client_shared ); - if (!funcs->p_context_reset) return 0; + if (!funcs->p_context_create) return 0; if (!(context = calloc( 1, sizeof(*context) ))) { RtlSetLastWin32Error( ERROR_OUTOFMEMORY ); return 0; } context->base.client_context = client_context; - context->hdc = hdc; context->share = (HGLRC)-1; /* initial shared context */ context->attribs = memdup_attribs( attribs ); @@ -1533,7 +1531,7 @@ HGLRC wrap_wglCreateContextAttribsARB( TEB *teb, HDC hdc, HGLRC client_shared, c } } - if (!(funcs->p_context_reset( &context->base, hdc, shared ? &shared->base : NULL, attribs ))) + if (!(funcs->p_context_create( &context->base, hdc, shared ? &shared->base : NULL, attribs ))) { free_context( context ); return 0; diff --git a/dlls/win32u/opengl.c b/dlls/win32u/opengl.c index e655b034cfe..3558b66c792 100644 --- a/dlls/win32u/opengl.c +++ b/dlls/win32u/opengl.c @@ -2259,26 +2259,13 @@ static int get_window_swap_interval( HWND hwnd ) return interval; } -static BOOL win32u_context_reset( struct opengl_context *context, HDC hdc, struct opengl_context *share, const int *attribs ) +static BOOL win32u_context_create( struct opengl_context *context, HDC hdc, struct opengl_context *share, const int *attribs ) { void *share_private = share ? share->driver_private : NULL; int format; TRACE( "context %p, hdc %p, share %p, attribs %p\n", context, hdc, share, attribs ); - if (context->internal_context) - { - driver_funcs->p_context_destroy( context->internal_context ); - context->internal_context = NULL; - } - if (context->driver_private && !driver_funcs->p_context_destroy( context->driver_private )) - { - WARN( "Failed to destroy driver context %p\n", context->driver_private ); - return FALSE; - } - context->driver_private = NULL; - if (!hdc) return TRUE; - if ((format = get_dc_pixel_format( hdc )) <= 0 && (format = get_window_pixel_format( NtUserWindowFromDC( hdc ) )) <= 0) { @@ -2293,10 +2280,39 @@ static BOOL win32u_context_reset( struct opengl_context *context, HDC hdc, struc } context->format = format; - TRACE( "reset context %p, format %u for driver context %p\n", context, format, context->driver_private ); + TRACE( "created context %p, format %u for driver context %p\n", context, format, context->driver_private ); + return TRUE; +} + +static BOOL win32u_context_destroy( struct opengl_context *context ) +{ + TRACE( "context %p\n", context ); + + if (context->internal_context) + { + driver_funcs->p_context_destroy( context->internal_context ); + context->internal_context = NULL; + } + if (context->driver_private && !driver_funcs->p_context_destroy( context->driver_private )) + { + WARN( "Failed to destroy driver context %p\n", context->driver_private ); + return FALSE; + } + context->driver_private = NULL; + return TRUE; } +static BOOL win32u_context_reset( struct opengl_context *context, struct opengl_context *share, const int *attribs ) +{ + void *share_private = share ? share->driver_private : NULL; + + TRACE( "context %p, share %p, attribs %p\n", context, share, attribs ); + + if (!win32u_context_destroy( context )) return FALSE; + return driver_funcs->p_context_create( context->format, share_private, attribs, &context->driver_private ); +} + static BOOL flush_memory_pbuffer( void (*flush)(void) ) { HDC draw_hdc = NtCurrentTeb()->glReserved1[0], read_hdc = NtCurrentTeb()->glReserved1[1]; @@ -2704,8 +2720,10 @@ static void display_funcs_init(void) display_funcs.p_wglMakeCurrent = win32u_wglMakeCurrent; display_funcs.p_wglSwapBuffers = win32u_wglSwapBuffers; - display_funcs.p_context_reset = win32u_context_reset; display_funcs.p_context_flush = win32u_context_flush; + display_funcs.p_context_create = win32u_context_create; + display_funcs.p_context_destroy = win32u_context_destroy; + display_funcs.p_context_reset = win32u_context_reset; register_extension( wgl_extensions, ARRAY_SIZE(wgl_extensions), "WGL_ARB_pixel_format" ); display_funcs.p_wglChoosePixelFormatARB = (void *)1; /* never called */ diff --git a/include/wine/opengl_driver.h b/include/wine/opengl_driver.h index 61c006270ba..0ca0a4708fc 100644 --- a/include/wine/opengl_driver.h +++ b/include/wine/opengl_driver.h @@ -129,7 +129,9 @@ struct opengl_funcs void (*p_get_pixel_formats)( struct wgl_pixel_format *formats, UINT max_formats, UINT *num_formats, UINT *num_onscreen_formats ); BOOL (*p_query_renderer)( UINT attribute, void *value ); BOOL (*p_context_flush)( struct opengl_context *context, void (*flush)(void), UINT flags ); - BOOL (*p_context_reset)( struct opengl_context *context, HDC hdc, struct opengl_context *share, const int *attribs ); + BOOL (*p_context_create)( struct opengl_context *context, HDC hdc, struct opengl_context *share, const int *attribs ); + BOOL (*p_context_destroy)( struct opengl_context *context ); + BOOL (*p_context_reset)( struct opengl_context *context, struct opengl_context *share, const int *attribs ); void *egl_handle; }; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/9991