[GTK] Should have the ability to output composited contents during layout testing
authormrobinson@webkit.org <mrobinson@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 22 Apr 2014 01:56:04 +0000 (01:56 +0000)
committermrobinson@webkit.org <mrobinson@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 22 Apr 2014 01:56:04 +0000 (01:56 +0000)
https://bugs.webkit.org/show_bug.cgi?id=131864

Reviewed by Philippe Normand.

* WebKitTestRunner/cairo/TestInvocationCairo.cpp:
(WTR::TestInvocation::dumpPixelsAndCompareWithExpected): Add a path that paints the widget contents
to an image surface. We run the main loop a bit to match the implementation from WebKit1 and EFL.
* WebKitTestRunner/gtk/PlatformWebViewGtk.cpp:
(WTR::PlatformWebView::windowSnapshotImage): Use the new UI-process path on GTK+.

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

Tools/ChangeLog
Tools/WebKitTestRunner/cairo/TestInvocationCairo.cpp
Tools/WebKitTestRunner/gtk/PlatformWebViewGtk.cpp

index 725a287..dce477c 100644 (file)
@@ -1,3 +1,16 @@
+2014-04-21  Martin Robinson  <mrobinson@igalia.com>
+
+        [GTK] Should have the ability to output composited contents during layout testing
+        https://bugs.webkit.org/show_bug.cgi?id=131864
+
+        Reviewed by Philippe Normand.
+
+        * WebKitTestRunner/cairo/TestInvocationCairo.cpp:
+        (WTR::TestInvocation::dumpPixelsAndCompareWithExpected): Add a path that paints the widget contents
+        to an image surface. We run the main loop a bit to match the implementation from WebKit1 and EFL.
+        * WebKitTestRunner/gtk/PlatformWebViewGtk.cpp:
+        (WTR::PlatformWebView::windowSnapshotImage): Use the new UI-process path on GTK+.
+
 2014-04-21  Sam Weinig  <sam@webkit.org>
 
         Attempt to fix the tests.
index 3abdfb6..5d9229d 100644 (file)
@@ -108,7 +108,7 @@ static void paintRepaintRectOverlay(cairo_surface_t* surface, WKArrayRef repaint
 
 void TestInvocation::dumpPixelsAndCompareWithExpected(WKImageRef wkImage, WKArrayRef repaintRects)
 {
-#if PLATFORM(EFL)
+#if PLATFORM(EFL) || PLATFORM(GTK)
     UNUSED_PARAM(wkImage);
     cairo_surface_t* surface = WKImageCreateCairoSurface(TestController::shared().mainWebView()->windowSnapshotImage().get());
 #else
index 9e7c876..3825deb 100644 (file)
@@ -28,6 +28,7 @@
 #include "config.h"
 #include "PlatformWebView.h"
 
+#include <WebKit2/WKImageCairo.h>
 #include <WebKit2/WKViewPrivate.h>
 #include <gtk/gtk.h>
 
@@ -120,9 +121,22 @@ void PlatformWebView::changeWindowScaleIfNeeded(float)
 
 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;
+    int width = gtk_widget_get_allocated_width(GTK_WIDGET(m_view));
+    int height = gtk_widget_get_allocated_height(GTK_WIDGET(m_view));
+
+    while (gtk_events_pending())
+        gtk_main_iteration();
+
+    cairo_surface_t* imageSurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
+
+    cairo_t* context = cairo_create(imageSurface);
+    gtk_widget_draw(GTK_WIDGET(m_view), context);
+    cairo_destroy(context);
+
+    WKRetainPtr<WKImageRef> wkImage = adoptWK(WKImageCreateFromCairoSurface(imageSurface, 0 /* options */));
+
+    cairo_surface_destroy(imageSurface);
+    return wkImage;
 }
 
 void PlatformWebView::didInitializeClients()