Should use CARenderServerRenderLayerWithTransform for snapshots on iOS
authorbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 Sep 2015 21:24:01 +0000 (21:24 +0000)
committerbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 Sep 2015 21:24:01 +0000 (21:24 +0000)
https://bugs.webkit.org/show_bug.cgi?id=149069
-and corresponding-
rdar://problem/19726953

Reviewed by Tim Horton.

This will let us own the backing IOSurface, which will let us share more code
with Mac.

Use CARenderServerRenderLayerWithTransform
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _takeViewSnapshot]):
(-[WKWebView _zoomToPoint:atScale:animated:]):

We can eliminate things needed for the slot-based API.
* UIProcess/mac/ViewSnapshotStore.h:
(WebKit::ViewSnapshot::setDeviceScaleFactor):
(WebKit::ViewSnapshot::deviceScaleFactor):
(WebKit::ViewSnapshot::surface):
(WebKit::ViewSnapshot::imageSizeInBytes):
(WebKit::ViewSnapshot::size):
* UIProcess/mac/ViewSnapshotStore.mm:
(WebKit::ViewSnapshotStore::singleton):
(WebKit::ViewSnapshotStore::didAddImageToSnapshot):
(WebKit::ViewSnapshotStore::discardSnapshotImages):
(WebKit::ViewSnapshot::create):
(WebKit::ViewSnapshot::ViewSnapshot):
(WebKit::ViewSnapshot::~ViewSnapshot):
(WebKit::ViewSnapshot::setSurface):
(WebKit::ViewSnapshot::hasImage):
(WebKit::ViewSnapshot::clearImage):
(WebKit::ViewSnapshot::asLayerContents):
(WebKit::ViewSnapshotStore::snapshottingContext): Deleted.

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit2/UIProcess/mac/ViewSnapshotStore.h
Source/WebKit2/UIProcess/mac/ViewSnapshotStore.mm

index 0311865..2a83f9a 100644 (file)
@@ -1,3 +1,40 @@
+2015-09-11  Beth Dakin  <bdakin@apple.com>
+
+        Should use CARenderServerRenderLayerWithTransform for snapshots on iOS
+        https://bugs.webkit.org/show_bug.cgi?id=149069
+        -and corresponding-
+        rdar://problem/19726953
+
+        Reviewed by Tim Horton.
+
+        This will let us own the backing IOSurface, which will let us share more code 
+        with Mac.
+
+        Use CARenderServerRenderLayerWithTransform
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _takeViewSnapshot]):
+        (-[WKWebView _zoomToPoint:atScale:animated:]):
+
+        We can eliminate things needed for the slot-based API.
+        * UIProcess/mac/ViewSnapshotStore.h:
+        (WebKit::ViewSnapshot::setDeviceScaleFactor):
+        (WebKit::ViewSnapshot::deviceScaleFactor):
+        (WebKit::ViewSnapshot::surface):
+        (WebKit::ViewSnapshot::imageSizeInBytes):
+        (WebKit::ViewSnapshot::size):
+        * UIProcess/mac/ViewSnapshotStore.mm:
+        (WebKit::ViewSnapshotStore::singleton):
+        (WebKit::ViewSnapshotStore::didAddImageToSnapshot):
+        (WebKit::ViewSnapshotStore::discardSnapshotImages):
+        (WebKit::ViewSnapshot::create):
+        (WebKit::ViewSnapshot::ViewSnapshot):
+        (WebKit::ViewSnapshot::~ViewSnapshot):
+        (WebKit::ViewSnapshot::setSurface):
+        (WebKit::ViewSnapshot::hasImage):
+        (WebKit::ViewSnapshot::clearImage):
+        (WebKit::ViewSnapshot::asLayerContents):
+        (WebKit::ViewSnapshotStore::snapshottingContext): Deleted.
+
 2015-09-11  Andreas Kling  <akling@apple.com>
 
         [JSC] Weak should only accept cell pointees.
index 82f210a..fcf7398 100644 (file)
@@ -1103,20 +1103,14 @@ static inline bool areEssentiallyEqualAsFloat(float a, float b)
 - (PassRefPtr<WebKit::ViewSnapshot>)_takeViewSnapshot
 {
     float deviceScale = WKGetScreenScaleFactor();
-    CGSize snapshotSize = self.bounds.size;
-    snapshotSize.width *= deviceScale;
-    snapshotSize.height *= deviceScale;
-
-    uint32_t slotID = [WebKit::ViewSnapshotStore::snapshottingContext() createImageSlot:snapshotSize hasAlpha:YES];
-
-    if (!slotID)
-        return nullptr;
+    WebCore::FloatSize snapshotSize(self.bounds.size);
+    snapshotSize.scale(deviceScale, deviceScale);
 
     CATransform3D transform = CATransform3DMakeScale(deviceScale, deviceScale, 1);
-    CARenderServerCaptureLayerWithTransform(MACH_PORT_NULL, self.layer.context.contextId, (uint64_t)self.layer, slotID, 0, 0, &transform);
+    auto surface = WebCore::IOSurface::create(WebCore::expandedIntSize(snapshotSize), WebCore::ColorSpaceDeviceRGB);
+    CARenderServerRenderLayerWithTransform(MACH_PORT_NULL, self.layer.context.contextId, reinterpret_cast<uint64_t>(self.layer), surface->surface(), 0, 0, &transform);
 
-    WebCore::IntSize imageSize = WebCore::expandedIntSize(WebCore::FloatSize(snapshotSize));
-    return WebKit::ViewSnapshot::create(slotID, imageSize, imageSize.width() * imageSize.height() * 4);
+    return WebKit::ViewSnapshot::create(nullptr);
 }
 
 - (void)_zoomToPoint:(WebCore::FloatPoint)point atScale:(double)scale animated:(BOOL)animated
index a14a10c..235383f 100644 (file)
@@ -41,14 +41,6 @@ typedef struct objc_object *id;
 
 OBJC_CLASS CAContext;
 
-#if PLATFORM(MAC)
-#define USE_IOSURFACE_VIEW_SNAPSHOTS 1
-#define USE_RENDER_SERVER_VIEW_SNAPSHOTS 0
-#else
-#define USE_IOSURFACE_VIEW_SNAPSHOTS 0
-#define USE_RENDER_SERVER_VIEW_SNAPSHOTS 1
-#endif
-
 namespace WebCore {
 class IOSurface;
 }
@@ -61,11 +53,7 @@ class WebPageProxy;
 
 class ViewSnapshot : public RefCounted<ViewSnapshot> {
 public:
-#if USE_IOSURFACE_VIEW_SNAPSHOTS
     static Ref<ViewSnapshot> create(std::unique_ptr<WebCore::IOSurface>);
-#elif USE_RENDER_SERVER_VIEW_SNAPSHOTS
-    static Ref<ViewSnapshot> create(uint32_t slotID, WebCore::IntSize, size_t imageSizeInBytes);
-#endif
 
     ~ViewSnapshot();
 
@@ -82,29 +70,20 @@ public:
     void setDeviceScaleFactor(float deviceScaleFactor) { m_deviceScaleFactor = deviceScaleFactor; }
     float deviceScaleFactor() const { return m_deviceScaleFactor; }
 
-    size_t imageSizeInBytes() const { return m_imageSizeInBytes; }
-#if USE_IOSURFACE_VIEW_SNAPSHOTS
     WebCore::IOSurface* surface() const { return m_surface.get(); }
-#endif
-    WebCore::IntSize size() const { return m_size; }
+
+    size_t imageSizeInBytes() const { return m_surface ? m_surface->totalBytes() : 0; }
+    WebCore::IntSize size() const { return m_surface ? m_surface->size() : WebCore::IntSize(); }
+
+    void setSurface(std::unique_ptr<WebCore::IOSurface>);
 
 private:
-#if USE_IOSURFACE_VIEW_SNAPSHOTS
     explicit ViewSnapshot(std::unique_ptr<WebCore::IOSurface>);
-#elif USE_RENDER_SERVER_VIEW_SNAPSHOTS
-    explicit ViewSnapshot(uint32_t slotID, WebCore::IntSize, size_t imageSizeInBytes);
-#endif
 
-#if USE_IOSURFACE_VIEW_SNAPSHOTS
     std::unique_ptr<WebCore::IOSurface> m_surface;
-#elif USE_RENDER_SERVER_VIEW_SNAPSHOTS
-    uint32_t m_slotID;
-#endif
 
-    size_t m_imageSizeInBytes;
     uint64_t m_renderTreeSize;
     float m_deviceScaleFactor;
-    WebCore::IntSize m_size;
     WebCore::Color m_backgroundColor;
 };
 
@@ -121,10 +100,6 @@ public:
 
     void discardSnapshotImages();
 
-#if USE_RENDER_SERVER_VIEW_SNAPSHOTS
-    static CAContext *snapshottingContext();
-#endif
-
 private:
     void didAddImageToSnapshot(ViewSnapshot&);
     void willRemoveImageFromSnapshot(ViewSnapshot&);
index b608426..2f579ec 100644 (file)
 
 using namespace WebCore;
 
-#if USE_IOSURFACE_VIEW_SNAPSHOTS
-static const size_t maximumSnapshotCacheSize = 400 * (1024 * 1024);
-#elif USE_RENDER_SERVER_VIEW_SNAPSHOTS
-// Because render server snapshots are not purgeable, we should keep fewer around.
+#if PLATFORM(IOS)
 static const size_t maximumSnapshotCacheSize = 50 * (1024 * 1024);
+#else
+static const size_t maximumSnapshotCacheSize = 400 * (1024 * 1024);
 #endif
 
 namespace WebKit {
@@ -62,24 +61,6 @@ ViewSnapshotStore& ViewSnapshotStore::singleton()
     return store;
 }
 
-#if USE_RENDER_SERVER_VIEW_SNAPSHOTS
-CAContext *ViewSnapshotStore::snapshottingContext()
-{
-    static CAContext *context;
-    static dispatch_once_t onceToken;
-    dispatch_once(&onceToken, ^{
-        NSDictionary *options = @{
-            kCAContextDisplayName: @"WebKitSnapshotting",
-            kCAContextIgnoresHitTest: @YES,
-            kCAContextDisplayId : @20000
-        };
-        context = [[CAContext remoteContextWithOptions:options] retain];
-    });
-
-    return context;
-}
-#endif
-
 void ViewSnapshotStore::didAddImageToSnapshot(ViewSnapshot& snapshot)
 {
     bool isNewEntry = m_snapshotsWithImages.add(&snapshot).isNewEntry;
@@ -132,30 +113,13 @@ void ViewSnapshotStore::discardSnapshotImages()
         m_snapshotsWithImages.first()->clearImage();
 }
 
-
-#if USE_IOSURFACE_VIEW_SNAPSHOTS
 Ref<ViewSnapshot> ViewSnapshot::create(std::unique_ptr<IOSurface> surface)
 {
     return adoptRef(*new ViewSnapshot(WTF::move(surface)));
 }
-#elif USE_RENDER_SERVER_VIEW_SNAPSHOTS
-Ref<ViewSnapshot> ViewSnapshot::create(uint32_t slotID, IntSize size, size_t imageSizeInBytes)
-{
-    return adoptRef(*new ViewSnapshot(slotID, size, imageSizeInBytes));
-}
-#endif
 
-#if USE_IOSURFACE_VIEW_SNAPSHOTS
 ViewSnapshot::ViewSnapshot(std::unique_ptr<IOSurface> surface)
     : m_surface(WTF::move(surface))
-    , m_imageSizeInBytes(m_surface->totalBytes())
-    , m_size(m_surface->size())
-#elif USE_RENDER_SERVER_VIEW_SNAPSHOTS
-ViewSnapshot::ViewSnapshot(uint32_t slotID, IntSize size, size_t imageSizeInBytes)
-    : m_slotID(slotID)
-    , m_imageSizeInBytes(imageSizeInBytes)
-    , m_size(size)
-#endif
 {
     if (hasImage())
         ViewSnapshotStore::singleton().didAddImageToSnapshot(*this);
@@ -166,13 +130,21 @@ ViewSnapshot::~ViewSnapshot()
     clearImage();
 }
 
+void ViewSnapshot::setSurface(std::unique_ptr<WebCore::IOSurface> surface)
+{
+    ASSERT(!m_surface);
+    if (!surface) {
+        clearImage();
+        return;
+    }
+
+    m_surface = WTF::move(surface);
+    ViewSnapshotStore::singleton().didAddImageToSnapshot(*this);
+}
+
 bool ViewSnapshot::hasImage() const
 {
-#if USE_IOSURFACE_VIEW_SNAPSHOTS
     return !!m_surface;
-#elif USE_RENDER_SERVER_VIEW_SNAPSHOTS
-    return m_slotID;
-#endif
 }
 
 void ViewSnapshot::clearImage()
@@ -182,18 +154,11 @@ void ViewSnapshot::clearImage()
 
     ViewSnapshotStore::singleton().willRemoveImageFromSnapshot(*this);
 
-#if USE_IOSURFACE_VIEW_SNAPSHOTS
     m_surface = nullptr;
-#elif USE_RENDER_SERVER_VIEW_SNAPSHOTS
-    [ViewSnapshotStore::snapshottingContext() deleteSlot:m_slotID];
-    m_slotID = 0;
-#endif
-    m_imageSizeInBytes = 0;
 }
 
 id ViewSnapshot::asLayerContents()
 {
-#if USE_IOSURFACE_VIEW_SNAPSHOTS
     if (!m_surface)
         return nullptr;
 
@@ -203,9 +168,6 @@ id ViewSnapshot::asLayerContents()
     }
 
     return (id)m_surface->surface();
-#elif USE_RENDER_SERVER_VIEW_SNAPSHOTS
-    return [CAContext objectForSlot:m_slotID];
-#endif
 }
 
 } // namespace WebKit