Source/WebCore:
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Mar 2015 22:47:53 +0000 (22:47 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Mar 2015 22:47:53 +0000 (22:47 +0000)
WebCore part of <rdar://problem/20282863> Transforms are flattened in snapshots of on-screen WKWebViews
https://bugs.webkit.org/show_bug.cgi?id=143023

Reviewed by Tim Horton.

* platform/spi/cocoa/QuartzCoreSPI.h: Added the declaration of
CARenderServerRenderLayerWithTransform.

Source/WebKit2:
WebKit2 part of <rdar://problem/20282863> Transforms are flattened in snapshots of on-screen WKWebViews
https://bugs.webkit.org/show_bug.cgi?id=143023

Reviewed by Tim Horton.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _snapshotRect:intoImageOfWidth:completionHandler:]): If the view is in a
window, use CARenderServerRenderLayerWithTransform to synchronously capture a snapshot of
its layer tree into an IOSurfcae, then call the completion handler with an image created
from the IOSurface.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/spi/cocoa/QuartzCoreSPI.h
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm

index c254b44..b93417d 100644 (file)
@@ -1,3 +1,13 @@
+2015-03-24  Dan Bernstein  <mitz@apple.com>
+
+        WebCore part of <rdar://problem/20282863> Transforms are flattened in snapshots of on-screen WKWebViews
+        https://bugs.webkit.org/show_bug.cgi?id=143023
+
+        Reviewed by Tim Horton.
+
+        * platform/spi/cocoa/QuartzCoreSPI.h: Added the declaration of
+        CARenderServerRenderLayerWithTransform.
+
 2015-03-24  David Hyatt  <hyatt@apple.com>
 
         Disable layout dimensions optimization for RenderRegions
 2015-03-24  David Hyatt  <hyatt@apple.com>
 
         Disable layout dimensions optimization for RenderRegions
index 4730d59..903d27e 100644 (file)
@@ -115,6 +115,8 @@ typedef struct CAColorMatrix CAColorMatrix;
 EXTERN_C void CARenderServerCaptureLayerWithTransform(mach_port_t serverPort, uint32_t clientId, uint64_t layerId,
                                                       uint32_t slotId, int32_t ox, int32_t oy, const CATransform3D *);
 
 EXTERN_C void CARenderServerCaptureLayerWithTransform(mach_port_t serverPort, uint32_t clientId, uint64_t layerId,
                                                       uint32_t slotId, int32_t ox, int32_t oy, const CATransform3D *);
 
+EXTERN_C void CARenderServerRenderLayerWithTransform(mach_port_t server_port, uint32_t client_id, uint64_t layer_id, IOSurfaceRef iosurface, int32_t ox, int32_t oy, const CATransform3D *matrix);
+
 EXTERN_C NSString * const kCATiledLayerRemoveImmediately;
 
 EXTERN_C NSString * const kCAFilterColorInvert;
 EXTERN_C NSString * const kCATiledLayerRemoveImmediately;
 
 EXTERN_C NSString * const kCAFilterColorInvert;
index 1003252..11eed6e 100644 (file)
@@ -1,3 +1,16 @@
+2015-03-24  Dan Bernstein  <mitz@apple.com>
+
+        WebKit2 part of <rdar://problem/20282863> Transforms are flattened in snapshots of on-screen WKWebViews
+        https://bugs.webkit.org/show_bug.cgi?id=143023
+
+        Reviewed by Tim Horton.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _snapshotRect:intoImageOfWidth:completionHandler:]): If the view is in a
+        window, use CARenderServerRenderLayerWithTransform to synchronously capture a snapshot of
+        its layer tree into an IOSurfcae, then call the completion handler with an image created
+        from the IOSurface.
+
 2015-03-24  Beth Dakin  <bdakin@apple.com>
 
         Add events related to force click gesture
 2015-03-24  Beth Dakin  <bdakin@apple.com>
 
         Add events related to force click gesture
index 55c7a5f..7e14dfa 100644 (file)
@@ -77,6 +77,7 @@
 #import "_WKWebsiteDataStoreInternal.h"
 #import <JavaScriptCore/JSContext.h>
 #import <JavaScriptCore/JSValue.h>
 #import "_WKWebsiteDataStoreInternal.h"
 #import <JavaScriptCore/JSContext.h>
 #import <JavaScriptCore/JSValue.h>
+#import <WebCore/IOSurface.h>
 #import <wtf/HashMap.h>
 #import <wtf/MathExtras.h>
 #import <wtf/NeverDestroyed.h>
 #import <wtf/HashMap.h>
 #import <wtf/MathExtras.h>
 #import <wtf/NeverDestroyed.h>
@@ -2502,7 +2503,27 @@ static inline WebKit::FindOptions toFindOptions(_WKFindOptions wkFindOptions)
         UIGraphicsEndImageContext();
         return;
     }
         UIGraphicsEndImageContext();
         return;
     }
-    
+
+#if USE(IOSURFACE)
+    // If we are parented and thus won't incur a significant penalty from paging in tiles, snapshot the view hierarchy directly.
+    if (self.window) {
+        float deviceScaleFactor = _page->deviceScaleFactor();
+
+        CGRect imageRectInPoints;
+        imageRectInPoints.size.width = imageWidth / deviceScaleFactor;
+        imageRectInPoints.size.height = imageRectInPoints.size.width / rectInViewCoordinates.size.width * rectInViewCoordinates.size.height;
+        imageRectInPoints.origin.x = rectInViewCoordinates.origin.x / deviceScaleFactor;
+        imageRectInPoints.origin.y = rectInViewCoordinates.origin.y / deviceScaleFactor;
+
+        auto surface = WebCore::IOSurface::create(WebCore::expandedIntSize(WebCore::FloatSize(imageSize)), WebCore::ColorSpaceDeviceRGB);
+        CATransform3D transform = CATransform3DMakeScale(deviceScaleFactor, deviceScaleFactor, 1);
+        CARenderServerRenderLayerWithTransform(MACH_PORT_NULL, self.layer.context.contextId, reinterpret_cast<uint64_t>(self.layer), surface->surface(), 0, 0, &transform);
+        completionHandler(surface->createImage().get());
+
+        return;
+    }
+#endif
+
     void(^copiedCompletionHandler)(CGImageRef) = [completionHandler copy];
     _page->takeSnapshot(WebCore::enclosingIntRect(snapshotRectInContentCoordinates), WebCore::expandedIntSize(WebCore::FloatSize(imageSize)), WebKit::SnapshotOptionsExcludeDeviceScaleFactor, [=](const WebKit::ShareableBitmap::Handle& imageHandle, WebKit::CallbackBase::Error) {
         if (imageHandle.isNull()) {
     void(^copiedCompletionHandler)(CGImageRef) = [completionHandler copy];
     _page->takeSnapshot(WebCore::enclosingIntRect(snapshotRectInContentCoordinates), WebCore::expandedIntSize(WebCore::FloatSize(imageSize)), WebKit::SnapshotOptionsExcludeDeviceScaleFactor, [=](const WebKit::ShareableBitmap::Handle& imageHandle, WebKit::CallbackBase::Error) {
         if (imageHandle.isNull()) {