From: Esme Povirk esme@codeweavers.com
--- dlls/gdiplus/gdiplus_private.h | 2 +- dlls/gdiplus/graphics.c | 38 ++++++++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/dlls/gdiplus/gdiplus_private.h b/dlls/gdiplus/gdiplus_private.h index e25f60de78e..d247b973b3b 100644 --- a/dlls/gdiplus/gdiplus_private.h +++ b/dlls/gdiplus/gdiplus_private.h @@ -665,7 +665,7 @@ static inline void image_unlock(GpImage *image)
static inline BOOL has_gdi_dc(GpGraphics *graphics) { - return graphics->hdc != NULL; + return graphics->hdc != NULL || graphics->owndc; }
static inline void set_rect(GpRectF *rect, REAL x, REAL y, REAL width, REAL height) diff --git a/dlls/gdiplus/graphics.c b/dlls/gdiplus/graphics.c index d50379e5943..58fa129b504 100644 --- a/dlls/gdiplus/graphics.c +++ b/dlls/gdiplus/graphics.c @@ -55,6 +55,14 @@ GpStatus gdi_dc_acquire(GpGraphics *graphics, HDC *hdc) graphics->hdc_refs++; return Ok; } + else if (graphics->owndc) + { + *hdc = graphics->hdc = GetDC(graphics->hwnd); + if (!graphics->hdc) + return OutOfMemory; + graphics->hdc_refs++; + return Ok; + }
*hdc = NULL; return InvalidParameter; @@ -64,6 +72,13 @@ void gdi_dc_release(GpGraphics *graphics, HDC hdc) { assert(graphics->hdc_refs > 0); graphics->hdc_refs--; + + if (graphics->owndc && !graphics->hdc_refs) + { + assert(graphics->hdc == hdc); + graphics->hdc = NULL; + ReleaseDC(graphics->hwnd, hdc); + } }
static GpStatus draw_driver_string(GpGraphics *graphics, GDIPCONST UINT16 *text, INT length, @@ -2556,6 +2571,9 @@ GpStatus WINGDIPAPI GdipCreateFromHWND(HWND hwnd, GpGraphics **graphics) (*graphics)->hwnd = hwnd; (*graphics)->owndc = TRUE;
+ ReleaseDC(hwnd, hdc); + (*graphics)->hdc = NULL; + return Ok; }
@@ -2610,13 +2628,13 @@ GpStatus WINGDIPAPI GdipDeleteGraphics(GpGraphics *graphics)
if (graphics->temp_hdc) { - DeleteDC(graphics->temp_hdc); + if (graphics->owndc) + ReleaseDC(graphics->hwnd, graphics->temp_hdc); + else + DeleteDC(graphics->temp_hdc); graphics->temp_hdc = NULL; }
- if(graphics->owndc) - ReleaseDC(graphics->hwnd, graphics->hdc); - LIST_FOR_EACH_ENTRY_SAFE(cont, next, &graphics->containers, GraphicsContainerItem, entry){ list_remove(&cont->entry); delete_container(cont); @@ -7002,6 +7020,13 @@ GpStatus WINGDIPAPI GdipGetDC(GpGraphics *graphics, HDC *hdc) { stat = METAFILE_GetDC((GpMetafile*)graphics->image, hdc); } + else if (graphics->owndc) + { + graphics->temp_hdc = GetDC(graphics->hwnd); + if (!graphics->temp_hdc) + return OutOfMemory; + *hdc = graphics->temp_hdc; + } else if (!graphics->hdc || (graphics->image && graphics->image->type == ImageTypeBitmap)) { @@ -7083,6 +7108,11 @@ GpStatus WINGDIPAPI GdipReleaseDC(GpGraphics *graphics, HDC hdc) { stat = METAFILE_ReleaseDC((GpMetafile*)graphics->image, hdc); } + else if (graphics->owndc) + { + ReleaseDC(graphics->hwnd, graphics->temp_hdc); + graphics->temp_hdc = NULL; + } else if (graphics->temp_hdc == hdc) { DWORD* pos;