2011-06-22 Martin Robinson <mrobinson@igalia.com>
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Jun 2011 13:49:45 +0000 (13:49 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Jun 2011 13:49:45 +0000 (13:49 +0000)
        Reviewed by Adam Roben.

        [GTK] Implement pixel dump support for WebKitTestRunner
        https://bugs.webkit.org/show_bug.cgi?id=58242

        * GNUmakefile.am: Reference the new ImageDiff GNUmakefile.
2011-06-22  Martin Robinson  <mrobinson@igalia.com>

        Reviewed by Adam Roben.

        [GTK] Implement pixel dump support for WebKitTestRunner
        https://bugs.webkit.org/show_bug.cgi?id=58242

        * GNUmakefile.am: Added new Cairo specific image handling files to the build.
        * Shared/API/c/cairo/WKImageCairo.cpp: Copied from Source/WebKit2/Shared/cairo/ShareableBitmapCairo.cpp.
        (WKImageCreateCairoSurface): Added
        (WKImageCreateFromCairoSurface): Added
        * Shared/API/c/cairo/WKImageCairo.h: Copied from Source/WebKit2/Shared/cairo/ShareableBitmapCairo.cpp.
2011-06-22  Martin Robinson  <mrobinson@igalia.com>

        Reviewed by Adam Roben.

        [GTK] Implement pixel dump support for WebKitTestRunner
        https://bugs.webkit.org/show_bug.cgi?id=58242

        * DumpRenderTree/gtk/GNUmakefile.ImageDiff.am: Added.
        * GNUmakefile.am: Separate out the ImageDiff bits of the GNUmakefile.
        * Scripts/old-run-webkit-tests: Update to add support for the GTK+ port.
        * WebKitTestRunner/GNUmakefile.am: Added Cairo specific files to the build.
        * WebKitTestRunner/TestInvocation.cpp: Moved this code to the platform-independent
        file so that we can share it across platforms.
        (WTR::TestInvocation::compareActualHashToExpectedAndDumpResults):
        * WebKitTestRunner/TestInvocation.h: Updated method list.
        * WebKitTestRunner/cairo/TestInvocationCairo.cpp: Added Cairo implementation.
        * WebKitTestRunner/cg/TestInvocationCG.cpp:
        (WTR::TestInvocation::dumpPixelsAndCompareWithExpected): Updated to use new helper.

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

14 files changed:
ChangeLog
GNUmakefile.am
Source/WebKit2/ChangeLog
Source/WebKit2/GNUmakefile.am
Source/WebKit2/Shared/API/c/cairo/WKImageCairo.cpp [new file with mode: 0644]
Source/WebKit2/Shared/API/c/cairo/WKImageCairo.h [moved from Tools/WebKitTestRunner/gtk/TestInvocationGtk.cpp with 72% similarity]
Tools/ChangeLog
Tools/DumpRenderTree/gtk/GNUmakefile.ImageDiff.am [new file with mode: 0644]
Tools/GNUmakefile.am
Tools/WebKitTestRunner/GNUmakefile.am
Tools/WebKitTestRunner/TestInvocation.cpp
Tools/WebKitTestRunner/TestInvocation.h
Tools/WebKitTestRunner/cairo/TestInvocationCairo.cpp
Tools/WebKitTestRunner/cg/TestInvocationCG.cpp

index c0224f7..6597800 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2011-06-22  Martin Robinson  <mrobinson@igalia.com>
+
+        Reviewed by Adam Roben.
+
+        [GTK] Implement pixel dump support for WebKitTestRunner
+        https://bugs.webkit.org/show_bug.cgi?id=58242
+
+        * GNUmakefile.am: Reference the new ImageDiff GNUmakefile.
+
 2011-06-21  MORITA Hajime  <morrita@google.com>
 
         Unreviewed, rolling out r89401 and r89403.
index 9c88c19..fb10790 100644 (file)
@@ -197,6 +197,8 @@ include Source/WebKit/gtk/GNUmakefile.am
 include Source/WebCore/bindings/gobject/GNUmakefile.am
 include Tools/GNUmakefile.am
 include Source/WebKit/gtk/po/GNUmakefile.am
+include Tools/DumpRenderTree/gtk/GNUmakefile.ImageDiff.am
+
 if ENABLE_WEBKIT2
 include Source/WebKit2/GNUmakefile.am
 include Tools/MiniBrowser/gtk/GNUmakefile.am
index 04ffe91..ce99de0 100644 (file)
@@ -1,3 +1,16 @@
+2011-06-22  Martin Robinson  <mrobinson@igalia.com>
+
+        Reviewed by Adam Roben.
+
+        [GTK] Implement pixel dump support for WebKitTestRunner
+        https://bugs.webkit.org/show_bug.cgi?id=58242
+
+        * GNUmakefile.am: Added new Cairo specific image handling files to the build.
+        * Shared/API/c/cairo/WKImageCairo.cpp: Copied from Source/WebKit2/Shared/cairo/ShareableBitmapCairo.cpp.
+        (WKImageCreateCairoSurface): Added
+        (WKImageCreateFromCairoSurface): Added
+        * Shared/API/c/cairo/WKImageCairo.h: Copied from Source/WebKit2/Shared/cairo/ShareableBitmapCairo.cpp.
+
 2011-06-21  MORITA Hajime  <morrita@google.com>
 
         Unreviewed, rolling out r89401 and r89403.
index eb7ee22..43abde3 100644 (file)
@@ -126,6 +126,8 @@ libwebkit2gtk_@WEBKITGTK_API_MAJOR_VERSION@_@WEBKITGTK_API_MINOR_VERSION@_la_SOU
        Source/WebKit2/PluginProcess/gtk/PluginControllerProxyGtk.cpp \
        Source/WebKit2/PluginProcess/gtk/PluginProcessGtk.cpp \
        Source/WebKit2/Shared/APIClient.h \
+       Source/WebKit2/Shared/API/c/cairo/WKImageCairo.cpp \
+       Source/WebKit2/Shared/API/c/cairo/WKImageCairo.h \
        Source/WebKit2/Shared/API/c/gtk/WKBaseGtk.h \
        Source/WebKit2/Shared/API/c/gtk/WKGraphicsContextGtk.h \
        Source/WebKit2/Shared/API/c/gtk/WKGraphicsContextGtk.cpp \
@@ -189,8 +191,8 @@ libwebkit2gtk_@WEBKITGTK_API_MAJOR_VERSION@_@WEBKITGTK_API_MINOR_VERSION@_la_SOU
        Source/WebKit2/Shared/DrawingAreaInfo.h \
        Source/WebKit2/Shared/EditorState.h \
        Source/WebKit2/Shared/FontSmoothingLevel.h \
-       Source/WebKit2/Shared/cairo/ShareableBitmapCairo.cpp \
        Source/WebKit2/Shared/cairo/LayerTreeContextCairo.cpp \
+       Source/WebKit2/Shared/cairo/ShareableBitmapCairo.cpp \
        Source/WebKit2/Shared/gtk/NativeWebKeyboardEventGtk.cpp \
        Source/WebKit2/Shared/gtk/NativeWebMouseEventGtk.cpp \
        Source/WebKit2/Shared/gtk/NativeWebWheelEventGtk.cpp \
diff --git a/Source/WebKit2/Shared/API/c/cairo/WKImageCairo.cpp b/Source/WebKit2/Shared/API/c/cairo/WKImageCairo.cpp
new file mode 100644 (file)
index 0000000..703d869
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2011 Igalia S.L.
+ *
+ * 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. AND ITS CONTRIBUTORS ``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 ITS 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 "WKImageCairo.h"
+
+#include "ShareableBitmap.h"
+#include "WKSharedAPICast.h"
+#include "WebImage.h"
+#include <WebCore/GraphicsContext.h>
+#include <WebCore/PlatformContextCairo.h>
+
+using namespace WebKit;
+using namespace WebCore;
+
+cairo_surface_t* WKImageCreateCairoSurface(WKImageRef imageRef)
+{
+    // We cannot pass a RefPtr through the API here, so we just leak the reference.
+    return toImpl(imageRef)->bitmap()->createCairoSurface().leakRef();
+}
+
+WKImageRef WKImageCreateFromCairoSurface(cairo_surface_t* surface, WKImageOptions options)
+{
+    IntSize imageSize(cairo_image_surface_get_width(surface), cairo_image_surface_get_height(surface));
+    RefPtr<WebImage> webImage = WebImage::create(imageSize, toImageOptions(options));
+    OwnPtr<GraphicsContext> graphicsContext = webImage->bitmap()->createGraphicsContext();
+
+    cairo_t* cr = graphicsContext->platformContext()->cr();
+    cairo_set_source_surface(cr, surface, 0, 0);
+    cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
+    cairo_rectangle(cr, 0, 0, imageSize.width(), imageSize.height());
+    cairo_fill(cr);
+
+    return toAPI(webImage.release().leakRef());
+}
@@ -1,5 +1,6 @@
 /*
- * Copyright (C) 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2011 Igalia S.L.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include "config.h"
-#include "TestInvocation.h"
+#ifndef WKImageCairo_h
+#define WKImageCairo_h
 
-namespace WTR {
+#include <WebKit2/WKBase.h>
+#include <WebKit2/WKImage.h>
 
-void TestInvocation::dumpPixelsAndCompareWithExpected(WKImageRef image)
-{
+typedef _cairo_surface cairo_surface_t;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+WK_EXPORT cairo_surface_t* WKImageCreateCairoSurface(WKImageRef image);
+
+WK_EXPORT WKImageRef WKImageCreateFromCairoSurface(cairo_surface_t* surface, WKImageOptions options);
+
+#ifdef __cplusplus
 }
+#endif
 
-} // namespace WTR
+#endif /* WKImageCairo_h */
index e9c7840..c576209 100644 (file)
@@ -1,3 +1,22 @@
+2011-06-22  Martin Robinson  <mrobinson@igalia.com>
+
+        Reviewed by Adam Roben.
+
+        [GTK] Implement pixel dump support for WebKitTestRunner
+        https://bugs.webkit.org/show_bug.cgi?id=58242
+
+        * DumpRenderTree/gtk/GNUmakefile.ImageDiff.am: Added.
+        * GNUmakefile.am: Separate out the ImageDiff bits of the GNUmakefile.
+        * Scripts/old-run-webkit-tests: Update to add support for the GTK+ port.
+        * WebKitTestRunner/GNUmakefile.am: Added Cairo specific files to the build.
+        * WebKitTestRunner/TestInvocation.cpp: Moved this code to the platform-independent
+        file so that we can share it across platforms.
+        (WTR::TestInvocation::compareActualHashToExpectedAndDumpResults):
+        * WebKitTestRunner/TestInvocation.h: Updated method list.
+        * WebKitTestRunner/cairo/TestInvocationCairo.cpp: Added Cairo implementation.
+        * WebKitTestRunner/cg/TestInvocationCG.cpp:
+        (WTR::TestInvocation::dumpPixelsAndCompareWithExpected): Updated to use new helper.
+
 2011-06-22  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r89414.
diff --git a/Tools/DumpRenderTree/gtk/GNUmakefile.ImageDiff.am b/Tools/DumpRenderTree/gtk/GNUmakefile.ImageDiff.am
new file mode 100644 (file)
index 0000000..e7c3aef
--- /dev/null
@@ -0,0 +1,28 @@
+noinst_PROGRAMS += \
+       Programs/ImageDiff
+
+Programs_ImageDiff_CPPFLAGS = $(global_cppflags)
+
+Programs_ImageDiff_SOURCES = \
+   Tools/DumpRenderTree/gtk/ImageDiff.cpp
+
+Programs_ImageDiff_CXXFLAGS = \
+   $(global_cxxflags) \
+   $(global_cppflags) \
+   $(Programs_ImageDiff_CFLAGS)
+
+Programs_ImageDiff_CFLAGS = \
+   -fno-strict-aliasing \
+   $(global_cflags) \
+   $(GLOBALDEPS_CFLAGS) \
+   $(GTK_CFLAGS)
+
+Programs_ImageDiff_LDADD = \
+   $(GTK_LIBS)
+
+Programs_ImageDiff_LDFLAGS = \
+   -no-fast-install \
+   -no-install
+
+CLEANFILES += \
+       Programs/ImageDiff
index b303d06..c68b6ee 100644 (file)
@@ -1,7 +1,6 @@
 noinst_PROGRAMS += \
        Programs/DumpRenderTree \
-       Programs/GtkLauncher \
-       Programs/ImageDiff
+       Programs/GtkLauncher
 
 if ENABLE_WEBKIT2
 noinst_PROGRAMS += \
@@ -205,35 +204,10 @@ Programs_DumpRenderTree_LDFLAGS = \
        -no-fast-install \
        -no-install
 
-# ImageDiff
-Programs_ImageDiff_CPPFLAGS = $(global_cppflags)
-
-Programs_ImageDiff_SOURCES = \
-   Tools/DumpRenderTree/gtk/ImageDiff.cpp
-
-Programs_ImageDiff_CXXFLAGS = \
-   $(global_cxxflags) \
-   $(global_cppflags) \
-   $(Programs_ImageDiff_CFLAGS)
-
-Programs_ImageDiff_CFLAGS = \
-   -fno-strict-aliasing \
-   $(global_cflags) \
-   $(GLOBALDEPS_CFLAGS) \
-   $(GTK_CFLAGS)
-
-Programs_ImageDiff_LDADD = \
-   $(GTK_LIBS)
-
-Programs_ImageDiff_LDFLAGS = \
-   -no-fast-install \
-   -no-install
-
 # clean target
 CLEANFILES += \
        Programs/DumpRenderTree \
-       Programs/GtkLauncher \
-       Programs/ImageDiff
+       Programs/GtkLauncher
 
 if ENABLE_WEBKIT2
 CLEANFILES += \
index 23ac85d..228a159 100644 (file)
@@ -12,7 +12,7 @@ Programs_WebKitTestRunner_SOURCES = \
        Tools/WebKitTestRunner/gtk/main.cpp \
        Tools/WebKitTestRunner/gtk/PlatformWebViewGtk.cpp \
        Tools/WebKitTestRunner/gtk/TestControllerGtk.cpp \
-       Tools/WebKitTestRunner/gtk/TestInvocationGtk.cpp \
+       Tools/WebKitTestRunner/cairo/TestInvocationCairo.cpp \
        Tools/WebKitTestRunner/PlatformWebView.h \
        Tools/WebKitTestRunner/StringFunctions.h \
        Tools/WebKitTestRunner/TestController.cpp \
index c271967..ec9ab95 100644 (file)
@@ -174,6 +174,21 @@ void TestInvocation::dump(const char* stringToDump, bool singleEOF)
     fflush(stderr);
 }
 
+bool TestInvocation::compareActualHashToExpectedAndDumpResults(const char actualHash[33])
+{
+    // Compute the hash of the bitmap context pixels
+    fprintf(stdout, "\nActualHash: %s\n", actualHash);
+
+    if (!m_expectedPixelHash.length())
+        return false;
+
+    ASSERT(m_expectedPixelHash.length() == 32);
+    fprintf(stdout, "\nExpectedHash: %s\n", m_expectedPixelHash.c_str());
+
+    // FIXME: Do case insensitive compare.
+    return m_expectedPixelHash == actualHash;
+}
+
 void TestInvocation::didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody)
 {
     if (WKStringIsEqualToUTF8CString(messageName, "Error")) {
index 9faf1cc..aab58a2 100644 (file)
@@ -47,6 +47,7 @@ public:
 private:
     void dump(const char*, bool singleEOF = false);
     void dumpPixelsAndCompareWithExpected(WKImageRef);
+    bool compareActualHashToExpectedAndDumpResults(const char[33]);
     
     WKRetainPtr<WKURLRef> m_url;
     std::string m_pathOrURL;
index 88aacbd..04f60f7 100644 (file)
@@ -1,6 +1,7 @@
 /*
- * Copyright (C) 2011 Apple Inc. All rights reserved.
- * Copyright (C) 2011 Brent Fulgham <bfulgham@webkit.org>. All rights reserved.
+ * Copyright (C) 2009 Apple Inc. All rights reserved.
+ *           (C) 2011 Brent Fulgham <bfulgham@webkit.org>. All rights reserved.
+ *           (C) 2010, 2011 Igalia S.L
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #include "config.h"
 #include "TestInvocation.h"
 
+#include <WebKit2/WKImageCairo.h>
+#include <cairo/cairo.h>
+#include <cstdio>
+#include <wtf/Assertions.h>
+#include <wtf/MD5.h>
+
 namespace WTR {
 
-void TestInvocation::dumpPixelsAndCompareWithExpected(WKImageRef image)
+void computeMD5HashStringForCairoSurface(cairo_surface_t* surface, char hashString[33])
 {
-    // FIXME: This stub should be replaced with a Cairo implementation
-    // of the pixel dumping and comparison routines.
+    ASSERT(cairo_image_surface_get_format(surface) == CAIRO_FORMAT_ARGB32); // ImageDiff assumes 32 bit RGBA, we must as well.
+
+    size_t pixelsHigh = cairo_image_surface_get_height(surface);
+    size_t pixelsWide = cairo_image_surface_get_width(surface);
+    size_t bytesPerRow = cairo_image_surface_get_stride(surface);
+
+    MD5 md5Context;
+    unsigned char* bitmapData = static_cast<unsigned char*>(cairo_image_surface_get_data(surface));
+    for (size_t row = 0; row < pixelsHigh; ++row) {
+        md5Context.addBytes(bitmapData, 4 * pixelsWide);
+        bitmapData += bytesPerRow;
+    }
+    Vector<uint8_t, 16> hash;
+    md5Context.checksum(hash);
+
+    snprintf(hashString, 33, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
+        hash[0], hash[1], hash[2], hash[3], hash[4], hash[5], hash[6], hash[7],
+        hash[8], hash[9], hash[10], hash[11], hash[12], hash[13], hash[14], hash[15]);
+}
+
+static cairo_status_t writeFunction(void* closure, const unsigned char* data, unsigned int length)
+{
+    Vector<unsigned char>* in = reinterpret_cast<Vector<unsigned char>*>(closure);
+    in->append(data, length);
+    return CAIRO_STATUS_SUCCESS;
+}
+
+static void dumpBitmap(cairo_surface_t* surface)
+{
+    Vector<unsigned char> pixelData;
+    cairo_surface_write_to_png_stream(surface, writeFunction, &pixelData);
+    const size_t dataLength = pixelData.size();
+    const unsigned char* data = pixelData.data();
+
+    printf("Content-Type: %s\n", "image/png");
+    printf("Content-Length: %lu\n", static_cast<unsigned long>(dataLength));
+
+    const size_t bytesToWriteInOneChunk = 1 << 15;
+    size_t dataRemainingToWrite = dataLength;
+    while (dataRemainingToWrite) {
+        size_t bytesToWriteInThisChunk = std::min(dataRemainingToWrite, bytesToWriteInOneChunk);
+        size_t bytesWritten = fwrite(data, 1, bytesToWriteInThisChunk, stdout);
+        if (bytesWritten != bytesToWriteInThisChunk)
+            break;
+        dataRemainingToWrite -= bytesWritten;
+        data += bytesWritten;
+    }
+}
+
+void TestInvocation::dumpPixelsAndCompareWithExpected(WKImageRef wkImage)
+{
+    cairo_surface_t* surface = WKImageCreateCairoSurface(wkImage);
+
+    char actualHash[33];
+    computeMD5HashStringForCairoSurface(surface, actualHash);
+    if (!compareActualHashToExpectedAndDumpResults(actualHash))
+        dumpBitmap(surface);
+
+    cairo_surface_destroy(surface);
 }
 
 } // namespace WTR
index cba2908..33f2476 100644 (file)
@@ -130,24 +130,9 @@ void TestInvocation::dumpPixelsAndCompareWithExpected(WKImageRef image)
 {
     CGContextRef context = createCGContextFromImage(image);
 
-    // Compute the hash of the bitmap context pixels
     char actualHash[33];
     computeMD5HashStringForContext(context, actualHash);
-    fprintf(stdout, "\nActualHash: %s\n", actualHash);
-
-    // Check the computed hash against the expected one and dump image on mismatch
-    bool hashesMatch = false;
-    if (m_expectedPixelHash.length() > 0) {
-        ASSERT(m_expectedPixelHash.length() == 32);
-
-        fprintf(stdout, "\nExpectedHash: %s\n", m_expectedPixelHash.c_str());
-
-        // FIXME: Do case insensitive compare.
-        if (m_expectedPixelHash == actualHash)
-            hashesMatch = true;
-    }
-
-    if (!hashesMatch)
+    if (!compareActualHashToExpectedAndDumpResults(actualHash))
         dumpBitmap(context);
 }