Make GraphicsLayers ref-counted, so their tree can persist when disconnected from...
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Sep 2018 21:27:07 +0000 (21:27 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Sep 2018 21:27:07 +0000 (21:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=189521

Reviewed by Tim Horton.
Source/WebCore:

Make GraphicsLayer be RefCounted<GraphicsLayer>. GraphicsLayers own their children, via a Vector<Ref<GraphicsLayer>>.

RenderLayerBacking and other holders of GraphicsLayers use RefPtr<GraphicsLayer>.

All the other changes are just to adapt to the new ownership patterns.

I verified that no GraphicsLayers were leaked or abandoned after this change.

No behavior change.

* page/PageOverlayController.cpp:
(WebCore::PageOverlayController::layerWithDocumentOverlays):
(WebCore::PageOverlayController::layerWithViewOverlays):
(WebCore::PageOverlayController::installPageOverlay):
(WebCore::PageOverlayController::uninstallPageOverlay):
(WebCore::PageOverlayController::setPageOverlayNeedsDisplay):
(WebCore::PageOverlayController::didChangeViewSize):
(WebCore::PageOverlayController::didChangeDocumentSize):
(WebCore::PageOverlayController::didChangeSettings):
(WebCore::PageOverlayController::paintContents):
(WebCore::PageOverlayController::didChangeOverlayFrame):
(WebCore::PageOverlayController::didChangeOverlayBackgroundColor):
* page/PageOverlayController.h:
* page/mac/ServicesOverlayController.h:
(WebCore::ServicesOverlayController::Highlight::layer const):
* page/mac/ServicesOverlayController.mm:
(WebCore::ServicesOverlayController::Highlight::Highlight):
(WebCore::ServicesOverlayController::Highlight::invalidate):
(WebCore::ServicesOverlayController::Highlight::fadeIn):
(WebCore::ServicesOverlayController::Highlight::fadeOut):
(WebCore::ServicesOverlayController::Highlight::didFinishFadeOutAnimation):
(WebCore::ServicesOverlayController::determineActiveHighlight):
* platform/graphics/GraphicsLayer.cpp:
(WebCore::GraphicsLayer::GraphicsLayer):
(WebCore::GraphicsLayer::willBeDestroyed):
(WebCore::GraphicsLayer::setChildren):
(WebCore::GraphicsLayer::addChild):
(WebCore::GraphicsLayer::addChildAtIndex):
(WebCore::GraphicsLayer::addChildBelow):
(WebCore::GraphicsLayer::addChildAbove):
(WebCore::GraphicsLayer::replaceChild):
(WebCore::GraphicsLayer::removeAllChildren):
(WebCore::GraphicsLayer::removeFromParent):
(WebCore::GraphicsLayer::setMaskLayer):
(WebCore::GraphicsLayer::noteDeviceOrPageScaleFactorChangedIncludingDescendants):
(WebCore::GraphicsLayer::distributeOpacity):
(WebCore::GraphicsLayer::traverse):
(WebCore::dumpChildren):
* platform/graphics/GraphicsLayer.h:
(WebCore::GraphicsLayer::children const):
(WebCore::GraphicsLayer::children):
(WebCore::GraphicsLayer::maskLayer const):
(WebCore::GraphicsLayer::replicaLayer const):
(WebCore::GraphicsLayer::beingDestroyed const):
(WebCore::GraphicsLayer:: const): Deleted.
* platform/graphics/GraphicsLayerFactory.h:
* platform/graphics/ca/GraphicsLayerCA.cpp:
(WebCore::GraphicsLayer::create):
(WebCore::GraphicsLayerCA::setChildren):
(WebCore::GraphicsLayerCA::addChild):
(WebCore::GraphicsLayerCA::addChildAtIndex):
(WebCore::GraphicsLayerCA::addChildBelow):
(WebCore::GraphicsLayerCA::addChildAbove):
(WebCore::GraphicsLayerCA::replaceChild):
(WebCore::GraphicsLayerCA::setMaskLayer):
(WebCore::GraphicsLayerCA::recursiveVisibleRectChangeRequiresFlush const):
(WebCore::GraphicsLayerCA::recursiveCommitChanges):
(WebCore::GraphicsLayerCA::updateSublayerList):
(WebCore::GraphicsLayerCA::createTransformAnimationsFromKeyframes):
* platform/graphics/ca/GraphicsLayerCA.h:
* platform/graphics/texmap/GraphicsLayerTextureMapper.cpp:
(WebCore::GraphicsLayer::create):
(WebCore::GraphicsLayerTextureMapper::setChildren):
(WebCore::GraphicsLayerTextureMapper::addChild):
(WebCore::GraphicsLayerTextureMapper::addChildAtIndex):
(WebCore::GraphicsLayerTextureMapper::addChildAbove):
(WebCore::GraphicsLayerTextureMapper::addChildBelow):
(WebCore::GraphicsLayerTextureMapper::replaceChild):
(WebCore::GraphicsLayerTextureMapper::setMaskLayer):
(WebCore::GraphicsLayerTextureMapper::updateBackingStoreIncludingSubLayers):
* platform/graphics/texmap/GraphicsLayerTextureMapper.h:
* platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp:
(WebCore::GraphicsLayer::create):
(WebCore::CoordinatedGraphicsLayer::setShouldUpdateVisibleRect):
(WebCore::CoordinatedGraphicsLayer::addChild):
(WebCore::CoordinatedGraphicsLayer::addChildAtIndex):
(WebCore::CoordinatedGraphicsLayer::addChildAbove):
(WebCore::CoordinatedGraphicsLayer::addChildBelow):
(WebCore::CoordinatedGraphicsLayer::replaceChild):
(WebCore::CoordinatedGraphicsLayer::setMaskLayer):
(WebCore::CoordinatedGraphicsLayer::syncPendingStateChangesIncludingSubLayers):
(WebCore::CoordinatedGraphicsLayer::updateContentBuffersIncludingSubLayers):
(WebCore::CoordinatedGraphicsLayer::setCoordinatorIncludingSubLayersIfNeeded):
* platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.h:
* platform/graphics/win/GraphicsLayerDirect2D.cpp:
(WebCore::GraphicsLayer::create):
(WebCore::GraphicsLayerDirect2D::GraphicsLayerDirect2D): Deleted.
(WebCore::GraphicsLayerDirect2D::initialize): Deleted.
(WebCore::GraphicsLayerDirect2D::~GraphicsLayerDirect2D): Deleted.
(WebCore::GraphicsLayerDirect2D::setNeedsDisplay): Deleted.
(WebCore::GraphicsLayerDirect2D::setNeedsDisplayInRect): Deleted.
* rendering/RenderLayerBacking.cpp:
(WebCore::RenderLayerBacking::createGraphicsLayer):
(WebCore::RenderLayerBacking::createPrimaryGraphicsLayer):
(WebCore::RenderLayerBacking::updateConfiguration):
(WebCore::RenderLayerBacking::updateInternalHierarchy):
(WebCore::RenderLayerBacking::updateMaskingLayer):
(WebCore::RenderLayerBacking::updateChildClippingStrategy):
(WebCore::RenderLayerBacking::updateScrollingLayers):
* rendering/RenderLayerBacking.h:
* rendering/RenderLayerCompositor.cpp:
(WebCore::RenderLayerCompositor::updateCompositingLayers):
(WebCore::RenderLayerCompositor::appendDocumentOverlayLayers):
(WebCore::RenderLayerCompositor::setCompositingParent):
(WebCore::RenderLayerCompositor::rebuildCompositingLayerTree):
(WebCore::RenderLayerCompositor::parentFrameContentLayers):
(WebCore::RenderLayerCompositor::updateLayerForTopOverhangArea):
(WebCore::RenderLayerCompositor::updateLayerForBottomOverhangArea):
(WebCore::RenderLayerCompositor::updateLayerForHeader):
(WebCore::RenderLayerCompositor::updateLayerForFooter):
(WebCore::RenderLayerCompositor::updateOverflowControlsLayers):
(WebCore::RenderLayerCompositor::ensureRootLayer):
(WebCore::RenderLayerCompositor::rootLayerAttachmentChanged):
* rendering/RenderLayerCompositor.h:

Source/WebKit:

Make GraphicsLayer be RefCounted<GraphicsLayer>. GraphicsLayers own their children, via a Vector<Ref<GraphicsLayer>>.

RenderLayerBacking and other holders of GraphicsLayers use RefPtr<GraphicsLayer>.

All the other changes are just to adapt to the new ownership patterns.

I verified that no GraphicsLayers were leaked or abandoned after this change.

* WebProcess/WebCoreSupport/WebInspectorClient.cpp:
(WebKit::WebInspectorClient::~WebInspectorClient):
(WebKit::WebInspectorClient::showPaintRect):
(WebKit::WebInspectorClient::animationEndedForLayer):
* WebProcess/WebCoreSupport/WebInspectorClient.h:
* WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeContext.h:
* WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeContext.mm:
(WebKit::RemoteLayerTreeContext::createGraphicsLayer):
* WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.h:
* WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.mm:
(WebKit::RemoteLayerTreeDrawingArea::updateRootLayers):
(WebKit::RemoteLayerTreeDrawingArea::flushLayers):

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

34 files changed:
Source/WebCore/ChangeLog
Source/WebCore/page/PageOverlayController.cpp
Source/WebCore/page/PageOverlayController.h
Source/WebCore/page/ResourceUsageOverlay.h
Source/WebCore/page/linux/ResourceUsageOverlayLinux.cpp
Source/WebCore/page/mac/ServicesOverlayController.h
Source/WebCore/page/mac/ServicesOverlayController.mm
Source/WebCore/platform/graphics/GraphicsLayer.cpp
Source/WebCore/platform/graphics/GraphicsLayer.h
Source/WebCore/platform/graphics/GraphicsLayerFactory.h
Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp
Source/WebCore/platform/graphics/ca/GraphicsLayerCA.h
Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.cpp
Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.h
Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp
Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.h
Source/WebCore/platform/graphics/win/GraphicsLayerDirect2D.cpp
Source/WebCore/rendering/RenderLayerBacking.cpp
Source/WebCore/rendering/RenderLayerBacking.h
Source/WebCore/rendering/RenderLayerCompositor.cpp
Source/WebCore/rendering/RenderLayerCompositor.h
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/WebCoreSupport/WebInspectorClient.cpp
Source/WebKit/WebProcess/WebCoreSupport/WebInspectorClient.h
Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp
Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.h
Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeContext.h
Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeContext.mm
Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.h
Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.mm
Source/WebKitLegacy/win/WebCoreSupport/AcceleratedCompositingContext.cpp
Source/WebKitLegacy/win/WebCoreSupport/AcceleratedCompositingContext.h
Source/WebKitLegacy/win/WebView.cpp
Source/WebKitLegacy/win/WebView.h

index c953168..0f525f3 100644 (file)
@@ -1,3 +1,135 @@
+2018-09-11  Simon Fraser  <simon.fraser@apple.com>
+
+        Make GraphicsLayers ref-counted, so their tree can persist when disconnected from RenderLayerBackings
+        https://bugs.webkit.org/show_bug.cgi?id=189521
+
+        Reviewed by Tim Horton.
+        
+        Make GraphicsLayer be RefCounted<GraphicsLayer>. GraphicsLayers own their children, via a Vector<Ref<GraphicsLayer>>.
+        
+        RenderLayerBacking and other holders of GraphicsLayers use RefPtr<GraphicsLayer>.
+        
+        All the other changes are just to adapt to the new ownership patterns.
+        
+        I verified that no GraphicsLayers were leaked or abandoned after this change.
+
+        No behavior change.
+
+        * page/PageOverlayController.cpp:
+        (WebCore::PageOverlayController::layerWithDocumentOverlays):
+        (WebCore::PageOverlayController::layerWithViewOverlays):
+        (WebCore::PageOverlayController::installPageOverlay):
+        (WebCore::PageOverlayController::uninstallPageOverlay):
+        (WebCore::PageOverlayController::setPageOverlayNeedsDisplay):
+        (WebCore::PageOverlayController::didChangeViewSize):
+        (WebCore::PageOverlayController::didChangeDocumentSize):
+        (WebCore::PageOverlayController::didChangeSettings):
+        (WebCore::PageOverlayController::paintContents):
+        (WebCore::PageOverlayController::didChangeOverlayFrame):
+        (WebCore::PageOverlayController::didChangeOverlayBackgroundColor):
+        * page/PageOverlayController.h:
+        * page/mac/ServicesOverlayController.h:
+        (WebCore::ServicesOverlayController::Highlight::layer const):
+        * page/mac/ServicesOverlayController.mm:
+        (WebCore::ServicesOverlayController::Highlight::Highlight):
+        (WebCore::ServicesOverlayController::Highlight::invalidate):
+        (WebCore::ServicesOverlayController::Highlight::fadeIn):
+        (WebCore::ServicesOverlayController::Highlight::fadeOut):
+        (WebCore::ServicesOverlayController::Highlight::didFinishFadeOutAnimation):
+        (WebCore::ServicesOverlayController::determineActiveHighlight):
+        * platform/graphics/GraphicsLayer.cpp:
+        (WebCore::GraphicsLayer::GraphicsLayer):
+        (WebCore::GraphicsLayer::willBeDestroyed):
+        (WebCore::GraphicsLayer::setChildren):
+        (WebCore::GraphicsLayer::addChild):
+        (WebCore::GraphicsLayer::addChildAtIndex):
+        (WebCore::GraphicsLayer::addChildBelow):
+        (WebCore::GraphicsLayer::addChildAbove):
+        (WebCore::GraphicsLayer::replaceChild):
+        (WebCore::GraphicsLayer::removeAllChildren):
+        (WebCore::GraphicsLayer::removeFromParent):
+        (WebCore::GraphicsLayer::setMaskLayer):
+        (WebCore::GraphicsLayer::noteDeviceOrPageScaleFactorChangedIncludingDescendants):
+        (WebCore::GraphicsLayer::distributeOpacity):
+        (WebCore::GraphicsLayer::traverse):
+        (WebCore::dumpChildren):
+        * platform/graphics/GraphicsLayer.h:
+        (WebCore::GraphicsLayer::children const):
+        (WebCore::GraphicsLayer::children):
+        (WebCore::GraphicsLayer::maskLayer const):
+        (WebCore::GraphicsLayer::replicaLayer const):
+        (WebCore::GraphicsLayer::beingDestroyed const):
+        (WebCore::GraphicsLayer:: const): Deleted.
+        * platform/graphics/GraphicsLayerFactory.h:
+        * platform/graphics/ca/GraphicsLayerCA.cpp:
+        (WebCore::GraphicsLayer::create):
+        (WebCore::GraphicsLayerCA::setChildren):
+        (WebCore::GraphicsLayerCA::addChild):
+        (WebCore::GraphicsLayerCA::addChildAtIndex):
+        (WebCore::GraphicsLayerCA::addChildBelow):
+        (WebCore::GraphicsLayerCA::addChildAbove):
+        (WebCore::GraphicsLayerCA::replaceChild):
+        (WebCore::GraphicsLayerCA::setMaskLayer):
+        (WebCore::GraphicsLayerCA::recursiveVisibleRectChangeRequiresFlush const):
+        (WebCore::GraphicsLayerCA::recursiveCommitChanges):
+        (WebCore::GraphicsLayerCA::updateSublayerList):
+        (WebCore::GraphicsLayerCA::createTransformAnimationsFromKeyframes):
+        * platform/graphics/ca/GraphicsLayerCA.h:
+        * platform/graphics/texmap/GraphicsLayerTextureMapper.cpp:
+        (WebCore::GraphicsLayer::create):
+        (WebCore::GraphicsLayerTextureMapper::setChildren):
+        (WebCore::GraphicsLayerTextureMapper::addChild):
+        (WebCore::GraphicsLayerTextureMapper::addChildAtIndex):
+        (WebCore::GraphicsLayerTextureMapper::addChildAbove):
+        (WebCore::GraphicsLayerTextureMapper::addChildBelow):
+        (WebCore::GraphicsLayerTextureMapper::replaceChild):
+        (WebCore::GraphicsLayerTextureMapper::setMaskLayer):
+        (WebCore::GraphicsLayerTextureMapper::updateBackingStoreIncludingSubLayers):
+        * platform/graphics/texmap/GraphicsLayerTextureMapper.h:
+        * platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp:
+        (WebCore::GraphicsLayer::create):
+        (WebCore::CoordinatedGraphicsLayer::setShouldUpdateVisibleRect):
+        (WebCore::CoordinatedGraphicsLayer::addChild):
+        (WebCore::CoordinatedGraphicsLayer::addChildAtIndex):
+        (WebCore::CoordinatedGraphicsLayer::addChildAbove):
+        (WebCore::CoordinatedGraphicsLayer::addChildBelow):
+        (WebCore::CoordinatedGraphicsLayer::replaceChild):
+        (WebCore::CoordinatedGraphicsLayer::setMaskLayer):
+        (WebCore::CoordinatedGraphicsLayer::syncPendingStateChangesIncludingSubLayers):
+        (WebCore::CoordinatedGraphicsLayer::updateContentBuffersIncludingSubLayers):
+        (WebCore::CoordinatedGraphicsLayer::setCoordinatorIncludingSubLayersIfNeeded):
+        * platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.h:
+        * platform/graphics/win/GraphicsLayerDirect2D.cpp:
+        (WebCore::GraphicsLayer::create):
+        (WebCore::GraphicsLayerDirect2D::GraphicsLayerDirect2D): Deleted.
+        (WebCore::GraphicsLayerDirect2D::initialize): Deleted.
+        (WebCore::GraphicsLayerDirect2D::~GraphicsLayerDirect2D): Deleted.
+        (WebCore::GraphicsLayerDirect2D::setNeedsDisplay): Deleted.
+        (WebCore::GraphicsLayerDirect2D::setNeedsDisplayInRect): Deleted.
+        * rendering/RenderLayerBacking.cpp:
+        (WebCore::RenderLayerBacking::createGraphicsLayer):
+        (WebCore::RenderLayerBacking::createPrimaryGraphicsLayer):
+        (WebCore::RenderLayerBacking::updateConfiguration):
+        (WebCore::RenderLayerBacking::updateInternalHierarchy):
+        (WebCore::RenderLayerBacking::updateMaskingLayer):
+        (WebCore::RenderLayerBacking::updateChildClippingStrategy):
+        (WebCore::RenderLayerBacking::updateScrollingLayers):
+        * rendering/RenderLayerBacking.h:
+        * rendering/RenderLayerCompositor.cpp:
+        (WebCore::RenderLayerCompositor::updateCompositingLayers):
+        (WebCore::RenderLayerCompositor::appendDocumentOverlayLayers):
+        (WebCore::RenderLayerCompositor::setCompositingParent):
+        (WebCore::RenderLayerCompositor::rebuildCompositingLayerTree):
+        (WebCore::RenderLayerCompositor::parentFrameContentLayers):
+        (WebCore::RenderLayerCompositor::updateLayerForTopOverhangArea):
+        (WebCore::RenderLayerCompositor::updateLayerForBottomOverhangArea):
+        (WebCore::RenderLayerCompositor::updateLayerForHeader):
+        (WebCore::RenderLayerCompositor::updateLayerForFooter):
+        (WebCore::RenderLayerCompositor::updateOverflowControlsLayers):
+        (WebCore::RenderLayerCompositor::ensureRootLayer):
+        (WebCore::RenderLayerCompositor::rootLayerAttachmentChanged):
+        * rendering/RenderLayerCompositor.h:
+
 2018-09-12  Alex Christensen  <achristensen@webkit.org>
 
         Expose fewer of URL's internal members
index 4856ff6..77936c2 100644 (file)
@@ -43,8 +43,7 @@
 namespace WebCore {
 
 PageOverlayController::PageOverlayController(Page& page)
-    : m_initialized(false)
-    , m_page(page)
+    :  m_page(page)
 {
 }
 
@@ -98,14 +97,14 @@ GraphicsLayer& PageOverlayController::layerWithDocumentOverlays()
         if (overlay.overlayType() != PageOverlay::OverlayType::Document)
             continue;
 
-        GraphicsLayer& layer = *overlayAndLayer.value;
-        GraphicsLayer::traverse(layer, [inWindow](GraphicsLayer& layer) {
+        auto& layer = overlayAndLayer.value;
+        GraphicsLayer::traverse(layer.get(), [inWindow](GraphicsLayer& layer) {
             layer.setIsInWindow(inWindow);
         });
-        updateOverlayGeometry(overlay, layer);
+        updateOverlayGeometry(overlay, layer.get());
         
-        if (!layer.parent())
-            m_documentOverlayRootLayer->addChild(&layer);
+        if (!layer->parent())
+            m_documentOverlayRootLayer->addChild(layer.copyRef());
     }
 
     return *m_documentOverlayRootLayer;
@@ -122,14 +121,14 @@ GraphicsLayer& PageOverlayController::layerWithViewOverlays()
         if (overlay.overlayType() != PageOverlay::OverlayType::View)
             continue;
 
-        GraphicsLayer& layer = *overlayAndLayer.value;
-        GraphicsLayer::traverse(layer, [inWindow](GraphicsLayer& layer) {
+        auto& layer = overlayAndLayer.value;
+        GraphicsLayer::traverse(layer.get(), [inWindow](GraphicsLayer& layer) {
             layer.setIsInWindow(inWindow);
         });
-        updateOverlayGeometry(overlay, layer);
+        updateOverlayGeometry(overlay, layer.get());
         
-        if (!layer.parent())
-            m_viewOverlayRootLayer->addChild(&layer);
+        if (!layer->parent())
+            m_viewOverlayRootLayer->addChild(layer.copyRef());
     }
 
     return *m_viewOverlayRootLayer;
@@ -144,12 +143,12 @@ void PageOverlayController::installPageOverlay(PageOverlay& overlay, PageOverlay
 
     m_pageOverlays.append(&overlay);
 
-    std::unique_ptr<GraphicsLayer> layer = GraphicsLayer::create(m_page.chrome().client().graphicsLayerFactory(), *this);
+    auto layer = GraphicsLayer::create(m_page.chrome().client().graphicsLayerFactory(), *this);
     layer->setAnchorPoint(FloatPoint3D());
     layer->setBackgroundColor(overlay.backgroundColor());
     layer->setName("Overlay content");
 
-    updateSettingsForLayer(*layer);
+    updateSettingsForLayer(layer.get());
 
     switch (overlay.overlayType()) {
     case PageOverlay::OverlayType::View:
@@ -160,7 +159,7 @@ void PageOverlayController::installPageOverlay(PageOverlay& overlay, PageOverlay
         break;
     }
 
-    GraphicsLayer& rawLayer = *layer;
+    auto& rawLayer = layer.get();
     m_overlayGraphicsLayers.set(&overlay, WTFMove(layer));
 
     updateForceSynchronousScrollLayerPositionUpdates();
@@ -185,7 +184,8 @@ void PageOverlayController::uninstallPageOverlay(PageOverlay& overlay, PageOverl
 
     overlay.setPage(nullptr);
 
-    m_overlayGraphicsLayers.take(&overlay)->removeFromParent();
+    if (auto optionalLayer = m_overlayGraphicsLayers.take(&overlay))
+        optionalLayer.value()->removeFromParent();
 
     bool removed = m_pageOverlays.removeFirst(&overlay);
     ASSERT_UNUSED(removed, removed);
@@ -211,14 +211,14 @@ void PageOverlayController::updateForceSynchronousScrollLayerPositionUpdates()
 void PageOverlayController::setPageOverlayNeedsDisplay(PageOverlay& overlay, const WebCore::IntRect& dirtyRect)
 {
     ASSERT(m_pageOverlays.contains(&overlay));
-    GraphicsLayer& graphicsLayer = *m_overlayGraphicsLayers.get(&overlay);
+    auto* graphicsLayer = m_overlayGraphicsLayers.get(&overlay);
 
-    if (!graphicsLayer.drawsContent()) {
-        graphicsLayer.setDrawsContent(true);
-        updateOverlayGeometry(overlay, graphicsLayer);
+    if (!graphicsLayer->drawsContent()) {
+        graphicsLayer->setDrawsContent(true);
+        updateOverlayGeometry(overlay, *graphicsLayer);
     }
 
-    graphicsLayer.setNeedsDisplayInRect(dirtyRect);
+    graphicsLayer->setNeedsDisplayInRect(dirtyRect);
 }
 
 void PageOverlayController::setPageOverlayOpacity(PageOverlay& overlay, float opacity)
@@ -241,8 +241,15 @@ GraphicsLayer& PageOverlayController::layerForOverlay(PageOverlay& overlay) cons
 
 void PageOverlayController::willDetachRootLayer()
 {
-    m_documentOverlayRootLayer = nullptr;
-    m_viewOverlayRootLayer = nullptr;
+    if (m_documentOverlayRootLayer) {
+        m_documentOverlayRootLayer->removeFromParent();
+        m_documentOverlayRootLayer = nullptr;
+    }
+
+    if (m_viewOverlayRootLayer) {
+        m_viewOverlayRootLayer->removeFromParent();
+        m_viewOverlayRootLayer = nullptr;
+    }
     m_initialized = false;
 }
 
@@ -250,7 +257,7 @@ void PageOverlayController::didChangeViewSize()
 {
     for (auto& overlayAndLayer : m_overlayGraphicsLayers) {
         if (overlayAndLayer.key->overlayType() == PageOverlay::OverlayType::View)
-            updateOverlayGeometry(*overlayAndLayer.key, *overlayAndLayer.value);
+            updateOverlayGeometry(*overlayAndLayer.key, overlayAndLayer.value.get());
     }
 }
 
@@ -258,7 +265,7 @@ void PageOverlayController::didChangeDocumentSize()
 {
     for (auto& overlayAndLayer : m_overlayGraphicsLayers) {
         if (overlayAndLayer.key->overlayType() == PageOverlay::OverlayType::Document)
-            updateOverlayGeometry(*overlayAndLayer.key, *overlayAndLayer.value);
+            updateOverlayGeometry(*overlayAndLayer.key, overlayAndLayer.value.get());
     }
 }
 
@@ -266,7 +273,7 @@ void PageOverlayController::didChangeSettings()
 {
     // FIXME: We should apply these settings to all overlay sublayers recursively.
     for (auto& graphicsLayer : m_overlayGraphicsLayers.values())
-        updateSettingsForLayer(*graphicsLayer);
+        updateSettingsForLayer(graphicsLayer.get());
 }
 
 void PageOverlayController::didChangeDeviceScaleFactor()
@@ -359,7 +366,7 @@ Vector<String> PageOverlayController::copyAccessibilityAttributesNames(bool para
 void PageOverlayController::paintContents(const WebCore::GraphicsLayer* graphicsLayer, WebCore::GraphicsContext& graphicsContext, WebCore::GraphicsLayerPaintingPhase, const WebCore::FloatRect& clipRect, GraphicsLayerPaintBehavior)
 {
     for (auto& overlayAndGraphicsLayer : m_overlayGraphicsLayers) {
-        if (overlayAndGraphicsLayer.value.get() != graphicsLayer)
+        if (overlayAndGraphicsLayer.value.ptr() != graphicsLayer)
             continue;
 
         GraphicsContextStateSaver stateSaver(graphicsContext);
@@ -383,13 +390,15 @@ void PageOverlayController::notifyFlushRequired(const WebCore::GraphicsLayer*)
 void PageOverlayController::didChangeOverlayFrame(PageOverlay& overlay)
 {
     ASSERT(m_pageOverlays.contains(&overlay));
-    updateOverlayGeometry(overlay, *m_overlayGraphicsLayers.get(&overlay));
+    if (auto* layer = m_overlayGraphicsLayers.get(&overlay))
+        updateOverlayGeometry(overlay, *layer);
 }
 
 void PageOverlayController::didChangeOverlayBackgroundColor(PageOverlay& overlay)
 {
     ASSERT(m_pageOverlays.contains(&overlay));
-    m_overlayGraphicsLayers.get(&overlay)->setBackgroundColor(overlay.backgroundColor());
+    if (auto* layer = m_overlayGraphicsLayers.get(&overlay))
+        layer->setBackgroundColor(overlay.backgroundColor());
 }
 
 bool PageOverlayController::shouldSkipLayerInDump(const GraphicsLayer*, LayerTreeAsTextBehavior behavior) const
index 763a7e2..82f7368 100644 (file)
@@ -92,13 +92,13 @@ private:
     bool shouldSkipLayerInDump(const GraphicsLayer*, LayerTreeAsTextBehavior) const override;
     void tiledBackingUsageChanged(const GraphicsLayer*, bool) override;
 
-    std::unique_ptr<GraphicsLayer> m_documentOverlayRootLayer;
-    std::unique_ptr<GraphicsLayer> m_viewOverlayRootLayer;
-    bool m_initialized;
+    Page& m_page;
+    RefPtr<GraphicsLayer> m_documentOverlayRootLayer;
+    RefPtr<GraphicsLayer> m_viewOverlayRootLayer;
 
-    HashMap<PageOverlay*, std::unique_ptr<GraphicsLayer>> m_overlayGraphicsLayers;
+    HashMap<PageOverlay*, Ref<GraphicsLayer>> m_overlayGraphicsLayers;
     Vector<RefPtr<PageOverlay>> m_pageOverlays;
-    Page& m_page;
+    bool m_initialized { false };
 };
 
 } // namespace WebKit
index 16aea60..780b6aa 100644 (file)
@@ -83,7 +83,7 @@ private:
 #endif
 
 #if OS(LINUX)
-    std::unique_ptr<GraphicsLayer> m_paintLayer;
+    RefPtr<GraphicsLayer> m_paintLayer;
     std::unique_ptr<GraphicsLayerClient> m_overlayPainter;
 #endif
 };
index 13d9ca2..c3c87fd 100644 (file)
@@ -137,7 +137,7 @@ void ResourceUsageOverlay::platformInitialize()
     m_paintLayer->setSize({ normalWidth, normalHeight });
     m_paintLayer->setBackgroundColor(Color(0.0f, 0.0f, 0.0f, 0.8f));
     m_paintLayer->setDrawsContent(true);
-    overlay().layer().addChild(m_paintLayer.get());
+    overlay().layer().addChild(*m_paintLayer);
 
     ResourceUsageThread::addObserver(this, [this] (const ResourceUsageData& data) {
         gData = data;
index fad43a8..8f8a5fb 100644 (file)
@@ -63,7 +63,7 @@ private:
 
         DDHighlightRef ddHighlight() const { return m_ddHighlight.get(); }
         Range& range() const { return m_range.get(); }
-        GraphicsLayer* layer() const { return m_graphicsLayer.get(); }
+        GraphicsLayer& layer() const { return m_graphicsLayer.get(); }
 
         enum {
             TelephoneNumberType = 1 << 0,
@@ -87,11 +87,11 @@ private:
 
         void didFinishFadeOutAnimation();
 
+        ServicesOverlayController* m_controller;
         RetainPtr<DDHighlightRef> m_ddHighlight;
         Ref<Range> m_range;
-        std::unique_ptr<GraphicsLayer> m_graphicsLayer;
+        Ref<GraphicsLayer> m_graphicsLayer;
         Type m_type;
-        ServicesOverlayController* m_controller;
     };
 
     // PageOverlay::Client
index 9c44b86..f3409fa 100644 (file)
@@ -66,21 +66,20 @@ Ref<ServicesOverlayController::Highlight> ServicesOverlayController::Highlight::
 }
 
 ServicesOverlayController::Highlight::Highlight(ServicesOverlayController& controller, Type type, RetainPtr<DDHighlightRef> ddHighlight, Ref<WebCore::Range>&& range)
-    : m_range(WTFMove(range))
+    : m_controller(&controller)
+    , m_range(WTFMove(range))
+    , m_graphicsLayer(GraphicsLayer::create(controller.page().chrome().client().graphicsLayerFactory(), *this))
     , m_type(type)
-    , m_controller(&controller)
 {
     ASSERT(ddHighlight);
 
-    auto& page = controller.page();
-    m_graphicsLayer = GraphicsLayer::create(page.chrome().client().graphicsLayerFactory(), *this);
     m_graphicsLayer->setDrawsContent(true);
 
     setDDHighlight(ddHighlight.get());
 
     // Set directly on the PlatformCALayer so that when we leave the 'from' value implicit
     // in our animations, we get the right initial value regardless of flush timing.
-    downcast<GraphicsLayerCA>(*layer()).platformCALayer()->setOpacity(0);
+    downcast<GraphicsLayerCA>(layer()).platformCALayer()->setOpacity(0);
 
     controller.didCreateHighlight(this);
 }
@@ -113,7 +112,7 @@ void ServicesOverlayController::Highlight::setDDHighlight(DDHighlightRef highlig
 
 void ServicesOverlayController::Highlight::invalidate()
 {
-    layer()->removeFromParent();
+    layer().removeFromParent();
     m_controller = nullptr;
 }
 
@@ -158,7 +157,7 @@ void ServicesOverlayController::Highlight::fadeIn()
     [animation setToValue:@1];
 
     RefPtr<PlatformCAAnimation> platformAnimation = PlatformCAAnimationCocoa::create(animation.get());
-    downcast<GraphicsLayerCA>(*layer()).platformCALayer()->addAnimationForKey("FadeHighlightIn", *platformAnimation);
+    downcast<GraphicsLayerCA>(layer()).platformCALayer()->addAnimationForKey("FadeHighlightIn", *platformAnimation);
 }
 
 void ServicesOverlayController::Highlight::fadeOut()
@@ -176,7 +175,7 @@ void ServicesOverlayController::Highlight::fadeOut()
     }];
 
     RefPtr<PlatformCAAnimation> platformAnimation = PlatformCAAnimationCocoa::create(animation.get());
-    downcast<GraphicsLayerCA>(*layer()).platformCALayer()->addAnimationForKey("FadeHighlightOut", *platformAnimation);
+    downcast<GraphicsLayerCA>(layer()).platformCALayer()->addAnimationForKey("FadeHighlightOut", *platformAnimation);
     [CATransaction commit];
 }
 
@@ -188,7 +187,7 @@ void ServicesOverlayController::Highlight::didFinishFadeOutAnimation()
     if (m_controller->activeHighlight() == this)
         return;
 
-    layer()->removeFromParent();
+    layer().removeFromParent();
 }
 
 static IntRect textQuadsToBoundingRectForRange(Range& range)
@@ -714,7 +713,8 @@ void ServicesOverlayController::determineActiveHighlight(bool& mouseIsOverActive
         m_activeHighlight = WTFMove(m_nextActiveHighlight);
 
         if (m_activeHighlight) {
-            m_servicesOverlay->layer().addChild(m_activeHighlight->layer());
+            Ref<GraphicsLayer> highlightLayer = m_activeHighlight->layer();
+            m_servicesOverlay->layer().addChild(WTFMove(highlightLayer));
             m_activeHighlight->fadeIn();
         }
     }
index 4ed3609..62acc8b 100644 (file)
@@ -113,6 +113,7 @@ bool GraphicsLayer::supportsContentsTiling()
 GraphicsLayer::GraphicsLayer(Type type, GraphicsLayerClient& client)
     : m_client(client)
     , m_type(type)
+    , m_beingDestroyed(false)
     , m_contentsOpaque(false)
     , m_supportsSubpixelAntialiasedText(false)
     , m_preserves3D(false)
@@ -143,6 +144,7 @@ GraphicsLayer::~GraphicsLayer()
 
 void GraphicsLayer::willBeDestroyed()
 {
+    m_beingDestroyed = true;
 #ifndef NDEBUG
     m_client.verifyNotPainting();
 #endif
@@ -177,99 +179,96 @@ bool GraphicsLayer::hasAncestor(GraphicsLayer* ancestor) const
     return false;
 }
 
-bool GraphicsLayer::setChildren(const Vector<GraphicsLayer*>& newChildren)
+bool GraphicsLayer::setChildren(Vector<Ref<GraphicsLayer>>&& newChildren)
 {
     // If the contents of the arrays are the same, nothing to do.
     if (newChildren == m_children)
         return false;
 
     removeAllChildren();
-    
+
     size_t listSize = newChildren.size();
     for (size_t i = 0; i < listSize; ++i)
-        addChild(newChildren[i]);
+        addChild(WTFMove(newChildren[i]));
     
     return true;
 }
 
-void GraphicsLayer::addChild(GraphicsLayer* childLayer)
+void GraphicsLayer::addChild(Ref<GraphicsLayer>&& childLayer)
 {
-    ASSERT(childLayer != this);
+    ASSERT(childLayer.ptr() != this);
     
     if (childLayer->parent())
         childLayer->removeFromParent();
 
     childLayer->setParent(this);
-    m_children.append(childLayer);
+    m_children.append(WTFMove(childLayer));
 }
 
-void GraphicsLayer::addChildAtIndex(GraphicsLayer* childLayer, int index)
+void GraphicsLayer::addChildAtIndex(Ref<GraphicsLayer>&& childLayer, int index)
 {
-    ASSERT(childLayer != this);
+    ASSERT(childLayer.ptr() != this);
 
     if (childLayer->parent())
         childLayer->removeFromParent();
 
     childLayer->setParent(this);
-    m_children.insert(index, childLayer);
+    m_children.insert(index, WTFMove(childLayer));
 }
 
-void GraphicsLayer::addChildBelow(GraphicsLayer* childLayer, GraphicsLayer* sibling)
+void GraphicsLayer::addChildBelow(Ref<GraphicsLayer>&& childLayer, GraphicsLayer* sibling)
 {
-    ASSERT(childLayer != this);
+    ASSERT(childLayer.ptr() != this);
     childLayer->removeFromParent();
 
-    bool found = false;
+    childLayer->setParent(this);
+
     for (unsigned i = 0; i < m_children.size(); i++) {
-        if (sibling == m_children[i]) {
-            m_children.insert(i, childLayer);
-            found = true;
-            break;
+        if (sibling == m_children[i].ptr()) {
+            m_children.insert(i, WTFMove(childLayer));
+            return;
         }
     }
 
-    childLayer->setParent(this);
-
-    if (!found)
-        m_children.append(childLayer);
+    m_children.append(WTFMove(childLayer));
 }
 
-void GraphicsLayer::addChildAbove(GraphicsLayer* childLayer, GraphicsLayer* sibling)
+void GraphicsLayer::addChildAbove(Ref<GraphicsLayer>&& childLayer, GraphicsLayer* sibling)
 {
     childLayer->removeFromParent();
-    ASSERT(childLayer != this);
+    ASSERT(childLayer.ptr() != this);
+
+    childLayer->setParent(this);
 
-    bool found = false;
     for (unsigned i = 0; i < m_children.size(); i++) {
-        if (sibling == m_children[i]) {
-            m_children.insert(i+1, childLayer);
-            found = true;
-            break;
+        if (sibling == m_children[i].ptr()) {
+            m_children.insert(i + 1, WTFMove(childLayer));
+            return;
         }
     }
 
-    childLayer->setParent(this);
-
-    if (!found)
-        m_children.append(childLayer);
+    m_children.append(WTFMove(childLayer));
 }
 
-bool GraphicsLayer::replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild)
+bool GraphicsLayer::replaceChild(GraphicsLayer* oldChild, Ref<GraphicsLayer>&& newChild)
 {
     ASSERT(!newChild->parent());
+    
+    GraphicsLayer* rawNewChild = newChild.ptr();
+
     bool found = false;
     for (unsigned i = 0; i < m_children.size(); i++) {
-        if (oldChild == m_children[i]) {
-            m_children[i] = newChild;
+        if (oldChild == m_children[i].ptr()) {
+            m_children[i] = WTFMove(newChild);
             found = true;
             break;
         }
     }
     if (found) {
-        oldChild->setParent(0);
+        oldChild->setParent(nullptr);
 
-        newChild->removeFromParent();
-        newChild->setParent(this);
+        rawNewChild->removeFromParent();
+        rawNewChild->setParent(this);
         return true;
     }
     return false;
@@ -278,17 +277,22 @@ bool GraphicsLayer::replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChil
 void GraphicsLayer::removeAllChildren()
 {
     while (m_children.size()) {
-        GraphicsLayer* curLayer = m_children[0];
+        GraphicsLayer* curLayer = m_children[0].ptr();
         ASSERT(curLayer->parent());
         curLayer->removeFromParent();
+        // curLayer may be destroyed here.
     }
 }
 
 void GraphicsLayer::removeFromParent()
 {
     if (m_parent) {
-        m_parent->m_children.removeFirst(this);
+        GraphicsLayer* parent = m_parent;
         setParent(nullptr);
+        parent->m_children.removeFirstMatching([this](auto& layer) {
+            return layer.ptr() == this;
+        });
+        // |this| may be destroyed here.
     }
 }
 
@@ -318,7 +322,7 @@ void GraphicsLayer::setChildrenTransform(const TransformationMatrix& matrix)
         m_childrenTransform = std::make_unique<TransformationMatrix>(matrix);
 }
 
-void GraphicsLayer::setMaskLayer(GraphicsLayer* layer)
+void GraphicsLayer::setMaskLayer(RefPtr<GraphicsLayer>&& layer)
 {
     if (layer == m_maskLayer)
         return;
@@ -332,7 +336,7 @@ void GraphicsLayer::setMaskLayer(GraphicsLayer* layer)
         m_maskLayer->setIsMaskLayer(false);
     }
     
-    m_maskLayer = layer;
+    m_maskLayer = WTFMove(layer);
 }
 
 Path GraphicsLayer::shapeLayerPath() const
@@ -381,10 +385,8 @@ void GraphicsLayer::noteDeviceOrPageScaleFactorChangedIncludingDescendants()
     if (m_replicaLayer)
         m_replicaLayer->noteDeviceOrPageScaleFactorChangedIncludingDescendants();
 
-    const Vector<GraphicsLayer*>& childLayers = children();
-    size_t numChildren = childLayers.size();
-    for (size_t i = 0; i < numChildren; ++i)
-        childLayers[i]->noteDeviceOrPageScaleFactorChangedIncludingDescendants();
+    for (auto& layer : children())
+        layer->noteDeviceOrPageScaleFactorChangedIncludingDescendants();
 }
 
 void GraphicsLayer::setIsInWindow(bool inWindow)
@@ -534,9 +536,8 @@ void GraphicsLayer::distributeOpacity(float accumulatedOpacity)
     setOpacityInternal(accumulatedOpacity);
     
     if (preserves3D()) {
-        size_t numChildren = children().size();
-        for (size_t i = 0; i < numChildren; ++i)
-            children()[i]->distributeOpacity(accumulatedOpacity);
+        for (auto& layer : children())
+            layer->distributeOpacity(accumulatedOpacity);
     }
 }
 
@@ -693,8 +694,8 @@ void GraphicsLayer::traverse(GraphicsLayer& layer, const WTF::Function<void (Gra
 {
     traversalFunc(layer);
 
-    for (auto* childLayer : layer.children())
-        traverse(*childLayer, traversalFunc);
+    for (auto& childLayer : layer.children())
+        traverse(childLayer.get(), traversalFunc);
 
     if (auto* replicaLayer = layer.replicaLayer())
         traverse(*replicaLayer, traversalFunc);
@@ -717,11 +718,11 @@ void GraphicsLayer::dumpLayer(TextStream& ts, LayerTreeAsTextBehavior behavior)
     ts << indent << ")\n";
 }
 
-static void dumpChildren(TextStream& ts, const Vector<GraphicsLayer*>& children, unsigned& totalChildCount, LayerTreeAsTextBehavior behavior)
+static void dumpChildren(TextStream& ts, const Vector<Ref<GraphicsLayer>>& children, unsigned& totalChildCount, LayerTreeAsTextBehavior behavior)
 {
     totalChildCount += children.size();
-    for (auto* child : children) {
-        if ((behavior & LayerTreeAsTextDebug) || !child->client().shouldSkipLayerInDump(child, behavior)) {
+    for (auto& child : children) {
+        if ((behavior & LayerTreeAsTextDebug) || !child->client().shouldSkipLayerInDump(child.ptr(), behavior)) {
             TextStream::IndentScope indentScope(ts);
             child->dumpLayer(ts, behavior);
             continue;
index 202409b..38adf19 100644 (file)
@@ -230,8 +230,8 @@ protected:
 // GraphicsLayer is an abstraction for a rendering surface with backing store,
 // which may have associated transformation and animations.
 
-class GraphicsLayer {
-    WTF_MAKE_NONCOPYABLE(GraphicsLayer); WTF_MAKE_FAST_ALLOCATED;
+class GraphicsLayer : public RefCounted<GraphicsLayer> {
+    WTF_MAKE_FAST_ALLOCATED;
 public:
     enum class Type : uint8_t {
         Normal,
@@ -239,8 +239,8 @@ public:
         Scrolling,
         Shape
     };
-    
-    WEBCORE_EXPORT static std::unique_ptr<GraphicsLayer> create(GraphicsLayerFactory*, GraphicsLayerClient&, Type = Type::Normal);
+
+    WEBCORE_EXPORT static Ref<GraphicsLayer> create(GraphicsLayerFactory*, GraphicsLayerClient&, Type = Type::Normal);
     
     WEBCORE_EXPORT virtual ~GraphicsLayer();
     
@@ -263,32 +263,25 @@ public:
     // Returns true if the layer has the given layer as an ancestor (excluding self).
     bool hasAncestor(GraphicsLayer*) const;
     
-    const Vector<GraphicsLayer*>& children() const { return m_children; }
-    // Returns true if the child list changed.
-    WEBCORE_EXPORT virtual bool setChildren(const Vector<GraphicsLayer*>&);
+    const Vector<Ref<GraphicsLayer>>& children() const { return m_children; }
+    Vector<Ref<GraphicsLayer>>& children() { return m_children; }
 
-    enum class ContentsLayerPurpose : uint8_t {
-        None = 0,
-        Image,
-        Media,
-        Canvas,
-        BackgroundColor,
-        Plugin
-    };
+    // Returns true if the child list changed.
+    WEBCORE_EXPORT virtual bool setChildren(Vector<Ref<GraphicsLayer>>&&);
 
     // Add child layers. If the child is already parented, it will be removed from its old parent.
-    WEBCORE_EXPORT virtual void addChild(GraphicsLayer*);
-    WEBCORE_EXPORT virtual void addChildAtIndex(GraphicsLayer*, int index);
-    WEBCORE_EXPORT virtual void addChildAbove(GraphicsLayer*, GraphicsLayer* sibling);
-    WEBCORE_EXPORT virtual void addChildBelow(GraphicsLayer*, GraphicsLayer* sibling);
-    WEBCORE_EXPORT virtual bool replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild);
+    WEBCORE_EXPORT virtual void addChild(Ref<GraphicsLayer>&&);
+    WEBCORE_EXPORT virtual void addChildAtIndex(Ref<GraphicsLayer>&&, int index);
+    WEBCORE_EXPORT virtual void addChildAbove(Ref<GraphicsLayer>&&, GraphicsLayer* sibling);
+    WEBCORE_EXPORT virtual void addChildBelow(Ref<GraphicsLayer>&&, GraphicsLayer* sibling);
+    WEBCORE_EXPORT virtual bool replaceChild(GraphicsLayer* oldChild, Ref<GraphicsLayer>&& newChild);
 
     WEBCORE_EXPORT void removeAllChildren();
     WEBCORE_EXPORT virtual void removeFromParent();
 
     // The parent() of a maskLayer is set to the layer being masked.
-    GraphicsLayer* maskLayer() const { return m_maskLayer; }
-    virtual void setMaskLayer(GraphicsLayer*);
+    GraphicsLayer* maskLayer() const { return m_maskLayer.get(); }
+    virtual void setMaskLayer(RefPtr<GraphicsLayer>&&);
 
     void setIsMaskLayer(bool isMask) { m_isMaskLayer = isMask; }
     bool isMaskLayer() const { return m_isMaskLayer; }
@@ -298,7 +291,7 @@ public:
     // Whether this layer is being replicated by another layer.
     bool isReplicated() const { return m_replicaLayer; }
     // The layer that replicates this layer (if any).
-    GraphicsLayer* replicaLayer() const { return m_replicaLayer; }
+    GraphicsLayer* replicaLayer() const { return m_replicaLayer.get(); }
 
     const FloatPoint& replicatedLayerPosition() const { return m_replicatedLayerPosition; }
     void setReplicatedLayerPosition(const FloatPoint& p) { m_replicatedLayerPosition = p; }
@@ -466,6 +459,16 @@ public:
 #if PLATFORM(IOS)
     virtual PlatformLayer* contentsLayerForMedia() const { return 0; }
 #endif
+
+    enum class ContentsLayerPurpose : uint8_t {
+        None = 0,
+        Image,
+        Media,
+        Canvas,
+        BackgroundColor,
+        Plugin
+    };
+
     // Pass an invalid color to remove the contents layer.
     virtual void setContentsToSolidColor(const Color&) { }
     virtual void setContentsToPlatformLayer(PlatformLayer*, ContentsLayerPurpose) { }
@@ -591,6 +594,7 @@ protected:
 
     // Should be called from derived class destructors. Should call willBeDestroyed() on super.
     WEBCORE_EXPORT virtual void willBeDestroyed();
+    bool beingDestroyed() const { return m_beingDestroyed; }
 
     // This method is used by platform GraphicsLayer classes to clear the filters
     // when compositing is not done in hardware. It is not virtual, so the caller
@@ -656,6 +660,7 @@ protected:
     GraphicsLayerPaintingPhase m_paintingPhase { GraphicsLayerPaintAllWithOverflowClip };
     CompositingCoordinatesOrientation m_contentsOrientation { CompositingCoordinatesOrientation::TopDown }; // affects orientation of layer contents
 
+    bool m_beingDestroyed : 1;
     bool m_contentsOpaque : 1;
     bool m_supportsSubpixelAntialiasedText : 1;
     bool m_preserves3D: 1;
@@ -675,12 +680,12 @@ protected:
 
     int m_repaintCount { 0 };
 
-    Vector<GraphicsLayer*> m_children;
+    Vector<Ref<GraphicsLayer>> m_children;
     GraphicsLayer* m_parent { nullptr };
 
-    GraphicsLayer* m_maskLayer { nullptr }; // Reference to mask layer. We don't own this.
+    RefPtr<GraphicsLayer> m_maskLayer { nullptr }; // Reference to mask layer.
 
-    GraphicsLayer* m_replicaLayer { nullptr }; // A layer that replicates this layer. We only allow one, for now.
+    RefPtr<GraphicsLayer> m_replicaLayer { nullptr }; // A layer that replicates this layer. We only allow one, for now.
                                    // The replica is not parented; this is the primary reference to it.
     GraphicsLayer* m_replicatedLayer { nullptr }; // For a replica layer, a reference to the original layer.
     FloatPoint m_replicatedLayerPosition; // For a replica layer, the position of the replica.
index a7405fc..a7e6104 100644 (file)
@@ -23,8 +23,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef GraphicsLayerFactory_h
-#define GraphicsLayerFactory_h
+#pragma once
 
 #include "GraphicsLayer.h"
 #include <wtf/Forward.h>
@@ -35,9 +34,7 @@ class GraphicsLayerFactory {
 public:
     virtual ~GraphicsLayerFactory() = default;
 
-    virtual std::unique_ptr<GraphicsLayer> createGraphicsLayer(GraphicsLayer::Type, GraphicsLayerClient&) = 0;
+    virtual Ref<GraphicsLayer> createGraphicsLayer(GraphicsLayer::Type, GraphicsLayerClient&) = 0;
 };
 
 } // namespace WebCore
-
-#endif // GraphicsLayerFactory_h
index cf1aa41..23b0664 100644 (file)
@@ -339,17 +339,17 @@ bool GraphicsLayer::supportsSubpixelAntialiasedLayerText()
 #endif
 }
 
-std::unique_ptr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerFactory* factory, GraphicsLayerClient& client, Type layerType)
+Ref<GraphicsLayer> GraphicsLayer::create(GraphicsLayerFactory* factory, GraphicsLayerClient& client, Type layerType)
 {
-    std::unique_ptr<GraphicsLayer> graphicsLayer;
-    if (!factory)
-        graphicsLayer = std::make_unique<GraphicsLayerCA>(layerType, client);
-    else
-        graphicsLayer = factory->createGraphicsLayer(layerType, client);
-
-    graphicsLayer->initialize(layerType);
-
-    return graphicsLayer;
+    if (factory) {
+        auto layer = factory->createGraphicsLayer(layerType, client);
+        layer->initialize(layerType);
+        return layer;
+    }
+    
+    auto layer = adoptRef(*new GraphicsLayerCA(layerType, client));
+    layer->initialize(layerType);
+    return WTFMove(layer);
 }
 
 bool GraphicsLayerCA::filtersCanBeComposited(const FilterOperations& filters)
@@ -505,42 +505,42 @@ PlatformLayer* GraphicsLayerCA::platformLayer() const
     return primaryLayer()->platformLayer();
 }
 
-bool GraphicsLayerCA::setChildren(const Vector<GraphicsLayer*>& children)
+bool GraphicsLayerCA::setChildren(Vector<Ref<GraphicsLayer>>&& children)
 {
-    bool childrenChanged = GraphicsLayer::setChildren(children);
+    bool childrenChanged = GraphicsLayer::setChildren(WTFMove(children));
     if (childrenChanged)
         noteSublayersChanged();
     
     return childrenChanged;
 }
 
-void GraphicsLayerCA::addChild(GraphicsLayer* childLayer)
+void GraphicsLayerCA::addChild(Ref<GraphicsLayer>&& childLayer)
 {
-    GraphicsLayer::addChild(childLayer);
+    GraphicsLayer::addChild(WTFMove(childLayer));
     noteSublayersChanged();
 }
 
-void GraphicsLayerCA::addChildAtIndex(GraphicsLayer* childLayer, int index)
+void GraphicsLayerCA::addChildAtIndex(Ref<GraphicsLayer>&& childLayer, int index)
 {
-    GraphicsLayer::addChildAtIndex(childLayer, index);
+    GraphicsLayer::addChildAtIndex(WTFMove(childLayer), index);
     noteSublayersChanged();
 }
 
-void GraphicsLayerCA::addChildBelow(GraphicsLayer* childLayer, GraphicsLayer* sibling)
+void GraphicsLayerCA::addChildBelow(Ref<GraphicsLayer>&& childLayer, GraphicsLayer* sibling)
 {
-    GraphicsLayer::addChildBelow(childLayer, sibling);
+    GraphicsLayer::addChildBelow(WTFMove(childLayer), sibling);
     noteSublayersChanged();
 }
 
-void GraphicsLayerCA::addChildAbove(GraphicsLayer* childLayer, GraphicsLayer* sibling)
+void GraphicsLayerCA::addChildAbove(Ref<GraphicsLayer>&& childLayer, GraphicsLayer* sibling)
 {
-    GraphicsLayer::addChildAbove(childLayer, sibling);
+    GraphicsLayer::addChildAbove(WTFMove(childLayer), sibling);
     noteSublayersChanged();
 }
 
-bool GraphicsLayerCA::replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild)
+bool GraphicsLayerCA::replaceChild(GraphicsLayer* oldChild, Ref<GraphicsLayer>&& newChild)
 {
-    if (GraphicsLayer::replaceChild(oldChild, newChild)) {
+    if (GraphicsLayer::replaceChild(oldChild, WTFMove(newChild))) {
         noteSublayersChanged();
         return true;
     }
@@ -554,12 +554,12 @@ void GraphicsLayerCA::removeFromParent()
     GraphicsLayer::removeFromParent();
 }
 
-void GraphicsLayerCA::setMaskLayer(GraphicsLayer* layer)
+void GraphicsLayerCA::setMaskLayer(RefPtr<GraphicsLayer>&& layer)
 {
     if (layer == m_maskLayer)
         return;
 
-    GraphicsLayer::setMaskLayer(layer);
+    GraphicsLayer::setMaskLayer(WTFMove(layer));
     noteLayerPropertyChanged(MaskLayerChanged);
 
     propagateLayerChangeToReplicas();
@@ -1300,16 +1300,13 @@ bool GraphicsLayerCA::recursiveVisibleRectChangeRequiresFlush(const CommitState&
     childCommitState.ancestorIsViewportConstrained |= m_isViewportConstrained;
 
     if (m_maskLayer) {
-        GraphicsLayerCA& maskLayerCA = downcast<GraphicsLayerCA>(*m_maskLayer);
+        auto& maskLayerCA = downcast<GraphicsLayerCA>(*m_maskLayer);
         if (maskLayerCA.recursiveVisibleRectChangeRequiresFlush(childCommitState, localState))
             return true;
     }
 
-    const Vector<GraphicsLayer*>& childLayers = children();
-    size_t numChildren = childLayers.size();
-    
-    for (size_t i = 0; i < numChildren; ++i) {
-        GraphicsLayerCA& currentChild = downcast<GraphicsLayerCA>(*childLayers[i]);
+    for (const auto& layer : children()) {
+        const auto& currentChild = downcast<GraphicsLayerCA>(layer.get());
         if (currentChild.recursiveVisibleRectChangeRequiresFlush(childCommitState, localState))
             return true;
     }
@@ -1572,28 +1569,25 @@ void GraphicsLayerCA::recursiveCommitChanges(const CommitState& commitState, con
     
     childCommitState.ancestorIsViewportConstrained |= m_isViewportConstrained;
 
-    if (GraphicsLayerCA* maskLayer = downcast<GraphicsLayerCA>(m_maskLayer)) {
+    if (GraphicsLayerCA* maskLayer = downcast<GraphicsLayerCA>(m_maskLayer.get())) {
         maskLayer->setVisibleAndCoverageRects(rects, m_isViewportConstrained || commitState.ancestorIsViewportConstrained);
         maskLayer->commitLayerChangesBeforeSublayers(childCommitState, pageScaleFactor, baseRelativePosition);
     }
 
-    const Vector<GraphicsLayer*>& childLayers = children();
-    size_t numChildren = childLayers.size();
-
     bool hasDescendantsWithRunningTransformAnimations = false;
     
-    for (size_t i = 0; i < numChildren; ++i) {
-        GraphicsLayerCA& currentChild = downcast<GraphicsLayerCA>(*childLayers[i]);
+    for (auto& layer : children()) {
+        auto& currentChild = downcast<GraphicsLayerCA>(layer.get());
         currentChild.recursiveCommitChanges(childCommitState, localState, pageScaleFactor, baseRelativePosition, affectedByPageScale);
 
         if (currentChild.isRunningTransformAnimation() || currentChild.hasDescendantsWithRunningTransformAnimations())
             hasDescendantsWithRunningTransformAnimations = true;
     }
 
-    if (GraphicsLayerCA* replicaLayer = downcast<GraphicsLayerCA>(m_replicaLayer))
+    if (GraphicsLayerCA* replicaLayer = downcast<GraphicsLayerCA>(m_replicaLayer.get()))
         replicaLayer->recursiveCommitChanges(childCommitState, localState, pageScaleFactor, baseRelativePosition, affectedByPageScale);
 
-    if (GraphicsLayerCA* maskLayer = downcast<GraphicsLayerCA>(m_maskLayer))
+    if (GraphicsLayerCA* maskLayer = downcast<GraphicsLayerCA>(m_maskLayer.get()))
         maskLayer->commitLayerChangesAfterSublayers(childCommitState);
 
     setHasDescendantsWithUncommittedChanges(false);
@@ -1928,10 +1922,8 @@ void GraphicsLayerCA::updateSublayerList(bool maxLayerDepthReached)
         primaryLayerChildren.append(m_contentsClippingLayer ? m_contentsClippingLayer : m_contentsLayer);
     }
     
-    const Vector<GraphicsLayer*>& childLayers = children();
-    size_t numChildren = childLayers.size();
-    for (size_t i = 0; i < numChildren; ++i) {
-        GraphicsLayerCA& currentChild = downcast<GraphicsLayerCA>(*childLayers[i]);
+    for (const auto& layer : children()) {
+        const auto& currentChild = downcast<GraphicsLayerCA>(layer.get());
         PlatformCALayer* childLayer = currentChild.layerForSuperlayer();
         childListForSublayers.append(childLayer);
     }
@@ -3977,7 +3969,7 @@ RefPtr<PlatformCALayer> GraphicsLayerCA::fetchCloneLayers(GraphicsLayer* replica
         return primaryLayer;
     }
 
-    const Vector<GraphicsLayer*>& childLayers = children();
+    auto& childLayers = children();
     Vector<RefPtr<PlatformCALayer>> clonalSublayers;
 
     RefPtr<PlatformCALayer> replicaLayer;
@@ -4027,8 +4019,8 @@ RefPtr<PlatformCALayer> GraphicsLayerCA::fetchCloneLayers(GraphicsLayer* replica
         
         replicaState.push(ReplicaState::ChildBranch);
 
-        for (auto* childLayer : childLayers) {
-            GraphicsLayerCA& childLayerCA = downcast<GraphicsLayerCA>(*childLayer);
+        for (auto& childLayer : childLayers) {
+            GraphicsLayerCA& childLayerCA = downcast<GraphicsLayerCA>(childLayer.get());
             if (auto platformLayer = childLayerCA.fetchCloneLayers(replicaRoot, replicaState, IntermediateCloneLevel))
                 clonalSublayers.append(WTFMove(platformLayer));
         }
@@ -4192,6 +4184,9 @@ void GraphicsLayerCA::setHasDescendantsWithUncommittedChanges(bool value)
 
 void GraphicsLayerCA::noteLayerPropertyChanged(LayerChangeFlags flags, ScheduleFlushOrNot scheduleFlush)
 {
+    if (beingDestroyed())
+        return;
+
     bool hadUncommittedChanges = !!m_uncommittedChanges;
     bool oldCanThrottleLayerFlush = canThrottleLayerFlush();
 
index cc307fb..8213ec4 100644 (file)
@@ -49,7 +49,6 @@ class TransformState;
 
 class GraphicsLayerCA : public GraphicsLayer, public PlatformCALayerClient {
 public:
-
     WEBCORE_EXPORT explicit GraphicsLayerCA(Type, GraphicsLayerClient&);
     WEBCORE_EXPORT virtual ~GraphicsLayerCA();
 
@@ -62,16 +61,16 @@ public:
     WEBCORE_EXPORT PlatformLayer* platformLayer() const override;
     PlatformCALayer* platformCALayer() const { return primaryLayer(); }
 
-    WEBCORE_EXPORT bool setChildren(const Vector<GraphicsLayer*>&) override;
-    WEBCORE_EXPORT void addChild(GraphicsLayer*) override;
-    WEBCORE_EXPORT void addChildAtIndex(GraphicsLayer*, int index) override;
-    WEBCORE_EXPORT void addChildAbove(GraphicsLayer*, GraphicsLayer* sibling) override;
-    WEBCORE_EXPORT void addChildBelow(GraphicsLayer*, GraphicsLayer* sibling) override;
-    WEBCORE_EXPORT bool replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild) override;
+    WEBCORE_EXPORT bool setChildren(Vector<Ref<GraphicsLayer>>&&) override;
+    WEBCORE_EXPORT void addChild(Ref<GraphicsLayer>&&) override;
+    WEBCORE_EXPORT void addChildAtIndex(Ref<GraphicsLayer>&&, int index) override;
+    WEBCORE_EXPORT void addChildAbove(Ref<GraphicsLayer>&&, GraphicsLayer* sibling) override;
+    WEBCORE_EXPORT void addChildBelow(Ref<GraphicsLayer>&&, GraphicsLayer* sibling) override;
+    WEBCORE_EXPORT bool replaceChild(GraphicsLayer* oldChild, Ref<GraphicsLayer>&& newChild) override;
 
     WEBCORE_EXPORT void removeFromParent() override;
 
-    WEBCORE_EXPORT void setMaskLayer(GraphicsLayer*) override;
+    WEBCORE_EXPORT void setMaskLayer(RefPtr<GraphicsLayer>&&) override;
     WEBCORE_EXPORT void setReplicatedLayer(GraphicsLayer*) override;
 
     WEBCORE_EXPORT void setPosition(const FloatPoint&) override;
index 0cec0c5..e604198 100644 (file)
 
 namespace WebCore {
 
-std::unique_ptr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerFactory* factory, GraphicsLayerClient& client, Type layerType)
+Ref<GraphicsLayer> GraphicsLayer::create(GraphicsLayerFactory* factory, GraphicsLayerClient& client, Type layerType)
 {
     if (!factory)
-        return std::make_unique<GraphicsLayerTextureMapper>(layerType, client);
+        return adoptRef(*new GraphicsLayerTextureMapper(layerType, client));
 
     return factory->createGraphicsLayer(layerType, client);
 }
@@ -93,59 +93,61 @@ void GraphicsLayerTextureMapper::setNeedsDisplayInRect(const FloatRect& rect, Sh
     addRepaintRect(rect);
 }
 
-bool GraphicsLayerTextureMapper::setChildren(const Vector<GraphicsLayer*>& children)
+bool GraphicsLayerTextureMapper::setChildren(Vector<Ref<GraphicsLayer>>&& children)
 {
-    if (GraphicsLayer::setChildren(children)) {
+    if (GraphicsLayer::setChildren(WTFMove(children))) {
         notifyChange(ChildrenChange);
         return true;
     }
     return false;
 }
 
-void GraphicsLayerTextureMapper::addChild(GraphicsLayer* layer)
+void GraphicsLayerTextureMapper::addChild(Ref<GraphicsLayer>&& layer)
 {
     notifyChange(ChildrenChange);
-    GraphicsLayer::addChild(layer);
+    GraphicsLayer::addChild(WTFMove(layer));
 }
 
-void GraphicsLayerTextureMapper::addChildAtIndex(GraphicsLayer* layer, int index)
+void GraphicsLayerTextureMapper::addChildAtIndex(Ref<GraphicsLayer>&& layer, int index)
 {
-    GraphicsLayer::addChildAtIndex(layer, index);
+    GraphicsLayer::addChildAtIndex(WTFMove(layer), index);
     notifyChange(ChildrenChange);
 }
 
-void GraphicsLayerTextureMapper::addChildAbove(GraphicsLayer* layer, GraphicsLayer* sibling)
+void GraphicsLayerTextureMapper::addChildAbove(Ref<GraphicsLayer>&& layer, GraphicsLayer* sibling)
 {
-    GraphicsLayer::addChildAbove(layer, sibling);
+    GraphicsLayer::addChildAbove(WTFMove(layer), sibling);
     notifyChange(ChildrenChange);
 }
 
-void GraphicsLayerTextureMapper::addChildBelow(GraphicsLayer* layer, GraphicsLayer* sibling)
+void GraphicsLayerTextureMapper::addChildBelow(Ref<GraphicsLayer>&& layer, GraphicsLayer* sibling)
 {
-    GraphicsLayer::addChildBelow(layer, sibling);
+    GraphicsLayer::addChildBelow(WTFMove(layer), sibling);
     notifyChange(ChildrenChange);
 }
 
-bool GraphicsLayerTextureMapper::replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild)
+bool GraphicsLayerTextureMapper::replaceChild(GraphicsLayer* oldChild, Ref<GraphicsLayer>&& newChild)
 {
-    if (GraphicsLayer::replaceChild(oldChild, newChild)) {
+    if (GraphicsLayer::replaceChild(oldChild, WTFMove(newChild))) {
         notifyChange(ChildrenChange);
         return true;
     }
     return false;
 }
 
-void GraphicsLayerTextureMapper::setMaskLayer(GraphicsLayer* value)
+void GraphicsLayerTextureMapper::setMaskLayer(RefPtr<GraphicsLayer>&& value)
 {
     if (value == maskLayer())
         return;
-    GraphicsLayer::setMaskLayer(value);
+
+    GraphicsLayer* rawLayer = value.get();
+    GraphicsLayer::setMaskLayer(WTFMove(value));
     notifyChange(MaskLayerChange);
 
-    if (!value)
+    if (!rawLayer)
         return;
-    value->setSize(size());
-    value->setContentsVisible(contentsAreVisible());
+    rawLayer->setSize(size());
+    rawLayer->setContentsVisible(contentsAreVisible());
 }
 
 
@@ -391,8 +393,13 @@ void GraphicsLayerTextureMapper::commitLayerChanges()
     if (m_changeMask == NoChanges)
         return;
 
-    if (m_changeMask & ChildrenChange)
-        m_layer.setChildren(children());
+    if (m_changeMask & ChildrenChange) {
+        Vector<GraphicsLayer*> rawChildren;
+        rawChildren.reserveInitialCapacity(children().size());
+        for (auto& layer : children())
+            rawChildren.uncheckedAppend(layer.ptr());
+        m_layer.setChildren(rawChildren);
+    }
 
     if (m_changeMask & MaskLayerChange)
         m_layer.setMaskLayer(&downcast<GraphicsLayerTextureMapper>(maskLayer())->layer());
@@ -477,7 +484,7 @@ void GraphicsLayerTextureMapper::flushCompositingState(const FloatRect& rect)
         maskLayer()->flushCompositingState(rect);
     if (replicaLayer())
         replicaLayer()->flushCompositingState(rect);
-    for (auto* child : children())
+    for (auto& child : children())
         child->flushCompositingState(rect);
 }
 
@@ -492,8 +499,8 @@ void GraphicsLayerTextureMapper::updateBackingStoreIncludingSubLayers()
         downcast<GraphicsLayerTextureMapper>(*maskLayer()).updateBackingStoreIfNeeded();
     if (replicaLayer())
         downcast<GraphicsLayerTextureMapper>(*replicaLayer()).updateBackingStoreIfNeeded();
-    for (auto* child : children())
-        downcast<GraphicsLayerTextureMapper>(*child).updateBackingStoreIncludingSubLayers();
+    for (auto& child : children())
+        downcast<GraphicsLayerTextureMapper>(child.get()).updateBackingStoreIncludingSubLayers();
 }
 
 void GraphicsLayerTextureMapper::updateBackingStoreIfNeeded()
index 3fda5f1..fc91d92 100644 (file)
@@ -39,14 +39,14 @@ public:
     void setID(uint32_t id) { m_layer.setID(id); }
 
     // GraphicsLayer
-    bool setChildren(const Vector<GraphicsLayer*>&) override;
-    void addChild(GraphicsLayer*) override;
-    void addChildAtIndex(GraphicsLayer*, int index) override;
-    void addChildAbove(GraphicsLayer*, GraphicsLayer* sibling) override;
-    void addChildBelow(GraphicsLayer*, GraphicsLayer* sibling) override;
-    bool replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild) override;
-
-    void setMaskLayer(GraphicsLayer*) override;
+    bool setChildren(Vector<Ref<GraphicsLayer>>&&) override;
+    void addChild(Ref<GraphicsLayer>&&) override;
+    void addChildAtIndex(Ref<GraphicsLayer>&&, int index) override;
+    void addChildAbove(Ref<GraphicsLayer>&&, GraphicsLayer* sibling) override;
+    void addChildBelow(Ref<GraphicsLayer>&&, GraphicsLayer* sibling) override;
+    bool replaceChild(GraphicsLayer* oldChild, Ref<GraphicsLayer>&& newChild) override;
+
+    void setMaskLayer(RefPtr<GraphicsLayer>&&) override;
     void setReplicatedByLayer(GraphicsLayer*) override;
     void setPosition(const FloatPoint&) override;
     void setAnchorPoint(const FloatPoint3D&) override;
index 09e56f3..a078e4a 100644 (file)
 
 namespace WebCore {
 
-std::unique_ptr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerFactory* factory, GraphicsLayerClient& client, Type layerType)
+Ref<GraphicsLayer> GraphicsLayer::create(GraphicsLayerFactory* factory, GraphicsLayerClient& client, Type layerType)
 {
     if (!factory)
-        return std::make_unique<CoordinatedGraphicsLayer>(layerType, client);
+        return adoptRef(*new CoordinatedGraphicsLayer(layerType, client));
 
     return factory->createGraphicsLayer(layerType, client);
 }
@@ -97,7 +97,7 @@ void CoordinatedGraphicsLayer::setShouldUpdateVisibleRect()
 {
     m_shouldUpdateVisibleRect = true;
     for (auto& child : children())
-        downcast<CoordinatedGraphicsLayer>(*child).setShouldUpdateVisibleRect();
+        downcast<CoordinatedGraphicsLayer>(child.get()).setShouldUpdateVisibleRect();
     if (replicaLayer())
         downcast<CoordinatedGraphicsLayer>(*replicaLayer()).setShouldUpdateVisibleRect();
 }
@@ -158,49 +158,54 @@ auto CoordinatedGraphicsLayer::primaryLayerID() const -> PlatformLayerID
     return id();
 }
 
-bool CoordinatedGraphicsLayer::setChildren(const Vector<GraphicsLayer*>& children)
+bool CoordinatedGraphicsLayer::setChildren(Vector<Ref<GraphicsLayer>>&& children)
 {
-    bool ok = GraphicsLayer::setChildren(children);
+    bool ok = GraphicsLayer::setChildren(WTFMove(children));
     if (!ok)
         return false;
     didChangeChildren();
     return true;
 }
 
-void CoordinatedGraphicsLayer::addChild(GraphicsLayer* layer)
+void CoordinatedGraphicsLayer::addChild(Ref<GraphicsLayer>&& layer)
 {
-    GraphicsLayer::addChild(layer);
-    downcast<CoordinatedGraphicsLayer>(*layer).setCoordinatorIncludingSubLayersIfNeeded(m_coordinator);
+    GraphicsLayer* rawLayer = layer.ptr();
+    GraphicsLayer::addChild(WTFMove(layer));
+    downcast<CoordinatedGraphicsLayer>(*rawLayer).setCoordinatorIncludingSubLayersIfNeeded(m_coordinator);
     didChangeChildren();
 }
 
-void CoordinatedGraphicsLayer::addChildAtIndex(GraphicsLayer* layer, int index)
+void CoordinatedGraphicsLayer::addChildAtIndex(Ref<GraphicsLayer>&& layer, int index)
 {
-    GraphicsLayer::addChildAtIndex(layer, index);
-    downcast<CoordinatedGraphicsLayer>(*layer).setCoordinatorIncludingSubLayersIfNeeded(m_coordinator);
+    GraphicsLayer* rawLayer = layer.ptr();
+    GraphicsLayer::addChildAtIndex(WTFMove(layer), index);
+    downcast<CoordinatedGraphicsLayer>(*rawLayer).setCoordinatorIncludingSubLayersIfNeeded(m_coordinator);
     didChangeChildren();
 }
 
-void CoordinatedGraphicsLayer::addChildAbove(GraphicsLayer* layer, GraphicsLayer* sibling)
+void CoordinatedGraphicsLayer::addChildAbove(Ref<GraphicsLayer>&& layer, GraphicsLayer* sibling)
 {
-    GraphicsLayer::addChildAbove(layer, sibling);
-    downcast<CoordinatedGraphicsLayer>(*layer).setCoordinatorIncludingSubLayersIfNeeded(m_coordinator);
+    GraphicsLayer* rawLayer = layer.ptr();
+    GraphicsLayer::addChildAbove(WTFMove(layer), sibling);
+    downcast<CoordinatedGraphicsLayer>(*rawLayer).setCoordinatorIncludingSubLayersIfNeeded(m_coordinator);
     didChangeChildren();
 }
 
-void CoordinatedGraphicsLayer::addChildBelow(GraphicsLayer* layer, GraphicsLayer* sibling)
+void CoordinatedGraphicsLayer::addChildBelow(Ref<GraphicsLayer>&& layer, GraphicsLayer* sibling)
 {
-    GraphicsLayer::addChildBelow(layer, sibling);
-    downcast<CoordinatedGraphicsLayer>(*layer).setCoordinatorIncludingSubLayersIfNeeded(m_coordinator);
+    GraphicsLayer* rawLayer = layer.ptr();
+    GraphicsLayer::addChildBelow(WTFMove(layer), sibling);
+    downcast<CoordinatedGraphicsLayer>(*rawLayer).setCoordinatorIncludingSubLayersIfNeeded(m_coordinator);
     didChangeChildren();
 }
 
-bool CoordinatedGraphicsLayer::replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild)
+bool CoordinatedGraphicsLayer::replaceChild(GraphicsLayer* oldChild, Ref<GraphicsLayer>&& newChild)
 {
-    bool ok = GraphicsLayer::replaceChild(oldChild, newChild);
+    GraphicsLayer* rawLayer = newChild.ptr();
+    bool ok = GraphicsLayer::replaceChild(oldChild, WTFMove(newChild));
     if (!ok)
         return false;
-    downcast<CoordinatedGraphicsLayer>(*newChild).setCoordinatorIncludingSubLayersIfNeeded(m_coordinator);
+    downcast<CoordinatedGraphicsLayer>(*rawLayer).setCoordinatorIncludingSubLayersIfNeeded(m_coordinator);
     didChangeChildren();
     return true;
 }
@@ -495,18 +500,19 @@ void CoordinatedGraphicsLayer::setContentsToImage(Image* image)
     notifyFlushRequired();
 }
 
-void CoordinatedGraphicsLayer::setMaskLayer(GraphicsLayer* layer)
+void CoordinatedGraphicsLayer::setMaskLayer(RefPtr<GraphicsLayer>&& layer)
 {
     if (layer == maskLayer())
         return;
 
-    GraphicsLayer::setMaskLayer(layer);
+    GraphicsLayer* rawLayer = layer.get();
+    GraphicsLayer::setMaskLayer(WTFMove(layer));
 
-    if (!layer)
+    if (!rawLayer)
         return;
 
-    layer->setSize(size());
-    layer->setContentsVisible(contentsAreVisible());
+    rawLayer->setSize(size());
+    rawLayer->setContentsVisible(contentsAreVisible());
 
     m_nicosia.delta.maskChanged = true;
 
@@ -732,9 +738,9 @@ void CoordinatedGraphicsLayer::flushCompositingStateForThisLayerOnly()
 
                 if (localDelta.childrenChanged) {
                     state.children = WTF::map(children(),
-                        [](auto* child)
+                        [](auto& child)
                         {
-                            return downcast<CoordinatedGraphicsLayer>(child)->m_nicosia.layer;
+                            return downcast<CoordinatedGraphicsLayer>(child.get()).m_nicosia.layer;
                         });
                 }
 
@@ -784,7 +790,7 @@ void CoordinatedGraphicsLayer::syncPendingStateChangesIncludingSubLayers()
         downcast<CoordinatedGraphicsLayer>(*maskLayer()).syncPendingStateChangesIncludingSubLayers();
 
     for (auto& child : children())
-        downcast<CoordinatedGraphicsLayer>(*child).syncPendingStateChangesIncludingSubLayers();
+        downcast<CoordinatedGraphicsLayer>(child.get()).syncPendingStateChangesIncludingSubLayers();
 }
 
 void CoordinatedGraphicsLayer::deviceOrPageScaleFactorChanged()
@@ -837,7 +843,7 @@ void CoordinatedGraphicsLayer::updateContentBuffersIncludingSubLayers()
     updateContentBuffers();
 
     for (auto& child : children())
-        downcast<CoordinatedGraphicsLayer>(*child).updateContentBuffersIncludingSubLayers();
+        downcast<CoordinatedGraphicsLayer>(child.get()).updateContentBuffersIncludingSubLayers();
 }
 
 void CoordinatedGraphicsLayer::updateContentBuffers()
@@ -1007,7 +1013,7 @@ void CoordinatedGraphicsLayer::setCoordinatorIncludingSubLayersIfNeeded(Coordina
 
     coordinator->attachLayer(this);
     for (auto& child : children())
-        downcast<CoordinatedGraphicsLayer>(*child).setCoordinatorIncludingSubLayersIfNeeded(coordinator);
+        downcast<CoordinatedGraphicsLayer>(child.get()).setCoordinatorIncludingSubLayersIfNeeded(coordinator);
 }
 
 const RefPtr<Nicosia::CompositionLayer>& CoordinatedGraphicsLayer::compositionLayer() const
index f679b2c..ee4e841 100644 (file)
@@ -63,12 +63,12 @@ public:
     PlatformLayerID primaryLayerID() const override;
 
     // Reimplementations from GraphicsLayer.h.
-    bool setChildren(const Vector<GraphicsLayer*>&) override;
-    void addChild(GraphicsLayer*) override;
-    void addChildAtIndex(GraphicsLayer*, int) override;
-    void addChildAbove(GraphicsLayer*, GraphicsLayer*) override;
-    void addChildBelow(GraphicsLayer*, GraphicsLayer*) override;
-    bool replaceChild(GraphicsLayer*, GraphicsLayer*) override;
+    bool setChildren(Vector<Ref<GraphicsLayer>>&&) override;
+    void addChild(Ref<GraphicsLayer>&&) override;
+    void addChildAtIndex(Ref<GraphicsLayer>&&, int) override;
+    void addChildAbove(Ref<GraphicsLayer>&&, GraphicsLayer*) override;
+    void addChildBelow(Ref<GraphicsLayer>&&, GraphicsLayer*) override;
+    bool replaceChild(GraphicsLayer*, Ref<GraphicsLayer>&&) override;
     void removeFromParent() override;
     void setPosition(const FloatPoint&) override;
     void setAnchorPoint(const FloatPoint3D&) override;
@@ -91,7 +91,7 @@ public:
     void setShowRepaintCounter(bool) override;
     bool shouldDirectlyCompositeImage(Image*) const override;
     void setContentsToPlatformLayer(PlatformLayer*, ContentsLayerPurpose) override;
-    void setMaskLayer(GraphicsLayer*) override;
+    void setMaskLayer(RefPtr<GraphicsLayer>&&) override;
     void setReplicatedByLayer(GraphicsLayer*) override;
     void setNeedsDisplay() override;
     void setNeedsDisplayInRect(const FloatRect&, ShouldClipToLayer = ClipToLayer) override;
index 644fa39..99bd71d 100644 (file)
 
 namespace WebCore {
 
-
-std::unique_ptr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerFactory* factory, GraphicsLayerClient& client, Type layerType)
+Ref<GraphicsLayer> GraphicsLayer::create(GraphicsLayerFactory* factory, GraphicsLayerClient& client, Type layerType)
 {
-    std::unique_ptr<GraphicsLayer> graphicsLayer;
-    if (!factory)
-        graphicsLayer = std::make_unique<GraphicsLayerDirect2D>(layerType, client);
-    else
-        graphicsLayer = factory->createGraphicsLayer(layerType, client);
-
-    graphicsLayer->initialize(layerType);
-
-    return graphicsLayer;
+    if (factory) {
+        auto layer = factory->createGraphicsLayer(layerType, client);
+        layer->initialize(layerType);
+        return layer;
+    }
+    
+    auto layer = adoptRef(*new GraphicsLayerCA(layerType, client);
+    layer->initialize(layerType);
+    return layer;
 }
 
 GraphicsLayerDirect2D::GraphicsLayerDirect2D(Type layerType, GraphicsLayerClient& client)
index 0aa00dd..72b4328 100644 (file)
@@ -254,11 +254,11 @@ void RenderLayerBacking::willDestroyLayer(const GraphicsLayer* layer)
         compositor().layerTiledBackingUsageChanged(layer, false);
 }
 
-std::unique_ptr<GraphicsLayer> RenderLayerBacking::createGraphicsLayer(const String& name, GraphicsLayer::Type layerType)
+Ref<GraphicsLayer> RenderLayerBacking::createGraphicsLayer(const String& name, GraphicsLayer::Type layerType)
 {
     auto* graphicsLayerFactory = renderer().page().chrome().client().graphicsLayerFactory();
 
-    std::unique_ptr<GraphicsLayer> graphicsLayer = GraphicsLayer::create(graphicsLayerFactory, *this, layerType);
+    auto graphicsLayer = GraphicsLayer::create(graphicsLayerFactory, *this, layerType);
 
     graphicsLayer->setName(name);
 
@@ -401,7 +401,7 @@ void RenderLayerBacking::createPrimaryGraphicsLayer()
 
     if (m_isFrameLayerWithTiledBacking) {
         m_childContainmentLayer = createGraphicsLayer("Page TiledBacking containment");
-        m_graphicsLayer->addChild(m_childContainmentLayer.get());
+        m_graphicsLayer->addChild(*m_childContainmentLayer);
     }
 
 #if !PLATFORM(IOS)
@@ -709,7 +709,7 @@ bool RenderLayerBacking::updateConfiguration()
 
     if (auto* flatteningLayer = tileCacheFlatteningLayer()) {
         if (layerConfigChanged || flatteningLayer->parent() != m_graphicsLayer.get())
-            m_graphicsLayer->addChild(flatteningLayer);
+            m_graphicsLayer->addChild(*flatteningLayer);
     }
 
     updateMaskingLayer(renderer().hasMask(), renderer().hasClipPath());
@@ -1302,26 +1302,26 @@ void RenderLayerBacking::updateInternalHierarchy()
     if (m_contentsContainmentLayer) {
         m_contentsContainmentLayer->removeAllChildren();
         if (m_ancestorClippingLayer)
-            m_ancestorClippingLayer->addChild(m_contentsContainmentLayer.get());
+            m_ancestorClippingLayer->addChild(*m_contentsContainmentLayer);
     }
     
     if (m_backgroundLayer)
-        m_contentsContainmentLayer->addChild(m_backgroundLayer.get());
+        m_contentsContainmentLayer->addChild(*m_backgroundLayer);
 
     if (m_contentsContainmentLayer)
-        m_contentsContainmentLayer->addChild(m_graphicsLayer.get());
+        m_contentsContainmentLayer->addChild(*m_graphicsLayer);
     else if (m_ancestorClippingLayer)
-        m_ancestorClippingLayer->addChild(m_graphicsLayer.get());
+        m_ancestorClippingLayer->addChild(*m_graphicsLayer);
 
     if (m_childContainmentLayer) {
         m_childContainmentLayer->removeFromParent();
-        m_graphicsLayer->addChild(m_childContainmentLayer.get());
+        m_graphicsLayer->addChild(*m_childContainmentLayer);
     }
 
     if (m_scrollingLayer) {
         auto* superlayer = m_childContainmentLayer ? m_childContainmentLayer.get() : m_graphicsLayer.get();
         m_scrollingLayer->removeFromParent();
-        superlayer->addChild(m_scrollingLayer.get());
+        superlayer->addChild(*m_scrollingLayer);
     }
 
     // The clip for child layers does not include space for overflow controls, so they exist as
@@ -1329,15 +1329,15 @@ void RenderLayerBacking::updateInternalHierarchy()
     // children of the clipping layer.
     if (m_layerForHorizontalScrollbar) {
         m_layerForHorizontalScrollbar->removeFromParent();
-        m_graphicsLayer->addChild(m_layerForHorizontalScrollbar.get());
+        m_graphicsLayer->addChild(*m_layerForHorizontalScrollbar);
     }
     if (m_layerForVerticalScrollbar) {
         m_layerForVerticalScrollbar->removeFromParent();
-        m_graphicsLayer->addChild(m_layerForVerticalScrollbar.get());
+        m_graphicsLayer->addChild(*m_layerForVerticalScrollbar);
     }
     if (m_layerForScrollCorner) {
         m_layerForScrollCorner->removeFromParent();
-        m_graphicsLayer->addChild(m_layerForScrollCorner.get());
+        m_graphicsLayer->addChild(*m_layerForScrollCorner);
     }
 }
 
@@ -1690,7 +1690,7 @@ void RenderLayerBacking::updateMaskingLayer(bool hasMask, bool hasClipPath)
             m_maskLayer->setDrawsContent(paintsContent);
             m_maskLayer->setPaintingPhase(maskPhases);
             layerChanged = true;
-            m_graphicsLayer->setMaskLayer(m_maskLayer.get());
+            m_graphicsLayer->setMaskLayer(m_maskLayer.copyRef());
         }
     } else if (m_maskLayer) {
         m_graphicsLayer->setMaskLayer(nullptr);
@@ -1721,7 +1721,7 @@ void RenderLayerBacking::updateChildClippingStrategy(bool needsDescendantsClippi
                 m_childClippingMaskLayer = createGraphicsLayer("child clipping mask");
                 m_childClippingMaskLayer->setDrawsContent(true);
                 m_childClippingMaskLayer->setPaintingPhase(GraphicsLayerPaintChildClippingMask);
-                clippingLayer()->setMaskLayer(m_childClippingMaskLayer.get());
+                clippingLayer()->setMaskLayer(m_childClippingMaskLayer.copyRef());
             }
         }
     } else {
@@ -1754,7 +1754,7 @@ bool RenderLayerBacking::updateScrollingLayers(bool needsScrollingLayers)
         if (!m_foregroundLayer)
             paintPhase |= GraphicsLayerPaintForeground;
         m_scrollingContentsLayer->setPaintingPhase(paintPhase);
-        m_scrollingLayer->addChild(m_scrollingContentsLayer.get());
+        m_scrollingLayer->addChild(*m_scrollingContentsLayer);
     } else {
         compositor().willRemoveScrollingLayerWithBacking(m_owningLayer, *this);
 
index 34546f5..c1e3f7d 100644 (file)
@@ -136,7 +136,7 @@ public:
 
     void setIsScrollCoordinatedWithViewportConstrainedRole(bool);
 
-    bool hasMaskLayer() const { return m_maskLayer != 0; }
+    bool hasMaskLayer() const { return m_maskLayer; }
     bool hasChildClippingMaskLayer() const { return m_childClippingMaskLayer != nullptr; }
 
     GraphicsLayer* parentForSublayers() const;
@@ -267,7 +267,7 @@ private:
 
     LayoutRect compositedBoundsIncludingMargin() const;
     
-    std::unique_ptr<GraphicsLayer> createGraphicsLayer(const String&, GraphicsLayer::Type = GraphicsLayer::Type::Normal);
+    Ref<GraphicsLayer> createGraphicsLayer(const String&, GraphicsLayer::Type = GraphicsLayer::Type::Normal);
 
     RenderLayerModelObject& renderer() const { return m_owningLayer.renderer(); }
     RenderBox* renderBox() const { return m_owningLayer.renderBox(); }
@@ -355,21 +355,21 @@ private:
 
     RenderLayer& m_owningLayer;
 
-    std::unique_ptr<GraphicsLayer> m_ancestorClippingLayer; // Only used if we are clipped by an ancestor which is not a stacking context.
-    std::unique_ptr<GraphicsLayer> m_contentsContainmentLayer; // Only used if we have a background layer; takes the transform.
-    std::unique_ptr<GraphicsLayer> m_graphicsLayer;
-    std::unique_ptr<GraphicsLayer> m_foregroundLayer; // Only used in cases where we need to draw the foreground separately.
-    std::unique_ptr<GraphicsLayer> m_backgroundLayer; // Only used in cases where we need to draw the background separately.
-    std::unique_ptr<GraphicsLayer> m_childContainmentLayer; // Only used if we have clipping on a stacking context with compositing children, or if the layer has a tile cache.
-    std::unique_ptr<GraphicsLayer> m_maskLayer; // Only used if we have a mask and/or clip-path.
-    std::unique_ptr<GraphicsLayer> m_childClippingMaskLayer; // Only used if we have to clip child layers or accelerated contents with border radius or clip-path.
-
-    std::unique_ptr<GraphicsLayer> m_layerForHorizontalScrollbar;
-    std::unique_ptr<GraphicsLayer> m_layerForVerticalScrollbar;
-    std::unique_ptr<GraphicsLayer> m_layerForScrollCorner;
-
-    std::unique_ptr<GraphicsLayer> m_scrollingLayer; // Only used if the layer is using composited scrolling.
-    std::unique_ptr<GraphicsLayer> m_scrollingContentsLayer; // Only used if the layer is using composited scrolling.
+    RefPtr<GraphicsLayer> m_ancestorClippingLayer; // Only used if we are clipped by an ancestor which is not a stacking context.
+    RefPtr<GraphicsLayer> m_contentsContainmentLayer; // Only used if we have a background layer; takes the transform.
+    RefPtr<GraphicsLayer> m_graphicsLayer;
+    RefPtr<GraphicsLayer> m_foregroundLayer; // Only used in cases where we need to draw the foreground separately.
+    RefPtr<GraphicsLayer> m_backgroundLayer; // Only used in cases where we need to draw the background separately.
+    RefPtr<GraphicsLayer> m_childContainmentLayer; // Only used if we have clipping on a stacking context with compositing children, or if the layer has a tile cache.
+    RefPtr<GraphicsLayer> m_maskLayer; // Only used if we have a mask and/or clip-path.
+    RefPtr<GraphicsLayer> m_childClippingMaskLayer; // Only used if we have to clip child layers or accelerated contents with border radius or clip-path.
+
+    RefPtr<GraphicsLayer> m_layerForHorizontalScrollbar;
+    RefPtr<GraphicsLayer> m_layerForVerticalScrollbar;
+    RefPtr<GraphicsLayer> m_layerForScrollCorner;
+
+    RefPtr<GraphicsLayer> m_scrollingLayer; // Only used if the layer is using composited scrolling.
+    RefPtr<GraphicsLayer> m_scrollingContentsLayer; // Only used if the layer is using composited scrolling.
 
     LayoutRect m_compositedBounds;
     LayoutSize m_subpixelOffsetFromRenderer; // This is the subpixel distance between the primary graphics layer and the associated renderer's bounds.
index 175d58d..8d82753 100644 (file)
@@ -758,7 +758,7 @@ bool RenderLayerCompositor::updateCompositingLayers(CompositingUpdateType update
 
     if (needHierarchyUpdate) {
         // Update the hierarchy of the compositing layers.
-        Vector<GraphicsLayer*> childList;
+        Vector<Ref<GraphicsLayer>> childList;
         rebuildCompositingLayerTree(*updateRoot, childList, 0);
 
         // Host the document layer in the RenderView's root layer.
@@ -769,7 +769,7 @@ bool RenderLayerCompositor::updateCompositingLayers(CompositingUpdateType update
             if (childList.isEmpty() && !hasAnyAdditionalCompositedLayers(*updateRoot))
                 destroyRootLayer();
             else if (m_rootContentLayer)
-                m_rootContentLayer->setChildren(childList);
+                m_rootContentLayer->setChildren(WTFMove(childList));
         }
         
         reattachSubframeScrollLayers();
@@ -802,12 +802,13 @@ bool RenderLayerCompositor::updateCompositingLayers(CompositingUpdateType update
     return true;
 }
 
-void RenderLayerCompositor::appendDocumentOverlayLayers(Vector<GraphicsLayer*>& childList)
+void RenderLayerCompositor::appendDocumentOverlayLayers(Vector<Ref<GraphicsLayer>>& childList)
 {
     if (!isMainFrameCompositor() || !m_compositing)
         return;
 
-    childList.append(&page().pageOverlayController().layerWithDocumentOverlays());
+    Ref<GraphicsLayer> overlayHost = page().pageOverlayController().layerWithDocumentOverlays();
+    childList.append(WTFMove(overlayHost));
 }
 
 void RenderLayerCompositor::layerBecameNonComposited(const RenderLayer& layer)
@@ -1523,7 +1524,7 @@ void RenderLayerCompositor::setCompositingParent(RenderLayer& childLayer, Render
         auto* hostingLayer = parentLayer->backing()->parentForSublayers();
         auto* hostedLayer = childLayer.backing()->childForSuperlayers();
         
-        hostingLayer->addChild(hostedLayer);
+        hostingLayer->addChild(*hostedLayer);
     } else
         childLayer.backing()->childForSuperlayers()->removeFromParent();
 }
@@ -1545,7 +1546,7 @@ bool RenderLayerCompositor::canAccelerateVideoRendering(RenderVideo& video) cons
 }
 #endif
 
-void RenderLayerCompositor::rebuildCompositingLayerTree(RenderLayer& layer, Vector<GraphicsLayer*>& childLayersOfEnclosingLayer, int depth)
+void RenderLayerCompositor::rebuildCompositingLayerTree(RenderLayer& layer, Vector<Ref<GraphicsLayer>>& childLayersOfEnclosingLayer, int depth)
 {
     // Make the layer compositing if necessary, and set up clipping and content layers.
     // Note that we can only do work here that is independent of whether the descendant layers
@@ -1581,8 +1582,8 @@ void RenderLayerCompositor::rebuildCompositingLayerTree(RenderLayer& layer, Vect
 
     // If this layer has backing, then we are collecting its children, otherwise appending
     // to the compositing child list of an enclosing layer.
-    Vector<GraphicsLayer*> layerChildren;
-    Vector<GraphicsLayer*>& childList = layerBacking ? layerChildren : childLayersOfEnclosingLayer;
+    Vector<Ref<GraphicsLayer>> layerChildren;
+    auto& childList = layerBacking ? layerChildren : childLayersOfEnclosingLayer;
 
 #if !ASSERT_DISABLED
     LayerListMutationDetector mutationChecker(&layer);
@@ -1594,7 +1595,7 @@ void RenderLayerCompositor::rebuildCompositingLayerTree(RenderLayer& layer, Vect
 
         // If a negative z-order child is compositing, we get a foreground layer which needs to get parented.
         if (layerBacking && layerBacking->foregroundLayer())
-            childList.append(layerBacking->foregroundLayer());
+            childList.append(*layerBacking->foregroundLayer());
     }
 
     if (auto* normalFlowList = layer.normalFlowList()) {
@@ -1613,28 +1614,28 @@ void RenderLayerCompositor::rebuildCompositingLayerTree(RenderLayer& layer, Vect
             parented = parentFrameContentLayers(&downcast<RenderWidget>(layer.renderer()));
 
         if (!parented)
-            layerBacking->parentForSublayers()->setChildren(layerChildren);
+            layerBacking->parentForSublayers()->setChildren(WTFMove(layerChildren));
 
         // If the layer has a clipping layer the overflow controls layers will be siblings of the clipping layer.
         // Otherwise, the overflow control layers are normal children.
         if (!layerBacking->hasClippingLayer() && !layerBacking->hasScrollingLayer()) {
             if (auto* overflowControlLayer = layerBacking->layerForHorizontalScrollbar()) {
                 overflowControlLayer->removeFromParent();
-                layerBacking->parentForSublayers()->addChild(overflowControlLayer);
+                layerBacking->parentForSublayers()->addChild(*overflowControlLayer);
             }
 
             if (auto* overflowControlLayer = layerBacking->layerForVerticalScrollbar()) {
                 overflowControlLayer->removeFromParent();
-                layerBacking->parentForSublayers()->addChild(overflowControlLayer);
+                layerBacking->parentForSublayers()->addChild(*overflowControlLayer);
             }
 
             if (auto* overflowControlLayer = layerBacking->layerForScrollCorner()) {
                 overflowControlLayer->removeFromParent();
-                layerBacking->parentForSublayers()->addChild(overflowControlLayer);
+                layerBacking->parentForSublayers()->addChild(*overflowControlLayer);
             }
         }
 
-        childLayersOfEnclosingLayer.append(layerBacking->childForSuperlayers());
+        childLayersOfEnclosingLayer.append(*layerBacking->childForSuperlayers());
     }
     
     if (auto* layerBacking = layer.backing())
@@ -1809,9 +1810,9 @@ bool RenderLayerCompositor::parentFrameContentLayers(RenderWidget* renderer)
     auto* backing = layer->backing();
     auto* hostingLayer = backing->parentForSublayers();
     auto* rootLayer = innerCompositor->rootGraphicsLayer();
-    if (hostingLayer->children().size() != 1 || hostingLayer->children()[0] != rootLayer) {
+    if (hostingLayer->children().size() != 1 || hostingLayer->children()[0].ptr() != rootLayer) {
         hostingLayer->removeAllChildren();
-        hostingLayer->addChild(rootLayer);
+        hostingLayer->addChild(*rootLayer);
     }
     return true;
 }
@@ -3046,7 +3047,7 @@ GraphicsLayer* RenderLayerCompositor::updateLayerForTopOverhangArea(bool wantsLa
     if (!m_layerForTopOverhangArea) {
         m_layerForTopOverhangArea = GraphicsLayer::create(graphicsLayerFactory(), *this);
         m_layerForTopOverhangArea->setName("top overhang");
-        m_scrollLayer->addChildBelow(m_layerForTopOverhangArea.get(), m_rootContentLayer.get());
+        m_scrollLayer->addChildBelow(*m_layerForTopOverhangArea, m_rootContentLayer.get());
     }
 
     return m_layerForTopOverhangArea.get();
@@ -3068,7 +3069,7 @@ GraphicsLayer* RenderLayerCompositor::updateLayerForBottomOverhangArea(bool want
     if (!m_layerForBottomOverhangArea) {
         m_layerForBottomOverhangArea = GraphicsLayer::create(graphicsLayerFactory(), *this);
         m_layerForBottomOverhangArea->setName("bottom overhang");
-        m_scrollLayer->addChildBelow(m_layerForBottomOverhangArea.get(), m_rootContentLayer.get());
+        m_scrollLayer->addChildBelow(*m_layerForBottomOverhangArea, m_rootContentLayer.get());
     }
 
     m_layerForBottomOverhangArea->setPosition(FloatPoint(0, m_rootContentLayer->size().height() + m_renderView.frameView().headerHeight()
@@ -3097,7 +3098,7 @@ GraphicsLayer* RenderLayerCompositor::updateLayerForHeader(bool wantsLayer)
     if (!m_layerForHeader) {
         m_layerForHeader = GraphicsLayer::create(graphicsLayerFactory(), *this);
         m_layerForHeader->setName("header");
-        m_scrollLayer->addChildAbove(m_layerForHeader.get(), m_rootContentLayer.get());
+        m_scrollLayer->addChildAbove(*m_layerForHeader, m_rootContentLayer.get());
         m_renderView.frameView().addPaintPendingMilestones(DidFirstFlushForHeaderLayer);
     }
 
@@ -3135,7 +3136,7 @@ GraphicsLayer* RenderLayerCompositor::updateLayerForFooter(bool wantsLayer)
     if (!m_layerForFooter) {
         m_layerForFooter = GraphicsLayer::create(graphicsLayerFactory(), *this);
         m_layerForFooter->setName("footer");
-        m_scrollLayer->addChildAbove(m_layerForFooter.get(), m_rootContentLayer.get());
+        m_scrollLayer->addChildAbove(*m_layerForFooter, m_rootContentLayer.get());
     }
 
     float totalContentHeight = m_rootContentLayer->size().height() + m_renderView.frameView().headerHeight() + m_renderView.frameView().footerHeight();
@@ -3258,7 +3259,7 @@ void RenderLayerCompositor::updateOverflowControlsLayers()
 
             // We want the overhang areas layer to be positioned below the frame contents,
             // so insert it below the clip layer.
-            m_overflowControlsHostLayer->addChildBelow(m_layerForOverhangAreas.get(), m_clipLayer.get());
+            m_overflowControlsHostLayer->addChildBelow(*m_layerForOverhangAreas, m_clipLayer.get());
         }
     } else if (m_layerForOverhangAreas) {
         m_layerForOverhangAreas->removeFromParent();
@@ -3274,7 +3275,7 @@ void RenderLayerCompositor::updateOverflowControlsLayers()
             m_contentShadowLayer->setAnchorPoint(FloatPoint3D());
             m_contentShadowLayer->setCustomAppearance(GraphicsLayer::CustomAppearance::ScrollingShadow);
 
-            m_scrollLayer->addChildBelow(m_contentShadowLayer.get(), m_rootContentLayer.get());
+            m_scrollLayer->addChildBelow(*m_contentShadowLayer, m_rootContentLayer.get());
         }
     } else if (m_contentShadowLayer) {
         m_contentShadowLayer->removeFromParent();
@@ -3291,7 +3292,7 @@ void RenderLayerCompositor::updateOverflowControlsLayers()
 #if PLATFORM(COCOA) && USE(CA)
             m_layerForHorizontalScrollbar->setAcceleratesDrawing(acceleratedDrawingEnabled());
 #endif
-            m_overflowControlsHostLayer->addChild(m_layerForHorizontalScrollbar.get());
+            m_overflowControlsHostLayer->addChild(*m_layerForHorizontalScrollbar);
 
             if (auto* scrollingCoordinator = this->scrollingCoordinator())
                 scrollingCoordinator->scrollableAreaScrollbarLayerDidChange(m_renderView.frameView(), HorizontalScrollbar);
@@ -3313,7 +3314,7 @@ void RenderLayerCompositor::updateOverflowControlsLayers()
 #if PLATFORM(COCOA) && USE(CA)
             m_layerForVerticalScrollbar->setAcceleratesDrawing(acceleratedDrawingEnabled());
 #endif
-            m_overflowControlsHostLayer->addChild(m_layerForVerticalScrollbar.get());
+            m_overflowControlsHostLayer->addChild(*m_layerForVerticalScrollbar);
 
             if (auto* scrollingCoordinator = this->scrollingCoordinator())
                 scrollingCoordinator->scrollableAreaScrollbarLayerDidChange(m_renderView.frameView(), VerticalScrollbar);
@@ -3335,7 +3336,7 @@ void RenderLayerCompositor::updateOverflowControlsLayers()
 #if PLATFORM(COCOA) && USE(CA)
             m_layerForScrollCorner->setAcceleratesDrawing(acceleratedDrawingEnabled());
 #endif
-            m_overflowControlsHostLayer->addChild(m_layerForScrollCorner.get());
+            m_overflowControlsHostLayer->addChild(*m_layerForScrollCorner);
         }
     } else if (m_layerForScrollCorner) {
         m_layerForScrollCorner->removeFromParent();
@@ -3387,9 +3388,9 @@ void RenderLayerCompositor::ensureRootLayer()
             m_scrollLayer->setName("frame scrolling");
 
             // Hook them up
-            m_overflowControlsHostLayer->addChild(m_clipLayer.get());
-            m_clipLayer->addChild(m_scrollLayer.get());
-            m_scrollLayer->addChild(m_rootContentLayer.get());
+            m_overflowControlsHostLayer->addChild(*m_clipLayer);
+            m_clipLayer->addChild(*m_scrollLayer);
+            m_scrollLayer->addChild(*m_rootContentLayer);
 
             m_clipLayer->setSize(m_renderView.frameView().sizeForVisibleContent());
             m_clipLayer->setPosition(positionForClipLayer());
@@ -3560,7 +3561,8 @@ void RenderLayerCompositor::rootLayerAttachmentChanged()
     if (!frame.isMainFrame())
         return;
 
-    m_rootContentLayer->addChild(&page().pageOverlayController().layerWithDocumentOverlays());
+    Ref<GraphicsLayer> overlayHost = page().pageOverlayController().layerWithDocumentOverlays();
+    m_rootContentLayer->addChild(WTFMove(overlayHost));
 }
 
 void RenderLayerCompositor::notifyIFramesOfCompositingChange()
index 2bf183b..a5d83b6 100644 (file)
@@ -376,7 +376,7 @@ private:
     void computeCompositingRequirements(RenderLayer* ancestorLayer, RenderLayer&, OverlapMap&, CompositingState&, bool& layersChanged, bool& descendantHas3DTransform);
 
     // Recurses down the tree, parenting descendant compositing layers and collecting an array of child layers for the current compositing layer.
-    void rebuildCompositingLayerTree(RenderLayer&, Vector<GraphicsLayer*>& childGraphicsLayersOfEnclosingLayer, int depth);
+    void rebuildCompositingLayerTree(RenderLayer&, Vector<Ref<GraphicsLayer>>& childGraphicsLayersOfEnclosingLayer, int depth);
 
     // Recurses down the tree, updating layer geometry only.
     void updateLayerTreeGeometry(RenderLayer&, int depth);
@@ -388,7 +388,7 @@ private:
     bool layerHas3DContent(const RenderLayer&) const;
     bool isRunningTransformAnimation(RenderLayerModelObject&) const;
 
-    void appendDocumentOverlayLayers(Vector<GraphicsLayer*>&);
+    void appendDocumentOverlayLayers(Vector<Ref<GraphicsLayer>>&);
     bool hasAnyAdditionalCompositedLayers(const RenderLayer& rootLayer) const;
 
     void ensureRootLayer();
@@ -488,7 +488,7 @@ private:
 
 private:
     RenderView& m_renderView;
-    std::unique_ptr<GraphicsLayer> m_rootContentLayer;
+    RefPtr<GraphicsLayer> m_rootContentLayer;
     Timer m_updateCompositingLayersTimer;
 
     ChromeClient::CompositingTriggerFlags m_compositingTriggers { static_cast<ChromeClient::CompositingTriggerFlags>(ChromeClient::AllTriggers) };
@@ -524,8 +524,8 @@ private:
     RootLayerAttachment m_rootLayerAttachment { RootLayerUnattached };
 
     // Enclosing clipping layer for iframe content
-    std::unique_ptr<GraphicsLayer> m_clipLayer;
-    std::unique_ptr<GraphicsLayer> m_scrollLayer;
+    RefPtr<GraphicsLayer> m_clipLayer;
+    RefPtr<GraphicsLayer> m_scrollLayer;
 
 #if PLATFORM(IOS)
     HashSet<RenderLayer*> m_scrollingLayers;
@@ -535,19 +535,19 @@ private:
     HashSet<RenderLayer*> m_scrollCoordinatedLayersNeedingUpdate;
 
     // Enclosing layer for overflow controls and the clipping layer
-    std::unique_ptr<GraphicsLayer> m_overflowControlsHostLayer;
+    RefPtr<GraphicsLayer> m_overflowControlsHostLayer;
 
     // Layers for overflow controls
-    std::unique_ptr<GraphicsLayer> m_layerForHorizontalScrollbar;
-    std::unique_ptr<GraphicsLayer> m_layerForVerticalScrollbar;
-    std::unique_ptr<GraphicsLayer> m_layerForScrollCorner;
+    RefPtr<GraphicsLayer> m_layerForHorizontalScrollbar;
+    RefPtr<GraphicsLayer> m_layerForVerticalScrollbar;
+    RefPtr<GraphicsLayer> m_layerForScrollCorner;
 #if ENABLE(RUBBER_BANDING)
-    std::unique_ptr<GraphicsLayer> m_layerForOverhangAreas;
-    std::unique_ptr<GraphicsLayer> m_contentShadowLayer;
-    std::unique_ptr<GraphicsLayer> m_layerForTopOverhangArea;
-    std::unique_ptr<GraphicsLayer> m_layerForBottomOverhangArea;
-    std::unique_ptr<GraphicsLayer> m_layerForHeader;
-    std::unique_ptr<GraphicsLayer> m_layerForFooter;
+    RefPtr<GraphicsLayer> m_layerForOverhangAreas;
+    RefPtr<GraphicsLayer> m_contentShadowLayer;
+    RefPtr<GraphicsLayer> m_layerForTopOverhangArea;
+    RefPtr<GraphicsLayer> m_layerForBottomOverhangArea;
+    RefPtr<GraphicsLayer> m_layerForHeader;
+    RefPtr<GraphicsLayer> m_layerForFooter;
 #endif
 
     std::unique_ptr<GraphicsLayerUpdater> m_layerUpdater; // Updates tiled layer visible area periodically while animations are running.
index e98a001..52386e1 100644 (file)
@@ -1,3 +1,31 @@
+2018-09-11  Simon Fraser  <simon.fraser@apple.com>
+
+        Make GraphicsLayers ref-counted, so their tree can persist when disconnected from RenderLayerBackings
+        https://bugs.webkit.org/show_bug.cgi?id=189521
+
+        Reviewed by Tim Horton.
+
+        Make GraphicsLayer be RefCounted<GraphicsLayer>. GraphicsLayers own their children, via a Vector<Ref<GraphicsLayer>>.
+        
+        RenderLayerBacking and other holders of GraphicsLayers use RefPtr<GraphicsLayer>.
+        
+        All the other changes are just to adapt to the new ownership patterns.
+        
+        I verified that no GraphicsLayers were leaked or abandoned after this change.
+
+        * WebProcess/WebCoreSupport/WebInspectorClient.cpp:
+        (WebKit::WebInspectorClient::~WebInspectorClient):
+        (WebKit::WebInspectorClient::showPaintRect):
+        (WebKit::WebInspectorClient::animationEndedForLayer):
+        * WebProcess/WebCoreSupport/WebInspectorClient.h:
+        * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeContext.h:
+        * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeContext.mm:
+        (WebKit::RemoteLayerTreeContext::createGraphicsLayer):
+        * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.h:
+        * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.mm:
+        (WebKit::RemoteLayerTreeDrawingArea::updateRootLayers):
+        (WebKit::RemoteLayerTreeDrawingArea::flushLayers):
+
 2018-09-12  Chris Dumez  <cdumez@apple.com>
 
         PSON: No process swap on back navigation after URL bar navigation
index a51a4a3..81423ec 100644 (file)
@@ -66,10 +66,10 @@ WebInspectorClient::WebInspectorClient(WebPage* page)
 
 WebInspectorClient::~WebInspectorClient()
 {
-    for (auto layer : m_paintRectLayers) {
+    for (auto& layer : m_paintRectLayers)
         layer->removeFromParent();
-        delete layer;
-    }
+    
+    m_paintRectLayers.clear();
 
     if (m_paintRectOverlay && m_page->corePage())
         m_page->corePage()->pageOverlayController().uninstallPageOverlay(*m_paintRectOverlay, PageOverlay::FadeMode::Fade);
@@ -152,7 +152,7 @@ void WebInspectorClient::showPaintRect(const FloatRect& rect)
     if (!m_paintIndicatorLayerClient)
         m_paintIndicatorLayerClient = std::make_unique<RepaintIndicatorLayerClient>(*this);
 
-    std::unique_ptr<GraphicsLayer> paintLayer = GraphicsLayer::create(m_page->drawingArea()->graphicsLayerFactory(), *m_paintIndicatorLayerClient);
+    auto paintLayer = GraphicsLayer::create(m_page->drawingArea()->graphicsLayerFactory(), *m_paintIndicatorLayerClient);
     
     paintLayer->setName("paint rect");
     paintLayer->setAnchorPoint(FloatPoint3D());
@@ -165,22 +165,23 @@ void WebInspectorClient::showPaintRect(const FloatRect& rect)
 
     fadeKeyframes.insert(std::make_unique<FloatAnimationValue>(0.25, 0));
     
-    RefPtr<Animation> opacityAnimation = Animation::create();
+    auto opacityAnimation = Animation::create();
     opacityAnimation->setDuration(0.25);
 
-    paintLayer->addAnimation(fadeKeyframes, FloatSize(), opacityAnimation.get(), "opacity"_s, 0);
+    paintLayer->addAnimation(fadeKeyframes, FloatSize(), opacityAnimation.ptr(), "opacity"_s, 0);
     
-    m_paintRectLayers.add(paintLayer.get());
+    GraphicsLayer& rawLayer = paintLayer.get();
+    m_paintRectLayers.add(WTFMove(paintLayer));
 
     GraphicsLayer& overlayRootLayer = m_paintRectOverlay->layer();
-    overlayRootLayer.addChild(paintLayer.release());
+    overlayRootLayer.addChild(rawLayer);
 }
 
 void WebInspectorClient::animationEndedForLayer(const GraphicsLayer* layer)
 {
-    const_cast<GraphicsLayer*>(layer)->removeFromParent();
-    m_paintRectLayers.remove(const_cast<GraphicsLayer*>(layer));
-    delete layer;
+    GraphicsLayer* nonConstLayer = const_cast<GraphicsLayer*>(layer);
+    nonConstLayer->removeFromParent();
+    m_paintRectLayers.remove(*nonConstLayer);
 }
 
 #if PLATFORM(IOS)
index 9c214ce..e974695 100644 (file)
@@ -84,7 +84,7 @@ private:
     
     RefPtr<WebCore::PageOverlay> m_paintRectOverlay;
     std::unique_ptr<RepaintIndicatorLayerClient> m_paintIndicatorLayerClient;
-    HashSet<WebCore::GraphicsLayer*> m_paintRectLayers; // Ideally this would be HashSet<std::unique_ptr<GraphicsLayer>> but that doesn't work yet. webkit.org/b/136166
+    HashSet<Ref<WebCore::GraphicsLayer>> m_paintRectLayers;
 };
 
 } // namespace WebKit
index 36d52b6..ae37833 100644 (file)
@@ -85,7 +85,7 @@ void CompositingCoordinator::setRootCompositingLayer(GraphicsLayer* graphicsLaye
 
     m_rootCompositingLayer = graphicsLayer;
     if (m_rootCompositingLayer)
-        m_rootLayer->addChildAtIndex(m_rootCompositingLayer, 0);
+        m_rootLayer->addChildAtIndex(*m_rootCompositingLayer, 0);
 }
 
 void CompositingCoordinator::setViewOverlayRootLayer(GraphicsLayer* graphicsLayer)
@@ -98,7 +98,7 @@ void CompositingCoordinator::setViewOverlayRootLayer(GraphicsLayer* graphicsLaye
 
     m_overlayCompositingLayer = graphicsLayer;
     if (m_overlayCompositingLayer)
-        m_rootLayer->addChild(m_overlayCompositingLayer);
+        m_rootLayer->addChild(*m_overlayCompositingLayer);
 }
 
 void CompositingCoordinator::sizeDidChange(const IntSize& newSize)
@@ -231,15 +231,15 @@ float CompositingCoordinator::pageScaleFactor() const
     return m_page->pageScaleFactor();
 }
 
-std::unique_ptr<GraphicsLayer> CompositingCoordinator::createGraphicsLayer(GraphicsLayer::Type layerType, GraphicsLayerClient& client)
+Ref<GraphicsLayer> CompositingCoordinator::createGraphicsLayer(GraphicsLayer::Type layerType, GraphicsLayerClient& client)
 {
-    CoordinatedGraphicsLayer* layer = new CoordinatedGraphicsLayer(layerType, client);
+    auto layer = adoptRef(*new CoordinatedGraphicsLayer(layerType, client));
     layer->setCoordinator(this);
     m_nicosia.state.layers.add(layer->compositionLayer());
-    m_registeredLayers.add(layer->id(), layer);
+    m_registeredLayers.add(layer->id(), layer.ptr());
     layer->setNeedsVisibleRectAdjustment();
-    notifyFlushRequired(layer);
-    return std::unique_ptr<GraphicsLayer>(layer);
+    notifyFlushRequired(layer.ptr());
+    return WTFMove(layer);
 }
 
 FloatRect CompositingCoordinator::visibleContentsRect() const
index 6ba85f1..b4a0d15 100644 (file)
@@ -103,7 +103,7 @@ private:
     void syncLayerState() override;
 
     // GraphicsLayerFactory
-    std::unique_ptr<WebCore::GraphicsLayer> createGraphicsLayer(WebCore::GraphicsLayer::Type, WebCore::GraphicsLayerClient&) override;
+    Ref<WebCore::GraphicsLayer> createGraphicsLayer(WebCore::GraphicsLayer::Type, WebCore::GraphicsLayerClient&) override;
 
     void initializeRootCompositingLayerIfNeeded();
 
@@ -114,7 +114,7 @@ private:
     WebCore::Page* m_page;
     CompositingCoordinator::Client& m_client;
 
-    std::unique_ptr<WebCore::GraphicsLayer> m_rootLayer;
+    RefPtr<WebCore::GraphicsLayer> m_rootLayer;
     WebCore::GraphicsLayer* m_rootCompositingLayer { nullptr };
     WebCore::GraphicsLayer* m_overlayCompositingLayer { nullptr };
 
index e3d3f5a..9a413f3 100644 (file)
@@ -74,7 +74,7 @@ public:
 
 private:
     // WebCore::GraphicsLayerFactory
-    std::unique_ptr<WebCore::GraphicsLayer> createGraphicsLayer(WebCore::GraphicsLayer::Type, WebCore::GraphicsLayerClient&) override;
+    Ref<WebCore::GraphicsLayer> createGraphicsLayer(WebCore::GraphicsLayer::Type, WebCore::GraphicsLayerClient&) override;
 
     WebPage& m_webPage;
 
index 9677dda..4281194 100644 (file)
@@ -109,9 +109,9 @@ bool RemoteLayerTreeContext::backingStoreWillBeDisplayed(RemoteLayerBackingStore
     return m_backingStoreCollection.backingStoreWillBeDisplayed(backingStore);
 }
 
-std::unique_ptr<GraphicsLayer> RemoteLayerTreeContext::createGraphicsLayer(WebCore::GraphicsLayer::Type layerType, GraphicsLayerClient& client)
+Ref<GraphicsLayer> RemoteLayerTreeContext::createGraphicsLayer(WebCore::GraphicsLayer::Type layerType, GraphicsLayerClient& client)
 {
-    return std::make_unique<GraphicsLayerCARemote>(layerType, client, *this);
+    return adoptRef(*new GraphicsLayerCARemote(layerType, client, *this));
 }
 
 void RemoteLayerTreeContext::buildTransaction(RemoteLayerTreeTransaction& transaction, PlatformCALayer& rootLayer)
index 747cfd4..ba7fd8b 100644 (file)
@@ -137,7 +137,7 @@ private:
     };
 
     std::unique_ptr<RemoteLayerTreeContext> m_remoteLayerTreeContext;
-    std::unique_ptr<WebCore::GraphicsLayer> m_rootLayer;
+    Ref<WebCore::GraphicsLayer> m_rootLayer;
 
     WebCore::IntSize m_viewSize;
 
index 837d6c5..3f5ceed 100644 (file)
@@ -115,14 +115,14 @@ void RemoteLayerTreeDrawingArea::willDestroyDisplayRefreshMonitor(DisplayRefresh
 
 void RemoteLayerTreeDrawingArea::updateRootLayers()
 {
-    Vector<GraphicsLayer*> children;
+    Vector<Ref<GraphicsLayer>> children;
     if (m_contentLayer) {
-        children.append(m_contentLayer);
+        children.append(*m_contentLayer);
         if (m_viewOverlayRootLayer)
-            children.append(m_viewOverlayRootLayer);
+            children.append(*m_viewOverlayRootLayer);
     }
 
-    m_rootLayer->setChildren(children);
+    m_rootLayer->setChildren(WTFMove(children));
 }
 
 void RemoteLayerTreeDrawingArea::attachViewOverlayGraphicsLayer(Frame* frame, GraphicsLayer* viewOverlayRootLayer)
@@ -318,9 +318,6 @@ bool RemoteLayerTreeDrawingArea::adjustLayerFlushThrottling(WebCore::LayerFlushT
 
 void RemoteLayerTreeDrawingArea::flushLayers()
 {
-    if (!m_rootLayer)
-        return;
-
     if (m_isFlushingSuspended) {
         m_hasDeferredFlush = true;
         return;
@@ -366,7 +363,7 @@ void RemoteLayerTreeDrawingArea::flushLayers()
     layerTransaction.setTransactionID(takeNextTransactionID());
     layerTransaction.setCallbackIDs(WTFMove(m_pendingCallbackIDs));
     m_remoteLayerTreeContext->setNextFlushIsForImmediatePaint(m_nextFlushIsForImmediatePaint);
-    m_remoteLayerTreeContext->buildTransaction(layerTransaction, *downcast<GraphicsLayerCARemote>(*m_rootLayer).platformCALayer());
+    m_remoteLayerTreeContext->buildTransaction(layerTransaction, *downcast<GraphicsLayerCARemote>(m_rootLayer.get()).platformCALayer());
     m_remoteLayerTreeContext->setNextFlushIsForImmediatePaint(false);
     backingStoreCollection.willCommitLayerTree(layerTransaction);
     m_webPage.willCommitLayerTree(layerTransaction);
index 18d5c5c..a52b120 100644 (file)
@@ -97,7 +97,7 @@ void AcceleratedCompositingContext::initialize()
     m_nonCompositedContentLayer->setName("Non-composited content");
 #endif
 
-    m_rootLayer->addChild(m_nonCompositedContentLayer.get());
+    m_rootLayer->addChild(*m_nonCompositedContentLayer);
     m_nonCompositedContentLayer->setNeedsDisplay();
 
     // The creation of the TextureMapper needs an active OpenGL context.
@@ -211,7 +211,7 @@ void AcceleratedCompositingContext::setRootCompositingLayer(GraphicsLayer* graph
         return;
 
     m_nonCompositedContentLayer->removeAllChildren();
-    m_nonCompositedContentLayer->addChild(graphicsLayer);
+    m_nonCompositedContentLayer->addChild(*graphicsLayer);
 
     stopAnyPendingLayerFlush();
 
index f7f3842..6bb334d 100644 (file)
@@ -71,8 +71,8 @@ private:
     WebView& m_webView;
     std::unique_ptr<WebCore::GLContext> m_context;
     HWND m_window;
-    std::unique_ptr<WebCore::GraphicsLayer> m_rootLayer;
-    std::unique_ptr<WebCore::GraphicsLayer> m_nonCompositedContentLayer;
+    RefPtr<WebCore::GraphicsLayer> m_rootLayer;
+    RefPtr<WebCore::GraphicsLayer> m_nonCompositedContentLayer;
     std::unique_ptr<WebCore::TextureMapper> m_textureMapper;
     WebCore::TextureMapperFPSCounter m_fpsCounter;
 
index 9ffd8c4..0d9fcab 100644 (file)
@@ -7145,7 +7145,12 @@ void WebView::setRootChildLayer(GraphicsLayer* layer)
 #if USE(CA)
     if (!m_backingLayer)
         return;
-    m_backingLayer->addChild(layer);
+
+    if (layer)
+        m_backingLayer->addChild(*layer);
+    else
+        m_backingLayer->removeAllChildren();
+
 #elif USE(TEXTURE_MAPPER_GL)
     if (!m_acceleratedCompositingContext)
         return;
index 2c6264e..3cfd667 100644 (file)
@@ -705,7 +705,7 @@ protected:
     void setAcceleratedCompositing(bool);
 #if USE(CA)
     RefPtr<WebCore::CACFLayerTreeHost> m_layerTreeHost;
-    std::unique_ptr<WebCore::GraphicsLayer> m_backingLayer;
+    RefPtr<WebCore::GraphicsLayer> m_backingLayer;
 #elif USE(TEXTURE_MAPPER_GL)
     std::unique_ptr<AcceleratedCompositingContext> m_acceleratedCompositingContext;
 #endif