[PATCH] gdiplus: Use static data for identity check in GdipIsMatrixIdentity()

Nikolay Sivov nsivov at codeweavers.com
Thu Nov 3 20:18:19 CDT 2016


Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
---
 dlls/gdiplus/matrix.c       | 20 +++++++-------------
 dlls/gdiplus/tests/matrix.c | 38 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 44 insertions(+), 14 deletions(-)

diff --git a/dlls/gdiplus/matrix.c b/dlls/gdiplus/matrix.c
index fc2d3f5..3cd8d82 100644
--- a/dlls/gdiplus/matrix.c
+++ b/dlls/gdiplus/matrix.c
@@ -497,23 +497,17 @@ GpStatus WINGDIPAPI GdipIsMatrixEqual(GDIPCONST GpMatrix *matrix, GDIPCONST GpMa
 
 GpStatus WINGDIPAPI GdipIsMatrixIdentity(GDIPCONST GpMatrix *matrix, BOOL *result)
 {
-    GpMatrix *e;
-    GpStatus ret;
-    BOOL isIdentity;
+    static const GpMatrix identity =
+    {
+      { 1.0, 0.0,
+        0.0, 1.0,
+        0.0, 0.0 }
+    };
 
     TRACE("(%p, %p)\n", matrix, result);
 
     if(!matrix || !result)
         return InvalidParameter;
 
-    ret = GdipCreateMatrix(&e);
-    if(ret != Ok) return ret;
-
-    ret = GdipIsMatrixEqual(matrix, e, &isIdentity);
-    if(ret == Ok)
-        *result = isIdentity;
-
-    heap_free(e);
-
-    return ret;
+    return GdipIsMatrixEqual(matrix, &identity, result);
 }
diff --git a/dlls/gdiplus/tests/matrix.c b/dlls/gdiplus/tests/matrix.c
index 83b57ef..a2e0595 100644
--- a/dlls/gdiplus/tests/matrix.c
+++ b/dlls/gdiplus/tests/matrix.c
@@ -302,7 +302,42 @@ static void test_constructor3(void)
     expectf(0.0, values[4]);
     expectf(0.0, values[5]);
 
-    GdipDeleteMatrix(matrix);}
+    GdipDeleteMatrix(matrix);
+}
+
+static void test_isidentity(void)
+{
+    GpMatrix *matrix;
+    GpStatus stat;
+    BOOL result;
+
+    stat = GdipIsMatrixIdentity(NULL, NULL);
+    expect(InvalidParameter, stat);
+
+    stat = GdipIsMatrixIdentity(NULL, &result);
+    expect(InvalidParameter, stat);
+
+    stat = GdipCreateMatrix2(1.0, 0.0, 0.0, 1.0, 0.0, 0.0, &matrix);
+    expect(Ok, stat);
+
+    stat = GdipIsMatrixIdentity(matrix, NULL);
+    expect(InvalidParameter, stat);
+
+    result = FALSE;
+    stat = GdipIsMatrixIdentity(matrix, &result);
+    expect(Ok, stat);
+    ok(!!result, "got %d\n", result);
+
+    stat = GdipSetMatrixElements(matrix, 1.0, 0.0, 0.0, 1.0, 0.1, 0.0);
+    expect(Ok, stat);
+
+    result = TRUE;
+    stat = GdipIsMatrixIdentity(matrix, &result);
+    expect(Ok, stat);
+    ok(!result, "got %d\n", result);
+
+    GdipDeleteMatrix(matrix);
+}
 
 START_TEST(matrix)
 {
@@ -322,6 +357,7 @@ START_TEST(matrix)
     test_invert();
     test_shear();
     test_constructor3();
+    test_isidentity();
 
     GdiplusShutdown(gdiplusToken);
 }
-- 
2.10.1




More information about the wine-patches mailing list