[3/5] gdiplus: semistubs for GdipGetDC/GdipReleaseDC (see bug 10903)

Nikolay Sivov bunglehead at gmail.com
Sun Jun 29 04:02:14 CDT 2008


If this approach for locking Graphics object will be accepted
every Graphics:: method should check a lock flag and return 
ObjectBusy immediately on TRUE..

Changelog:
    - Semistub implementation of GdipGetDC/GdipReleaseDC with tests

---
 dlls/gdiplus/gdiplus_private.h |    1 +
 dlls/gdiplus/graphics.c        |   30 ++++++++++++++++++++++++------
 dlls/gdiplus/tests/graphics.c  |   38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+), 6 deletions(-)

diff --git a/dlls/gdiplus/gdiplus_private.h b/dlls/gdiplus/gdiplus_private.h
index b8269f2..672bf40 100644
--- a/dlls/gdiplus/gdiplus_private.h
+++ b/dlls/gdiplus/gdiplus_private.h
@@ -74,6 +74,7 @@ struct GpPen{
 
 struct GpGraphics{
     HDC hdc;
+    BOOL hdc_returned;
     HWND hwnd;
     SmoothingMode smoothing;
     CompositingQuality compqual;
diff --git a/dlls/gdiplus/graphics.c b/dlls/gdiplus/graphics.c
index c274b2e..2f2036b 100644
--- a/dlls/gdiplus/graphics.c
+++ b/dlls/gdiplus/graphics.c
@@ -773,6 +773,7 @@ GpStatus WINGDIPAPI GdipCreateFromHDC2(HDC hdc, HANDLE hDevice, GpGraphics **gra
     }
 
     (*graphics)->hdc = hdc;
+    (*graphics)->hdc_returned = FALSE;
     (*graphics)->hwnd = NULL;
     (*graphics)->smoothing = SmoothingModeDefault;
     (*graphics)->compqual = CompositingQualityDefault;
@@ -2474,20 +2475,37 @@ GpStatus WINGDIPAPI GdipMultiplyWorldTransform(GpGraphics *graphics, GDIPCONST G
 
     return ret;
 }
-
+/* FIXME: every Graphics method should check hdc_returned and
+   return ObjectBusy on TRUE */
 GpStatus WINGDIPAPI GdipGetDC(GpGraphics *graphics, HDC *hdc)
 {
-    FIXME("(%p, %p): stub\n", graphics, hdc);
+    FIXME("(%p, %p): semi stub\n", graphics, hdc);
 
-    *hdc = NULL;
-    return NotImplemented;
+    if(!graphics || !hdc)
+        return InvalidParameter;
+
+    if(graphics->hdc_returned)
+        return ObjectBusy;
+
+    *hdc = graphics->hdc;
+    graphics->hdc_returned = TRUE;
+
+    return Ok;
 }
 
 GpStatus WINGDIPAPI GdipReleaseDC(GpGraphics *graphics, HDC hdc)
 {
-    FIXME("(%p, %p): stub\n", graphics, hdc);
+    FIXME("(%p, %p): semi stub\n", graphics, hdc);
 
-    return NotImplemented;
+    if(!graphics)
+        return InvalidParameter;
+
+    if(!(graphics->hdc == hdc))
+        return InvalidParameter;
+
+    graphics->hdc_returned = FALSE;
+
+    return Ok;
 }
 
 GpStatus WINGDIPAPI GdipGetClip(GpGraphics *graphics, GpRegion *region)
diff --git a/dlls/gdiplus/tests/graphics.c b/dlls/gdiplus/tests/graphics.c
index 168eae3..e029da6 100644
--- a/dlls/gdiplus/tests/graphics.c
+++ b/dlls/gdiplus/tests/graphics.c
@@ -452,6 +452,43 @@ static void test_GdipDrawLinesI(void)
     ReleaseDC(0, hdc);
 }
 
+static void test_GetReleaseHDC(void)
+{
+    GpStatus status;
+    GpGraphics *graphics = NULL;
+    HDC hdc = GetDC(0);
+    HDC hdc2 = NULL;
+
+    /* make a graphics object */
+    status = GdipCreateFromHDC(hdc, &graphics);
+    expect(Ok, status);
+    ok(hdc != NULL, "Expected HDC to be initialized\n");
+
+    /* return HDC */
+    status = GdipGetDC(graphics, &hdc2);
+    expect(Ok, status);
+    ok(hdc2 == hdc, "Wrong HDC returned\n");
+
+    /* next GetHDC() call should return busy state */
+    status = GdipGetDC(graphics, &hdc2);
+    expect(ObjectBusy, status);
+
+    /* releasing, HDC passed by value */
+    status = GdipReleaseDC(graphics, NULL);
+    expect(InvalidParameter, status);
+
+    status = GdipReleaseDC(graphics, hdc2);
+    expect(Ok, status);
+
+    /* check that GetHDC() available again */
+    status = GdipGetDC(graphics, &hdc2);
+    expect(Ok, status);
+    ok(hdc2 == hdc, "Wrong HDC returned\n");
+
+    status = GdipReleaseDC(graphics, hdc2);
+    expect(Ok, status);
+}
+
 START_TEST(graphics)
 {
     struct GdiplusStartupInput gdiplusStartupInput;
@@ -466,6 +503,7 @@ START_TEST(graphics)
 
     test_constructor_destructor();
     test_save_restore();
+    test_GetReleaseHDC();
     test_GdipDrawBezierI();
     test_GdipDrawArc();
     test_GdipDrawArcI();
-- 
1.4.4.4






More information about the wine-patches mailing list