⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 238547 in webkit


Ignore:
Timestamp:
Nov 27, 2018, 1:12:03 AM (8 years ago)
Author:
Antti Koivisto
Message:

Remote tile layers shouldn't be UIViews
https://bugs.webkit.org/show_bug.cgi?id=191953

Reviewed by Tim Horton.

They don't need any UIView functionality, nor do they ever have UIView descendants.
We can use lighter weight objects.

  • Shared/RemoteLayerTree/RemoteLayerTreePropertyApplier.h:
  • Shared/RemoteLayerTree/RemoteLayerTreePropertyApplier.mm:

(WebKit::RemoteLayerTreePropertyApplier::applyProperties):
(WebKit::RemoteLayerTreePropertyApplier::updateChildren):

Factor to a function shared between platforms.
Support having both views and plain layers in the same tree.
Assert that all siblings are of the same type and that we don't attempt to add views to layers.

(WebKit::RemoteLayerTreePropertyApplier::applyPropertiesToUIView):

  • UIProcess/RemoteLayerTree/RemoteLayerTreeHost.mm:

(WebKit::RemoteLayerTreeHost::makeNode):

Use new plain layer on Mac too.

  • UIProcess/RemoteLayerTree/RemoteLayerTreeNode.h:
  • UIProcess/RemoteLayerTree/RemoteLayerTreeNode.mm:

(-[WKPlainRemoteLayer description]):

Add a CALayer subclass so we can have a description, similar to WKCompositingView and pals.

(WebKit::RemoteLayerTreeNode::createWithPlainLayer):
(WebKit::RemoteLayerTreeNode::detachFromParent):

Support having null view.

(WebKit::RemoteLayerTreeNode::appendLayerDescription):

Helper for layer descriptions.

  • UIProcess/RemoteLayerTree/ios/RemoteLayerTreeHostIOS.mm:

(WebKit::RemoteLayerTreeHost::makeNode):

Construct plain layers for tiles.

  • UIProcess/RemoteLayerTree/ios/RemoteLayerTreeViews.mm:

(-[WKCompositingView description]):
(-[WKUIRemoteView description]):
(-[WKBackdropView description]):

Location:
trunk/Source/WebKit
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r238546 r238547  
     12018-11-27  Antti Koivisto  <antti@apple.com>
     2
     3        Remote tile layers shouldn't be UIViews
     4        https://bugs.webkit.org/show_bug.cgi?id=191953
     5
     6        Reviewed by Tim Horton.
     7
     8        They don't need any UIView functionality, nor do they ever have UIView descendants.
     9        We can use lighter weight objects.
     10
     11        * Shared/RemoteLayerTree/RemoteLayerTreePropertyApplier.h:
     12        * Shared/RemoteLayerTree/RemoteLayerTreePropertyApplier.mm:
     13        (WebKit::RemoteLayerTreePropertyApplier::applyProperties):
     14        (WebKit::RemoteLayerTreePropertyApplier::updateChildren):
     15
     16        Factor to a function shared between platforms.
     17        Support having both views and plain layers in the same tree.
     18        Assert that all siblings are of the same type and that we don't attempt to add views to layers.
     19
     20        (WebKit::RemoteLayerTreePropertyApplier::applyPropertiesToUIView):
     21        * UIProcess/RemoteLayerTree/RemoteLayerTreeHost.mm:
     22        (WebKit::RemoteLayerTreeHost::makeNode):
     23
     24        Use new plain layer on Mac too.
     25
     26        * UIProcess/RemoteLayerTree/RemoteLayerTreeNode.h:
     27        * UIProcess/RemoteLayerTree/RemoteLayerTreeNode.mm:
     28        (-[WKPlainRemoteLayer description]):
     29
     30        Add a CALayer subclass so we can have a description, similar to WKCompositingView and pals.
     31
     32        (WebKit::RemoteLayerTreeNode::createWithPlainLayer):
     33        (WebKit::RemoteLayerTreeNode::detachFromParent):
     34
     35        Support having null view.
     36
     37        (WebKit::RemoteLayerTreeNode::appendLayerDescription):
     38
     39        Helper for layer descriptions.
     40
     41        * UIProcess/RemoteLayerTree/ios/RemoteLayerTreeHostIOS.mm:
     42        (WebKit::RemoteLayerTreeHost::makeNode):
     43
     44        Construct plain layers for tiles.
     45
     46        * UIProcess/RemoteLayerTree/ios/RemoteLayerTreeViews.mm:
     47        (-[WKCompositingView description]):
     48        (-[WKUIRemoteView description]):
     49        (-[WKBackdropView description]):
     50
    1512018-11-27  Fujii Hironori  <Hironori.Fujii@sony.com>
    252
  • trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerTreePropertyApplier.h

    r238468 r238547  
    4141
    4242private:
     43    static void updateChildren(RemoteLayerTreeNode&, const RemoteLayerTreeTransaction::LayerProperties&, const RelatedLayerMap&);
    4344#if PLATFORM(IOS_FAMILY)
    4445    static void applyPropertiesToUIView(UIView *, const RemoteLayerTreeTransaction::LayerProperties&, const RelatedLayerMap&);
  • trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerTreePropertyApplier.mm

    r238468 r238547  
    262262
    263263    applyPropertiesToLayer(layer, layerTreeHost, properties, layerContentsType);
     264    updateChildren(node, properties, relatedLayers);
    264265
    265266#if PLATFORM(IOS_FAMILY)
    266267    applyPropertiesToUIView(node.uiView(), properties, relatedLayers);
    267268#else
    268     if (properties.changedProperties & RemoteLayerTreeTransaction::ChildrenChanged) {
    269         RetainPtr<NSMutableArray> children = adoptNS([[NSMutableArray alloc] initWithCapacity:properties.children.size()]);
    270         for (auto& child : properties.children) {
    271             ASSERT(relatedLayers.contains(child));
    272             [children addObject:relatedLayers.get(child)->layer()];
    273         }
    274 
    275         layer.sublayers = children.get();
    276     }
    277 
    278269    if (properties.changedProperties & RemoteLayerTreeTransaction::MaskLayerChanged) {
    279270        if (!properties.maskLayerID)
     
    290281}
    291282
    292 #if PLATFORM(IOS_FAMILY)
    293 void RemoteLayerTreePropertyApplier::applyPropertiesToUIView(UIView *view, const RemoteLayerTreeTransaction::LayerProperties& properties, const RelatedLayerMap& relatedLayers)
    294 {
    295     if (properties.changedProperties & RemoteLayerTreeTransaction::ChildrenChanged) {
    296         RetainPtr<NSMutableArray> children = adoptNS([[NSMutableArray alloc] initWithCapacity:properties.children.size()]);
    297         for (auto& child : properties.children) {
    298             ASSERT(relatedLayers.contains(child));
    299             [children addObject:relatedLayers.get(child)->uiView()];
    300         }
    301 
     283void RemoteLayerTreePropertyApplier::updateChildren(RemoteLayerTreeNode& node, const RemoteLayerTreeTransaction::LayerProperties& properties, const RelatedLayerMap& relatedLayers)
     284{
     285    if (!properties.changedProperties.contains(RemoteLayerTreeTransaction::ChildrenChanged))
     286        return;
     287
     288#if PLATFORM(IOS_FAMILY)
     289    auto hasViewChildren = [&] {
     290        if (node.uiView() && [[node.uiView() subviews] count])
     291            return true;
     292        return !properties.children.isEmpty() && relatedLayers.get(properties.children.first())->uiView();
     293    };
     294
     295    auto contentView = [&] {
    302296        if (properties.customAppearance == GraphicsLayer::CustomAppearance::LightBackdrop || properties.customAppearance == GraphicsLayer::CustomAppearance::DarkBackdrop) {
    303297            // This is a UIBackdropView, which should have children attached to
    304298            // its content view, not directly on its layers.
    305             [[(_UIBackdropView*)view contentView] _web_setSubviews:children.get()];
    306         } else
    307             [view _web_setSubviews:children.get()];
    308     }
    309 
    310     if (properties.changedProperties & RemoteLayerTreeTransaction::MaskLayerChanged) {
     299            return [(_UIBackdropView *)node.uiView() contentView];
     300        }
     301        return node.uiView();
     302    };
     303
     304    if (hasViewChildren()) {
     305        ASSERT(node.uiView());
     306
     307        RetainPtr<NSMutableArray> subviews = adoptNS([[NSMutableArray alloc] initWithCapacity:properties.children.size()]);
     308        for (auto& child : properties.children) {
     309            auto* childNode = relatedLayers.get(child);
     310            ASSERT(childNode->uiView());
     311            [subviews addObject:childNode->uiView()];
     312        }
     313
     314        [contentView() _web_setSubviews:subviews.get()];
     315        return;
     316    }
     317#endif
     318
     319    RetainPtr<NSMutableArray> sublayers = adoptNS([[NSMutableArray alloc] initWithCapacity:properties.children.size()]);
     320    for (auto& child : properties.children) {
     321        auto* childNode = relatedLayers.get(child);
     322#if PLATFORM(IOS_FAMILY)
     323        ASSERT(!childNode->uiView());
     324#endif
     325        [sublayers addObject:childNode->layer()];
     326    }
     327
     328    node.layer().sublayers = sublayers.get();
     329}
     330
     331#if PLATFORM(IOS_FAMILY)
     332void RemoteLayerTreePropertyApplier::applyPropertiesToUIView(UIView *view, const RemoteLayerTreeTransaction::LayerProperties& properties, const RelatedLayerMap& relatedLayers)
     333{
     334    if (properties.changedProperties.contains(RemoteLayerTreeTransaction::MaskLayerChanged)) {
    311335        CALayer *maskOwnerLayer = view.layer;
    312336
     
    331355    if (properties.changedProperties.containsAny({ RemoteLayerTreeTransaction::ContentsHiddenChanged, RemoteLayerTreeTransaction::UserInteractionEnabledChanged }))
    332356        view.userInteractionEnabled = !properties.contentsHidden && properties.userInteractionEnabled;
    333 
    334357}
    335358#endif
  • trunk/Source/WebKit/UIProcess/RemoteLayerTree/RemoteLayerTreeHost.mm

    r238476 r238547  
    273273    case PlatformCALayer::LayerTypeScrollingLayer:
    274274    case PlatformCALayer::LayerTypeEditableImageLayer:
    275         return makeAdoptingLayer([[CALayer alloc] init]);
     275        return RemoteLayerTreeNode::createWithPlainLayer(properties.layerID);
    276276
    277277    case PlatformCALayer::LayerTypeTransformLayer:
     
    285285#else
    286286        ASSERT_NOT_REACHED();
    287         return makeAdoptingLayer([[CALayer alloc] init]);
     287        return RemoteLayerTreeNode::createWithPlainLayer(properties.layerID);
    288288#endif
    289289    case PlatformCALayer::LayerTypeCustom:
     
    291291    case PlatformCALayer::LayerTypeContentsProvidedLayer:
    292292        if (m_isDebugLayerTreeHost)
    293             return makeAdoptingLayer([[CALayer alloc] init]);
     293            return RemoteLayerTreeNode::createWithPlainLayer(properties.layerID);
    294294        return makeWithLayer([CALayer _web_renderLayerWithContextID:properties.hostingContextID]);
    295295
  • trunk/Source/WebKit/UIProcess/RemoteLayerTree/RemoteLayerTreeNode.h

    r238476 r238547  
    4343    RemoteLayerTreeNode(WebCore::GraphicsLayer::PlatformLayerID, RetainPtr<UIView>);
    4444#endif
     45    ~RemoteLayerTreeNode();
    4546
    46     ~RemoteLayerTreeNode();
     47    static std::unique_ptr<RemoteLayerTreeNode> createWithPlainLayer(WebCore::GraphicsLayer::PlatformLayerID);
    4748
    4849    CALayer *layer() const { return m_layer.get(); }
     
    5354    void detachFromParent();
    5455
    55     static WebCore::GraphicsLayer::PlatformLayerID layerID(CALayer*);
     56    static WebCore::GraphicsLayer::PlatformLayerID layerID(CALayer *);
     57    static NSString *appendLayerDescription(NSString *description, CALayer *);
    5658
    5759private:
  • trunk/Source/WebKit/UIProcess/RemoteLayerTree/RemoteLayerTreeNode.mm

    r238476 r238547  
    2424 */
    2525
    26 #include "config.h"
    27 #include "RemoteLayerTreeNode.h"
     26#import "config.h"
     27#import "RemoteLayerTreeNode.h"
    2828
     29#import <QuartzCore/CALayer.h>
    2930#import <WebCore/WebActionDisablingCALayerDelegate.h>
     31
     32#if PLATFORM(IOS_FAMILY)
     33#import <UIKit/UIView.h>
     34#endif
     35
     36@interface WKPlainRemoteLayer : CALayer
     37@end
     38
     39@implementation WKPlainRemoteLayer
     40- (NSString *)description
     41{
     42    return WebKit::RemoteLayerTreeNode::appendLayerDescription(super.description, self);
     43}
     44@end
    3045
    3146namespace WebKit {
     
    4964RemoteLayerTreeNode::~RemoteLayerTreeNode() = default;
    5065
     66std::unique_ptr<RemoteLayerTreeNode> RemoteLayerTreeNode::createWithPlainLayer(WebCore::GraphicsLayer::PlatformLayerID layerID)
     67{
     68    RetainPtr<CALayer> layer = adoptNS([[WKPlainRemoteLayer alloc] init]);
     69    return std::make_unique<RemoteLayerTreeNode>(layerID, WTFMove(layer));
     70}
     71
    5172void RemoteLayerTreeNode::detachFromParent()
    5273{
    5374#if PLATFORM(IOS_FAMILY)
    54     [uiView() removeFromSuperview];
    55 #else
     75    if (auto view = uiView()) {
     76        [view removeFromSuperview];
     77        return;
     78    }
     79#endif
    5680    [layer() removeFromSuperlayer];
    57 #endif
    5881}
    5982
    60 static NSString* const WKLayerIDPropertyKey = @"WKLayerID";
     83static NSString *const WKLayerIDPropertyKey = @"WKLayerID";
    6184
    6285void RemoteLayerTreeNode::setLayerID(WebCore::GraphicsLayer::PlatformLayerID layerID)
     
    6588}
    6689
    67 WebCore::GraphicsLayer::PlatformLayerID RemoteLayerTreeNode::layerID(CALayer* layer)
     90WebCore::GraphicsLayer::PlatformLayerID RemoteLayerTreeNode::layerID(CALayer *layer)
    6891{
    6992    return [[layer valueForKey:WKLayerIDPropertyKey] unsignedLongLongValue];
    7093}
    7194
     95NSString *RemoteLayerTreeNode::appendLayerDescription(NSString *description, CALayer *layer)
     96{
     97    NSString *layerDescription = [NSString stringWithFormat:@" layerID = %llu \"%@\"", WebKit::RemoteLayerTreeNode::layerID(layer), layer.name ? layer.name : @""];
     98    return [description stringByAppendingString:layerDescription];
    7299}
     100
     101}
  • trunk/Source/WebKit/UIProcess/RemoteLayerTree/ios/RemoteLayerTreeHostIOS.mm

    r238538 r238547  
    7676    case PlatformCALayer::LayerTypeTiledBackingLayer:
    7777    case PlatformCALayer::LayerTypePageTiledBackingLayer:
     78        return makeAdoptingView([[WKCompositingView alloc] init]);
     79
    7880    case PlatformCALayer::LayerTypeTiledBackingTileLayer:
    79         return makeAdoptingView([[WKCompositingView alloc] init]);
     81        return RemoteLayerTreeNode::createWithPlainLayer(properties.layerID);
    8082
    8183    case PlatformCALayer::LayerTypeBackdropLayer:
  • trunk/Source/WebKit/UIProcess/RemoteLayerTree/ios/RemoteLayerTreeViews.mm

    r238538 r238547  
    9292- (NSString *)description
    9393{
    94     NSString *viewDescription = [super description];
    95     NSString *webKitDetails = [NSString stringWithFormat:@" layerID = %llu \"%@\"", WebKit::RemoteLayerTreeNode::layerID(self.layer), self.layer.name ? self.layer.name : @""];
    96     return [viewDescription stringByAppendingString:webKitDetails];
     94    return WebKit::RemoteLayerTreeNode::appendLayerDescription(super.description, self.layer);
    9795}
    9896
     
    161159- (NSString *)description
    162160{
    163     NSString *viewDescription = [super description];
    164     NSString *webKitDetails = [NSString stringWithFormat:@" layerID = %llu \"%@\"", WebKit::RemoteLayerTreeNode::layerID(self.layer), self.layer.name ? self.layer.name : @""];
    165     return [viewDescription stringByAppendingString:webKitDetails];
     161    return WebKit::RemoteLayerTreeNode::appendLayerDescription(super.description, self.layer);
    166162}
    167163
     
    178174- (NSString *)description
    179175{
    180     NSString *viewDescription = [super description];
    181     NSString *webKitDetails = [NSString stringWithFormat:@" layerID = %llu \"%@\"", WebKit::RemoteLayerTreeNode::layerID(self.layer), self.layer.name ? self.layer.name : @""];
    182     return [viewDescription stringByAppendingString:webKitDetails];
     176    return WebKit::RemoteLayerTreeNode::appendLayerDescription(super.description, self.layer);
    183177}
    184178
Note: See TracChangeset for help on using the changeset viewer.