Commit e7e576d6 authored by Alexandre Julliard's avatar Alexandre Julliard

user32: Also user the thread-safe display DC in icon functions.

parent daa832f4
...@@ -92,15 +92,20 @@ struct animated_cursoricon_object ...@@ -92,15 +92,20 @@ struct animated_cursoricon_object
HICON frames[1]; /* list of animated cursor frames */ HICON frames[1]; /* list of animated cursor frames */
}; };
static HDC get_screen_dc(void) static HBITMAP create_color_bitmap( int width, int height )
{ {
static const WCHAR DISPLAYW[] = {'D','I','S','P','L','A','Y',0}; HDC hdc = get_display_dc();
static HDC screen_dc; HBITMAP ret = CreateCompatibleBitmap( hdc, width, height );
release_display_dc( hdc );
if (!screen_dc) return ret;
screen_dc = CreateDCW( DISPLAYW, NULL, NULL, NULL ); }
return screen_dc; static int get_display_bpp(void)
{
HDC hdc = get_display_dc();
int ret = GetDeviceCaps( hdc, BITSPIXEL );
release_display_dc( hdc );
return ret;
} }
static HICON alloc_icon_handle( BOOL is_ani, UINT num_steps ) static HICON alloc_icon_handle( BOOL is_ani, UINT num_steps )
...@@ -811,7 +816,6 @@ static HICON create_icon_from_bmi( const BITMAPINFO *bmi, DWORD maxsize, HMODULE ...@@ -811,7 +816,6 @@ static HICON create_icon_from_bmi( const BITMAPINFO *bmi, DWORD maxsize, HMODULE
BOOL ret = FALSE; BOOL ret = FALSE;
BOOL do_stretch; BOOL do_stretch;
HICON hObj = 0; HICON hObj = 0;
HDC screen_dc;
HDC hdc = 0; HDC hdc = 0;
LONG bmi_width, bmi_height; LONG bmi_width, bmi_height;
WORD bpp; WORD bpp;
...@@ -875,8 +879,6 @@ static HICON create_icon_from_bmi( const BITMAPINFO *bmi, DWORD maxsize, HMODULE ...@@ -875,8 +879,6 @@ static HICON create_icon_from_bmi( const BITMAPINFO *bmi, DWORD maxsize, HMODULE
hotspot.y = (hotspot.y * height) / (bmi_height / 2); hotspot.y = (hotspot.y * height) / (bmi_height / 2);
} }
if (!(screen_dc = get_screen_dc())) return 0;
if (!(bmi_copy = HeapAlloc( GetProcessHeap(), 0, max( size, FIELD_OFFSET( BITMAPINFO, bmiColors[2] ))))) if (!(bmi_copy = HeapAlloc( GetProcessHeap(), 0, max( size, FIELD_OFFSET( BITMAPINFO, bmiColors[2] )))))
return 0; return 0;
if (!(hdc = CreateCompatibleDC( 0 ))) goto done; if (!(hdc = CreateCompatibleDC( 0 ))) goto done;
...@@ -906,8 +908,7 @@ static HICON create_icon_from_bmi( const BITMAPINFO *bmi, DWORD maxsize, HMODULE ...@@ -906,8 +908,7 @@ static HICON create_icon_from_bmi( const BITMAPINFO *bmi, DWORD maxsize, HMODULE
else else
{ {
if (!(mask = CreateBitmap( width, height, 1, 1, NULL ))) goto done; if (!(mask = CreateBitmap( width, height, 1, 1, NULL ))) goto done;
if (!(color = CreateBitmap( width, height, GetDeviceCaps( screen_dc, PLANES ), if (!(color = create_color_bitmap( width, height )))
GetDeviceCaps( screen_dc, BITSPIXEL ), NULL )))
{ {
DeleteObject( mask ); DeleteObject( mask );
goto done; goto done;
...@@ -1830,11 +1831,7 @@ INT WINAPI LookupIconIdFromDirectoryEx( LPBYTE xdir, BOOL bIcon, ...@@ -1830,11 +1831,7 @@ INT WINAPI LookupIconIdFromDirectoryEx( LPBYTE xdir, BOOL bIcon,
if( dir && !dir->idReserved && (dir->idType & 3) ) if( dir && !dir->idReserved && (dir->idType & 3) )
{ {
const CURSORICONDIRENTRY* entry; const CURSORICONDIRENTRY* entry;
int depth = (cFlag & LR_MONOCHROME) ? 1 : get_display_bpp();
const HDC hdc = GetDC(0);
const int depth = (cFlag & LR_MONOCHROME) ?
1 : GetDeviceCaps(hdc, BITSPIXEL);
ReleaseDC(0, hdc);
if( bIcon ) if( bIcon )
entry = CURSORICON_FindBestIconRes( dir, ~0u, width, height, depth, LR_DEFAULTSIZE ); entry = CURSORICON_FindBestIconRes( dir, ~0u, width, height, depth, LR_DEFAULTSIZE );
...@@ -2168,7 +2165,7 @@ HICON WINAPI CreateIconIndirect(PICONINFO iconinfo) ...@@ -2168,7 +2165,7 @@ HICON WINAPI CreateIconIndirect(PICONINFO iconinfo)
height = bmpXor.bmHeight; height = bmpXor.bmHeight;
if (bmpXor.bmPlanes * bmpXor.bmBitsPixel != 1 || bmpAnd.bmPlanes * bmpAnd.bmBitsPixel != 1) if (bmpXor.bmPlanes * bmpXor.bmBitsPixel != 1 || bmpAnd.bmPlanes * bmpAnd.bmBitsPixel != 1)
{ {
color = CreateCompatibleBitmap( get_screen_dc(), width, height ); color = create_color_bitmap( width, height );
mask = CreateBitmap( width, height, 1, 1, NULL ); mask = CreateBitmap( width, height, 1, 1, NULL );
} }
else mask = CreateBitmap( width, height * 2, 1, 1, NULL ); else mask = CreateBitmap( width, height * 2, 1, 1, NULL );
...@@ -2498,7 +2495,6 @@ static HBITMAP BITMAP_Load( HINSTANCE instance, LPCWSTR name, ...@@ -2498,7 +2495,6 @@ static HBITMAP BITMAP_Load( HINSTANCE instance, LPCWSTR name,
DWORD compr_dummy, offbits = 0; DWORD compr_dummy, offbits = 0;
INT bm_type; INT bm_type;
HDC screen_mem_dc = NULL; HDC screen_mem_dc = NULL;
HDC screen_dc;
if (!(loadflags & LR_LOADFROMFILE)) if (!(loadflags & LR_LOADFROMFILE))
{ {
...@@ -2578,22 +2574,21 @@ static HBITMAP BITMAP_Load( HINSTANCE instance, LPCWSTR name, ...@@ -2578,22 +2574,21 @@ static HBITMAP BITMAP_Load( HINSTANCE instance, LPCWSTR name,
if (new_height < 0) new_height = -new_height; if (new_height < 0) new_height = -new_height;
screen_dc = get_screen_dc(); if (!(screen_mem_dc = CreateCompatibleDC( 0 ))) goto end;
if (!(screen_mem_dc = CreateCompatibleDC( screen_dc ))) goto end;
bits = (char *)info + (offbits ? offbits : size); bits = (char *)info + (offbits ? offbits : size);
if (loadflags & LR_CREATEDIBSECTION) if (loadflags & LR_CREATEDIBSECTION)
{ {
scaled_info->bmiHeader.biCompression = 0; /* DIBSection can't be compressed */ scaled_info->bmiHeader.biCompression = 0; /* DIBSection can't be compressed */
hbitmap = CreateDIBSection(screen_dc, scaled_info, DIB_RGB_COLORS, NULL, 0, 0); hbitmap = CreateDIBSection(0, scaled_info, DIB_RGB_COLORS, NULL, 0, 0);
} }
else else
{ {
if (is_dib_monochrome(fix_info)) if (is_dib_monochrome(fix_info))
hbitmap = CreateBitmap(new_width, new_height, 1, 1, NULL); hbitmap = CreateBitmap(new_width, new_height, 1, 1, NULL);
else else
hbitmap = CreateCompatibleBitmap(screen_dc, new_width, new_height); hbitmap = create_color_bitmap(new_width, new_height);
} }
orig_bm = SelectObject(screen_mem_dc, hbitmap); orig_bm = SelectObject(screen_mem_dc, hbitmap);
...@@ -2672,13 +2667,7 @@ HANDLE WINAPI LoadImageW( HINSTANCE hinst, LPCWSTR name, UINT type, ...@@ -2672,13 +2667,7 @@ HANDLE WINAPI LoadImageW( HINSTANCE hinst, LPCWSTR name, UINT type,
case IMAGE_ICON: case IMAGE_ICON:
case IMAGE_CURSOR: case IMAGE_CURSOR:
depth = 1; depth = 1;
if (!(loadflags & LR_MONOCHROME)) if (!(loadflags & LR_MONOCHROME)) depth = get_display_bpp();
{
HDC screen_dc;
if ((screen_dc = get_screen_dc()))
depth = GetDeviceCaps( screen_dc, BITSPIXEL );
}
return CURSORICON_Load(hinst, name, desiredx, desiredy, depth, (type == IMAGE_CURSOR), loadflags); return CURSORICON_Load(hinst, name, desiredx, desiredy, depth, (type == IMAGE_CURSOR), loadflags);
} }
return 0; return 0;
...@@ -2818,37 +2807,18 @@ HANDLE WINAPI CopyImage( HANDLE hnd, UINT type, INT desiredx, ...@@ -2818,37 +2807,18 @@ HANDLE WINAPI CopyImage( HANDLE hnd, UINT type, INT desiredx,
} }
if (monochrome) if (monochrome)
{
res = CreateBitmap(desiredx, desiredy, 1, 1, NULL); res = CreateBitmap(desiredx, desiredy, 1, 1, NULL);
}
else else
{ res = create_color_bitmap(desiredx, desiredy);
HDC screenDC = GetDC(NULL);
res = CreateCompatibleBitmap(screenDC, desiredx, desiredy);
ReleaseDC(NULL, screenDC);
}
} }
if (res) if (res)
{ {
/* Only copy the bitmap if it's a DIB section or if it's /* Only copy the bitmap if it's a DIB section or if it's
compatible to the screen */ compatible to the screen */
BOOL copyContents; if (objSize == sizeof(DIBSECTION) ||
ds.dsBm.bmBitsPixel == 1 ||
if (objSize == sizeof(DIBSECTION)) ds.dsBm.bmBitsPixel == get_display_bpp())
{
copyContents = TRUE;
}
else
{
HDC screenDC = GetDC(NULL);
int screen_depth = GetDeviceCaps(screenDC, BITSPIXEL);
ReleaseDC(NULL, screenDC);
copyContents = (ds.dsBm.bmBitsPixel == 1 || ds.dsBm.bmBitsPixel == screen_depth);
}
if (copyContents)
{ {
/* The source bitmap may already be selected in a device context, /* The source bitmap may already be selected in a device context,
use GetDIBits/StretchDIBits and not StretchBlt */ use GetDIBits/StretchDIBits and not StretchBlt */
...@@ -2901,7 +2871,7 @@ HANDLE WINAPI CopyImage( HANDLE hnd, UINT type, INT desiredx, ...@@ -2901,7 +2871,7 @@ HANDLE WINAPI CopyImage( HANDLE hnd, UINT type, INT desiredx,
{ {
struct cursoricon_object *icon; struct cursoricon_object *icon;
HICON res = 0; HICON res = 0;
int depth = (flags & LR_MONOCHROME) ? 1 : GetDeviceCaps( get_screen_dc(), BITSPIXEL ); int depth = (flags & LR_MONOCHROME) ? 1 : get_display_bpp();
if (flags & LR_DEFAULTSIZE) if (flags & LR_DEFAULTSIZE)
{ {
......
...@@ -612,19 +612,15 @@ static BOOL init_entry_string( struct sysparam_entry *entry, const WCHAR *str ) ...@@ -612,19 +612,15 @@ static BOOL init_entry_string( struct sysparam_entry *entry, const WCHAR *str )
return init_entry( entry, str, (strlenW(str) + 1) * sizeof(WCHAR), REG_SZ ); return init_entry( entry, str, (strlenW(str) + 1) * sizeof(WCHAR), REG_SZ );
} }
static inline HDC get_display_dc(void) HDC get_display_dc(void)
{ {
static const WCHAR DISPLAY[] = {'D','I','S','P','L','A','Y',0}; static const WCHAR DISPLAY[] = {'D','I','S','P','L','A','Y',0};
EnterCriticalSection( &display_dc_section ); EnterCriticalSection( &display_dc_section );
if (!display_dc) if (!display_dc) display_dc = CreateDCW( DISPLAY, NULL, NULL, NULL );
{
display_dc = CreateICW( DISPLAY, NULL, NULL, NULL );
__wine_make_gdi_object_system( display_dc, TRUE );
}
return display_dc; return display_dc;
} }
static inline void release_display_dc( HDC hdc ) void release_display_dc( HDC hdc )
{ {
LeaveCriticalSection( &display_dc_section ); LeaveCriticalSection( &display_dc_section );
} }
......
...@@ -227,6 +227,8 @@ extern BOOL FOCUS_MouseActivate( HWND hwnd ) DECLSPEC_HIDDEN; ...@@ -227,6 +227,8 @@ extern BOOL FOCUS_MouseActivate( HWND hwnd ) DECLSPEC_HIDDEN;
extern BOOL set_capture_window( HWND hwnd, UINT gui_flags, HWND *prev_ret ) DECLSPEC_HIDDEN; extern BOOL set_capture_window( HWND hwnd, UINT gui_flags, HWND *prev_ret ) DECLSPEC_HIDDEN;
extern void free_dce( struct dce *dce, HWND hwnd ) DECLSPEC_HIDDEN; extern void free_dce( struct dce *dce, HWND hwnd ) DECLSPEC_HIDDEN;
extern void invalidate_dce( struct tagWND *win, const RECT *rect ) DECLSPEC_HIDDEN; extern void invalidate_dce( struct tagWND *win, const RECT *rect ) DECLSPEC_HIDDEN;
extern HDC get_display_dc(void) DECLSPEC_HIDDEN;
extern void release_display_dc( HDC hdc ) DECLSPEC_HIDDEN;
extern void erase_now( HWND hwnd, UINT rdw_flags ) DECLSPEC_HIDDEN; extern void erase_now( HWND hwnd, UINT rdw_flags ) DECLSPEC_HIDDEN;
extern void move_window_bits( HWND hwnd, struct window_surface *old_surface, extern void move_window_bits( HWND hwnd, struct window_surface *old_surface,
struct window_surface *new_surface, struct window_surface *new_surface,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment