Alexandre Julliard : gdi32: Avoid locking in CreateCompatibleBitmap.

Alexandre Julliard julliard at winehq.org
Wed Feb 6 07:27:44 CST 2008


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

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue Feb  5 17:34:56 2008 +0100

gdi32: Avoid locking in CreateCompatibleBitmap.

---

 dlls/gdi32/bitmap.c |   35 +++++++++++++++++------------------
 1 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/dlls/gdi32/bitmap.c b/dlls/gdi32/bitmap.c
index 55b3236..de2fdae 100644
--- a/dlls/gdi32/bitmap.c
+++ b/dlls/gdi32/bitmap.c
@@ -132,13 +132,10 @@ HBITMAP WINAPI CreateBitmap( INT width, INT height, UINT planes,
 HBITMAP WINAPI CreateCompatibleBitmap( HDC hdc, INT width, INT height)
 {
     HBITMAP hbmpRet = 0;
-    DC *dc;
 
     TRACE("(%p,%d,%d) =\n", hdc, width, height);
 
-    if (!(dc = DC_GetDCPtr(hdc))) return 0;
-
-    if (GDIMAGIC( dc->header.wMagic ) != MEMORY_DC_MAGIC)
+    if (GetObjectType( hdc ) != OBJ_MEMDC)
     {
         hbmpRet = CreateBitmap(width, height,
                                GetDeviceCaps(hdc, PLANES),
@@ -147,14 +144,18 @@ HBITMAP WINAPI CreateCompatibleBitmap( HDC hdc, INT width, INT height)
     }
     else  /* Memory DC */
     {
-        BITMAPOBJ *bmp = GDI_GetObjPtr( dc->hBitmap, BITMAP_MAGIC );
+        DIBSECTION dib;
+        HBITMAP bitmap = GetCurrentObject( hdc, OBJ_BITMAP );
+        INT size = GetObjectW( bitmap, sizeof(dib), &dib );
+
+        if (!size) return 0;
 
-        if (!bmp->dib)
+        if (size == sizeof(BITMAP))
         {
             /* A device-dependent bitmap is selected in the DC */
             hbmpRet = CreateBitmap(width, height,
-                                   bmp->bitmap.bmPlanes,
-                                   bmp->bitmap.bmBitsPixel,
+                                   dib.dsBm.bmPlanes,
+                                   dib.dsBm.bmBitsPixel,
                                    NULL);
         }
         else
@@ -174,19 +175,19 @@ HBITMAP WINAPI CreateCompatibleBitmap( HDC hdc, INT width, INT height)
                 bi->bmiHeader.biSize          = sizeof(bi->bmiHeader);
                 bi->bmiHeader.biWidth         = width;
                 bi->bmiHeader.biHeight        = height;
-                bi->bmiHeader.biPlanes        = bmp->dib->dsBmih.biPlanes;
-                bi->bmiHeader.biBitCount      = bmp->dib->dsBmih.biBitCount;
-                bi->bmiHeader.biCompression   = bmp->dib->dsBmih.biCompression;
+                bi->bmiHeader.biPlanes        = dib.dsBmih.biPlanes;
+                bi->bmiHeader.biBitCount      = dib.dsBmih.biBitCount;
+                bi->bmiHeader.biCompression   = dib.dsBmih.biCompression;
                 bi->bmiHeader.biSizeImage     = 0;
-                bi->bmiHeader.biXPelsPerMeter = bmp->dib->dsBmih.biXPelsPerMeter;
-                bi->bmiHeader.biYPelsPerMeter = bmp->dib->dsBmih.biYPelsPerMeter;
-                bi->bmiHeader.biClrUsed       = bmp->dib->dsBmih.biClrUsed;
-                bi->bmiHeader.biClrImportant  = bmp->dib->dsBmih.biClrImportant;
+                bi->bmiHeader.biXPelsPerMeter = dib.dsBmih.biXPelsPerMeter;
+                bi->bmiHeader.biYPelsPerMeter = dib.dsBmih.biYPelsPerMeter;
+                bi->bmiHeader.biClrUsed       = dib.dsBmih.biClrUsed;
+                bi->bmiHeader.biClrImportant  = dib.dsBmih.biClrImportant;
 
                 if (bi->bmiHeader.biCompression == BI_BITFIELDS)
                 {
                     /* Copy the color masks */
-                    CopyMemory(bi->bmiColors, bmp->dib->dsBitfields, 3 * sizeof(DWORD));
+                    CopyMemory(bi->bmiColors, dib.dsBitfields, 3 * sizeof(DWORD));
                 }
                 else if (bi->bmiHeader.biBitCount <= 8)
                 {
@@ -198,9 +199,7 @@ HBITMAP WINAPI CreateCompatibleBitmap( HDC hdc, INT width, INT height)
                 HeapFree(GetProcessHeap(), 0, bi);
             }
         }
-        GDI_ReleaseObj(dc->hBitmap);
     }
-    DC_ReleaseDCPtr( dc );
 
     TRACE("\t\t%p\n", hbmpRet);
     return hbmpRet;




More information about the wine-cvs mailing list