2009-06-17 Brent Fulgham <bfulgham@webkit.org>
authorbfulgham@webkit.org <bfulgham@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 18 Jun 2009 01:22:19 +0000 (01:22 +0000)
committerbfulgham@webkit.org <bfulgham@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 18 Jun 2009 01:22:19 +0000 (01:22 +0000)
        Reviewed by Adam Roben.

        Refactor a few common routines in the various Windows ports
        and reduce some duplicated code.

        (1) Create TransformationMatrix XFORM casting operator, and
            switch various XFORM structure uses to utilize it.
        (2) Push concatCTM call to GraphicsContextWin now that the
            TransformationMatrix can directly create XFORM (rather
            than converting to CGAffineTransform/cairo_matrix_t first.)

        * WebCore.vcproj/WebCore.vcproj: Add new BitmapInfo structure.
        * platform/graphics/transforms/TransformationMatrix.h:
        * platform/graphics/win/GraphicsContextCGWin.cpp:
        * platform/graphics/win/GraphicsContextCairoWin.cpp:
        * platform/graphics/win/GraphicsContextWin.cpp:
        (WebCore::GraphicsContextPlatformPrivate::scale):
        (WebCore::GraphicsContextPlatformPrivate::rotate):
        (WebCore::GraphicsContextPlatformPrivate::translate):
        (WebCore::GraphicsContextPlatformPrivate::concatCTM):
        * platform/graphics/win/TransformationMatrixWin.cpp: Added.
        (WebCore::TransformationMatrix::operator XFORM): New operator

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@44793 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/WebCore.vcproj/WebCore.vcproj
WebCore/platform/graphics/transforms/TransformationMatrix.h
WebCore/platform/graphics/win/GraphicsContextCGWin.cpp
WebCore/platform/graphics/win/GraphicsContextCairoWin.cpp
WebCore/platform/graphics/win/GraphicsContextWin.cpp
WebCore/platform/graphics/win/TransformationMatrixWin.cpp [new file with mode: 0644]

index 3fe1a4c..ea11126 100644 (file)
@@ -1,5 +1,30 @@
 2009-06-17  Brent Fulgham  <bfulgham@webkit.org>
 
+        Reviewed by Adam Roben.
+
+        Refactor a few common routines in the various Windows ports
+        and reduce some duplicated code.
+
+        (1) Create TransformationMatrix XFORM casting operator, and
+            switch various XFORM structure uses to utilize it.
+        (2) Push concatCTM call to GraphicsContextWin now that the
+            TransformationMatrix can directly create XFORM (rather
+            than converting to CGAffineTransform/cairo_matrix_t first.)
+
+        * WebCore.vcproj/WebCore.vcproj: Add new BitmapInfo structure.
+        * platform/graphics/transforms/TransformationMatrix.h:
+        * platform/graphics/win/GraphicsContextCGWin.cpp:
+        * platform/graphics/win/GraphicsContextCairoWin.cpp:
+        * platform/graphics/win/GraphicsContextWin.cpp:
+        (WebCore::GraphicsContextPlatformPrivate::scale):
+        (WebCore::GraphicsContextPlatformPrivate::rotate):
+        (WebCore::GraphicsContextPlatformPrivate::translate):
+        (WebCore::GraphicsContextPlatformPrivate::concatCTM):
+        * platform/graphics/win/TransformationMatrixWin.cpp: Added.
+        (WebCore::TransformationMatrix::operator XFORM): New operator
+
+2009-06-17  Brent Fulgham  <bfulgham@webkit.org>
+
         Non-CG Windows build fix after @r44758.
 
         * rendering/RenderThemeWin.cpp:
index 24efbab..37e2f5a 100644 (file)
                        <File\r
                                RelativePath="$(WebKitOutputDir)\obj\$(ProjectName)\DerivedSources\JSInspectorController.cpp"\r
                                >\r
-                       </File>\r
-                       <File\r
-                               RelativePath="$(WebKitOutputDir)\obj\$(ProjectName)\DerivedSources\JSInspectorController.cpp"\r
-                               >\r
                                <FileConfiguration\r
                                        Name="Debug|Win32"\r
                                        ExcludedFromBuild="true"\r
                                </FileConfiguration>\r
                        </File>\r
                        <File\r
+                               RelativePath="$(WebKitOutputDir)\obj\$(ProjectName)\DerivedSources\JSInspectorController.cpp"\r
+                               >\r
+                       </File>\r
+                       <File\r
                                RelativePath="$(WebKitOutputDir)\obj\$(ProjectName)\DerivedSources\JSInspectorController.h"\r
                                >\r
                        </File>\r
                        <File\r
                                RelativePath="$(WebKitOutputDir)\obj\$(ProjectName)\DerivedSources\JSSVGElementWrapperFactory.cpp"\r
                                >\r
-                       </File>\r
-                       <File\r
-                               RelativePath="$(WebKitOutputDir)\obj\$(ProjectName)\DerivedSources\JSSVGElementWrapperFactory.cpp"\r
-                               >\r
                                <FileConfiguration\r
                                        Name="Debug|Win32"\r
                                        ExcludedFromBuild="true"\r
                                </FileConfiguration>\r
                        </File>\r
                        <File\r
+                               RelativePath="$(WebKitOutputDir)\obj\$(ProjectName)\DerivedSources\JSSVGElementWrapperFactory.cpp"\r
+                               >\r
+                       </File>\r
+                       <File\r
                                RelativePath="$(WebKitOutputDir)\obj\$(ProjectName)\DerivedSources\JSSVGElementWrapperFactory.h"\r
                                >\r
                        </File>\r
                                                >\r
                                        </File>\r
                                        <File\r
+                                               RelativePath="..\platform\graphics\win\TransformationMatrixWin.cpp"\r
+                                               >\r
+                                       </File>\r
+                                       <File\r
                                                RelativePath="..\platform\graphics\win\UniscribeController.cpp"\r
                                                >\r
                                        </File>\r
index 12d69e2..36e4b70 100644 (file)
@@ -303,6 +303,10 @@ public:
     operator wxGraphicsMatrix() const;
 #endif
 
+#if PLATFORM(WIN)
+    operator XFORM() const;
+#endif
+
 private:
     // multiply passed 2D point by matrix (assume z=0)
     void multVecMatrix(double x, double y, double& dstX, double& dstY) const;
index 1f99452..7192001 100644 (file)
@@ -108,13 +108,8 @@ HDC GraphicsContext::getWindowsContext(const IntRect& dstRect, bool supportAlpha
         SetGraphicsMode(bitmapDC, GM_ADVANCED);
 
         // Apply a translation to our context so that the drawing done will be at (0,0) of the bitmap.
-        XFORM xform;
-        xform.eM11 = 1.0f;
-        xform.eM12 = 0.0f;
-        xform.eM21 = 0.0f;
-        xform.eM22 = 1.0f;
-        xform.eDx = -dstRect.x();
-        xform.eDy = -dstRect.y();
+        TransformationMatrix translate(1.0f, 0.0f, 0.0f, 1.0f, -dstRect.x(), -dstRect.y());
+        XFORM xform = translate;
         ::SetWorldTransform(bitmapDC, &xform);
 
         return bitmapDC;
@@ -207,23 +202,6 @@ void GraphicsContext::drawWindowsBitmap(WindowsBitmap* image, const IntPoint& po
     CGContextDrawImage(m_data->m_cgContext, CGRectMake(point.x(), point.y(), image->size().width(), image->size().height()), cgImage.get());   
 }
 
-void GraphicsContextPlatformPrivate::concatCTM(const TransformationMatrix& transform)
-{
-    if (!m_hdc)
-        return;
-
-    CGAffineTransform mat = transform;
-    XFORM xform;
-    xform.eM11 = mat.a;
-    xform.eM12 = mat.b;
-    xform.eM21 = mat.c;
-    xform.eM22 = mat.d;
-    xform.eDx = mat.tx;
-    xform.eDy = mat.ty;
-
-    ModifyWorldTransform(m_hdc, &xform, MWT_LEFTMULTIPLY);
-}
-
 void GraphicsContext::drawFocusRing(const Color& color)
 {
     if (paintingDisabled())
index 1767dce..122eab8 100644 (file)
@@ -114,13 +114,10 @@ HDC GraphicsContext::getWindowsContext(const IntRect& dstRect, bool supportAlpha
         SetGraphicsMode(bitmapDC, GM_ADVANCED);
 
         // Apply a translation to our context so that the drawing done will be at (0,0) of the bitmap.
-        XFORM xform;
-        xform.eM11 = 1.0f;
-        xform.eM12 = 0.0f;
-        xform.eM21 = 0.0f;
-        xform.eM22 = 1.0f;
-        xform.eDx = -dstRect.x();
-        xform.eDy = -dstRect.y();
+        TransformationMatrix translate(1.0f, 0.0f, 0.0f, 1.0f, -dstRect.x(), -dstRect.y());
+
+        XFORM xform = translate;
+
         ::SetWorldTransform(bitmapDC, &xform);
 
         return bitmapDC;
@@ -177,21 +174,6 @@ void GraphicsContext::releaseWindowsContext(HDC hdc, const IntRect& dstRect, boo
     ::DeleteObject(bitmap);
 }
 
-void GraphicsContextPlatformPrivate::concatCTM(const TransformationMatrix& transform)
-{
-    const cairo_matrix_t* matrix = reinterpret_cast<const cairo_matrix_t*>(&transform);
-
-    XFORM xform;
-    xform.eM11 = matrix->xx;
-    xform.eM12 = matrix->xy;
-    xform.eM21 = matrix->yx;
-    xform.eM22 = matrix->yy;
-    xform.eDx = matrix->x0;
-    xform.eDy = matrix->y0;
-
-    ModifyWorldTransform(m_hdc, &xform, MWT_LEFTMULTIPLY);
-}
-
 void GraphicsContextPlatformPrivate::syncContext(PlatformGraphicsContext* cr)
 {
     if (!cr)
index e4c5b04..60ea36b 100644 (file)
@@ -85,13 +85,10 @@ void GraphicsContextPlatformPrivate::scale(const FloatSize& size)
 {
     if (!m_hdc)
         return;
-    XFORM xform;
-    xform.eM11 = size.width();
-    xform.eM12 = 0.0f;
-    xform.eM21 = 0.0f;
-    xform.eM22 = size.height();
-    xform.eDx = 0.0f;
-    xform.eDy = 0.0f;
+
+    TransformationMatrix scale(size.width(), 0.0f, 0.0f, size.height(), 0.0f, 0.0f);
+
+    XFORM xform = scale;
     ModifyWorldTransform(m_hdc, &xform, MWT_LEFTMULTIPLY);
 }
 
@@ -102,13 +99,10 @@ void GraphicsContextPlatformPrivate::rotate(float degreesAngle)
     float radiansAngle = degreesAngle * deg2rad;
     float cosAngle = cosf(radiansAngle);
     float sinAngle = sinf(radiansAngle);
-    XFORM xform;
-    xform.eM11 = cosAngle;
-    xform.eM12 = -sinAngle;
-    xform.eM21 = sinAngle;
-    xform.eM22 = cosAngle;
-    xform.eDx = 0.0f;
-    xform.eDy = 0.0f;
+
+    TransformationMatrix rotate(cosAngle, -sinAngle, sinAngle, cosAngle, 0.0f, 0.0f);
+
+    XFORM xform = rotate;
     ModifyWorldTransform(m_hdc, &xform, MWT_LEFTMULTIPLY);
 }
 
@@ -116,13 +110,20 @@ void GraphicsContextPlatformPrivate::translate(float x , float y)
 {
     if (!m_hdc)
         return;
-    XFORM xform;
-    xform.eM11 = 1.0f;
-    xform.eM12 = 0.0f;
-    xform.eM21 = 0.0f;
-    xform.eM22 = 1.0f;
-    xform.eDx = x;
-    xform.eDy = y;
+
+    TransformationMatrix translate(1.0f, 0.0f, 0.0f, 1.0f, x, y);
+
+    XFORM xform = translate;
+    ModifyWorldTransform(m_hdc, &xform, MWT_LEFTMULTIPLY);
+}
+
+void GraphicsContextPlatformPrivate::concatCTM(const TransformationMatrix& transform)
+{
+    if (!m_hdc)
+        return;
+
+    XFORM xform = transform;
+
     ModifyWorldTransform(m_hdc, &xform, MWT_LEFTMULTIPLY);
 }
 
diff --git a/WebCore/platform/graphics/win/TransformationMatrixWin.cpp b/WebCore/platform/graphics/win/TransformationMatrixWin.cpp
new file mode 100644 (file)
index 0000000..38dbfbf
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2009 Apple Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "config.h"
+#include "TransformationMatrix.h"
+
+namespace WebCore {
+
+TransformationMatrix::operator XFORM() const
+{
+    XFORM xform;
+    xform.eM11 = a();
+    xform.eM12 = b();
+    xform.eM21 = c();
+    xform.eM22 = d();
+    xform.eDx = e();
+    xform.eDy = f();
+
+    return xform;
+}
+
+}