- Revision
- 131306
- Author
- [email protected]
- Date
- 2012-10-15 09:15:44 -0700 (Mon, 15 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 (131305 => 131306)
--- trunk/Source/WebKit2/ChangeLog 2012-10-15 15:53:26 UTC (rev 131305)
+++ trunk/Source/WebKit2/ChangeLog 2012-10-15 16:15:44 UTC (rev 131306)
@@ -1,3 +1,17 @@
+2012-10-15 Balazs Kelemen <[email protected]>
+
+ [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-15 Simon Hausmann <[email protected]>
[Qt] Separate Qt WebKit into Qt WebKit and Qt WebKit Widgets
Modified: trunk/Source/WebKit2/Shared/API/c/qt/WKImageQt.cpp (131305 => 131306)
--- trunk/Source/WebKit2/Shared/API/c/qt/WKImageQt.cpp 2012-10-15 15:53:26 UTC (rev 131305)
+++ trunk/Source/WebKit2/Shared/API/c/qt/WKImageQt.cpp 2012-10-15 16:15:44 UTC (rev 131306)
@@ -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 (131305 => 131306)
--- trunk/Source/WebKit2/Shared/API/c/qt/WKImageQt.h 2012-10-15 15:53:26 UTC (rev 131305)
+++ trunk/Source/WebKit2/Shared/API/c/qt/WKImageQt.h 2012-10-15 16:15:44 UTC (rev 131306)
@@ -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 (131305 => 131306)
--- trunk/Tools/ChangeLog 2012-10-15 15:53:26 UTC (rev 131305)
+++ trunk/Tools/ChangeLog 2012-10-15 16:15:44 UTC (rev 131306)
@@ -1,3 +1,35 @@
+2012-10-15 Balazs Kelemen <[email protected]>
+
+ [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-15 Simon Hausmann <[email protected]>
[Qt] Separate Qt WebKit into Qt WebKit and Qt WebKit Widgets
Modified: trunk/Tools/WebKitTestRunner/TestInvocation.cpp (131305 => 131306)
--- trunk/Tools/WebKitTestRunner/TestInvocation.cpp 2012-10-15 15:53:26 UTC (rev 131305)
+++ trunk/Tools/WebKitTestRunner/TestInvocation.cpp 2012-10-15 16:15:44 UTC (rev 131306)
@@ -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 (131305 => 131306)
--- trunk/Tools/WebKitTestRunner/TestInvocation.h 2012-10-15 15:53:26 UTC (rev 131305)
+++ trunk/Tools/WebKitTestRunner/TestInvocation.h 2012-10-15 16:15:44 UTC (rev 131306)
@@ -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 (131305 => 131306)
--- trunk/Tools/WebKitTestRunner/qt/PlatformWebViewQt.cpp 2012-10-15 15:53:26 UTC (rev 131305)
+++ trunk/Tools/WebKitTestRunner/qt/PlatformWebViewQt.cpp 2012-10-15 16:15:44 UTC (rev 131306)
@@ -154,7 +154,7 @@
{
// FIXME: implement to capture pixels in the UI process,
// which may be necessary to capture things like 3D transforms.
- return 0;
+ return adoptWK(WKImageCreateFromQImage(QImage()));
}
} // namespace WTR
Modified: trunk/Tools/WebKitTestRunner/qt/TestInvocationQt.cpp (131305 => 131306)
--- trunk/Tools/WebKitTestRunner/qt/TestInvocationQt.cpp 2012-10-15 15:53:26 UTC (rev 131305)
+++ trunk/Tools/WebKitTestRunner/qt/TestInvocationQt.cpp 2012-10-15 16:15:44 UTC (rev 131306)
@@ -27,6 +27,8 @@
#include "TestInvocation.h"
+#include "PlatformWebView.h"
+#include "TestController.h"
#include <QBuffer>
#include <QCryptographicHash>
#include <QtGui/QPainter>
@@ -63,10 +65,29 @@
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)
+ image = WKImageCreateQImage(TestController::shared().mainWebView()->windowSnapshotImage().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));