From: Rémi Bernon rbernon@codeweavers.com
--- dlls/win32u/opengl.c | 46 +++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-)
diff --git a/dlls/win32u/opengl.c b/dlls/win32u/opengl.c index fc67e2c4fb0..efeded55245 100644 --- a/dlls/win32u/opengl.c +++ b/dlls/win32u/opengl.c @@ -175,6 +175,7 @@ struct wgl_context };
static struct opengl_funcs osmesa_opengl_funcs; +static const struct opengl_driver_funcs osmesa_driver_funcs;
static OSMesaContext (*pOSMesaCreateContextExt)( GLenum format, GLint depthBits, GLint stencilBits, GLint accumBits, OSMesaContext sharelist ); @@ -184,7 +185,7 @@ static GLboolean (*pOSMesaMakeCurrent)( OSMesaContext ctx, void *buffer, GLenum GLsizei width, GLsizei height ); static void (*pOSMesaPixelStore)( GLint pname, GLint value );
-static struct opengl_funcs *osmesa_get_wgl_driver(void) +static struct opengl_funcs *osmesa_get_wgl_driver( const struct opengl_driver_funcs **driver_funcs ) { static void *osmesa_handle;
@@ -217,6 +218,7 @@ static struct opengl_funcs *osmesa_get_wgl_driver(void) ALL_GL_FUNCS #undef USE_GL_FUNC
+ *driver_funcs = &osmesa_driver_funcs; return &osmesa_opengl_funcs;
failed: @@ -225,6 +227,16 @@ failed: return NULL; }
+static const char *osmesa_init_wgl_extensions(void) +{ + return ""; +} + +static BOOL osmesa_set_pixel_format( HWND hwnd, int old_format, int new_format, BOOL internal ) +{ + return TRUE; +} + static struct wgl_context *osmesa_create_context( HDC hdc, const PIXELFORMATDESCRIPTOR *descr ) { struct wgl_context *context; @@ -386,9 +398,15 @@ static struct opengl_funcs osmesa_opengl_funcs = .p_get_pixel_formats = osmesa_get_pixel_formats, };
+static const struct opengl_driver_funcs osmesa_driver_funcs = +{ + .p_init_wgl_extensions = osmesa_init_wgl_extensions, + .p_set_pixel_format = osmesa_set_pixel_format, +}; + #else /* SONAME_LIBOSMESA */
-static struct opengl_funcs *osmesa_get_wgl_driver(void) +static struct opengl_funcs *osmesa_get_wgl_driver( const struct opengl_driver_funcs **driver_funcs ) { return NULL; } @@ -450,7 +468,9 @@ static const struct opengl_driver_funcs nulldrv_funcs = .p_pbuffer_updated = nulldrv_pbuffer_updated, .p_pbuffer_bind = nulldrv_pbuffer_bind, }; -static const struct opengl_driver_funcs *driver_funcs = &nulldrv_funcs; + +static const struct opengl_driver_funcs *memory_driver_funcs = &nulldrv_funcs; +static const struct opengl_driver_funcs *display_driver_funcs = &nulldrv_funcs; static UINT formats_count, onscreen_count;
static char wgl_extensions[4096]; @@ -517,7 +537,7 @@ static BOOL set_dc_pixel_format( HDC hdc, int new_format, BOOL internal ) TRACE( "%p/%p format %d, internal %u\n", hdc, hwnd, new_format, internal );
if ((old_format = get_window_pixel_format( hwnd )) && !internal) return old_format == new_format; - if (!driver_funcs->p_set_pixel_format( hwnd, old_format, new_format, internal )) return FALSE; + if (!display_driver_funcs->p_set_pixel_format( hwnd, old_format, new_format, internal )) return FALSE; return set_window_pixel_format( hwnd, new_format, internal ); }
@@ -535,12 +555,12 @@ static BOOL win32u_wglSetPixelFormatWINE( HDC hdc, int format ) return set_dc_pixel_format( hdc, format, TRUE ); }
-static void win32u_get_pixel_formats( struct wgl_pixel_format *formats, UINT max_formats, - UINT *num_formats, UINT *num_onscreen_formats ) +static void win32u_display_get_pixel_formats( struct wgl_pixel_format *formats, UINT max_formats, + UINT *num_formats, UINT *num_onscreen_formats ) { UINT i = 0;
- if (formats) while (i < max_formats && driver_funcs->p_describe_pixel_format( i + 1, &formats[i] )) i++; + if (formats) while (i < max_formats && display_driver_funcs->p_describe_pixel_format( i + 1, &formats[i] )) i++; *num_formats = formats_count; *num_onscreen_formats = onscreen_count; } @@ -575,7 +595,7 @@ static struct wgl_pbuffer *win32u_wglCreatePbufferARB( HDC hdc, int format, int return NULL; } NtGdiSetPixelFormat( pbuffer->hdc, format ); - pbuffer->driver_funcs = driver_funcs; + pbuffer->driver_funcs = funcs == memory_funcs ? memory_driver_funcs : display_driver_funcs; pbuffer->funcs = funcs; pbuffer->width = width; pbuffer->height = height; @@ -961,7 +981,7 @@ static BOOL win32u_wglSetPbufferAttribARB( struct wgl_pbuffer *pbuffer, const in
static void memory_funcs_init(void) { - memory_funcs = osmesa_get_wgl_driver(); + memory_funcs = osmesa_get_wgl_driver( &memory_driver_funcs ); if (!memory_funcs) return;
memory_funcs->p_wglGetPixelFormat = win32u_wglGetPixelFormat; @@ -972,18 +992,18 @@ static void display_funcs_init(void) { UINT status;
- if ((status = user_driver->pOpenGLInit( WINE_OPENGL_DRIVER_VERSION, &display_funcs, &driver_funcs )) && + if ((status = user_driver->pOpenGLInit( WINE_OPENGL_DRIVER_VERSION, &display_funcs, &display_driver_funcs )) && status != STATUS_NOT_IMPLEMENTED) { ERR( "Failed to initialize the driver opengl functions, status %#x\n", status ); return; } - if (display_funcs && !(formats_count = driver_funcs->p_init_pixel_formats( &onscreen_count ))) display_funcs = NULL; + if (display_funcs && !(formats_count = display_driver_funcs->p_init_pixel_formats( &onscreen_count ))) display_funcs = NULL; if (!display_funcs) return;
- display_funcs->p_get_pixel_formats = win32u_get_pixel_formats; + display_funcs->p_get_pixel_formats = win32u_display_get_pixel_formats;
- strcpy( wgl_extensions, driver_funcs->p_init_wgl_extensions() ); + strcpy( wgl_extensions, display_driver_funcs->p_init_wgl_extensions() ); display_funcs->p_wglGetPixelFormat = win32u_wglGetPixelFormat; display_funcs->p_wglSetPixelFormat = win32u_wglSetPixelFormat;
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/win32u/opengl.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-)
diff --git a/dlls/win32u/opengl.c b/dlls/win32u/opengl.c index efeded55245..4fad50fadcc 100644 --- a/dlls/win32u/opengl.c +++ b/dlls/win32u/opengl.c @@ -237,35 +237,40 @@ static BOOL osmesa_set_pixel_format( HWND hwnd, int old_format, int new_format, return TRUE; }
-static struct wgl_context *osmesa_create_context( HDC hdc, const PIXELFORMATDESCRIPTOR *descr ) +static struct wgl_context *osmesa_create_context( HDC hdc, int format ) { + PIXELFORMATDESCRIPTOR descr; struct wgl_context *context; UINT gl_format;
- switch (descr->cColorBits) + describe_pixel_format( format, &descr ); + + switch (descr.cColorBits) { case 32: - if (descr->cRedShift == 8) gl_format = OSMESA_ARGB; - else if (descr->cRedShift == 16) gl_format = OSMESA_BGRA; + if (descr.cRedShift == 8) gl_format = OSMESA_ARGB; + else if (descr.cRedShift == 16) gl_format = OSMESA_BGRA; else gl_format = OSMESA_RGBA; break; case 24: - gl_format = descr->cRedShift == 16 ? OSMESA_BGR : OSMESA_RGB; + gl_format = descr.cRedShift == 16 ? OSMESA_BGR : OSMESA_RGB; break; case 16: gl_format = OSMESA_RGB_565; break; default: - return NULL; + return FALSE; } - if (!(context = malloc( sizeof(*context) ))) return NULL; + + if (!(context = malloc( sizeof(*context) ))) return FALSE; context->format = gl_format; - if (!(context->context = pOSMesaCreateContextExt( gl_format, descr->cDepthBits, descr->cStencilBits, - descr->cAccumBits, 0 ))) + if (!(context->context = pOSMesaCreateContextExt( gl_format, descr.cDepthBits, descr.cStencilBits, + descr.cAccumBits, 0 ))) { free( context ); - return NULL; + return FALSE; } + return context; }
@@ -324,7 +329,7 @@ static struct wgl_context *osmesa_wglCreateContext( HDC hdc ) if (!(format = funcs->p_wglGetPixelFormat( hdc ))) format = 1; describe_pixel_format( format, &descr );
- return osmesa_create_context( hdc, &descr ); + return osmesa_create_context( hdc, format ); }
static PROC osmesa_wglGetProcAddress( const char *proc )
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/opengl32/tests/opengl.c | 4 +- dlls/win32u/opengl.c | 256 ++++++++++++++++++++++++++--------- include/wine/opengl_driver.h | 6 +- 3 files changed, 198 insertions(+), 68 deletions(-)
diff --git a/dlls/opengl32/tests/opengl.c b/dlls/opengl32/tests/opengl.c index 868cb41ee70..deecc5c67e8 100644 --- a/dlls/opengl32/tests/opengl.c +++ b/dlls/opengl32/tests/opengl.c @@ -1409,7 +1409,7 @@ static void test_bitmap_rendering( BOOL use_dib ) /* cannot create a GL context without a pixel format */
hglrc = wglCreateContext( hdc ); - todo_wine ok( !hglrc, "wglCreateContext succeeded\n" ); + ok( !hglrc, "wglCreateContext succeeded\n" ); if (hglrc) wglDeleteContext( hglrc );
/* cannot set pixel format twice */ @@ -1695,7 +1695,7 @@ static void test_d3dkmt_rendering(void) /* cannot create a GL context without a pixel format */
hglrc = wglCreateContext( desc.hDc ); - todo_wine ok( !hglrc, "wglCreateContext succeeded\n" ); + ok( !hglrc, "wglCreateContext succeeded\n" ); if (hglrc) wglDeleteContext( hglrc );
/* cannot set pixel format twice */ diff --git a/dlls/win32u/opengl.c b/dlls/win32u/opengl.c index 4fad50fadcc..35665b25add 100644 --- a/dlls/win32u/opengl.c +++ b/dlls/win32u/opengl.c @@ -39,6 +39,13 @@
WINE_DEFAULT_DEBUG_CHANNEL(wgl);
+struct wgl_context +{ + const struct opengl_driver_funcs *driver_funcs; + struct opengl_funcs *funcs; + void *driver_private; +}; + struct wgl_pbuffer { const struct opengl_driver_funcs *driver_funcs; @@ -168,7 +175,7 @@ static void register_extension( char *list, size_t size, const char *name )
typedef struct osmesa_context *OSMesaContext;
-struct wgl_context +struct osmesa_context { OSMesaContext context; UINT format; @@ -184,6 +191,7 @@ static void * (*pOSMesaGetProcAddress)( const char *funcName ); static GLboolean (*pOSMesaMakeCurrent)( OSMesaContext ctx, void *buffer, GLenum type, GLsizei width, GLsizei height ); static void (*pOSMesaPixelStore)( GLint pname, GLint value ); +static void describe_pixel_format( int fmt, PIXELFORMATDESCRIPTOR *descr );
static struct opengl_funcs *osmesa_get_wgl_driver( const struct opengl_driver_funcs **driver_funcs ) { @@ -237,12 +245,18 @@ static BOOL osmesa_set_pixel_format( HWND hwnd, int old_format, int new_format, return TRUE; }
-static struct wgl_context *osmesa_create_context( HDC hdc, int format ) +static BOOL osmesa_context_create( HDC hdc, int format, void *shared, const int *attribs, void **private ) { + struct osmesa_context *context; PIXELFORMATDESCRIPTOR descr; - struct wgl_context *context; UINT gl_format;
+ if (attribs) + { + ERR( "attribs not supported\n" ); + return FALSE; + } + describe_pixel_format( format, &descr );
switch (descr.cColorBits) @@ -271,11 +285,13 @@ static struct wgl_context *osmesa_create_context( HDC hdc, int format ) return FALSE; }
- return context; + *private = context; + return TRUE; }
-static BOOL osmesa_delete_context( struct wgl_context *context ) +static BOOL osmesa_context_destroy( void *private ) { + struct osmesa_context *context = private; pOSMesaDestroyContext( context->context ); free( context ); return TRUE; @@ -286,68 +302,50 @@ static PROC osmesa_get_proc_address( const char *proc ) return (PROC)pOSMesaGetProcAddress( proc ); }
-static BOOL osmesa_make_current( struct wgl_context *context, void *bits, - int width, int height, int bpp, int stride ) -{ - BOOL ret; - GLenum type; - - if (!context) - { - pOSMesaMakeCurrent( NULL, NULL, GL_UNSIGNED_BYTE, 0, 0 ); - return TRUE; - } - - type = context->format == OSMESA_RGB_565 ? GL_UNSIGNED_SHORT_5_6_5 : GL_UNSIGNED_BYTE; - ret = pOSMesaMakeCurrent( context->context, bits, type, width, height ); - if (ret) - { - pOSMesaPixelStore( OSMESA_ROW_LENGTH, abs( stride ) * 8 / bpp ); - pOSMesaPixelStore( OSMESA_Y_UP, 1 ); /* Windows seems to assume bottom-up */ - } - return ret; -} - -static BOOL osmesa_wglCopyContext( struct wgl_context *src, struct wgl_context *dst, UINT mask ) +static PROC osmesa_wglGetProcAddress( const char *proc ) { - FIXME( "not supported yet\n" ); - return FALSE; + if (!strncmp( proc, "wgl", 3 )) return NULL; + return osmesa_get_proc_address( proc ); }
-static BOOL osmesa_wglDeleteContext( struct wgl_context *context ) +static BOOL osmesa_wglSwapBuffers( HDC hdc ) { - return osmesa_delete_context( context ); + return TRUE; }
-static struct wgl_context *osmesa_wglCreateContext( HDC hdc ) +static BOOL osmesa_context_copy( void *src_private, void *dst_private, UINT mask ) { - PIXELFORMATDESCRIPTOR descr; - struct opengl_funcs *funcs; - int format; - - if (!(funcs = get_dc_funcs( hdc, NULL ))) return NULL; - if (!(format = funcs->p_wglGetPixelFormat( hdc ))) format = 1; - describe_pixel_format( format, &descr ); - - return osmesa_create_context( hdc, format ); + FIXME( "not supported yet\n" ); + return FALSE; }
-static PROC osmesa_wglGetProcAddress( const char *proc ) +static BOOL osmesa_context_share( void *src_private, void *dst_private ) { - if (!strncmp( proc, "wgl", 3 )) return NULL; - return osmesa_get_proc_address( proc ); + FIXME( "not supported yet\n" ); + return FALSE; }
-static BOOL osmesa_wglMakeCurrent( HDC hdc, struct wgl_context *context ) +static BOOL osmesa_context_make_current( HDC draw_hdc, HDC read_hdc, void *private ) { + struct osmesa_context *context = private; HBITMAP bitmap; BITMAPOBJ *bmp; dib_info dib; BOOL ret = FALSE;
- if (!context) return osmesa_make_current( NULL, NULL, 0, 0, 0, 0 ); + if (!private) + { + pOSMesaMakeCurrent( NULL, NULL, GL_UNSIGNED_BYTE, 0, 0 ); + return TRUE; + } + + if (draw_hdc != read_hdc) + { + ERR( "read != draw not supported\n" ); + return FALSE; + }
- bitmap = NtGdiGetDCObject( hdc, NTGDI_OBJ_SURF ); + bitmap = NtGdiGetDCObject( draw_hdc, NTGDI_OBJ_SURF ); bmp = GDI_GetObjPtr( bitmap, NTGDI_OBJ_BITMAP ); if (!bmp) return FALSE;
@@ -356,6 +354,7 @@ static BOOL osmesa_wglMakeCurrent( HDC hdc, struct wgl_context *context ) char *bits; int width = dib.rect.right - dib.rect.left; int height = dib.rect.bottom - dib.rect.top; + GLenum type;
if (dib.stride < 0) bits = (char *)dib.bits.ptr + (dib.rect.bottom - 1) * dib.stride; else bits = (char *)dib.bits.ptr + dib.rect.top * dib.stride; @@ -363,23 +362,18 @@ static BOOL osmesa_wglMakeCurrent( HDC hdc, struct wgl_context *context )
TRACE( "context %p bits %p size %ux%u\n", context, bits, width, height );
- ret = osmesa_make_current( context, bits, width, height, dib.bit_count, dib.stride ); + type = context->format == OSMESA_RGB_565 ? GL_UNSIGNED_SHORT_5_6_5 : GL_UNSIGNED_BYTE; + ret = pOSMesaMakeCurrent( context->context, bits, type, width, height ); + if (ret) + { + pOSMesaPixelStore( OSMESA_ROW_LENGTH, abs( dib.stride ) * 8 / dib.bit_count ); + pOSMesaPixelStore( OSMESA_Y_UP, 1 ); /* Windows seems to assume bottom-up */ + } } GDI_ReleaseObj( bitmap ); return ret; }
-static BOOL osmesa_wglShareLists( struct wgl_context *org, struct wgl_context *dest ) -{ - FIXME( "not supported yet\n" ); - return FALSE; -} - -static BOOL osmesa_wglSwapBuffers( HDC hdc ) -{ - return TRUE; -} - static void osmesa_get_pixel_formats( struct wgl_pixel_format *formats, UINT max_formats, UINT *num_formats, UINT *num_onscreen_formats ) { @@ -393,12 +387,7 @@ static void osmesa_get_pixel_formats( struct wgl_pixel_format *formats, UINT max
static struct opengl_funcs osmesa_opengl_funcs = { - .p_wglCopyContext = osmesa_wglCopyContext, - .p_wglCreateContext = osmesa_wglCreateContext, - .p_wglDeleteContext = osmesa_wglDeleteContext, .p_wglGetProcAddress = osmesa_wglGetProcAddress, - .p_wglMakeCurrent = osmesa_wglMakeCurrent, - .p_wglShareLists = osmesa_wglShareLists, .p_wglSwapBuffers = osmesa_wglSwapBuffers, .p_get_pixel_formats = osmesa_get_pixel_formats, }; @@ -407,6 +396,11 @@ static const struct opengl_driver_funcs osmesa_driver_funcs = { .p_init_wgl_extensions = osmesa_init_wgl_extensions, .p_set_pixel_format = osmesa_set_pixel_format, + .p_context_create = osmesa_context_create, + .p_context_destroy = osmesa_context_destroy, + .p_context_copy = osmesa_context_copy, + .p_context_share = osmesa_context_share, + .p_context_make_current = osmesa_context_make_current, };
#else /* SONAME_LIBOSMESA */ @@ -570,6 +564,114 @@ static void win32u_display_get_pixel_formats( struct wgl_pixel_format *formats, *num_onscreen_formats = onscreen_count; }
+static struct wgl_context *context_create( HDC hdc, struct wgl_context *shared, const int *attribs ) +{ + void *shared_private = shared ? shared->driver_private : NULL; + const struct opengl_driver_funcs *driver_funcs; + struct wgl_context *context; + struct opengl_funcs *funcs; + int format; + + TRACE( "hdc %p, shared %p, attribs %p\n", hdc, shared, attribs ); + + if (!(format = win32u_wglGetPixelFormat( hdc ))) + { + RtlSetLastWin32Error( ERROR_INVALID_PIXEL_FORMAT ); + return NULL; + } + + if (!(funcs = get_dc_funcs( hdc, NULL ))) return NULL; + driver_funcs = funcs == display_funcs ? display_driver_funcs : memory_driver_funcs; + + if (!(context = calloc( 1, sizeof(*context) ))) return NULL; + context->driver_funcs = driver_funcs; + context->funcs = funcs; + + if (!driver_funcs->p_context_create( hdc, format, shared_private, attribs, &context->driver_private )) + { + free( context ); + return NULL; + } + + TRACE( "created context %p for driver context %p\n", context, context->driver_private ); + return context; +} + +static struct wgl_context *win32u_wglCreateContextAttribsARB( HDC hdc, struct wgl_context *shared, const int *attribs ) +{ + static const int empty_attribs = {0}; + + TRACE( "hdc %p, shared %p, attribs %p\n", hdc, shared, attribs ); + + if (!attribs) attribs = &empty_attribs; + return context_create( hdc, shared, attribs ); +} + +static struct wgl_context *win32u_wglCreateContext( HDC hdc ) +{ + TRACE( "hdc %p\n", hdc ); + return context_create( hdc, NULL, NULL ); +} + +static BOOL win32u_wglDeleteContext( struct wgl_context *context ) +{ + const struct opengl_driver_funcs *funcs = context->driver_funcs; + BOOL ret; + + TRACE( "context %p\n", context ); + + ret = funcs->p_context_destroy( context->driver_private ); + free( context ); + + return ret; +} + +static BOOL win32u_wglCopyContext( struct wgl_context *src, struct wgl_context *dst, UINT mask ) +{ + const struct opengl_driver_funcs *funcs = src->driver_funcs; + + TRACE( "src %p, dst %p, mask %#x\n", src, dst, mask ); + + if (funcs != dst->driver_funcs) return FALSE; + return funcs->p_context_copy( src->driver_private, dst->driver_private, mask ); +} + +static BOOL win32u_wglShareLists( struct wgl_context *src, struct wgl_context *dst ) +{ + const struct opengl_driver_funcs *funcs = src->driver_funcs; + + TRACE( "src %p, dst %p\n", src, dst ); + + if (funcs != dst->driver_funcs) return FALSE; + 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 ) +{ + const struct opengl_driver_funcs *funcs; + + TRACE( "draw_hdc %p, read_hdc %p, context %p\n", draw_hdc, read_hdc, context ); + + if (!context) + { + if (!(context = NtCurrentTeb()->glContext)) return TRUE; + funcs = context->driver_funcs; + if (!funcs->p_context_make_current( NULL, NULL, NULL )) return FALSE; + NtCurrentTeb()->glContext = NULL; + return TRUE; + } + + funcs = context->driver_funcs; + if (!funcs->p_context_make_current( draw_hdc, read_hdc, context->driver_private )) return FALSE; + NtCurrentTeb()->glContext = context; + return TRUE; +} + +static BOOL win32u_wglMakeCurrent( HDC hdc, struct wgl_context *context ) +{ + return win32u_wglMakeContextCurrentARB( hdc, hdc, context ); +} + static struct wgl_pbuffer *win32u_wglCreatePbufferARB( HDC hdc, int format, int width, int height, const int *attribs ) { @@ -991,6 +1093,12 @@ static void memory_funcs_init(void)
memory_funcs->p_wglGetPixelFormat = win32u_wglGetPixelFormat; memory_funcs->p_wglSetPixelFormat = win32u_wglSetPixelFormat; + + memory_funcs->p_wglCreateContext = win32u_wglCreateContext; + memory_funcs->p_wglDeleteContext = win32u_wglDeleteContext; + memory_funcs->p_wglCopyContext = win32u_wglCopyContext; + memory_funcs->p_wglShareLists = win32u_wglShareLists; + memory_funcs->p_wglMakeCurrent = win32u_wglMakeCurrent; }
static void display_funcs_init(void) @@ -1029,6 +1137,24 @@ static void display_funcs_init(void) display_funcs->p_wglGetPixelFormatAttribfvARB = (void *)1; /* never called */ display_funcs->p_wglGetPixelFormatAttribivARB = (void *)1; /* never called */
+ if (display_driver_funcs->p_context_create) + { + display_funcs->p_wglCreateContext = win32u_wglCreateContext; + display_funcs->p_wglDeleteContext = win32u_wglDeleteContext; + display_funcs->p_wglCopyContext = win32u_wglCopyContext; + display_funcs->p_wglShareLists = win32u_wglShareLists; + display_funcs->p_wglMakeCurrent = win32u_wglMakeCurrent; + + register_extension( wgl_extensions, ARRAY_SIZE(wgl_extensions), "WGL_ARB_create_context" ); + register_extension( wgl_extensions, ARRAY_SIZE(wgl_extensions), "WGL_ARB_create_context_no_error" ); + register_extension( wgl_extensions, ARRAY_SIZE(wgl_extensions), "WGL_ARB_create_context_profile" ); + display_funcs->p_wglCreateContextAttribsARB = win32u_wglCreateContextAttribsARB; + + register_extension( wgl_extensions, ARRAY_SIZE(wgl_extensions), "WGL_ARB_make_current_read" ); + display_funcs->p_wglGetCurrentReadDCARB = (void *)1; /* never called */ + display_funcs->p_wglMakeContextCurrentARB = win32u_wglMakeContextCurrentARB; + } + register_extension( wgl_extensions, ARRAY_SIZE(wgl_extensions), "WGL_ARB_pbuffer" ); display_funcs->p_wglCreatePbufferARB = win32u_wglCreatePbufferARB; display_funcs->p_wglDestroyPbufferARB = win32u_wglDestroyPbufferARB; diff --git a/include/wine/opengl_driver.h b/include/wine/opengl_driver.h index 1d78ac09b1c..2a760e98020 100644 --- a/include/wine/opengl_driver.h +++ b/include/wine/opengl_driver.h @@ -117,7 +117,11 @@ struct opengl_driver_funcs BOOL (*p_describe_pixel_format)(int,struct wgl_pixel_format*); const char *(*p_init_wgl_extensions)(void); BOOL (*p_set_pixel_format)(HWND,int,int,BOOL); - + BOOL (*p_context_create)(HDC,int,void*,const int*,void**); + BOOL (*p_context_destroy)(void*); + BOOL (*p_context_copy)(void*,void*,UINT); + BOOL (*p_context_share)(void*,void*); + BOOL (*p_context_make_current)(HDC,HDC,void*); BOOL (*p_pbuffer_create)(HDC,int,BOOL,GLenum,GLenum,GLint,GLsizei*,GLsizei*,void **); BOOL (*p_pbuffer_destroy)(HDC,void*); BOOL (*p_pbuffer_updated)(HDC,void*,GLenum,GLint);
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/win32u/opengl.c | 40 ++++++++++++++++++++++++++++++------ dlls/win32u/win32u_private.h | 2 +- dlls/win32u/window.c | 4 ++-- 3 files changed, 37 insertions(+), 9 deletions(-)
diff --git a/dlls/win32u/opengl.c b/dlls/win32u/opengl.c index 35665b25add..291dc28eba9 100644 --- a/dlls/win32u/opengl.c +++ b/dlls/win32u/opengl.c @@ -44,6 +44,7 @@ struct wgl_context const struct opengl_driver_funcs *driver_funcs; struct opengl_funcs *funcs; void *driver_private; + int pixel_format; };
struct wgl_pbuffer @@ -489,14 +490,14 @@ static const char *win32u_wglGetExtensionsStringEXT(void) static struct opengl_funcs *display_funcs; static struct opengl_funcs *memory_funcs;
-static int win32u_wglGetPixelFormat( HDC hdc ) +static int get_dc_pixel_format( HDC hdc, BOOL internal ) { int ret = 0; HWND hwnd; DC *dc;
if ((hwnd = NtUserWindowFromDC( hdc ))) - ret = get_window_pixel_format( hwnd ); + ret = get_window_pixel_format( hwnd, internal ); else if ((dc = get_dc_ptr( hdc ))) { BOOL is_display = dc->is_display; @@ -508,11 +509,23 @@ static int win32u_wglGetPixelFormat( HDC hdc ) */ if (is_display && ret >= 0 && ret > onscreen_count) ret = 1; } + else + { + WARN( "Invalid DC handle %p\n", hdc ); + RtlSetLastWin32Error( ERROR_INVALID_HANDLE ); + return -1; + }
TRACE( "%p/%p -> %d\n", hdc, hwnd, ret ); return ret; }
+static int win32u_wglGetPixelFormat( HDC hdc ) +{ + int format = get_dc_pixel_format( hdc, FALSE ); + return format > 0 ? format : 0; +} + static BOOL set_dc_pixel_format( HDC hdc, int new_format, BOOL internal ) { struct opengl_funcs *funcs; @@ -535,7 +548,7 @@ static BOOL set_dc_pixel_format( HDC hdc, int new_format, BOOL internal )
TRACE( "%p/%p format %d, internal %u\n", hdc, hwnd, new_format, internal );
- if ((old_format = get_window_pixel_format( hwnd )) && !internal) return old_format == new_format; + if ((old_format = get_window_pixel_format( hwnd, FALSE )) && !internal) return old_format == new_format; if (!display_driver_funcs->p_set_pixel_format( hwnd, old_format, new_format, internal )) return FALSE; return set_window_pixel_format( hwnd, new_format, internal ); } @@ -574,9 +587,9 @@ static struct wgl_context *context_create( HDC hdc, struct wgl_context *shared,
TRACE( "hdc %p, shared %p, attribs %p\n", hdc, shared, attribs );
- if (!(format = win32u_wglGetPixelFormat( hdc ))) + if ((format = get_dc_pixel_format( hdc, TRUE )) <= 0) { - RtlSetLastWin32Error( ERROR_INVALID_PIXEL_FORMAT ); + if (!format) RtlSetLastWin32Error( ERROR_INVALID_PIXEL_FORMAT ); return NULL; }
@@ -586,6 +599,7 @@ static struct wgl_context *context_create( HDC hdc, struct wgl_context *shared, if (!(context = calloc( 1, sizeof(*context) ))) return NULL; context->driver_funcs = driver_funcs; context->funcs = funcs; + context->pixel_format = format;
if (!driver_funcs->p_context_create( hdc, format, shared_private, attribs, &context->driver_private )) { @@ -593,7 +607,7 @@ static struct wgl_context *context_create( HDC hdc, struct wgl_context *shared, return NULL; }
- TRACE( "created context %p for driver context %p\n", context, context->driver_private ); + TRACE( "created context %p, format %u for driver context %p\n", context, format, context->driver_private ); return context; }
@@ -649,6 +663,7 @@ static BOOL win32u_wglShareLists( struct wgl_context *src, struct wgl_context *d static BOOL win32u_wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, struct wgl_context *context ) { const struct opengl_driver_funcs *funcs; + int format;
TRACE( "draw_hdc %p, read_hdc %p, context %p\n", draw_hdc, read_hdc, context );
@@ -661,6 +676,19 @@ static BOOL win32u_wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, struct return TRUE; }
+ if ((format = get_dc_pixel_format( draw_hdc, TRUE )) <= 0) + { + WARN( "Invalid draw_hdc %p format %u\n", draw_hdc, format ); + if (!format) RtlSetLastWin32Error( ERROR_INVALID_PIXEL_FORMAT ); + return FALSE; + } + if (context->pixel_format != format) + { + WARN( "Mismatched draw_hdc %p format %u, context %p format %u\n", draw_hdc, format, context, context->pixel_format ); + RtlSetLastWin32Error( ERROR_INVALID_PIXEL_FORMAT ); + return FALSE; + } + funcs = context->driver_funcs; if (!funcs->p_context_make_current( draw_hdc, read_hdc, context->driver_private )) return FALSE; NtCurrentTeb()->glContext = context; diff --git a/dlls/win32u/win32u_private.h b/dlls/win32u/win32u_private.h index 1af1df67c88..80ca1058d97 100644 --- a/dlls/win32u/win32u_private.h +++ b/dlls/win32u/win32u_private.h @@ -249,7 +249,7 @@ extern BOOL is_window_unicode( HWND hwnd ); extern BOOL is_window_visible( HWND hwnd ); extern BOOL is_zoomed( HWND hwnd ); extern BOOL set_window_pixel_format( HWND hwnd, int format, BOOL internal ); -extern int get_window_pixel_format( HWND hwnd ); +extern int get_window_pixel_format( HWND hwnd, BOOL internal ); extern DWORD get_window_long( HWND hwnd, INT offset ); extern ULONG_PTR get_window_long_ptr( HWND hwnd, INT offset, BOOL ansi ); extern BOOL get_window_rect( HWND hwnd, RECT *rect, UINT dpi ); diff --git a/dlls/win32u/window.c b/dlls/win32u/window.c index 15145667ce1..e4ca25a9521 100644 --- a/dlls/win32u/window.c +++ b/dlls/win32u/window.c @@ -1476,7 +1476,7 @@ BOOL set_window_pixel_format( HWND hwnd, int format, BOOL internal ) return TRUE; }
-int get_window_pixel_format( HWND hwnd ) +int get_window_pixel_format( HWND hwnd, BOOL internal ) { WND *win = get_win_ptr( hwnd ); int ret; @@ -1487,7 +1487,7 @@ int get_window_pixel_format( HWND hwnd ) return 0; }
- ret = win->pixel_format; + ret = internal && win->internal_pixel_format ? win->internal_pixel_format : win->pixel_format; release_win_ptr( win );
return ret;
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/wineandroid.drv/opengl.c | 199 +++++++++++----------------------- 1 file changed, 63 insertions(+), 136 deletions(-)
diff --git a/dlls/wineandroid.drv/opengl.c b/dlls/wineandroid.drv/opengl.c index 9b48b9d3ba0..6a83b9b93ca 100644 --- a/dlls/wineandroid.drv/opengl.c +++ b/dlls/wineandroid.drv/opengl.c @@ -72,7 +72,7 @@ struct egl_pixel_format EGLConfig config; };
-struct wgl_context +struct android_context { struct list entry; EGLConfig config; @@ -163,7 +163,7 @@ void destroy_gl_drawable( HWND hwnd ) pthread_mutex_unlock( &drawable_mutex ); }
-static BOOL refresh_context( struct wgl_context *ctx ) +static BOOL refresh_context( struct android_context *ctx ) { BOOL ret = InterlockedExchange( &ctx->refresh, FALSE );
@@ -179,19 +179,19 @@ static BOOL refresh_context( struct wgl_context *ctx ) void update_gl_drawable( HWND hwnd ) { struct gl_drawable *gl; - struct wgl_context *ctx; + struct android_context *ctx;
if ((gl = get_gl_drawable( hwnd, 0 ))) { if (!gl->surface && (gl->surface = p_eglCreateWindowSurface( display, pixel_formats[gl->format - 1].config, gl->window, NULL ))) { - LIST_FOR_EACH_ENTRY( ctx, &gl_contexts, struct wgl_context, entry ) + LIST_FOR_EACH_ENTRY( ctx, &gl_contexts, struct android_context, entry ) { if (ctx->hwnd != hwnd) continue; - TRACE( "hwnd %p refreshing %p %scurrent\n", hwnd, ctx, NtCurrentTeb()->glContext == ctx ? "" : "not " ); + TRACE( "hwnd %p refreshing %p %scurrent\n", hwnd, ctx, NtCurrentTeb()->glReserved2 == ctx ? "" : "not " ); ctx->surface = gl->surface; - if (NtCurrentTeb()->glContext == ctx) + if (NtCurrentTeb()->glReserved2 == ctx) p_eglMakeCurrent( display, ctx->surface, ctx->surface, ctx->context ); else InterlockedExchange( &ctx->refresh, TRUE ); @@ -224,24 +224,54 @@ static BOOL android_set_pixel_format( HWND hwnd, int old_format, int new_format, return TRUE; }
-static struct wgl_context *create_context( HDC hdc, struct wgl_context *share, const int *attribs ) +static BOOL android_context_create( HDC hdc, int format, void *share, const int *attribs, void **private ) { - struct gl_drawable *gl; - struct wgl_context *ctx; + struct android_context *ctx, *shared_ctx = share; + int count = 0, egl_attribs[3]; + BOOL opengl_es = FALSE;
- if (!(gl = get_gl_drawable( NtUserWindowFromDC( hdc ), hdc ))) return NULL; + if (!attribs) opengl_es = TRUE; + while (attribs && *attribs && count < 2) + { + switch (*attribs) + { + case WGL_CONTEXT_PROFILE_MASK_ARB: + if (attribs[1] == WGL_CONTEXT_ES2_PROFILE_BIT_EXT) + opengl_es = TRUE; + break; + case WGL_CONTEXT_MAJOR_VERSION_ARB: + egl_attribs[count++] = EGL_CONTEXT_CLIENT_VERSION; + egl_attribs[count++] = attribs[1]; + break; + default: + FIXME("Unhandled attributes: %#x %#x\n", attribs[0], attribs[1]); + } + attribs += 2; + } + if (!opengl_es) + { + WARN("Requested creation of an OpenGL (non ES) context, that's not supported.\n"); + return FALSE; + } + if (!count) /* FIXME: force version if not specified */ + { + egl_attribs[count++] = EGL_CONTEXT_CLIENT_VERSION; + egl_attribs[count++] = egl_client_version; + } + egl_attribs[count] = EGL_NONE; + attribs = egl_attribs;
ctx = malloc( sizeof(*ctx) );
- ctx->config = pixel_formats[gl->format - 1].config; + ctx->config = pixel_formats[format - 1].config; ctx->surface = 0; ctx->refresh = FALSE; - ctx->context = p_eglCreateContext( display, ctx->config, - share ? share->context : EGL_NO_CONTEXT, attribs ); - TRACE( "%p fmt %d ctx %p\n", hdc, gl->format, ctx->context ); + ctx->context = p_eglCreateContext( display, ctx->config, shared_ctx ? shared_ctx->context : EGL_NO_CONTEXT, attribs ); + TRACE( "%p fmt %d ctx %p\n", hdc, format, ctx->context ); list_add_head( &gl_contexts, &ctx->entry ); - release_gl_drawable( gl ); - return ctx; + + *private = ctx; + return TRUE; }
static BOOL android_describe_pixel_format( int format, struct wgl_pixel_format *desc ) @@ -282,52 +312,9 @@ static BOOL android_describe_pixel_format( int format, struct wgl_pixel_format * return TRUE; }
-/*********************************************************************** - * android_wglCreateContextAttribsARB - */ -static struct wgl_context *android_wglCreateContextAttribsARB( HDC hdc, struct wgl_context *share, - const int *attribs ) -{ - int count = 0, egl_attribs[3]; - BOOL opengl_es = FALSE; - - while (attribs && *attribs && count < 2) - { - switch (*attribs) - { - case WGL_CONTEXT_PROFILE_MASK_ARB: - if (attribs[1] == WGL_CONTEXT_ES2_PROFILE_BIT_EXT) - opengl_es = TRUE; - break; - case WGL_CONTEXT_MAJOR_VERSION_ARB: - egl_attribs[count++] = EGL_CONTEXT_CLIENT_VERSION; - egl_attribs[count++] = attribs[1]; - break; - default: - FIXME("Unhandled attributes: %#x %#x\n", attribs[0], attribs[1]); - } - attribs += 2; - } - if (!opengl_es) - { - WARN("Requested creation of an OpenGL (non ES) context, that's not supported.\n"); - return NULL; - } - if (!count) /* FIXME: force version if not specified */ - { - egl_attribs[count++] = EGL_CONTEXT_CLIENT_VERSION; - egl_attribs[count++] = egl_client_version; - } - egl_attribs[count] = EGL_NONE; - - return create_context( hdc, share, egl_attribs ); -} - -/*********************************************************************** - * android_wglMakeContextCurrentARB - */ -static BOOL android_wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, struct wgl_context *ctx ) +static BOOL android_context_make_current( HDC draw_hdc, HDC read_hdc, void *private ) { + struct android_context *ctx = private; BOOL ret = FALSE; struct gl_drawable *draw_gl, *read_gl = NULL; EGLSurface draw_surface, read_surface; @@ -335,10 +322,10 @@ static BOOL android_wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, struct
TRACE( "%p %p %p\n", draw_hdc, read_hdc, ctx );
- if (!ctx) + if (!private) { p_eglMakeCurrent( display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ); - NtCurrentTeb()->glContext = NULL; + NtCurrentTeb()->glReserved2 = NULL; return TRUE; }
@@ -356,7 +343,7 @@ static BOOL android_wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, struct ctx->surface = draw_gl->surface; ctx->hwnd = draw_hwnd; ctx->refresh = FALSE; - NtCurrentTeb()->glContext = ctx; + NtCurrentTeb()->glReserved2 = ctx; goto done; } } @@ -404,27 +391,18 @@ static int android_wglGetSwapIntervalEXT(void) /*********************************************************************** * android_wglCopyContext */ -static BOOL android_wglCopyContext( struct wgl_context *src, struct wgl_context *dst, UINT mask ) +static BOOL android_context_copy( void *src, void *dst, UINT mask ) { FIXME( "%p -> %p mask %#x unsupported\n", src, dst, mask ); return FALSE; }
-/*********************************************************************** - * android_wglCreateContext - */ -static struct wgl_context *android_wglCreateContext( HDC hdc ) -{ - int egl_attribs[3] = { EGL_CONTEXT_CLIENT_VERSION, egl_client_version, EGL_NONE }; - - return create_context( hdc, NULL, egl_attribs ); -} - /*********************************************************************** * android_wglDeleteContext */ -static BOOL android_wglDeleteContext( struct wgl_context *ctx ) +static BOOL android_context_destroy( void *private ) { + struct android_context *ctx = private; pthread_mutex_lock( &drawable_mutex ); list_remove( &ctx->entry ); pthread_mutex_unlock( &drawable_mutex ); @@ -445,50 +423,7 @@ static PROC android_wglGetProcAddress( LPCSTR name ) return ret; }
-/*********************************************************************** - * android_wglMakeCurrent - */ -static BOOL android_wglMakeCurrent( HDC hdc, struct wgl_context *ctx ) -{ - BOOL ret = FALSE; - struct gl_drawable *gl; - HWND hwnd; - - TRACE( "%p %p\n", hdc, ctx ); - - if (!ctx) - { - p_eglMakeCurrent( display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ); - NtCurrentTeb()->glContext = NULL; - return TRUE; - } - - hwnd = NtUserWindowFromDC( hdc ); - if ((gl = get_gl_drawable( hwnd, hdc ))) - { - EGLSurface surface = gl->surface ? gl->surface : gl->pbuffer; - TRACE( "%p hwnd %p context %p surface %p\n", hdc, gl->hwnd, ctx->context, surface ); - ret = p_eglMakeCurrent( display, surface, surface, ctx->context ); - if (ret) - { - ctx->surface = gl->surface; - ctx->hwnd = hwnd; - ctx->refresh = FALSE; - NtCurrentTeb()->glContext = ctx; - goto done; - } - } - RtlSetLastWin32Error( ERROR_INVALID_HANDLE ); - -done: - release_gl_drawable( gl ); - return ret; -} - -/*********************************************************************** - * android_wglShareLists - */ -static BOOL android_wglShareLists( struct wgl_context *org, struct wgl_context *dest ) +static BOOL android_context_share( void *org, void *dest ) { FIXME( "%p %p\n", org, dest ); return FALSE; @@ -499,7 +434,7 @@ static BOOL android_wglShareLists( struct wgl_context *org, struct wgl_context * */ static BOOL android_wglSwapBuffers( HDC hdc ) { - struct wgl_context *ctx = NtCurrentTeb()->glContext; + struct android_context *ctx = NtCurrentTeb()->glReserved2;
if (!ctx) return FALSE;
@@ -512,7 +447,7 @@ static BOOL android_wglSwapBuffers( HDC hdc )
static void wglFinish(void) { - struct wgl_context *ctx = NtCurrentTeb()->glContext; + struct android_context *ctx = NtCurrentTeb()->glReserved2;
if (!ctx) return; TRACE( "hwnd %p context %p\n", ctx->hwnd, ctx->context ); @@ -522,7 +457,7 @@ static void wglFinish(void)
static void wglFlush(void) { - struct wgl_context *ctx = NtCurrentTeb()->glContext; + struct android_context *ctx = NtCurrentTeb()->glReserved2;
if (!ctx) return; TRACE( "hwnd %p context %p\n", ctx->hwnd, ctx->context ); @@ -539,14 +474,6 @@ static void register_extension( const char *ext )
static const char *android_init_wgl_extensions(void) { - register_extension("WGL_ARB_create_context"); - register_extension("WGL_ARB_create_context_profile"); - egl_funcs.p_wglCreateContextAttribsARB = android_wglCreateContextAttribsARB; - - register_extension("WGL_ARB_make_current_read"); - egl_funcs.p_wglGetCurrentReadDCARB = (void *)1; /* never called */ - egl_funcs.p_wglMakeContextCurrentARB = android_wglMakeContextCurrentARB; - register_extension("WGL_EXT_swap_control"); egl_funcs.p_wglSwapIntervalEXT = android_wglSwapIntervalEXT; egl_funcs.p_wglGetSwapIntervalEXT = android_wglGetSwapIntervalEXT; @@ -905,6 +832,11 @@ static const struct opengl_driver_funcs android_driver_funcs = .p_describe_pixel_format = android_describe_pixel_format, .p_init_wgl_extensions = android_init_wgl_extensions, .p_set_pixel_format = android_set_pixel_format, + .p_context_create = android_context_create, + .p_context_destroy = android_context_destroy, + .p_context_copy = android_context_copy, + .p_context_share = android_context_share, + .p_context_make_current = android_context_make_current, };
/********************************************************************** @@ -975,12 +907,7 @@ ALL_GL_FUNCS
static struct opengl_funcs egl_funcs = { - .p_wglCopyContext = android_wglCopyContext, - .p_wglCreateContext = android_wglCreateContext, - .p_wglDeleteContext = android_wglDeleteContext, .p_wglGetProcAddress = android_wglGetProcAddress, - .p_wglMakeCurrent = android_wglMakeCurrent, - .p_wglShareLists = android_wglShareLists, .p_wglSwapBuffers = android_wglSwapBuffers, #define USE_GL_FUNC(name) .p_##name = (void *)glstub_##name, ALL_GL_FUNCS
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/winemac.drv/opengl.c | 286 ++++++++++++-------------------------- 1 file changed, 86 insertions(+), 200 deletions(-)
diff --git a/dlls/winemac.drv/opengl.c b/dlls/winemac.drv/opengl.c index 6731cb0cba3..a98e72a99c7 100644 --- a/dlls/winemac.drv/opengl.c +++ b/dlls/winemac.drv/opengl.c @@ -57,7 +57,7 @@ struct gl_info { static struct gl_info gl_info;
-struct wgl_context +struct macdrv_context { struct list entry; int format; @@ -85,7 +85,6 @@ static struct list context_list = LIST_INIT(context_list); static pthread_mutex_t context_mutex = PTHREAD_MUTEX_INITIALIZER;
static CFMutableDictionaryRef dc_pbuffers; -static CFMutableDictionaryRef dc_pbformats; static pthread_mutex_t dc_pbuffers_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -1322,7 +1321,7 @@ static BOOL init_gl_info(void) /********************************************************************** * create_context */ -static BOOL create_context(struct wgl_context *context, CGLContextObj share, unsigned int major) +static BOOL create_context(struct macdrv_context *context, CGLContextObj share, unsigned int major) { const pixel_format *pf; CGLPixelFormatAttribute attribs[64]; @@ -1491,10 +1490,10 @@ static BOOL macdrv_set_pixel_format(HWND hwnd, int old_format, int new_format, B */ static void mark_contexts_for_moved_view(macdrv_view view) { - struct wgl_context *context; + struct macdrv_context *context;
pthread_mutex_lock(&context_mutex); - LIST_FOR_EACH_ENTRY(context, &context_list, struct wgl_context, entry) + LIST_FOR_EACH_ENTRY(context, &context_list, struct macdrv_context, entry) { if (context->draw_view == view) InterlockedExchange(&context->view_moved, TRUE); @@ -1506,7 +1505,7 @@ static void mark_contexts_for_moved_view(macdrv_view view) /********************************************************************** * sync_context_rect */ -static BOOL sync_context_rect(struct wgl_context *context) +static BOOL sync_context_rect(struct macdrv_context *context) { BOOL ret = FALSE; if (InterlockedCompareExchange(&context->view_moved, FALSE, TRUE)) @@ -1532,7 +1531,7 @@ static BOOL sync_context_rect(struct wgl_context *context) /********************************************************************** * make_context_current */ -static void make_context_current(struct wgl_context *context, BOOL read) +static void make_context_current(struct macdrv_context *context, BOOL read) { macdrv_view view; RECT view_rect; @@ -1570,7 +1569,7 @@ static void make_context_current(struct wgl_context *context, BOOL read) /********************************************************************** * sync_context */ -static void sync_context(struct wgl_context *context) +static void sync_context(struct macdrv_context *context) { if (sync_context_rect(context)) make_context_current(context, FALSE); @@ -1580,7 +1579,7 @@ static void sync_context(struct wgl_context *context) /********************************************************************** * set_swap_interval */ -static BOOL set_swap_interval(struct wgl_context *context, long interval) +static BOOL set_swap_interval(struct macdrv_context *context, long interval) { CGLError err;
@@ -1601,7 +1600,7 @@ static BOOL set_swap_interval(struct wgl_context *context, long interval) /********************************************************************** * sync_swap_interval */ -static void sync_swap_interval(struct wgl_context *context) +static void sync_swap_interval(struct macdrv_context *context) { if (InterlockedCompareExchange(&context->update_swap_interval, FALSE, TRUE)) { @@ -2053,7 +2052,7 @@ static BOOL query_renderer_integer(CGLRendererInfoObj renderer_info, GLint rende static void macdrv_glCopyColorTable(GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width) { - struct wgl_context *context = NtCurrentTeb()->glContext; + struct macdrv_context *context = NtCurrentTeb()->glReserved2;
if (context->read_view || context->read_pbuffer) make_context_current(context, TRUE); @@ -2076,7 +2075,7 @@ static void macdrv_glCopyColorTable(GLenum target, GLenum internalformat, GLint */ static void macdrv_glCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type) { - struct wgl_context *context = NtCurrentTeb()->glContext; + struct macdrv_context *context = NtCurrentTeb()->glReserved2;
if (context->read_view || context->read_pbuffer) make_context_current(context, TRUE); @@ -2093,7 +2092,7 @@ static void macdrv_glCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, */ static void macdrv_glFinish(void) { - struct wgl_context *context = NtCurrentTeb()->glContext; + struct macdrv_context *context = NtCurrentTeb()->glReserved2;
sync_swap_interval(context); sync_context(context); @@ -2106,7 +2105,7 @@ static void macdrv_glFinish(void) */ static void macdrv_glFlush(void) { - struct wgl_context *context = NtCurrentTeb()->glContext; + struct macdrv_context *context = NtCurrentTeb()->glReserved2;
sync_swap_interval(context); sync_context(context); @@ -2167,7 +2166,7 @@ static const GLubyte *macdrv_glGetString(GLenum name) static void macdrv_glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels) { - struct wgl_context *context = NtCurrentTeb()->glContext; + struct macdrv_context *context = NtCurrentTeb()->glReserved2;
if (context->read_view || context->read_pbuffer) make_context_current(context, TRUE); @@ -2188,7 +2187,7 @@ static void macdrv_glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, */ static void macdrv_glViewport(GLint x, GLint y, GLsizei width, GLsizei height) { - struct wgl_context *context = NtCurrentTeb()->glContext; + struct macdrv_context *context = NtCurrentTeb()->glReserved2;
sync_context(context); macdrv_update_opengl_context(context->context); @@ -2203,7 +2202,7 @@ static void macdrv_glViewport(GLint x, GLint y, GLsizei width, GLsizei height) */ static UINT macdrv_pbuffer_bind(HDC hdc, void *private, GLenum source) { - struct wgl_context *context = NtCurrentTeb()->glContext; + struct macdrv_context *context = NtCurrentTeb()->glReserved2; CGLPBufferObj pbuffer = private; CGLError err;
@@ -2223,61 +2222,21 @@ static UINT macdrv_pbuffer_bind(HDC hdc, void *private, GLenum source) return GL_TRUE; }
-static int get_dc_pixel_format(HDC hdc) -{ - int format; - HWND hwnd; - - if ((hwnd = NtUserWindowFromDC(hdc))) - { - struct macdrv_win_data *data; - - if (!(data = get_win_data(hwnd))) - { - FIXME("DC for window %p of other process: not implemented\n", hwnd); - return 0; - } - - format = data->pixel_format; - release_win_data(data); - } - else - { - pthread_mutex_lock(&dc_pbuffers_mutex); - format = (UINT_PTR)CFDictionaryGetValue(dc_pbformats, hdc); - if (!format) WARN("no window or pbuffer for DC %p\n", hdc); - pthread_mutex_unlock(&dc_pbuffers_mutex); - } - - return format; -} - /*********************************************************************** * macdrv_wglCreateContextAttribsARB * * WGL_ARB_create_context: wglCreateContextAttribsARB */ -static struct wgl_context *macdrv_wglCreateContextAttribsARB(HDC hdc, - struct wgl_context *share_context, - const int *attrib_list) +static BOOL macdrv_context_create(HDC hdc, int format, void *shared, const int *attrib_list, void **private) { - int format; - struct wgl_context *context; + struct macdrv_context *share_context = shared; + struct macdrv_context *context; const int *iptr; int major = 1, minor = 0, profile = WGL_CONTEXT_CORE_PROFILE_BIT_ARB, flags = 0; BOOL core = FALSE; GLint renderer_id = 0;
- TRACE("hdc %p, share_context %p, attrib_list %p\n", hdc, share_context, attrib_list); - - format = get_dc_pixel_format(hdc); - - if (!is_valid_pixel_format(format)) - { - ERR("Invalid pixel format %d, expect problems!\n", format); - RtlSetLastWin32Error(ERROR_INVALID_PIXEL_FORMAT); - return NULL; - } + TRACE("hdc %p, format %d, share_context %p, attrib_list %p\n", hdc, format, share_context, attrib_list);
for (iptr = attrib_list; iptr && *iptr; iptr += 2) { @@ -2313,7 +2272,7 @@ static struct wgl_context *macdrv_wglCreateContextAttribsARB(HDC hdc, { WARN("WGL_CONTEXT_PROFILE_MASK_ARB bits %#x invalid\n", value); RtlSetLastWin32Error(ERROR_INVALID_PROFILE_ARB); - return NULL; + return FALSE; } profile = value; break; @@ -2329,7 +2288,7 @@ static struct wgl_context *macdrv_wglCreateContextAttribsARB(HDC hdc, { WARN("CGLQueryRendererInfo failed: %d %s\n", err, CGLErrorString(err)); RtlSetLastWin32Error(ERROR_GEN_FAILURE); - return NULL; + return FALSE; }
value = map_renderer_index(renderer_info, renderer_count, value); @@ -2339,7 +2298,7 @@ static struct wgl_context *macdrv_wglCreateContextAttribsARB(HDC hdc, WARN("WGL_RENDERER_ID_WINE renderer %d exceeds count (%d)\n", value, renderer_count); CGLDestroyRendererInfo(renderer_info); RtlSetLastWin32Error(ERROR_INVALID_PARAMETER); - return NULL; + return FALSE; }
if (!get_renderer_property(renderer_info, value, kCGLRPRendererID, &temp)) @@ -2347,7 +2306,7 @@ static struct wgl_context *macdrv_wglCreateContextAttribsARB(HDC hdc, WARN("WGL_RENDERER_ID_WINE failed to get ID of renderer %d\n", value); CGLDestroyRendererInfo(renderer_info); RtlSetLastWin32Error(ERROR_GEN_FAILURE); - return NULL; + return FALSE; }
CGLDestroyRendererInfo(renderer_info); @@ -2356,7 +2315,7 @@ static struct wgl_context *macdrv_wglCreateContextAttribsARB(HDC hdc, { WARN("WGL_RENDERER_ID_WINE requested two different renderers (0x%08x vs. 0x%08x)\n", renderer_id, temp); RtlSetLastWin32Error(ERROR_INVALID_PARAMETER); - return NULL; + return FALSE; } renderer_id = temp; break; @@ -2365,7 +2324,7 @@ static struct wgl_context *macdrv_wglCreateContextAttribsARB(HDC hdc, default: WARN("Unknown attribute %s.\n", debugstr_attrib(attr, value)); RtlSetLastWin32Error(ERROR_INVALID_PARAMETER); - return NULL; + return FALSE; } }
@@ -2376,13 +2335,13 @@ static struct wgl_context *macdrv_wglCreateContextAttribsARB(HDC hdc, { WARN("OS X only supports forward-compatible 3.2+ contexts\n"); RtlSetLastWin32Error(ERROR_INVALID_VERSION_ARB); - return NULL; + return FALSE; } if (profile != WGL_CONTEXT_CORE_PROFILE_BIT_ARB) { WARN("Compatibility profiles for GL version >= 3.2 not supported\n"); RtlSetLastWin32Error(ERROR_INVALID_PROFILE_ARB); - return NULL; + return FALSE; } if (major > gl_info.max_major || (major == gl_info.max_major && minor > gl_info.max_minor)) @@ -2390,7 +2349,7 @@ static struct wgl_context *macdrv_wglCreateContextAttribsARB(HDC hdc, WARN("This GL implementation does not support the requested GL version %u.%u\n", major, minor); RtlSetLastWin32Error(ERROR_INVALID_PROFILE_ARB); - return NULL; + return FALSE; } core = TRUE; } @@ -2398,37 +2357,38 @@ static struct wgl_context *macdrv_wglCreateContextAttribsARB(HDC hdc, { WARN("Profile version %u.%u not supported\n", major, minor); RtlSetLastWin32Error(ERROR_INVALID_VERSION_ARB); - return NULL; + return FALSE; } else if (major < 1 || (major == 1 && (minor < 0 || minor > 5)) || (major == 2 && (minor < 0 || minor > 1))) { WARN("Invalid GL version requested\n"); RtlSetLastWin32Error(ERROR_INVALID_VERSION_ARB); - return NULL; + return FALSE; } if (!core && flags & WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB) { WARN("Forward compatible context requested for GL version < 3\n"); RtlSetLastWin32Error(ERROR_INVALID_VERSION_ARB); - return NULL; + return FALSE; }
- if (!(context = calloc(1, sizeof(*context)))) return NULL; + if (!(context = calloc(1, sizeof(*context)))) return FALSE;
context->format = format; context->renderer_id = renderer_id; if (!create_context(context, share_context ? share_context->cglcontext : NULL, major)) { free(context); - return NULL; + return FALSE; }
pthread_mutex_lock(&context_mutex); list_add_tail(&context_list, &context->entry); pthread_mutex_unlock(&context_mutex);
- return context; + *private = context; + return TRUE; }
static BOOL macdrv_pbuffer_create(HDC hdc, int format, BOOL largest, GLenum texture_format, GLenum texture_target, @@ -2455,7 +2415,6 @@ static BOOL macdrv_pbuffer_create(HDC hdc, int format, BOOL largest, GLenum text
pthread_mutex_lock(&dc_pbuffers_mutex); CFDictionarySetValue(dc_pbuffers, hdc, private); - CFDictionarySetValue(dc_pbformats, hdc, (void *)(UINT_PTR)format); pthread_mutex_unlock(&dc_pbuffers_mutex);
TRACE(" -> %p\n", *private); @@ -2468,7 +2427,6 @@ static BOOL macdrv_pbuffer_destroy(HDC hdc, void *private)
pthread_mutex_lock(&dc_pbuffers_mutex); CFDictionaryRemoveValue(dc_pbuffers, hdc); - CFDictionaryRemoveValue(dc_pbformats, hdc); pthread_mutex_unlock(&dc_pbuffers_mutex);
CGLReleasePBuffer(private); @@ -2483,7 +2441,7 @@ static BOOL macdrv_pbuffer_destroy(HDC hdc, void *private) */ static int macdrv_wglGetSwapIntervalEXT(void) { - struct wgl_context *context = NtCurrentTeb()->glContext; + struct macdrv_context *context = NtCurrentTeb()->glReserved2; struct macdrv_win_data *data; long value; CGLError err; @@ -2512,29 +2470,19 @@ static int macdrv_wglGetSwapIntervalEXT(void) return value; }
- -/*********************************************************************** - * macdrv_wglMakeContextCurrentARB - * - * WGL_ARB_make_current_read: wglMakeContextCurrentARB - * - * This is not supported directly by OpenGL on the Mac. We emulate it - * by hooking into glReadPixels, glCopyPixels, and glCopyColorTable to - * temporarily swap the drawable. This follows the technique used in - * the implementation of Mesa GLX for Apple. - */ -static BOOL macdrv_wglMakeContextCurrentARB(HDC draw_hdc, HDC read_hdc, struct wgl_context *context) +static BOOL macdrv_context_make_current(HDC draw_hdc, HDC read_hdc, void *private) { + 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));
- if (!context) + if (!private) { macdrv_make_context_current(NULL, NULL, CGRectNull); - NtCurrentTeb()->glContext = NULL; + NtCurrentTeb()->glReserved2 = NULL; return TRUE; }
@@ -2546,21 +2494,6 @@ static BOOL macdrv_wglMakeContextCurrentARB(HDC draw_hdc, HDC read_hdc, struct w return FALSE; }
- if (!data->pixel_format) - { - WARN("no pixel format set\n"); - release_win_data(data); - RtlSetLastWin32Error(ERROR_INVALID_HANDLE); - return FALSE; - } - if (context->format != data->pixel_format) - { - WARN("mismatched pixel format draw_hdc %p %u context %p %u\n", draw_hdc, data->pixel_format, context, context->format); - release_win_data(data); - RtlSetLastWin32Error(ERROR_INVALID_PIXEL_FORMAT); - return FALSE; - } - if (InterlockedCompareExchange(&context->update_swap_interval, FALSE, TRUE) || hwnd != context->draw_hwnd) set_swap_interval(context, allow_vsync ? data->swap_interval : 0);
@@ -2579,15 +2512,6 @@ static BOOL macdrv_wglMakeContextCurrentARB(HDC draw_hdc, HDC read_hdc, struct w pbuffer = (CGLPBufferObj)CFDictionaryGetValue(dc_pbuffers, draw_hdc); if (pbuffer) { - int format = (UINT_PTR)CFDictionaryGetValue(dc_pbformats, draw_hdc); - if (context->format != format) - { - WARN("mismatched pixel format draw_hdc %p %u context %p %u\n", draw_hdc, format, context, context->format); - pthread_mutex_unlock(&dc_pbuffers_mutex); - RtlSetLastWin32Error(ERROR_INVALID_PIXEL_FORMAT); - return FALSE; - } - if (InterlockedCompareExchange(&context->update_swap_interval, FALSE, TRUE) || pbuffer != context->draw_pbuffer) set_swap_interval(context, 0); } @@ -2636,7 +2560,7 @@ static BOOL macdrv_wglMakeContextCurrentARB(HDC draw_hdc, HDC read_hdc, struct w
make_context_current(context, FALSE); context->has_been_current = TRUE; - NtCurrentTeb()->glContext = context; + NtCurrentTeb()->glReserved2 = context;
return TRUE; } @@ -2650,7 +2574,7 @@ static BOOL macdrv_wglMakeContextCurrentARB(HDC draw_hdc, HDC read_hdc, struct w static BOOL macdrv_wglQueryCurrentRendererIntegerWINE(GLenum attribute, GLuint *value) { BOOL ret = FALSE; - struct wgl_context *context = NtCurrentTeb()->glContext; + struct macdrv_context *context = NtCurrentTeb()->glReserved2; CGLPixelFormatObj pixel_format; CGLError err; GLint virtual_screen; @@ -2730,7 +2654,7 @@ static BOOL macdrv_wglQueryCurrentRendererIntegerWINE(GLenum attribute, GLuint * static const char *macdrv_wglQueryCurrentRendererStringWINE(GLenum attribute) { const char* ret = NULL; - struct wgl_context *context = NtCurrentTeb()->glContext; + struct macdrv_context *context = NtCurrentTeb()->glReserved2;
TRACE("context %p/%p/%p attribute 0x%04x\n", context, (context ? context->context : NULL), (context ? context->cglcontext : NULL), attribute); @@ -2855,7 +2779,7 @@ done:
static BOOL macdrv_pbuffer_updated(HDC hdc, void *private, GLenum cube_face, GLint mipmap_level) { - struct wgl_context *context = NtCurrentTeb()->glContext; + struct macdrv_context *context = NtCurrentTeb()->glReserved2; CGLPBufferObj pbuffer = private;
TRACE("hdc %p pbuffer %p cube_face %#x mipmap_level %d\n", hdc, pbuffer, cube_face, mipmap_level); @@ -2878,7 +2802,7 @@ static BOOL macdrv_pbuffer_updated(HDC hdc, void *private, GLenum cube_face, GLi */ static BOOL macdrv_wglSwapIntervalEXT(int interval) { - struct wgl_context *context = NtCurrentTeb()->glContext; + struct macdrv_context *context = NtCurrentTeb()->glReserved2; BOOL changed = FALSE;
TRACE("interval %d\n", interval); @@ -2917,10 +2841,10 @@ static BOOL macdrv_wglSwapIntervalEXT(int interval)
if (changed) { - struct wgl_context *ctx; + struct macdrv_context *ctx;
pthread_mutex_lock(&context_mutex); - LIST_FOR_EACH_ENTRY(ctx, &context_list, struct wgl_context, entry) + LIST_FOR_EACH_ENTRY(ctx, &context_list, struct macdrv_context, entry) { if (ctx != context && ctx->draw_hwnd == context->draw_hwnd) InterlockedExchange(&context->update_swap_interval, TRUE); @@ -2946,9 +2870,6 @@ static const char *macdrv_init_wgl_extensions(void) /* * ARB Extensions */ - register_extension("WGL_ARB_make_current_read"); - opengl_funcs.p_wglGetCurrentReadDCARB = (void *)1; /* never called */ - opengl_funcs.p_wglMakeContextCurrentARB = macdrv_wglMakeContextCurrentARB;
if (gluCheckExtension((GLubyte*)"GL_ARB_color_buffer_float", (GLubyte*)gl_info.glExtensions)) { @@ -2969,10 +2890,6 @@ static const char *macdrv_init_wgl_extensions(void) register_extension("WGL_NV_render_texture_rectangle"); }
- register_extension("WGL_ARB_create_context"); - register_extension("WGL_ARB_create_context_profile"); - opengl_funcs.p_wglCreateContextAttribsARB = macdrv_wglCreateContextAttribsARB; - /* * EXT Extensions */ @@ -3018,8 +2935,7 @@ UINT macdrv_OpenGLInit(UINT version, struct opengl_funcs **funcs, const struct o }
dc_pbuffers = CFDictionaryCreateMutable(NULL, 0, NULL, NULL); - dc_pbformats = CFDictionaryCreateMutable(NULL, 0, NULL, NULL); - if (!dc_pbuffers || !dc_pbformats) + if (!dc_pbuffers) { WARN("CFDictionaryCreateMutable failed\n"); return STATUS_NOT_SUPPORTED; @@ -3191,11 +3107,9 @@ static BOOL macdrv_describe_pixel_format(int format, struct wgl_pixel_format *de return TRUE; }
-/*********************************************************************** - * macdrv_wglCopyContext - */ -static BOOL macdrv_wglCopyContext(struct wgl_context *src, struct wgl_context *dst, UINT mask) +static BOOL macdrv_context_copy(void *src_private, void *dst_private, UINT mask) { + struct macdrv_context *src = src_private, *dst = dst_private; CGLError err;
TRACE("src %p dst %p mask %x\n", src, dst, mask); @@ -3206,25 +3120,10 @@ static BOOL macdrv_wglCopyContext(struct wgl_context *src, struct wgl_context *d return (err == kCGLNoError); }
-/*********************************************************************** - * macdrv_wglCreateContext - */ -static struct wgl_context *macdrv_wglCreateContext(HDC hdc) +static BOOL macdrv_context_destroy(void *private) { - struct wgl_context *context; - - TRACE("hdc %p\n", hdc); - - context = macdrv_wglCreateContextAttribsARB(hdc, NULL, NULL); + struct macdrv_context *context = private;
- return context; -} - -/*********************************************************************** - * macdrv_wglDeleteContext - */ -static BOOL macdrv_wglDeleteContext(struct wgl_context *context) -{ TRACE("deleting context %p/%p/%p\n", context, context->context, context->cglcontext);
pthread_mutex_lock(&context_mutex); @@ -3236,47 +3135,9 @@ static BOOL macdrv_wglDeleteContext(struct wgl_context *context) return TRUE; }
-/*********************************************************************** - * macdrv_wglGetProcAddress - */ -static PROC macdrv_wglGetProcAddress(const char *proc) -{ - void *ret; - - if (!strncmp(proc, "wgl", 3)) return NULL; - ret = dlsym(opengl_handle, proc); - if (ret) - { - if (TRACE_ON(wgl)) - { - Dl_info info; - if (dladdr(ret, &info)) - TRACE("%s -> %s from %s\n", proc, info.dli_sname, info.dli_fname); - else - TRACE("%s -> %p (no library info)\n", proc, ret); - } - } - else - WARN("failed to find proc %s\n", debugstr_a(proc)); - return ret; -} - -/*********************************************************************** - * macdrv_wglMakeCurrent - */ -static BOOL macdrv_wglMakeCurrent(HDC hdc, struct wgl_context *context) -{ - TRACE("hdc %p context %p/%p/%p\n", hdc, context, (context ? context->context : NULL), - (context ? context->cglcontext : NULL)); - - return macdrv_wglMakeContextCurrentARB(hdc, hdc, context); -} - -/*********************************************************************** - * macdrv_wglShareLists - */ -static BOOL macdrv_wglShareLists(struct wgl_context *org, struct wgl_context *dest) +static BOOL macdrv_context_share(void *src_private, void *dst_private) { + struct macdrv_context *org = src_private, *dest = dst_private; macdrv_opengl_context saved_context; CGLContextObj saved_cglcontext;
@@ -3325,12 +3186,37 @@ static BOOL macdrv_wglShareLists(struct wgl_context *org, struct wgl_context *de return TRUE; }
+/*********************************************************************** + * macdrv_wglGetProcAddress + */ +static PROC macdrv_wglGetProcAddress(const char *proc) +{ + void *ret; + + if (!strncmp(proc, "wgl", 3)) return NULL; + ret = dlsym(opengl_handle, proc); + if (ret) + { + if (TRACE_ON(wgl)) + { + Dl_info info; + if (dladdr(ret, &info)) + TRACE("%s -> %s from %s\n", proc, info.dli_sname, info.dli_fname); + else + TRACE("%s -> %p (no library info)\n", proc, ret); + } + } + else + WARN("failed to find proc %s\n", debugstr_a(proc)); + return ret; +} + /********************************************************************** * macdrv_wglSwapBuffers */ static BOOL macdrv_wglSwapBuffers(HDC hdc) { - struct wgl_context *context = NtCurrentTeb()->glContext; + struct macdrv_context *context = NtCurrentTeb()->glReserved2; BOOL match = FALSE; HWND hwnd;
@@ -3402,15 +3288,15 @@ static const struct opengl_driver_funcs macdrv_driver_funcs = .p_pbuffer_destroy = macdrv_pbuffer_destroy, .p_pbuffer_updated = macdrv_pbuffer_updated, .p_pbuffer_bind = macdrv_pbuffer_bind, + .p_context_create = macdrv_context_create, + .p_context_destroy = macdrv_context_destroy, + .p_context_copy = macdrv_context_copy, + .p_context_share = macdrv_context_share, + .p_context_make_current = macdrv_context_make_current, };
static struct opengl_funcs opengl_funcs = { - .p_wglCopyContext = macdrv_wglCopyContext, - .p_wglCreateContext = macdrv_wglCreateContext, - .p_wglDeleteContext = macdrv_wglDeleteContext, .p_wglGetProcAddress = macdrv_wglGetProcAddress, - .p_wglMakeCurrent = macdrv_wglMakeCurrent, - .p_wglShareLists = macdrv_wglShareLists, .p_wglSwapBuffers = macdrv_wglSwapBuffers, };
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/winewayland.drv/opengl.c | 121 ++++++++++++---------------------- 1 file changed, 41 insertions(+), 80 deletions(-)
diff --git a/dlls/winewayland.drv/opengl.c b/dlls/winewayland.drv/opengl.c index cc595f87252..eae566b77a4 100644 --- a/dlls/winewayland.drv/opengl.c +++ b/dlls/winewayland.drv/opengl.c @@ -94,7 +94,7 @@ struct wayland_gl_drawable BOOL double_buffered; };
-struct wgl_context +struct wayland_context { struct list entry; EGLConfig config; @@ -231,9 +231,9 @@ err: static void update_context_drawables(struct wayland_gl_drawable *new, struct wayland_gl_drawable *old) { - struct wgl_context *ctx; + struct wayland_context *ctx;
- LIST_FOR_EACH_ENTRY(ctx, &gl_contexts, struct wgl_context, entry) + LIST_FOR_EACH_ENTRY(ctx, &gl_contexts, struct wayland_context, entry) { if (ctx->draw == old || ctx->new_draw == old) ctx->new_draw = new; if (ctx->read == old || ctx->new_read == old) ctx->new_read = new; @@ -275,12 +275,22 @@ static void wayland_gl_drawable_sync_size(struct wayland_gl_drawable *gl) } }
-static BOOL wgl_context_make_current(struct wgl_context *ctx, HDC draw_hdc, HDC read_hdc) +static BOOL wayland_context_make_current(HDC draw_hdc, HDC read_hdc, void *private) { 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); + + if (!private) + { + p_eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + NtCurrentTeb()->glReserved2 = NULL; + return TRUE; + } + draw = wayland_gl_drawable_get(NtUserWindowFromDC(draw_hdc), draw_hdc); read = wayland_gl_drawable_get(NtUserWindowFromDC(read_hdc), read_hdc);
@@ -307,7 +317,7 @@ static BOOL wgl_context_make_current(struct wgl_context *ctx, HDC draw_hdc, HDC ctx->read = read; ctx->new_draw = ctx->new_read = NULL; ctx->has_been_current = TRUE; - NtCurrentTeb()->glContext = ctx; + NtCurrentTeb()->glReserved2 = ctx; } else { @@ -323,7 +333,7 @@ static BOOL wgl_context_make_current(struct wgl_context *ctx, HDC draw_hdc, HDC return ret; }
-static BOOL wgl_context_populate_attribs(struct wgl_context *ctx, const int *wgl_attribs) +static BOOL wayland_context_populate_attribs(struct wayland_context *ctx, const int *wgl_attribs) { EGLint *attribs_end = ctx->attribs;
@@ -385,7 +395,7 @@ out: }
-static void wgl_context_refresh(struct wgl_context *ctx) +static void wayland_context_refresh(struct wayland_context *ctx) { BOOL refresh = FALSE; struct wayland_gl_drawable *old_draw = NULL, *old_read = NULL; @@ -438,24 +448,22 @@ static BOOL wayland_set_pixel_format(HWND hwnd, int old_format, int new_format, return TRUE; }
-static struct wgl_context *create_context(HDC hdc, struct wgl_context *share, - const int *attribs) +static BOOL wayland_context_create(HDC hdc, int format, void *share_private, const int *attribs, void **private) { - struct wayland_gl_drawable *gl; - struct wgl_context *ctx; + struct wayland_context *share = share_private, *ctx;
- if (!(gl = wayland_gl_drawable_get(NtUserWindowFromDC(hdc), hdc))) return NULL; + TRACE("hdc=%p format=%d share=%p attribs=%p\n", hdc, format, share, attribs);
if (!(ctx = calloc(1, sizeof(*ctx)))) { ERR("Failed to allocate memory for GL context\n"); - goto out; + return FALSE; }
- if (!wgl_context_populate_attribs(ctx, attribs)) + if (!wayland_context_populate_attribs(ctx, attribs)) { ctx->attribs[0] = EGL_NONE; - goto out; + return FALSE; }
/* For now only OpenGL is supported. It's enough to set the API only for @@ -476,43 +484,29 @@ static struct wgl_context *create_context(HDC hdc, struct wgl_context *share,
TRACE("ctx=%p egl_context=%p\n", ctx, ctx->context);
-out: - wayland_gl_drawable_release(gl); - return ctx; + *private = ctx; + return TRUE; }
void wayland_glClear(GLbitfield mask) { - struct wgl_context *ctx = NtCurrentTeb()->glContext; + struct wayland_context *ctx = NtCurrentTeb()->glReserved2; /* Since glClear is one of the operations that may latch the native size, * perform any pending resizes before calling it. */ if (ctx && ctx->draw) wayland_gl_drawable_sync_size(ctx->draw); p_glClear(mask); }
-static BOOL wayland_wglCopyContext(struct wgl_context *src, - struct wgl_context *dst, UINT mask) +static BOOL wayland_context_copy(void *src, void *dst, UINT mask) { FIXME("%p -> %p mask %#x unsupported\n", src, dst, mask); return FALSE; }
-static struct wgl_context *wayland_wglCreateContext(HDC hdc) +static BOOL wayland_context_destroy(void *private) { - TRACE("hdc=%p\n", hdc); - return create_context(hdc, NULL, NULL); -} + struct wayland_context *ctx = private;
-static struct wgl_context *wayland_wglCreateContextAttribsARB(HDC hdc, - struct wgl_context *share, - const int *attribs) -{ - TRACE("hdc=%p share=%p attribs=%p\n", hdc, share, attribs); - return create_context(hdc, share, attribs); -} - -static BOOL wayland_wglDeleteContext(struct wgl_context *ctx) -{ pthread_mutex_lock(&gl_object_mutex); list_remove(&ctx->entry); pthread_mutex_unlock(&gl_object_mutex); @@ -531,7 +525,7 @@ static PROC wayland_wglGetProcAddress(LPCSTR name)
static int wayland_wglGetSwapIntervalEXT(void) { - struct wgl_context *ctx = NtCurrentTeb()->glContext; + struct wayland_context *ctx = NtCurrentTeb()->glReserved2;
if (!ctx || !ctx->draw) { @@ -544,34 +538,10 @@ static int wayland_wglGetSwapIntervalEXT(void) return ctx->draw->swap_interval; }
-static BOOL wayland_wglMakeContextCurrentARB(HDC draw_hdc, HDC read_hdc, - struct wgl_context *ctx) +static BOOL wayland_context_share(void *src_private, void *dst_private) { - BOOL ret; - - TRACE("draw_hdc=%p read_hdc=%p ctx=%p\n", draw_hdc, read_hdc, ctx); - - if (!ctx) - { - p_eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - NtCurrentTeb()->glContext = NULL; - return TRUE; - } - - ret = wgl_context_make_current(ctx, draw_hdc, read_hdc); - if (!ret) RtlSetLastWin32Error(ERROR_INVALID_HANDLE); - - return ret; -} - -static BOOL wayland_wglMakeCurrent(HDC hdc, struct wgl_context *ctx) -{ - return wayland_wglMakeContextCurrentARB(hdc, hdc, ctx); -} - -static BOOL wayland_wglShareLists(struct wgl_context *orig, struct wgl_context *dest) -{ - struct wgl_context *keep, *clobber; + struct wayland_context *orig = src_private, *dest = dst_private; + struct wayland_context *keep, *clobber;
TRACE("(%p, %p)\n", orig, dest);
@@ -614,13 +584,13 @@ static BOOL wayland_wglShareLists(struct wgl_context *orig, struct wgl_context *
static BOOL wayland_wglSwapBuffers(HDC hdc) { - struct wgl_context *ctx = NtCurrentTeb()->glContext; + struct wayland_context *ctx = NtCurrentTeb()->glReserved2; HWND hwnd = NtUserWindowFromDC(hdc), toplevel = NtUserGetAncestor(hwnd, GA_ROOT); struct wayland_gl_drawable *gl;
if (!(gl = wayland_gl_drawable_get(NtUserWindowFromDC(hdc), hdc))) return FALSE;
- if (ctx) wgl_context_refresh(ctx); + if (ctx) wayland_context_refresh(ctx); ensure_window_surface_contents(toplevel); /* Although all the EGL surfaces we create are double-buffered, we want to * use some as single-buffered, so avoid swapping those. */ @@ -634,7 +604,7 @@ static BOOL wayland_wglSwapBuffers(HDC hdc)
static BOOL wayland_wglSwapIntervalEXT(int interval) { - struct wgl_context *ctx = NtCurrentTeb()->glContext; + struct wayland_context *ctx = NtCurrentTeb()->glReserved2; BOOL ret;
TRACE("(%d)\n", interval); @@ -889,15 +859,6 @@ static BOOL init_opengl_funcs(void)
static const char *wayland_init_wgl_extensions(void) { - register_extension("WGL_ARB_make_current_read"); - opengl_funcs.p_wglGetCurrentReadDCARB = (void *)1; /* never called */ - opengl_funcs.p_wglMakeContextCurrentARB = wayland_wglMakeContextCurrentARB; - - register_extension("WGL_ARB_create_context"); - register_extension("WGL_ARB_create_context_no_error"); - register_extension("WGL_ARB_create_context_profile"); - opengl_funcs.p_wglCreateContextAttribsARB = wayland_wglCreateContextAttribsARB; - register_extension("WGL_EXT_swap_control"); opengl_funcs.p_wglGetSwapIntervalEXT = wayland_wglGetSwapIntervalEXT; opengl_funcs.p_wglSwapIntervalEXT = wayland_wglSwapIntervalEXT; @@ -972,6 +933,11 @@ static const struct opengl_driver_funcs wayland_driver_funcs = .p_describe_pixel_format = wayland_describe_pixel_format, .p_init_wgl_extensions = wayland_init_wgl_extensions, .p_set_pixel_format = wayland_set_pixel_format, + .p_context_create = wayland_context_create, + .p_context_destroy = wayland_context_destroy, + .p_context_copy = wayland_context_copy, + .p_context_share = wayland_context_share, + .p_context_make_current = wayland_context_make_current, .p_pbuffer_create = wayland_pbuffer_create, .p_pbuffer_destroy = wayland_pbuffer_destroy, .p_pbuffer_updated = wayland_pbuffer_updated, @@ -1083,12 +1049,7 @@ err:
static struct opengl_funcs opengl_funcs = { - .p_wglCopyContext = wayland_wglCopyContext, - .p_wglCreateContext = wayland_wglCreateContext, - .p_wglDeleteContext = wayland_wglDeleteContext, .p_wglGetProcAddress = wayland_wglGetProcAddress, - .p_wglMakeCurrent = wayland_wglMakeCurrent, - .p_wglShareLists = wayland_wglShareLists, .p_wglSwapBuffers = wayland_wglSwapBuffers, };
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/winex11.drv/opengl.c | 194 +++++++++----------------------------- 1 file changed, 44 insertions(+), 150 deletions(-)
diff --git a/dlls/winex11.drv/opengl.c b/dlls/winex11.drv/opengl.c index 05ae284761c..95c8687981f 100644 --- a/dlls/winex11.drv/opengl.c +++ b/dlls/winex11.drv/opengl.c @@ -194,7 +194,7 @@ struct glx_pixel_format DWORD dwFlags; /* We store some PFD_* flags in here for emulated bitmap formats */ };
-struct wgl_context +struct x11drv_context { HDC hdc; BOOL has_been_current; @@ -937,10 +937,10 @@ static void release_gl_drawable( struct gl_drawable *gl ) /* Mark any allocated context using the glx drawable 'old' to use 'new' */ static void mark_drawable_dirty( struct gl_drawable *old, struct gl_drawable *new ) { - struct wgl_context *ctx; + struct x11drv_context *ctx;
pthread_mutex_lock( &context_mutex ); - LIST_FOR_EACH_ENTRY( ctx, &context_list, struct wgl_context, entry ) + LIST_FOR_EACH_ENTRY( ctx, &context_list, struct x11drv_context, entry ) { if (old == ctx->drawables[0] || old == ctx->new_drawables[0]) { @@ -957,7 +957,7 @@ static void mark_drawable_dirty( struct gl_drawable *old, struct gl_drawable *ne }
/* Given the current context, make sure its drawable is sync'd */ -static inline void sync_context(struct wgl_context *context) +static inline void sync_context(struct x11drv_context *context) { BOOL refresh = FALSE; struct gl_drawable *old[2] = { NULL }; @@ -1042,7 +1042,7 @@ static struct gl_drawable *get_gl_drawable( HWND hwnd, HDC hdc ) return gl; }
-static GLXContext create_glxcontext(Display *display, struct wgl_context *context, GLXContext shareList) +static GLXContext create_glxcontext(Display *display, struct x11drv_context *context, GLXContext shareList) { GLXContext ctx;
@@ -1522,8 +1522,9 @@ static BOOL x11drv_describe_pixel_format( int iPixelFormat, struct wgl_pixel_for /*********************************************************************** * glxdrv_wglCopyContext */ -static BOOL glxdrv_wglCopyContext(struct wgl_context *src, struct wgl_context *dst, UINT mask) +static BOOL x11drv_context_copy(void *src_private, void *dst_private, UINT mask) { + struct x11drv_context *src = src_private, *dst = dst_private; TRACE("%p -> %p mask %#x\n", src, dst, mask);
X11DRV_expect_error( gdi_display, GLXErrorHandler, NULL ); @@ -1544,39 +1545,13 @@ static BOOL glxdrv_wglCopyContext(struct wgl_context *src, struct wgl_context *d return TRUE; }
-/*********************************************************************** - * glxdrv_wglCreateContext - */ -static struct wgl_context *glxdrv_wglCreateContext( HDC hdc ) -{ - struct wgl_context *ret; - struct gl_drawable *gl; - - if (!(gl = get_gl_drawable( NtUserWindowFromDC( hdc ), hdc ))) - { - RtlSetLastWin32Error( ERROR_INVALID_PIXEL_FORMAT ); - return NULL; - } - - if ((ret = calloc( 1, sizeof(*ret) ))) - { - ret->hdc = hdc; - ret->fmt = gl->format; - ret->ctx = create_glxcontext(gdi_display, ret, NULL); - pthread_mutex_lock( &context_mutex ); - list_add_head( &context_list, &ret->entry ); - pthread_mutex_unlock( &context_mutex ); - } - release_gl_drawable( gl ); - TRACE( "%p -> %p\n", hdc, ret ); - return ret; -} - /*********************************************************************** * glxdrv_wglDeleteContext */ -static BOOL glxdrv_wglDeleteContext(struct wgl_context *ctx) +static BOOL x11drv_context_destroy(void *private) { + struct x11drv_context *ctx = private; + TRACE("(%p)\n", ctx);
pthread_mutex_lock( &context_mutex ); @@ -1601,7 +1576,7 @@ static PROC glxdrv_wglGetProcAddress(LPCSTR lpszProc) return pglXGetProcAddressARB((const GLubyte*)lpszProc); }
-static void set_context_drawables( struct wgl_context *ctx, struct gl_drawable *draw, +static void set_context_drawables( struct x11drv_context *ctx, struct gl_drawable *draw, struct gl_drawable *read ) { struct gl_drawable *prev[4]; @@ -1617,88 +1592,34 @@ static void set_context_drawables( struct wgl_context *ctx, struct gl_drawable * for (i = 0; i < 4; i++) release_gl_drawable( prev[i] ); }
-/*********************************************************************** - * glxdrv_wglMakeCurrent - */ -static BOOL glxdrv_wglMakeCurrent(HDC hdc, struct wgl_context *ctx) -{ - BOOL ret = FALSE; - struct gl_drawable *gl; - - TRACE("(%p,%p)\n", hdc, ctx); - - if (!ctx) - { - pglXMakeCurrent(gdi_display, None, NULL); - NtCurrentTeb()->glContext = NULL; - return TRUE; - } - - if ((gl = get_gl_drawable( NtUserWindowFromDC( hdc ), hdc ))) - { - if (ctx->fmt != gl->format) - { - WARN( "mismatched pixel format hdc %p %p ctx %p %p\n", hdc, gl->format, ctx, ctx->fmt ); - RtlSetLastWin32Error( ERROR_INVALID_PIXEL_FORMAT ); - goto done; - } - - TRACE("hdc %p drawable %lx fmt %p ctx %p %s\n", hdc, gl->drawable, gl->format, ctx->ctx, - debugstr_fbconfig( gl->format->fbconfig )); - - pthread_mutex_lock( &context_mutex ); - ret = pglXMakeCurrent(gdi_display, gl->drawable, ctx->ctx); - if (ret) - { - NtCurrentTeb()->glContext = ctx; - ctx->has_been_current = TRUE; - ctx->hdc = hdc; - set_context_drawables( ctx, gl, gl ); - pthread_mutex_unlock( &context_mutex ); - goto done; - } - pthread_mutex_unlock( &context_mutex ); - } - RtlSetLastWin32Error( ERROR_INVALID_HANDLE ); - -done: - release_gl_drawable( gl ); - TRACE( "%p,%p returning %d\n", hdc, ctx, ret ); - return ret; -} - -/*********************************************************************** - * X11DRV_wglMakeContextCurrentARB - */ -static BOOL X11DRV_wglMakeContextCurrentARB( HDC draw_hdc, HDC read_hdc, struct wgl_context *ctx ) +static BOOL x11drv_context_make_current( HDC draw_hdc, HDC read_hdc, void *private ) { + 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);
- if (!ctx) + if (!private) { - pglXMakeCurrent(gdi_display, None, NULL); - NtCurrentTeb()->glContext = NULL; + pglXMakeCurrent( gdi_display, None, NULL ); + NtCurrentTeb()->glReserved2 = NULL; return TRUE; }
- if (!pglXMakeContextCurrent) return FALSE; - if ((draw_gl = get_gl_drawable( NtUserWindowFromDC( draw_hdc ), draw_hdc ))) { read_gl = get_gl_drawable( NtUserWindowFromDC( read_hdc ), read_hdc );
pthread_mutex_lock( &context_mutex ); - ret = pglXMakeContextCurrent(gdi_display, draw_gl->drawable, - read_gl ? read_gl->drawable : 0, ctx->ctx); + 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) { ctx->has_been_current = TRUE; ctx->hdc = draw_hdc; set_context_drawables( ctx, draw_gl, read_gl ); - NtCurrentTeb()->glContext = ctx; + NtCurrentTeb()->glReserved2 = ctx; pthread_mutex_unlock( &context_mutex ); goto done; } @@ -1715,9 +1636,10 @@ done: /*********************************************************************** * glxdrv_wglShareLists */ -static BOOL glxdrv_wglShareLists(struct wgl_context *org, struct wgl_context *dest) +static BOOL x11drv_context_share(void *src_private, void *dst_private) { - struct wgl_context *keep, *clobber; + struct x11drv_context *org = src_private, *dest = dst_private; + struct x11drv_context *keep, *clobber;
TRACE("(%p, %p)\n", org, dest);
@@ -1805,7 +1727,7 @@ static void present_gl_drawable( HWND hwnd, HDC hdc, struct gl_drawable *gl, BOO static void wglFinish(void) { struct gl_drawable *gl; - struct wgl_context *ctx = NtCurrentTeb()->glContext; + struct x11drv_context *ctx = NtCurrentTeb()->glReserved2; HWND hwnd = NtUserWindowFromDC( ctx->hdc );
if (!(gl = get_gl_drawable( hwnd, 0 ))) pglFinish(); @@ -1821,7 +1743,7 @@ static void wglFinish(void) static void wglFlush(void) { struct gl_drawable *gl; - struct wgl_context *ctx = NtCurrentTeb()->glContext; + struct x11drv_context *ctx = NtCurrentTeb()->glReserved2; HWND hwnd = NtUserWindowFromDC( ctx->hdc );
if (!(gl = get_gl_drawable( hwnd, 0 ))) pglFlush(); @@ -1843,29 +1765,21 @@ static const GLubyte *wglGetString(GLenum name) /*********************************************************************** * X11DRV_wglCreateContextAttribsARB */ -static struct wgl_context *X11DRV_wglCreateContextAttribsARB( HDC hdc, struct wgl_context *hShareContext, - const int* attribList ) +static BOOL x11drv_context_create( HDC hdc, int format, void *share_private, const int *attribList, void **private ) { - struct wgl_context *ret; - struct gl_drawable *gl; + struct x11drv_context *ret, *hShareContext = share_private; int err = 0;
- TRACE("(%p %p %p)\n", hdc, hShareContext, attribList); - - if (!(gl = get_gl_drawable( NtUserWindowFromDC( hdc ), hdc ))) - { - RtlSetLastWin32Error( ERROR_INVALID_PIXEL_FORMAT ); - return NULL; - } + TRACE("(%p %d %p %p)\n", hdc, format, hShareContext, attribList);
if ((ret = calloc( 1, sizeof(*ret) ))) { ret->hdc = hdc; - ret->fmt = gl->format; - ret->gl3_context = TRUE; + ret->fmt = &pixel_formats[format - 1]; if (attribList) { int *pContextAttribList = &ret->attribList[0]; + ret->gl3_context = TRUE; /* attribList consists of pairs {token, value] terminated with 0 */ while(attribList[0] != 0) { @@ -1925,19 +1839,17 @@ static struct wgl_context *X11DRV_wglCreateContextAttribsARB( HDC hdc, struct wg /* In the future we should convert the GLX error to a win32 one here if needed */ WARN("Context creation failed (error %#x).\n", err); free( ret ); - ret = NULL; - } - else - { - pthread_mutex_lock( &context_mutex ); - list_add_head( &context_list, &ret->entry ); - pthread_mutex_unlock( &context_mutex ); + return FALSE; } + + pthread_mutex_lock( &context_mutex ); + list_add_head( &context_list, &ret->entry ); + pthread_mutex_unlock( &context_mutex ); }
- release_gl_drawable( gl ); TRACE( "%p -> %p\n", hdc, ret ); - return ret; + *private = ret; + return TRUE; }
static BOOL x11drv_pbuffer_create( HDC hdc, int format, BOOL largest, GLenum texture_format, GLenum texture_target, @@ -2027,7 +1939,7 @@ static UINT x11drv_pbuffer_bind( HDC hdc, void *private, GLenum buffer ) */ static int X11DRV_wglGetSwapIntervalEXT(void) { - struct wgl_context *ctx = NtCurrentTeb()->glContext; + struct x11drv_context *ctx = NtCurrentTeb()->glReserved2; struct gl_drawable *gl; int swap_interval;
@@ -2055,7 +1967,7 @@ static int X11DRV_wglGetSwapIntervalEXT(void) */ static BOOL X11DRV_wglSwapIntervalEXT(int interval) { - struct wgl_context *ctx = NtCurrentTeb()->glContext; + struct x11drv_context *ctx = NtCurrentTeb()->glReserved2; struct gl_drawable *gl; BOOL ret;
@@ -2136,24 +2048,6 @@ static const char *x11drv_init_wgl_extensions(void)
/* ARB Extensions */
- if (has_extension( glxExtensions, "GLX_ARB_create_context")) - { - register_extension( "WGL_ARB_create_context" ); - opengl_funcs.p_wglCreateContextAttribsARB = X11DRV_wglCreateContextAttribsARB; - - if (has_extension( glxExtensions, "GLX_ARB_create_context_no_error" )) - register_extension( "WGL_ARB_create_context_no_error" ); - if (has_extension( glxExtensions, "GLX_ARB_create_context_profile")) - register_extension("WGL_ARB_create_context_profile"); - } - - if (glxRequireVersion(3)) - { - register_extension( "WGL_ARB_make_current_read" ); - opengl_funcs.p_wglGetCurrentReadDCARB = (void *)1; /* never called */ - opengl_funcs.p_wglMakeContextCurrentARB = X11DRV_wglMakeContextCurrentARB; - } - if (has_extension( glxExtensions, "GLX_ARB_multisample")) register_extension( "WGL_ARB_multisample" );
if (has_extension( glxExtensions, "GLX_ARB_fbconfig_float")) @@ -2239,7 +2133,7 @@ static const char *x11drv_init_wgl_extensions(void) static BOOL glxdrv_wglSwapBuffers( HDC hdc ) { struct gl_drawable *gl; - struct wgl_context *ctx = NtCurrentTeb()->glContext; + struct x11drv_context *ctx = NtCurrentTeb()->glReserved2; INT64 ust, msc, sbc, target_sbc = 0; HWND hwnd = NtUserWindowFromDC( hdc ); Drawable drawable = 0; @@ -2313,6 +2207,11 @@ static const struct opengl_driver_funcs x11drv_driver_funcs = .p_describe_pixel_format = x11drv_describe_pixel_format, .p_init_wgl_extensions = x11drv_init_wgl_extensions, .p_set_pixel_format = x11drv_set_pixel_format, + .p_context_create = x11drv_context_create, + .p_context_destroy = x11drv_context_destroy, + .p_context_copy = x11drv_context_copy, + .p_context_share = x11drv_context_share, + .p_context_make_current = x11drv_context_make_current, .p_pbuffer_create = x11drv_pbuffer_create, .p_pbuffer_destroy = x11drv_pbuffer_destroy, .p_pbuffer_updated = x11drv_pbuffer_updated, @@ -2321,12 +2220,7 @@ static const struct opengl_driver_funcs x11drv_driver_funcs =
static struct opengl_funcs opengl_funcs = { - .p_wglCopyContext = glxdrv_wglCopyContext, - .p_wglCreateContext = glxdrv_wglCreateContext, - .p_wglDeleteContext = glxdrv_wglDeleteContext, .p_wglGetProcAddress = glxdrv_wglGetProcAddress, - .p_wglMakeCurrent = glxdrv_wglMakeCurrent, - .p_wglShareLists = glxdrv_wglShareLists, .p_wglSwapBuffers = glxdrv_wglSwapBuffers, };
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/win32u/opengl.c | 61 ++++++++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 17 deletions(-)
diff --git a/dlls/win32u/opengl.c b/dlls/win32u/opengl.c index 291dc28eba9..f5da65bd4d5 100644 --- a/dlls/win32u/opengl.c +++ b/dlls/win32u/opengl.c @@ -457,6 +457,31 @@ static UINT nulldrv_pbuffer_bind( HDC hdc, void *private, GLenum buffer ) return -1; /* use default implementation */ }
+static BOOL nulldrv_context_create( HDC hdc, int format, void *share, const int *attribs, void **private ) +{ + return FALSE; +} + +static BOOL nulldrv_context_destroy( void *private ) +{ + return FALSE; +} + +static BOOL nulldrv_context_copy( void *src_private, void *dst_private, UINT mask ) +{ + return FALSE; +} + +static BOOL nulldrv_context_share( void *src_private, void *dst_private ) +{ + return FALSE; +} + +static BOOL nulldrv_context_make_current( HDC draw_hdc, HDC read_hdc, void *private ) +{ + return FALSE; +} + static const struct opengl_driver_funcs nulldrv_funcs = { .p_init_pixel_formats = nulldrv_init_pixel_formats, @@ -467,6 +492,11 @@ static const struct opengl_driver_funcs nulldrv_funcs = .p_pbuffer_destroy = nulldrv_pbuffer_destroy, .p_pbuffer_updated = nulldrv_pbuffer_updated, .p_pbuffer_bind = nulldrv_pbuffer_bind, + .p_context_create = nulldrv_context_create, + .p_context_destroy = nulldrv_context_destroy, + .p_context_copy = nulldrv_context_copy, + .p_context_share = nulldrv_context_share, + .p_context_make_current = nulldrv_context_make_current, };
static const struct opengl_driver_funcs *memory_driver_funcs = &nulldrv_funcs; @@ -1148,6 +1178,12 @@ static void display_funcs_init(void) display_funcs->p_wglGetPixelFormat = win32u_wglGetPixelFormat; display_funcs->p_wglSetPixelFormat = win32u_wglSetPixelFormat;
+ display_funcs->p_wglCreateContext = win32u_wglCreateContext; + display_funcs->p_wglDeleteContext = win32u_wglDeleteContext; + display_funcs->p_wglCopyContext = win32u_wglCopyContext; + display_funcs->p_wglShareLists = win32u_wglShareLists; + display_funcs->p_wglMakeCurrent = win32u_wglMakeCurrent; + register_extension( wgl_extensions, ARRAY_SIZE(wgl_extensions), "WGL_ARB_extensions_string" ); display_funcs->p_wglGetExtensionsStringARB = win32u_wglGetExtensionsStringARB;
@@ -1165,23 +1201,14 @@ static void display_funcs_init(void) display_funcs->p_wglGetPixelFormatAttribfvARB = (void *)1; /* never called */ display_funcs->p_wglGetPixelFormatAttribivARB = (void *)1; /* never called */
- if (display_driver_funcs->p_context_create) - { - display_funcs->p_wglCreateContext = win32u_wglCreateContext; - display_funcs->p_wglDeleteContext = win32u_wglDeleteContext; - display_funcs->p_wglCopyContext = win32u_wglCopyContext; - display_funcs->p_wglShareLists = win32u_wglShareLists; - display_funcs->p_wglMakeCurrent = win32u_wglMakeCurrent; - - register_extension( wgl_extensions, ARRAY_SIZE(wgl_extensions), "WGL_ARB_create_context" ); - register_extension( wgl_extensions, ARRAY_SIZE(wgl_extensions), "WGL_ARB_create_context_no_error" ); - register_extension( wgl_extensions, ARRAY_SIZE(wgl_extensions), "WGL_ARB_create_context_profile" ); - display_funcs->p_wglCreateContextAttribsARB = win32u_wglCreateContextAttribsARB; - - register_extension( wgl_extensions, ARRAY_SIZE(wgl_extensions), "WGL_ARB_make_current_read" ); - display_funcs->p_wglGetCurrentReadDCARB = (void *)1; /* never called */ - display_funcs->p_wglMakeContextCurrentARB = win32u_wglMakeContextCurrentARB; - } + register_extension( wgl_extensions, ARRAY_SIZE(wgl_extensions), "WGL_ARB_create_context" ); + register_extension( wgl_extensions, ARRAY_SIZE(wgl_extensions), "WGL_ARB_create_context_no_error" ); + register_extension( wgl_extensions, ARRAY_SIZE(wgl_extensions), "WGL_ARB_create_context_profile" ); + display_funcs->p_wglCreateContextAttribsARB = win32u_wglCreateContextAttribsARB; + + register_extension( wgl_extensions, ARRAY_SIZE(wgl_extensions), "WGL_ARB_make_current_read" ); + display_funcs->p_wglGetCurrentReadDCARB = (void *)1; /* never called */ + display_funcs->p_wglMakeContextCurrentARB = win32u_wglMakeContextCurrentARB;
register_extension( wgl_extensions, ARRAY_SIZE(wgl_extensions), "WGL_ARB_pbuffer" ); display_funcs->p_wglCreatePbufferARB = win32u_wglCreatePbufferARB;
Dmitry Timoshkov (@dmitry) commented about dlls/win32u/opengl.c:
if (descr->cRedShift == 8) gl_format = OSMESA_ARGB;
else if (descr->cRedShift == 16) gl_format = OSMESA_BGRA;
if (descr.cRedShift == 8) gl_format = OSMESA_ARGB;
case 24:else if (descr.cRedShift == 16) gl_format = OSMESA_BGRA; else gl_format = OSMESA_RGBA; break;
gl_format = descr->cRedShift == 16 ? OSMESA_BGR : OSMESA_RGB;
case 16: gl_format = OSMESA_RGB_565; break; default:gl_format = descr.cRedShift == 16 ? OSMESA_BGR : OSMESA_RGB; break;
return NULL;
return FALSE;
Why are you changing return value to FALSE? (here and below multiple times)
On Wed Apr 16 10:28:38 2025 +0000, Dmitry Timoshkov wrote:
Why are you changing return value to FALSE? (here and below multiple times)
That's from a bad patch split sorry, it belongs to the next change.