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

Alexandre Julliard julliard at winehq.org
Tue Jan 23 16:09:49 CST 2018


Module: wine
Branch: master
Commit: e7e576d67597924ca14f4c06cb3c9a7f13f3b892
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=e7e576d67597924ca14f4c06cb3c9a7f13f3b892

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue Jan 23 12:30:22 2018 +0100

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

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/user32/cursoricon.c   | 78 ++++++++++++++--------------------------------
 dlls/user32/sysparams.c    | 10 ++----
 dlls/user32/user_private.h |  2 ++
 3 files changed, 29 insertions(+), 61 deletions(-)

diff --git a/dlls/user32/cursoricon.c b/dlls/user32/cursoricon.c
index 1fbec2a..1203250 100644
--- a/dlls/user32/cursoricon.c
+++ b/dlls/user32/cursoricon.c
@@ -92,15 +92,20 @@ struct animated_cursoricon_object
     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};
-    static HDC screen_dc;
-
-    if (!screen_dc)
-        screen_dc = CreateDCW( DISPLAYW, NULL, NULL, NULL );
+    HDC hdc = get_display_dc();
+    HBITMAP ret = CreateCompatibleBitmap( hdc, width, height );
+    release_display_dc( hdc );
+    return ret;
+}
 
-    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 )
@@ -811,7 +816,6 @@ static HICON create_icon_from_bmi( const BITMAPINFO *bmi, DWORD maxsize, HMODULE
     BOOL ret = FALSE;
     BOOL do_stretch;
     HICON hObj = 0;
-    HDC screen_dc;
     HDC hdc = 0;
     LONG bmi_width, bmi_height;
     WORD bpp;
@@ -875,8 +879,6 @@ static HICON create_icon_from_bmi( const BITMAPINFO *bmi, DWORD maxsize, HMODULE
         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] )))))
         return 0;
     if (!(hdc = CreateCompatibleDC( 0 ))) goto done;
@@ -906,8 +908,7 @@ static HICON create_icon_from_bmi( const BITMAPINFO *bmi, DWORD maxsize, HMODULE
     else
     {
         if (!(mask = CreateBitmap( width, height, 1, 1, NULL ))) goto done;
-        if (!(color = CreateBitmap( width, height, GetDeviceCaps( screen_dc, PLANES ),
-                                     GetDeviceCaps( screen_dc, BITSPIXEL ), NULL )))
+        if (!(color = create_color_bitmap( width, height )))
         {
             DeleteObject( mask );
             goto done;
@@ -1830,11 +1831,7 @@ INT WINAPI LookupIconIdFromDirectoryEx( LPBYTE xdir, BOOL bIcon,
     if( dir && !dir->idReserved && (dir->idType & 3) )
     {
         const CURSORICONDIRENTRY* entry;
-
-        const HDC hdc = GetDC(0);
-        const int depth = (cFlag & LR_MONOCHROME) ?
-            1 : GetDeviceCaps(hdc, BITSPIXEL);
-        ReleaseDC(0, hdc);
+        int depth = (cFlag & LR_MONOCHROME) ? 1 : get_display_bpp();
 
         if( bIcon )
             entry = CURSORICON_FindBestIconRes( dir, ~0u, width, height, depth, LR_DEFAULTSIZE );
@@ -2168,7 +2165,7 @@ HICON WINAPI CreateIconIndirect(PICONINFO iconinfo)
         height = bmpXor.bmHeight;
         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 );
         }
         else mask = CreateBitmap( width, height * 2, 1, 1, NULL );
@@ -2498,7 +2495,6 @@ static HBITMAP BITMAP_Load( HINSTANCE instance, LPCWSTR name,
     DWORD compr_dummy, offbits = 0;
     INT bm_type;
     HDC screen_mem_dc = NULL;
-    HDC screen_dc;
 
     if (!(loadflags & LR_LOADFROMFILE))
     {
@@ -2578,22 +2574,21 @@ static HBITMAP BITMAP_Load( HINSTANCE instance, LPCWSTR name,
 
     if (new_height < 0) new_height = -new_height;
 
-    screen_dc = get_screen_dc();
-    if (!(screen_mem_dc = CreateCompatibleDC( screen_dc ))) goto end;
+    if (!(screen_mem_dc = CreateCompatibleDC( 0 ))) goto end;
 
     bits = (char *)info + (offbits ? offbits : size);
 
     if (loadflags & LR_CREATEDIBSECTION)
     {
         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
     {
         if (is_dib_monochrome(fix_info))
             hbitmap = CreateBitmap(new_width, new_height, 1, 1, NULL);
         else
-            hbitmap = CreateCompatibleBitmap(screen_dc, new_width, new_height);        
+            hbitmap = create_color_bitmap(new_width, new_height);
     }
 
     orig_bm = SelectObject(screen_mem_dc, hbitmap);
@@ -2672,13 +2667,7 @@ HANDLE WINAPI LoadImageW( HINSTANCE hinst, LPCWSTR name, UINT type,
     case IMAGE_ICON:
     case IMAGE_CURSOR:
         depth = 1;
-        if (!(loadflags & LR_MONOCHROME))
-        {
-            HDC screen_dc;
-
-            if ((screen_dc = get_screen_dc()))
-                depth = GetDeviceCaps( screen_dc, BITSPIXEL );
-        }
+        if (!(loadflags & LR_MONOCHROME)) depth = get_display_bpp();
         return CURSORICON_Load(hinst, name, desiredx, desiredy, depth, (type == IMAGE_CURSOR), loadflags);
     }
     return 0;
@@ -2818,37 +2807,18 @@ HANDLE WINAPI CopyImage( HANDLE hnd, UINT type, INT desiredx,
                 }
 
                 if (monochrome)
-                {
                     res = CreateBitmap(desiredx, desiredy, 1, 1, NULL);
-                }
                 else
-                {
-                    HDC screenDC = GetDC(NULL);
-                    res = CreateCompatibleBitmap(screenDC, desiredx, desiredy);
-                    ReleaseDC(NULL, screenDC);
-                }
+                    res = create_color_bitmap(desiredx, desiredy);
             }
 
             if (res)
             {
                 /* Only copy the bitmap if it's a DIB section or if it's
                    compatible to the screen */
-                BOOL copyContents;
-
-                if (objSize == sizeof(DIBSECTION))
-                {
-                    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)
+                if (objSize == sizeof(DIBSECTION) ||
+                    ds.dsBm.bmBitsPixel == 1 ||
+                    ds.dsBm.bmBitsPixel == get_display_bpp())
                 {
                     /* The source bitmap may already be selected in a device context,
                        use GetDIBits/StretchDIBits and not StretchBlt  */
@@ -2901,7 +2871,7 @@ HANDLE WINAPI CopyImage( HANDLE hnd, UINT type, INT desiredx,
         {
             struct cursoricon_object *icon;
             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)
             {
diff --git a/dlls/user32/sysparams.c b/dlls/user32/sysparams.c
index 4b66eb2..f80cea1 100644
--- a/dlls/user32/sysparams.c
+++ b/dlls/user32/sysparams.c
@@ -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 );
 }
 
-static inline HDC get_display_dc(void)
+HDC get_display_dc(void)
 {
     static const WCHAR DISPLAY[] = {'D','I','S','P','L','A','Y',0};
     EnterCriticalSection( &display_dc_section );
-    if (!display_dc)
-    {
-        display_dc = CreateICW( DISPLAY, NULL, NULL, NULL );
-        __wine_make_gdi_object_system( display_dc, TRUE );
-    }
+    if (!display_dc) display_dc = CreateDCW( DISPLAY, NULL, NULL, NULL );
     return display_dc;
 }
 
-static inline void release_display_dc( HDC hdc )
+void release_display_dc( HDC hdc )
 {
     LeaveCriticalSection( &display_dc_section );
 }
diff --git a/dlls/user32/user_private.h b/dlls/user32/user_private.h
index 052fdd8..0ffdcdd 100644
--- a/dlls/user32/user_private.h
+++ b/dlls/user32/user_private.h
@@ -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 void free_dce( struct dce *dce, HWND hwnd ) 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 move_window_bits( HWND hwnd, struct window_surface *old_surface,
                               struct window_surface *new_surface,




More information about the wine-cvs mailing list