Changeset 215176 in webkit
- Timestamp:
- Apr 10, 2017 3:16:26 AM (7 years ago)
- Location:
- trunk/Tools
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r215173 r215176 1 2017-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 1 35 2017-04-10 Chris Dumez <cdumez@apple.com> 2 36 -
trunk/Tools/WebKitTestRunner/PlatformWebView.h
r211662 r215176 28 28 29 29 #include "TestOptions.h" 30 #include <WebKit/WKRetainPtr.h>31 30 32 31 #if PLATFORM(COCOA) && !defined(BUILDING_GTK__) 33 32 #include <WebKit/WKFoundation.h> 33 #include <wtf/RetainPtr.h> 34 34 OBJC_CLASS NSView; 35 35 OBJC_CLASS UIView; … … 37 37 OBJC_CLASS WKWebViewConfiguration; 38 38 OBJC_CLASS WebKitTestRunnerWindow; 39 typedef struct CGImage *CGImageRef; 39 40 40 41 #if WK_API_ENABLED … … 44 45 #endif 45 46 typedef WebKitTestRunnerWindow *PlatformWindow; 47 typedef RetainPtr<CGImageRef> PlatformImage; 46 48 #elif defined(BUILDING_GTK__) 47 49 typedef struct _GtkWidget GtkWidget; 48 50 typedef WKViewRef PlatformWKView; 49 51 typedef GtkWidget* PlatformWindow; 52 typedef cairo_surface_t *PlatformImage; 50 53 #elif PLATFORM(EFL) 51 54 typedef Evas_Object* PlatformWKView; … … 93 96 bool viewSupportsOptions(const TestOptions&) const; 94 97 95 WKRetainPtr<WKImageRef>windowSnapshotImage();98 PlatformImage windowSnapshotImage(); 96 99 const TestOptions& options() const { return m_options; } 97 100 -
trunk/Tools/WebKitTestRunner/TestInvocation.cpp
r214413 r215176 268 268 if (m_dumpPixels) { 269 269 if (m_pixelResult) 270 dumpPixelsAndCompareWithExpected( m_pixelResult.get(), m_repaintRects.get(), TestInvocation::SnapshotResultType::WebContents);270 dumpPixelsAndCompareWithExpected(SnapshotResultType::WebContents, m_repaintRects.get(), m_pixelResult.get()); 271 271 else if (m_pixelResultIsPending) { 272 272 m_gotRepaint = false; … … 279 279 } 280 280 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()); 283 282 } 284 283 } -
trunk/Tools/WebKitTestRunner/TestInvocation.h
r209798 r215176 76 76 static void dump(const char* textToStdout, const char* textToStderr = 0, bool seenError = false); 77 77 enum class SnapshotResultType { WebView, WebContents }; 78 void dumpPixelsAndCompareWithExpected( WKImageRef, WKArrayRef repaintRects, SnapshotResultType);78 void dumpPixelsAndCompareWithExpected(SnapshotResultType, WKArrayRef repaintRects, WKImageRef = nullptr); 79 79 void dumpAudio(WKDataRef); 80 80 bool compareActualHashToExpectedAndDumpResults(const char[33]); -
trunk/Tools/WebKitTestRunner/cairo/TestInvocationCairo.cpp
r190304 r215176 107 107 } 108 108 109 void TestInvocation::dumpPixelsAndCompareWithExpected( WKImageRef image, WKArrayRef repaintRects, SnapshotResultType)109 void TestInvocation::dumpPixelsAndCompareWithExpected(SnapshotResultType snapshotType, WKArrayRef repaintRects, WKImageRef image) 110 110 { 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 } 112 120 113 121 if (repaintRects) -
trunk/Tools/WebKitTestRunner/cg/TestInvocationCG.cpp
r202532 r215176 47 47 namespace WTR { 48 48 49 static CGContextRef createCGContextFrom Image(WKImageRef wkImage)49 static CGContextRef createCGContextFromCGImage(CGImageRef image) 50 50 { 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); 55 53 size_t rowBytes = (4 * pixelsWide + 63) & ~63; 56 54 … … 61 59 return nullptr; 62 60 63 CGContextDrawImage(context, CGRectMake(0, 0, pixelsWide, pixelsHigh), image .get());61 CGContextDrawImage(context, CGRectMake(0, 0, pixelsWide, pixelsHigh), image); 64 62 return context; 63 } 64 65 static CGContextRef createCGContextFromImage(WKImageRef wkImage) 66 { 67 RetainPtr<CGImageRef> image = adoptCF(WKImageCreateCGImage(wkImage)); 68 return createCGContextFromCGImage(image.get()); 65 69 } 66 70 … … 119 123 } 120 124 121 static void paintRepaintRectOverlay(CGContextRef context, WK ImageRef image, WKArrayRef repaintRects)125 static void paintRepaintRectOverlay(CGContextRef context, WKSize imageSize, WKArrayRef repaintRects) 122 126 { 123 WKSize imageSize = WKImageGetSize(image);124 125 127 CGContextSaveGState(context); 126 128 … … 147 149 } 148 150 149 void TestInvocation::dumpPixelsAndCompareWithExpected( WKImageRef image, WKArrayRef repaintRects, SnapshotResultType snapshotType)151 void TestInvocation::dumpPixelsAndCompareWithExpected(SnapshotResultType snapshotType, WKArrayRef repaintRects, WKImageRef wkImage) 150 152 { 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; 154 174 } 155 175 156 RetainPtr<CGContextRef> context = adoptCF(createCGContextFromImage(image));157 176 if (!context) { 158 177 WTFLogAlways("dumpPixelsAndCompareWithExpected: context is null\n"); … … 162 181 // A non-null repaintRects array means we're doing a repaint test. 163 182 if (repaintRects) 164 paintRepaintRectOverlay(context.get(), image , repaintRects);183 paintRepaintRectOverlay(context.get(), imageSize, repaintRects); 165 184 166 185 char actualHash[33]; -
trunk/Tools/WebKitTestRunner/gtk/PlatformWebViewGtk.cpp
r211662 r215176 133 133 } 134 134 135 WKRetainPtr<WKImageRef>PlatformWebView::windowSnapshotImage()135 cairo_surface_t* PlatformWebView::windowSnapshotImage() 136 136 { 137 137 int width = gtk_widget_get_allocated_width(GTK_WIDGET(m_view)); … … 141 141 gtk_main_iteration(); 142 142 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); 144 144 145 145 cairo_t* context = cairo_create(imageSurface); … … 147 147 cairo_destroy(context); 148 148 149 WKRetainPtr<WKImageRef> wkImage = adoptWK(WKImageCreateFromCairoSurface(imageSurface, 0 /* options */)); 150 151 cairo_surface_destroy(imageSurface); 152 return wkImage; 149 return imageSurface; 153 150 } 154 151 -
trunk/Tools/WebKitTestRunner/ios/PlatformWebViewIOS.mm
r213694 r215176 251 251 } 252 252 253 WKRetainPtr<WKImageRef> PlatformWebView::windowSnapshotImage() 253 #if !USE(IOSURFACE) 254 static void releaseDataProviderData(void* info, const void*, size_t) 255 { 256 CARenderServerDestroyBuffer(static_cast<CARenderServerBufferRef>(info)); 257 } 258 #endif 259 260 RetainPtr<CGImageRef> PlatformWebView::windowSnapshotImage() 254 261 { 255 262 BEGIN_BLOCK_OBJC_EXCEPTIONS; … … 280 287 281 288 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)); 283 290 284 291 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; 290 294 #endif 291 295 END_BLOCK_OBJC_EXCEPTIONS; -
trunk/Tools/WebKitTestRunner/mac/PlatformWebViewMac.mm
r213694 r215176 272 272 } 273 273 274 WKRetainPtr<WKImageRef> PlatformWebView::windowSnapshotImage()274 RetainPtr<CGImageRef> PlatformWebView::windowSnapshotImage() 275 275 { 276 276 [platformView() display]; … … 280 280 options |= kCGWindowImageNominalResolution; 281 281 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)); 286 283 } 287 284
Note: See TracChangeset
for help on using the changeset viewer.