Changeset 215176 in webkit


Ignore:
Timestamp:
Apr 10, 2017 3:16:26 AM (7 years ago)
Author:
commit-queue@webkit.org
Message:

WTR: Avoid conversion from platform image to WKImage and then to platform image again when dumping pixel results
https://bugs.webkit.org/show_bug.cgi?id=170653

Patch by Carlos Garcia Campos <cgarcia@igalia.com> on 2017-04-10
Reviewed by Tim Horton.

When dumping pixels from a web view snapshot, we create a platform image that is then converted to a WKImage,
which is a ShareableBitmap, so the image is rendered into a graphics context. Then we immediately extract the
platform image back from the WKImage to dump the pixels. We could avoid that conversion by taking the web
snapshot from TestInvocation::dumpPixelsAndCompareWithExpected().

  • WebKitTestRunner/PlatformWebView.h: Add PlatformImage typedef and use it as return value of windowSnapshotImage().
  • WebKitTestRunner/TestInvocation.cpp:

(WTR::TestInvocation::dumpResults): Pass the WKImage to dumpPixelsAndCompareWithExpected() only when pixel
results were created in the web process.

  • WebKitTestRunner/TestInvocation.h: Make WKImage a default paramater of dumpPixelsAndCompareWithExpected().
  • WebKitTestRunner/cairo/TestInvocationCairo.cpp:

(WTR::TestInvocation::dumpPixelsAndCompareWithExpected): Create the cairo surface from the given WKimage in case
of web contents snapshot, and use PlatformWebView::windowSnapshotImage() in case of web view snapshot.

  • WebKitTestRunner/cg/TestInvocationCG.cpp:

(WTR::createCGContextFromCGImage): Changed to receive a CGImageRef and renamed.
(WTR::createCGContextFromImage): Get the CGImageRef from the WKImage and call createCGContextFromCGImage().
(WTR::paintRepaintRectOverlay): It receives now the image size instead of the WKImage.
(WTR::TestInvocation::dumpPixelsAndCompareWithExpected): Create the CGContextRef from the WKImage in case of web
contents snpashot, and use PlatformWebView::windowSnapshotImage() in case of web view snapshot.

  • WebKitTestRunner/gtk/PlatformWebViewGtk.cpp:

(WTR::PlatformWebView::windowSnapshotImage): Return the cairo surface instead of creating a WKImage. Also use
RGB24 format to match what mac does (kCGWindowImageShouldBeOpaque).

  • WebKitTestRunner/ios/PlatformWebViewIOS.mm:

(WTR::PlatformWebView::windowSnapshotImage): Return the CGImageRef instead of creating a WKImage.

  • WebKitTestRunner/mac/PlatformWebViewMac.mm:

(WTR::PlatformWebView::windowSnapshotImage): Ditto.

Location:
trunk/Tools
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r215173 r215176  
     12017-04-10  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        WTR: Avoid conversion from platform image to WKImage and then to platform image again when dumping pixel results
     4        https://bugs.webkit.org/show_bug.cgi?id=170653
     5
     6        Reviewed by Tim Horton.
     7
     8        When dumping pixels from a web view snapshot, we create a platform image that is then converted to a WKImage,
     9        which is a ShareableBitmap, so the image is rendered into a graphics context. Then we immediately extract the
     10        platform image back from the WKImage to dump the pixels. We could avoid that conversion by taking the web
     11        snapshot from TestInvocation::dumpPixelsAndCompareWithExpected().
     12
     13        * WebKitTestRunner/PlatformWebView.h: Add PlatformImage typedef and use it as return value of windowSnapshotImage().
     14        * WebKitTestRunner/TestInvocation.cpp:
     15        (WTR::TestInvocation::dumpResults): Pass the WKImage to dumpPixelsAndCompareWithExpected() only when pixel
     16        results were created in the web process.
     17        * WebKitTestRunner/TestInvocation.h: Make WKImage a default paramater of dumpPixelsAndCompareWithExpected().
     18        * WebKitTestRunner/cairo/TestInvocationCairo.cpp:
     19        (WTR::TestInvocation::dumpPixelsAndCompareWithExpected): Create the cairo surface from the given WKimage in case
     20        of web contents snapshot, and use PlatformWebView::windowSnapshotImage() in case of web view snapshot.
     21        * WebKitTestRunner/cg/TestInvocationCG.cpp:
     22        (WTR::createCGContextFromCGImage): Changed to receive a CGImageRef and renamed.
     23        (WTR::createCGContextFromImage): Get the CGImageRef from the WKImage and call createCGContextFromCGImage().
     24        (WTR::paintRepaintRectOverlay): It receives now the image size instead of the WKImage.
     25        (WTR::TestInvocation::dumpPixelsAndCompareWithExpected): Create the CGContextRef from the WKImage in case of web
     26        contents snpashot, and use PlatformWebView::windowSnapshotImage() in case of web view snapshot.
     27        * WebKitTestRunner/gtk/PlatformWebViewGtk.cpp:
     28        (WTR::PlatformWebView::windowSnapshotImage): Return the cairo surface instead of creating a WKImage. Also use
     29        RGB24 format to match what mac does (kCGWindowImageShouldBeOpaque).
     30        * WebKitTestRunner/ios/PlatformWebViewIOS.mm:
     31        (WTR::PlatformWebView::windowSnapshotImage): Return the CGImageRef instead of creating a WKImage.
     32        * WebKitTestRunner/mac/PlatformWebViewMac.mm:
     33        (WTR::PlatformWebView::windowSnapshotImage): Ditto.
     34
    1352017-04-10  Chris Dumez  <cdumez@apple.com>
    236
  • trunk/Tools/WebKitTestRunner/PlatformWebView.h

    r211662 r215176  
    2828
    2929#include "TestOptions.h"
    30 #include <WebKit/WKRetainPtr.h>
    3130
    3231#if PLATFORM(COCOA) && !defined(BUILDING_GTK__)
    3332#include <WebKit/WKFoundation.h>
     33#include <wtf/RetainPtr.h>
    3434OBJC_CLASS NSView;
    3535OBJC_CLASS UIView;
     
    3737OBJC_CLASS WKWebViewConfiguration;
    3838OBJC_CLASS WebKitTestRunnerWindow;
     39typedef struct CGImage *CGImageRef;
    3940
    4041#if WK_API_ENABLED
     
    4445#endif
    4546typedef WebKitTestRunnerWindow *PlatformWindow;
     47typedef RetainPtr<CGImageRef> PlatformImage;
    4648#elif defined(BUILDING_GTK__)
    4749typedef struct _GtkWidget GtkWidget;
    4850typedef WKViewRef PlatformWKView;
    4951typedef GtkWidget* PlatformWindow;
     52typedef cairo_surface_t *PlatformImage;
    5053#elif PLATFORM(EFL)
    5154typedef Evas_Object* PlatformWKView;
     
    9396    bool viewSupportsOptions(const TestOptions&) const;
    9497
    95     WKRetainPtr<WKImageRef> windowSnapshotImage();
     98    PlatformImage windowSnapshotImage();
    9699    const TestOptions& options() const { return m_options; }
    97100
  • trunk/Tools/WebKitTestRunner/TestInvocation.cpp

    r214413 r215176  
    268268    if (m_dumpPixels) {
    269269        if (m_pixelResult)
    270             dumpPixelsAndCompareWithExpected(m_pixelResult.get(), m_repaintRects.get(), TestInvocation::SnapshotResultType::WebContents);
     270            dumpPixelsAndCompareWithExpected(SnapshotResultType::WebContents, m_repaintRects.get(), m_pixelResult.get());
    271271        else if (m_pixelResultIsPending) {
    272272            m_gotRepaint = false;
     
    279279            }
    280280
    281             WKRetainPtr<WKImageRef> windowSnapshot = TestController::singleton().mainWebView()->windowSnapshotImage();
    282             dumpPixelsAndCompareWithExpected(windowSnapshot.get(), m_repaintRects.get(), TestInvocation::SnapshotResultType::WebView);
     281            dumpPixelsAndCompareWithExpected(SnapshotResultType::WebView, m_repaintRects.get());
    283282        }
    284283    }
  • trunk/Tools/WebKitTestRunner/TestInvocation.h

    r209798 r215176  
    7676    static void dump(const char* textToStdout, const char* textToStderr = 0, bool seenError = false);
    7777    enum class SnapshotResultType { WebView, WebContents };
    78     void dumpPixelsAndCompareWithExpected(WKImageRef, WKArrayRef repaintRects, SnapshotResultType);
     78    void dumpPixelsAndCompareWithExpected(SnapshotResultType, WKArrayRef repaintRects, WKImageRef = nullptr);
    7979    void dumpAudio(WKDataRef);
    8080    bool compareActualHashToExpectedAndDumpResults(const char[33]);
  • trunk/Tools/WebKitTestRunner/cairo/TestInvocationCairo.cpp

    r190304 r215176  
    107107}
    108108
    109 void TestInvocation::dumpPixelsAndCompareWithExpected(WKImageRef image, WKArrayRef repaintRects, SnapshotResultType)
     109void TestInvocation::dumpPixelsAndCompareWithExpected(SnapshotResultType snapshotType, WKArrayRef repaintRects, WKImageRef image)
    110110{
    111     cairo_surface_t* surface = WKImageCreateCairoSurface(image);
     111    cairo_surface_t* surface = nullptr;
     112    switch (snapshotType) {
     113    case SnapshotResultType::WebContents:
     114        surface = WKImageCreateCairoSurface(image);
     115        break;
     116    case SnapshotResultType::WebView:
     117        surface = TestController::singleton().mainWebView()->windowSnapshotImage();
     118        break;
     119    }
    112120
    113121    if (repaintRects)
  • trunk/Tools/WebKitTestRunner/cg/TestInvocationCG.cpp

    r202532 r215176  
    4747namespace WTR {
    4848
    49 static CGContextRef createCGContextFromImage(WKImageRef wkImage)
     49static CGContextRef createCGContextFromCGImage(CGImageRef image)
    5050{
    51     RetainPtr<CGImageRef> image = adoptCF(WKImageCreateCGImage(wkImage));
    52 
    53     size_t pixelsWide = CGImageGetWidth(image.get());
    54     size_t pixelsHigh = CGImageGetHeight(image.get());
     51    size_t pixelsWide = CGImageGetWidth(image);
     52    size_t pixelsHigh = CGImageGetHeight(image);
    5553    size_t rowBytes = (4 * pixelsWide + 63) & ~63;
    5654
     
    6159        return nullptr;
    6260
    63     CGContextDrawImage(context, CGRectMake(0, 0, pixelsWide, pixelsHigh), image.get());
     61    CGContextDrawImage(context, CGRectMake(0, 0, pixelsWide, pixelsHigh), image);
    6462    return context;
     63}
     64
     65static CGContextRef createCGContextFromImage(WKImageRef wkImage)
     66{
     67    RetainPtr<CGImageRef> image = adoptCF(WKImageCreateCGImage(wkImage));
     68    return createCGContextFromCGImage(image.get());
    6569}
    6670
     
    119123}
    120124
    121 static void paintRepaintRectOverlay(CGContextRef context, WKImageRef image, WKArrayRef repaintRects)
     125static void paintRepaintRectOverlay(CGContextRef context, WKSize imageSize, WKArrayRef repaintRects)
    122126{
    123     WKSize imageSize = WKImageGetSize(image);
    124 
    125127    CGContextSaveGState(context);
    126128
     
    147149}
    148150
    149 void TestInvocation::dumpPixelsAndCompareWithExpected(WKImageRef image, WKArrayRef repaintRects, SnapshotResultType snapshotType)
     151void TestInvocation::dumpPixelsAndCompareWithExpected(SnapshotResultType snapshotType, WKArrayRef repaintRects, WKImageRef wkImage)
    150152{
    151     if (!image) {
    152         WTFLogAlways("dumpPixelsAndCompareWithExpected: image is null\n");
    153         return;
     153    RetainPtr<CGContextRef> context;
     154    WKSize imageSize;
     155
     156    switch (snapshotType) {
     157    case SnapshotResultType::WebContents:
     158        if (!wkImage) {
     159            WTFLogAlways("dumpPixelsAndCompareWithExpected: image is null\n");
     160            return;
     161        }
     162        context = adoptCF(createCGContextFromImage(wkImage));
     163        imageSize = WKImageGetSize(wkImage);
     164        break;
     165    case SnapshotResultType::WebView:
     166        auto image = TestController::singleton().mainWebView()->windowSnapshotImage();
     167        if (!image) {
     168            WTFLogAlways("dumpPixelsAndCompareWithExpected: image is null\n");
     169            return;
     170        }
     171        context = adoptCF(createCGContextFromCGImage(image.get()));
     172        imageSize = WKSizeMake(CGImageGetWidth(image.get()), CGImageGetHeight(image.get()));
     173        break;
    154174    }
    155175
    156     RetainPtr<CGContextRef> context = adoptCF(createCGContextFromImage(image));
    157176    if (!context) {
    158177        WTFLogAlways("dumpPixelsAndCompareWithExpected: context is null\n");
     
    162181    // A non-null repaintRects array means we're doing a repaint test.
    163182    if (repaintRects)
    164         paintRepaintRectOverlay(context.get(), image, repaintRects);
     183        paintRepaintRectOverlay(context.get(), imageSize, repaintRects);
    165184
    166185    char actualHash[33];
  • trunk/Tools/WebKitTestRunner/gtk/PlatformWebViewGtk.cpp

    r211662 r215176  
    133133}
    134134
    135 WKRetainPtr<WKImageRef> PlatformWebView::windowSnapshotImage()
     135cairo_surface_t* PlatformWebView::windowSnapshotImage()
    136136{
    137137    int width = gtk_widget_get_allocated_width(GTK_WIDGET(m_view));
     
    141141        gtk_main_iteration();
    142142
    143     cairo_surface_t* imageSurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
     143    cairo_surface_t* imageSurface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, width, height);
    144144
    145145    cairo_t* context = cairo_create(imageSurface);
     
    147147    cairo_destroy(context);
    148148
    149     WKRetainPtr<WKImageRef> wkImage = adoptWK(WKImageCreateFromCairoSurface(imageSurface, 0 /* options */));
    150 
    151     cairo_surface_destroy(imageSurface);
    152     return wkImage;
     149    return imageSurface;
    153150}
    154151
  • trunk/Tools/WebKitTestRunner/ios/PlatformWebViewIOS.mm

    r213694 r215176  
    251251}
    252252
    253 WKRetainPtr<WKImageRef> PlatformWebView::windowSnapshotImage()
     253#if !USE(IOSURFACE)
     254static void releaseDataProviderData(void* info, const void*, size_t)
     255{
     256    CARenderServerDestroyBuffer(static_cast<CARenderServerBufferRef>(info));
     257}
     258#endif
     259
     260RetainPtr<CGImageRef> PlatformWebView::windowSnapshotImage()
    254261{
    255262    BEGIN_BLOCK_OBJC_EXCEPTIONS;
     
    280287
    281288    static CGColorSpaceRef sRGBSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
    282     RetainPtr<CGDataProviderRef> provider = adoptCF(CGDataProviderCreateWithData(0, data, CARenderServerGetBufferDataSize(buffer), nullptr));
     289    RetainPtr<CGDataProviderRef> provider = adoptCF(CGDataProviderCreateWithData(0, data, CARenderServerGetBufferDataSize(buffer), releaseDataProviderData));
    283290   
    284291    RetainPtr<CGImageRef> cgImage = adoptCF(CGImageCreate(bufferWidth, bufferHeight, 8, 32, rowBytes, sRGBSpace, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, provider.get(), 0, false, kCGRenderingIntentDefault));
    285     WKRetainPtr<WKImageRef> result = adoptWK(WKImageCreateFromCGImage(cgImage.get(), 0));
    286 
    287     CARenderServerDestroyBuffer(buffer);
    288 
    289     return result;
     292
     293    return cgImage;
    290294#endif
    291295    END_BLOCK_OBJC_EXCEPTIONS;
  • trunk/Tools/WebKitTestRunner/mac/PlatformWebViewMac.mm

    r213694 r215176  
    272272}
    273273
    274 WKRetainPtr<WKImageRef> PlatformWebView::windowSnapshotImage()
     274RetainPtr<CGImageRef> PlatformWebView::windowSnapshotImage()
    275275{
    276276    [platformView() display];
     
    280280        options |= kCGWindowImageNominalResolution;
    281281
    282     RetainPtr<CGImageRef> windowSnapshotImage = adoptCF(CGWindowListCreateImage(CGRectNull, kCGWindowListOptionIncludingWindow, [m_window windowNumber], options));
    283 
    284     // windowSnapshotImage will be in GenericRGB, as we've set the main display's color space to GenericRGB.
    285     return adoptWK(WKImageCreateFromCGImage(windowSnapshotImage.get(), 0));
     282    return adoptCF(CGWindowListCreateImage(CGRectNull, kCGWindowListOptionIncludingWindow, [m_window windowNumber], options));
    286283}
    287284
Note: See TracChangeset for help on using the changeset viewer.