From d87adf2a60723ee5dacdd59a0d2849c4534306bf Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Fri, 28 Aug 2009 15:05:38 -0500 Subject: [PATCH] gdiplus: Don't use IPicture to manage the HDC associated with a GpBitmap. --- dlls/gdiplus/brush.c | 2 +- dlls/gdiplus/gdiplus_private.h | 1 + dlls/gdiplus/image.c | 23 ++++++++++++----------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/dlls/gdiplus/brush.c b/dlls/gdiplus/brush.c index f719ff8b1a..370de616f4 100644 --- a/dlls/gdiplus/brush.c +++ b/dlls/gdiplus/brush.c @@ -672,7 +672,7 @@ GpStatus WINGDIPAPI GdipCreateTextureIA(GpImage *image, hbm = ((GpBitmap*)image)->hbitmap; if(!hbm) return GenericError; - IPicture_get_CurDC(image->picture, &hdc); + hdc = ((GpBitmap*)image)->hdc; bm_is_selected = (hdc != 0); pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)); diff --git a/dlls/gdiplus/gdiplus_private.h b/dlls/gdiplus/gdiplus_private.h index 5765eaccac..71974631f8 100644 --- a/dlls/gdiplus/gdiplus_private.h +++ b/dlls/gdiplus/gdiplus_private.h @@ -223,6 +223,7 @@ struct GpBitmap{ INT numlocks; BYTE *bitmapbits; /* pointer to the buffer we passed in BitmapLockBits */ HBITMAP hbitmap; + HDC hdc; }; struct GpCachedBitmap{ diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c index e201973392..9d91755472 100644 --- a/dlls/gdiplus/image.c +++ b/dlls/gdiplus/image.c @@ -168,7 +168,7 @@ GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap* bitmap, GDIPCONST GpRect* rect, return WrongState; hbm = bitmap->hbitmap; - IPicture_get_CurDC(bitmap->image.picture, &hdc); + hdc = bitmap->hdc; bm_is_selected = (hdc != 0); pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)); @@ -264,7 +264,7 @@ GpStatus WINGDIPAPI GdipBitmapUnlockBits(GpBitmap* bitmap, } hbm = bitmap->hbitmap; - IPicture_get_CurDC(bitmap->image.picture, &hdc); + hdc = bitmap->hdc; bm_is_selected = (hdc != 0); pbmi = GdipAlloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)); @@ -588,6 +588,7 @@ GpStatus WINGDIPAPI GdipCreateBitmapFromHICON(HICON hicon, GpBitmap** bitmap) (*bitmap)->width = ipicture_pixel_width((*bitmap)->image.picture); (*bitmap)->height = ipicture_pixel_height((*bitmap)->image.picture); (*bitmap)->hbitmap = NULL; + (*bitmap)->hdc = NULL; DeleteObject(iinfo.hbmColor); DeleteObject(iinfo.hbmMask); @@ -689,6 +690,7 @@ GpStatus WINGDIPAPI GdipCreateBitmapFromScan0(INT width, INT height, INT stride, (*bitmap)->height = height; (*bitmap)->format = format; IPicture_get_Handle((*bitmap)->image.picture, (OLE_HANDLE*)&(*bitmap)->hbitmap); + IPicture_get_CurDC((*bitmap)->image.picture, &(*bitmap)->hdc); return Ok; } @@ -786,18 +788,17 @@ GpStatus WINGDIPAPI GdipEmfToWmfBits(HENHMETAFILE hemf, UINT cbData16, GpStatus WINGDIPAPI GdipDisposeImage(GpImage *image) { - HDC hdc; - TRACE("%p\n", image); if(!image) return InvalidParameter; - IPicture_get_CurDC(image->picture, &hdc); - DeleteDC(hdc); IPicture_Release(image->picture); if (image->type == ImageTypeBitmap) + { GdipFree(((GpBitmap*)image)->bitmapbits); + DeleteDC(((GpBitmap*)image)->hdc); + } GdipFree(image); return Ok; @@ -889,11 +890,12 @@ GpStatus WINGDIPAPI GdipGetImageGraphicsContext(GpImage *image, return NotImplemented; } - IPicture_get_CurDC(image->picture, &hdc); + hdc = ((GpBitmap*)image)->hdc; if(!hdc){ hdc = CreateCompatibleDC(0); - IPicture_SelectPicture(image->picture, hdc, NULL, NULL); + SelectObject(hdc, ((GpBitmap*)image)->hbitmap); + ((GpBitmap*)image)->hdc = hdc; } return GdipCreateFromHDC(hdc, graphics); @@ -1264,6 +1266,7 @@ static GpStatus decode_image_olepicture_bitmap(IStream* stream, REFCLSID clsid, IPicture_get_CurDC(pic, &hdc); (*((GpBitmap**) image))->hbitmap = hbm; + (*((GpBitmap**) image))->hdc = hdc; bmch = (BITMAPCOREHEADER*) (&pbmi->bmiHeader); bmch->bcSize = sizeof(BITMAPCOREHEADER); @@ -1583,9 +1586,7 @@ GpStatus WINGDIPAPI GdipSaveImageToStream(GpImage *image, IStream* stream, hbmp = ((GpBitmap*)image)->hbitmap; if (!hbmp) return GenericError; - hr = IPicture_get_CurDC(image->picture, &hdc); - if (FAILED(hr)) - return GenericError; + hdc = ((GpBitmap*)image)->hdc; bm_is_selected = (hdc != 0); if (!bm_is_selected) { hdc = CreateCompatibleDC(0); -- 2.32.0.93.g670b81a890