Changeset 235953 in webkit
- Timestamp:
- Sep 12, 2018, 2:27:07 PM (7 years ago)
- Location:
- trunk/Source
- Files:
-
- 34 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r235949 r235953 1 2018-09-11 Simon Fraser <simon.fraser@apple.com> 2 3 Make GraphicsLayers ref-counted, so their tree can persist when disconnected from RenderLayerBackings 4 https://bugs.webkit.org/show_bug.cgi?id=189521 5 6 Reviewed by Tim Horton. 7 8 Make GraphicsLayer be RefCounted<GraphicsLayer>. GraphicsLayers own their children, via a Vector<Ref<GraphicsLayer>>. 9 10 RenderLayerBacking and other holders of GraphicsLayers use RefPtr<GraphicsLayer>. 11 12 All the other changes are just to adapt to the new ownership patterns. 13 14 I verified that no GraphicsLayers were leaked or abandoned after this change. 15 16 No behavior change. 17 18 * page/PageOverlayController.cpp: 19 (WebCore::PageOverlayController::layerWithDocumentOverlays): 20 (WebCore::PageOverlayController::layerWithViewOverlays): 21 (WebCore::PageOverlayController::installPageOverlay): 22 (WebCore::PageOverlayController::uninstallPageOverlay): 23 (WebCore::PageOverlayController::setPageOverlayNeedsDisplay): 24 (WebCore::PageOverlayController::didChangeViewSize): 25 (WebCore::PageOverlayController::didChangeDocumentSize): 26 (WebCore::PageOverlayController::didChangeSettings): 27 (WebCore::PageOverlayController::paintContents): 28 (WebCore::PageOverlayController::didChangeOverlayFrame): 29 (WebCore::PageOverlayController::didChangeOverlayBackgroundColor): 30 * page/PageOverlayController.h: 31 * page/mac/ServicesOverlayController.h: 32 (WebCore::ServicesOverlayController::Highlight::layer const): 33 * page/mac/ServicesOverlayController.mm: 34 (WebCore::ServicesOverlayController::Highlight::Highlight): 35 (WebCore::ServicesOverlayController::Highlight::invalidate): 36 (WebCore::ServicesOverlayController::Highlight::fadeIn): 37 (WebCore::ServicesOverlayController::Highlight::fadeOut): 38 (WebCore::ServicesOverlayController::Highlight::didFinishFadeOutAnimation): 39 (WebCore::ServicesOverlayController::determineActiveHighlight): 40 * platform/graphics/GraphicsLayer.cpp: 41 (WebCore::GraphicsLayer::GraphicsLayer): 42 (WebCore::GraphicsLayer::willBeDestroyed): 43 (WebCore::GraphicsLayer::setChildren): 44 (WebCore::GraphicsLayer::addChild): 45 (WebCore::GraphicsLayer::addChildAtIndex): 46 (WebCore::GraphicsLayer::addChildBelow): 47 (WebCore::GraphicsLayer::addChildAbove): 48 (WebCore::GraphicsLayer::replaceChild): 49 (WebCore::GraphicsLayer::removeAllChildren): 50 (WebCore::GraphicsLayer::removeFromParent): 51 (WebCore::GraphicsLayer::setMaskLayer): 52 (WebCore::GraphicsLayer::noteDeviceOrPageScaleFactorChangedIncludingDescendants): 53 (WebCore::GraphicsLayer::distributeOpacity): 54 (WebCore::GraphicsLayer::traverse): 55 (WebCore::dumpChildren): 56 * platform/graphics/GraphicsLayer.h: 57 (WebCore::GraphicsLayer::children const): 58 (WebCore::GraphicsLayer::children): 59 (WebCore::GraphicsLayer::maskLayer const): 60 (WebCore::GraphicsLayer::replicaLayer const): 61 (WebCore::GraphicsLayer::beingDestroyed const): 62 (WebCore::GraphicsLayer:: const): Deleted. 63 * platform/graphics/GraphicsLayerFactory.h: 64 * platform/graphics/ca/GraphicsLayerCA.cpp: 65 (WebCore::GraphicsLayer::create): 66 (WebCore::GraphicsLayerCA::setChildren): 67 (WebCore::GraphicsLayerCA::addChild): 68 (WebCore::GraphicsLayerCA::addChildAtIndex): 69 (WebCore::GraphicsLayerCA::addChildBelow): 70 (WebCore::GraphicsLayerCA::addChildAbove): 71 (WebCore::GraphicsLayerCA::replaceChild): 72 (WebCore::GraphicsLayerCA::setMaskLayer): 73 (WebCore::GraphicsLayerCA::recursiveVisibleRectChangeRequiresFlush const): 74 (WebCore::GraphicsLayerCA::recursiveCommitChanges): 75 (WebCore::GraphicsLayerCA::updateSublayerList): 76 (WebCore::GraphicsLayerCA::createTransformAnimationsFromKeyframes): 77 * platform/graphics/ca/GraphicsLayerCA.h: 78 * platform/graphics/texmap/GraphicsLayerTextureMapper.cpp: 79 (WebCore::GraphicsLayer::create): 80 (WebCore::GraphicsLayerTextureMapper::setChildren): 81 (WebCore::GraphicsLayerTextureMapper::addChild): 82 (WebCore::GraphicsLayerTextureMapper::addChildAtIndex): 83 (WebCore::GraphicsLayerTextureMapper::addChildAbove): 84 (WebCore::GraphicsLayerTextureMapper::addChildBelow): 85 (WebCore::GraphicsLayerTextureMapper::replaceChild): 86 (WebCore::GraphicsLayerTextureMapper::setMaskLayer): 87 (WebCore::GraphicsLayerTextureMapper::updateBackingStoreIncludingSubLayers): 88 * platform/graphics/texmap/GraphicsLayerTextureMapper.h: 89 * platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp: 90 (WebCore::GraphicsLayer::create): 91 (WebCore::CoordinatedGraphicsLayer::setShouldUpdateVisibleRect): 92 (WebCore::CoordinatedGraphicsLayer::addChild): 93 (WebCore::CoordinatedGraphicsLayer::addChildAtIndex): 94 (WebCore::CoordinatedGraphicsLayer::addChildAbove): 95 (WebCore::CoordinatedGraphicsLayer::addChildBelow): 96 (WebCore::CoordinatedGraphicsLayer::replaceChild): 97 (WebCore::CoordinatedGraphicsLayer::setMaskLayer): 98 (WebCore::CoordinatedGraphicsLayer::syncPendingStateChangesIncludingSubLayers): 99 (WebCore::CoordinatedGraphicsLayer::updateContentBuffersIncludingSubLayers): 100 (WebCore::CoordinatedGraphicsLayer::setCoordinatorIncludingSubLayersIfNeeded): 101 * platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.h: 102 * platform/graphics/win/GraphicsLayerDirect2D.cpp: 103 (WebCore::GraphicsLayer::create): 104 (WebCore::GraphicsLayerDirect2D::GraphicsLayerDirect2D): Deleted. 105 (WebCore::GraphicsLayerDirect2D::initialize): Deleted. 106 (WebCore::GraphicsLayerDirect2D::~GraphicsLayerDirect2D): Deleted. 107 (WebCore::GraphicsLayerDirect2D::setNeedsDisplay): Deleted. 108 (WebCore::GraphicsLayerDirect2D::setNeedsDisplayInRect): Deleted. 109 * rendering/RenderLayerBacking.cpp: 110 (WebCore::RenderLayerBacking::createGraphicsLayer): 111 (WebCore::RenderLayerBacking::createPrimaryGraphicsLayer): 112 (WebCore::RenderLayerBacking::updateConfiguration): 113 (WebCore::RenderLayerBacking::updateInternalHierarchy): 114 (WebCore::RenderLayerBacking::updateMaskingLayer): 115 (WebCore::RenderLayerBacking::updateChildClippingStrategy): 116 (WebCore::RenderLayerBacking::updateScrollingLayers): 117 * rendering/RenderLayerBacking.h: 118 * rendering/RenderLayerCompositor.cpp: 119 (WebCore::RenderLayerCompositor::updateCompositingLayers): 120 (WebCore::RenderLayerCompositor::appendDocumentOverlayLayers): 121 (WebCore::RenderLayerCompositor::setCompositingParent): 122 (WebCore::RenderLayerCompositor::rebuildCompositingLayerTree): 123 (WebCore::RenderLayerCompositor::parentFrameContentLayers): 124 (WebCore::RenderLayerCompositor::updateLayerForTopOverhangArea): 125 (WebCore::RenderLayerCompositor::updateLayerForBottomOverhangArea): 126 (WebCore::RenderLayerCompositor::updateLayerForHeader): 127 (WebCore::RenderLayerCompositor::updateLayerForFooter): 128 (WebCore::RenderLayerCompositor::updateOverflowControlsLayers): 129 (WebCore::RenderLayerCompositor::ensureRootLayer): 130 (WebCore::RenderLayerCompositor::rootLayerAttachmentChanged): 131 * rendering/RenderLayerCompositor.h: 132 1 133 2018-09-12 Alex Christensen <achristensen@webkit.org> 2 134 -
trunk/Source/WebCore/page/PageOverlayController.cpp
r230211 r235953 44 44 45 45 PageOverlayController::PageOverlayController(Page& page) 46 : m_initialized(false) 47 , m_page(page) 46 : m_page(page) 48 47 { 49 48 } … … 99 98 continue; 100 99 101 GraphicsLayer& layer = *overlayAndLayer.value;102 GraphicsLayer::traverse(layer , [inWindow](GraphicsLayer& layer) {100 auto& layer = overlayAndLayer.value; 101 GraphicsLayer::traverse(layer.get(), [inWindow](GraphicsLayer& layer) { 103 102 layer.setIsInWindow(inWindow); 104 103 }); 105 updateOverlayGeometry(overlay, layer );104 updateOverlayGeometry(overlay, layer.get()); 106 105 107 if (!layer .parent())108 m_documentOverlayRootLayer->addChild( &layer);106 if (!layer->parent()) 107 m_documentOverlayRootLayer->addChild(layer.copyRef()); 109 108 } 110 109 … … 123 122 continue; 124 123 125 GraphicsLayer& layer = *overlayAndLayer.value;126 GraphicsLayer::traverse(layer , [inWindow](GraphicsLayer& layer) {124 auto& layer = overlayAndLayer.value; 125 GraphicsLayer::traverse(layer.get(), [inWindow](GraphicsLayer& layer) { 127 126 layer.setIsInWindow(inWindow); 128 127 }); 129 updateOverlayGeometry(overlay, layer );128 updateOverlayGeometry(overlay, layer.get()); 130 129 131 if (!layer .parent())132 m_viewOverlayRootLayer->addChild( &layer);130 if (!layer->parent()) 131 m_viewOverlayRootLayer->addChild(layer.copyRef()); 133 132 } 134 133 … … 145 144 m_pageOverlays.append(&overlay); 146 145 147 std::unique_ptr<GraphicsLayer>layer = GraphicsLayer::create(m_page.chrome().client().graphicsLayerFactory(), *this);146 auto layer = GraphicsLayer::create(m_page.chrome().client().graphicsLayerFactory(), *this); 148 147 layer->setAnchorPoint(FloatPoint3D()); 149 148 layer->setBackgroundColor(overlay.backgroundColor()); 150 149 layer->setName("Overlay content"); 151 150 152 updateSettingsForLayer( *layer);151 updateSettingsForLayer(layer.get()); 153 152 154 153 switch (overlay.overlayType()) { … … 161 160 } 162 161 163 GraphicsLayer& rawLayer = *layer;162 auto& rawLayer = layer.get(); 164 163 m_overlayGraphicsLayers.set(&overlay, WTFMove(layer)); 165 164 … … 186 185 overlay.setPage(nullptr); 187 186 188 m_overlayGraphicsLayers.take(&overlay)->removeFromParent(); 187 if (auto optionalLayer = m_overlayGraphicsLayers.take(&overlay)) 188 optionalLayer.value()->removeFromParent(); 189 189 190 190 bool removed = m_pageOverlays.removeFirst(&overlay); … … 212 212 { 213 213 ASSERT(m_pageOverlays.contains(&overlay)); 214 GraphicsLayer& graphicsLayer = *m_overlayGraphicsLayers.get(&overlay);215 216 if (!graphicsLayer .drawsContent()) {217 graphicsLayer .setDrawsContent(true);218 updateOverlayGeometry(overlay, graphicsLayer);219 } 220 221 graphicsLayer .setNeedsDisplayInRect(dirtyRect);214 auto* graphicsLayer = m_overlayGraphicsLayers.get(&overlay); 215 216 if (!graphicsLayer->drawsContent()) { 217 graphicsLayer->setDrawsContent(true); 218 updateOverlayGeometry(overlay, *graphicsLayer); 219 } 220 221 graphicsLayer->setNeedsDisplayInRect(dirtyRect); 222 222 } 223 223 … … 242 242 void PageOverlayController::willDetachRootLayer() 243 243 { 244 m_documentOverlayRootLayer = nullptr; 245 m_viewOverlayRootLayer = nullptr; 244 if (m_documentOverlayRootLayer) { 245 m_documentOverlayRootLayer->removeFromParent(); 246 m_documentOverlayRootLayer = nullptr; 247 } 248 249 if (m_viewOverlayRootLayer) { 250 m_viewOverlayRootLayer->removeFromParent(); 251 m_viewOverlayRootLayer = nullptr; 252 } 246 253 m_initialized = false; 247 254 } … … 251 258 for (auto& overlayAndLayer : m_overlayGraphicsLayers) { 252 259 if (overlayAndLayer.key->overlayType() == PageOverlay::OverlayType::View) 253 updateOverlayGeometry(*overlayAndLayer.key, *overlayAndLayer.value);260 updateOverlayGeometry(*overlayAndLayer.key, overlayAndLayer.value.get()); 254 261 } 255 262 } … … 259 266 for (auto& overlayAndLayer : m_overlayGraphicsLayers) { 260 267 if (overlayAndLayer.key->overlayType() == PageOverlay::OverlayType::Document) 261 updateOverlayGeometry(*overlayAndLayer.key, *overlayAndLayer.value);268 updateOverlayGeometry(*overlayAndLayer.key, overlayAndLayer.value.get()); 262 269 } 263 270 } … … 267 274 // FIXME: We should apply these settings to all overlay sublayers recursively. 268 275 for (auto& graphicsLayer : m_overlayGraphicsLayers.values()) 269 updateSettingsForLayer( *graphicsLayer);276 updateSettingsForLayer(graphicsLayer.get()); 270 277 } 271 278 … … 360 367 { 361 368 for (auto& overlayAndGraphicsLayer : m_overlayGraphicsLayers) { 362 if (overlayAndGraphicsLayer.value. get() != graphicsLayer)369 if (overlayAndGraphicsLayer.value.ptr() != graphicsLayer) 363 370 continue; 364 371 … … 384 391 { 385 392 ASSERT(m_pageOverlays.contains(&overlay)); 386 updateOverlayGeometry(overlay, *m_overlayGraphicsLayers.get(&overlay)); 393 if (auto* layer = m_overlayGraphicsLayers.get(&overlay)) 394 updateOverlayGeometry(overlay, *layer); 387 395 } 388 396 … … 390 398 { 391 399 ASSERT(m_pageOverlays.contains(&overlay)); 392 m_overlayGraphicsLayers.get(&overlay)->setBackgroundColor(overlay.backgroundColor()); 400 if (auto* layer = m_overlayGraphicsLayers.get(&overlay)) 401 layer->setBackgroundColor(overlay.backgroundColor()); 393 402 } 394 403 -
trunk/Source/WebCore/page/PageOverlayController.h
r230211 r235953 93 93 void tiledBackingUsageChanged(const GraphicsLayer*, bool) override; 94 94 95 std::unique_ptr<GraphicsLayer> m_documentOverlayRootLayer;96 std::unique_ptr<GraphicsLayer> m_viewOverlayRootLayer;97 bool m_initialized;95 Page& m_page; 96 RefPtr<GraphicsLayer> m_documentOverlayRootLayer; 97 RefPtr<GraphicsLayer> m_viewOverlayRootLayer; 98 98 99 HashMap<PageOverlay*, std::unique_ptr<GraphicsLayer>> m_overlayGraphicsLayers;99 HashMap<PageOverlay*, Ref<GraphicsLayer>> m_overlayGraphicsLayers; 100 100 Vector<RefPtr<PageOverlay>> m_pageOverlays; 101 Page& m_page;101 bool m_initialized { false }; 102 102 }; 103 103 -
trunk/Source/WebCore/page/ResourceUsageOverlay.h
r225470 r235953 84 84 85 85 #if OS(LINUX) 86 std::unique_ptr<GraphicsLayer> m_paintLayer;86 RefPtr<GraphicsLayer> m_paintLayer; 87 87 std::unique_ptr<GraphicsLayerClient> m_overlayPainter; 88 88 #endif -
trunk/Source/WebCore/page/linux/ResourceUsageOverlayLinux.cpp
r234501 r235953 138 138 m_paintLayer->setBackgroundColor(Color(0.0f, 0.0f, 0.0f, 0.8f)); 139 139 m_paintLayer->setDrawsContent(true); 140 overlay().layer().addChild( m_paintLayer.get());140 overlay().layer().addChild(*m_paintLayer); 141 141 142 142 ResourceUsageThread::addObserver(this, [this] (const ResourceUsageData& data) { -
trunk/Source/WebCore/page/mac/ServicesOverlayController.h
r230211 r235953 64 64 DDHighlightRef ddHighlight() const { return m_ddHighlight.get(); } 65 65 Range& range() const { return m_range.get(); } 66 GraphicsLayer *layer() const { return m_graphicsLayer.get(); }66 GraphicsLayer& layer() const { return m_graphicsLayer.get(); } 67 67 68 68 enum { … … 88 88 void didFinishFadeOutAnimation(); 89 89 90 ServicesOverlayController* m_controller; 90 91 RetainPtr<DDHighlightRef> m_ddHighlight; 91 92 Ref<Range> m_range; 92 std::unique_ptr<GraphicsLayer> m_graphicsLayer;93 Ref<GraphicsLayer> m_graphicsLayer; 93 94 Type m_type; 94 ServicesOverlayController* m_controller;95 95 }; 96 96 -
trunk/Source/WebCore/page/mac/ServicesOverlayController.mm
r235935 r235953 67 67 68 68 ServicesOverlayController::Highlight::Highlight(ServicesOverlayController& controller, Type type, RetainPtr<DDHighlightRef> ddHighlight, Ref<WebCore::Range>&& range) 69 : m_range(WTFMove(range)) 69 : m_controller(&controller) 70 , m_range(WTFMove(range)) 71 , m_graphicsLayer(GraphicsLayer::create(controller.page().chrome().client().graphicsLayerFactory(), *this)) 70 72 , m_type(type) 71 , m_controller(&controller)72 73 { 73 74 ASSERT(ddHighlight); 74 75 75 auto& page = controller.page();76 m_graphicsLayer = GraphicsLayer::create(page.chrome().client().graphicsLayerFactory(), *this);77 76 m_graphicsLayer->setDrawsContent(true); 78 77 … … 81 80 // Set directly on the PlatformCALayer so that when we leave the 'from' value implicit 82 81 // in our animations, we get the right initial value regardless of flush timing. 83 downcast<GraphicsLayerCA>( *layer()).platformCALayer()->setOpacity(0);82 downcast<GraphicsLayerCA>(layer()).platformCALayer()->setOpacity(0); 84 83 85 84 controller.didCreateHighlight(this); … … 114 113 void ServicesOverlayController::Highlight::invalidate() 115 114 { 116 layer() ->removeFromParent();115 layer().removeFromParent(); 117 116 m_controller = nullptr; 118 117 } … … 159 158 160 159 RefPtr<PlatformCAAnimation> platformAnimation = PlatformCAAnimationCocoa::create(animation.get()); 161 downcast<GraphicsLayerCA>( *layer()).platformCALayer()->addAnimationForKey("FadeHighlightIn", *platformAnimation);160 downcast<GraphicsLayerCA>(layer()).platformCALayer()->addAnimationForKey("FadeHighlightIn", *platformAnimation); 162 161 } 163 162 … … 177 176 178 177 RefPtr<PlatformCAAnimation> platformAnimation = PlatformCAAnimationCocoa::create(animation.get()); 179 downcast<GraphicsLayerCA>( *layer()).platformCALayer()->addAnimationForKey("FadeHighlightOut", *platformAnimation);178 downcast<GraphicsLayerCA>(layer()).platformCALayer()->addAnimationForKey("FadeHighlightOut", *platformAnimation); 180 179 [CATransaction commit]; 181 180 } … … 189 188 return; 190 189 191 layer() ->removeFromParent();190 layer().removeFromParent(); 192 191 } 193 192 … … 715 714 716 715 if (m_activeHighlight) { 717 m_servicesOverlay->layer().addChild(m_activeHighlight->layer()); 716 Ref<GraphicsLayer> highlightLayer = m_activeHighlight->layer(); 717 m_servicesOverlay->layer().addChild(WTFMove(highlightLayer)); 718 718 m_activeHighlight->fadeIn(); 719 719 } -
trunk/Source/WebCore/platform/graphics/GraphicsLayer.cpp
r234610 r235953 114 114 : m_client(client) 115 115 , m_type(type) 116 , m_beingDestroyed(false) 116 117 , m_contentsOpaque(false) 117 118 , m_supportsSubpixelAntialiasedText(false) … … 144 145 void GraphicsLayer::willBeDestroyed() 145 146 { 147 m_beingDestroyed = true; 146 148 #ifndef NDEBUG 147 149 m_client.verifyNotPainting(); … … 178 180 } 179 181 180 bool GraphicsLayer::setChildren( const Vector<GraphicsLayer*>& newChildren)182 bool GraphicsLayer::setChildren(Vector<Ref<GraphicsLayer>>&& newChildren) 181 183 { 182 184 // If the contents of the arrays are the same, nothing to do. … … 185 187 186 188 removeAllChildren(); 187 189 188 190 size_t listSize = newChildren.size(); 189 191 for (size_t i = 0; i < listSize; ++i) 190 addChild( newChildren[i]);192 addChild(WTFMove(newChildren[i])); 191 193 192 194 return true; 193 195 } 194 196 195 void GraphicsLayer::addChild( GraphicsLayer*childLayer)196 { 197 ASSERT(childLayer != this);197 void GraphicsLayer::addChild(Ref<GraphicsLayer>&& childLayer) 198 { 199 ASSERT(childLayer.ptr() != this); 198 200 199 201 if (childLayer->parent()) … … 201 203 202 204 childLayer->setParent(this); 203 m_children.append( childLayer);204 } 205 206 void GraphicsLayer::addChildAtIndex( GraphicsLayer*childLayer, int index)207 { 208 ASSERT(childLayer != this);205 m_children.append(WTFMove(childLayer)); 206 } 207 208 void GraphicsLayer::addChildAtIndex(Ref<GraphicsLayer>&& childLayer, int index) 209 { 210 ASSERT(childLayer.ptr() != this); 209 211 210 212 if (childLayer->parent()) … … 212 214 213 215 childLayer->setParent(this); 214 m_children.insert(index, childLayer);215 } 216 217 void GraphicsLayer::addChildBelow( GraphicsLayer*childLayer, GraphicsLayer* sibling)218 { 219 ASSERT(childLayer != this);216 m_children.insert(index, WTFMove(childLayer)); 217 } 218 219 void GraphicsLayer::addChildBelow(Ref<GraphicsLayer>&& childLayer, GraphicsLayer* sibling) 220 { 221 ASSERT(childLayer.ptr() != this); 220 222 childLayer->removeFromParent(); 223 224 childLayer->setParent(this); 225 226 for (unsigned i = 0; i < m_children.size(); i++) { 227 if (sibling == m_children[i].ptr()) { 228 m_children.insert(i, WTFMove(childLayer)); 229 return; 230 } 231 } 232 233 m_children.append(WTFMove(childLayer)); 234 } 235 236 void GraphicsLayer::addChildAbove(Ref<GraphicsLayer>&& childLayer, GraphicsLayer* sibling) 237 { 238 childLayer->removeFromParent(); 239 ASSERT(childLayer.ptr() != this); 240 241 childLayer->setParent(this); 242 243 for (unsigned i = 0; i < m_children.size(); i++) { 244 if (sibling == m_children[i].ptr()) { 245 m_children.insert(i + 1, WTFMove(childLayer)); 246 return; 247 } 248 } 249 250 m_children.append(WTFMove(childLayer)); 251 } 252 253 bool GraphicsLayer::replaceChild(GraphicsLayer* oldChild, Ref<GraphicsLayer>&& newChild) 254 { 255 ASSERT(!newChild->parent()); 256 257 GraphicsLayer* rawNewChild = newChild.ptr(); 221 258 222 259 bool found = false; 223 260 for (unsigned i = 0; i < m_children.size(); i++) { 224 if ( sibling == m_children[i]) {225 m_children .insert(i, childLayer);261 if (oldChild == m_children[i].ptr()) { 262 m_children[i] = WTFMove(newChild); 226 263 found = true; 227 264 break; 228 265 } 229 266 } 230 231 childLayer->setParent(this);232 233 if (!found)234 m_children.append(childLayer);235 }236 237 void GraphicsLayer::addChildAbove(GraphicsLayer* childLayer, GraphicsLayer* sibling)238 {239 childLayer->removeFromParent();240 ASSERT(childLayer != this);241 242 bool found = false;243 for (unsigned i = 0; i < m_children.size(); i++) {244 if (sibling == m_children[i]) {245 m_children.insert(i+1, childLayer);246 found = true;247 break;248 }249 }250 251 childLayer->setParent(this);252 253 if (!found)254 m_children.append(childLayer);255 }256 257 bool GraphicsLayer::replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild)258 {259 ASSERT(!newChild->parent());260 bool found = false;261 for (unsigned i = 0; i < m_children.size(); i++) {262 if (oldChild == m_children[i]) {263 m_children[i] = newChild;264 found = true;265 break;266 }267 }268 267 if (found) { 269 oldChild->setParent( 0);270 271 newChild->removeFromParent();272 newChild->setParent(this);268 oldChild->setParent(nullptr); 269 270 rawNewChild->removeFromParent(); 271 rawNewChild->setParent(this); 273 272 return true; 274 273 } … … 279 278 { 280 279 while (m_children.size()) { 281 GraphicsLayer* curLayer = m_children[0] ;280 GraphicsLayer* curLayer = m_children[0].ptr(); 282 281 ASSERT(curLayer->parent()); 283 282 curLayer->removeFromParent(); 283 // curLayer may be destroyed here. 284 284 } 285 285 } … … 288 288 { 289 289 if (m_parent) { 290 m_parent->m_children.removeFirst(this);290 GraphicsLayer* parent = m_parent; 291 291 setParent(nullptr); 292 parent->m_children.removeFirstMatching([this](auto& layer) { 293 return layer.ptr() == this; 294 }); 295 // |this| may be destroyed here. 292 296 } 293 297 } … … 319 323 } 320 324 321 void GraphicsLayer::setMaskLayer( GraphicsLayer*layer)325 void GraphicsLayer::setMaskLayer(RefPtr<GraphicsLayer>&& layer) 322 326 { 323 327 if (layer == m_maskLayer) … … 333 337 } 334 338 335 m_maskLayer = layer;339 m_maskLayer = WTFMove(layer); 336 340 } 337 341 … … 382 386 m_replicaLayer->noteDeviceOrPageScaleFactorChangedIncludingDescendants(); 383 387 384 const Vector<GraphicsLayer*>& childLayers = children(); 385 size_t numChildren = childLayers.size(); 386 for (size_t i = 0; i < numChildren; ++i) 387 childLayers[i]->noteDeviceOrPageScaleFactorChangedIncludingDescendants(); 388 for (auto& layer : children()) 389 layer->noteDeviceOrPageScaleFactorChangedIncludingDescendants(); 388 390 } 389 391 … … 535 537 536 538 if (preserves3D()) { 537 size_t numChildren = children().size(); 538 for (size_t i = 0; i < numChildren; ++i) 539 children()[i]->distributeOpacity(accumulatedOpacity); 539 for (auto& layer : children()) 540 layer->distributeOpacity(accumulatedOpacity); 540 541 } 541 542 } … … 694 695 traversalFunc(layer); 695 696 696 for (auto *childLayer : layer.children())697 traverse( *childLayer, traversalFunc);697 for (auto& childLayer : layer.children()) 698 traverse(childLayer.get(), traversalFunc); 698 699 699 700 if (auto* replicaLayer = layer.replicaLayer()) … … 718 719 } 719 720 720 static void dumpChildren(TextStream& ts, const Vector< GraphicsLayer*>& children, unsigned& totalChildCount, LayerTreeAsTextBehavior behavior)721 static void dumpChildren(TextStream& ts, const Vector<Ref<GraphicsLayer>>& children, unsigned& totalChildCount, LayerTreeAsTextBehavior behavior) 721 722 { 722 723 totalChildCount += children.size(); 723 for (auto *child : children) {724 if ((behavior & LayerTreeAsTextDebug) || !child->client().shouldSkipLayerInDump(child , behavior)) {724 for (auto& child : children) { 725 if ((behavior & LayerTreeAsTextDebug) || !child->client().shouldSkipLayerInDump(child.ptr(), behavior)) { 725 726 TextStream::IndentScope indentScope(ts); 726 727 child->dumpLayer(ts, behavior); -
trunk/Source/WebCore/platform/graphics/GraphicsLayer.h
r234610 r235953 231 231 // which may have associated transformation and animations. 232 232 233 class GraphicsLayer {234 WTF_MAKE_ NONCOPYABLE(GraphicsLayer); WTF_MAKE_FAST_ALLOCATED;233 class GraphicsLayer : public RefCounted<GraphicsLayer> { 234 WTF_MAKE_FAST_ALLOCATED; 235 235 public: 236 236 enum class Type : uint8_t { … … 240 240 Shape 241 241 }; 242 243 WEBCORE_EXPORT static std::unique_ptr<GraphicsLayer> create(GraphicsLayerFactory*, GraphicsLayerClient&, Type = Type::Normal);242 243 WEBCORE_EXPORT static Ref<GraphicsLayer> create(GraphicsLayerFactory*, GraphicsLayerClient&, Type = Type::Normal); 244 244 245 245 WEBCORE_EXPORT virtual ~GraphicsLayer(); … … 264 264 bool hasAncestor(GraphicsLayer*) const; 265 265 266 const Vector<GraphicsLayer*>& children() const { return m_children; } 266 const Vector<Ref<GraphicsLayer>>& children() const { return m_children; } 267 Vector<Ref<GraphicsLayer>>& children() { return m_children; } 268 267 269 // Returns true if the child list changed. 268 WEBCORE_EXPORT virtual bool setChildren(const Vector<GraphicsLayer*>&); 270 WEBCORE_EXPORT virtual bool setChildren(Vector<Ref<GraphicsLayer>>&&); 271 272 // Add child layers. If the child is already parented, it will be removed from its old parent. 273 WEBCORE_EXPORT virtual void addChild(Ref<GraphicsLayer>&&); 274 WEBCORE_EXPORT virtual void addChildAtIndex(Ref<GraphicsLayer>&&, int index); 275 WEBCORE_EXPORT virtual void addChildAbove(Ref<GraphicsLayer>&&, GraphicsLayer* sibling); 276 WEBCORE_EXPORT virtual void addChildBelow(Ref<GraphicsLayer>&&, GraphicsLayer* sibling); 277 WEBCORE_EXPORT virtual bool replaceChild(GraphicsLayer* oldChild, Ref<GraphicsLayer>&& newChild); 278 279 WEBCORE_EXPORT void removeAllChildren(); 280 WEBCORE_EXPORT virtual void removeFromParent(); 281 282 // The parent() of a maskLayer is set to the layer being masked. 283 GraphicsLayer* maskLayer() const { return m_maskLayer.get(); } 284 virtual void setMaskLayer(RefPtr<GraphicsLayer>&&); 285 286 void setIsMaskLayer(bool isMask) { m_isMaskLayer = isMask; } 287 bool isMaskLayer() const { return m_isMaskLayer; } 288 289 // The given layer will replicate this layer and its children; the replica renders behind this layer. 290 WEBCORE_EXPORT virtual void setReplicatedByLayer(GraphicsLayer*); 291 // Whether this layer is being replicated by another layer. 292 bool isReplicated() const { return m_replicaLayer; } 293 // The layer that replicates this layer (if any). 294 GraphicsLayer* replicaLayer() const { return m_replicaLayer.get(); } 295 296 const FloatPoint& replicatedLayerPosition() const { return m_replicatedLayerPosition; } 297 void setReplicatedLayerPosition(const FloatPoint& p) { m_replicatedLayerPosition = p; } 298 299 enum ShouldSetNeedsDisplay { 300 DontSetNeedsDisplay, 301 SetNeedsDisplay 302 }; 303 304 // Offset is origin of the renderer minus origin of the graphics layer. 305 FloatSize offsetFromRenderer() const { return m_offsetFromRenderer; } 306 void setOffsetFromRenderer(const FloatSize&, ShouldSetNeedsDisplay = SetNeedsDisplay); 307 308 // The position of the layer (the location of its top-left corner in its parent) 309 const FloatPoint& position() const { return m_position; } 310 virtual void setPosition(const FloatPoint& p) { m_approximatePosition = std::nullopt; m_position = p; } 311 312 // approximatePosition, if set, overrides position() and is used during coverage rect computation. 313 FloatPoint approximatePosition() const { return m_approximatePosition ? m_approximatePosition.value() : m_position; } 314 virtual void setApproximatePosition(const FloatPoint& p) { m_approximatePosition = p; } 315 316 // For platforms that move underlying platform layers on a different thread for scrolling; just update the GraphicsLayer state. 317 virtual void syncPosition(const FloatPoint& p) { m_position = p; } 318 319 // Anchor point: (0, 0) is top left, (1, 1) is bottom right. The anchor point 320 // affects the origin of the transforms. 321 const FloatPoint3D& anchorPoint() const { return m_anchorPoint; } 322 virtual void setAnchorPoint(const FloatPoint3D& p) { m_anchorPoint = p; } 323 324 // The size of the layer. 325 const FloatSize& size() const { return m_size; } 326 WEBCORE_EXPORT virtual void setSize(const FloatSize&); 327 328 // The boundOrigin affects the offset at which content is rendered, and sublayers are positioned. 329 const FloatPoint& boundsOrigin() const { return m_boundsOrigin; } 330 virtual void setBoundsOrigin(const FloatPoint& origin) { m_boundsOrigin = origin; } 331 332 // For platforms that move underlying platform layers on a different thread for scrolling; just update the GraphicsLayer state. 333 virtual void syncBoundsOrigin(const FloatPoint& origin) { m_boundsOrigin = origin; } 334 335 const TransformationMatrix& transform() const; 336 virtual void setTransform(const TransformationMatrix&); 337 bool hasNonIdentityTransform() const { return m_transform && !m_transform->isIdentity(); } 338 339 const TransformationMatrix& childrenTransform() const; 340 virtual void setChildrenTransform(const TransformationMatrix&); 341 bool hasNonIdentityChildrenTransform() const { return m_childrenTransform && !m_childrenTransform->isIdentity(); } 342 343 bool preserves3D() const { return m_preserves3D; } 344 virtual void setPreserves3D(bool b) { m_preserves3D = b; } 345 346 bool masksToBounds() const { return m_masksToBounds; } 347 virtual void setMasksToBounds(bool b) { m_masksToBounds = b; } 348 349 bool drawsContent() const { return m_drawsContent; } 350 virtual void setDrawsContent(bool b) { m_drawsContent = b; } 351 352 bool contentsAreVisible() const { return m_contentsVisible; } 353 virtual void setContentsVisible(bool b) { m_contentsVisible = b; } 354 355 bool userInteractionEnabled() const { return m_userInteractionEnabled; } 356 virtual void setUserInteractionEnabled(bool b) { m_userInteractionEnabled = b; } 357 358 bool acceleratesDrawing() const { return m_acceleratesDrawing; } 359 virtual void setAcceleratesDrawing(bool b) { m_acceleratesDrawing = b; } 360 361 bool usesDisplayListDrawing() const { return m_usesDisplayListDrawing; } 362 virtual void setUsesDisplayListDrawing(bool b) { m_usesDisplayListDrawing = b; } 363 364 bool needsBackdrop() const { return !m_backdropFilters.isEmpty(); } 365 366 // The color used to paint the layer background. Pass an invalid color to remove it. 367 // Note that this covers the entire layer. Use setContentsToSolidColor() if the color should 368 // only cover the contentsRect. 369 const Color& backgroundColor() const { return m_backgroundColor; } 370 WEBCORE_EXPORT virtual void setBackgroundColor(const Color&); 371 372 // opaque means that we know the layer contents have no alpha 373 bool contentsOpaque() const { return m_contentsOpaque; } 374 virtual void setContentsOpaque(bool b) { m_contentsOpaque = b; } 375 376 bool supportsSubpixelAntialiasedText() const { return m_supportsSubpixelAntialiasedText; } 377 virtual void setSupportsSubpixelAntialiasedText(bool b) { m_supportsSubpixelAntialiasedText = b; } 378 379 bool backfaceVisibility() const { return m_backfaceVisibility; } 380 virtual void setBackfaceVisibility(bool b) { m_backfaceVisibility = b; } 381 382 float opacity() const { return m_opacity; } 383 virtual void setOpacity(float opacity) { m_opacity = opacity; } 384 385 const FilterOperations& filters() const { return m_filters; } 386 // Returns true if filter can be rendered by the compositor. 387 virtual bool setFilters(const FilterOperations& filters) { m_filters = filters; return true; } 388 389 const FilterOperations& backdropFilters() const { return m_backdropFilters; } 390 virtual bool setBackdropFilters(const FilterOperations& filters) { m_backdropFilters = filters; return true; } 391 392 virtual void setBackdropFiltersRect(const FloatRoundedRect& backdropFiltersRect) { m_backdropFiltersRect = backdropFiltersRect; } 393 const FloatRoundedRect& backdropFiltersRect() const { return m_backdropFiltersRect; } 394 395 #if ENABLE(CSS_COMPOSITING) 396 BlendMode blendMode() const { return m_blendMode; } 397 virtual void setBlendMode(BlendMode blendMode) { m_blendMode = blendMode; } 398 #endif 399 400 // Some GraphicsLayers paint only the foreground or the background content 401 GraphicsLayerPaintingPhase paintingPhase() const { return m_paintingPhase; } 402 void setPaintingPhase(GraphicsLayerPaintingPhase phase) { m_paintingPhase = phase; } 403 404 enum ShouldClipToLayer { 405 DoNotClipToLayer, 406 ClipToLayer 407 }; 408 409 virtual void setNeedsDisplay() = 0; 410 // mark the given rect (in layer coords) as needing dispay. Never goes deep. 411 virtual void setNeedsDisplayInRect(const FloatRect&, ShouldClipToLayer = ClipToLayer) = 0; 412 413 virtual void setContentsNeedsDisplay() { }; 414 415 // The tile phase is relative to the GraphicsLayer bounds. 416 virtual void setContentsTilePhase(const FloatSize& p) { m_contentsTilePhase = p; } 417 FloatSize contentsTilePhase() const { return m_contentsTilePhase; } 418 419 virtual void setContentsTileSize(const FloatSize& s) { m_contentsTileSize = s; } 420 FloatSize contentsTileSize() const { return m_contentsTileSize; } 421 bool hasContentsTiling() const { return !m_contentsTileSize.isEmpty(); } 422 423 // Set that the position/size of the contents (image or video). 424 FloatRect contentsRect() const { return m_contentsRect; } 425 virtual void setContentsRect(const FloatRect& r) { m_contentsRect = r; } 426 427 // Set a rounded rect that will be used to clip the layer contents. 428 FloatRoundedRect contentsClippingRect() const { return m_contentsClippingRect; } 429 virtual void setContentsClippingRect(const FloatRoundedRect& roundedRect) { m_contentsClippingRect = roundedRect; } 430 431 // Set a rounded rect that is used to clip this layer and its descendants (implies setting masksToBounds). 432 // Returns false if the platform can't support this rounded clip, and we should fall back to painting a mask. 433 FloatRoundedRect maskToBoundsRect() const { return m_masksToBoundsRect; }; 434 virtual bool setMasksToBoundsRect(const FloatRoundedRect& roundedRect) { m_masksToBoundsRect = roundedRect; return false; } 435 436 Path shapeLayerPath() const; 437 virtual void setShapeLayerPath(const Path&); 438 439 WindRule shapeLayerWindRule() const; 440 virtual void setShapeLayerWindRule(WindRule); 441 442 // Transitions are identified by a special animation name that cannot clash with a keyframe identifier. 443 static String animationNameForTransition(AnimatedPropertyID); 444 445 // Return true if the animation is handled by the compositing system. If this returns 446 // false, the animation will be run by CSSAnimationController. 447 // These methods handle both transitions and keyframe animations. 448 virtual bool addAnimation(const KeyframeValueList&, const FloatSize& /*boxSize*/, const Animation*, const String& /*animationName*/, double /*timeOffset*/) { return false; } 449 virtual void pauseAnimation(const String& /*animationName*/, double /*timeOffset*/) { } 450 virtual void seekAnimation(const String& /*animationName*/, double /*timeOffset*/) { } 451 virtual void removeAnimation(const String& /*animationName*/) { } 452 453 WEBCORE_EXPORT virtual void suspendAnimations(MonotonicTime); 454 WEBCORE_EXPORT virtual void resumeAnimations(); 455 456 // Layer contents 457 virtual void setContentsToImage(Image*) { } 458 virtual bool shouldDirectlyCompositeImage(Image*) const { return true; } 459 #if PLATFORM(IOS) 460 virtual PlatformLayer* contentsLayerForMedia() const { return 0; } 461 #endif 269 462 270 463 enum class ContentsLayerPurpose : uint8_t { … … 277 470 }; 278 471 279 // Add child layers. If the child is already parented, it will be removed from its old parent.280 WEBCORE_EXPORT virtual void addChild(GraphicsLayer*);281 WEBCORE_EXPORT virtual void addChildAtIndex(GraphicsLayer*, int index);282 WEBCORE_EXPORT virtual void addChildAbove(GraphicsLayer*, GraphicsLayer* sibling);283 WEBCORE_EXPORT virtual void addChildBelow(GraphicsLayer*, GraphicsLayer* sibling);284 WEBCORE_EXPORT virtual bool replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild);285 286 WEBCORE_EXPORT void removeAllChildren();287 WEBCORE_EXPORT virtual void removeFromParent();288 289 // The parent() of a maskLayer is set to the layer being masked.290 GraphicsLayer* maskLayer() const { return m_maskLayer; }291 virtual void setMaskLayer(GraphicsLayer*);292 293 void setIsMaskLayer(bool isMask) { m_isMaskLayer = isMask; }294 bool isMaskLayer() const { return m_isMaskLayer; }295 296 // The given layer will replicate this layer and its children; the replica renders behind this layer.297 WEBCORE_EXPORT virtual void setReplicatedByLayer(GraphicsLayer*);298 // Whether this layer is being replicated by another layer.299 bool isReplicated() const { return m_replicaLayer; }300 // The layer that replicates this layer (if any).301 GraphicsLayer* replicaLayer() const { return m_replicaLayer; }302 303 const FloatPoint& replicatedLayerPosition() const { return m_replicatedLayerPosition; }304 void setReplicatedLayerPosition(const FloatPoint& p) { m_replicatedLayerPosition = p; }305 306 enum ShouldSetNeedsDisplay {307 DontSetNeedsDisplay,308 SetNeedsDisplay309 };310 311 // Offset is origin of the renderer minus origin of the graphics layer.312 FloatSize offsetFromRenderer() const { return m_offsetFromRenderer; }313 void setOffsetFromRenderer(const FloatSize&, ShouldSetNeedsDisplay = SetNeedsDisplay);314 315 // The position of the layer (the location of its top-left corner in its parent)316 const FloatPoint& position() const { return m_position; }317 virtual void setPosition(const FloatPoint& p) { m_approximatePosition = std::nullopt; m_position = p; }318 319 // approximatePosition, if set, overrides position() and is used during coverage rect computation.320 FloatPoint approximatePosition() const { return m_approximatePosition ? m_approximatePosition.value() : m_position; }321 virtual void setApproximatePosition(const FloatPoint& p) { m_approximatePosition = p; }322 323 // For platforms that move underlying platform layers on a different thread for scrolling; just update the GraphicsLayer state.324 virtual void syncPosition(const FloatPoint& p) { m_position = p; }325 326 // Anchor point: (0, 0) is top left, (1, 1) is bottom right. The anchor point327 // affects the origin of the transforms.328 const FloatPoint3D& anchorPoint() const { return m_anchorPoint; }329 virtual void setAnchorPoint(const FloatPoint3D& p) { m_anchorPoint = p; }330 331 // The size of the layer.332 const FloatSize& size() const { return m_size; }333 WEBCORE_EXPORT virtual void setSize(const FloatSize&);334 335 // The boundOrigin affects the offset at which content is rendered, and sublayers are positioned.336 const FloatPoint& boundsOrigin() const { return m_boundsOrigin; }337 virtual void setBoundsOrigin(const FloatPoint& origin) { m_boundsOrigin = origin; }338 339 // For platforms that move underlying platform layers on a different thread for scrolling; just update the GraphicsLayer state.340 virtual void syncBoundsOrigin(const FloatPoint& origin) { m_boundsOrigin = origin; }341 342 const TransformationMatrix& transform() const;343 virtual void setTransform(const TransformationMatrix&);344 bool hasNonIdentityTransform() const { return m_transform && !m_transform->isIdentity(); }345 346 const TransformationMatrix& childrenTransform() const;347 virtual void setChildrenTransform(const TransformationMatrix&);348 bool hasNonIdentityChildrenTransform() const { return m_childrenTransform && !m_childrenTransform->isIdentity(); }349 350 bool preserves3D() const { return m_preserves3D; }351 virtual void setPreserves3D(bool b) { m_preserves3D = b; }352 353 bool masksToBounds() const { return m_masksToBounds; }354 virtual void setMasksToBounds(bool b) { m_masksToBounds = b; }355 356 bool drawsContent() const { return m_drawsContent; }357 virtual void setDrawsContent(bool b) { m_drawsContent = b; }358 359 bool contentsAreVisible() const { return m_contentsVisible; }360 virtual void setContentsVisible(bool b) { m_contentsVisible = b; }361 362 bool userInteractionEnabled() const { return m_userInteractionEnabled; }363 virtual void setUserInteractionEnabled(bool b) { m_userInteractionEnabled = b; }364 365 bool acceleratesDrawing() const { return m_acceleratesDrawing; }366 virtual void setAcceleratesDrawing(bool b) { m_acceleratesDrawing = b; }367 368 bool usesDisplayListDrawing() const { return m_usesDisplayListDrawing; }369 virtual void setUsesDisplayListDrawing(bool b) { m_usesDisplayListDrawing = b; }370 371 bool needsBackdrop() const { return !m_backdropFilters.isEmpty(); }372 373 // The color used to paint the layer background. Pass an invalid color to remove it.374 // Note that this covers the entire layer. Use setContentsToSolidColor() if the color should375 // only cover the contentsRect.376 const Color& backgroundColor() const { return m_backgroundColor; }377 WEBCORE_EXPORT virtual void setBackgroundColor(const Color&);378 379 // opaque means that we know the layer contents have no alpha380 bool contentsOpaque() const { return m_contentsOpaque; }381 virtual void setContentsOpaque(bool b) { m_contentsOpaque = b; }382 383 bool supportsSubpixelAntialiasedText() const { return m_supportsSubpixelAntialiasedText; }384 virtual void setSupportsSubpixelAntialiasedText(bool b) { m_supportsSubpixelAntialiasedText = b; }385 386 bool backfaceVisibility() const { return m_backfaceVisibility; }387 virtual void setBackfaceVisibility(bool b) { m_backfaceVisibility = b; }388 389 float opacity() const { return m_opacity; }390 virtual void setOpacity(float opacity) { m_opacity = opacity; }391 392 const FilterOperations& filters() const { return m_filters; }393 // Returns true if filter can be rendered by the compositor.394 virtual bool setFilters(const FilterOperations& filters) { m_filters = filters; return true; }395 396 const FilterOperations& backdropFilters() const { return m_backdropFilters; }397 virtual bool setBackdropFilters(const FilterOperations& filters) { m_backdropFilters = filters; return true; }398 399 virtual void setBackdropFiltersRect(const FloatRoundedRect& backdropFiltersRect) { m_backdropFiltersRect = backdropFiltersRect; }400 const FloatRoundedRect& backdropFiltersRect() const { return m_backdropFiltersRect; }401 402 #if ENABLE(CSS_COMPOSITING)403 BlendMode blendMode() const { return m_blendMode; }404 virtual void setBlendMode(BlendMode blendMode) { m_blendMode = blendMode; }405 #endif406 407 // Some GraphicsLayers paint only the foreground or the background content408 GraphicsLayerPaintingPhase paintingPhase() const { return m_paintingPhase; }409 void setPaintingPhase(GraphicsLayerPaintingPhase phase) { m_paintingPhase = phase; }410 411 enum ShouldClipToLayer {412 DoNotClipToLayer,413 ClipToLayer414 };415 416 virtual void setNeedsDisplay() = 0;417 // mark the given rect (in layer coords) as needing dispay. Never goes deep.418 virtual void setNeedsDisplayInRect(const FloatRect&, ShouldClipToLayer = ClipToLayer) = 0;419 420 virtual void setContentsNeedsDisplay() { };421 422 // The tile phase is relative to the GraphicsLayer bounds.423 virtual void setContentsTilePhase(const FloatSize& p) { m_contentsTilePhase = p; }424 FloatSize contentsTilePhase() const { return m_contentsTilePhase; }425 426 virtual void setContentsTileSize(const FloatSize& s) { m_contentsTileSize = s; }427 FloatSize contentsTileSize() const { return m_contentsTileSize; }428 bool hasContentsTiling() const { return !m_contentsTileSize.isEmpty(); }429 430 // Set that the position/size of the contents (image or video).431 FloatRect contentsRect() const { return m_contentsRect; }432 virtual void setContentsRect(const FloatRect& r) { m_contentsRect = r; }433 434 // Set a rounded rect that will be used to clip the layer contents.435 FloatRoundedRect contentsClippingRect() const { return m_contentsClippingRect; }436 virtual void setContentsClippingRect(const FloatRoundedRect& roundedRect) { m_contentsClippingRect = roundedRect; }437 438 // Set a rounded rect that is used to clip this layer and its descendants (implies setting masksToBounds).439 // Returns false if the platform can't support this rounded clip, and we should fall back to painting a mask.440 FloatRoundedRect maskToBoundsRect() const { return m_masksToBoundsRect; };441 virtual bool setMasksToBoundsRect(const FloatRoundedRect& roundedRect) { m_masksToBoundsRect = roundedRect; return false; }442 443 Path shapeLayerPath() const;444 virtual void setShapeLayerPath(const Path&);445 446 WindRule shapeLayerWindRule() const;447 virtual void setShapeLayerWindRule(WindRule);448 449 // Transitions are identified by a special animation name that cannot clash with a keyframe identifier.450 static String animationNameForTransition(AnimatedPropertyID);451 452 // Return true if the animation is handled by the compositing system. If this returns453 // false, the animation will be run by CSSAnimationController.454 // These methods handle both transitions and keyframe animations.455 virtual bool addAnimation(const KeyframeValueList&, const FloatSize& /*boxSize*/, const Animation*, const String& /*animationName*/, double /*timeOffset*/) { return false; }456 virtual void pauseAnimation(const String& /*animationName*/, double /*timeOffset*/) { }457 virtual void seekAnimation(const String& /*animationName*/, double /*timeOffset*/) { }458 virtual void removeAnimation(const String& /*animationName*/) { }459 460 WEBCORE_EXPORT virtual void suspendAnimations(MonotonicTime);461 WEBCORE_EXPORT virtual void resumeAnimations();462 463 // Layer contents464 virtual void setContentsToImage(Image*) { }465 virtual bool shouldDirectlyCompositeImage(Image*) const { return true; }466 #if PLATFORM(IOS)467 virtual PlatformLayer* contentsLayerForMedia() const { return 0; }468 #endif469 472 // Pass an invalid color to remove the contents layer. 470 473 virtual void setContentsToSolidColor(const Color&) { } … … 592 595 // Should be called from derived class destructors. Should call willBeDestroyed() on super. 593 596 WEBCORE_EXPORT virtual void willBeDestroyed(); 597 bool beingDestroyed() const { return m_beingDestroyed; } 594 598 595 599 // This method is used by platform GraphicsLayer classes to clear the filters … … 657 661 CompositingCoordinatesOrientation m_contentsOrientation { CompositingCoordinatesOrientation::TopDown }; // affects orientation of layer contents 658 662 663 bool m_beingDestroyed : 1; 659 664 bool m_contentsOpaque : 1; 660 665 bool m_supportsSubpixelAntialiasedText : 1; … … 676 681 int m_repaintCount { 0 }; 677 682 678 Vector< GraphicsLayer*> m_children;683 Vector<Ref<GraphicsLayer>> m_children; 679 684 GraphicsLayer* m_parent { nullptr }; 680 685 681 GraphicsLayer* m_maskLayer { nullptr }; // Reference to mask layer. We don't own this.682 683 GraphicsLayer*m_replicaLayer { nullptr }; // A layer that replicates this layer. We only allow one, for now.686 RefPtr<GraphicsLayer> m_maskLayer { nullptr }; // Reference to mask layer. 687 688 RefPtr<GraphicsLayer> m_replicaLayer { nullptr }; // A layer that replicates this layer. We only allow one, for now. 684 689 // The replica is not parented; this is the primary reference to it. 685 690 GraphicsLayer* m_replicatedLayer { nullptr }; // For a replica layer, a reference to the original layer. -
trunk/Source/WebCore/platform/graphics/GraphicsLayerFactory.h
r223728 r235953 24 24 */ 25 25 26 #ifndef GraphicsLayerFactory_h 27 #define GraphicsLayerFactory_h 26 #pragma once 28 27 29 28 #include "GraphicsLayer.h" … … 36 35 virtual ~GraphicsLayerFactory() = default; 37 36 38 virtual std::unique_ptr<GraphicsLayer> createGraphicsLayer(GraphicsLayer::Type, GraphicsLayerClient&) = 0;37 virtual Ref<GraphicsLayer> createGraphicsLayer(GraphicsLayer::Type, GraphicsLayerClient&) = 0; 39 38 }; 40 39 41 40 } // namespace WebCore 42 43 #endif // GraphicsLayerFactory_h -
trunk/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp
r235854 r235953 340 340 } 341 341 342 std::unique_ptr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerFactory* factory, GraphicsLayerClient& client, Type layerType)343 { 344 std::unique_ptr<GraphicsLayer> graphicsLayer;345 if (!factory)346 graphicsLayer = std::make_unique<GraphicsLayerCA>(layerType, client);347 else348 graphicsLayer = factory->createGraphicsLayer(layerType, client);349 350 graphicsLayer->initialize(layerType);351 352 return graphicsLayer;342 Ref<GraphicsLayer> GraphicsLayer::create(GraphicsLayerFactory* factory, GraphicsLayerClient& client, Type layerType) 343 { 344 if (factory) { 345 auto layer = factory->createGraphicsLayer(layerType, client); 346 layer->initialize(layerType); 347 return layer; 348 } 349 350 auto layer = adoptRef(*new GraphicsLayerCA(layerType, client)); 351 layer->initialize(layerType); 352 return WTFMove(layer); 353 353 } 354 354 … … 506 506 } 507 507 508 bool GraphicsLayerCA::setChildren( const Vector<GraphicsLayer*>& children)509 { 510 bool childrenChanged = GraphicsLayer::setChildren( children);508 bool GraphicsLayerCA::setChildren(Vector<Ref<GraphicsLayer>>&& children) 509 { 510 bool childrenChanged = GraphicsLayer::setChildren(WTFMove(children)); 511 511 if (childrenChanged) 512 512 noteSublayersChanged(); … … 515 515 } 516 516 517 void GraphicsLayerCA::addChild( GraphicsLayer*childLayer)518 { 519 GraphicsLayer::addChild( childLayer);517 void GraphicsLayerCA::addChild(Ref<GraphicsLayer>&& childLayer) 518 { 519 GraphicsLayer::addChild(WTFMove(childLayer)); 520 520 noteSublayersChanged(); 521 521 } 522 522 523 void GraphicsLayerCA::addChildAtIndex( GraphicsLayer*childLayer, int index)524 { 525 GraphicsLayer::addChildAtIndex( childLayer, index);523 void GraphicsLayerCA::addChildAtIndex(Ref<GraphicsLayer>&& childLayer, int index) 524 { 525 GraphicsLayer::addChildAtIndex(WTFMove(childLayer), index); 526 526 noteSublayersChanged(); 527 527 } 528 528 529 void GraphicsLayerCA::addChildBelow( GraphicsLayer*childLayer, GraphicsLayer* sibling)530 { 531 GraphicsLayer::addChildBelow( childLayer, sibling);529 void GraphicsLayerCA::addChildBelow(Ref<GraphicsLayer>&& childLayer, GraphicsLayer* sibling) 530 { 531 GraphicsLayer::addChildBelow(WTFMove(childLayer), sibling); 532 532 noteSublayersChanged(); 533 533 } 534 534 535 void GraphicsLayerCA::addChildAbove( GraphicsLayer*childLayer, GraphicsLayer* sibling)536 { 537 GraphicsLayer::addChildAbove( childLayer, sibling);535 void GraphicsLayerCA::addChildAbove(Ref<GraphicsLayer>&& childLayer, GraphicsLayer* sibling) 536 { 537 GraphicsLayer::addChildAbove(WTFMove(childLayer), sibling); 538 538 noteSublayersChanged(); 539 539 } 540 540 541 bool GraphicsLayerCA::replaceChild(GraphicsLayer* oldChild, GraphicsLayer*newChild)542 { 543 if (GraphicsLayer::replaceChild(oldChild, newChild)) {541 bool GraphicsLayerCA::replaceChild(GraphicsLayer* oldChild, Ref<GraphicsLayer>&& newChild) 542 { 543 if (GraphicsLayer::replaceChild(oldChild, WTFMove(newChild))) { 544 544 noteSublayersChanged(); 545 545 return true; … … 555 555 } 556 556 557 void GraphicsLayerCA::setMaskLayer( GraphicsLayer*layer)557 void GraphicsLayerCA::setMaskLayer(RefPtr<GraphicsLayer>&& layer) 558 558 { 559 559 if (layer == m_maskLayer) 560 560 return; 561 561 562 GraphicsLayer::setMaskLayer( layer);562 GraphicsLayer::setMaskLayer(WTFMove(layer)); 563 563 noteLayerPropertyChanged(MaskLayerChanged); 564 564 … … 1301 1301 1302 1302 if (m_maskLayer) { 1303 GraphicsLayerCA& maskLayerCA = downcast<GraphicsLayerCA>(*m_maskLayer);1303 auto& maskLayerCA = downcast<GraphicsLayerCA>(*m_maskLayer); 1304 1304 if (maskLayerCA.recursiveVisibleRectChangeRequiresFlush(childCommitState, localState)) 1305 1305 return true; 1306 1306 } 1307 1307 1308 const Vector<GraphicsLayer*>& childLayers = children(); 1309 size_t numChildren = childLayers.size(); 1310 1311 for (size_t i = 0; i < numChildren; ++i) { 1312 GraphicsLayerCA& currentChild = downcast<GraphicsLayerCA>(*childLayers[i]); 1308 for (const auto& layer : children()) { 1309 const auto& currentChild = downcast<GraphicsLayerCA>(layer.get()); 1313 1310 if (currentChild.recursiveVisibleRectChangeRequiresFlush(childCommitState, localState)) 1314 1311 return true; … … 1573 1570 childCommitState.ancestorIsViewportConstrained |= m_isViewportConstrained; 1574 1571 1575 if (GraphicsLayerCA* maskLayer = downcast<GraphicsLayerCA>(m_maskLayer )) {1572 if (GraphicsLayerCA* maskLayer = downcast<GraphicsLayerCA>(m_maskLayer.get())) { 1576 1573 maskLayer->setVisibleAndCoverageRects(rects, m_isViewportConstrained || commitState.ancestorIsViewportConstrained); 1577 1574 maskLayer->commitLayerChangesBeforeSublayers(childCommitState, pageScaleFactor, baseRelativePosition); 1578 1575 } 1579 1576 1580 const Vector<GraphicsLayer*>& childLayers = children();1581 size_t numChildren = childLayers.size();1582 1583 1577 bool hasDescendantsWithRunningTransformAnimations = false; 1584 1578 1585 for ( size_t i = 0; i < numChildren; ++i) {1586 GraphicsLayerCA& currentChild = downcast<GraphicsLayerCA>(*childLayers[i]);1579 for (auto& layer : children()) { 1580 auto& currentChild = downcast<GraphicsLayerCA>(layer.get()); 1587 1581 currentChild.recursiveCommitChanges(childCommitState, localState, pageScaleFactor, baseRelativePosition, affectedByPageScale); 1588 1582 … … 1591 1585 } 1592 1586 1593 if (GraphicsLayerCA* replicaLayer = downcast<GraphicsLayerCA>(m_replicaLayer ))1587 if (GraphicsLayerCA* replicaLayer = downcast<GraphicsLayerCA>(m_replicaLayer.get())) 1594 1588 replicaLayer->recursiveCommitChanges(childCommitState, localState, pageScaleFactor, baseRelativePosition, affectedByPageScale); 1595 1589 1596 if (GraphicsLayerCA* maskLayer = downcast<GraphicsLayerCA>(m_maskLayer ))1590 if (GraphicsLayerCA* maskLayer = downcast<GraphicsLayerCA>(m_maskLayer.get())) 1597 1591 maskLayer->commitLayerChangesAfterSublayers(childCommitState); 1598 1592 … … 1929 1923 } 1930 1924 1931 const Vector<GraphicsLayer*>& childLayers = children(); 1932 size_t numChildren = childLayers.size(); 1933 for (size_t i = 0; i < numChildren; ++i) { 1934 GraphicsLayerCA& currentChild = downcast<GraphicsLayerCA>(*childLayers[i]); 1925 for (const auto& layer : children()) { 1926 const auto& currentChild = downcast<GraphicsLayerCA>(layer.get()); 1935 1927 PlatformCALayer* childLayer = currentChild.layerForSuperlayer(); 1936 1928 childListForSublayers.append(childLayer); … … 3978 3970 } 3979 3971 3980 const Vector<GraphicsLayer*>& childLayers = children();3972 auto& childLayers = children(); 3981 3973 Vector<RefPtr<PlatformCALayer>> clonalSublayers; 3982 3974 … … 4028 4020 replicaState.push(ReplicaState::ChildBranch); 4029 4021 4030 for (auto *childLayer : childLayers) {4031 GraphicsLayerCA& childLayerCA = downcast<GraphicsLayerCA>( *childLayer);4022 for (auto& childLayer : childLayers) { 4023 GraphicsLayerCA& childLayerCA = downcast<GraphicsLayerCA>(childLayer.get()); 4032 4024 if (auto platformLayer = childLayerCA.fetchCloneLayers(replicaRoot, replicaState, IntermediateCloneLevel)) 4033 4025 clonalSublayers.append(WTFMove(platformLayer)); … … 4193 4185 void GraphicsLayerCA::noteLayerPropertyChanged(LayerChangeFlags flags, ScheduleFlushOrNot scheduleFlush) 4194 4186 { 4187 if (beingDestroyed()) 4188 return; 4189 4195 4190 bool hadUncommittedChanges = !!m_uncommittedChanges; 4196 4191 bool oldCanThrottleLayerFlush = canThrottleLayerFlush(); -
trunk/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.h
r234393 r235953 50 50 class GraphicsLayerCA : public GraphicsLayer, public PlatformCALayerClient { 51 51 public: 52 53 52 WEBCORE_EXPORT explicit GraphicsLayerCA(Type, GraphicsLayerClient&); 54 53 WEBCORE_EXPORT virtual ~GraphicsLayerCA(); … … 63 62 PlatformCALayer* platformCALayer() const { return primaryLayer(); } 64 63 65 WEBCORE_EXPORT bool setChildren( const Vector<GraphicsLayer*>&) override;66 WEBCORE_EXPORT void addChild( GraphicsLayer*) override;67 WEBCORE_EXPORT void addChildAtIndex( GraphicsLayer*, int index) override;68 WEBCORE_EXPORT void addChildAbove( GraphicsLayer*, GraphicsLayer* sibling) override;69 WEBCORE_EXPORT void addChildBelow( GraphicsLayer*, GraphicsLayer* sibling) override;70 WEBCORE_EXPORT bool replaceChild(GraphicsLayer* oldChild, GraphicsLayer*newChild) override;64 WEBCORE_EXPORT bool setChildren(Vector<Ref<GraphicsLayer>>&&) override; 65 WEBCORE_EXPORT void addChild(Ref<GraphicsLayer>&&) override; 66 WEBCORE_EXPORT void addChildAtIndex(Ref<GraphicsLayer>&&, int index) override; 67 WEBCORE_EXPORT void addChildAbove(Ref<GraphicsLayer>&&, GraphicsLayer* sibling) override; 68 WEBCORE_EXPORT void addChildBelow(Ref<GraphicsLayer>&&, GraphicsLayer* sibling) override; 69 WEBCORE_EXPORT bool replaceChild(GraphicsLayer* oldChild, Ref<GraphicsLayer>&& newChild) override; 71 70 72 71 WEBCORE_EXPORT void removeFromParent() override; 73 72 74 WEBCORE_EXPORT void setMaskLayer( GraphicsLayer*) override;73 WEBCORE_EXPORT void setMaskLayer(RefPtr<GraphicsLayer>&&) override; 75 74 WEBCORE_EXPORT void setReplicatedLayer(GraphicsLayer*) override; 76 75 -
trunk/Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.cpp
r234393 r235953 30 30 namespace WebCore { 31 31 32 std::unique_ptr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerFactory* factory, GraphicsLayerClient& client, Type layerType)32 Ref<GraphicsLayer> GraphicsLayer::create(GraphicsLayerFactory* factory, GraphicsLayerClient& client, Type layerType) 33 33 { 34 34 if (!factory) 35 return std::make_unique<GraphicsLayerTextureMapper>(layerType, client);35 return adoptRef(*new GraphicsLayerTextureMapper(layerType, client)); 36 36 37 37 return factory->createGraphicsLayer(layerType, client); … … 94 94 } 95 95 96 bool GraphicsLayerTextureMapper::setChildren( const Vector<GraphicsLayer*>& children)97 { 98 if (GraphicsLayer::setChildren( children)) {96 bool GraphicsLayerTextureMapper::setChildren(Vector<Ref<GraphicsLayer>>&& children) 97 { 98 if (GraphicsLayer::setChildren(WTFMove(children))) { 99 99 notifyChange(ChildrenChange); 100 100 return true; … … 103 103 } 104 104 105 void GraphicsLayerTextureMapper::addChild( GraphicsLayer*layer)105 void GraphicsLayerTextureMapper::addChild(Ref<GraphicsLayer>&& layer) 106 106 { 107 107 notifyChange(ChildrenChange); 108 GraphicsLayer::addChild( layer);109 } 110 111 void GraphicsLayerTextureMapper::addChildAtIndex( GraphicsLayer*layer, int index)112 { 113 GraphicsLayer::addChildAtIndex( layer, index);108 GraphicsLayer::addChild(WTFMove(layer)); 109 } 110 111 void GraphicsLayerTextureMapper::addChildAtIndex(Ref<GraphicsLayer>&& layer, int index) 112 { 113 GraphicsLayer::addChildAtIndex(WTFMove(layer), index); 114 114 notifyChange(ChildrenChange); 115 115 } 116 116 117 void GraphicsLayerTextureMapper::addChildAbove( GraphicsLayer*layer, GraphicsLayer* sibling)118 { 119 GraphicsLayer::addChildAbove( layer, sibling);117 void GraphicsLayerTextureMapper::addChildAbove(Ref<GraphicsLayer>&& layer, GraphicsLayer* sibling) 118 { 119 GraphicsLayer::addChildAbove(WTFMove(layer), sibling); 120 120 notifyChange(ChildrenChange); 121 121 } 122 122 123 void GraphicsLayerTextureMapper::addChildBelow( GraphicsLayer*layer, GraphicsLayer* sibling)124 { 125 GraphicsLayer::addChildBelow( layer, sibling);123 void GraphicsLayerTextureMapper::addChildBelow(Ref<GraphicsLayer>&& layer, GraphicsLayer* sibling) 124 { 125 GraphicsLayer::addChildBelow(WTFMove(layer), sibling); 126 126 notifyChange(ChildrenChange); 127 127 } 128 128 129 bool GraphicsLayerTextureMapper::replaceChild(GraphicsLayer* oldChild, GraphicsLayer*newChild)130 { 131 if (GraphicsLayer::replaceChild(oldChild, newChild)) {129 bool GraphicsLayerTextureMapper::replaceChild(GraphicsLayer* oldChild, Ref<GraphicsLayer>&& newChild) 130 { 131 if (GraphicsLayer::replaceChild(oldChild, WTFMove(newChild))) { 132 132 notifyChange(ChildrenChange); 133 133 return true; … … 136 136 } 137 137 138 void GraphicsLayerTextureMapper::setMaskLayer( GraphicsLayer*value)138 void GraphicsLayerTextureMapper::setMaskLayer(RefPtr<GraphicsLayer>&& value) 139 139 { 140 140 if (value == maskLayer()) 141 141 return; 142 GraphicsLayer::setMaskLayer(value); 142 143 GraphicsLayer* rawLayer = value.get(); 144 GraphicsLayer::setMaskLayer(WTFMove(value)); 143 145 notifyChange(MaskLayerChange); 144 146 145 if (! value)146 return; 147 value->setSize(size());148 value->setContentsVisible(contentsAreVisible());147 if (!rawLayer) 148 return; 149 rawLayer->setSize(size()); 150 rawLayer->setContentsVisible(contentsAreVisible()); 149 151 } 150 152 … … 392 394 return; 393 395 394 if (m_changeMask & ChildrenChange) 395 m_layer.setChildren(children()); 396 if (m_changeMask & ChildrenChange) { 397 Vector<GraphicsLayer*> rawChildren; 398 rawChildren.reserveInitialCapacity(children().size()); 399 for (auto& layer : children()) 400 rawChildren.uncheckedAppend(layer.ptr()); 401 m_layer.setChildren(rawChildren); 402 } 396 403 397 404 if (m_changeMask & MaskLayerChange) … … 478 485 if (replicaLayer()) 479 486 replicaLayer()->flushCompositingState(rect); 480 for (auto *child : children())487 for (auto& child : children()) 481 488 child->flushCompositingState(rect); 482 489 } … … 493 500 if (replicaLayer()) 494 501 downcast<GraphicsLayerTextureMapper>(*replicaLayer()).updateBackingStoreIfNeeded(); 495 for (auto *child : children())496 downcast<GraphicsLayerTextureMapper>( *child).updateBackingStoreIncludingSubLayers();502 for (auto& child : children()) 503 downcast<GraphicsLayerTextureMapper>(child.get()).updateBackingStoreIncludingSubLayers(); 497 504 } 498 505 -
trunk/Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.h
r234393 r235953 40 40 41 41 // GraphicsLayer 42 bool setChildren( const Vector<GraphicsLayer*>&) override;43 void addChild( GraphicsLayer*) override;44 void addChildAtIndex( GraphicsLayer*, int index) override;45 void addChildAbove( GraphicsLayer*, GraphicsLayer* sibling) override;46 void addChildBelow( GraphicsLayer*, GraphicsLayer* sibling) override;47 bool replaceChild(GraphicsLayer* oldChild, GraphicsLayer*newChild) override;42 bool setChildren(Vector<Ref<GraphicsLayer>>&&) override; 43 void addChild(Ref<GraphicsLayer>&&) override; 44 void addChildAtIndex(Ref<GraphicsLayer>&&, int index) override; 45 void addChildAbove(Ref<GraphicsLayer>&&, GraphicsLayer* sibling) override; 46 void addChildBelow(Ref<GraphicsLayer>&&, GraphicsLayer* sibling) override; 47 bool replaceChild(GraphicsLayer* oldChild, Ref<GraphicsLayer>&& newChild) override; 48 48 49 void setMaskLayer( GraphicsLayer*) override;49 void setMaskLayer(RefPtr<GraphicsLayer>&&) override; 50 50 void setReplicatedByLayer(GraphicsLayer*) override; 51 51 void setPosition(const FloatPoint&) override; -
trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp
r235671 r235953 47 47 namespace WebCore { 48 48 49 std::unique_ptr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerFactory* factory, GraphicsLayerClient& client, Type layerType)49 Ref<GraphicsLayer> GraphicsLayer::create(GraphicsLayerFactory* factory, GraphicsLayerClient& client, Type layerType) 50 50 { 51 51 if (!factory) 52 return std::make_unique<CoordinatedGraphicsLayer>(layerType, client);52 return adoptRef(*new CoordinatedGraphicsLayer(layerType, client)); 53 53 54 54 return factory->createGraphicsLayer(layerType, client); … … 98 98 m_shouldUpdateVisibleRect = true; 99 99 for (auto& child : children()) 100 downcast<CoordinatedGraphicsLayer>( *child).setShouldUpdateVisibleRect();100 downcast<CoordinatedGraphicsLayer>(child.get()).setShouldUpdateVisibleRect(); 101 101 if (replicaLayer()) 102 102 downcast<CoordinatedGraphicsLayer>(*replicaLayer()).setShouldUpdateVisibleRect(); … … 159 159 } 160 160 161 bool CoordinatedGraphicsLayer::setChildren( const Vector<GraphicsLayer*>& children)162 { 163 bool ok = GraphicsLayer::setChildren( children);161 bool CoordinatedGraphicsLayer::setChildren(Vector<Ref<GraphicsLayer>>&& children) 162 { 163 bool ok = GraphicsLayer::setChildren(WTFMove(children)); 164 164 if (!ok) 165 165 return false; … … 168 168 } 169 169 170 void CoordinatedGraphicsLayer::addChild(GraphicsLayer* layer) 171 { 172 GraphicsLayer::addChild(layer); 173 downcast<CoordinatedGraphicsLayer>(*layer).setCoordinatorIncludingSubLayersIfNeeded(m_coordinator); 170 void CoordinatedGraphicsLayer::addChild(Ref<GraphicsLayer>&& layer) 171 { 172 GraphicsLayer* rawLayer = layer.ptr(); 173 GraphicsLayer::addChild(WTFMove(layer)); 174 downcast<CoordinatedGraphicsLayer>(*rawLayer).setCoordinatorIncludingSubLayersIfNeeded(m_coordinator); 174 175 didChangeChildren(); 175 176 } 176 177 177 void CoordinatedGraphicsLayer::addChildAtIndex(GraphicsLayer* layer, int index) 178 { 179 GraphicsLayer::addChildAtIndex(layer, index); 180 downcast<CoordinatedGraphicsLayer>(*layer).setCoordinatorIncludingSubLayersIfNeeded(m_coordinator); 178 void CoordinatedGraphicsLayer::addChildAtIndex(Ref<GraphicsLayer>&& layer, int index) 179 { 180 GraphicsLayer* rawLayer = layer.ptr(); 181 GraphicsLayer::addChildAtIndex(WTFMove(layer), index); 182 downcast<CoordinatedGraphicsLayer>(*rawLayer).setCoordinatorIncludingSubLayersIfNeeded(m_coordinator); 181 183 didChangeChildren(); 182 184 } 183 185 184 void CoordinatedGraphicsLayer::addChildAbove(GraphicsLayer* layer, GraphicsLayer* sibling) 185 { 186 GraphicsLayer::addChildAbove(layer, sibling); 187 downcast<CoordinatedGraphicsLayer>(*layer).setCoordinatorIncludingSubLayersIfNeeded(m_coordinator); 186 void CoordinatedGraphicsLayer::addChildAbove(Ref<GraphicsLayer>&& layer, GraphicsLayer* sibling) 187 { 188 GraphicsLayer* rawLayer = layer.ptr(); 189 GraphicsLayer::addChildAbove(WTFMove(layer), sibling); 190 downcast<CoordinatedGraphicsLayer>(*rawLayer).setCoordinatorIncludingSubLayersIfNeeded(m_coordinator); 188 191 didChangeChildren(); 189 192 } 190 193 191 void CoordinatedGraphicsLayer::addChildBelow(GraphicsLayer* layer, GraphicsLayer* sibling) 192 { 193 GraphicsLayer::addChildBelow(layer, sibling); 194 downcast<CoordinatedGraphicsLayer>(*layer).setCoordinatorIncludingSubLayersIfNeeded(m_coordinator); 194 void CoordinatedGraphicsLayer::addChildBelow(Ref<GraphicsLayer>&& layer, GraphicsLayer* sibling) 195 { 196 GraphicsLayer* rawLayer = layer.ptr(); 197 GraphicsLayer::addChildBelow(WTFMove(layer), sibling); 198 downcast<CoordinatedGraphicsLayer>(*rawLayer).setCoordinatorIncludingSubLayersIfNeeded(m_coordinator); 195 199 didChangeChildren(); 196 200 } 197 201 198 bool CoordinatedGraphicsLayer::replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild) 199 { 200 bool ok = GraphicsLayer::replaceChild(oldChild, newChild); 202 bool CoordinatedGraphicsLayer::replaceChild(GraphicsLayer* oldChild, Ref<GraphicsLayer>&& newChild) 203 { 204 GraphicsLayer* rawLayer = newChild.ptr(); 205 bool ok = GraphicsLayer::replaceChild(oldChild, WTFMove(newChild)); 201 206 if (!ok) 202 207 return false; 203 downcast<CoordinatedGraphicsLayer>(* newChild).setCoordinatorIncludingSubLayersIfNeeded(m_coordinator);208 downcast<CoordinatedGraphicsLayer>(*rawLayer).setCoordinatorIncludingSubLayersIfNeeded(m_coordinator); 204 209 didChangeChildren(); 205 210 return true; … … 496 501 } 497 502 498 void CoordinatedGraphicsLayer::setMaskLayer( GraphicsLayer*layer)503 void CoordinatedGraphicsLayer::setMaskLayer(RefPtr<GraphicsLayer>&& layer) 499 504 { 500 505 if (layer == maskLayer()) 501 506 return; 502 507 503 GraphicsLayer::setMaskLayer(layer); 504 505 if (!layer) 506 return; 507 508 layer->setSize(size()); 509 layer->setContentsVisible(contentsAreVisible()); 508 GraphicsLayer* rawLayer = layer.get(); 509 GraphicsLayer::setMaskLayer(WTFMove(layer)); 510 511 if (!rawLayer) 512 return; 513 514 rawLayer->setSize(size()); 515 rawLayer->setContentsVisible(contentsAreVisible()); 510 516 511 517 m_nicosia.delta.maskChanged = true; … … 733 739 if (localDelta.childrenChanged) { 734 740 state.children = WTF::map(children(), 735 [](auto *child)741 [](auto& child) 736 742 { 737 return downcast<CoordinatedGraphicsLayer>(child )->m_nicosia.layer;743 return downcast<CoordinatedGraphicsLayer>(child.get()).m_nicosia.layer; 738 744 }); 739 745 } … … 785 791 786 792 for (auto& child : children()) 787 downcast<CoordinatedGraphicsLayer>( *child).syncPendingStateChangesIncludingSubLayers();793 downcast<CoordinatedGraphicsLayer>(child.get()).syncPendingStateChangesIncludingSubLayers(); 788 794 } 789 795 … … 838 844 839 845 for (auto& child : children()) 840 downcast<CoordinatedGraphicsLayer>( *child).updateContentBuffersIncludingSubLayers();846 downcast<CoordinatedGraphicsLayer>(child.get()).updateContentBuffersIncludingSubLayers(); 841 847 } 842 848 … … 1008 1014 coordinator->attachLayer(this); 1009 1015 for (auto& child : children()) 1010 downcast<CoordinatedGraphicsLayer>( *child).setCoordinatorIncludingSubLayersIfNeeded(coordinator);1016 downcast<CoordinatedGraphicsLayer>(child.get()).setCoordinatorIncludingSubLayersIfNeeded(coordinator); 1011 1017 } 1012 1018 -
trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.h
r235314 r235953 64 64 65 65 // Reimplementations from GraphicsLayer.h. 66 bool setChildren( const Vector<GraphicsLayer*>&) override;67 void addChild( GraphicsLayer*) override;68 void addChildAtIndex( GraphicsLayer*, int) override;69 void addChildAbove( GraphicsLayer*, GraphicsLayer*) override;70 void addChildBelow( GraphicsLayer*, GraphicsLayer*) override;71 bool replaceChild(GraphicsLayer*, GraphicsLayer*) override;66 bool setChildren(Vector<Ref<GraphicsLayer>>&&) override; 67 void addChild(Ref<GraphicsLayer>&&) override; 68 void addChildAtIndex(Ref<GraphicsLayer>&&, int) override; 69 void addChildAbove(Ref<GraphicsLayer>&&, GraphicsLayer*) override; 70 void addChildBelow(Ref<GraphicsLayer>&&, GraphicsLayer*) override; 71 bool replaceChild(GraphicsLayer*, Ref<GraphicsLayer>&&) override; 72 72 void removeFromParent() override; 73 73 void setPosition(const FloatPoint&) override; … … 92 92 bool shouldDirectlyCompositeImage(Image*) const override; 93 93 void setContentsToPlatformLayer(PlatformLayer*, ContentsLayerPurpose) override; 94 void setMaskLayer( GraphicsLayer*) override;94 void setMaskLayer(RefPtr<GraphicsLayer>&&) override; 95 95 void setReplicatedByLayer(GraphicsLayer*) override; 96 96 void setNeedsDisplay() override; -
trunk/Source/WebCore/platform/graphics/win/GraphicsLayerDirect2D.cpp
r229209 r235953 47 47 namespace WebCore { 48 48 49 50 std::unique_ptr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerFactory* factory, GraphicsLayerClient& client, Type layerType) 49 Ref<GraphicsLayer> GraphicsLayer::create(GraphicsLayerFactory* factory, GraphicsLayerClient& client, Type layerType) 51 50 { 52 std::unique_ptr<GraphicsLayer> graphicsLayer;53 if (!factory)54 graphicsLayer = std::make_unique<GraphicsLayerDirect2D>(layerType, client);55 else56 graphicsLayer = factory->createGraphicsLayer(layerType, client);57 58 graphicsLayer->initialize(layerType);59 60 return graphicsLayer;51 if (factory) { 52 auto layer = factory->createGraphicsLayer(layerType, client); 53 layer->initialize(layerType); 54 return layer; 55 } 56 57 auto layer = adoptRef(*new GraphicsLayerCA(layerType, client); 58 layer->initialize(layerType); 59 return layer; 61 60 } 62 61 -
trunk/Source/WebCore/rendering/RenderLayerBacking.cpp
r235586 r235953 255 255 } 256 256 257 std::unique_ptr<GraphicsLayer> RenderLayerBacking::createGraphicsLayer(const String& name, GraphicsLayer::Type layerType)257 Ref<GraphicsLayer> RenderLayerBacking::createGraphicsLayer(const String& name, GraphicsLayer::Type layerType) 258 258 { 259 259 auto* graphicsLayerFactory = renderer().page().chrome().client().graphicsLayerFactory(); 260 260 261 std::unique_ptr<GraphicsLayer>graphicsLayer = GraphicsLayer::create(graphicsLayerFactory, *this, layerType);261 auto graphicsLayer = GraphicsLayer::create(graphicsLayerFactory, *this, layerType); 262 262 263 263 graphicsLayer->setName(name); … … 402 402 if (m_isFrameLayerWithTiledBacking) { 403 403 m_childContainmentLayer = createGraphicsLayer("Page TiledBacking containment"); 404 m_graphicsLayer->addChild( m_childContainmentLayer.get());404 m_graphicsLayer->addChild(*m_childContainmentLayer); 405 405 } 406 406 … … 710 710 if (auto* flatteningLayer = tileCacheFlatteningLayer()) { 711 711 if (layerConfigChanged || flatteningLayer->parent() != m_graphicsLayer.get()) 712 m_graphicsLayer->addChild( flatteningLayer);712 m_graphicsLayer->addChild(*flatteningLayer); 713 713 } 714 714 … … 1303 1303 m_contentsContainmentLayer->removeAllChildren(); 1304 1304 if (m_ancestorClippingLayer) 1305 m_ancestorClippingLayer->addChild( m_contentsContainmentLayer.get());1305 m_ancestorClippingLayer->addChild(*m_contentsContainmentLayer); 1306 1306 } 1307 1307 1308 1308 if (m_backgroundLayer) 1309 m_contentsContainmentLayer->addChild( m_backgroundLayer.get());1309 m_contentsContainmentLayer->addChild(*m_backgroundLayer); 1310 1310 1311 1311 if (m_contentsContainmentLayer) 1312 m_contentsContainmentLayer->addChild( m_graphicsLayer.get());1312 m_contentsContainmentLayer->addChild(*m_graphicsLayer); 1313 1313 else if (m_ancestorClippingLayer) 1314 m_ancestorClippingLayer->addChild( m_graphicsLayer.get());1314 m_ancestorClippingLayer->addChild(*m_graphicsLayer); 1315 1315 1316 1316 if (m_childContainmentLayer) { 1317 1317 m_childContainmentLayer->removeFromParent(); 1318 m_graphicsLayer->addChild( m_childContainmentLayer.get());1318 m_graphicsLayer->addChild(*m_childContainmentLayer); 1319 1319 } 1320 1320 … … 1322 1322 auto* superlayer = m_childContainmentLayer ? m_childContainmentLayer.get() : m_graphicsLayer.get(); 1323 1323 m_scrollingLayer->removeFromParent(); 1324 superlayer->addChild( m_scrollingLayer.get());1324 superlayer->addChild(*m_scrollingLayer); 1325 1325 } 1326 1326 … … 1330 1330 if (m_layerForHorizontalScrollbar) { 1331 1331 m_layerForHorizontalScrollbar->removeFromParent(); 1332 m_graphicsLayer->addChild( m_layerForHorizontalScrollbar.get());1332 m_graphicsLayer->addChild(*m_layerForHorizontalScrollbar); 1333 1333 } 1334 1334 if (m_layerForVerticalScrollbar) { 1335 1335 m_layerForVerticalScrollbar->removeFromParent(); 1336 m_graphicsLayer->addChild( m_layerForVerticalScrollbar.get());1336 m_graphicsLayer->addChild(*m_layerForVerticalScrollbar); 1337 1337 } 1338 1338 if (m_layerForScrollCorner) { 1339 1339 m_layerForScrollCorner->removeFromParent(); 1340 m_graphicsLayer->addChild( m_layerForScrollCorner.get());1340 m_graphicsLayer->addChild(*m_layerForScrollCorner); 1341 1341 } 1342 1342 } … … 1691 1691 m_maskLayer->setPaintingPhase(maskPhases); 1692 1692 layerChanged = true; 1693 m_graphicsLayer->setMaskLayer(m_maskLayer. get());1693 m_graphicsLayer->setMaskLayer(m_maskLayer.copyRef()); 1694 1694 } 1695 1695 } else if (m_maskLayer) { … … 1722 1722 m_childClippingMaskLayer->setDrawsContent(true); 1723 1723 m_childClippingMaskLayer->setPaintingPhase(GraphicsLayerPaintChildClippingMask); 1724 clippingLayer()->setMaskLayer(m_childClippingMaskLayer. get());1724 clippingLayer()->setMaskLayer(m_childClippingMaskLayer.copyRef()); 1725 1725 } 1726 1726 } … … 1755 1755 paintPhase |= GraphicsLayerPaintForeground; 1756 1756 m_scrollingContentsLayer->setPaintingPhase(paintPhase); 1757 m_scrollingLayer->addChild( m_scrollingContentsLayer.get());1757 m_scrollingLayer->addChild(*m_scrollingContentsLayer); 1758 1758 } else { 1759 1759 compositor().willRemoveScrollingLayerWithBacking(m_owningLayer, *this); -
trunk/Source/WebCore/rendering/RenderLayerBacking.h
r234768 r235953 137 137 void setIsScrollCoordinatedWithViewportConstrainedRole(bool); 138 138 139 bool hasMaskLayer() const { return m_maskLayer != 0; }139 bool hasMaskLayer() const { return m_maskLayer; } 140 140 bool hasChildClippingMaskLayer() const { return m_childClippingMaskLayer != nullptr; } 141 141 … … 268 268 LayoutRect compositedBoundsIncludingMargin() const; 269 269 270 std::unique_ptr<GraphicsLayer> createGraphicsLayer(const String&, GraphicsLayer::Type = GraphicsLayer::Type::Normal);270 Ref<GraphicsLayer> createGraphicsLayer(const String&, GraphicsLayer::Type = GraphicsLayer::Type::Normal); 271 271 272 272 RenderLayerModelObject& renderer() const { return m_owningLayer.renderer(); } … … 356 356 RenderLayer& m_owningLayer; 357 357 358 std::unique_ptr<GraphicsLayer> m_ancestorClippingLayer; // Only used if we are clipped by an ancestor which is not a stacking context.359 std::unique_ptr<GraphicsLayer> m_contentsContainmentLayer; // Only used if we have a background layer; takes the transform.360 std::unique_ptr<GraphicsLayer> m_graphicsLayer;361 std::unique_ptr<GraphicsLayer> m_foregroundLayer; // Only used in cases where we need to draw the foreground separately.362 std::unique_ptr<GraphicsLayer> m_backgroundLayer; // Only used in cases where we need to draw the background separately.363 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.364 std::unique_ptr<GraphicsLayer> m_maskLayer; // Only used if we have a mask and/or clip-path.365 std::unique_ptr<GraphicsLayer> m_childClippingMaskLayer; // Only used if we have to clip child layers or accelerated contents with border radius or clip-path.366 367 std::unique_ptr<GraphicsLayer> m_layerForHorizontalScrollbar;368 std::unique_ptr<GraphicsLayer> m_layerForVerticalScrollbar;369 std::unique_ptr<GraphicsLayer> m_layerForScrollCorner;370 371 std::unique_ptr<GraphicsLayer> m_scrollingLayer; // Only used if the layer is using composited scrolling.372 std::unique_ptr<GraphicsLayer> m_scrollingContentsLayer; // Only used if the layer is using composited scrolling.358 RefPtr<GraphicsLayer> m_ancestorClippingLayer; // Only used if we are clipped by an ancestor which is not a stacking context. 359 RefPtr<GraphicsLayer> m_contentsContainmentLayer; // Only used if we have a background layer; takes the transform. 360 RefPtr<GraphicsLayer> m_graphicsLayer; 361 RefPtr<GraphicsLayer> m_foregroundLayer; // Only used in cases where we need to draw the foreground separately. 362 RefPtr<GraphicsLayer> m_backgroundLayer; // Only used in cases where we need to draw the background separately. 363 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. 364 RefPtr<GraphicsLayer> m_maskLayer; // Only used if we have a mask and/or clip-path. 365 RefPtr<GraphicsLayer> m_childClippingMaskLayer; // Only used if we have to clip child layers or accelerated contents with border radius or clip-path. 366 367 RefPtr<GraphicsLayer> m_layerForHorizontalScrollbar; 368 RefPtr<GraphicsLayer> m_layerForVerticalScrollbar; 369 RefPtr<GraphicsLayer> m_layerForScrollCorner; 370 371 RefPtr<GraphicsLayer> m_scrollingLayer; // Only used if the layer is using composited scrolling. 372 RefPtr<GraphicsLayer> m_scrollingContentsLayer; // Only used if the layer is using composited scrolling. 373 373 374 374 LayoutRect m_compositedBounds; -
trunk/Source/WebCore/rendering/RenderLayerCompositor.cpp
r235560 r235953 759 759 if (needHierarchyUpdate) { 760 760 // Update the hierarchy of the compositing layers. 761 Vector< GraphicsLayer*> childList;761 Vector<Ref<GraphicsLayer>> childList; 762 762 rebuildCompositingLayerTree(*updateRoot, childList, 0); 763 763 … … 770 770 destroyRootLayer(); 771 771 else if (m_rootContentLayer) 772 m_rootContentLayer->setChildren( childList);772 m_rootContentLayer->setChildren(WTFMove(childList)); 773 773 } 774 774 … … 803 803 } 804 804 805 void RenderLayerCompositor::appendDocumentOverlayLayers(Vector< GraphicsLayer*>& childList)805 void RenderLayerCompositor::appendDocumentOverlayLayers(Vector<Ref<GraphicsLayer>>& childList) 806 806 { 807 807 if (!isMainFrameCompositor() || !m_compositing) 808 808 return; 809 809 810 childList.append(&page().pageOverlayController().layerWithDocumentOverlays()); 810 Ref<GraphicsLayer> overlayHost = page().pageOverlayController().layerWithDocumentOverlays(); 811 childList.append(WTFMove(overlayHost)); 811 812 } 812 813 … … 1524 1525 auto* hostedLayer = childLayer.backing()->childForSuperlayers(); 1525 1526 1526 hostingLayer->addChild( hostedLayer);1527 hostingLayer->addChild(*hostedLayer); 1527 1528 } else 1528 1529 childLayer.backing()->childForSuperlayers()->removeFromParent(); … … 1546 1547 #endif 1547 1548 1548 void RenderLayerCompositor::rebuildCompositingLayerTree(RenderLayer& layer, Vector< GraphicsLayer*>& childLayersOfEnclosingLayer, int depth)1549 void RenderLayerCompositor::rebuildCompositingLayerTree(RenderLayer& layer, Vector<Ref<GraphicsLayer>>& childLayersOfEnclosingLayer, int depth) 1549 1550 { 1550 1551 // Make the layer compositing if necessary, and set up clipping and content layers. … … 1582 1583 // If this layer has backing, then we are collecting its children, otherwise appending 1583 1584 // to the compositing child list of an enclosing layer. 1584 Vector< GraphicsLayer*> layerChildren;1585 Vector<GraphicsLayer*>& childList = layerBacking ? layerChildren : childLayersOfEnclosingLayer;1585 Vector<Ref<GraphicsLayer>> layerChildren; 1586 auto& childList = layerBacking ? layerChildren : childLayersOfEnclosingLayer; 1586 1587 1587 1588 #if !ASSERT_DISABLED … … 1595 1596 // If a negative z-order child is compositing, we get a foreground layer which needs to get parented. 1596 1597 if (layerBacking && layerBacking->foregroundLayer()) 1597 childList.append( layerBacking->foregroundLayer());1598 childList.append(*layerBacking->foregroundLayer()); 1598 1599 } 1599 1600 … … 1614 1615 1615 1616 if (!parented) 1616 layerBacking->parentForSublayers()->setChildren( layerChildren);1617 layerBacking->parentForSublayers()->setChildren(WTFMove(layerChildren)); 1617 1618 1618 1619 // If the layer has a clipping layer the overflow controls layers will be siblings of the clipping layer. … … 1621 1622 if (auto* overflowControlLayer = layerBacking->layerForHorizontalScrollbar()) { 1622 1623 overflowControlLayer->removeFromParent(); 1623 layerBacking->parentForSublayers()->addChild( overflowControlLayer);1624 layerBacking->parentForSublayers()->addChild(*overflowControlLayer); 1624 1625 } 1625 1626 1626 1627 if (auto* overflowControlLayer = layerBacking->layerForVerticalScrollbar()) { 1627 1628 overflowControlLayer->removeFromParent(); 1628 layerBacking->parentForSublayers()->addChild( overflowControlLayer);1629 layerBacking->parentForSublayers()->addChild(*overflowControlLayer); 1629 1630 } 1630 1631 1631 1632 if (auto* overflowControlLayer = layerBacking->layerForScrollCorner()) { 1632 1633 overflowControlLayer->removeFromParent(); 1633 layerBacking->parentForSublayers()->addChild( overflowControlLayer);1634 layerBacking->parentForSublayers()->addChild(*overflowControlLayer); 1634 1635 } 1635 1636 } 1636 1637 1637 childLayersOfEnclosingLayer.append( layerBacking->childForSuperlayers());1638 childLayersOfEnclosingLayer.append(*layerBacking->childForSuperlayers()); 1638 1639 } 1639 1640 … … 1810 1811 auto* hostingLayer = backing->parentForSublayers(); 1811 1812 auto* rootLayer = innerCompositor->rootGraphicsLayer(); 1812 if (hostingLayer->children().size() != 1 || hostingLayer->children()[0] != rootLayer) {1813 if (hostingLayer->children().size() != 1 || hostingLayer->children()[0].ptr() != rootLayer) { 1813 1814 hostingLayer->removeAllChildren(); 1814 hostingLayer->addChild( rootLayer);1815 hostingLayer->addChild(*rootLayer); 1815 1816 } 1816 1817 return true; … … 3047 3048 m_layerForTopOverhangArea = GraphicsLayer::create(graphicsLayerFactory(), *this); 3048 3049 m_layerForTopOverhangArea->setName("top overhang"); 3049 m_scrollLayer->addChildBelow( m_layerForTopOverhangArea.get(), m_rootContentLayer.get());3050 m_scrollLayer->addChildBelow(*m_layerForTopOverhangArea, m_rootContentLayer.get()); 3050 3051 } 3051 3052 … … 3069 3070 m_layerForBottomOverhangArea = GraphicsLayer::create(graphicsLayerFactory(), *this); 3070 3071 m_layerForBottomOverhangArea->setName("bottom overhang"); 3071 m_scrollLayer->addChildBelow( m_layerForBottomOverhangArea.get(), m_rootContentLayer.get());3072 m_scrollLayer->addChildBelow(*m_layerForBottomOverhangArea, m_rootContentLayer.get()); 3072 3073 } 3073 3074 … … 3098 3099 m_layerForHeader = GraphicsLayer::create(graphicsLayerFactory(), *this); 3099 3100 m_layerForHeader->setName("header"); 3100 m_scrollLayer->addChildAbove( m_layerForHeader.get(), m_rootContentLayer.get());3101 m_scrollLayer->addChildAbove(*m_layerForHeader, m_rootContentLayer.get()); 3101 3102 m_renderView.frameView().addPaintPendingMilestones(DidFirstFlushForHeaderLayer); 3102 3103 } … … 3136 3137 m_layerForFooter = GraphicsLayer::create(graphicsLayerFactory(), *this); 3137 3138 m_layerForFooter->setName("footer"); 3138 m_scrollLayer->addChildAbove( m_layerForFooter.get(), m_rootContentLayer.get());3139 m_scrollLayer->addChildAbove(*m_layerForFooter, m_rootContentLayer.get()); 3139 3140 } 3140 3141 … … 3259 3260 // We want the overhang areas layer to be positioned below the frame contents, 3260 3261 // so insert it below the clip layer. 3261 m_overflowControlsHostLayer->addChildBelow( m_layerForOverhangAreas.get(), m_clipLayer.get());3262 m_overflowControlsHostLayer->addChildBelow(*m_layerForOverhangAreas, m_clipLayer.get()); 3262 3263 } 3263 3264 } else if (m_layerForOverhangAreas) { … … 3275 3276 m_contentShadowLayer->setCustomAppearance(GraphicsLayer::CustomAppearance::ScrollingShadow); 3276 3277 3277 m_scrollLayer->addChildBelow( m_contentShadowLayer.get(), m_rootContentLayer.get());3278 m_scrollLayer->addChildBelow(*m_contentShadowLayer, m_rootContentLayer.get()); 3278 3279 } 3279 3280 } else if (m_contentShadowLayer) { … … 3292 3293 m_layerForHorizontalScrollbar->setAcceleratesDrawing(acceleratedDrawingEnabled()); 3293 3294 #endif 3294 m_overflowControlsHostLayer->addChild( m_layerForHorizontalScrollbar.get());3295 m_overflowControlsHostLayer->addChild(*m_layerForHorizontalScrollbar); 3295 3296 3296 3297 if (auto* scrollingCoordinator = this->scrollingCoordinator()) … … 3314 3315 m_layerForVerticalScrollbar->setAcceleratesDrawing(acceleratedDrawingEnabled()); 3315 3316 #endif 3316 m_overflowControlsHostLayer->addChild( m_layerForVerticalScrollbar.get());3317 m_overflowControlsHostLayer->addChild(*m_layerForVerticalScrollbar); 3317 3318 3318 3319 if (auto* scrollingCoordinator = this->scrollingCoordinator()) … … 3336 3337 m_layerForScrollCorner->setAcceleratesDrawing(acceleratedDrawingEnabled()); 3337 3338 #endif 3338 m_overflowControlsHostLayer->addChild( m_layerForScrollCorner.get());3339 m_overflowControlsHostLayer->addChild(*m_layerForScrollCorner); 3339 3340 } 3340 3341 } else if (m_layerForScrollCorner) { … … 3388 3389 3389 3390 // Hook them up 3390 m_overflowControlsHostLayer->addChild( m_clipLayer.get());3391 m_clipLayer->addChild( m_scrollLayer.get());3392 m_scrollLayer->addChild( m_rootContentLayer.get());3391 m_overflowControlsHostLayer->addChild(*m_clipLayer); 3392 m_clipLayer->addChild(*m_scrollLayer); 3393 m_scrollLayer->addChild(*m_rootContentLayer); 3393 3394 3394 3395 m_clipLayer->setSize(m_renderView.frameView().sizeForVisibleContent()); … … 3561 3562 return; 3562 3563 3563 m_rootContentLayer->addChild(&page().pageOverlayController().layerWithDocumentOverlays()); 3564 Ref<GraphicsLayer> overlayHost = page().pageOverlayController().layerWithDocumentOverlays(); 3565 m_rootContentLayer->addChild(WTFMove(overlayHost)); 3564 3566 } 3565 3567 -
trunk/Source/WebCore/rendering/RenderLayerCompositor.h
r234768 r235953 377 377 378 378 // Recurses down the tree, parenting descendant compositing layers and collecting an array of child layers for the current compositing layer. 379 void rebuildCompositingLayerTree(RenderLayer&, Vector< GraphicsLayer*>& childGraphicsLayersOfEnclosingLayer, int depth);379 void rebuildCompositingLayerTree(RenderLayer&, Vector<Ref<GraphicsLayer>>& childGraphicsLayersOfEnclosingLayer, int depth); 380 380 381 381 // Recurses down the tree, updating layer geometry only. … … 389 389 bool isRunningTransformAnimation(RenderLayerModelObject&) const; 390 390 391 void appendDocumentOverlayLayers(Vector< GraphicsLayer*>&);391 void appendDocumentOverlayLayers(Vector<Ref<GraphicsLayer>>&); 392 392 bool hasAnyAdditionalCompositedLayers(const RenderLayer& rootLayer) const; 393 393 … … 489 489 private: 490 490 RenderView& m_renderView; 491 std::unique_ptr<GraphicsLayer> m_rootContentLayer;491 RefPtr<GraphicsLayer> m_rootContentLayer; 492 492 Timer m_updateCompositingLayersTimer; 493 493 … … 525 525 526 526 // Enclosing clipping layer for iframe content 527 std::unique_ptr<GraphicsLayer> m_clipLayer;528 std::unique_ptr<GraphicsLayer> m_scrollLayer;527 RefPtr<GraphicsLayer> m_clipLayer; 528 RefPtr<GraphicsLayer> m_scrollLayer; 529 529 530 530 #if PLATFORM(IOS) … … 536 536 537 537 // Enclosing layer for overflow controls and the clipping layer 538 std::unique_ptr<GraphicsLayer> m_overflowControlsHostLayer;538 RefPtr<GraphicsLayer> m_overflowControlsHostLayer; 539 539 540 540 // Layers for overflow controls 541 std::unique_ptr<GraphicsLayer> m_layerForHorizontalScrollbar;542 std::unique_ptr<GraphicsLayer> m_layerForVerticalScrollbar;543 std::unique_ptr<GraphicsLayer> m_layerForScrollCorner;541 RefPtr<GraphicsLayer> m_layerForHorizontalScrollbar; 542 RefPtr<GraphicsLayer> m_layerForVerticalScrollbar; 543 RefPtr<GraphicsLayer> m_layerForScrollCorner; 544 544 #if ENABLE(RUBBER_BANDING) 545 std::unique_ptr<GraphicsLayer> m_layerForOverhangAreas;546 std::unique_ptr<GraphicsLayer> m_contentShadowLayer;547 std::unique_ptr<GraphicsLayer> m_layerForTopOverhangArea;548 std::unique_ptr<GraphicsLayer> m_layerForBottomOverhangArea;549 std::unique_ptr<GraphicsLayer> m_layerForHeader;550 std::unique_ptr<GraphicsLayer> m_layerForFooter;545 RefPtr<GraphicsLayer> m_layerForOverhangAreas; 546 RefPtr<GraphicsLayer> m_contentShadowLayer; 547 RefPtr<GraphicsLayer> m_layerForTopOverhangArea; 548 RefPtr<GraphicsLayer> m_layerForBottomOverhangArea; 549 RefPtr<GraphicsLayer> m_layerForHeader; 550 RefPtr<GraphicsLayer> m_layerForFooter; 551 551 #endif 552 552 -
trunk/Source/WebKit/ChangeLog
r235952 r235953 1 2018-09-11 Simon Fraser <simon.fraser@apple.com> 2 3 Make GraphicsLayers ref-counted, so their tree can persist when disconnected from RenderLayerBackings 4 https://bugs.webkit.org/show_bug.cgi?id=189521 5 6 Reviewed by Tim Horton. 7 8 Make GraphicsLayer be RefCounted<GraphicsLayer>. GraphicsLayers own their children, via a Vector<Ref<GraphicsLayer>>. 9 10 RenderLayerBacking and other holders of GraphicsLayers use RefPtr<GraphicsLayer>. 11 12 All the other changes are just to adapt to the new ownership patterns. 13 14 I verified that no GraphicsLayers were leaked or abandoned after this change. 15 16 * WebProcess/WebCoreSupport/WebInspectorClient.cpp: 17 (WebKit::WebInspectorClient::~WebInspectorClient): 18 (WebKit::WebInspectorClient::showPaintRect): 19 (WebKit::WebInspectorClient::animationEndedForLayer): 20 * WebProcess/WebCoreSupport/WebInspectorClient.h: 21 * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeContext.h: 22 * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeContext.mm: 23 (WebKit::RemoteLayerTreeContext::createGraphicsLayer): 24 * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.h: 25 * WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.mm: 26 (WebKit::RemoteLayerTreeDrawingArea::updateRootLayers): 27 (WebKit::RemoteLayerTreeDrawingArea::flushLayers): 28 1 29 2018-09-12 Chris Dumez <cdumez@apple.com> 2 30 -
trunk/Source/WebKit/WebProcess/WebCoreSupport/WebInspectorClient.cpp
r235205 r235953 67 67 WebInspectorClient::~WebInspectorClient() 68 68 { 69 for (auto layer : m_paintRectLayers) {69 for (auto& layer : m_paintRectLayers) 70 70 layer->removeFromParent(); 71 delete layer;72 }71 72 m_paintRectLayers.clear(); 73 73 74 74 if (m_paintRectOverlay && m_page->corePage()) … … 153 153 m_paintIndicatorLayerClient = std::make_unique<RepaintIndicatorLayerClient>(*this); 154 154 155 std::unique_ptr<GraphicsLayer>paintLayer = GraphicsLayer::create(m_page->drawingArea()->graphicsLayerFactory(), *m_paintIndicatorLayerClient);155 auto paintLayer = GraphicsLayer::create(m_page->drawingArea()->graphicsLayerFactory(), *m_paintIndicatorLayerClient); 156 156 157 157 paintLayer->setName("paint rect"); … … 166 166 fadeKeyframes.insert(std::make_unique<FloatAnimationValue>(0.25, 0)); 167 167 168 RefPtr<Animation>opacityAnimation = Animation::create();168 auto opacityAnimation = Animation::create(); 169 169 opacityAnimation->setDuration(0.25); 170 170 171 paintLayer->addAnimation(fadeKeyframes, FloatSize(), opacityAnimation.get(), "opacity"_s, 0); 172 173 m_paintRectLayers.add(paintLayer.get()); 171 paintLayer->addAnimation(fadeKeyframes, FloatSize(), opacityAnimation.ptr(), "opacity"_s, 0); 172 173 GraphicsLayer& rawLayer = paintLayer.get(); 174 m_paintRectLayers.add(WTFMove(paintLayer)); 174 175 175 176 GraphicsLayer& overlayRootLayer = m_paintRectOverlay->layer(); 176 overlayRootLayer.addChild( paintLayer.release());177 overlayRootLayer.addChild(rawLayer); 177 178 } 178 179 179 180 void WebInspectorClient::animationEndedForLayer(const GraphicsLayer* layer) 180 181 { 181 const_cast<GraphicsLayer*>(layer)->removeFromParent();182 m_paintRectLayers.remove(const_cast<GraphicsLayer*>(layer));183 delete layer;182 GraphicsLayer* nonConstLayer = const_cast<GraphicsLayer*>(layer); 183 nonConstLayer->removeFromParent(); 184 m_paintRectLayers.remove(*nonConstLayer); 184 185 } 185 186 -
trunk/Source/WebKit/WebProcess/WebCoreSupport/WebInspectorClient.h
r231439 r235953 85 85 RefPtr<WebCore::PageOverlay> m_paintRectOverlay; 86 86 std::unique_ptr<RepaintIndicatorLayerClient> m_paintIndicatorLayerClient; 87 HashSet< WebCore::GraphicsLayer*> m_paintRectLayers; // Ideally this would be HashSet<std::unique_ptr<GraphicsLayer>> but that doesn't work yet. webkit.org/b/13616687 HashSet<Ref<WebCore::GraphicsLayer>> m_paintRectLayers; 88 88 }; 89 89 -
trunk/Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.cpp
r235221 r235953 86 86 m_rootCompositingLayer = graphicsLayer; 87 87 if (m_rootCompositingLayer) 88 m_rootLayer->addChildAtIndex( m_rootCompositingLayer, 0);88 m_rootLayer->addChildAtIndex(*m_rootCompositingLayer, 0); 89 89 } 90 90 … … 99 99 m_overlayCompositingLayer = graphicsLayer; 100 100 if (m_overlayCompositingLayer) 101 m_rootLayer->addChild( m_overlayCompositingLayer);101 m_rootLayer->addChild(*m_overlayCompositingLayer); 102 102 } 103 103 … … 232 232 } 233 233 234 std::unique_ptr<GraphicsLayer> CompositingCoordinator::createGraphicsLayer(GraphicsLayer::Type layerType, GraphicsLayerClient& client)235 { 236 CoordinatedGraphicsLayer* layer = new CoordinatedGraphicsLayer(layerType, client);234 Ref<GraphicsLayer> CompositingCoordinator::createGraphicsLayer(GraphicsLayer::Type layerType, GraphicsLayerClient& client) 235 { 236 auto layer = adoptRef(*new CoordinatedGraphicsLayer(layerType, client)); 237 237 layer->setCoordinator(this); 238 238 m_nicosia.state.layers.add(layer->compositionLayer()); 239 m_registeredLayers.add(layer->id(), layer );239 m_registeredLayers.add(layer->id(), layer.ptr()); 240 240 layer->setNeedsVisibleRectAdjustment(); 241 notifyFlushRequired(layer );242 return std::unique_ptr<GraphicsLayer>(layer);241 notifyFlushRequired(layer.ptr()); 242 return WTFMove(layer); 243 243 } 244 244 -
trunk/Source/WebKit/WebProcess/WebPage/CoordinatedGraphics/CompositingCoordinator.h
r235221 r235953 104 104 105 105 // GraphicsLayerFactory 106 std::unique_ptr<WebCore::GraphicsLayer> createGraphicsLayer(WebCore::GraphicsLayer::Type, WebCore::GraphicsLayerClient&) override;106 Ref<WebCore::GraphicsLayer> createGraphicsLayer(WebCore::GraphicsLayer::Type, WebCore::GraphicsLayerClient&) override; 107 107 108 108 void initializeRootCompositingLayerIfNeeded(); … … 115 115 CompositingCoordinator::Client& m_client; 116 116 117 std::unique_ptr<WebCore::GraphicsLayer> m_rootLayer;117 RefPtr<WebCore::GraphicsLayer> m_rootLayer; 118 118 WebCore::GraphicsLayer* m_rootCompositingLayer { nullptr }; 119 119 WebCore::GraphicsLayer* m_overlayCompositingLayer { nullptr }; -
trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeContext.h
r229174 r235953 75 75 private: 76 76 // WebCore::GraphicsLayerFactory 77 std::unique_ptr<WebCore::GraphicsLayer> createGraphicsLayer(WebCore::GraphicsLayer::Type, WebCore::GraphicsLayerClient&) override;77 Ref<WebCore::GraphicsLayer> createGraphicsLayer(WebCore::GraphicsLayer::Type, WebCore::GraphicsLayerClient&) override; 78 78 79 79 WebPage& m_webPage; -
trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeContext.mm
r235205 r235953 110 110 } 111 111 112 std::unique_ptr<GraphicsLayer> RemoteLayerTreeContext::createGraphicsLayer(WebCore::GraphicsLayer::Type layerType, GraphicsLayerClient& client)112 Ref<GraphicsLayer> RemoteLayerTreeContext::createGraphicsLayer(WebCore::GraphicsLayer::Type layerType, GraphicsLayerClient& client) 113 113 { 114 return std::make_unique<GraphicsLayerCARemote>(layerType, client, *this);114 return adoptRef(*new GraphicsLayerCARemote(layerType, client, *this)); 115 115 } 116 116 -
trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.h
r234920 r235953 138 138 139 139 std::unique_ptr<RemoteLayerTreeContext> m_remoteLayerTreeContext; 140 std::unique_ptr<WebCore::GraphicsLayer> m_rootLayer;140 Ref<WebCore::GraphicsLayer> m_rootLayer; 141 141 142 142 WebCore::IntSize m_viewSize; -
trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteLayerTreeDrawingArea.mm
r235205 r235953 116 116 void RemoteLayerTreeDrawingArea::updateRootLayers() 117 117 { 118 Vector< GraphicsLayer*> children;118 Vector<Ref<GraphicsLayer>> children; 119 119 if (m_contentLayer) { 120 children.append( m_contentLayer);120 children.append(*m_contentLayer); 121 121 if (m_viewOverlayRootLayer) 122 children.append( m_viewOverlayRootLayer);123 } 124 125 m_rootLayer->setChildren( children);122 children.append(*m_viewOverlayRootLayer); 123 } 124 125 m_rootLayer->setChildren(WTFMove(children)); 126 126 } 127 127 … … 319 319 void RemoteLayerTreeDrawingArea::flushLayers() 320 320 { 321 if (!m_rootLayer)322 return;323 324 321 if (m_isFlushingSuspended) { 325 322 m_hasDeferredFlush = true; … … 367 364 layerTransaction.setCallbackIDs(WTFMove(m_pendingCallbackIDs)); 368 365 m_remoteLayerTreeContext->setNextFlushIsForImmediatePaint(m_nextFlushIsForImmediatePaint); 369 m_remoteLayerTreeContext->buildTransaction(layerTransaction, *downcast<GraphicsLayerCARemote>( *m_rootLayer).platformCALayer());366 m_remoteLayerTreeContext->buildTransaction(layerTransaction, *downcast<GraphicsLayerCARemote>(m_rootLayer.get()).platformCALayer()); 370 367 m_remoteLayerTreeContext->setNextFlushIsForImmediatePaint(false); 371 368 backingStoreCollection.willCommitLayerTree(layerTransaction); -
trunk/Source/WebKitLegacy/win/WebCoreSupport/AcceleratedCompositingContext.cpp
r230211 r235953 98 98 #endif 99 99 100 m_rootLayer->addChild( m_nonCompositedContentLayer.get());100 m_rootLayer->addChild(*m_nonCompositedContentLayer); 101 101 m_nonCompositedContentLayer->setNeedsDisplay(); 102 102 … … 212 212 213 213 m_nonCompositedContentLayer->removeAllChildren(); 214 m_nonCompositedContentLayer->addChild( graphicsLayer);214 m_nonCompositedContentLayer->addChild(*graphicsLayer); 215 215 216 216 stopAnyPendingLayerFlush(); -
trunk/Source/WebKitLegacy/win/WebCoreSupport/AcceleratedCompositingContext.h
r219876 r235953 72 72 std::unique_ptr<WebCore::GLContext> m_context; 73 73 HWND m_window; 74 std::unique_ptr<WebCore::GraphicsLayer> m_rootLayer;75 std::unique_ptr<WebCore::GraphicsLayer> m_nonCompositedContentLayer;74 RefPtr<WebCore::GraphicsLayer> m_rootLayer; 75 RefPtr<WebCore::GraphicsLayer> m_nonCompositedContentLayer; 76 76 std::unique_ptr<WebCore::TextureMapper> m_textureMapper; 77 77 WebCore::TextureMapperFPSCounter m_fpsCounter; -
trunk/Source/WebKitLegacy/win/WebView.cpp
r235560 r235953 7146 7146 if (!m_backingLayer) 7147 7147 return; 7148 m_backingLayer->addChild(layer); 7148 7149 if (layer) 7150 m_backingLayer->addChild(*layer); 7151 else 7152 m_backingLayer->removeAllChildren(); 7153 7149 7154 #elif USE(TEXTURE_MAPPER_GL) 7150 7155 if (!m_acceleratedCompositingContext) -
trunk/Source/WebKitLegacy/win/WebView.h
r229174 r235953 706 706 #if USE(CA) 707 707 RefPtr<WebCore::CACFLayerTreeHost> m_layerTreeHost; 708 std::unique_ptr<WebCore::GraphicsLayer> m_backingLayer;708 RefPtr<WebCore::GraphicsLayer> m_backingLayer; 709 709 #elif USE(TEXTURE_MAPPER_GL) 710 710 std::unique_ptr<AcceleratedCompositingContext> m_acceleratedCompositingContext;
Note:
See TracChangeset
for help on using the changeset viewer.