Alexandre Julliard : gdi32: Grab the bits directly for DIB pattern brushes instead of duplicating the bitmap .

Alexandre Julliard julliard at winehq.org
Wed Nov 9 13:29:41 CST 2011


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

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Thu Nov  3 21:14:42 2011 +0100

gdi32: Grab the bits directly for DIB pattern brushes instead of duplicating the bitmap.

---

 dlls/gdi32/brush.c |   41 +++++++++++++++++++++++++++++++++++++++--
 1 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/dlls/gdi32/brush.c b/dlls/gdi32/brush.c
index 5cbae61..ccd1369 100644
--- a/dlls/gdi32/brush.c
+++ b/dlls/gdi32/brush.c
@@ -90,6 +90,44 @@ static BOOL store_bitmap_bits( BRUSHOBJ *brush, BITMAPOBJ *bmp )
     return TRUE;
 }
 
+static BOOL copy_bitmap( BRUSHOBJ *brush, HBITMAP bitmap )
+{
+    BITMAPINFO *info;
+    BITMAPOBJ *bmp = GDI_GetObjPtr( bitmap, OBJ_BITMAP );
+
+    if (!bmp) return FALSE;
+
+    if (!bmp->dib)
+    {
+        GDI_ReleaseObj( bitmap );
+        brush->bitmap = BITMAP_CopyBitmap( bitmap );
+        return brush->bitmap != 0;
+    }
+
+    info = HeapAlloc( GetProcessHeap(), 0,
+                      bitmap_info_size( (BITMAPINFO *)&bmp->dib->dsBmih, DIB_RGB_COLORS ));
+    if (!info) goto done;
+    info->bmiHeader = bmp->dib->dsBmih;
+    if (bmp->dib->dsBmih.biCompression == BI_BITFIELDS)
+        memcpy( &info->bmiHeader + 1, bmp->dib->dsBitfields, sizeof(bmp->dib->dsBitfields) );
+    else if (bmp->nb_colors)
+        memcpy( &info->bmiHeader + 1, bmp->color_table, bmp->nb_colors * sizeof(RGBQUAD) );
+    if (!(brush->bits.ptr = HeapAlloc( GetProcessHeap(), 0, get_dib_image_size( info ))))
+    {
+        HeapFree( GetProcessHeap(), 0, info );
+        goto done;
+    }
+    memcpy( brush->bits.ptr, bmp->dib->dsBm.bmBits, get_dib_image_size( info ));
+    brush->bits.is_copy = TRUE;
+    brush->bits.free = free_heap_bits;
+    brush->info = info;
+    brush->usage = DIB_RGB_COLORS;
+
+done:
+    GDI_ReleaseObj( bitmap );
+    return brush->info != NULL;
+}
+
 BOOL get_brush_bitmap_info( HBRUSH handle, BITMAPINFO *info, void **bits, UINT *usage )
 {
     BRUSHOBJ *brush;
@@ -159,8 +197,7 @@ HBRUSH WINAPI CreateBrushIndirect( const LOGBRUSH * brush )
         ptr->logbrush.lbStyle = BS_PATTERN;
         /* fall through */
     case BS_PATTERN:
-        ptr->bitmap = BITMAP_CopyBitmap( (HBITMAP)ptr->logbrush.lbHatch );
-        if (!ptr->bitmap) goto error;
+        if (!copy_bitmap( ptr, (HBITMAP)ptr->logbrush.lbHatch )) goto error;
         ptr->logbrush.lbColor = 0;
         break;
 




More information about the wine-cvs mailing list