Alexandre Julliard : winex11: Make sure the bitmap of the brush pattern is owned by x11drv before getting its pixmap .

Alexandre Julliard julliard at winehq.org
Thu Sep 8 14:52:10 CDT 2011


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

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Wed Sep  7 22:54:49 2011 +0200

winex11: Make sure the bitmap of the brush pattern is owned by x11drv before getting its pixmap.

---

 dlls/winex11.drv/brush.c |   43 +++++++++++++++++++++++++++++--------------
 1 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/dlls/winex11.drv/brush.c b/dlls/winex11.drv/brush.c
index 6909d52..e16380a 100644
--- a/dlls/winex11.drv/brush.c
+++ b/dlls/winex11.drv/brush.c
@@ -252,14 +252,40 @@ static BOOL BRUSH_SelectPatternBrush( X11DRV_PDEVICE *physDev, HBITMAP hbitmap )
 
 
 /***********************************************************************
+ *           BRUSH_SelectDIBPatternBrush
+ */
+static BOOL BRUSH_SelectDIBPatternBrush( X11DRV_PDEVICE *physDev, HGLOBAL mem )
+{
+    BOOL ret;
+    HDC memdc;
+    BITMAPINFO *info = GlobalLock( mem );
+    HBITMAP bitmap = CreateDIBitmap( physDev->dev.hdc, &info->bmiHeader, CBM_INIT,
+                                     (LPBYTE)info + bitmap_info_size( info, DIB_RGB_COLORS ),
+                                     info, DIB_RGB_COLORS );
+
+    /* make sure it's owned by x11drv */
+    memdc = CreateCompatibleDC( physDev->dev.hdc );
+    SelectObject( memdc, bitmap );
+    DeleteDC( memdc );
+
+    if ((ret = BRUSH_SelectPatternBrush( physDev, bitmap )))
+    {
+        X_PHYSBITMAP *physBitmap = X11DRV_get_phys_bitmap( bitmap );
+        physBitmap->pixmap = 0;  /* so it doesn't get freed */
+    }
+    DeleteObject( bitmap );
+    GlobalUnlock( mem );
+    return ret;
+}
+
+
+/***********************************************************************
  *           SelectBrush   (X11DRV.@)
  */
 HBRUSH X11DRV_SelectBrush( PHYSDEV dev, HBRUSH hbrush )
 {
     X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
     LOGBRUSH logbrush;
-    HBITMAP hBitmap;
-    BITMAPINFO * bmpInfo;
 
     if (!GetObjectA( hbrush, sizeof(logbrush), &logbrush )) return 0;
 
@@ -304,18 +330,7 @@ HBRUSH X11DRV_SelectBrush( PHYSDEV dev, HBRUSH hbrush )
 
       case BS_DIBPATTERN:
 	TRACE("BS_DIBPATTERN\n");
-        if ((bmpInfo = GlobalLock( (HGLOBAL)logbrush.lbHatch )))
-	{
-	    int size = bitmap_info_size( bmpInfo, logbrush.lbColor );
-	    hBitmap = CreateDIBitmap( dev->hdc, &bmpInfo->bmiHeader,
-                                        CBM_INIT, ((char *)bmpInfo) + size,
-                                        bmpInfo,
-                                        (WORD)logbrush.lbColor );
-	    BRUSH_SelectPatternBrush( physDev, hBitmap );
-	    DeleteObject( hBitmap );
-            GlobalUnlock( (HGLOBAL)logbrush.lbHatch );
-	}
-
+	if (!BRUSH_SelectDIBPatternBrush( physDev, (HGLOBAL)logbrush.lbHatch )) return 0;
 	break;
     }
     return hbrush;




More information about the wine-cvs mailing list