Title: [131160] trunk
Revision
131160
Author
kbal...@webkit.org
Date
2012-10-12 01:44:24 -0700 (Fri, 12 Oct 2012)

Log Message

[Qt][WTR] Do a forced repaint before generating pixel results
https://bugs.webkit.org/show_bug.cgi?id=98654

Reviewed by Jocelyn Turcotte.

Source/WebKit2:

Added API to convert a QImage to a WKImage so we can
pass it to cross-platform code.

* Shared/API/c/qt/WKImageQt.cpp:
(WKImageCreateFromQImage):
* Shared/API/c/qt/WKImageQt.h:

Tools:

Do a forced repaint before grabbing the pixel snapshot. This extra
synchronisation is necessary with the CoordinatedGraphics rendering
backend because it has a fully asynchronous nature. This patch make
us using the window snapshot for pixel results which is necessary to
capture animations and other dynamic content. The actual grabbing of
the window has not been implemented in this patch. It will come in
a follow-up.

* WebKitTestRunner/TestInvocation.cpp:
(WTR::TestInvocation::invoke):
(WTR::TestInvocation::dump): Store results in member variables.
Don't close output channels yet.
(WTR::TestInvocation::dumpResults): Added. This is where we dump
the results if no error happened.
(WTR):
(WTR::TestInvocation::didReceiveMessageFromInjectedBundle):
* WebKitTestRunner/TestInvocation.h:
(TestInvocation):
* WebKitTestRunner/qt/PlatformWebViewQt.cpp:
(WTR::PlatformWebView::windowSnapshotImage):
* WebKitTestRunner/qt/TestInvocationQt.cpp:
(WTR::TestInvocation::forceRepaintDoneCallback):
(WTR):
(WTR::TestInvocation::dumpPixelsAndCompareWithExpected):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (131159 => 131160)


--- trunk/Source/WebKit2/ChangeLog	2012-10-12 08:39:25 UTC (rev 131159)
+++ trunk/Source/WebKit2/ChangeLog	2012-10-12 08:44:24 UTC (rev 131160)
@@ -1,3 +1,17 @@
+2012-10-12  Balazs Kelemen  <kbal...@webkit.org>
+
+        [Qt][WTR] Do a forced repaint before generating pixel results
+        https://bugs.webkit.org/show_bug.cgi?id=98654
+
+        Reviewed by Jocelyn Turcotte.
+
+        Added API to convert a QImage to a WKImage so we can
+        pass it to cross-platform code.
+
+        * Shared/API/c/qt/WKImageQt.cpp:
+        (WKImageCreateFromQImage):
+        * Shared/API/c/qt/WKImageQt.h:
+
 2012-10-12  Sheriff Bot  <webkit.review....@gmail.com>
 
         Unreviewed, rolling out r131121.

Modified: trunk/Source/WebKit2/Shared/API/c/qt/WKImageQt.cpp (131159 => 131160)


--- trunk/Source/WebKit2/Shared/API/c/qt/WKImageQt.cpp	2012-10-12 08:39:25 UTC (rev 131159)
+++ trunk/Source/WebKit2/Shared/API/c/qt/WKImageQt.cpp	2012-10-12 08:44:24 UTC (rev 131160)
@@ -25,10 +25,30 @@
 #include "ShareableBitmap.h"
 #include "WKSharedAPICast.h"
 #include "WebImage.h"
+#include <QPainter>
+#include <WebCore/GraphicsContext.h>
+#include <WebCore/IntSize.h>
 
+using namespace WebCore;
 using namespace WebKit;
 
 QImage WKImageCreateQImage(WKImageRef imageRef)
 {
     return toImpl(imageRef)->bitmap()->createQImage().copy();
 }
+
+WKImageRef WKImageCreateFromQImage(const QImage& image)
+{
+    if (image.isNull())
+        return 0;
+
+    ASSERT(image.bytesPerLine() == image.width() * 4);
+
+    RefPtr<WebImage> webImage = WebImage::create(image.size(), static_cast<ImageOptions>(0));
+    if (!webImage->bitmap())
+        return 0;
+    OwnPtr<GraphicsContext> graphicsContext = webImage->bitmap()->createGraphicsContext();
+    QPainter* painter = graphicsContext->platformContext();
+    painter->drawImage(QPoint(0, 0), image);
+    return toAPI(webImage.release().leakRef());
+}

Modified: trunk/Source/WebKit2/Shared/API/c/qt/WKImageQt.h (131159 => 131160)


--- trunk/Source/WebKit2/Shared/API/c/qt/WKImageQt.h	2012-10-12 08:39:25 UTC (rev 131159)
+++ trunk/Source/WebKit2/Shared/API/c/qt/WKImageQt.h	2012-10-12 08:44:24 UTC (rev 131160)
@@ -27,5 +27,6 @@
 #include <WebKit2/WKImage.h>
 
 WK_EXPORT QImage WKImageCreateQImage(WKImageRef image);
+WK_EXPORT WKImageRef WKImageCreateFromQImage(const QImage& image);
 
 #endif

Modified: trunk/Tools/ChangeLog (131159 => 131160)


--- trunk/Tools/ChangeLog	2012-10-12 08:39:25 UTC (rev 131159)
+++ trunk/Tools/ChangeLog	2012-10-12 08:44:24 UTC (rev 131160)
@@ -1,3 +1,35 @@
+2012-10-12  Balazs Kelemen  <kbal...@webkit.org>
+
+        [Qt][WTR] Do a forced repaint before generating pixel results
+        https://bugs.webkit.org/show_bug.cgi?id=98654
+
+        Reviewed by Jocelyn Turcotte.
+
+        Do a forced repaint before grabbing the pixel snapshot. This extra
+        synchronisation is necessary with the CoordinatedGraphics rendering
+        backend because it has a fully asynchronous nature. This patch make
+        us using the window snapshot for pixel results which is necessary to
+        capture animations and other dynamic content. The actual grabbing of
+        the window has not been implemented in this patch. It will come in
+        a follow-up.
+
+        * WebKitTestRunner/TestInvocation.cpp:
+        (WTR::TestInvocation::invoke):
+        (WTR::TestInvocation::dump): Store results in member variables.
+        Don't close output channels yet.
+        (WTR::TestInvocation::dumpResults): Added. This is where we dump
+        the results if no error happened.
+        (WTR):
+        (WTR::TestInvocation::didReceiveMessageFromInjectedBundle):
+        * WebKitTestRunner/TestInvocation.h:
+        (TestInvocation):
+        * WebKitTestRunner/qt/PlatformWebViewQt.cpp:
+        (WTR::PlatformWebView::windowSnapshotImage):
+        * WebKitTestRunner/qt/TestInvocationQt.cpp:
+        (WTR::TestInvocation::forceRepaintDoneCallback):
+        (WTR):
+        (WTR::TestInvocation::dumpPixelsAndCompareWithExpected):
+
 2012-10-12  Ilya Tikhonovsky  <loi...@chromium.org>
 
         Unreviewed compile error fix for chromium windows bot.

Modified: trunk/Tools/WebKitTestRunner/TestInvocation.cpp (131159 => 131160)


--- trunk/Tools/WebKitTestRunner/TestInvocation.cpp	2012-10-12 08:39:25 UTC (rev 131159)
+++ trunk/Tools/WebKitTestRunner/TestInvocation.cpp	2012-10-12 08:44:24 UTC (rev 131160)
@@ -192,6 +192,8 @@
         goto end;
     }
 
+    dumpResults();
+
 end:
 #if ENABLE(INSPECTOR)
     if (m_gotInitialResponse)
@@ -235,6 +237,17 @@
     fflush(stderr);
 }
 
+void TestInvocation::dumpResults()
+{
+    dump(toWTFString(m_textOutput.get()).utf8().data());
+
+    if (m_dumpPixels && m_pixelResult)
+        dumpPixelsAndCompareWithExpected(m_pixelResult.get(), m_repaintRects.get());
+
+    fputs("#EOF\n", stdout);
+    fflush(stdout);
+}
+
 bool TestInvocation::compareActualHashToExpectedAndDumpResults(const char actualHash[33])
 {
     // Compute the hash of the bitmap context pixels
@@ -278,26 +291,15 @@
         WKDictionaryRef messageBodyDictionary = static_cast<WKDictionaryRef>(messageBody);
 
         WKRetainPtr<WKStringRef> textOutputKey(AdoptWK, WKStringCreateWithUTF8CString("TextOutput"));
-        WKStringRef textOutput = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, textOutputKey.get()));
+        m_textOutput = static_cast<WKStringRef>(WKDictionaryGetItemForKey(messageBodyDictionary, textOutputKey.get()));
 
         WKRetainPtr<WKStringRef> pixelResultKey = adoptWK(WKStringCreateWithUTF8CString("PixelResult"));
-        WKImageRef pixelResult = static_cast<WKImageRef>(WKDictionaryGetItemForKey(messageBodyDictionary, pixelResultKey.get()));
-        ASSERT(!pixelResult || m_dumpPixels);
-        
+        m_pixelResult = static_cast<WKImageRef>(WKDictionaryGetItemForKey(messageBodyDictionary, pixelResultKey.get()));
+        ASSERT(!m_pixelResult || m_dumpPixels);
+
         WKRetainPtr<WKStringRef> repaintRectsKey = adoptWK(WKStringCreateWithUTF8CString("RepaintRects"));
-        WKArrayRef repaintRects = static_cast<WKArrayRef>(WKDictionaryGetItemForKey(messageBodyDictionary, repaintRectsKey.get()));        
+        m_repaintRects = static_cast<WKArrayRef>(WKDictionaryGetItemForKey(messageBodyDictionary, repaintRectsKey.get()));
 
-        // Dump text.
-        dump(toWTFString(textOutput).utf8().data());
-
-        // Dump pixels (if necessary).
-        if (m_dumpPixels && pixelResult)
-            dumpPixelsAndCompareWithExpected(pixelResult, repaintRects);
-
-        fputs("#EOF\n", stdout);
-        fflush(stdout);
-        fflush(stderr);
-        
         m_gotFinalMessage = true;
         TestController::shared().notifyDone();
         return;

Modified: trunk/Tools/WebKitTestRunner/TestInvocation.h (131159 => 131160)


--- trunk/Tools/WebKitTestRunner/TestInvocation.h	2012-10-12 08:39:25 UTC (rev 131159)
+++ trunk/Tools/WebKitTestRunner/TestInvocation.h	2012-10-12 08:44:24 UTC (rev 131160)
@@ -46,9 +46,15 @@
 
     static void dumpWebProcessUnresponsiveness(const char* textToStdout);
 private:
+    void dumpResults();
     static void dump(const char* textToStdout, const char* textToStderr = 0, bool seenError = false);
     void dumpPixelsAndCompareWithExpected(WKImageRef, WKArrayRef repaintRects);
     bool compareActualHashToExpectedAndDumpResults(const char[33]);
+
+#if PLATFORM(QT)
+    static void forceRepaintDoneCallback(WKErrorRef, void* context);
+    void forceRepaintDone();
+#endif
     
     WKRetainPtr<WKURLRef> m_url;
     std::string m_pathOrURL;
@@ -61,6 +67,10 @@
     bool m_gotFinalMessage;
     bool m_gotRepaint;
     bool m_error;
+
+    WKRetainPtr<WKStringRef> m_textOutput;
+    WKRetainPtr<WKImageRef> m_pixelResult;
+    WKRetainPtr<WKArrayRef> m_repaintRects;
 };
 
 } // namespace WTR

Modified: trunk/Tools/WebKitTestRunner/qt/PlatformWebViewQt.cpp (131159 => 131160)


--- trunk/Tools/WebKitTestRunner/qt/PlatformWebViewQt.cpp	2012-10-12 08:39:25 UTC (rev 131159)
+++ trunk/Tools/WebKitTestRunner/qt/PlatformWebViewQt.cpp	2012-10-12 08:44:24 UTC (rev 131160)
@@ -153,7 +153,7 @@
 {
     // FIXME: implement to capture pixels in the UI process,
     // which may be necessary to capture things like 3D transforms.
-    return 0;
+    return WKImageCreateFromQImage(QImage());
 }
 
 } // namespace WTR

Modified: trunk/Tools/WebKitTestRunner/qt/TestInvocationQt.cpp (131159 => 131160)


--- trunk/Tools/WebKitTestRunner/qt/TestInvocationQt.cpp	2012-10-12 08:39:25 UTC (rev 131159)
+++ trunk/Tools/WebKitTestRunner/qt/TestInvocationQt.cpp	2012-10-12 08:44:24 UTC (rev 131160)
@@ -27,6 +27,8 @@
 
 #include "TestInvocation.h"
 
+#include "PlatformWebView.h"
+#include "TestController.h"
 #include <QBuffer>
 #include <QCryptographicHash>
 #include <QtGui/QPainter>
@@ -63,10 +65,30 @@
     fflush(stdout);
 }
 
+void TestInvocation::forceRepaintDoneCallback(WKErrorRef, void *context)
+{
+    static_cast<TestInvocation*>(context)->m_gotRepaint = true;
+    TestController::shared().notifyDone();
+}
+
 void TestInvocation::dumpPixelsAndCompareWithExpected(WKImageRef imageRef, WKArrayRef repaintRects)
 {
-    QImage image = WKImageCreateQImage(imageRef);
+    WKPageRef page = TestController::shared().mainWebView()->page();
+    WKPageForceRepaint(page, this, &forceRepaintDoneCallback);
 
+    TestController::shared().runUntil(m_gotRepaint, TestController::ShortTimeout);
+
+    QImage image;
+    if (m_gotRepaint) {
+        WKRetainPtr<WKImageRef> windowSnapshot = TestController::shared().mainWebView()->windowSnapshotImage();
+        image = WKImageCreateQImage(windowSnapshot.get());
+    } else {
+        // The test harness expects an image so we output an empty one.
+        WKRect windowRect = TestController::shared().mainWebView()->windowFrame();
+        image = QImage(QSize(windowRect.size.width, windowRect.size.height), QImage::Format_ARGB32_Premultiplied);
+        image.fill(Qt::red);
+    }
+
     if (repaintRects) {
         QImage mask(image.size(), image.format());
         mask.fill(QColor(0, 0, 0, 0.66 * 255));
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to