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

        Move some common functions out of platform files and into
        the common implementation.

        https://bugs.webkit.org/show_bug.cgi?id=26425.
        Add a new platform context method (flush) so that the
        getWindowsContext method can be consolidated into the common
        GraphicsContextWin.cpp file.

        * platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h:
        (WebCore::GraphicsContextPlatformPrivate::flush):
        * platform/graphics/cg/GraphicsContextPlatformPrivateCG.h:
        (WebCore::GraphicsContextPlatformPrivate::flush):
        * platform/graphics/win/GraphicsContextCGWin.cpp: Remove
          getWindowContext method.
        * platform/graphics/win/GraphicsContextCairoWin.cpp: Remove
          getWindowContext method and fillWithClearColor methods.
        * platform/graphics/win/GraphicsContextWin.cpp:
        (WebCore::fillWithClearColor): Moved from *CairoWin.cpp
        (WebCore::GraphicsContext::getWindowsContext): Moved
          from *CairoWin.cpp

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

WebCore/ChangeLog
WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h
WebCore/platform/graphics/cg/GraphicsContextPlatformPrivateCG.h
WebCore/platform/graphics/win/GraphicsContextCGWin.cpp
WebCore/platform/graphics/win/GraphicsContextCairoWin.cpp
WebCore/platform/graphics/win/GraphicsContextWin.cpp

index 213f9c8..39e53e1 100644 (file)
@@ -1,3 +1,28 @@
+2009-06-17  Brent Fulgham  <bfulgham@webkit.org>
+
+        Reviewed by Eric Seidel.
+
+        Move some common functions out of platform files and into
+        the common implementation.
+
+        https://bugs.webkit.org/show_bug.cgi?id=26425.
+        Add a new platform context method (flush) so that the
+        getWindowsContext method can be consolidated into the common
+        GraphicsContextWin.cpp file.
+         
+        * platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h:
+        (WebCore::GraphicsContextPlatformPrivate::flush):
+        * platform/graphics/cg/GraphicsContextPlatformPrivateCG.h:
+        (WebCore::GraphicsContextPlatformPrivate::flush):
+        * platform/graphics/win/GraphicsContextCGWin.cpp: Remove
+          getWindowContext method.
+        * platform/graphics/win/GraphicsContextCairoWin.cpp: Remove
+          getWindowContext method and fillWithClearColor methods.
+        * platform/graphics/win/GraphicsContextWin.cpp:
+        (WebCore::fillWithClearColor): Moved from *CairoWin.cpp
+        (WebCore::GraphicsContext::getWindowsContext): Moved
+          from *CairoWin.cpp
+
 2009-06-18  Ojan Vafai  <ojan@chromium.org>
 
         Reviewed by Oliver Hunt.
index 531ebf4..54e1217 100644 (file)
@@ -65,6 +65,7 @@ public:
     // On Windows, we need to update the HDC for form controls to draw in the right place.
     void save();
     void restore();
+    void flush();
     void clip(const FloatRect&);
     void clip(const Path&);
     void scale(const FloatSize&);
@@ -78,6 +79,7 @@ public:
     // On everything else, we do nothing.
     void save() {}
     void restore() {}
+    void flush() {}
     void clip(const FloatRect&) {}
     void clip(const Path&) {}
     void scale(const FloatSize&) {}
index beee660..f63a8dd 100644 (file)
@@ -50,6 +50,7 @@ public:
     // These methods do nothing on Mac.
     void save() {}
     void restore() {}
+    void flush() {}
     void clip(const FloatRect&) {}
     void clip(const Path&) {}
     void scale(const FloatSize&) {}
@@ -64,6 +65,7 @@ public:
     // On Windows, we need to update the HDC for form controls to draw in the right place.
     void save();
     void restore();
+    void flush();
     void clip(const FloatRect&);
     void clip(const Path&);
     void scale(const FloatSize&);
index 7192001..31e3163 100644 (file)
@@ -78,48 +78,6 @@ GraphicsContext::GraphicsContext(HDC hdc, bool hasAlpha)
 
 // FIXME: Is it possible to merge getWindowsContext and createWindowsBitmap into a single API
 // suitable for all clients?
-HDC GraphicsContext::getWindowsContext(const IntRect& dstRect, bool supportAlphaBlend, bool mayCreateBitmap)
-{
-    // FIXME: Should a bitmap be created also when a shadow is set?
-    if (mayCreateBitmap && inTransparencyLayer()) {
-        if (dstRect.isEmpty())
-            return 0;
-
-        // Create a bitmap DC in which to draw.
-        BitmapInfo bitmapInfo = BitmapInfo::create(dstRect.size());
-
-        void* pixels = 0;
-        HBITMAP bitmap = ::CreateDIBSection(NULL, &bitmapInfo, DIB_RGB_COLORS, &pixels, 0, 0);
-        if (!bitmap)
-            return 0;
-
-        HDC bitmapDC = ::CreateCompatibleDC(m_data->m_hdc);
-        ::SelectObject(bitmapDC, bitmap);
-
-        // Fill our buffer with clear if we're going to alpha blend.
-        if (supportAlphaBlend) {
-            BITMAP bmpInfo;
-            GetObject(bitmap, sizeof(bmpInfo), &bmpInfo);
-            int bufferSize = bmpInfo.bmWidthBytes * bmpInfo.bmHeight;
-            memset(bmpInfo.bmBits, 0, bufferSize);
-        }
-
-        // Make sure we can do world transforms.
-        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;
-        ::SetWorldTransform(bitmapDC, &xform);
-
-        return bitmapDC;
-    }
-
-    CGContextFlush(platformContext());
-    m_data->save();
-    return m_data->m_hdc;
-}
-
 void GraphicsContext::releaseWindowsContext(HDC hdc, const IntRect& dstRect, bool supportAlphaBlend, bool mayCreateBitmap)
 {
     if (mayCreateBitmap && hdc && inTransparencyLayer()) {
@@ -319,4 +277,9 @@ void GraphicsContext::drawLineForMisspellingOrBadGrammar(const IntPoint& point,
     CGContextRestoreGState(context);
 }
 
+void GraphicsContextPlatformPrivate::flush()
+{
+    CGContextFlush(m_cgContext);
+}
+
 }
index 122eab8..2489e02 100644 (file)
@@ -26,7 +26,6 @@
 #include "config.h"
 #include "GraphicsContext.h"
 
-#include "BitmapInfo.h"
 #include "TransformationMatrix.h"
 #include "Path.h"
 
@@ -60,14 +59,6 @@ static cairo_t* createCairoContextWithHDC(HDC hdc, bool hasAlpha)
     return context;
 }
 
-static void fillWithClearColor(HBITMAP bitmap)
-{
-    BITMAP bmpInfo;
-    GetObject(bitmap, sizeof(bmpInfo), &bmpInfo);
-    int bufferSize = bmpInfo.bmWidthBytes * bmpInfo.bmHeight;
-    memset(bmpInfo.bmBits, 0, bufferSize);
-}
-
 GraphicsContext::GraphicsContext(HDC dc, bool hasAlpha)
     : m_common(createGraphicsContextPrivate())
     , m_data(new GraphicsContextPlatformPrivate)
@@ -88,50 +79,6 @@ GraphicsContext::GraphicsContext(HDC dc, bool hasAlpha)
     }
 }
 
-HDC GraphicsContext::getWindowsContext(const IntRect& dstRect, bool supportAlphaBlend, bool mayCreateBitmap)
-{
-    // FIXME: Should a bitmap be created also when a shadow is set?
-    if (mayCreateBitmap && inTransparencyLayer()) {
-        if (dstRect.isEmpty())
-            return 0;
-
-        // Create a bitmap DC in which to draw.
-        BitmapInfo bitmapInfo = BitmapInfo::create(dstRect.size());
-
-        void* pixels = 0;
-        HBITMAP bitmap = ::CreateDIBSection(NULL, &bitmapInfo, DIB_RGB_COLORS, &pixels, 0, 0);
-        if (!bitmap)
-            return 0;
-
-        HDC bitmapDC = ::CreateCompatibleDC(m_data->m_hdc);
-        ::SelectObject(bitmapDC, bitmap);
-
-        // Fill our buffer with clear if we're going to alpha blend.
-        if (supportAlphaBlend)
-           fillWithClearColor(bitmap);
-
-        // Make sure we can do world transforms.
-        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;
-
-        ::SetWorldTransform(bitmapDC, &xform);
-
-        return bitmapDC;
-    }
-
-    cairo_surface_t* surface = cairo_win32_surface_create(m_data->m_hdc);
-    cairo_surface_flush(surface);
-    cairo_surface_destroy(surface);
-
-    m_data->save();
-
-    return m_data->m_hdc;
-}
-
 void GraphicsContext::releaseWindowsContext(HDC hdc, const IntRect& dstRect, bool supportAlphaBlend, bool mayCreateBitmap)
 {
     if (!mayCreateBitmap || !hdc || !inTransparencyLayer()) {
@@ -185,4 +132,11 @@ void GraphicsContextPlatformPrivate::syncContext(PlatformGraphicsContext* cr)
     SetGraphicsMode(m_hdc, GM_ADVANCED); // We need this call for themes to honor world transforms.
 }
 
+void GraphicsContextPlatformPrivate::flush()
+{
+    cairo_surface_t* surface = cairo_win32_surface_create(m_hdc);
+    cairo_surface_flush(surface);
+    cairo_surface_destroy(surface);
+}
+
 }
index 60ea36b..0d8bcfa 100644 (file)
@@ -32,6 +32,7 @@
 #include "GraphicsContextPlatformPrivateCairo.h"
 #endif
 
+#include "BitmapInfo.h"
 #include "TransformationMatrix.h"
 #include "NotImplemented.h"
 #include "Path.h"
@@ -43,6 +44,14 @@ namespace WebCore {
 
 class SVGResourceImage;
 
+static void fillWithClearColor(HBITMAP bitmap)
+{
+    BITMAP bmpInfo;
+    GetObject(bitmap, sizeof(bmpInfo), &bmpInfo);
+    int bufferSize = bmpInfo.bmWidthBytes * bmpInfo.bmHeight;
+    memset(bmpInfo.bmBits, 0, bufferSize);
+}
+
 bool GraphicsContext::inTransparencyLayer() const { return m_data->m_transparencyCount; }
 
 void GraphicsContext::setShouldIncludeChildWindows(bool include)
@@ -55,6 +64,45 @@ bool GraphicsContext::shouldIncludeChildWindows() const
     return m_data->m_shouldIncludeChildWindows;
 }
 
+HDC GraphicsContext::getWindowsContext(const IntRect& dstRect, bool supportAlphaBlend, bool mayCreateBitmap)
+{
+    // FIXME: Should a bitmap be created also when a shadow is set?
+    if (mayCreateBitmap && inTransparencyLayer()) {
+        if (dstRect.isEmpty())
+            return 0;
+
+        // Create a bitmap DC in which to draw.
+        BitmapInfo bitmapInfo = BitmapInfo::create(dstRect.size());
+
+        void* pixels = 0;
+        HBITMAP bitmap = ::CreateDIBSection(NULL, &bitmapInfo, DIB_RGB_COLORS, &pixels, 0, 0);
+        if (!bitmap)
+            return 0;
+
+        HDC bitmapDC = ::CreateCompatibleDC(m_data->m_hdc);
+        ::SelectObject(bitmapDC, bitmap);
+
+        // Fill our buffer with clear if we're going to alpha blend.
+        if (supportAlphaBlend)
+           fillWithClearColor(bitmap);
+
+        // Make sure we can do world transforms.
+        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;
+
+        ::SetWorldTransform(bitmapDC, &xform);
+
+        return bitmapDC;
+    }
+
+    m_data->flush();
+    m_data->save();
+    return m_data->m_hdc;
+}
+
 void GraphicsContextPlatformPrivate::save()
 {
     if (!m_hdc)