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
+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.
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
+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.
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 \
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 \
--- /dev/null
+/*
+ * 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());
+}
/*
- * 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 */
+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.
--- /dev/null
+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
noinst_PROGRAMS += \
Programs/DumpRenderTree \
- Programs/GtkLauncher \
- Programs/ImageDiff
+ Programs/GtkLauncher
if ENABLE_WEBKIT2
noinst_PROGRAMS += \
-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 += \
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 \
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")) {
private:
void dump(const char*, bool singleEOF = false);
void dumpPixelsAndCompareWithExpected(WKImageRef);
+ bool compareActualHashToExpectedAndDumpResults(const char[33]);
WKRetainPtr<WKURLRef> m_url;
std::string m_pathOrURL;
/*
- * 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
{
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);
}