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

        Final cleanups in this refactoring:
        (1) Move WindowsBitmap implementation from CG-specific file to
            the platform-common GraphicsContextWin.cpp, since it is
            equally useful on both platforms.
        (2) Revise the TransformationMatrix logic as suggested by
            Adam Roben in his review comments to Part #2 of this
            refactoring.

        * platform/graphics/win/GraphicsContextCGWin.cpp:
        * platform/graphics/win/GraphicsContextWin.cpp:
        (WebCore::GraphicsContext::WindowsBitmap::WindowsBitmap):
        (WebCore::GraphicsContext::WindowsBitmap::~WindowsBitmap):
        (WebCore::GraphicsContext::createWindowsBitmap):
        (WebCore::GraphicsContext::getWindowsContext):
        (WebCore::GraphicsContextPlatformPrivate::scale):
        (WebCore::GraphicsContextPlatformPrivate::rotate):
        (WebCore::GraphicsContextPlatformPrivate::translate):
        (WebCore::GraphicsContextPlatformPrivate::concatCTM):

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

WebCore/ChangeLog
WebCore/platform/graphics/win/GraphicsContextCGWin.cpp
WebCore/platform/graphics/win/GraphicsContextWin.cpp

index fe82920..7b94997 100644 (file)
@@ -1,3 +1,26 @@
+2009-06-17  Brent Fulgham  <bfulgham@webkit.org>
+
+        Reviewed by Eric Seidel.
+
+        Final cleanups in this refactoring:
+        (1) Move WindowsBitmap implementation from CG-specific file to
+            the platform-common GraphicsContextWin.cpp, since it is
+            equally useful on both platforms.
+        (2) Revise the TransformationMatrix logic as suggested by
+            Adam Roben in his review comments to Part #2 of this
+            refactoring.
+
+        * platform/graphics/win/GraphicsContextCGWin.cpp:
+        * platform/graphics/win/GraphicsContextWin.cpp:
+        (WebCore::GraphicsContext::WindowsBitmap::WindowsBitmap):
+        (WebCore::GraphicsContext::WindowsBitmap::~WindowsBitmap):
+        (WebCore::GraphicsContext::createWindowsBitmap):
+        (WebCore::GraphicsContext::getWindowsContext):
+        (WebCore::GraphicsContextPlatformPrivate::scale):
+        (WebCore::GraphicsContextPlatformPrivate::rotate):
+        (WebCore::GraphicsContextPlatformPrivate::translate):
+        (WebCore::GraphicsContextPlatformPrivate::concatCTM):
+
 2009-06-18  Peter Kasting  <pkasting@google.com>
 
         Reviewed by Eric Seidel.
index 31e3163..9eaf54b 100644 (file)
@@ -26,7 +26,6 @@
 #include "config.h"
 #include "GraphicsContext.h"
 
-#include "BitmapInfo.h"
 #include "TransformationMatrix.h"
 #include "Path.h"
 
@@ -113,41 +112,6 @@ void GraphicsContext::releaseWindowsContext(HDC hdc, const IntRect& dstRect, boo
     m_data->restore();
 }
 
-GraphicsContext::WindowsBitmap::WindowsBitmap(HDC hdc, IntSize size)
-    : m_hdc(0)
-    , m_size(size)
-{
-    BitmapInfo bitmapInfo = BitmapInfo::create(m_size);
-
-    m_bitmap = CreateDIBSection(0, &bitmapInfo, DIB_RGB_COLORS, reinterpret_cast<void**>(&m_bitmapBuffer), 0, 0);
-    if (!m_bitmap)
-        return;
-
-    m_hdc = CreateCompatibleDC(hdc);
-    SelectObject(m_hdc, m_bitmap);
-
-    BITMAP bmpInfo;
-    GetObject(m_bitmap, sizeof(bmpInfo), &bmpInfo);
-    m_bytesPerRow = bmpInfo.bmWidthBytes;
-    m_bitmapBufferLength = bmpInfo.bmWidthBytes * bmpInfo.bmHeight;
-
-    SetGraphicsMode(m_hdc, GM_ADVANCED);
-}
-
-GraphicsContext::WindowsBitmap::~WindowsBitmap()
-{
-    if (!m_bitmap)
-        return;
-
-    DeleteDC(m_hdc);
-    DeleteObject(m_bitmap);
-}
-
-GraphicsContext::WindowsBitmap* GraphicsContext::createWindowsBitmap(IntSize size)
-{
-    return new WindowsBitmap(m_data->m_hdc, size);
-}
-
 void GraphicsContext::drawWindowsBitmap(WindowsBitmap* image, const IntPoint& point)
 {
     RetainPtr<CGColorSpaceRef> deviceRGB(AdoptCF, CGColorSpaceCreateDeviceRGB());
index 0d8bcfa..54b0cb2 100644 (file)
@@ -64,6 +64,41 @@ bool GraphicsContext::shouldIncludeChildWindows() const
     return m_data->m_shouldIncludeChildWindows;
 }
 
+GraphicsContext::WindowsBitmap::WindowsBitmap(HDC hdc, IntSize size)
+    : m_hdc(0)
+    , m_size(size)
+{
+    BitmapInfo bitmapInfo = BitmapInfo::create(m_size);
+
+    m_bitmap = CreateDIBSection(0, &bitmapInfo, DIB_RGB_COLORS, reinterpret_cast<void**>(&m_bitmapBuffer), 0, 0);
+    if (!m_bitmap)
+        return;
+
+    m_hdc = CreateCompatibleDC(hdc);
+    SelectObject(m_hdc, m_bitmap);
+
+    BITMAP bmpInfo;
+    GetObject(m_bitmap, sizeof(bmpInfo), &bmpInfo);
+    m_bytesPerRow = bmpInfo.bmWidthBytes;
+    m_bitmapBufferLength = bmpInfo.bmWidthBytes * bmpInfo.bmHeight;
+
+    SetGraphicsMode(m_hdc, GM_ADVANCED);
+}
+
+GraphicsContext::WindowsBitmap::~WindowsBitmap()
+{
+    if (!m_bitmap)
+        return;
+
+    DeleteDC(m_hdc);
+    DeleteObject(m_bitmap);
+}
+
+GraphicsContext::WindowsBitmap* GraphicsContext::createWindowsBitmap(IntSize size)
+{
+    return new WindowsBitmap(m_data->m_hdc, size);
+}
+
 HDC GraphicsContext::getWindowsContext(const IntRect& dstRect, bool supportAlphaBlend, bool mayCreateBitmap)
 {
     // FIXME: Should a bitmap be created also when a shadow is set?
@@ -90,8 +125,7 @@ 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.
-        TransformationMatrix translate(1.0f, 0.0f, 0.0f, 1.0f, -dstRect.x(), -dstRect.y());
-        XFORM xform = translate;
+        XFORM xform = TransformationMatrix().translate(-dstRect.x(), -dstRect.y());
 
         ::SetWorldTransform(bitmapDC, &xform);
 
@@ -134,9 +168,7 @@ void GraphicsContextPlatformPrivate::scale(const FloatSize& size)
     if (!m_hdc)
         return;
 
-    TransformationMatrix scale(size.width(), 0.0f, 0.0f, size.height(), 0.0f, 0.0f);
-
-    XFORM xform = scale;
+    XFORM xform = TransformationMatrix().scaleNonUniform(size.width(), size.height());
     ModifyWorldTransform(m_hdc, &xform, MWT_LEFTMULTIPLY);
 }
 
@@ -144,13 +176,7 @@ static const double deg2rad = 0.017453292519943295769; // pi/180
 
 void GraphicsContextPlatformPrivate::rotate(float degreesAngle)
 {
-    float radiansAngle = degreesAngle * deg2rad;
-    float cosAngle = cosf(radiansAngle);
-    float sinAngle = sinf(radiansAngle);
-
-    TransformationMatrix rotate(cosAngle, -sinAngle, sinAngle, cosAngle, 0.0f, 0.0f);
-
-    XFORM xform = rotate;
+    XFORM xform = TransformationMatrix().rotate(degreesAngle);
     ModifyWorldTransform(m_hdc, &xform, MWT_LEFTMULTIPLY);
 }
 
@@ -159,9 +185,7 @@ void GraphicsContextPlatformPrivate::translate(float x , float y)
     if (!m_hdc)
         return;
 
-    TransformationMatrix translate(1.0f, 0.0f, 0.0f, 1.0f, x, y);
-
-    XFORM xform = translate;
+    XFORM xform = TransformationMatrix().translate(x, y);
     ModifyWorldTransform(m_hdc, &xform, MWT_LEFTMULTIPLY);
 }
 
@@ -171,7 +195,6 @@ void GraphicsContextPlatformPrivate::concatCTM(const TransformationMatrix& trans
         return;
 
     XFORM xform = transform;
-
     ModifyWorldTransform(m_hdc, &xform, MWT_LEFTMULTIPLY);
 }