From: Rémi Bernon rbernon@codeweavers.com
--- dlls/win32u/dibdrv/dc.c | 229 ------------------------------------ dlls/win32u/ntgdi_private.h | 1 - dlls/win32u/opengl.c | 190 ++++++++++++++++++++++++++++++ 3 files changed, 190 insertions(+), 230 deletions(-)
diff --git a/dlls/win32u/dibdrv/dc.c b/dlls/win32u/dibdrv/dc.c index 60cd41142b2..e141965b697 100644 --- a/dlls/win32u/dibdrv/dc.c +++ b/dlls/win32u/dibdrv/dc.c @@ -34,8 +34,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(dib);
-static const struct osmesa_funcs *osmesa_funcs; - static const DWORD bit_fields_888[3] = {0xff0000, 0x00ff00, 0x0000ff}; static const DWORD bit_fields_555[3] = {0x7c00, 0x03e0, 0x001f};
@@ -398,233 +396,6 @@ static UINT dibdrv_SetBoundsRect( PHYSDEV dev, RECT *rect, UINT flags ) return DCB_RESET; /* we don't have device-specific bounds */ }
-struct wgl_context; - -static const struct -{ - BYTE color_bits; - BYTE red_bits, red_shift; - BYTE green_bits, green_shift; - BYTE blue_bits, blue_shift; - BYTE alpha_bits, alpha_shift; - BYTE accum_bits; - BYTE depth_bits; - BYTE stencil_bits; -} pixel_formats[] = -{ - { 32, 8, 16, 8, 8, 8, 0, 8, 24, 16, 32, 8 }, - { 32, 8, 16, 8, 8, 8, 0, 8, 24, 16, 16, 8 }, - { 32, 8, 0, 8, 8, 8, 16, 8, 24, 16, 32, 8 }, - { 32, 8, 0, 8, 8, 8, 16, 8, 24, 16, 16, 8 }, - { 32, 8, 8, 8, 16, 8, 24, 8, 0, 16, 32, 8 }, - { 32, 8, 8, 8, 16, 8, 24, 8, 0, 16, 16, 8 }, - { 24, 8, 0, 8, 8, 8, 16, 0, 0, 16, 32, 8 }, - { 24, 8, 0, 8, 8, 8, 16, 0, 0, 16, 16, 8 }, - { 24, 8, 16, 8, 8, 8, 0, 0, 0, 16, 32, 8 }, - { 24, 8, 16, 8, 8, 8, 0, 0, 0, 16, 16, 8 }, - { 16, 5, 0, 6, 5, 5, 11, 0, 0, 16, 32, 8 }, - { 16, 5, 0, 6, 5, 5, 11, 0, 0, 16, 16, 8 }, -}; - -static void describe_pixel_format( int fmt, PIXELFORMATDESCRIPTOR *descr ) -{ - memset( descr, 0, sizeof(*descr) ); - descr->nSize = sizeof(*descr); - descr->nVersion = 1; - descr->dwFlags = PFD_SUPPORT_GDI | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_BITMAP | PFD_GENERIC_FORMAT; - descr->iPixelType = PFD_TYPE_RGBA; - descr->cColorBits = pixel_formats[fmt - 1].color_bits; - descr->cRedBits = pixel_formats[fmt - 1].red_bits; - descr->cRedShift = pixel_formats[fmt - 1].red_shift; - descr->cGreenBits = pixel_formats[fmt - 1].green_bits; - descr->cGreenShift = pixel_formats[fmt - 1].green_shift; - descr->cBlueBits = pixel_formats[fmt - 1].blue_bits; - descr->cBlueShift = pixel_formats[fmt - 1].blue_shift; - descr->cAlphaBits = pixel_formats[fmt - 1].alpha_bits; - descr->cAlphaShift = pixel_formats[fmt - 1].alpha_shift; - descr->cAccumBits = pixel_formats[fmt - 1].accum_bits; - descr->cAccumRedBits = pixel_formats[fmt - 1].accum_bits / 4; - descr->cAccumGreenBits = pixel_formats[fmt - 1].accum_bits / 4; - descr->cAccumBlueBits = pixel_formats[fmt - 1].accum_bits / 4; - descr->cAccumAlphaBits = pixel_formats[fmt - 1].accum_bits / 4; - descr->cDepthBits = pixel_formats[fmt - 1].depth_bits; - descr->cStencilBits = pixel_formats[fmt - 1].stencil_bits; - descr->cAuxBuffers = 0; - descr->iLayerType = PFD_MAIN_PLANE; -} - -/*********************************************************************** - * dibdrv_wglCopyContext - */ -static BOOL dibdrv_wglCopyContext( struct wgl_context *src, struct wgl_context *dst, UINT mask ) -{ - FIXME( "not supported yet\n" ); - return FALSE; -} - -/*********************************************************************** - * dibdrv_wglDeleteContext - */ -static BOOL dibdrv_wglDeleteContext( struct wgl_context *context ) -{ - if (!osmesa_funcs) return FALSE; - return osmesa_funcs->delete_context( context ); -} - -/*********************************************************************** - * dibdrv_wglGetPixelFormat - */ -static int dibdrv_wglGetPixelFormat( HDC hdc ) -{ - DC *dc = get_dc_ptr( hdc ); - int ret = 0; - - if (dc) - { - ret = dc->pixel_format; - release_dc_ptr( dc ); - } - return ret; -} - -/*********************************************************************** - * dibdrv_wglCreateContext - */ -static struct wgl_context *dibdrv_wglCreateContext( HDC hdc ) -{ - PIXELFORMATDESCRIPTOR descr; - int format = dibdrv_wglGetPixelFormat( hdc ); - - if (!format) format = 1; - if (format <= 0 || format > ARRAY_SIZE( pixel_formats )) return NULL; - describe_pixel_format( format, &descr ); - - if (!osmesa_funcs) return NULL; - return osmesa_funcs->create_context( hdc, &descr ); -} - -/*********************************************************************** - * dibdrv_wglGetProcAddress - */ -static PROC dibdrv_wglGetProcAddress( const char *proc ) -{ - if (!strncmp( proc, "wgl", 3 )) return NULL; - if (!osmesa_funcs) return NULL; - return osmesa_funcs->get_proc_address( proc ); -} - -/*********************************************************************** - * dibdrv_wglMakeCurrent - */ -static BOOL dibdrv_wglMakeCurrent( HDC hdc, struct wgl_context *context ) -{ - HBITMAP bitmap; - BITMAPOBJ *bmp; - dib_info dib; - BOOL ret = FALSE; - - if (!osmesa_funcs) return FALSE; - if (!context) return osmesa_funcs->make_current( NULL, NULL, 0, 0, 0, 0 ); - - bitmap = NtGdiGetDCObject( hdc, NTGDI_OBJ_SURF ); - bmp = GDI_GetObjPtr( bitmap, NTGDI_OBJ_BITMAP ); - if (!bmp) return FALSE; - - if (init_dib_info_from_bitmapobj( &dib, bmp )) - { - char *bits; - int width = dib.rect.right - dib.rect.left; - int height = dib.rect.bottom - dib.rect.top; - - 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; - bits += dib.rect.left * dib.bit_count / 8; - - TRACE( "context %p bits %p size %ux%u\n", context, bits, width, height ); - - ret = osmesa_funcs->make_current( context, bits, width, height, dib.bit_count, dib.stride ); - } - GDI_ReleaseObj( bitmap ); - return ret; -} - -/********************************************************************** - * dibdrv_wglSetPixelFormat - */ -static BOOL dibdrv_wglSetPixelFormat( HDC hdc, int fmt, const PIXELFORMATDESCRIPTOR *descr ) -{ - if (fmt <= 0 || fmt > ARRAY_SIZE( pixel_formats )) return FALSE; - return NtGdiSetPixelFormat( hdc, fmt ); -} - -/*********************************************************************** - * dibdrv_wglShareLists - */ -static BOOL dibdrv_wglShareLists( struct wgl_context *org, struct wgl_context *dest ) -{ - FIXME( "not supported yet\n" ); - return FALSE; -} - -/*********************************************************************** - * dibdrv_wglSwapBuffers - */ -static BOOL dibdrv_wglSwapBuffers( HDC hdc ) -{ - return TRUE; -} - -/*********************************************************************** - * dibdrv_get_pixel_formats - */ -static void dibdrv_get_pixel_formats( struct wgl_pixel_format *formats, - UINT max_formats, UINT *num_formats, - UINT *num_onscreen_formats ) -{ - UINT num_pixel_formats = ARRAY_SIZE( pixel_formats ); - UINT i; - - if (formats) - { - for (i = 0; i < min( max_formats, num_pixel_formats ); ++i) - describe_pixel_format( i + 1, &formats[i].pfd ); - } - *num_formats = *num_onscreen_formats = num_pixel_formats; -} - -static struct opengl_funcs opengl_funcs = -{ - { - dibdrv_wglCopyContext, /* p_wglCopyContext */ - dibdrv_wglCreateContext, /* p_wglCreateContext */ - dibdrv_wglDeleteContext, /* p_wglDeleteContext */ - dibdrv_wglGetPixelFormat, /* p_wglGetPixelFormat */ - dibdrv_wglGetProcAddress, /* p_wglGetProcAddress */ - dibdrv_wglMakeCurrent, /* p_wglMakeCurrent */ - dibdrv_wglSetPixelFormat, /* p_wglSetPixelFormat */ - dibdrv_wglShareLists, /* p_wglShareLists */ - dibdrv_wglSwapBuffers, /* p_wglSwapBuffers */ - dibdrv_get_pixel_formats, /* p_get_pixel_formats */ - } -}; - -/********************************************************************** - * dibdrv_get_wgl_driver - */ -struct opengl_funcs *dibdrv_get_wgl_driver(void) -{ - if (!osmesa_funcs && !(osmesa_funcs = init_opengl_lib())) - { - static int warned; - if (!warned++) ERR( "OSMesa not available, no OpenGL bitmap support\n" ); - return (void *)-1; - } - osmesa_funcs->get_gl_funcs( &opengl_funcs ); - return &opengl_funcs; -} - const struct gdi_dc_funcs dib_driver = { NULL, /* pAbortDoc */ diff --git a/dlls/win32u/ntgdi_private.h b/dlls/win32u/ntgdi_private.h index f1cbdfbe591..99ebb127d68 100644 --- a/dlls/win32u/ntgdi_private.h +++ b/dlls/win32u/ntgdi_private.h @@ -219,7 +219,6 @@ extern UINT get_dib_dc_color_table( HDC hdc, UINT startpos, UINT entries, extern UINT set_dib_dc_color_table( HDC hdc, UINT startpos, UINT entries, const RGBQUAD *colors ); extern void dibdrv_set_window_surface( DC *dc, struct window_surface *surface ); -extern struct opengl_funcs *dibdrv_get_wgl_driver(void);
/* driver.c */ extern const struct gdi_dc_funcs null_driver; diff --git a/dlls/win32u/opengl.c b/dlls/win32u/opengl.c index 0c4b77876d8..1fd1a35b51e 100644 --- a/dlls/win32u/opengl.c +++ b/dlls/win32u/opengl.c @@ -33,8 +33,198 @@ #include "wine/wgl.h" #include "wine/wgl_driver.h"
+#include "dibdrv/dibdrv.h" + WINE_DEFAULT_DEBUG_CHANNEL(wgl);
+static const struct osmesa_funcs *osmesa_funcs; + +struct wgl_context; + +static const struct +{ + BYTE color_bits; + BYTE red_bits, red_shift; + BYTE green_bits, green_shift; + BYTE blue_bits, blue_shift; + BYTE alpha_bits, alpha_shift; + BYTE accum_bits; + BYTE depth_bits; + BYTE stencil_bits; +} pixel_formats[] = +{ + { 32, 8, 16, 8, 8, 8, 0, 8, 24, 16, 32, 8 }, + { 32, 8, 16, 8, 8, 8, 0, 8, 24, 16, 16, 8 }, + { 32, 8, 0, 8, 8, 8, 16, 8, 24, 16, 32, 8 }, + { 32, 8, 0, 8, 8, 8, 16, 8, 24, 16, 16, 8 }, + { 32, 8, 8, 8, 16, 8, 24, 8, 0, 16, 32, 8 }, + { 32, 8, 8, 8, 16, 8, 24, 8, 0, 16, 16, 8 }, + { 24, 8, 0, 8, 8, 8, 16, 0, 0, 16, 32, 8 }, + { 24, 8, 0, 8, 8, 8, 16, 0, 0, 16, 16, 8 }, + { 24, 8, 16, 8, 8, 8, 0, 0, 0, 16, 32, 8 }, + { 24, 8, 16, 8, 8, 8, 0, 0, 0, 16, 16, 8 }, + { 16, 5, 0, 6, 5, 5, 11, 0, 0, 16, 32, 8 }, + { 16, 5, 0, 6, 5, 5, 11, 0, 0, 16, 16, 8 }, +}; + +static void describe_pixel_format( int fmt, PIXELFORMATDESCRIPTOR *descr ) +{ + memset( descr, 0, sizeof(*descr) ); + descr->nSize = sizeof(*descr); + descr->nVersion = 1; + descr->dwFlags = PFD_SUPPORT_GDI | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_BITMAP | PFD_GENERIC_FORMAT; + descr->iPixelType = PFD_TYPE_RGBA; + descr->cColorBits = pixel_formats[fmt - 1].color_bits; + descr->cRedBits = pixel_formats[fmt - 1].red_bits; + descr->cRedShift = pixel_formats[fmt - 1].red_shift; + descr->cGreenBits = pixel_formats[fmt - 1].green_bits; + descr->cGreenShift = pixel_formats[fmt - 1].green_shift; + descr->cBlueBits = pixel_formats[fmt - 1].blue_bits; + descr->cBlueShift = pixel_formats[fmt - 1].blue_shift; + descr->cAlphaBits = pixel_formats[fmt - 1].alpha_bits; + descr->cAlphaShift = pixel_formats[fmt - 1].alpha_shift; + descr->cAccumBits = pixel_formats[fmt - 1].accum_bits; + descr->cAccumRedBits = pixel_formats[fmt - 1].accum_bits / 4; + descr->cAccumGreenBits = pixel_formats[fmt - 1].accum_bits / 4; + descr->cAccumBlueBits = pixel_formats[fmt - 1].accum_bits / 4; + descr->cAccumAlphaBits = pixel_formats[fmt - 1].accum_bits / 4; + descr->cDepthBits = pixel_formats[fmt - 1].depth_bits; + descr->cStencilBits = pixel_formats[fmt - 1].stencil_bits; + descr->cAuxBuffers = 0; + descr->iLayerType = PFD_MAIN_PLANE; +} + +static BOOL dibdrv_wglCopyContext( struct wgl_context *src, struct wgl_context *dst, UINT mask ) +{ + FIXME( "not supported yet\n" ); + return FALSE; +} + +static BOOL dibdrv_wglDeleteContext( struct wgl_context *context ) +{ + if (!osmesa_funcs) return FALSE; + return osmesa_funcs->delete_context( context ); +} + +static int dibdrv_wglGetPixelFormat( HDC hdc ) +{ + DC *dc = get_dc_ptr( hdc ); + int ret = 0; + + if (dc) + { + ret = dc->pixel_format; + release_dc_ptr( dc ); + } + return ret; +} + +static struct wgl_context *dibdrv_wglCreateContext( HDC hdc ) +{ + PIXELFORMATDESCRIPTOR descr; + int format = dibdrv_wglGetPixelFormat( hdc ); + + if (!format) format = 1; + if (format <= 0 || format > ARRAY_SIZE( pixel_formats )) return NULL; + describe_pixel_format( format, &descr ); + + if (!osmesa_funcs) return NULL; + return osmesa_funcs->create_context( hdc, &descr ); +} + +static PROC dibdrv_wglGetProcAddress( const char *proc ) +{ + if (!strncmp( proc, "wgl", 3 )) return NULL; + if (!osmesa_funcs) return NULL; + return osmesa_funcs->get_proc_address( proc ); +} + +static BOOL dibdrv_wglMakeCurrent( HDC hdc, struct wgl_context *context ) +{ + HBITMAP bitmap; + BITMAPOBJ *bmp; + dib_info dib; + BOOL ret = FALSE; + + if (!osmesa_funcs) return FALSE; + if (!context) return osmesa_funcs->make_current( NULL, NULL, 0, 0, 0, 0 ); + + bitmap = NtGdiGetDCObject( hdc, NTGDI_OBJ_SURF ); + bmp = GDI_GetObjPtr( bitmap, NTGDI_OBJ_BITMAP ); + if (!bmp) return FALSE; + + if (init_dib_info_from_bitmapobj( &dib, bmp )) + { + char *bits; + int width = dib.rect.right - dib.rect.left; + int height = dib.rect.bottom - dib.rect.top; + + 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; + bits += dib.rect.left * dib.bit_count / 8; + + TRACE( "context %p bits %p size %ux%u\n", context, bits, width, height ); + + ret = osmesa_funcs->make_current( context, bits, width, height, dib.bit_count, dib.stride ); + } + GDI_ReleaseObj( bitmap ); + return ret; +} + +static BOOL dibdrv_wglSetPixelFormat( HDC hdc, int fmt, const PIXELFORMATDESCRIPTOR *descr ) +{ + if (fmt <= 0 || fmt > ARRAY_SIZE( pixel_formats )) return FALSE; + return NtGdiSetPixelFormat( hdc, fmt ); +} + +static BOOL dibdrv_wglShareLists( struct wgl_context *org, struct wgl_context *dest ) +{ + FIXME( "not supported yet\n" ); + return FALSE; +} + +static BOOL dibdrv_wglSwapBuffers( HDC hdc ) +{ + return TRUE; +} + +static void dibdrv_get_pixel_formats( struct wgl_pixel_format *formats, UINT max_formats, + UINT *num_formats, UINT *num_onscreen_formats ) +{ + UINT i, num_pixel_formats = ARRAY_SIZE( pixel_formats ); + + for (i = 0; formats && i < min( max_formats, num_pixel_formats ); ++i) + describe_pixel_format( i + 1, &formats[i].pfd ); + + *num_formats = *num_onscreen_formats = num_pixel_formats; +} + +static struct opengl_funcs dibdrv_opengl_funcs = +{ + .wgl.p_wglCopyContext = dibdrv_wglCopyContext, + .wgl.p_wglCreateContext = dibdrv_wglCreateContext, + .wgl.p_wglDeleteContext = dibdrv_wglDeleteContext, + .wgl.p_wglGetPixelFormat = dibdrv_wglGetPixelFormat, + .wgl.p_wglGetProcAddress = dibdrv_wglGetProcAddress, + .wgl.p_wglMakeCurrent = dibdrv_wglMakeCurrent, + .wgl.p_wglSetPixelFormat = dibdrv_wglSetPixelFormat, + .wgl.p_wglShareLists = dibdrv_wglShareLists, + .wgl.p_wglSwapBuffers = dibdrv_wglSwapBuffers, + .wgl.p_get_pixel_formats = dibdrv_get_pixel_formats, +}; + +static struct opengl_funcs *dibdrv_get_wgl_driver(void) +{ + if (!osmesa_funcs && !(osmesa_funcs = init_opengl_lib())) + { + static int warned; + if (!warned++) ERR( "OSMesa not available, no OpenGL bitmap support\n" ); + return (void *)-1; + } + osmesa_funcs->get_gl_funcs( &dibdrv_opengl_funcs ); + return &dibdrv_opengl_funcs; +} + /*********************************************************************** * __wine_get_wgl_driver (win32u.@) */