From: Rémi Bernon rbernon@codeweavers.com
--- dlls/opengl32/unix_wgl.c | 121 +++++++++++++++-------------------- dlls/win32u/opengl.c | 34 ++++++---- include/wine/opengl_driver.h | 11 +++- 3 files changed, 83 insertions(+), 83 deletions(-)
diff --git a/dlls/opengl32/unix_wgl.c b/dlls/opengl32/unix_wgl.c index 920c1fc535a..a68e9fa0b56 100644 --- a/dlls/opengl32/unix_wgl.c +++ b/dlls/opengl32/unix_wgl.c @@ -65,24 +65,13 @@ enum wgl_handle_type HANDLE_TYPE_MASK = 15 << 12, };
-struct opengl_context -{ - DWORD tid; /* thread that the context is current in */ - UINT64 debug_callback; /* client pointer */ - UINT64 debug_user; /* client pointer */ - GLubyte *extensions; /* extension string */ - GLuint *disabled_exts; /* indices of disabled extensions */ - struct wgl_context *drv_ctx; /* driver context */ - GLubyte *wow64_version; /* wow64 GL version override */ -}; - struct wgl_handle { UINT handle; const struct opengl_funcs *funcs; union { - struct opengl_context *context; /* for HANDLE_CONTEXT */ + struct wgl_context *context; /* for HANDLE_CONTEXT */ struct wgl_pbuffer *pbuffer; /* for HANDLE_PBUFFER */ GLsync sync; /* for HANDLE_GLSYNC */ struct wgl_handle *next; /* for free handles */ @@ -95,7 +84,7 @@ static struct wgl_handle *next_free; static unsigned int handle_count;
/* the current context is assumed valid and doesn't need locking */ -static struct opengl_context *get_current_context( TEB *teb ) +static struct wgl_context *get_current_context( TEB *teb ) { if (!teb->glCurrentRC) return NULL; return wgl_handles[LOWORD(teb->glCurrentRC) & ~HANDLE_TYPE_MASK].u.context; @@ -120,7 +109,7 @@ static struct wgl_handle *get_handle_ptr( HANDLE handle ) return NULL; }
-static struct opengl_context *opengl_context_from_handle( HGLRC handle, const struct opengl_funcs **funcs ) +static struct wgl_context *wgl_context_from_handle( HGLRC handle, const struct opengl_funcs **funcs ) { struct wgl_handle *entry; if (!(entry = get_handle_ptr( handle ))) return NULL; @@ -410,7 +399,7 @@ static BOOL filter_extensions( TEB * teb, const char *extensions, GLubyte **exts
static const GLuint *disabled_extensions_index( TEB *teb ) { - struct opengl_context *ctx = get_current_context( teb ); + struct wgl_context *ctx = get_current_context( teb ); GLuint **disabled = &ctx->disabled_exts; if (*disabled || filter_extensions( teb, NULL, NULL, disabled )) return *disabled; return NULL; @@ -504,14 +493,14 @@ static const GLubyte *wrap_glGetString( TEB *teb, GLenum name ) { if (name == GL_EXTENSIONS) { - struct opengl_context *ctx = get_current_context( teb ); + struct wgl_context *ctx = get_current_context( teb ); GLubyte **extensions = &ctx->extensions; GLuint **disabled = &ctx->disabled_exts; if (*extensions || filter_extensions( teb, (const char *)ret, extensions, disabled )) return *extensions; } else if (name == GL_VERSION && is_win64 && is_wow64()) { - struct opengl_context *ctx = get_current_context( teb ); + struct wgl_context *ctx = get_current_context( teb ); GLubyte **str = &ctx->wow64_version; int major, minor;
@@ -672,50 +661,45 @@ static PROC wrap_wglGetProcAddress( TEB *teb, LPCSTR name ) static BOOL wrap_wglCopyContext( HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask ) { const struct opengl_funcs *src_funcs, *dst_funcs; - struct opengl_context *src, *dst; + struct wgl_context *src, *dst; BOOL ret = FALSE;
- if (!(src = opengl_context_from_handle( hglrcSrc, &src_funcs ))) return FALSE; - if (!(dst = opengl_context_from_handle( hglrcDst, &dst_funcs ))) return FALSE; + if (!(src = wgl_context_from_handle( hglrcSrc, &src_funcs ))) return FALSE; + if (!(dst = wgl_context_from_handle( hglrcDst, &dst_funcs ))) return FALSE; if (src_funcs != dst_funcs) RtlSetLastWin32Error( ERROR_INVALID_HANDLE ); - else ret = src_funcs->p_wglCopyContext( src->drv_ctx, dst->drv_ctx, mask ); + else ret = src_funcs->p_wglCopyContext( src, dst, mask ); return ret; }
static HGLRC wrap_wglCreateContext( HDC hdc ) { HGLRC ret = 0; - struct wgl_context *drv_ctx; - struct opengl_context *context; + struct wgl_context *context; const struct opengl_funcs *funcs = get_dc_funcs( hdc );
if (!funcs) return 0; - if (!(drv_ctx = funcs->p_wglCreateContext( hdc ))) return 0; - if ((context = calloc( 1, sizeof(*context) ))) - { - context->drv_ctx = drv_ctx; - if (!(ret = alloc_handle( HANDLE_CONTEXT, funcs, context ))) free( context ); - } - if (!ret) funcs->p_wglDeleteContext( drv_ctx ); + if (!(context = funcs->p_wglCreateContext( hdc ))) return 0; + ret = alloc_handle( HANDLE_CONTEXT, funcs, context ); + if (!ret) funcs->p_wglDeleteContext( context ); return ret; }
static BOOL wrap_wglMakeCurrent( TEB *teb, HDC hdc, HGLRC hglrc ) { DWORD tid = HandleToULong(teb->ClientId.UniqueThread); - struct opengl_context *ctx, *prev = get_current_context( teb ); + struct wgl_context *ctx, *prev = get_current_context( teb ); const struct opengl_funcs *funcs = teb->glTable;
if (hglrc) { - if (!(ctx = opengl_context_from_handle( hglrc, &funcs ))) return FALSE; + if (!(ctx = wgl_context_from_handle( hglrc, &funcs ))) return FALSE; if (ctx->tid && ctx->tid != tid) { RtlSetLastWin32Error( ERROR_BUSY ); return FALSE; }
- if (!funcs->p_wglMakeCurrent( hdc, ctx->drv_ctx )) return FALSE; + if (!funcs->p_wglMakeCurrent( hdc, ctx )) return FALSE; if (prev) prev->tid = 0; ctx->tid = tid; teb->glReserved1[0] = hdc; @@ -743,7 +727,7 @@ static BOOL wrap_wglMakeCurrent( TEB *teb, HDC hdc, HGLRC hglrc ) static BOOL wrap_wglDeleteContext( TEB *teb, HGLRC hglrc ) { struct wgl_handle *ptr; - struct opengl_context *ctx; + struct wgl_context *ctx; DWORD tid = HandleToULong(teb->ClientId.UniqueThread);
if (!(ptr = get_handle_ptr( hglrc ))) return FALSE; @@ -754,21 +738,20 @@ static BOOL wrap_wglDeleteContext( TEB *teb, HGLRC hglrc ) return FALSE; } if (hglrc == teb->glCurrentRC) wrap_wglMakeCurrent( teb, 0, 0 ); - ptr->funcs->p_wglDeleteContext( ctx->drv_ctx ); free( ctx->wow64_version ); free( ctx->disabled_exts ); free( ctx->extensions ); - free( ctx ); + ptr->funcs->p_wglDeleteContext( ctx ); free_handle_ptr( ptr ); return TRUE; }
-static void flush_context( TEB *teb, struct opengl_context *context, BOOL finish ) +static void flush_context( TEB *teb, struct wgl_context *context, BOOL finish ) { const struct opengl_funcs *funcs = teb->glTable; HDC hdc = teb->glReserved1[0];
- if (!funcs->p_wgl_context_flush( hdc, context->drv_ctx, finish )) + if (!funcs->p_wgl_context_flush( hdc, context, finish )) { /* default implementation: call the functions directly */ if (finish) funcs->p_glFinish(); @@ -780,7 +763,7 @@ NTSTATUS gl_glFinish( void *args ) { struct glFinish_params *params = args; const struct opengl_funcs *funcs = params->teb->glTable; - struct opengl_context *ctx = get_current_context( params->teb ); + struct wgl_context *ctx = get_current_context( params->teb );
if (ctx) flush_context( params->teb, ctx, TRUE ); else funcs->p_glFinish(); @@ -792,7 +775,7 @@ NTSTATUS gl_glFlush( void *args ) { struct glFlush_params *params = args; const struct opengl_funcs *funcs = params->teb->glTable; - struct opengl_context *ctx = get_current_context( params->teb ); + struct wgl_context *ctx = get_current_context( params->teb );
if (ctx) flush_context( params->teb, ctx, FALSE ); else funcs->p_glFlush(); @@ -808,7 +791,7 @@ NTSTATUS wgl_wglSwapBuffers( void *args )
if (!(params->ret = funcs->p_wglSwapBuffers( params->hdc ))) { - struct opengl_context *ctx = get_current_context( params->teb ); + struct wgl_context *ctx = get_current_context( params->teb ); /* default implementation: implicitly flush the context */ if (ctx) flush_context( params->teb, ctx, FALSE ); } @@ -819,13 +802,13 @@ NTSTATUS wgl_wglSwapBuffers( void *args ) static BOOL wrap_wglShareLists( HGLRC hglrcSrc, HGLRC hglrcDst ) { const struct opengl_funcs *src_funcs, *dst_funcs; - struct opengl_context *src, *dst; + struct wgl_context *src, *dst; BOOL ret = FALSE;
- if (!(src = opengl_context_from_handle( hglrcSrc, &src_funcs ))) return FALSE; - if (!(dst = opengl_context_from_handle( hglrcDst, &dst_funcs ))) return FALSE; + if (!(src = wgl_context_from_handle( hglrcSrc, &src_funcs ))) return FALSE; + if (!(dst = wgl_context_from_handle( hglrcDst, &dst_funcs ))) return FALSE; if (src_funcs != dst_funcs) RtlSetLastWin32Error( ERROR_INVALID_HANDLE ); - else ret = src_funcs->p_wglShareLists( src->drv_ctx, dst->drv_ctx ); + else ret = src_funcs->p_wglShareLists( src, dst ); return ret; }
@@ -840,8 +823,7 @@ static BOOL wrap_wglBindTexImageARB( HPBUFFERARB handle, int buffer ) static HGLRC wrap_wglCreateContextAttribsARB( HDC hdc, HGLRC share, const int *attribs ) { HGLRC ret = 0; - struct wgl_context *drv_ctx; - struct opengl_context *context, *share_ctx = NULL; + struct wgl_context *context, *share_ctx = NULL; const struct opengl_funcs *funcs = get_dc_funcs( hdc ), *share_funcs;
if (!funcs) @@ -850,34 +832,31 @@ static HGLRC wrap_wglCreateContextAttribsARB( HDC hdc, HGLRC share, const int *a return 0; } if (!funcs->p_wglCreateContextAttribsARB) return 0; - if (share && !(share_ctx = opengl_context_from_handle( share, &share_funcs ))) + + if (share && !(share_ctx = wgl_context_from_handle( share, &share_funcs ))) { RtlSetLastWin32Error( ERROR_INVALID_OPERATION ); return 0; } - if ((drv_ctx = funcs->p_wglCreateContextAttribsARB( hdc, share_ctx ? share_ctx->drv_ctx : NULL, attribs ))) + if ((context = funcs->p_wglCreateContextAttribsARB( hdc, share_ctx, attribs ))) { - if ((context = calloc( 1, sizeof(*context) ))) - { - enum wgl_handle_type type = HANDLE_CONTEXT; + enum wgl_handle_type type = HANDLE_CONTEXT;
- if (attribs) + if (attribs) + { + while (*attribs) { - while (*attribs) + if (attribs[0] == WGL_CONTEXT_MAJOR_VERSION_ARB) { - if (attribs[0] == WGL_CONTEXT_MAJOR_VERSION_ARB) - { - if (attribs[1] >= 3) type = HANDLE_CONTEXT_V3; - break; - } - attribs += 2; + if (attribs[1] >= 3) type = HANDLE_CONTEXT_V3; + break; } + attribs += 2; } - - context->drv_ctx = drv_ctx; - if (!(ret = alloc_handle( type, funcs, context ))) free( context ); } - if (!ret) funcs->p_wglDeleteContext( drv_ctx ); + + ret = alloc_handle( type, funcs, context ); + if (!ret) funcs->p_wglDeleteContext( context ); }
return ret; @@ -919,12 +898,12 @@ static HDC wrap_wglGetPbufferDCARB( HPBUFFERARB handle ) static BOOL wrap_wglMakeContextCurrentARB( TEB *teb, HDC draw_hdc, HDC read_hdc, HGLRC hglrc ) { DWORD tid = HandleToULong(teb->ClientId.UniqueThread); - struct opengl_context *ctx, *prev = get_current_context( teb ); + struct wgl_context *ctx, *prev = get_current_context( teb ); const struct opengl_funcs *funcs = teb->glTable;
if (hglrc) { - if (!(ctx = opengl_context_from_handle( hglrc, &funcs ))) return FALSE; + if (!(ctx = wgl_context_from_handle( hglrc, &funcs ))) return FALSE; if (ctx->tid && ctx->tid != tid) { RtlSetLastWin32Error( ERROR_BUSY ); @@ -932,7 +911,7 @@ static BOOL wrap_wglMakeContextCurrentARB( TEB *teb, HDC draw_hdc, HDC read_hdc, }
if (!funcs->p_wglMakeContextCurrentARB) return FALSE; - if (!funcs->p_wglMakeContextCurrentARB( draw_hdc, read_hdc, ctx->drv_ctx )) return FALSE; + if (!funcs->p_wglMakeContextCurrentARB( draw_hdc, read_hdc, ctx )) return FALSE; if (prev) prev->tid = 0; ctx->tid = tid; teb->glReserved1[0] = draw_hdc; @@ -989,7 +968,7 @@ static void gl_debug_message_callback( GLenum source, GLenum type, GLuint id, GL struct gl_debug_message_callback_params *params; void *ret_ptr; ULONG ret_len; - struct opengl_context *ctx = (struct opengl_context *)user; + struct wgl_context *ctx = (struct wgl_context *)user; UINT len = strlen( message ) + 1, size;
if (!ctx->debug_callback) return; @@ -1018,7 +997,7 @@ static void gl_debug_message_callback( GLenum source, GLenum type, GLuint id, GL
static void wrap_glDebugMessageCallback( TEB *teb, GLDEBUGPROC callback, const void *user ) { - struct opengl_context *ctx = get_current_context( teb ); + struct wgl_context *ctx = get_current_context( teb ); const struct opengl_funcs *funcs = teb->glTable;
if (!funcs->p_glDebugMessageCallback) return; @@ -1030,7 +1009,7 @@ static void wrap_glDebugMessageCallback( TEB *teb, GLDEBUGPROC callback, const v
static void wrap_glDebugMessageCallbackAMD( TEB *teb, GLDEBUGPROCAMD callback, void *user ) { - struct opengl_context *ctx = get_current_context( teb ); + struct wgl_context *ctx = get_current_context( teb ); const struct opengl_funcs *funcs = teb->glTable;
if (!funcs->p_glDebugMessageCallbackAMD) return; @@ -1042,7 +1021,7 @@ static void wrap_glDebugMessageCallbackAMD( TEB *teb, GLDEBUGPROCAMD callback, v
static void wrap_glDebugMessageCallbackARB( TEB *teb, GLDEBUGPROCARB callback, const void *user ) { - struct opengl_context *ctx = get_current_context( teb ); + struct wgl_context *ctx = get_current_context( teb ); const struct opengl_funcs *funcs = teb->glTable;
if (!funcs->p_glDebugMessageCallbackARB) return; diff --git a/dlls/win32u/opengl.c b/dlls/win32u/opengl.c index c7d185cf130..986178ceb8f 100644 --- a/dlls/win32u/opengl.c +++ b/dlls/win32u/opengl.c @@ -39,14 +39,20 @@
WINE_DEFAULT_DEBUG_CHANNEL(wgl);
-struct wgl_context +struct context { + struct wgl_context base; const struct opengl_driver_funcs *driver_funcs; const struct opengl_funcs *funcs; void *driver_private; int pixel_format; };
+static struct context *context_from_wgl_context( struct wgl_context *base ) +{ + return CONTAINING_RECORD( base, struct context, base ); +} + struct wgl_pbuffer { const struct opengl_driver_funcs *driver_funcs; @@ -1054,12 +1060,13 @@ static void win32u_memory_get_pixel_formats( struct wgl_pixel_format *formats, U *num_onscreen_formats = memory_onscreen_count; }
-static struct wgl_context *context_create( HDC hdc, struct wgl_context *shared, const int *attribs ) +static struct wgl_context *context_create( HDC hdc, struct wgl_context *shared_base, const int *attribs ) { + struct context *shared = context_from_wgl_context( shared_base ); void *shared_private = shared ? shared->driver_private : NULL; const struct opengl_driver_funcs *driver_funcs; const struct opengl_funcs *funcs; - struct wgl_context *context; + struct context *context; int format;
TRACE( "hdc %p, shared %p, attribs %p\n", hdc, shared, attribs ); @@ -1085,7 +1092,7 @@ static struct wgl_context *context_create( HDC hdc, struct wgl_context *shared, }
TRACE( "created context %p, format %u for driver context %p\n", context, format, context->driver_private ); - return context; + return &context->base; }
static struct wgl_context *win32u_wglCreateContextAttribsARB( HDC hdc, struct wgl_context *shared, const int *attribs ) @@ -1104,8 +1111,9 @@ static struct wgl_context *win32u_wglCreateContext( HDC hdc ) return context_create( hdc, NULL, NULL ); }
-static BOOL win32u_wglDeleteContext( struct wgl_context *context ) +static BOOL win32u_wglDeleteContext( struct wgl_context *base ) { + struct context *context = context_from_wgl_context( base ); const struct opengl_driver_funcs *funcs = context->driver_funcs; BOOL ret;
@@ -1117,8 +1125,9 @@ static BOOL win32u_wglDeleteContext( struct wgl_context *context ) return ret; }
-static BOOL win32u_wglCopyContext( struct wgl_context *src, struct wgl_context *dst, UINT mask ) +static BOOL win32u_wglCopyContext( struct wgl_context *src_base, struct wgl_context *dst_base, UINT mask ) { + struct context *src = context_from_wgl_context( src_base ), *dst = context_from_wgl_context( dst_base ); const struct opengl_driver_funcs *funcs = src->driver_funcs;
TRACE( "src %p, dst %p, mask %#x\n", src, dst, mask ); @@ -1127,8 +1136,9 @@ static BOOL win32u_wglCopyContext( struct wgl_context *src, struct wgl_context * return funcs->p_context_copy( src->driver_private, dst->driver_private, mask ); }
-static BOOL win32u_wglShareLists( struct wgl_context *src, struct wgl_context *dst ) +static BOOL win32u_wglShareLists( struct wgl_context *src_base, struct wgl_context *dst_base ) { + struct context *src = context_from_wgl_context( src_base ), *dst = context_from_wgl_context( dst_base ); const struct opengl_driver_funcs *funcs = src->driver_funcs;
TRACE( "src %p, dst %p\n", src, dst ); @@ -1137,8 +1147,9 @@ static BOOL win32u_wglShareLists( struct wgl_context *src, struct wgl_context *d return funcs->p_context_share( src->driver_private, dst->driver_private ); }
-static BOOL win32u_wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, struct wgl_context *context ) +static BOOL win32u_wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, struct wgl_context *base ) { + struct context *context = context_from_wgl_context( base ); const struct opengl_driver_funcs *funcs; int format;
@@ -1168,7 +1179,7 @@ static BOOL win32u_wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, struct
funcs = context->driver_funcs; if (!funcs->p_context_make_current( draw_hdc, read_hdc, context->driver_private )) return FALSE; - NtCurrentTeb()->glContext = context; + NtCurrentTeb()->glContext = &context->base; return TRUE; }
@@ -1603,8 +1614,9 @@ static int get_window_swap_interval( HWND hwnd ) return interval; }
-static BOOL win32u_wgl_context_flush( HDC hdc, struct wgl_context *context, BOOL finish ) +static BOOL win32u_wgl_context_flush( HDC hdc, struct wgl_context *base, BOOL finish ) { + struct context *context = context_from_wgl_context( base ); int interval; HWND hwnd;
@@ -1618,7 +1630,7 @@ static BOOL win32u_wgl_context_flush( HDC hdc, struct wgl_context *context, BOOL
static BOOL win32u_wglSwapBuffers( HDC hdc ) { - struct wgl_context *context = NtCurrentTeb()->glContext; + struct context *context = context_from_wgl_context( NtCurrentTeb()->glContext ); const struct opengl_driver_funcs *driver_funcs; const struct opengl_funcs *funcs; int interval; diff --git a/include/wine/opengl_driver.h b/include/wine/opengl_driver.h index 697b08fc99d..b48f2351b17 100644 --- a/include/wine/opengl_driver.h +++ b/include/wine/opengl_driver.h @@ -63,7 +63,16 @@ struct wgl_pixel_format /* Wine internal opengl driver version, needs to be bumped upon opengl_funcs changes. */ #define WINE_OPENGL_DRIVER_VERSION 35
-struct wgl_context; +struct wgl_context +{ + DWORD tid; /* thread that the context is current in */ + UINT64 debug_callback; /* client pointer */ + UINT64 debug_user; /* client pointer */ + GLubyte *extensions; /* extension string */ + GLuint *disabled_exts; /* indices of disabled extensions */ + GLubyte *wow64_version; /* wow64 GL version override */ +}; + struct wgl_pbuffer;
/* interface between opengl32 and win32u */