Title: [216462] trunk
Revision
216462
Author
jbed...@apple.com
Date
2017-05-08 16:15:00 -0700 (Mon, 08 May 2017)

Log Message

Implement PlatformWebView::windowSnapshotImage and createBitmapContextFromWebView for iOS devices
https://bugs.webkit.org/show_bug.cgi?id=169421
<rdar://problem/30950171>

Reviewed by Tim Horton.

Tools:

* DumpRenderTree/ios/PixelDumpSupportIOS.mm:
(createBitmapContextFromWebView): Implement for IOSurface.
* WebKitTestRunner/ios/PlatformWebViewIOS.mm:
(WTR::PlatformWebView::windowSnapshotImage): Use snapshot API for device.

LayoutTests:

* platform/ios-device/TestExpectations: Mark compositing tests as failures, this
is due to a bug tracked in https://bugs.webkit.org/show_bug.cgi?id=170772.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (216461 => 216462)


--- trunk/LayoutTests/ChangeLog	2017-05-08 23:12:29 UTC (rev 216461)
+++ trunk/LayoutTests/ChangeLog	2017-05-08 23:15:00 UTC (rev 216462)
@@ -1,3 +1,14 @@
+2017-05-08  Jonathan Bedard  <jbed...@apple.com>
+
+        Implement PlatformWebView::windowSnapshotImage and createBitmapContextFromWebView for iOS devices
+        https://bugs.webkit.org/show_bug.cgi?id=169421
+        <rdar://problem/30950171>
+
+        Reviewed by Tim Horton.
+
+        * platform/ios-device/TestExpectations: Mark compositing tests as failures, this
+        is due to a bug tracked in https://bugs.webkit.org/show_bug.cgi?id=170772.
+
 2017-05-08  Chris Dumez  <cdu...@apple.com>
 
         Drop non-standard document.implementation.createCSSStyleSheet() API

Modified: trunk/LayoutTests/platform/ios-device/TestExpectations (216461 => 216462)


--- trunk/LayoutTests/platform/ios-device/TestExpectations	2017-05-08 23:12:29 UTC (rev 216461)
+++ trunk/LayoutTests/platform/ios-device/TestExpectations	2017-05-08 23:15:00 UTC (rev 216462)
@@ -3,3 +3,10 @@
 # See http://trac.webkit.org/wiki/TestExpectations for more information on this file.
 #
 
+# https://bugs.webkit.org/show_bug.cgi?id=170772
+compositing/geometry/clipped-out-perspective.html [ ImageOnlyFailure ]
+compositing/hidpi-subpixel-transform-origin.html [ ImageOnlyFailure ]
+compositing/regions/position-layer-inside-region-overflow-hidden.html [ ImageOnlyFailure ]
+compositing/regions/position-layers-inside-region-overflow-hidden.html [ ImageOnlyFailure ]
+compositing/regions/position-layers-inside-regions-overflow-hidden.html [ ImageOnlyFailure ]
+

Modified: trunk/Tools/ChangeLog (216461 => 216462)


--- trunk/Tools/ChangeLog	2017-05-08 23:12:29 UTC (rev 216461)
+++ trunk/Tools/ChangeLog	2017-05-08 23:15:00 UTC (rev 216462)
@@ -1,5 +1,18 @@
 2017-05-08  Jonathan Bedard  <jbed...@apple.com>
 
+        Implement PlatformWebView::windowSnapshotImage and createBitmapContextFromWebView for iOS devices
+        https://bugs.webkit.org/show_bug.cgi?id=169421
+        <rdar://problem/30950171>
+
+        Reviewed by Tim Horton.
+
+        * DumpRenderTree/ios/PixelDumpSupportIOS.mm:
+        (createBitmapContextFromWebView): Implement for IOSurface.
+        * WebKitTestRunner/ios/PlatformWebViewIOS.mm:
+        (WTR::PlatformWebView::windowSnapshotImage): Use snapshot API for device.
+
+2017-05-08  Jonathan Bedard  <jbed...@apple.com>
+
         buildbot: Cleanup simulators after running tests
         https://bugs.webkit.org/show_bug.cgi?id=171679
 

Modified: trunk/Tools/DumpRenderTree/ios/PixelDumpSupportIOS.mm (216461 => 216462)


--- trunk/Tools/DumpRenderTree/ios/PixelDumpSupportIOS.mm	2017-05-08 23:12:29 UTC (rev 216461)
+++ trunk/Tools/DumpRenderTree/ios/PixelDumpSupportIOS.mm	2017-05-08 23:15:00 UTC (rev 216462)
@@ -38,6 +38,10 @@
 #import <CommonCrypto/CommonDigest.h>
 #import <MobileCoreServices/UTCoreTypes.h>
 #import <QuartzCore/QuartzCore.h>
+#import <WebCore/CoreGraphicsSPI.h>
+#import <WebCore/GraphicsContextCG.h>
+#import <WebCore/IOSurface.h>
+#import <WebCore/PlatformScreen.h>
 #import <WebCore/QuartzCoreSPI.h>
 #import <WebKit/WebCoreThread.h>
 #import <wtf/BlockObjCExceptions.h>
@@ -56,16 +60,32 @@
     WebThreadLock();
     [CATransaction flush];
 
-#if USE(IOSURFACE)
-    return nullptr;
-#else
     CGFloat deviceScaleFactor = 2; // FIXME: hardcode 2x for now. In future we could respect 1x and 3x as we do on Mac.
-    CATransform3D transform = CATransform3DMakeScale(deviceScaleFactor, deviceScaleFactor, 1);
     
     CGSize viewSize = [[mainFrame webView] frame].size;
     int bufferWidth = ceil(viewSize.width * deviceScaleFactor);
     int bufferHeight = ceil(viewSize.height * deviceScaleFactor);
 
+#if USE(IOSURFACE)
+    WebCore::FloatSize snapshotSize(viewSize);
+    snapshotSize.scale(deviceScaleFactor);
+
+    WebCore::IOSurface::Format snapshotFormat = WebCore::screenSupportsExtendedColor() ? WebCore::IOSurface::Format::RGB10 : WebCore::IOSurface::Format::RGBA;
+    auto surface = WebCore::IOSurface::create(WebCore::expandedIntSize(snapshotSize), WebCore::sRGBColorSpaceRef(), snapshotFormat);
+    RetainPtr<CGImageRef> cgImage = surface->createImage();
+
+    void* bitmapBuffer = nullptr;
+    size_t bitmapRowBytes = 0;
+    auto bitmapContext = createBitmapContext(bufferWidth, bufferHeight, bitmapRowBytes, bitmapBuffer);
+    if (!bitmapContext)
+        return nullptr;
+
+    CGContextDrawImage(bitmapContext->cgContext(), CGRectMake(0, 0, bufferWidth, bufferHeight), cgImage.get());
+    return bitmapContext;
+#else
+    CATransform3D transform = CATransform3DMakeScale(deviceScaleFactor, deviceScaleFactor, 1);
+    static CGColorSpaceRef sRGBSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
+
     CARenderServerBufferRef buffer = CARenderServerCreateBuffer(bufferWidth, bufferHeight);
     if (!buffer) {
         WTFLogAlways("CARenderServerCreateBuffer failed for buffer with width %d height %d\n", bufferWidth, bufferHeight);
@@ -77,7 +97,6 @@
     uint8_t* data = ""
     size_t rowBytes = CARenderServerGetBufferRowBytes(buffer);
 
-    static CGColorSpaceRef sRGBSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
     RetainPtr<CGDataProviderRef> provider = adoptCF(CGDataProviderCreateWithData(0, data, CARenderServerGetBufferDataSize(buffer), nullptr));
     
     RetainPtr<CGImageRef> cgImage = adoptCF(CGImageCreate(bufferWidth, bufferHeight, 8, 32, rowBytes, sRGBSpace, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, provider.get(), 0, false, kCGRenderingIntentDefault));

Modified: trunk/Tools/WebKitTestRunner/ios/PlatformWebViewIOS.mm (216461 => 216462)


--- trunk/Tools/WebKitTestRunner/ios/PlatformWebViewIOS.mm	2017-05-08 23:12:29 UTC (rev 216461)
+++ trunk/Tools/WebKitTestRunner/ios/PlatformWebViewIOS.mm	2017-05-08 23:15:00 UTC (rev 216462)
@@ -32,6 +32,7 @@
 #import <WebCore/QuartzCoreSPI.h>
 #import <WebKit/WKImageCG.h>
 #import <WebKit/WKPreferencesPrivate.h>
+#import <WebKit/WKSnapshotConfiguration.h>
 #import <WebKit/WKWebViewConfiguration.h>
 #import <WebKit/WKWebViewPrivate.h>
 #import <wtf/BlockObjCExceptions.h>
@@ -304,7 +305,22 @@
 {
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
 #if USE(IOSURFACE)
-    return nullptr;
+    __block bool isDone = false;
+    __block RetainPtr<CGImageRef> result;
+    
+    RetainPtr<WKSnapshotConfiguration> snapshotConfiguration = adoptNS([[WKSnapshotConfiguration alloc] init]);
+    [snapshotConfiguration setRect:CGRectMake(0, 0, m_view.frame.size.width, m_view.frame.size.height)];
+    [snapshotConfiguration setSnapshotWidth:@(m_view.frame.size.width)];
+    
+    [m_view takeSnapshotWithConfiguration:snapshotConfiguration.get() completionHandler:^(UIImage *snapshotImage, NSError *error) {
+        if (!error)
+            result = [snapshotImage CGImage];
+        isDone = true;
+    }];
+    while (!isDone)
+        [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantPast]];
+    return result;
+
 #else
     CGFloat deviceScaleFactor = 2; // FIXME: hardcode 2x for now. In future we could respect 1x and 3x as we do on Mac.
     CATransform3D transform = CATransform3DMakeScale(deviceScaleFactor, deviceScaleFactor, 1);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to