From: Rémi Bernon rbernon@codeweavers.com
--- dlls/win32u/opengl.c | 10 ++--- dlls/wineandroid.drv/android.h | 1 - dlls/wineandroid.drv/opengl.c | 80 ++++------------------------------ dlls/winemac.drv/opengl.c | 18 ++++---- dlls/winewayland.drv/opengl.c | 25 +++-------- dlls/winex11.drv/opengl.c | 78 ++++++++------------------------- include/wine/opengl_driver.h | 2 +- 7 files changed, 48 insertions(+), 166 deletions(-)
diff --git a/dlls/win32u/opengl.c b/dlls/win32u/opengl.c index 395a68d8cde..098e5fe04a8 100644 --- a/dlls/win32u/opengl.c +++ b/dlls/win32u/opengl.c @@ -438,7 +438,7 @@ static BOOL egldrv_context_destroy( void *private ) return FALSE; }
-static BOOL egldrv_context_make_current( HDC draw_hdc, HDC read_hdc, void *private ) +static BOOL egldrv_make_current( struct opengl_drawable *draw_base, struct opengl_drawable *read_base, void *private ) { FIXME( "stub!\n" ); return FALSE; @@ -456,7 +456,7 @@ static const struct opengl_driver_funcs egldrv_funcs = .p_pbuffer_bind = egldrv_pbuffer_bind, .p_context_create = egldrv_context_create, .p_context_destroy = egldrv_context_destroy, - .p_context_make_current = egldrv_context_make_current, + .p_make_current = egldrv_make_current, };
static BOOL egl_init( const struct opengl_driver_funcs **driver_funcs ) @@ -627,7 +627,7 @@ static BOOL nulldrv_context_destroy( void *private ) return FALSE; }
-static BOOL nulldrv_context_make_current( HDC draw, HDC read, void *context ) +static BOOL nulldrv_make_current( struct opengl_drawable *draw_base, struct opengl_drawable *read_base, void *private ) { return FALSE; } @@ -644,7 +644,7 @@ static const struct opengl_driver_funcs nulldrv_funcs = .p_pbuffer_bind = nulldrv_pbuffer_bind, .p_context_create = nulldrv_context_create, .p_context_destroy = nulldrv_context_destroy, - .p_context_make_current = nulldrv_context_make_current, + .p_make_current = nulldrv_make_current, };
static const struct opengl_driver_funcs *driver_funcs = &nulldrv_funcs; @@ -965,7 +965,7 @@ static BOOL context_set_drawables( struct wgl_context *context, void *private, H WARN( "Unexpected drawables with NULL context\n" ); else if (!force && new_draw == context->draw && new_read == context->read) TRACE( "Drawables didn't change, nothing to do\n" ); - else if (driver_funcs->p_context_make_current( draw_hdc, read_hdc, private )) + else if (driver_funcs->p_make_current( new_draw, new_read, private )) { if ((context->draw = new_draw)) opengl_drawable_add_ref( new_draw ); if ((context->read = new_read)) opengl_drawable_add_ref( new_read ); diff --git a/dlls/wineandroid.drv/android.h b/dlls/wineandroid.drv/android.h index 291d2f0d299..3316ee015ac 100644 --- a/dlls/wineandroid.drv/android.h +++ b/dlls/wineandroid.drv/android.h @@ -55,7 +55,6 @@ 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 UINT ANDROID_OpenGLInit( UINT version, const struct opengl_funcs *opengl_funcs, const struct opengl_driver_funcs **driver_funcs );
diff --git a/dlls/wineandroid.drv/opengl.c b/dlls/wineandroid.drv/opengl.c index 9d5d03292e1..4637a04eec9 100644 --- a/dlls/wineandroid.drv/opengl.c +++ b/dlls/wineandroid.drv/opengl.c @@ -76,9 +76,6 @@ static struct gl_drawable *impl_from_opengl_drawable( struct opengl_drawable *ba }
static void *opengl_handle; -static struct list gl_drawables = LIST_INIT( gl_drawables ); - -pthread_mutex_t drawable_mutex;
static inline EGLConfig egl_config_for_format(int format) { @@ -87,12 +84,6 @@ static inline EGLConfig egl_config_for_format(int format) return egl->configs[format - egl->config_count - 1]; }
-static struct gl_drawable *gl_drawable_grab( struct gl_drawable *gl ) -{ - opengl_drawable_add_ref( &gl->base ); - return gl; -} - static struct gl_drawable *create_gl_drawable( HWND hwnd, HDC hdc, int format, ANativeWindow *window ) { static const int attribs[] = { EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE }; @@ -106,28 +97,10 @@ static struct gl_drawable *create_gl_drawable( HWND hwnd, HDC hdc, int format, A if (!window) gl->surface = funcs->p_eglCreatePbufferSurface( egl->display, egl_config_for_format(gl->base.format), attribs ); else gl->surface = funcs->p_eglCreateWindowSurface( egl->display, egl_config_for_format(gl->base.format), gl->window, NULL );
- pthread_mutex_lock( &drawable_mutex ); - list_add_head( &gl_drawables, &gl->entry ); - opengl_drawable_add_ref( &gl->base ); - TRACE( "Created drawable %s with client window %p\n", debugstr_opengl_drawable( &gl->base ), gl->window ); return gl; }
-static struct gl_drawable *get_gl_drawable( HWND hwnd, HDC hdc ) -{ - struct gl_drawable *gl; - - pthread_mutex_lock( &drawable_mutex ); - LIST_FOR_EACH_ENTRY( gl, &gl_drawables, struct gl_drawable, entry ) - { - if (hwnd && gl->base.hwnd == hwnd) return gl_drawable_grab( gl ); - if (hdc && gl->base.hdc == hdc) return gl_drawable_grab( gl ); - } - pthread_mutex_unlock( &drawable_mutex ); - return NULL; -} - static void android_drawable_destroy( struct opengl_drawable *base ) { struct gl_drawable *gl = impl_from_opengl_drawable( base ); @@ -135,26 +108,6 @@ static void android_drawable_destroy( struct opengl_drawable *base ) release_ioctl_window( gl->window ); }
-static void release_gl_drawable( struct gl_drawable *gl ) -{ - opengl_drawable_release( &gl->base ); - pthread_mutex_unlock( &drawable_mutex ); -} - -void destroy_gl_drawable( HWND hwnd ) -{ - struct gl_drawable *gl; - - pthread_mutex_lock( &drawable_mutex ); - LIST_FOR_EACH_ENTRY( gl, &gl_drawables, struct gl_drawable, entry ) - { - if (gl->base.hwnd != hwnd) continue; - list_remove( &gl->entry ); - return release_gl_drawable( gl ); - } - pthread_mutex_unlock( &drawable_mutex ); -} - void update_gl_drawable( HWND hwnd ) { struct gl_drawable *old, *new; @@ -163,7 +116,7 @@ void update_gl_drawable( HWND hwnd ) if ((new = create_gl_drawable( hwnd, 0, old->base.format, old->window ))) { set_window_opengl_drawable( hwnd, &new->base ); - release_gl_drawable( new ); + opengl_drawable_release( &new->base ); } opengl_drawable_release( &old->base );
@@ -194,9 +147,7 @@ static BOOL android_surface_create( HWND hwnd, HDC hdc, int format, struct openg }
if (!(gl = create_gl_drawable( hwnd, hdc, format, NULL ))) return FALSE; - opengl_drawable_add_ref( (*drawable = &gl->base) ); - release_gl_drawable( gl ); - + *drawable = &gl->base; return TRUE; }
@@ -247,14 +198,12 @@ static BOOL android_context_create( int format, void *share, const int *attribs, return TRUE; }
-static BOOL android_context_make_current( HDC draw_hdc, HDC read_hdc, void *private ) +static BOOL android_make_current( struct opengl_drawable *draw_base, struct opengl_drawable *read_base, void *private ) { + struct gl_drawable *draw = impl_from_opengl_drawable( draw_base ), *read = impl_from_opengl_drawable( read_base ); struct android_context *ctx = private; - BOOL ret = FALSE; - struct gl_drawable *draw_gl, *read_gl = NULL; - HWND draw_hwnd;
- TRACE( "%p %p %p\n", draw_hdc, read_hdc, ctx ); + TRACE( "draw %s, read %s, context %p\n", debugstr_opengl_drawable( draw_base ), debugstr_opengl_drawable( read_base ), private );
if (!private) { @@ -262,21 +211,8 @@ static BOOL android_context_make_current( HDC draw_hdc, HDC read_hdc, void *priv return TRUE; }
- draw_hwnd = NtUserWindowFromDC( draw_hdc ); - if ((draw_gl = get_gl_drawable( draw_hwnd, draw_hdc ))) - { - read_gl = get_gl_drawable( NtUserWindowFromDC( read_hdc ), read_hdc ); - TRACE( "%p/%p context %p surface %p/%p\n", - draw_hdc, read_hdc, ctx->context, draw_gl->surface, read_gl->surface ); - ret = funcs->p_eglMakeCurrent( egl->display, draw_gl->surface, read_gl->surface, ctx->context ); - if (ret) goto done; - } - RtlSetLastWin32Error( ERROR_INVALID_HANDLE ); - -done: - if (read_gl) release_gl_drawable( read_gl ); - if (draw_gl) release_gl_drawable( draw_gl ); - return ret; + if (!funcs->p_eglMakeCurrent( egl->display, draw->surface, read->surface, ctx->context )) return FALSE; + return TRUE; }
/*********************************************************************** @@ -336,7 +272,7 @@ static struct opengl_driver_funcs android_driver_funcs = .p_surface_create = android_surface_create, .p_context_create = android_context_create, .p_context_destroy = android_context_destroy, - .p_context_make_current = android_context_make_current, + .p_make_current = android_make_current, };
static const struct opengl_drawable_funcs android_drawable_funcs = diff --git a/dlls/winemac.drv/opengl.c b/dlls/winemac.drv/opengl.c index f93890f6af1..9a28ec10b51 100644 --- a/dlls/winemac.drv/opengl.c +++ b/dlls/winemac.drv/opengl.c @@ -2383,14 +2383,14 @@ static BOOL macdrv_pbuffer_swap(struct opengl_drawable *base) return FALSE; }
-static BOOL macdrv_context_make_current(HDC draw_hdc, HDC read_hdc, void *private) +static BOOL macdrv_make_current(struct opengl_drawable *draw_base, struct opengl_drawable *read_base, void *private) { + struct gl_drawable *draw = impl_from_opengl_drawable(draw_base), *read = impl_from_opengl_drawable(read_base); struct macdrv_context *context = private; struct macdrv_win_data *data; HWND hwnd;
- TRACE("draw_hdc %p read_hdc %p context %p/%p/%p\n", draw_hdc, read_hdc, context, - (context ? context->context : NULL), (context ? context->cglcontext : NULL)); + TRACE("draw %s, read %s, context %p\n", debugstr_opengl_drawable(draw_base), debugstr_opengl_drawable(read_base), private);
if (!private) { @@ -2399,7 +2399,7 @@ static BOOL macdrv_context_make_current(HDC draw_hdc, HDC read_hdc, void *privat return TRUE; }
- if ((hwnd = NtUserWindowFromDC(draw_hdc))) + if ((hwnd = draw->base.hwnd)) { if (!(data = get_win_data(hwnd))) { @@ -2420,7 +2420,7 @@ static BOOL macdrv_context_make_current(HDC draw_hdc, HDC read_hdc, void *privat CGLPBufferObj pbuffer;
pthread_mutex_lock(&dc_pbuffers_mutex); - pbuffer = (CGLPBufferObj)CFDictionaryGetValue(dc_pbuffers, draw_hdc); + pbuffer = (CGLPBufferObj)CFDictionaryGetValue(dc_pbuffers, draw->base.hdc); if (!pbuffer) { WARN("no window or pbuffer for DC\n"); @@ -2437,9 +2437,9 @@ static BOOL macdrv_context_make_current(HDC draw_hdc, HDC read_hdc, void *privat
context->read_view = NULL; context->read_pbuffer = NULL; - if (read_hdc && read_hdc != draw_hdc) + if (read != draw) { - if ((hwnd = NtUserWindowFromDC(read_hdc))) + if ((hwnd = read->base.hwnd)) { if ((data = get_win_data(hwnd))) { @@ -2455,7 +2455,7 @@ static BOOL macdrv_context_make_current(HDC draw_hdc, HDC read_hdc, void *privat else { pthread_mutex_lock(&dc_pbuffers_mutex); - context->read_pbuffer = (CGLPBufferObj)CFDictionaryGetValue(dc_pbuffers, read_hdc); + context->read_pbuffer = (CGLPBufferObj)CFDictionaryGetValue(dc_pbuffers, read->base.hdc); pthread_mutex_unlock(&dc_pbuffers_mutex); } } @@ -3012,7 +3012,7 @@ static const struct opengl_driver_funcs macdrv_driver_funcs = .p_surface_create = macdrv_surface_create, .p_context_create = macdrv_context_create, .p_context_destroy = macdrv_context_destroy, - .p_context_make_current = macdrv_context_make_current, + .p_make_current = macdrv_make_current, .p_pbuffer_create = macdrv_pbuffer_create, .p_pbuffer_updated = macdrv_pbuffer_updated, .p_pbuffer_bind = macdrv_pbuffer_bind, diff --git a/dlls/winewayland.drv/opengl.c b/dlls/winewayland.drv/opengl.c index ead93917733..ede1b5982fa 100644 --- a/dlls/winewayland.drv/opengl.c +++ b/dlls/winewayland.drv/opengl.c @@ -236,14 +236,14 @@ static void wayland_gl_drawable_sync_size(struct wayland_gl_drawable *gl) } }
-static BOOL wayland_context_make_current(HDC draw_hdc, HDC read_hdc, void *private) +static BOOL wayland_make_current(struct opengl_drawable *draw_base, struct opengl_drawable *read_base, void *private) { + struct wayland_gl_drawable *draw = impl_from_opengl_drawable(draw_base), *read = impl_from_opengl_drawable(read_base); BOOL ret; struct wayland_context *ctx = private; - struct wayland_gl_drawable *draw, *read; struct wayland_gl_drawable *old_draw = NULL, *old_read = NULL;
- TRACE("draw_hdc=%p read_hdc=%p ctx=%p\n", draw_hdc, read_hdc, ctx); + TRACE("draw %s, read %s, context %p\n", debugstr_opengl_drawable(draw_base), debugstr_opengl_drawable(read_base), private);
if (!private) { @@ -251,14 +251,6 @@ static BOOL wayland_context_make_current(HDC draw_hdc, HDC read_hdc, void *priva return TRUE; }
- draw = wayland_gl_drawable_get(NtUserWindowFromDC(draw_hdc), draw_hdc); - read = wayland_gl_drawable_get(NtUserWindowFromDC(read_hdc), read_hdc); - - TRACE("%p/%p context %p surface %p/%p\n", - draw_hdc, read_hdc, ctx->context, - draw ? draw->surface : EGL_NO_SURFACE, - read ? read->surface : EGL_NO_SURFACE); - /* Since making an EGL surface current may latch the native size, * perform any pending resizes before calling it. */ if (draw) wayland_gl_drawable_sync_size(draw); @@ -273,13 +265,8 @@ static BOOL wayland_context_make_current(HDC draw_hdc, HDC read_hdc, void *priva { old_draw = ctx->draw; old_read = ctx->read; - ctx->draw = draw; - ctx->read = read; - } - else - { - old_draw = draw; - old_read = read; + if ((ctx->draw = draw)) opengl_drawable_add_ref(&draw->base); + if ((ctx->read = read)) opengl_drawable_add_ref(&read->base); }
pthread_mutex_unlock(&gl_object_mutex); @@ -481,7 +468,7 @@ static struct opengl_driver_funcs wayland_driver_funcs = .p_surface_create = wayland_opengl_surface_create, .p_context_create = wayland_context_create, .p_context_destroy = wayland_context_destroy, - .p_context_make_current = wayland_context_make_current, + .p_make_current = wayland_make_current, .p_pbuffer_create = wayland_pbuffer_create, .p_pbuffer_updated = wayland_pbuffer_updated, .p_pbuffer_bind = wayland_pbuffer_bind, diff --git a/dlls/winex11.drv/opengl.c b/dlls/winex11.drv/opengl.c index 37bb99d3bcc..7f0b3215ffd 100644 --- a/dlls/winex11.drv/opengl.c +++ b/dlls/winex11.drv/opengl.c @@ -821,12 +821,6 @@ static struct glx_pixel_format *glx_pixel_format_from_format( int format ) return &pixel_formats[format - 1]; }
-static struct gl_drawable *grab_gl_drawable( struct gl_drawable *gl ) -{ - opengl_drawable_add_ref( &gl->base ); - return gl; -} - static void x11drv_surface_destroy( struct opengl_drawable *base ) { struct gl_drawable *gl = impl_from_opengl_drawable( base ); @@ -879,21 +873,6 @@ static BOOL set_swap_interval( struct gl_drawable *gl, int interval ) return ret; }
-static struct gl_drawable *get_gl_drawable( HWND hwnd, HDC hdc ) -{ - struct gl_drawable *gl; - - pthread_mutex_lock( &context_mutex ); - if (hwnd && !XFindContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char **)&gl )) - gl = grab_gl_drawable( gl ); - else if (hdc && !XFindContext( gdi_display, (XID)hdc, gl_pbuffer_context, (char **)&gl )) - gl = grab_gl_drawable( gl ); - else - gl = NULL; - pthread_mutex_unlock( &context_mutex ); - return gl; -} - static GLXContext create_glxcontext( struct x11drv_context *context, int format, GLXContext share, const int *attribs ) { struct glx_pixel_format *fmt = glx_pixel_format_from_format( format ); @@ -1272,26 +1251,13 @@ static void *x11drv_get_proc_address( const char *name ) return pglXGetProcAddressARB( (const GLubyte *)name ); }
-static void set_context_drawables( struct x11drv_context *ctx, struct gl_drawable **draw, - struct gl_drawable **read ) -{ - struct gl_drawable *old_draw, *old_read; - - old_draw = ctx->draw; - old_read = ctx->read; - ctx->draw = *draw; - ctx->read = *read; - *draw = old_draw; - *read = old_read; -} - -static BOOL x11drv_context_make_current( HDC draw_hdc, HDC read_hdc, void *private ) +static BOOL x11drv_make_current( struct opengl_drawable *draw_base, struct opengl_drawable *read_base, void *private ) { + struct gl_drawable *old_draw, *old_read, *draw = impl_from_opengl_drawable( draw_base ), *read = impl_from_opengl_drawable( read_base ); struct x11drv_context *ctx = private; BOOL ret = FALSE; - struct gl_drawable *draw_gl, *read_gl = NULL;
- TRACE("(%p,%p,%p)\n", draw_hdc, read_hdc, ctx); + TRACE( "draw %s, read %s, context %p\n", debugstr_opengl_drawable( draw_base ), debugstr_opengl_drawable( read_base ), private );
if (!private) { @@ -1300,28 +1266,22 @@ static BOOL x11drv_context_make_current( HDC draw_hdc, HDC read_hdc, void *priva return TRUE; }
- if ((draw_gl = get_gl_drawable( NtUserWindowFromDC( draw_hdc ), draw_hdc ))) - { - read_gl = get_gl_drawable( NtUserWindowFromDC( read_hdc ), read_hdc ); + if (!pglXMakeContextCurrent) ret = pglXMakeCurrent( gdi_display, draw->drawable, ctx->ctx ); + else ret = pglXMakeContextCurrent( gdi_display, draw->drawable, read->drawable, ctx->ctx ); + if (!ret) return FALSE;
- pthread_mutex_lock( &context_mutex ); - if (!pglXMakeContextCurrent) ret = pglXMakeCurrent( gdi_display, draw_gl->drawable, ctx->ctx ); - else ret = pglXMakeContextCurrent( gdi_display, draw_gl->drawable, read_gl ? read_gl->drawable : 0, ctx->ctx ); - if (ret) - { - set_context_drawables( ctx, &draw_gl, &read_gl ); - NtCurrentTeb()->glReserved2 = ctx; - pthread_mutex_unlock( &context_mutex ); - goto done; - } - pthread_mutex_unlock( &context_mutex ); - } - RtlSetLastWin32Error( ERROR_INVALID_HANDLE ); -done: - if (read_gl) opengl_drawable_release( &read_gl->base ); - if (draw_gl) opengl_drawable_release( &draw_gl->base ); - TRACE( "%p,%p,%p returning %d\n", draw_hdc, read_hdc, ctx, ret ); - return ret; + pthread_mutex_lock( &context_mutex ); + old_draw = ctx->draw; + old_read = ctx->read; + if ((ctx->draw = draw)) opengl_drawable_add_ref( &draw->base ); + if ((ctx->read = read)) opengl_drawable_add_ref( &read->base ); + pthread_mutex_unlock( &context_mutex ); + + if (old_draw) opengl_drawable_release( &old_draw->base ); + if (old_read) opengl_drawable_release( &old_read->base ); + + NtCurrentTeb()->glReserved2 = ctx; + return TRUE; }
static void present_gl_drawable( struct gl_drawable *gl, BOOL flush, BOOL gl_finish ) @@ -1684,7 +1644,7 @@ static const struct opengl_driver_funcs x11drv_driver_funcs = .p_surface_create = x11drv_surface_create, .p_context_create = x11drv_context_create, .p_context_destroy = x11drv_context_destroy, - .p_context_make_current = x11drv_context_make_current, + .p_make_current = x11drv_make_current, .p_pbuffer_create = x11drv_pbuffer_create, .p_pbuffer_updated = x11drv_pbuffer_updated, .p_pbuffer_bind = x11drv_pbuffer_bind, diff --git a/include/wine/opengl_driver.h b/include/wine/opengl_driver.h index 3fd609e0f27..c319d93ce27 100644 --- a/include/wine/opengl_driver.h +++ b/include/wine/opengl_driver.h @@ -176,7 +176,7 @@ struct opengl_driver_funcs BOOL (*p_surface_create)( HWND hwnd, HDC hdc, 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_context_make_current)(HDC,HDC,void*); + BOOL (*p_make_current)( struct opengl_drawable *draw, struct opengl_drawable *read, void *private ); BOOL (*p_pbuffer_create)( HDC hdc, int format, BOOL largest, GLenum texture_format, GLenum texture_target, GLint max_level, GLsizei *width, GLsizei *height, struct opengl_drawable **drawable ); BOOL (*p_pbuffer_updated)( HDC hdc, struct opengl_drawable *drawable, GLenum cube_face, GLint mipmap_level );