From 0d30daa8e4221a40a295c6714777b05959570af3 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Mon, 4 Feb 2008 14:36:18 +0100 Subject: [PATCH] winex11: Abstract the depth->bpp conversion and use it in X11DRV_DIB_CreateDIBFromPixmap. --- dlls/winex11.drv/dib.c | 2 +- dlls/winex11.drv/x11drv.h | 2 ++ dlls/winex11.drv/x11drv_main.c | 61 ++++++++++++++++++---------------- 3 files changed, 35 insertions(+), 30 deletions(-) diff --git a/dlls/winex11.drv/dib.c b/dlls/winex11.drv/dib.c index 2f0bbc94feb..b05d90408e3 100644 --- a/dlls/winex11.drv/dib.c +++ b/dlls/winex11.drv/dib.c @@ -4856,7 +4856,7 @@ HGLOBAL X11DRV_DIB_CreateDIBFromPixmap(Pixmap pixmap, HDC hdc) * Create an HBITMAP with the same dimensions and BPP as the pixmap, * and make it a container for the pixmap passed. */ - hBmp = CreateBitmap( width, height, 1, depth, NULL ); + if (!(hBmp = CreateBitmap( width, height, 1, depth_to_bpp(depth), NULL ))) return 0; /* force bitmap to be owned by a screen DC */ hdcMem = CreateCompatibleDC( hdc ); diff --git a/dlls/winex11.drv/x11drv.h b/dlls/winex11.drv/x11drv.h index ffd04699ba6..7af082c7019 100644 --- a/dlls/winex11.drv/x11drv.h +++ b/dlls/winex11.drv/x11drv.h @@ -463,6 +463,8 @@ extern BOOL X11DRV_IsSolidColor(COLORREF color); extern COLORREF X11DRV_PALETTE_ToLogical(int pixel); extern int X11DRV_PALETTE_ToPhysical(X11DRV_PDEVICE *physDev, COLORREF color); +extern unsigned int depth_to_bpp( unsigned int depth ); + /* GDI escapes */ #define X11DRV_ESCAPE 6789 diff --git a/dlls/winex11.drv/x11drv_main.c b/dlls/winex11.drv/x11drv_main.c index 8d822ef9dd5..6f682c2a9e5 100644 --- a/dlls/winex11.drv/x11drv_main.c +++ b/dlls/winex11.drv/x11drv_main.c @@ -277,6 +277,37 @@ void wine_tsx11_unlock(void) } +/*********************************************************************** + * depth_to_bpp + * + * Convert X11-reported depth to the BPP value that Windows apps expect to see. + */ +unsigned int depth_to_bpp( unsigned int depth ) +{ + switch (depth) + { + case 1: + case 8: + return depth; + case 15: + case 16: + return 16; + case 24: + /* This is not necessarily right. X11 always has 24 bits per pixel, but it can run + * with 24 bit framebuffers and 32 bit framebuffers. It doesn't make any difference + * for windowing, but gl applications can get visuals with alpha channels. So we + * should check the framebuffer and/or opengl formats available to find out what the + * framebuffer actually does + */ + case 32: + return 32; + default: + FIXME( "Unexpected X11 depth %d bpp, what to report to app?\n", depth ); + return depth; + } +} + + /*********************************************************************** * get_config_key * @@ -491,35 +522,7 @@ static BOOL process_attach(void) screen_depth = desktop_vi->depth; XFree(desktop_vi); } - - switch(screen_depth) { - case 8: - screen_bpp = 8; - break; - - case 15: - /* In GetDeviceCaps MSDN description explicitly states that - * in 15 bpp mode 16 is returned. - */ - /* fall through */ - case 16: - screen_bpp = 16; - break; - - case 24: - /* This is not necessarily right. X11 always has 24 bits per pixel, but it can run - * with 24 bit framebuffers and 32 bit framebuffers. It doesn't make any difference - * for windowing, but gl applications can get visuals with alpha channels. So we - * should check the framebuffer and/or opengl formats available to find out what the - * framebuffer actually does - */ - screen_bpp = 32; - break; - - default: - FIXME("Unexpected X11 depth %d bpp, what to report to app?\n", screen_depth); - screen_bpp = screen_depth; - } + screen_bpp = depth_to_bpp( screen_depth ); XInternAtoms( display, (char **)atom_names, NB_XATOMS - FIRST_XATOM, False, X11DRV_Atoms );