From: Piotr Caban Subject: [PATCH 5/7] gdiplus: Store all informations about locked bitmap area in GpBitmap structure Message-Id: <61dcbdc0-4e4d-45ce-44c7-fcf3822b20ff@codeweavers.com> Date: Wed, 8 Feb 2017 16:57:13 +0100 Signed-off-by: Piotr Caban --- dlls/gdiplus/gdiplus_private.h | 3 +-- dlls/gdiplus/image.c | 39 ++++++++++++++++++++------------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/dlls/gdiplus/gdiplus_private.h b/dlls/gdiplus/gdiplus_private.h index c3a8fe3..7b06a3d 100644 --- a/dlls/gdiplus/gdiplus_private.h +++ b/dlls/gdiplus/gdiplus_private.h @@ -390,14 +390,13 @@ struct GpBitmap{ INT width; INT height; PixelFormat format; - ImageLockMode lockmode; - BYTE *bitmapbits; /* pointer to the buffer we passed in BitmapLockBits */ HBITMAP hbitmap; HDC hdc; BYTE *bits; /* actual image bits if this is a DIB */ INT stride; /* stride of bits if this is a DIB */ BYTE *own_bits; /* image bits that need to be freed with this object */ INT lockx, locky; /* X and Y coordinates of the rect when a bitmap is locked for writing. */ + BitmapData lock; IWICMetadataReader *metadata_reader; /* NULL if there is no metadata */ UINT prop_count; PropertyItem *prop_item; /* cached image properties */ diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c index b969e00..77f1406 100644 --- a/dlls/gdiplus/image.c +++ b/dlls/gdiplus/image.c @@ -1052,7 +1052,7 @@ GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap* bitmap, GDIPCONST GpRect* rect, act_rect.Height = bitmap->height; } - if(bitmap->lockmode) + if(bitmap->lock.Reserved) { WARN("bitmap is already locked and cannot be locked again\n"); image_unlock(&bitmap->image, unlock); @@ -1070,7 +1070,7 @@ GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap* bitmap, GDIPCONST GpRect* rect, lockeddata->Scan0 = bitmap->bits + (bitspp / 8) * act_rect.X + bitmap->stride * act_rect.Y; - bitmap->lockmode = flags | ImageLockModeRead; + bitmap->lock.Reserved = flags | ImageLockModeRead; image_unlock(&bitmap->image, unlock); return Ok; @@ -1110,15 +1110,16 @@ GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap* bitmap, GDIPCONST GpRect* rect, { lockeddata->Stride = (((act_rect.Width * bitspp + 7) / 8) + 3) & ~3; - bitmap->bitmapbits = heap_alloc_zero(lockeddata->Stride * act_rect.Height); + bitmap->lock = *lockeddata; + bitmap->lock.Scan0 = heap_alloc_zero(lockeddata->Stride * act_rect.Height); - if (!bitmap->bitmapbits) + if (!bitmap->lock.Scan0) { image_unlock(&bitmap->image, unlock); return OutOfMemory; } - lockeddata->Scan0 = bitmap->bitmapbits; + lockeddata->Scan0 = bitmap->lock.Scan0; } if ((flags & ImageLockModeRead) || (bitmap->image.flags & ImageFlagsReadOnly)) @@ -1139,14 +1140,14 @@ GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap* bitmap, GDIPCONST GpRect* rect, if (stat != Ok) { - heap_free(bitmap->bitmapbits); - bitmap->bitmapbits = NULL; + heap_free(bitmap->lock.Scan0); + bitmap->lock.Scan0 = NULL; image_unlock(&bitmap->image, unlock); return stat; } } - bitmap->lockmode = flags | ImageLockModeRead; + bitmap->lock.Reserved = flags | ImageLockModeRead; bitmap->lockx = act_rect.X; bitmap->locky = act_rect.Y; @@ -1181,24 +1182,24 @@ GpStatus WINGDIPAPI GdipBitmapUnlockBits(GpBitmap* bitmap, if(!image_lock(&bitmap->image, &unlock)) return ObjectBusy; - if(!bitmap->lockmode) + if(!bitmap->lock.Reserved) { image_unlock(&bitmap->image, unlock); return WrongState; } if(!(lockeddata->Reserved & ImageLockModeWrite)){ - bitmap->lockmode = 0; - heap_free(bitmap->bitmapbits); - bitmap->bitmapbits = NULL; + bitmap->lock.Reserved = 0; + heap_free(bitmap->lock.Scan0); + bitmap->lock.Scan0 = NULL; image_unlock(&bitmap->image, unlock); return Ok; } - if (!bitmap->bitmapbits && !(lockeddata->Reserved & ImageLockModeUserInputBuf)) + if (!bitmap->lock.Scan0 && !(lockeddata->Reserved & ImageLockModeUserInputBuf)) { /* we passed a direct reference; no need to do anything */ - bitmap->lockmode = 0; + bitmap->lock.Reserved = 0; image_unlock(&bitmap->image, unlock); return Ok; } @@ -1220,9 +1221,9 @@ GpStatus WINGDIPAPI GdipBitmapUnlockBits(GpBitmap* bitmap, ERR("failed to convert pixels; this should never happen\n"); } - heap_free(bitmap->bitmapbits); - bitmap->bitmapbits = NULL; - bitmap->lockmode = 0; + heap_free(bitmap->lock.Scan0); + bitmap->lock.Scan0 = NULL; + bitmap->lock.Reserved = 0; image_unlock(&bitmap->image, unlock); return stat; @@ -2031,7 +2032,7 @@ static void move_bitmap(GpBitmap *dst, GpBitmap *src, BOOL clobber_palette) assert(src->image.type == ImageTypeBitmap); assert(dst->image.type == ImageTypeBitmap); - heap_free(dst->bitmapbits); + heap_free(dst->lock.Scan0); heap_free(dst->own_bits); DeleteDC(dst->hdc); DeleteObject(dst->hbitmap); @@ -2083,7 +2084,7 @@ static GpStatus free_image_data(GpImage *image) if (image->type == ImageTypeBitmap) { - heap_free(((GpBitmap*)image)->bitmapbits); + heap_free(((GpBitmap*)image)->lock.Scan0); heap_free(((GpBitmap*)image)->own_bits); DeleteDC(((GpBitmap*)image)->hdc); DeleteObject(((GpBitmap*)image)->hbitmap);