From: Rémi Bernon rbernon@codeweavers.com
--- dlls/opengl32/unix_wgl.c | 42 ++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-)
diff --git a/dlls/opengl32/unix_wgl.c b/dlls/opengl32/unix_wgl.c index f21ee652ea1..6bff4de19c4 100644 --- a/dlls/opengl32/unix_wgl.c +++ b/dlls/opengl32/unix_wgl.c @@ -108,7 +108,7 @@ static inline HANDLE next_handle( struct wgl_handle *ptr, enum wgl_handle_type t return ULongToHandle( ptr->handle ); }
-static struct wgl_handle *get_handle_ptr( HANDLE handle, enum wgl_handle_type type ) +static struct wgl_handle *get_handle_ptr( HANDLE handle ) { unsigned int index = LOWORD( handle ) & ~HANDLE_TYPE_MASK;
@@ -641,8 +641,8 @@ static BOOL wrap_wglCopyContext( HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask ) struct wgl_handle *src, *dst; BOOL ret = FALSE;
- if (!(src = get_handle_ptr( hglrcSrc, HANDLE_CONTEXT ))) return FALSE; - if ((dst = get_handle_ptr( hglrcDst, HANDLE_CONTEXT ))) + if (!(src = get_handle_ptr( hglrcSrc ))) return FALSE; + if ((dst = get_handle_ptr( hglrcDst ))) { if (src->funcs != dst->funcs) RtlSetLastWin32Error( ERROR_INVALID_HANDLE ); else ret = src->funcs->p_wglCopyContext( src->u.context->drv_ctx, dst->u.context->drv_ctx, mask ); @@ -676,7 +676,7 @@ static BOOL wrap_wglMakeCurrent( TEB *teb, HDC hdc, HGLRC hglrc )
if (hglrc) { - if (!(ptr = get_handle_ptr( hglrc, HANDLE_CONTEXT ))) return FALSE; + if (!(ptr = get_handle_ptr( hglrc ))) return FALSE; if (!ptr->u.context->tid || ptr->u.context->tid == tid) { ret = ptr->funcs->p_wglMakeCurrent( hdc, ptr->u.context->drv_ctx ); @@ -716,7 +716,7 @@ static BOOL wrap_wglDeleteContext( TEB *teb, HGLRC hglrc ) struct wgl_handle *ptr; DWORD tid = HandleToULong(teb->ClientId.UniqueThread);
- if (!(ptr = get_handle_ptr( hglrc, HANDLE_CONTEXT ))) return FALSE; + if (!(ptr = get_handle_ptr( hglrc ))) return FALSE; if (ptr->u.context->tid && ptr->u.context->tid != tid) { RtlSetLastWin32Error( ERROR_BUSY ); @@ -737,8 +737,8 @@ static BOOL wrap_wglShareLists( HGLRC hglrcSrc, HGLRC hglrcDst ) BOOL ret = FALSE; struct wgl_handle *src, *dst;
- if (!(src = get_handle_ptr( hglrcSrc, HANDLE_CONTEXT ))) return FALSE; - if ((dst = get_handle_ptr( hglrcDst, HANDLE_CONTEXT ))) + if (!(src = get_handle_ptr( hglrcSrc ))) return FALSE; + if ((dst = get_handle_ptr( hglrcDst ))) { if (src->funcs != dst->funcs) RtlSetLastWin32Error( ERROR_INVALID_HANDLE ); else ret = src->funcs->p_wglShareLists( src->u.context->drv_ctx, dst->u.context->drv_ctx ); @@ -749,7 +749,7 @@ static BOOL wrap_wglShareLists( HGLRC hglrcSrc, HGLRC hglrcDst ) static BOOL wrap_wglBindTexImageARB( HPBUFFERARB handle, int buffer ) { struct wgl_handle *ptr; - if (!(ptr = get_handle_ptr( handle, HANDLE_PBUFFER ))) return FALSE; + if (!(ptr = get_handle_ptr( handle ))) return FALSE; return ptr->funcs->p_wglBindTexImageARB( ptr->u.pbuffer, buffer ); }
@@ -767,7 +767,7 @@ static HGLRC wrap_wglCreateContextAttribsARB( HDC hdc, HGLRC share, const int *a return 0; } if (!funcs->p_wglCreateContextAttribsARB) return 0; - if (share && !(share_ptr = get_handle_ptr( share, HANDLE_CONTEXT ))) + if (share && !(share_ptr = get_handle_ptr( share ))) { RtlSetLastWin32Error( ERROR_INVALID_OPERATION ); return 0; @@ -817,7 +817,7 @@ static BOOL wrap_wglDestroyPbufferARB( HPBUFFERARB handle ) { struct wgl_handle *ptr;
- if (!(ptr = get_handle_ptr( handle, HANDLE_PBUFFER ))) return FALSE; + if (!(ptr = get_handle_ptr( handle ))) return FALSE; ptr->funcs->p_wglDestroyPbufferARB( ptr->u.pbuffer ); free_handle_ptr( ptr ); return TRUE; @@ -826,7 +826,7 @@ static BOOL wrap_wglDestroyPbufferARB( HPBUFFERARB handle ) static HDC wrap_wglGetPbufferDCARB( HPBUFFERARB handle ) { struct wgl_handle *ptr; - if (!(ptr = get_handle_ptr( handle, HANDLE_PBUFFER ))) return 0; + if (!(ptr = get_handle_ptr( handle ))) return 0; return ptr->funcs->p_wglGetPbufferDCARB( ptr->u.pbuffer ); }
@@ -838,7 +838,7 @@ static BOOL wrap_wglMakeContextCurrentARB( TEB *teb, HDC draw_hdc, HDC read_hdc,
if (hglrc) { - if (!(ptr = get_handle_ptr( hglrc, HANDLE_CONTEXT ))) return FALSE; + if (!(ptr = get_handle_ptr( hglrc ))) return FALSE; if (!ptr->u.context->tid || ptr->u.context->tid == tid) { ret = (ptr->funcs->p_wglMakeContextCurrentARB && @@ -872,28 +872,28 @@ static BOOL wrap_wglMakeContextCurrentARB( TEB *teb, HDC draw_hdc, HDC read_hdc, static BOOL wrap_wglQueryPbufferARB( HPBUFFERARB handle, int attrib, int *value ) { struct wgl_handle *ptr; - if (!(ptr = get_handle_ptr( handle, HANDLE_PBUFFER ))) return FALSE; + if (!(ptr = get_handle_ptr( handle ))) return FALSE; return ptr->funcs->p_wglQueryPbufferARB( ptr->u.pbuffer, attrib, value ); }
static int wrap_wglReleasePbufferDCARB( HPBUFFERARB handle, HDC hdc ) { struct wgl_handle *ptr; - if (!(ptr = get_handle_ptr( handle, HANDLE_PBUFFER ))) return FALSE; + if (!(ptr = get_handle_ptr( handle ))) return FALSE; return ptr->funcs->p_wglReleasePbufferDCARB( ptr->u.pbuffer, hdc ); }
static BOOL wrap_wglReleaseTexImageARB( HPBUFFERARB handle, int buffer ) { struct wgl_handle *ptr; - if (!(ptr = get_handle_ptr( handle, HANDLE_PBUFFER ))) return FALSE; + if (!(ptr = get_handle_ptr( handle ))) return FALSE; return ptr->funcs->p_wglReleaseTexImageARB( ptr->u.pbuffer, buffer ); }
static BOOL wrap_wglSetPbufferAttribARB( HPBUFFERARB handle, const int *attribs ) { struct wgl_handle *ptr; - if (!(ptr = get_handle_ptr( handle, HANDLE_PBUFFER ))) return FALSE; + if (!(ptr = get_handle_ptr( handle ))) return FALSE; return ptr->funcs->p_wglSetPbufferAttribARB( ptr->u.pbuffer, attribs ); }
@@ -1635,7 +1635,7 @@ NTSTATUS wow64_ext_glClientWaitSync( void *args )
pthread_mutex_lock( &wgl_lock );
- if (!(handle = get_handle_ptr( ULongToPtr(params32->sync), HANDLE_GLSYNC ))) + if (!(handle = get_handle_ptr( ULongToPtr(params32->sync) ))) status = STATUS_INVALID_HANDLE; else { @@ -1666,7 +1666,7 @@ NTSTATUS wow64_ext_glDeleteSync( void *args )
pthread_mutex_lock( &wgl_lock );
- if (!(handle = get_handle_ptr( ULongToPtr(params32->sync), HANDLE_GLSYNC ))) + if (!(handle = get_handle_ptr( ULongToPtr(params32->sync) ))) status = STATUS_INVALID_HANDLE; else { @@ -1736,7 +1736,7 @@ NTSTATUS wow64_ext_glGetSynciv( void *args )
pthread_mutex_lock( &wgl_lock );
- if (!(handle = get_handle_ptr( ULongToPtr(params32->sync), HANDLE_GLSYNC ))) + if (!(handle = get_handle_ptr( ULongToPtr(params32->sync) ))) status = STATUS_INVALID_HANDLE; else { @@ -1769,7 +1769,7 @@ NTSTATUS wow64_ext_glIsSync( void *args )
pthread_mutex_lock( &wgl_lock );
- if (!(handle = get_handle_ptr( ULongToPtr(params32->sync), HANDLE_GLSYNC ))) + if (!(handle = get_handle_ptr( ULongToPtr(params32->sync) ))) status = STATUS_INVALID_HANDLE; else { @@ -1800,7 +1800,7 @@ NTSTATUS wow64_ext_glWaitSync( void *args )
pthread_mutex_lock( &wgl_lock );
- if (!(handle = get_handle_ptr( ULongToPtr(params32->sync), HANDLE_GLSYNC ))) + if (!(handle = get_handle_ptr( ULongToPtr(params32->sync) ))) status = STATUS_INVALID_HANDLE; else {
From: Rémi Bernon rbernon@codeweavers.com
This modifies the thread current context, which can only be attached to one thread at a time. --- dlls/opengl32/unix_wgl.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-)
diff --git a/dlls/opengl32/unix_wgl.c b/dlls/opengl32/unix_wgl.c index 6bff4de19c4..0acdeebce1d 100644 --- a/dlls/opengl32/unix_wgl.c +++ b/dlls/opengl32/unix_wgl.c @@ -73,7 +73,7 @@ struct opengl_context GLubyte *extensions; /* extension string */ GLuint *disabled_exts; /* indices of disabled extensions */ struct wgl_context *drv_ctx; /* driver context */ - GLubyte *version_string; + GLubyte *wow64_version; /* wow64 GL version override */ };
struct wgl_handle @@ -482,24 +482,18 @@ static const GLubyte *wrap_glGetString( TEB *teb, GLenum name ) else if (name == GL_VERSION && is_win64 && is_wow64()) { struct wgl_handle *ptr = get_current_context_ptr( teb ); + GLubyte **str = &ptr->u.context->wow64_version; int major, minor; - const char *rest;
- if (ptr->u.context->version_string) - return ptr->u.context->version_string; - - rest = parse_gl_version( (const char *)ret, &major, &minor ); - - /* 4.4 depends on ARB_buffer_storage, which we don't support on wow64. */ - if (major > 4 || (major == 4 && minor >= 4)) + if (!*str) { - char *str = NULL; - - asprintf( &str, "4.3%s", rest ); - if (InterlockedCompareExchangePointer( (void **)&ptr->u.context->version_string, str, NULL )) - free( str ); - return ptr->u.context->version_string; + const char *rest = parse_gl_version( (const char *)ret, &major, &minor ); + /* 4.4 depends on ARB_buffer_storage, which we don't support on wow64. */ + if (major > 4 || (major == 4 && minor >= 4)) asprintf( (char **)str, "4.3%s", rest ); + else *str = (GLubyte *)strdup( (char *)ret ); } + + return *str; } }
@@ -724,7 +718,7 @@ static BOOL wrap_wglDeleteContext( TEB *teb, HGLRC hglrc ) } if (hglrc == teb->glCurrentRC) wrap_wglMakeCurrent( teb, 0, 0 ); ptr->funcs->p_wglDeleteContext( ptr->u.context->drv_ctx ); - free( ptr->u.context->version_string ); + free( ptr->u.context->wow64_version ); free( ptr->u.context->disabled_exts ); free( ptr->u.context->extensions ); free( ptr->u.context );
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/opengl32/unix_wgl.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/dlls/opengl32/unix_wgl.c b/dlls/opengl32/unix_wgl.c index 0acdeebce1d..b49636b4062 100644 --- a/dlls/opengl32/unix_wgl.c +++ b/dlls/opengl32/unix_wgl.c @@ -84,6 +84,7 @@ struct wgl_handle { struct opengl_context *context; /* for HANDLE_CONTEXT */ struct wgl_pbuffer *pbuffer; /* for HANDLE_PBUFFER */ + GLsync sync; /* for HANDLE_GLSYNC */ struct wgl_handle *next; /* for free handles */ } u; }; @@ -1636,7 +1637,7 @@ NTSTATUS wow64_ext_glClientWaitSync( void *args ) struct glClientWaitSync_params params = { .teb = get_teb64(params32->teb), - .sync = (GLsync)handle->u.context, + .sync = handle->u.sync, .flags = params32->flags, .timeout = params32->timeout, }; @@ -1667,7 +1668,7 @@ NTSTATUS wow64_ext_glDeleteSync( void *args ) struct glDeleteSync_params params = { .teb = get_teb64(params32->teb), - .sync = (GLsync)handle->u.context, + .sync = handle->u.sync, }; status = ext_glDeleteSync( ¶ms ); free_handle_ptr( handle ); @@ -1737,7 +1738,7 @@ NTSTATUS wow64_ext_glGetSynciv( void *args ) struct glGetSynciv_params params = { .teb = get_teb64(params32->teb), - .sync = (GLsync)handle->u.context, + .sync = handle->u.sync, .pname = params32->pname, .count = params32->count, .length = ULongToPtr(params32->length), @@ -1770,7 +1771,7 @@ NTSTATUS wow64_ext_glIsSync( void *args ) struct glIsSync_params params = { .teb = get_teb64(params32->teb), - .sync = (GLsync)handle->u.context, + .sync = handle->u.sync, }; status = ext_glIsSync( ¶ms ); params32->ret = params.ret; @@ -1801,7 +1802,7 @@ NTSTATUS wow64_ext_glWaitSync( void *args ) struct glWaitSync_params params = { .teb = get_teb64(params32->teb), - .sync = (GLsync)handle->u.context, + .sync = handle->u.sync, .flags = params32->flags, .timeout = params32->timeout, };
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/opengl32/unix_wgl.c | 149 +++++++++++++++++++++------------------ 1 file changed, 79 insertions(+), 70 deletions(-)
diff --git a/dlls/opengl32/unix_wgl.c b/dlls/opengl32/unix_wgl.c index b49636b4062..2fc072526e1 100644 --- a/dlls/opengl32/unix_wgl.c +++ b/dlls/opengl32/unix_wgl.c @@ -95,10 +95,10 @@ static struct wgl_handle *next_free; static unsigned int handle_count;
/* the current context is assumed valid and doesn't need locking */ -static inline struct wgl_handle *get_current_context_ptr( TEB *teb ) +static struct opengl_context *get_current_context( TEB *teb ) { if (!teb->glCurrentRC) return NULL; - return &wgl_handles[LOWORD(teb->glCurrentRC) & ~HANDLE_TYPE_MASK]; + return wgl_handles[LOWORD(teb->glCurrentRC) & ~HANDLE_TYPE_MASK].u.context; }
static inline HANDLE next_handle( struct wgl_handle *ptr, enum wgl_handle_type type ) @@ -120,6 +120,14 @@ 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 ) +{ + struct wgl_handle *entry; + if (!(entry = get_handle_ptr( handle ))) return NULL; + *funcs = entry->funcs; + return entry->u.context; +} + static HANDLE alloc_handle( enum wgl_handle_type type, const struct opengl_funcs *funcs, void *user_ptr ) { HANDLE handle = 0; @@ -385,8 +393,8 @@ static BOOL filter_extensions( TEB * teb, const char *extensions, GLubyte **exts
static const GLuint *disabled_extensions_index( TEB *teb ) { - struct wgl_handle *ptr = get_current_context_ptr( teb ); - GLuint **disabled = &ptr->u.context->disabled_exts; + struct opengl_context *ctx = get_current_context( teb ); + GLuint **disabled = &ctx->disabled_exts; if (*disabled || filter_extensions( teb, NULL, NULL, disabled )) return *disabled; return NULL; } @@ -475,15 +483,15 @@ static const GLubyte *wrap_glGetString( TEB *teb, GLenum name ) { if (name == GL_EXTENSIONS) { - struct wgl_handle *ptr = get_current_context_ptr( teb ); - GLubyte **extensions = &ptr->u.context->extensions; - GLuint **disabled = &ptr->u.context->disabled_exts; + struct opengl_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 wgl_handle *ptr = get_current_context_ptr( teb ); - GLubyte **str = &ptr->u.context->wow64_version; + struct opengl_context *ctx = get_current_context( teb ); + GLubyte **str = &ctx->wow64_version; int major, minor;
if (!*str) @@ -578,7 +586,7 @@ static PROC wrap_wglGetProcAddress( TEB *teb, LPCSTR name ) /* Without an active context opengl32 doesn't know to what * driver it has to dispatch wglGetProcAddress. */ - if (!get_current_context_ptr( teb )) + if (!get_current_context( teb )) { WARN( "No active WGL context found\n" ); return (void *)-1; @@ -633,15 +641,14 @@ static PROC wrap_wglGetProcAddress( TEB *teb, LPCSTR name )
static BOOL wrap_wglCopyContext( HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask ) { - struct wgl_handle *src, *dst; + const struct opengl_funcs *src_funcs, *dst_funcs; + struct opengl_context *src, *dst; BOOL ret = FALSE;
- if (!(src = get_handle_ptr( hglrcSrc ))) return FALSE; - if ((dst = get_handle_ptr( hglrcDst ))) - { - if (src->funcs != dst->funcs) RtlSetLastWin32Error( ERROR_INVALID_HANDLE ); - else ret = src->funcs->p_wglCopyContext( src->u.context->drv_ctx, dst->u.context->drv_ctx, mask ); - } + if (!(src = opengl_context_from_handle( hglrcSrc, &src_funcs ))) return FALSE; + if (!(dst = opengl_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 ); return ret; }
@@ -667,22 +674,23 @@ static BOOL wrap_wglMakeCurrent( TEB *teb, HDC hdc, HGLRC hglrc ) { BOOL ret = TRUE; DWORD tid = HandleToULong(teb->ClientId.UniqueThread); - struct wgl_handle *ptr, *prev = get_current_context_ptr( teb ); + struct opengl_context *ctx, *prev = get_current_context( teb ); + const struct opengl_funcs *funcs = teb->glTable;
if (hglrc) { - if (!(ptr = get_handle_ptr( hglrc ))) return FALSE; - if (!ptr->u.context->tid || ptr->u.context->tid == tid) + if (!(ctx = opengl_context_from_handle( hglrc, &funcs ))) return FALSE; + if (!ctx->tid || ctx->tid == tid) { - ret = ptr->funcs->p_wglMakeCurrent( hdc, ptr->u.context->drv_ctx ); + ret = funcs->p_wglMakeCurrent( hdc, ctx->drv_ctx ); if (ret) { - if (prev) prev->u.context->tid = 0; - ptr->u.context->tid = tid; + if (prev) prev->tid = 0; + ctx->tid = tid; teb->glReserved1[0] = hdc; teb->glReserved1[1] = hdc; teb->glCurrentRC = hglrc; - teb->glTable = (void *)ptr->funcs; + teb->glTable = (void *)funcs; } } else @@ -693,8 +701,8 @@ static BOOL wrap_wglMakeCurrent( TEB *teb, HDC hdc, HGLRC hglrc ) } else if (prev) { - if (!prev->funcs->p_wglMakeCurrent( 0, NULL )) return FALSE; - prev->u.context->tid = 0; + if (!funcs->p_wglMakeCurrent( 0, NULL )) return FALSE; + prev->tid = 0; teb->glCurrentRC = 0; teb->glTable = &null_opengl_funcs; } @@ -709,35 +717,36 @@ 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; DWORD tid = HandleToULong(teb->ClientId.UniqueThread);
if (!(ptr = get_handle_ptr( hglrc ))) return FALSE; - if (ptr->u.context->tid && ptr->u.context->tid != tid) + ctx = ptr->u.context; + if (ctx->tid && ctx->tid != tid) { RtlSetLastWin32Error( ERROR_BUSY ); return FALSE; } if (hglrc == teb->glCurrentRC) wrap_wglMakeCurrent( teb, 0, 0 ); - ptr->funcs->p_wglDeleteContext( ptr->u.context->drv_ctx ); - free( ptr->u.context->wow64_version ); - free( ptr->u.context->disabled_exts ); - free( ptr->u.context->extensions ); - free( ptr->u.context ); + ptr->funcs->p_wglDeleteContext( ctx->drv_ctx ); + free( ctx->wow64_version ); + free( ctx->disabled_exts ); + free( ctx->extensions ); + free( ctx ); free_handle_ptr( ptr ); return TRUE; }
static BOOL wrap_wglShareLists( HGLRC hglrcSrc, HGLRC hglrcDst ) { + const struct opengl_funcs *src_funcs, *dst_funcs; + struct opengl_context *src, *dst; BOOL ret = FALSE; - struct wgl_handle *src, *dst;
- if (!(src = get_handle_ptr( hglrcSrc ))) return FALSE; - if ((dst = get_handle_ptr( hglrcDst ))) - { - if (src->funcs != dst->funcs) RtlSetLastWin32Error( ERROR_INVALID_HANDLE ); - else ret = src->funcs->p_wglShareLists( src->u.context->drv_ctx, dst->u.context->drv_ctx ); - } + if (!(src = opengl_context_from_handle( hglrcSrc, &src_funcs ))) return FALSE; + if (!(dst = opengl_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 ); return ret; }
@@ -752,9 +761,8 @@ static HGLRC wrap_wglCreateContextAttribsARB( HDC hdc, HGLRC share, const int *a { HGLRC ret = 0; struct wgl_context *drv_ctx; - struct wgl_handle *share_ptr = NULL; - struct opengl_context *context; - const struct opengl_funcs *funcs = get_dc_funcs( hdc ); + struct opengl_context *context, *share_ctx = NULL; + const struct opengl_funcs *funcs = get_dc_funcs( hdc ), *share_funcs;
if (!funcs) { @@ -762,12 +770,12 @@ static HGLRC wrap_wglCreateContextAttribsARB( HDC hdc, HGLRC share, const int *a return 0; } if (!funcs->p_wglCreateContextAttribsARB) return 0; - if (share && !(share_ptr = get_handle_ptr( share ))) + if (share && !(share_ctx = opengl_context_from_handle( share, &share_funcs ))) { RtlSetLastWin32Error( ERROR_INVALID_OPERATION ); return 0; } - if ((drv_ctx = funcs->p_wglCreateContextAttribsARB( hdc, share_ptr ? share_ptr->u.context->drv_ctx : NULL, attribs ))) + if ((drv_ctx = funcs->p_wglCreateContextAttribsARB( hdc, share_ctx ? share_ctx->drv_ctx : NULL, attribs ))) { if ((context = calloc( 1, sizeof(*context) ))) { @@ -829,23 +837,24 @@ static BOOL wrap_wglMakeContextCurrentARB( TEB *teb, HDC draw_hdc, HDC read_hdc, { BOOL ret = TRUE; DWORD tid = HandleToULong(teb->ClientId.UniqueThread); - struct wgl_handle *ptr, *prev = get_current_context_ptr( teb ); + struct opengl_context *ctx, *prev = get_current_context( teb ); + const struct opengl_funcs *funcs = teb->glTable;
if (hglrc) { - if (!(ptr = get_handle_ptr( hglrc ))) return FALSE; - if (!ptr->u.context->tid || ptr->u.context->tid == tid) + if (!(ctx = opengl_context_from_handle( hglrc, &funcs ))) return FALSE; + if (!ctx->tid || ctx->tid == tid) { - ret = (ptr->funcs->p_wglMakeContextCurrentARB && - ptr->funcs->p_wglMakeContextCurrentARB( draw_hdc, read_hdc, ptr->u.context->drv_ctx )); + ret = (funcs->p_wglMakeContextCurrentARB && + funcs->p_wglMakeContextCurrentARB( draw_hdc, read_hdc, ctx->drv_ctx )); if (ret) { - if (prev) prev->u.context->tid = 0; - ptr->u.context->tid = tid; + if (prev) prev->tid = 0; + ctx->tid = tid; teb->glReserved1[0] = draw_hdc; teb->glReserved1[1] = read_hdc; teb->glCurrentRC = hglrc; - teb->glTable = (void *)ptr->funcs; + teb->glTable = (void *)funcs; } } else @@ -856,8 +865,8 @@ static BOOL wrap_wglMakeContextCurrentARB( TEB *teb, HDC draw_hdc, HDC read_hdc, } else if (prev) { - if (!prev->funcs->p_wglMakeCurrent( 0, NULL )) return FALSE; - prev->u.context->tid = 0; + if (!funcs->p_wglMakeCurrent( 0, NULL )) return FALSE; + prev->tid = 0; teb->glCurrentRC = 0; teb->glTable = &null_opengl_funcs; } @@ -898,10 +907,10 @@ 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 wgl_handle *ptr = (struct wgl_handle *)user; + struct opengl_context *ctx = (struct opengl_context *)user; UINT len = strlen( message ) + 1, size;
- if (!ptr->u.context->debug_callback) return; + if (!ctx->debug_callback) return; if (!NtCurrentTeb()) { fprintf( stderr, "msg:gl_debug_message_callback called from native thread, severity %#x, message "%.*s".\n", @@ -912,8 +921,8 @@ static void gl_debug_message_callback( GLenum source, GLenum type, GLuint id, GL size = offsetof(struct gl_debug_message_callback_params, message[len] ); if (!(params = malloc( size ))) return; params->dispatch.callback = call_gl_debug_message_callback; - params->debug_callback = ptr->u.context->debug_callback; - params->debug_user = ptr->u.context->debug_user; + params->debug_callback = ctx->debug_callback; + params->debug_user = ctx->debug_user; params->source = source; params->type = type; params->id = id; @@ -927,38 +936,38 @@ 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 wgl_handle *ptr = get_current_context_ptr( teb ); + struct opengl_context *ctx = get_current_context( teb ); const struct opengl_funcs *funcs = teb->glTable;
if (!funcs->p_glDebugMessageCallback) return;
- ptr->u.context->debug_callback = (UINT_PTR)callback; - ptr->u.context->debug_user = (UINT_PTR)user; - funcs->p_glDebugMessageCallback( gl_debug_message_callback, ptr ); + ctx->debug_callback = (UINT_PTR)callback; + ctx->debug_user = (UINT_PTR)user; + funcs->p_glDebugMessageCallback( gl_debug_message_callback, ctx ); }
static void wrap_glDebugMessageCallbackAMD( TEB *teb, GLDEBUGPROCAMD callback, void *user ) { - struct wgl_handle *ptr = get_current_context_ptr( teb ); + struct opengl_context *ctx = get_current_context( teb ); const struct opengl_funcs *funcs = teb->glTable;
if (!funcs->p_glDebugMessageCallbackAMD) return;
- ptr->u.context->debug_callback = (UINT_PTR)callback; - ptr->u.context->debug_user = (UINT_PTR)user; - funcs->p_glDebugMessageCallbackAMD( gl_debug_message_callback, ptr ); + ctx->debug_callback = (UINT_PTR)callback; + ctx->debug_user = (UINT_PTR)user; + funcs->p_glDebugMessageCallbackAMD( gl_debug_message_callback, ctx ); }
static void wrap_glDebugMessageCallbackARB( TEB *teb, GLDEBUGPROCARB callback, const void *user ) { - struct wgl_handle *ptr = get_current_context_ptr( teb ); + struct opengl_context *ctx = get_current_context( teb ); const struct opengl_funcs *funcs = teb->glTable;
if (!funcs->p_glDebugMessageCallbackARB) return;
- ptr->u.context->debug_callback = (UINT_PTR)callback; - ptr->u.context->debug_user = (UINT_PTR)user; - funcs->p_glDebugMessageCallbackARB( gl_debug_message_callback, ptr ); + ctx->debug_callback = (UINT_PTR)callback; + ctx->debug_user = (UINT_PTR)user; + funcs->p_glDebugMessageCallbackARB( gl_debug_message_callback, ctx ); }
NTSTATUS wgl_wglCopyContext( void *args )
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/opengl32/unix_wgl.c | 54 ++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 19 deletions(-)
diff --git a/dlls/opengl32/unix_wgl.c b/dlls/opengl32/unix_wgl.c index 2fc072526e1..ea08eefe7b5 100644 --- a/dlls/opengl32/unix_wgl.c +++ b/dlls/opengl32/unix_wgl.c @@ -128,6 +128,14 @@ static struct opengl_context *opengl_context_from_handle( HGLRC handle, const st return entry->u.context; }
+static struct wgl_pbuffer *wgl_pbuffer_from_handle( HPBUFFERARB handle, const struct opengl_funcs **funcs ) +{ + struct wgl_handle *entry; + if (!(entry = get_handle_ptr( handle ))) return NULL; + *funcs = entry->funcs; + return entry->u.pbuffer; +} + static HANDLE alloc_handle( enum wgl_handle_type type, const struct opengl_funcs *funcs, void *user_ptr ) { HANDLE handle = 0; @@ -752,9 +760,10 @@ static BOOL wrap_wglShareLists( HGLRC hglrcSrc, HGLRC hglrcDst )
static BOOL wrap_wglBindTexImageARB( HPBUFFERARB handle, int buffer ) { - struct wgl_handle *ptr; - if (!(ptr = get_handle_ptr( handle ))) return FALSE; - return ptr->funcs->p_wglBindTexImageARB( ptr->u.pbuffer, buffer ); + const struct opengl_funcs *funcs; + struct wgl_pbuffer *pbuffer; + if (!(pbuffer = wgl_pbuffer_from_handle( handle, &funcs ))) return FALSE; + return funcs->p_wglBindTexImageARB( pbuffer, buffer ); }
static HGLRC wrap_wglCreateContextAttribsARB( HDC hdc, HGLRC share, const int *attribs ) @@ -818,19 +827,22 @@ static HPBUFFERARB wrap_wglCreatePbufferARB( HDC hdc, int format, int width, int
static BOOL wrap_wglDestroyPbufferARB( HPBUFFERARB handle ) { + struct wgl_pbuffer *pbuffer; struct wgl_handle *ptr;
if (!(ptr = get_handle_ptr( handle ))) return FALSE; - ptr->funcs->p_wglDestroyPbufferARB( ptr->u.pbuffer ); + pbuffer = ptr->u.pbuffer; + ptr->funcs->p_wglDestroyPbufferARB( pbuffer ); free_handle_ptr( ptr ); return TRUE; }
static HDC wrap_wglGetPbufferDCARB( HPBUFFERARB handle ) { - struct wgl_handle *ptr; - if (!(ptr = get_handle_ptr( handle ))) return 0; - return ptr->funcs->p_wglGetPbufferDCARB( ptr->u.pbuffer ); + const struct opengl_funcs *funcs; + struct wgl_pbuffer *pbuffer; + if (!(pbuffer = wgl_pbuffer_from_handle( handle, &funcs ))) return 0; + return funcs->p_wglGetPbufferDCARB( pbuffer ); }
static BOOL wrap_wglMakeContextCurrentARB( TEB *teb, HDC draw_hdc, HDC read_hdc, HGLRC hglrc ) @@ -875,30 +887,34 @@ static BOOL wrap_wglMakeContextCurrentARB( TEB *teb, HDC draw_hdc, HDC read_hdc,
static BOOL wrap_wglQueryPbufferARB( HPBUFFERARB handle, int attrib, int *value ) { - struct wgl_handle *ptr; - if (!(ptr = get_handle_ptr( handle ))) return FALSE; - return ptr->funcs->p_wglQueryPbufferARB( ptr->u.pbuffer, attrib, value ); + const struct opengl_funcs *funcs; + struct wgl_pbuffer *pbuffer; + if (!(pbuffer = wgl_pbuffer_from_handle( handle, &funcs ))) return FALSE; + return funcs->p_wglQueryPbufferARB( pbuffer, attrib, value ); }
static int wrap_wglReleasePbufferDCARB( HPBUFFERARB handle, HDC hdc ) { - struct wgl_handle *ptr; - if (!(ptr = get_handle_ptr( handle ))) return FALSE; - return ptr->funcs->p_wglReleasePbufferDCARB( ptr->u.pbuffer, hdc ); + const struct opengl_funcs *funcs; + struct wgl_pbuffer *pbuffer; + if (!(pbuffer = wgl_pbuffer_from_handle( handle, &funcs ))) return FALSE; + return funcs->p_wglReleasePbufferDCARB( pbuffer, hdc ); }
static BOOL wrap_wglReleaseTexImageARB( HPBUFFERARB handle, int buffer ) { - struct wgl_handle *ptr; - if (!(ptr = get_handle_ptr( handle ))) return FALSE; - return ptr->funcs->p_wglReleaseTexImageARB( ptr->u.pbuffer, buffer ); + const struct opengl_funcs *funcs; + struct wgl_pbuffer *pbuffer; + if (!(pbuffer = wgl_pbuffer_from_handle( handle, &funcs ))) return FALSE; + return funcs->p_wglReleaseTexImageARB( pbuffer, buffer ); }
static BOOL wrap_wglSetPbufferAttribARB( HPBUFFERARB handle, const int *attribs ) { - struct wgl_handle *ptr; - if (!(ptr = get_handle_ptr( handle ))) return FALSE; - return ptr->funcs->p_wglSetPbufferAttribARB( ptr->u.pbuffer, attribs ); + const struct opengl_funcs *funcs; + struct wgl_pbuffer *pbuffer; + if (!(pbuffer = wgl_pbuffer_from_handle( handle, &funcs ))) return FALSE; + return funcs->p_wglSetPbufferAttribARB( pbuffer, attribs ); }
static void gl_debug_message_callback( GLenum source, GLenum type, GLuint id, GLenum severity,