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

        Refactor a few common routines in the various Windows ports
        and reduce some duplicated code.
        https://bugs.webkit.org/show_bug.cgi?id=26425.

        Refactor use of BITMAPINFO for the new BitmapInfo structure.

        * WebCore.vcproj/WebCore.vcproj:
        * platform/win/BitmapInfo.cpp: Added.
        (WebCore::bitmapInfoForSize):
        (WebCore::BitmapInfo::create):
        (WebCore::BitmapInfo::createBottomUp):
        * platform/win/BitmapInfo.h: Added.
        * platform/graphics/win/GraphicsContextCairoWin.cpp:
        * platform/graphics/win/GraphicsContextCGWin.cpp:
        * platform/graphics/win/TransformationMatrixWin.cpp: Added.
        (WebCore::TransformationMatrix::operator XFORM): New operator
        * platform/win/DragImageCGWin.cpp:
        (WebCore::allocImage):
        * platform/win/DragImageCairoWin.cpp:
        (WebCore::allocImage):
        * platform/win/PasteboardWin.cpp:
        (WebCore::Pasteboard::writeImage):
        * platform/win/PopupMenuWin.cpp:
        (WebCore::PopupMenu::paint):

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

WebCore/ChangeLog
WebCore/WebCore.vcproj/WebCore.vcproj
WebCore/platform/graphics/win/GraphicsContextCGWin.cpp
WebCore/platform/graphics/win/GraphicsContextCairoWin.cpp
WebCore/platform/win/BitmapInfo.cpp [new file with mode: 0644]
WebCore/platform/win/BitmapInfo.h [new file with mode: 0644]
WebCore/platform/win/DragImageCGWin.cpp
WebCore/platform/win/DragImageCairoWin.cpp
WebCore/platform/win/PasteboardWin.cpp
WebCore/platform/win/PopupMenuWin.cpp

index 61af276..0c0b09f 100644 (file)
@@ -1,3 +1,32 @@
+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.
+        https://bugs.webkit.org/show_bug.cgi?id=26425.
+
+        Refactor use of BITMAPINFO for the new BitmapInfo structure.
+
+        * WebCore.vcproj/WebCore.vcproj:
+        * platform/win/BitmapInfo.cpp: Added.
+        (WebCore::bitmapInfoForSize):
+        (WebCore::BitmapInfo::create):
+        (WebCore::BitmapInfo::createBottomUp):
+        * platform/win/BitmapInfo.h: Added.
+        * platform/graphics/win/GraphicsContextCairoWin.cpp:
+        * platform/graphics/win/GraphicsContextCGWin.cpp:
+        * platform/graphics/win/TransformationMatrixWin.cpp: Added.
+        (WebCore::TransformationMatrix::operator XFORM): New operator
+        * platform/win/DragImageCGWin.cpp:
+        (WebCore::allocImage):
+        * platform/win/DragImageCairoWin.cpp:
+        (WebCore::allocImage):
+        * platform/win/PasteboardWin.cpp:
+        (WebCore::Pasteboard::writeImage):
+        * platform/win/PopupMenuWin.cpp:
+        (WebCore::PopupMenu::paint):
+
 2009-06-17  Adam Roben  <aroben@apple.com>
 
         Remove unnecessary 6th parameter from SOFT_LINK_OPTIONAL
index 56a23da..24efbab 100644 (file)
                                RelativePath="$(WebKitOutputDir)\obj\$(ProjectName)\DerivedSources\JSHTMLCollection.h"\r
                                >\r
                        </File>\r
-                        <File\r
+                       <File\r
                                RelativePath="$(WebKitOutputDir)\obj\$(ProjectName)\DerivedSources\JSHTMLDataGridElement.cpp"\r
                                >\r
                                <FileConfiguration\r
                        <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\win\BitmapInfo.cpp"\r
+                                       >\r
+                               </File>\r
+                               <File\r
+                                       RelativePath="..\platform\win\BitmapInfo.h"\r
+                                       >\r
+                               </File>\r
+                               <File\r
                                        RelativePath="..\platform\win\BString.cpp"\r
                                        >\r
                                </File>\r
index 917631b..1f99452 100644 (file)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "GraphicsContext.h"
 
+#include "BitmapInfo.h"
 #include "TransformationMatrix.h"
 #include "Path.h"
 
@@ -85,18 +86,7 @@ HDC GraphicsContext::getWindowsContext(const IntRect& dstRect, bool supportAlpha
             return 0;
 
         // Create a bitmap DC in which to draw.
-        BITMAPINFO bitmapInfo;
-        bitmapInfo.bmiHeader.biSize          = sizeof(BITMAPINFOHEADER);
-        bitmapInfo.bmiHeader.biWidth         = dstRect.width(); 
-        bitmapInfo.bmiHeader.biHeight        = dstRect.height();
-        bitmapInfo.bmiHeader.biPlanes        = 1;
-        bitmapInfo.bmiHeader.biBitCount      = 32;
-        bitmapInfo.bmiHeader.biCompression   = BI_RGB;
-        bitmapInfo.bmiHeader.biSizeImage     = 0;
-        bitmapInfo.bmiHeader.biXPelsPerMeter = 0;
-        bitmapInfo.bmiHeader.biYPelsPerMeter = 0;
-        bitmapInfo.bmiHeader.biClrUsed       = 0;
-        bitmapInfo.bmiHeader.biClrImportant  = 0;
+        BitmapInfo bitmapInfo = BitmapInfo::create(dstRect.size());
 
         void* pixels = 0;
         HBITMAP bitmap = ::CreateDIBSection(NULL, &bitmapInfo, DIB_RGB_COLORS, &pixels, 0, 0);
@@ -174,18 +164,7 @@ GraphicsContext::WindowsBitmap::WindowsBitmap(HDC hdc, IntSize size)
     : m_hdc(0)
     , m_size(size)
 {
-    BITMAPINFO bitmapInfo;
-    bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
-    bitmapInfo.bmiHeader.biWidth = m_size.width(); 
-    bitmapInfo.bmiHeader.biHeight = m_size.height();
-    bitmapInfo.bmiHeader.biPlanes = 1;
-    bitmapInfo.bmiHeader.biBitCount = 32;
-    bitmapInfo.bmiHeader.biCompression = BI_RGB;
-    bitmapInfo.bmiHeader.biSizeImage = 0;
-    bitmapInfo.bmiHeader.biXPelsPerMeter = 0;
-    bitmapInfo.bmiHeader.biYPelsPerMeter = 0;
-    bitmapInfo.bmiHeader.biClrUsed = 0;
-    bitmapInfo.bmiHeader.biClrImportant = 0;
+    BitmapInfo bitmapInfo = BitmapInfo::create(m_size);
 
     m_bitmap = CreateDIBSection(0, &bitmapInfo, DIB_RGB_COLORS, reinterpret_cast<void**>(&m_bitmapBuffer), 0, 0);
     if (!m_bitmap)
index 7d76794..1767dce 100644 (file)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "GraphicsContext.h"
 
+#include "BitmapInfo.h"
 #include "TransformationMatrix.h"
 #include "Path.h"
 
@@ -59,24 +60,6 @@ static cairo_t* createCairoContextWithHDC(HDC hdc, bool hasAlpha)
     return context;
 }
 
-static BITMAPINFO bitmapInfoForSize(const IntSize& size)
-{
-    BITMAPINFO bitmapInfo;
-    bitmapInfo.bmiHeader.biSize          = sizeof(BITMAPINFOHEADER);
-    bitmapInfo.bmiHeader.biWidth         = size.width(); 
-    bitmapInfo.bmiHeader.biHeight        = size.height();
-    bitmapInfo.bmiHeader.biPlanes        = 1;
-    bitmapInfo.bmiHeader.biBitCount      = 32;
-    bitmapInfo.bmiHeader.biCompression   = BI_RGB;
-    bitmapInfo.bmiHeader.biSizeImage     = 0;
-    bitmapInfo.bmiHeader.biXPelsPerMeter = 0;
-    bitmapInfo.bmiHeader.biYPelsPerMeter = 0;
-    bitmapInfo.bmiHeader.biClrUsed       = 0;
-    bitmapInfo.bmiHeader.biClrImportant  = 0;
-
-    return bitmapInfo;
-}
-
 static void fillWithClearColor(HBITMAP bitmap)
 {
     BITMAP bmpInfo;
@@ -113,7 +96,7 @@ HDC GraphicsContext::getWindowsContext(const IntRect& dstRect, bool supportAlpha
             return 0;
 
         // Create a bitmap DC in which to draw.
-        BITMAPINFO bitmapInfo = bitmapInfoForSize(dstRect.size());
+        BitmapInfo bitmapInfo = BitmapInfo::create(dstRect.size());
 
         void* pixels = 0;
         HBITMAP bitmap = ::CreateDIBSection(NULL, &bitmapInfo, DIB_RGB_COLORS, &pixels, 0, 0);
diff --git a/WebCore/platform/win/BitmapInfo.cpp b/WebCore/platform/win/BitmapInfo.cpp
new file mode 100644 (file)
index 0000000..9a2312c
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2009 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2009 Brent Fulgham
+ *
+ * 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 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 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 "BitmapInfo.h"
+
+namespace WebCore {
+
+BitmapInfo bitmapInfoForSize(int width, int height)
+{
+    BitmapInfo bitmapInfo;
+    bitmapInfo.bmiHeader.biSize          = sizeof(BITMAPINFOHEADER);
+    bitmapInfo.bmiHeader.biWidth         = width; 
+    bitmapInfo.bmiHeader.biHeight        = height;
+    bitmapInfo.bmiHeader.biPlanes        = 1;
+    bitmapInfo.bmiHeader.biBitCount      = 32;
+    bitmapInfo.bmiHeader.biCompression   = BI_RGB;
+    bitmapInfo.bmiHeader.biSizeImage     = 0;
+    bitmapInfo.bmiHeader.biXPelsPerMeter = 0;
+    bitmapInfo.bmiHeader.biYPelsPerMeter = 0;
+    bitmapInfo.bmiHeader.biClrUsed       = 0;
+    bitmapInfo.bmiHeader.biClrImportant  = 0;
+
+    return bitmapInfo;
+}
+
+BitmapInfo::BitmapInfo()
+{
+    memset(&bmiHeader, 0, sizeof(bmiHeader));
+    bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+}
+
+BitmapInfo BitmapInfo::create(const IntSize& size)
+{
+   return bitmapInfoForSize(size.width(), size.height());
+}
+
+BitmapInfo BitmapInfo::createBottomUp(const IntSize& size)
+{
+   return bitmapInfoForSize(size.width(), -size.height());
+}
+
+} // namespace WebCore
diff --git a/WebCore/platform/win/BitmapInfo.h b/WebCore/platform/win/BitmapInfo.h
new file mode 100644 (file)
index 0000000..0127fdb
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2009 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2009 Brent Fulgham
+ *
+ * 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 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 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.
+ */
+
+#ifndef BitmapInfo_h
+#define BitmapInfo_h
+
+#include <windows.h>
+#include "IntSize.h"
+
+namespace WebCore {
+
+struct BitmapInfo : public BITMAPINFO {
+    BitmapInfo ();
+    static BitmapInfo create(const IntSize&);
+    static BitmapInfo createBottomUp(const IntSize&);
+};
+
+} // namespace WebCore
+
+#endif // BitmapInfo_h
index 77b358b..ffd2162 100644 (file)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "DragImage.h"
 
+#include "BitmapInfo.h"
 #include "CachedImage.h"
 #include "GraphicsContext.h"
 #include "Image.h"
@@ -44,16 +45,10 @@ void deallocContext(CGContextRef target)
 
 HBITMAP allocImage(HDC dc, IntSize size, CGContextRef *targetRef)
 {
-    HBITMAP hbmp;
-    BITMAPINFO bmpInfo = {0};
-    bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
-    bmpInfo.bmiHeader.biWidth = size.width();
-    bmpInfo.bmiHeader.biHeight = size.height();
-    bmpInfo.bmiHeader.biPlanes = 1;
-    bmpInfo.bmiHeader.biBitCount = 32;
-    bmpInfo.bmiHeader.biCompression = BI_RGB;
+    BitmapInfo bmpInfo = BitmapInfo::create(size);
+
     LPVOID bits;
-    hbmp = CreateDIBSection(dc, &bmpInfo, DIB_RGB_COLORS, &bits, 0, 0);
+    HBITMAP hbmp = CreateDIBSection(dc, &bmpInfo, DIB_RGB_COLORS, &bits, 0, 0);
 
     if (!targetRef)
         return hbmp;
index 1b8fb06..e356575 100644 (file)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "DragImage.h"
 
+#include "BitmapInfo.h"
 #include "CachedImage.h"
 #include "GraphicsContext.h"
 #include "Image.h"
@@ -49,15 +50,7 @@ void deallocContext(CairoContextRef target)
 
 HBITMAP allocImage(HDC dc, IntSize size, CairoContextRef* targetRef)
 {
-    BITMAPINFO bmpInfo = {0};
-    bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
-    bmpInfo.bmiHeader.biWidth = size.width();
-    bmpInfo.bmiHeader.biHeight = size.height(); // Must be positive!
-    bmpInfo.bmiHeader.biPlanes = 1;
-    bmpInfo.bmiHeader.biBitCount = 32;
-    bmpInfo.bmiHeader.biCompression = BI_RGB;
-    bmpInfo.bmiHeader.biClrUsed = 0; // unused
-    bmpInfo.bmiHeader.biClrImportant = 0;
+    BitmapInfo bmpInfo = BitmapInfo::create(size);
 
     LPVOID bits;
     HBITMAP hbmp = CreateDIBSection(dc, &bmpInfo, DIB_RGB_COLORS, &bits, 0, 0);
index 8cf9bf2..e3633f4 100644 (file)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "Pasteboard.h"
 
+#include "BitmapInfo.h"
 #include "CString.h"
 #include "ClipboardUtilitiesWin.h"
 #include "Document.h"
@@ -201,13 +202,8 @@ void Pasteboard::writeImage(Node* node, const KURL&, const String&)
     HBITMAP resultBitmap = CreateCompatibleBitmap(dc, image->width(), image->height());
     HBITMAP oldBitmap = (HBITMAP)SelectObject(compatibleDC, resultBitmap);
 
-    BITMAPINFO bmInfo = {0};
-    bmInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
-    bmInfo.bmiHeader.biWidth = image->width();
-    bmInfo.bmiHeader.biHeight = image->height();
-    bmInfo.bmiHeader.biPlanes = 1;
-    bmInfo.bmiHeader.biBitCount = 32;
-    bmInfo.bmiHeader.biCompression = BI_RGB;
+    BitmapInfo bmInfo = BitmapInfo::create(image->size());
+
     HBITMAP coreBitmap = CreateDIBSection(dc, &bmInfo, DIB_RGB_COLORS, 0, 0, 0);
     HBITMAP oldSource = (HBITMAP)SelectObject(sourceDC, coreBitmap);
     image->getHBITMAP(coreBitmap);
index 21169c3..c8d7ba7 100644 (file)
@@ -21,6 +21,7 @@
 #include "config.h"
 #include "PopupMenu.h"
 
+#include "BitmapInfo.h"
 #include "Document.h"
 #include "FloatRect.h"
 #include "FontSelector.h"
@@ -451,18 +452,7 @@ void PopupMenu::paint(const IntRect& damageRect, HDC hdc)
         }
     }
     if (!m_bmp) {
-        BITMAPINFO bitmapInfo;
-        bitmapInfo.bmiHeader.biSize          = sizeof(BITMAPINFOHEADER);
-        bitmapInfo.bmiHeader.biWidth         = clientRect().width(); 
-        bitmapInfo.bmiHeader.biHeight        = -clientRect().height();
-        bitmapInfo.bmiHeader.biPlanes        = 1;
-        bitmapInfo.bmiHeader.biBitCount      = 32;
-        bitmapInfo.bmiHeader.biCompression   = BI_RGB;
-        bitmapInfo.bmiHeader.biSizeImage     = 0;
-        bitmapInfo.bmiHeader.biXPelsPerMeter = 0;
-        bitmapInfo.bmiHeader.biYPelsPerMeter = 0;
-        bitmapInfo.bmiHeader.biClrUsed       = 0;
-        bitmapInfo.bmiHeader.biClrImportant  = 0;
+        BITMAPINFO bitmapInfo = BitmapInfo::createBottomUp(clientRect().size());
 
         void* pixels = 0;
         m_bmp = ::CreateDIBSection(m_DC, &bitmapInfo, DIB_RGB_COLORS, &pixels, 0, 0);