RemoteLayerTreeNode construction cleanups
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 25 Nov 2018 12:19:02 +0000 (12:19 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 25 Nov 2018 12:19:02 +0000 (12:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191951

Reviewed by Tim Horton.

* UIProcess/RemoteLayerTree/RemoteLayerTreeHost.h:
* UIProcess/RemoteLayerTree/RemoteLayerTreeHost.mm:
(WebKit::RemoteLayerTreeHost::updateLayerTree):

    Drop unused LayerProperties argument.

(WebKit::RemoteLayerTreeHost::createLayer):

    Split the actual construction out to makeNode.
    Map updating is shared between platforms.
    Move setting of layerID and clearing default actions to RemoteLayerTreeNode.

(WebKit::RemoteLayerTreeHost::makeNode):

    Returns RemoteLayerTreeNode.

(WebKit::RemoteLayerTreeHost::setLayerID): Deleted.
(WebKit::RemoteLayerTreeHost::layerID): Deleted.

    Move to RemoteLayerTreeNode.

* UIProcess/RemoteLayerTree/RemoteLayerTreeNode.h:
* UIProcess/RemoteLayerTree/RemoteLayerTreeNode.mm:
(WebKit::RemoteLayerTreeNode::RemoteLayerTreeNode):
(WebKit::RemoteLayerTreeNode::setLayerID):
(WebKit::RemoteLayerTreeNode::layerID):
* UIProcess/RemoteLayerTree/ios/RemoteLayerTreeHostIOS.mm:
(WebKit::RemoteLayerTreeHost::makeNode):
(WebKit::RemoteLayerTreeHost::createEmbeddedView):
(WebKit::RemoteLayerTreeHost::createLayer): Deleted.
* UIProcess/RemoteLayerTree/ios/RemoteLayerTreeViews.mm:
(-[WKCompositingView description]):
(-[WKUIRemoteView description]):
(-[WKBackdropView description]):
* WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm:
(WebKit::addAnimationToLayer):

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/RemoteLayerTree/RemoteLayerTreeHost.h
Source/WebKit/UIProcess/RemoteLayerTree/RemoteLayerTreeHost.mm
Source/WebKit/UIProcess/RemoteLayerTree/RemoteLayerTreeNode.h
Source/WebKit/UIProcess/RemoteLayerTree/RemoteLayerTreeNode.mm
Source/WebKit/UIProcess/RemoteLayerTree/ios/RemoteLayerTreeHostIOS.mm
Source/WebKit/UIProcess/RemoteLayerTree/ios/RemoteLayerTreeViews.mm
Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm

index dcb9fb5..ec9d5c0 100644 (file)
@@ -1,3 +1,47 @@
+2018-11-25  Antti Koivisto  <antti@apple.com>
+
+        RemoteLayerTreeNode construction cleanups
+        https://bugs.webkit.org/show_bug.cgi?id=191951
+
+        Reviewed by Tim Horton.
+
+        * UIProcess/RemoteLayerTree/RemoteLayerTreeHost.h:
+        * UIProcess/RemoteLayerTree/RemoteLayerTreeHost.mm:
+        (WebKit::RemoteLayerTreeHost::updateLayerTree):
+
+            Drop unused LayerProperties argument.
+
+        (WebKit::RemoteLayerTreeHost::createLayer):
+
+            Split the actual construction out to makeNode.
+            Map updating is shared between platforms.
+            Move setting of layerID and clearing default actions to RemoteLayerTreeNode.
+
+        (WebKit::RemoteLayerTreeHost::makeNode):
+
+            Returns RemoteLayerTreeNode.
+
+        (WebKit::RemoteLayerTreeHost::setLayerID): Deleted.
+        (WebKit::RemoteLayerTreeHost::layerID): Deleted.
+
+            Move to RemoteLayerTreeNode.
+
+        * UIProcess/RemoteLayerTree/RemoteLayerTreeNode.h:
+        * UIProcess/RemoteLayerTree/RemoteLayerTreeNode.mm:
+        (WebKit::RemoteLayerTreeNode::RemoteLayerTreeNode):
+        (WebKit::RemoteLayerTreeNode::setLayerID):
+        (WebKit::RemoteLayerTreeNode::layerID):
+        * UIProcess/RemoteLayerTree/ios/RemoteLayerTreeHostIOS.mm:
+        (WebKit::RemoteLayerTreeHost::makeNode):
+        (WebKit::RemoteLayerTreeHost::createEmbeddedView):
+        (WebKit::RemoteLayerTreeHost::createLayer): Deleted.
+        * UIProcess/RemoteLayerTree/ios/RemoteLayerTreeViews.mm:
+        (-[WKCompositingView description]):
+        (-[WKUIRemoteView description]):
+        (-[WKBackdropView description]):
+        * WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm:
+        (WebKit::addAnimationToLayer):
+
 2018-11-25  Tim Horton  <timothy_horton@apple.com>
 
         Make it possible to insert editable images with a gesture
index afa5543..847ba58 100644 (file)
@@ -43,13 +43,11 @@ class WebPageProxy;
 class RemoteLayerTreeHost {
 public:
     explicit RemoteLayerTreeHost(RemoteLayerTreeDrawingAreaProxy&);
-    virtual ~RemoteLayerTreeHost();
+    ~RemoteLayerTreeHost();
 
     RemoteLayerTreeNode* nodeForID(WebCore::GraphicsLayer::PlatformLayerID) const;
     RemoteLayerTreeNode* rootNode() const { return m_rootNode; }
 
-    static WebCore::GraphicsLayer::PlatformLayerID layerID(CALayer*);
-
     CALayer *layerForID(WebCore::GraphicsLayer::PlatformLayerID) const;
     CALayer *rootLayer() const;
 
@@ -78,9 +76,10 @@ public:
     CALayer *layerWithIDForTesting(uint64_t) const;
 
 private:
-    void createLayer(const RemoteLayerTreeTransaction::LayerCreationProperties&, const RemoteLayerTreeTransaction::LayerProperties*);
-    RetainPtr<WKEmbeddedView> createEmbeddedView(const RemoteLayerTreeTransaction::LayerCreationProperties&, const RemoteLayerTreeTransaction::LayerProperties*);
-    static void setLayerID(CALayer *, WebCore::GraphicsLayer::PlatformLayerID);
+    void createLayer(const RemoteLayerTreeTransaction::LayerCreationProperties&);
+    std::unique_ptr<RemoteLayerTreeNode> makeNode(const RemoteLayerTreeTransaction::LayerCreationProperties&);
+
+    RetainPtr<WKEmbeddedView> createEmbeddedView(const RemoteLayerTreeTransaction::LayerCreationProperties&);
 
     void layerWillBeRemoved(WebCore::GraphicsLayer::PlatformLayerID);
 
index 562ad7f..3f0830a 100644 (file)
@@ -38,7 +38,6 @@
 #import <WebCore/GraphicsContextCG.h>
 #import <WebCore/IOSurface.h>
 #import <WebCore/PlatformLayer.h>
-#import <WebCore/WebActionDisablingCALayerDelegate.h>
 #import <WebCore/WebCoreCALayerExtras.h>
 #import <pal/spi/cocoa/QuartzCoreSPI.h>
 
@@ -69,10 +68,8 @@ bool RemoteLayerTreeHost::updateLayerTree(const RemoteLayerTreeTransaction& tran
     if (!m_drawingArea)
         return false;
 
-    for (const auto& createdLayer : transaction.createdLayers()) {
-        const RemoteLayerTreeTransaction::LayerProperties* properties = transaction.changedLayerProperties().get(createdLayer.layerID);
-        createLayer(createdLayer, properties);
-    }
+    for (const auto& createdLayer : transaction.createdLayers())
+        createLayer(createdLayer);
 
     bool rootLayerChanged = false;
     auto* rootNode = nodeForID(transaction.rootLayerID());
@@ -231,18 +228,6 @@ CALayer *RemoteLayerTreeHost::layerWithIDForTesting(uint64_t layerID) const
     return layerForID(layerID);
 }
 
-static NSString* const WKLayerIDPropertyKey = @"WKLayerID";
-
-void RemoteLayerTreeHost::setLayerID(CALayer *layer, WebCore::GraphicsLayer::PlatformLayerID layerID)
-{
-    [layer setValue:[NSNumber numberWithUnsignedLongLong:layerID] forKey:WKLayerIDPropertyKey];
-}
-
-WebCore::GraphicsLayer::PlatformLayerID RemoteLayerTreeHost::layerID(CALayer* layer)
-{
-    return [[layer valueForKey:WKLayerIDPropertyKey] unsignedLongLongValue];
-}
-
 CALayer *RemoteLayerTreeHost::layerForID(WebCore::GraphicsLayer::PlatformLayerID layerID) const
 {
     auto* node = nodeForID(layerID);
@@ -258,12 +243,24 @@ CALayer *RemoteLayerTreeHost::rootLayer() const
     return m_rootNode->layer();
 }
 
-#if !PLATFORM(IOS_FAMILY)
-void RemoteLayerTreeHost::createLayer(const RemoteLayerTreeTransaction::LayerCreationProperties& properties, const RemoteLayerTreeTransaction::LayerProperties*)
+void RemoteLayerTreeHost::createLayer(const RemoteLayerTreeTransaction::LayerCreationProperties& properties)
 {
     ASSERT(!m_nodes.contains(properties.layerID));
 
-    RetainPtr<CALayer> layer;
+    auto node = makeNode(properties);
+
+    m_nodes.add(properties.layerID, WTFMove(node));
+}
+
+#if !PLATFORM(IOS_FAMILY)
+std::unique_ptr<RemoteLayerTreeNode> RemoteLayerTreeHost::makeNode(const RemoteLayerTreeTransaction::LayerCreationProperties& properties)
+{
+    auto makeWithLayer = [&] (RetainPtr<CALayer> layer) {
+        return std::make_unique<RemoteLayerTreeNode>(properties.layerID, WTFMove(layer));
+    };
+    auto makeAdoptingLayer = [&] (CALayer* layer) {
+        return makeWithLayer(adoptNS(layer));
+    };
 
     switch (properties.type) {
     case PlatformCALayer::LayerTypeLayer:
@@ -275,40 +272,34 @@ void RemoteLayerTreeHost::createLayer(const RemoteLayerTreeTransaction::LayerCre
     case PlatformCALayer::LayerTypeTiledBackingTileLayer:
     case PlatformCALayer::LayerTypeScrollingLayer:
     case PlatformCALayer::LayerTypeEditableImageLayer:
-        layer = adoptNS([[CALayer alloc] init]);
-        break;
+        return makeAdoptingLayer([[CALayer alloc] init]);
+
     case PlatformCALayer::LayerTypeTransformLayer:
-        layer = adoptNS([[CATransformLayer alloc] init]);
-        break;
+        return makeAdoptingLayer([[CATransformLayer alloc] init]);
+
     case PlatformCALayer::LayerTypeBackdropLayer:
     case PlatformCALayer::LayerTypeLightSystemBackdropLayer:
     case PlatformCALayer::LayerTypeDarkSystemBackdropLayer:
 #if ENABLE(FILTERS_LEVEL_2)
-        layer = adoptNS([[CABackdropLayer alloc] init]);
+        return makeAdoptingLayer([[CABackdropLayer alloc] init]);
 #else
         ASSERT_NOT_REACHED();
-        layer = adoptNS([[CALayer alloc] init]);
+        return makeAdoptingLayer([[CALayer alloc] init]);
 #endif
-        break;
     case PlatformCALayer::LayerTypeCustom:
     case PlatformCALayer::LayerTypeAVPlayerLayer:
     case PlatformCALayer::LayerTypeContentsProvidedLayer:
-        if (!m_isDebugLayerTreeHost)
-            layer = [CALayer _web_renderLayerWithContextID:properties.hostingContextID];
-        else
-            layer = adoptNS([[CALayer alloc] init]);
-        break;
+        if (m_isDebugLayerTreeHost)
+            return makeAdoptingLayer([[CALayer alloc] init]);
+        return makeWithLayer([CALayer _web_renderLayerWithContextID:properties.hostingContextID]);
+
     case PlatformCALayer::LayerTypeShapeLayer:
-        layer = adoptNS([[CAShapeLayer alloc] init]);
-        break;
+        return makeAdoptingLayer([[CAShapeLayer alloc] init]);
+            
     default:
         ASSERT_NOT_REACHED();
+        return nullptr;
     }
-
-    [layer setDelegate:[WebActionDisablingCALayerDelegate shared]];
-    setLayerID(layer.get(), properties.layerID);
-
-    m_nodes.add(properties.layerID, std::make_unique<RemoteLayerTreeNode>(WTFMove(layer)));
 }
 #endif
 
index cc268ef..f25141c 100644 (file)
@@ -25,6 +25,7 @@
 
 #pragma once
 
+#include <WebCore/GraphicsLayer.h>
 #include <wtf/RetainPtr.h>
 
 OBJC_CLASS CALayer;
@@ -37,9 +38,9 @@ namespace WebKit {
 class RemoteLayerTreeNode {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    RemoteLayerTreeNode(RetainPtr<CALayer>);
+    RemoteLayerTreeNode(WebCore::GraphicsLayer::PlatformLayerID, RetainPtr<CALayer>);
 #if PLATFORM(IOS_FAMILY)
-    RemoteLayerTreeNode(RetainPtr<UIView>);
+    RemoteLayerTreeNode(WebCore::GraphicsLayer::PlatformLayerID, RetainPtr<UIView>);
 #endif
 
     ~RemoteLayerTreeNode();
@@ -51,7 +52,11 @@ public:
 
     void detachFromParent();
 
+    static WebCore::GraphicsLayer::PlatformLayerID layerID(CALayer*);
+
 private:
+    void setLayerID(WebCore::GraphicsLayer::PlatformLayerID);
+
     RetainPtr<CALayer> m_layer;
 #if PLATFORM(IOS_FAMILY)
     RetainPtr<UIView> m_uiView;
index eb38c49..141ac5a 100644 (file)
 #include "config.h"
 #include "RemoteLayerTreeNode.h"
 
+#import <WebCore/WebActionDisablingCALayerDelegate.h>
+
 namespace WebKit {
 
-RemoteLayerTreeNode::RemoteLayerTreeNode(RetainPtr<CALayer> layer)
+RemoteLayerTreeNode::RemoteLayerTreeNode(WebCore::GraphicsLayer::PlatformLayerID layerID, RetainPtr<CALayer> layer)
     : m_layer(WTFMove(layer))
 {
+    setLayerID(layerID);
+    [m_layer setDelegate:[WebActionDisablingCALayerDelegate shared]];
 }
 
 #if PLATFORM(IOS_FAMILY)
-RemoteLayerTreeNode::RemoteLayerTreeNode(RetainPtr<UIView> uiView)
+RemoteLayerTreeNode::RemoteLayerTreeNode(WebCore::GraphicsLayer::PlatformLayerID layerID, RetainPtr<UIView> uiView)
     : m_layer([uiView.get() layer])
     , m_uiView(WTFMove(uiView))
 {
+    setLayerID(layerID);
 }
 #endif
 
@@ -52,4 +57,16 @@ void RemoteLayerTreeNode::detachFromParent()
 #endif
 }
 
+static NSString* const WKLayerIDPropertyKey = @"WKLayerID";
+
+void RemoteLayerTreeNode::setLayerID(WebCore::GraphicsLayer::PlatformLayerID layerID)
+{
+    [layer() setValue:@(layerID) forKey:WKLayerIDPropertyKey];
+}
+
+WebCore::GraphicsLayer::PlatformLayerID RemoteLayerTreeNode::layerID(CALayer* layer)
+{
+    return [[layer valueForKey:WKLayerIDPropertyKey] unsignedLongLongValue];
+}
+
 }
index 9adffde..54ba668 100644 (file)
@@ -58,11 +58,14 @@ static RetainPtr<UIView> createRemoteView(pid_t pid, uint32_t contextID)
     return adoptNS([[WKRemoteView alloc] initWithFrame:CGRectZero contextID:contextID]);
 }
 
-void RemoteLayerTreeHost::createLayer(const RemoteLayerTreeTransaction::LayerCreationProperties& properties, const RemoteLayerTreeTransaction::LayerProperties* layerProperties)
+std::unique_ptr<RemoteLayerTreeNode> RemoteLayerTreeHost::makeNode(const RemoteLayerTreeTransaction::LayerCreationProperties& properties)
 {
-    ASSERT(!m_nodes.contains(properties.layerID));
-
-    RetainPtr<UIView> view;
+    auto makeWithView = [&] (RetainPtr<UIView> view) {
+        return std::make_unique<RemoteLayerTreeNode>(properties.layerID, WTFMove(view));
+    };
+    auto makeAdoptingView = [&] (UIView* view) {
+        return makeWithView(adoptNS(view));
+    };
 
     switch (properties.type) {
     case PlatformCALayer::LayerTypeLayer:
@@ -72,55 +75,53 @@ void RemoteLayerTreeHost::createLayer(const RemoteLayerTreeTransaction::LayerCre
     case PlatformCALayer::LayerTypeTiledBackingLayer:
     case PlatformCALayer::LayerTypePageTiledBackingLayer:
     case PlatformCALayer::LayerTypeTiledBackingTileLayer:
-        view = adoptNS([[WKCompositingView alloc] init]);
-        break;
+        return makeAdoptingView([[WKCompositingView alloc] init]);
+
     case PlatformCALayer::LayerTypeBackdropLayer:
-        view = adoptNS([[WKSimpleBackdropView alloc] init]);
-        break;
+        return makeAdoptingView([[WKSimpleBackdropView alloc] init]);
+
     case PlatformCALayer::LayerTypeLightSystemBackdropLayer:
-        view = adoptNS([[WKBackdropView alloc] initWithFrame:CGRectZero privateStyle:_UIBackdropViewStyle_Light]);
-        break;
+        return makeAdoptingView([[WKBackdropView alloc] initWithFrame:CGRectZero privateStyle:_UIBackdropViewStyle_Light]);
+
     case PlatformCALayer::LayerTypeDarkSystemBackdropLayer:
-        view = adoptNS([[WKBackdropView alloc] initWithFrame:CGRectZero privateStyle:_UIBackdropViewStyle_Dark]);
-        break;
+        return makeAdoptingView([[WKBackdropView alloc] initWithFrame:CGRectZero privateStyle:_UIBackdropViewStyle_Dark]);
+
     case PlatformCALayer::LayerTypeTransformLayer:
-        view = adoptNS([[WKTransformView alloc] init]);
-        break;
+        return makeAdoptingView([[WKTransformView alloc] init]);
+
     case PlatformCALayer::LayerTypeCustom:
     case PlatformCALayer::LayerTypeAVPlayerLayer:
     case PlatformCALayer::LayerTypeContentsProvidedLayer:
         if (!m_isDebugLayerTreeHost) {
-            view = createRemoteView(m_drawingArea->page().processIdentifier(), properties.hostingContextID);
+            auto view = createRemoteView(m_drawingArea->page().processIdentifier(), properties.hostingContextID);
             if (properties.type == PlatformCALayer::LayerTypeAVPlayerLayer) {
                 // Invert the scale transform added in the WebProcess to fix <rdar://problem/18316542>.
                 float inverseScale = 1 / properties.hostingDeviceScaleFactor;
                 [[view layer] setTransform:CATransform3DMakeScale(inverseScale, inverseScale, 1)];
             }
-        } else
-            view = adoptNS([[WKCompositingView alloc] init]);
-        break;
+            return makeWithView(WTFMove(view));
+        }
+        return makeAdoptingView([[WKCompositingView alloc] init]);
+
     case PlatformCALayer::LayerTypeShapeLayer:
-        view = adoptNS([[WKShapeView alloc] init]);
-        break;
+        return makeAdoptingView([[WKShapeView alloc] init]);
+
     case PlatformCALayer::LayerTypeScrollingLayer:
         if (!m_isDebugLayerTreeHost)
-            view = adoptNS([[WKChildScrollView alloc] init]);
-        else // The debug indicator parents views under layers, which can cause crashes with UIScrollView.
-            view = adoptNS([[UIView alloc] init]);
-        break;
+            return makeAdoptingView([[WKChildScrollView alloc] init]);
+        // The debug indicator parents views under layers, which can cause crashes with UIScrollView.
+        return makeAdoptingView([[UIView alloc] init]);
+
     case PlatformCALayer::LayerTypeEditableImageLayer:
-        view = createEmbeddedView(properties, layerProperties);
-        break;
+        return makeWithView(createEmbeddedView(properties));
+
     default:
         ASSERT_NOT_REACHED();
+        return nullptr;
     }
-
-    setLayerID([view layer], properties.layerID);
-
-    m_nodes.add(properties.layerID, std::make_unique<RemoteLayerTreeNode>(WTFMove(view)));
 }
 
-RetainPtr<WKEmbeddedView> RemoteLayerTreeHost::createEmbeddedView(const RemoteLayerTreeTransaction::LayerCreationProperties& properties, const RemoteLayerTreeTransaction::LayerProperties* layerProperties)
+RetainPtr<WKEmbeddedView> RemoteLayerTreeHost::createEmbeddedView(const RemoteLayerTreeTransaction::LayerCreationProperties& properties)
 {
     Class embeddedViewClass = nil;
     switch (properties.type) {
index c528698..1921fda 100644 (file)
@@ -92,7 +92,7 @@
 - (NSString *)description
 {
     NSString *viewDescription = [super description];
-    NSString *webKitDetails = [NSString stringWithFormat:@" layerID = %llu \"%@\"", WebKit::RemoteLayerTreeHost::layerID(self.layer), self.layer.name ? self.layer.name : @""];
+    NSString *webKitDetails = [NSString stringWithFormat:@" layerID = %llu \"%@\"", WebKit::RemoteLayerTreeNode::layerID(self.layer), self.layer.name ? self.layer.name : @""];
     return [viewDescription stringByAppendingString:webKitDetails];
 }
 
 - (NSString *)description
 {
     NSString *viewDescription = [super description];
-    NSString *webKitDetails = [NSString stringWithFormat:@" layerID = %llu \"%@\"", WebKit::RemoteLayerTreeHost::layerID(self.layer), self.layer.name ? self.layer.name : @""];
+    NSString *webKitDetails = [NSString stringWithFormat:@" layerID = %llu \"%@\"", WebKit::RemoteLayerTreeNode::layerID(self.layer), self.layer.name ? self.layer.name : @""];
     return [viewDescription stringByAppendingString:webKitDetails];
 }
 
 - (NSString *)description
 {
     NSString *viewDescription = [super description];
-    NSString *webKitDetails = [NSString stringWithFormat:@" layerID = %llu \"%@\"", WebKit::RemoteLayerTreeHost::layerID(self.layer), self.layer.name ? self.layer.name : @""];
+    NSString *webKitDetails = [NSString stringWithFormat:@" layerID = %llu \"%@\"", WebKit::RemoteLayerTreeNode::layerID(self.layer), self.layer.name ? self.layer.name : @""];
     return [viewDescription stringByAppendingString:webKitDetails];
 }
 
index c2de0a2..a54e2e8 100644 (file)
@@ -803,7 +803,7 @@ static void addAnimationToLayer(CALayer *layer, RemoteLayerTreeHost* layerTreeHo
         [caAnimation setValue:@YES forKey:WKExplicitBeginTimeFlag];
     
     if (layerTreeHost) {
-        GraphicsLayer::PlatformLayerID layerID = RemoteLayerTreeHost::layerID(layer);
+        GraphicsLayer::PlatformLayerID layerID = RemoteLayerTreeNode::layerID(layer);
     
         RetainPtr<WKAnimationDelegate>& delegate = layerTreeHost->animationDelegates().add(layerID, nullptr).iterator->value;
         if (!delegate)