Title: [97104] trunk/Tools
Revision
97104
Author
simon.fra...@apple.com
Date
2011-10-10 16:34:14 -0700 (Mon, 10 Oct 2011)

Log Message

3D transforms are flattened in WebKit2 snapshots
https://bugs.webkit.org/show_bug.cgi?id=68276

Reviewed by Anders Carlsson.

Use a snapshot of the window, rather than an image from the web process
for pixel testing in WebKitTestRunner. This correctly captures compositing
layers, so works for 3D transform tests.

* WebKitTestRunner/PlatformWebView.h: Add a windowSnapshotImage() method.
* WebKitTestRunner/cg/TestInvocationCG.cpp:
(WTR::createCGContextFromImage): Add a param to optionally flip the image when drawing.
(WTR::TestInvocation::dumpPixelsAndCompareWithExpected): Call windowSnapshotImage(), and if it returns an image,
use that instead of the image we get from the web process.
* WebKitTestRunner/gtk/PlatformWebViewGtk.cpp:
(WTR::PlatformWebView::windowSnapshotImage): Stub out the new method.
* WebKitTestRunner/mac/PlatformWebViewMac.mm:
(WTR::PlatformWebView::windowSnapshotImage): Ditto.
* WebKitTestRunner/qt/PlatformWebViewQt.cpp:
(WTR::PlatformWebView::windowSnapshotImage): Ditto.
* WebKitTestRunner/win/PlatformWebViewWin.cpp:
(WTR::PlatformWebView::windowSnapshotImage): Ditto.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (97103 => 97104)


--- trunk/Tools/ChangeLog	2011-10-10 23:32:15 UTC (rev 97103)
+++ trunk/Tools/ChangeLog	2011-10-10 23:34:14 UTC (rev 97104)
@@ -1,3 +1,28 @@
+2011-10-10  Simon Fraser  <simon.fra...@apple.com>
+
+        3D transforms are flattened in WebKit2 snapshots
+        https://bugs.webkit.org/show_bug.cgi?id=68276
+
+        Reviewed by Anders Carlsson.
+        
+        Use a snapshot of the window, rather than an image from the web process
+        for pixel testing in WebKitTestRunner. This correctly captures compositing
+        layers, so works for 3D transform tests.
+
+        * WebKitTestRunner/PlatformWebView.h: Add a windowSnapshotImage() method.
+        * WebKitTestRunner/cg/TestInvocationCG.cpp:
+        (WTR::createCGContextFromImage): Add a param to optionally flip the image when drawing.
+        (WTR::TestInvocation::dumpPixelsAndCompareWithExpected): Call windowSnapshotImage(), and if it returns an image,
+        use that instead of the image we get from the web process.
+        * WebKitTestRunner/gtk/PlatformWebViewGtk.cpp:
+        (WTR::PlatformWebView::windowSnapshotImage): Stub out the new method.
+        * WebKitTestRunner/mac/PlatformWebViewMac.mm:
+        (WTR::PlatformWebView::windowSnapshotImage): Ditto.
+        * WebKitTestRunner/qt/PlatformWebViewQt.cpp:
+        (WTR::PlatformWebView::windowSnapshotImage): Ditto.
+        * WebKitTestRunner/win/PlatformWebViewWin.cpp:
+        (WTR::PlatformWebView::windowSnapshotImage): Ditto.
+
 2011-10-10  David Levin  <le...@chromium.org>
 
         Quick fix for watchlist unit test failures when using Python 2.7+

Modified: trunk/Tools/WebKitTestRunner/PlatformWebView.h (97103 => 97104)


--- trunk/Tools/WebKitTestRunner/PlatformWebView.h	2011-10-10 23:32:15 UTC (rev 97103)
+++ trunk/Tools/WebKitTestRunner/PlatformWebView.h	2011-10-10 23:34:14 UTC (rev 97104)
@@ -26,6 +26,8 @@
 #ifndef PlatformWebView_h
 #define PlatformWebView_h
 
+#include <WebKit2/WKRetainPtr.h>
+
 #if defined(BUILDING_QT__)
 class QDesktopWebView;
 typedef QDesktopWebView* PlatformWKView;
@@ -76,6 +78,8 @@
     void makeWebViewFirstResponder();
     void setWindowIsKey(bool isKey) { m_windowIsKey = isKey; }
     bool windowIsKey() const { return m_windowIsKey; }
+    
+    WKRetainPtr<WKImageRef> windowSnapshotImage();
 
 private:
     PlatformWKView m_view;

Modified: trunk/Tools/WebKitTestRunner/cg/TestInvocationCG.cpp (97103 => 97104)


--- trunk/Tools/WebKitTestRunner/cg/TestInvocationCG.cpp	2011-10-10 23:32:15 UTC (rev 97103)
+++ trunk/Tools/WebKitTestRunner/cg/TestInvocationCG.cpp	2011-10-10 23:34:14 UTC (rev 97104)
@@ -45,7 +45,12 @@
 
 namespace WTR {
 
-static CGContextRef createCGContextFromImage(WKImageRef wkImage)
+enum FlipGraphicsContextOrNot {
+    DontFlipGraphicsContext,
+    FlipGraphicsContext
+};
+
+static CGContextRef createCGContextFromImage(WKImageRef wkImage, FlipGraphicsContextOrNot flip = DontFlipGraphicsContext)
 {
     RetainPtr<CGImageRef> image(AdoptCF, WKImageCreateCGImage(wkImage));
 
@@ -58,7 +63,15 @@
     CGContextRef context = CGBitmapContextCreate(buffer, pixelsWide, pixelsHigh, 8, rowBytes, colorSpace, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host);
     CGColorSpaceRelease(colorSpace);
     
+    if (flip == FlipGraphicsContext) {
+        CGContextSaveGState(context);
+        CGContextScaleCTM(context, 1, -1);
+        CGContextTranslateCTM(context, 0, -pixelsHigh);
+    }
+    
     CGContextDrawImage(context, CGRectMake(0, 0, pixelsWide, pixelsHigh), image.get());
+    if (flip == FlipGraphicsContext)
+        CGContextRestoreGState(context);
 
     return context;
 }
@@ -144,16 +157,23 @@
 
 void TestInvocation::dumpPixelsAndCompareWithExpected(WKImageRef image, WKArrayRef repaintRects)
 {
-    CGContextRef context = createCGContextFromImage(image);
+    PlatformWebView* webView = TestController::shared().mainWebView();
+    WKRetainPtr<WKImageRef> windowSnapshot = webView->windowSnapshotImage();
 
+    RetainPtr<CGContextRef> context;
+    if (windowSnapshot)
+        context.adoptCF(createCGContextFromImage(windowSnapshot.get(), FlipGraphicsContext));
+    else
+        context.adoptCF(createCGContextFromImage(image));
+
     // A non-null repaintRects array means we're doing a repaint test.
     if (repaintRects)
-        paintRepaintRectOverlay(context, image, repaintRects);
+        paintRepaintRectOverlay(context.get(), image, repaintRects);
 
     char actualHash[33];
-    computeMD5HashStringForContext(context, actualHash);
+    computeMD5HashStringForContext(context.get(), actualHash);
     if (!compareActualHashToExpectedAndDumpResults(actualHash))
-        dumpBitmap(context, actualHash);
+        dumpBitmap(context.get(), actualHash);
 }
 
 } // namespace WTR

Modified: trunk/Tools/WebKitTestRunner/gtk/PlatformWebViewGtk.cpp (97103 => 97104)


--- trunk/Tools/WebKitTestRunner/gtk/PlatformWebViewGtk.cpp	2011-10-10 23:32:15 UTC (rev 97103)
+++ trunk/Tools/WebKitTestRunner/gtk/PlatformWebViewGtk.cpp	2011-10-10 23:34:14 UTC (rev 97104)
@@ -110,5 +110,12 @@
 {
 }
 
+WKRetainPtr<WKImageRef> PlatformWebView::windowSnapshotImage()
+{
+    // FIXME: implement to capture pixels in the UI process,
+    // which may be necessary to capture things like 3D transforms.
+    return 0;
+}
+
 } // namespace WTR
 

Modified: trunk/Tools/WebKitTestRunner/mac/PlatformWebViewMac.mm (97103 => 97104)


--- trunk/Tools/WebKitTestRunner/mac/PlatformWebViewMac.mm	2011-10-10 23:32:15 UTC (rev 97103)
+++ trunk/Tools/WebKitTestRunner/mac/PlatformWebViewMac.mm	2011-10-10 23:34:14 UTC (rev 97104)
@@ -23,8 +23,12 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include "config.h"
 #include "PlatformWebView.h"
 
+#import <WebKit2/WKImageCG.h>
+#import <wtf/RetainPtr.h>
+
 @interface WebKitTestRunnerWindow : NSWindow {
     WTR::PlatformWebView* _platformWebView;
 }
@@ -124,4 +128,11 @@
     [m_window makeFirstResponder:m_view];
 }
 
+WKRetainPtr<WKImageRef> PlatformWebView::windowSnapshotImage()
+{
+    [m_view display];
+    RetainPtr<CGImageRef> windowSnapshotImage(AdoptCF, CGWindowListCreateImage(CGRectNull, kCGWindowListOptionIncludingWindow, [m_window windowNumber], kCGWindowImageBoundsIgnoreFraming | kCGWindowImageShouldBeOpaque));
+    return WKImageCreateFromCGImage(windowSnapshotImage.get(), 0);
+}
+
 } // namespace WTR

Modified: trunk/Tools/WebKitTestRunner/qt/PlatformWebViewQt.cpp (97103 => 97104)


--- trunk/Tools/WebKitTestRunner/qt/PlatformWebViewQt.cpp	2011-10-10 23:32:15 UTC (rev 97103)
+++ trunk/Tools/WebKitTestRunner/qt/PlatformWebViewQt.cpp	2011-10-10 23:34:14 UTC (rev 97104)
@@ -131,6 +131,13 @@
 {
 }
 
+WKRetainPtr<WKImageRef> PlatformWebView::windowSnapshotImage()
+{
+    // FIXME: implement to capture pixels in the UI process,
+    // which may be necessary to capture things like 3D transforms.
+    return 0;
+}
+
 } // namespace WTR
 
 #include "PlatformWebViewQt.moc"

Modified: trunk/Tools/WebKitTestRunner/win/PlatformWebViewWin.cpp (97103 => 97104)


--- trunk/Tools/WebKitTestRunner/win/PlatformWebViewWin.cpp	2011-10-10 23:32:15 UTC (rev 97103)
+++ trunk/Tools/WebKitTestRunner/win/PlatformWebViewWin.cpp	2011-10-10 23:34:14 UTC (rev 97104)
@@ -111,4 +111,11 @@
 {
 }
 
+WKRetainPtr<WKImageRef> PlatformWebView::windowSnapshotImage()
+{
+    // FIXME: implement to capture pixels in the UI process,
+    // which may be necessary to capture things like 3D transforms.
+    return 0;
+}
+
 } // namespace WTR
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to