Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/graphics/compositing/PaintArtifactCompositor.h" | 5 #include "platform/graphics/compositing/PaintArtifactCompositor.h" |
| 6 | 6 |
| 7 #include "cc/layers/content_layer_client.h" | 7 #include "cc/layers/content_layer_client.h" |
| 8 #include "cc/layers/layer.h" | 8 #include "cc/layers/layer.h" |
| 9 #include "cc/layers/picture_layer.h" | 9 #include "cc/layers/picture_layer.h" |
| 10 #include "cc/playback/display_item_list.h" | 10 #include "cc/playback/display_item_list.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 // TODO(jbroman): Actually calculate memory usage. | 57 // TODO(jbroman): Actually calculate memory usage. |
| 58 return 0; | 58 return 0; |
| 59 } | 59 } |
| 60 | 60 |
| 61 private: | 61 private: |
| 62 scoped_refptr<cc::DisplayItemList> m_ccDisplayItemList; | 62 scoped_refptr<cc::DisplayItemList> m_ccDisplayItemList; |
| 63 gfx::Rect m_paintableRegion; | 63 gfx::Rect m_paintableRegion; |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 PaintArtifactCompositor::PaintArtifactCompositor() | 66 PaintArtifactCompositor::PaintArtifactCompositor() |
| 67 : m_propertyTreeSequenceNumber(0) | |
| 67 { | 68 { |
| 68 if (!RuntimeEnabledFeatures::slimmingPaintV2Enabled()) | 69 if (!RuntimeEnabledFeatures::slimmingPaintV2Enabled()) |
| 69 return; | 70 return; |
| 70 m_rootLayer = cc::Layer::Create(); | 71 m_rootLayer = cc::Layer::Create(); |
| 71 m_webLayer = adoptPtr(Platform::current()->compositorSupport()->createLayerF romCCLayer(m_rootLayer.get())); | 72 m_webLayer = adoptPtr(Platform::current()->compositorSupport()->createLayerF romCCLayer(m_rootLayer.get())); |
| 72 } | 73 } |
| 73 | 74 |
| 74 PaintArtifactCompositor::~PaintArtifactCompositor() | 75 PaintArtifactCompositor::~PaintArtifactCompositor() |
| 75 { | 76 { |
| 76 } | 77 } |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 return nullptr; | 250 return nullptr; |
| 250 | 251 |
| 251 const auto& foreignLayerDisplayItem = static_cast<const ForeignLayerDisplayI tem&>(displayItem); | 252 const auto& foreignLayerDisplayItem = static_cast<const ForeignLayerDisplayI tem&>(displayItem); |
| 252 layerOffset = gfx::Vector2dF(foreignLayerDisplayItem.location().x(), foreign LayerDisplayItem.location().y()); | 253 layerOffset = gfx::Vector2dF(foreignLayerDisplayItem.location().x(), foreign LayerDisplayItem.location().y()); |
| 253 scoped_refptr<cc::Layer> layer = foreignLayerDisplayItem.layer(); | 254 scoped_refptr<cc::Layer> layer = foreignLayerDisplayItem.layer(); |
| 254 layer->SetBounds(foreignLayerDisplayItem.bounds()); | 255 layer->SetBounds(foreignLayerDisplayItem.bounds()); |
| 255 layer->SetIsDrawable(true); | 256 layer->SetIsDrawable(true); |
| 256 return layer; | 257 return layer; |
| 257 } | 258 } |
| 258 | 259 |
| 259 static const int kInvalidNodeId = -1; | |
| 260 static const int kRealRootNodeId = 0; | |
| 261 static const int kSecondaryRootNodeId = 1; | |
| 262 static const int kPropertyTreeSequenceNumber = 1; | |
| 263 | |
| 264 // Creates a minimal set of property trees for the compositor. | |
| 265 void setMinimalPropertyTrees(cc::PropertyTrees* propertyTrees, int ownerId) | |
| 266 { | |
| 267 // cc's property trees expect a child of the actual root to be used. So we | |
| 268 // need to create and populate an additional node for each type of tree. | |
| 269 | |
| 270 cc::TransformTree& transformTree = propertyTrees->transform_tree; | |
| 271 if (transformTree.size() < 2) { | |
| 272 transformTree.Insert(cc::TransformNode(), kRealRootNodeId); | |
| 273 cc::TransformNode& transformNode = *transformTree.back(); | |
| 274 transformNode.data.target_id = kRealRootNodeId; | |
| 275 transformNode.data.content_target_id = kSecondaryRootNodeId; | |
| 276 transformNode.data.source_node_id = kRealRootNodeId; | |
| 277 transformNode.data.needs_local_transform_update = true; | |
| 278 transformNode.owner_id = ownerId; | |
| 279 transformTree.set_needs_update(true); | |
| 280 } | |
| 281 DCHECK_EQ(transformTree.size(), 2u); | |
| 282 | |
| 283 cc::ClipTree& clipTree = propertyTrees->clip_tree; | |
| 284 if (clipTree.size() < 2) { | |
| 285 clipTree.Insert(cc::ClipNode(), kRealRootNodeId); | |
| 286 cc::ClipNode& clipNode = *clipTree.back(); | |
| 287 clipNode.data.transform_id = kSecondaryRootNodeId; | |
| 288 clipNode.data.target_id = kSecondaryRootNodeId; | |
| 289 clipNode.owner_id = ownerId; | |
| 290 clipTree.set_needs_update(true); | |
| 291 } | |
| 292 DCHECK_EQ(clipTree.size(), 2u); | |
| 293 | |
| 294 cc::EffectTree& effectTree = propertyTrees->effect_tree; | |
| 295 if (effectTree.size() < 2) { | |
| 296 // This matches what cc does right now: the secondary root isn't a child | |
| 297 // of the first root (at index 0). This may not have been intentional. | |
| 298 effectTree.Insert(cc::EffectNode(), kInvalidNodeId); | |
| 299 cc::EffectNode& effectNode = *effectTree.back(); | |
| 300 effectNode.data.has_render_surface = true; | |
| 301 effectNode.data.transform_id = kRealRootNodeId; | |
| 302 effectNode.data.clip_id = kRealRootNodeId; | |
| 303 effectNode.owner_id = ownerId; | |
| 304 effectTree.set_needs_update(true); | |
| 305 } | |
| 306 DCHECK_EQ(effectTree.size(), 2u); | |
| 307 | |
| 308 cc::ScrollTree& scrollTree = propertyTrees->scroll_tree; | |
| 309 if (scrollTree.size() < 2) { | |
| 310 scrollTree.Insert(cc::ScrollNode(), kRealRootNodeId); | |
| 311 cc::ScrollNode& scrollNode = *scrollTree.back(); | |
| 312 scrollNode.data.scrollable = false; | |
| 313 scrollNode.data.transform_id = kSecondaryRootNodeId; | |
| 314 scrollNode.owner_id = ownerId; | |
| 315 scrollTree.set_needs_update(true); | |
| 316 } | |
| 317 DCHECK_EQ(scrollTree.size(), 2u); | |
| 318 } | |
| 319 | |
| 320 } // namespace | 260 } // namespace |
| 321 | 261 |
| 322 void PaintArtifactCompositor::update(const PaintArtifact& paintArtifact) | 262 void PaintArtifactCompositor::update(const PaintArtifact& paintArtifact) |
| 323 { | 263 { |
| 324 DCHECK(m_rootLayer); | 264 DCHECK(m_rootLayer); |
| 325 | 265 |
| 326 // If the compositor is configured to expect using flat layer lists plus | 266 // If the compositor is configured to expect using flat layer lists plus |
| 327 // property trees, then we should provide that format. | 267 // property trees, then we should provide that format. |
| 328 cc::LayerTreeHost* host = m_rootLayer->layer_tree_host(); | 268 cc::LayerTreeHost* host = m_rootLayer->layer_tree_host(); |
| 329 const bool useLayerLists = host && host->settings().use_layer_lists; | 269 const bool useLayerLists = host && host->settings().use_layer_lists; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 378 layerOffset = combinedBounds.OffsetFromOrigin(); | 318 layerOffset = combinedBounds.OffsetFromOrigin(); |
| 379 scoped_refptr<cc::PictureLayer> layer = cc::PictureLayer::Create(contentLaye rClient.get()); | 319 scoped_refptr<cc::PictureLayer> layer = cc::PictureLayer::Create(contentLaye rClient.get()); |
| 380 layer->SetBounds(combinedBounds.size()); | 320 layer->SetBounds(combinedBounds.size()); |
| 381 layer->SetIsDrawable(true); | 321 layer->SetIsDrawable(true); |
| 382 if (paintChunk.knownToBeOpaque) | 322 if (paintChunk.knownToBeOpaque) |
| 383 layer->SetContentsOpaque(true); | 323 layer->SetContentsOpaque(true); |
| 384 m_contentLayerClients.append(std::move(contentLayerClient)); | 324 m_contentLayerClients.append(std::move(contentLayerClient)); |
| 385 return layer; | 325 return layer; |
| 386 } | 326 } |
| 387 | 327 |
| 328 constexpr int kRealRootNodeId = 0; | |
|
jbroman
2016/06/15 12:55:08
static constexpr int, since this is not in an anon
trchen
2016/06/29 01:24:32
Done.
| |
| 329 constexpr int kSecondaryRootNodeId = 1; | |
| 330 | |
| 331 // Creates a minimal set of property trees for the compositor. | |
| 332 static void resetPropertyTrees(cc::PropertyTrees* propertyTrees, int ownerId) | |
| 333 { | |
| 334 // cc is hardcoded to use transform node #1 for device scale and transform. | |
|
jbroman
2016/06/15 12:55:08
#1? It's not clear if you're using zero- or one-ba
trchen
2016/06/29 01:24:33
Done.
| |
| 335 cc::TransformTree& transformTree = propertyTrees->transform_tree; | |
| 336 transformTree.clear(); | |
| 337 cc::TransformNode& transformNode = *transformTree.Node(transformTree.Insert( cc::TransformNode(), kRealRootNodeId)); | |
| 338 DCHECK_EQ(transformNode.id, kSecondaryRootNodeId); | |
| 339 | |
| 340 // cc is hardcoded to use clip node #1 for viewport clip. | |
|
jbroman
2016/06/15 12:55:08
And it's okay for this to use the implicit root, r
trchen
2016/06/29 01:24:33
Yes, this matches what's done in cc::PropertyTreeB
| |
| 341 cc::ClipTree& clipTree = propertyTrees->clip_tree; | |
| 342 clipTree.clear(); | |
| 343 cc::ClipNode& clipNode = *clipTree.Node(clipTree.Insert(cc::ClipNode(), kRea lRootNodeId)); | |
| 344 DCHECK_EQ(clipNode.id, kSecondaryRootNodeId); | |
| 345 clipNode.owner_id = ownerId; | |
| 346 | |
| 347 // cc is hardcoded to use effect node #1 for root render surface. | |
| 348 cc::EffectTree& effectTree = propertyTrees->effect_tree; | |
| 349 effectTree.clear(); | |
| 350 cc::EffectNode& effectNode = *effectTree.Node(effectTree.Insert(cc::EffectNo de(), kRealRootNodeId)); | |
| 351 DCHECK_EQ(effectNode.id, kSecondaryRootNodeId); | |
| 352 effectNode.owner_id = ownerId; | |
| 353 effectNode.data.clip_id = kSecondaryRootNodeId; | |
| 354 effectNode.data.has_render_surface = true; | |
| 355 | |
| 356 cc::ScrollTree& scrollTree = propertyTrees->scroll_tree; | |
| 357 scrollTree.clear(); | |
| 358 } | |
| 359 | |
| 388 void PaintArtifactCompositor::updateInLayerListMode(const PaintArtifact& paintAr tifact) | 360 void PaintArtifactCompositor::updateInLayerListMode(const PaintArtifact& paintAr tifact) |
| 389 { | 361 { |
| 362 const int sequenceNumber = ++m_propertyTreeSequenceNumber; | |
| 363 | |
| 390 cc::LayerTreeHost* host = m_rootLayer->layer_tree_host(); | 364 cc::LayerTreeHost* host = m_rootLayer->layer_tree_host(); |
| 391 | 365 |
| 392 // The root layer must be the owner so that the render surface | 366 resetPropertyTrees(host->property_trees(), m_rootLayer->id()); |
| 393 // validation works. It's expected to own at least the effect node. | 367 |
| 394 setMinimalPropertyTrees(host->property_trees(), m_rootLayer->id()); | |
| 395 m_rootLayer->RemoveAllChildren(); | 368 m_rootLayer->RemoveAllChildren(); |
| 396 m_rootLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); | 369 m_rootLayer->set_property_tree_sequence_number(sequenceNumber); |
| 397 m_rootLayer->SetTransformTreeIndex(kSecondaryRootNodeId); | 370 m_rootLayer->SetTransformTreeIndex(kSecondaryRootNodeId); |
| 398 m_rootLayer->SetClipTreeIndex(kSecondaryRootNodeId); | 371 m_rootLayer->SetClipTreeIndex(kSecondaryRootNodeId); |
| 399 m_rootLayer->SetEffectTreeIndex(kSecondaryRootNodeId); | 372 m_rootLayer->SetEffectTreeIndex(kSecondaryRootNodeId); |
| 400 m_rootLayer->SetScrollTreeIndex(kSecondaryRootNodeId); | 373 m_rootLayer->SetScrollTreeIndex(kRealRootNodeId); |
| 401 | 374 |
| 402 m_contentLayerClients.clear(); | 375 m_contentLayerClients.clear(); |
| 403 m_contentLayerClients.reserveCapacity(paintArtifact.paintChunks().size()); | 376 m_contentLayerClients.reserveCapacity(paintArtifact.paintChunks().size()); |
| 404 for (const PaintChunk& paintChunk : paintArtifact.paintChunks()) { | 377 for (const PaintChunk& paintChunk : paintArtifact.paintChunks()) { |
| 405 gfx::Vector2dF layerOffset; | 378 gfx::Vector2dF layerOffset; |
| 406 scoped_refptr<cc::Layer> layer = layerForPaintChunk(paintArtifact, paint Chunk, layerOffset); | 379 scoped_refptr<cc::Layer> layer = layerForPaintChunk(paintArtifact, paint Chunk, layerOffset); |
| 407 // This is only good enough to get trivial 2D translations working. | 380 // This is only good enough to get trivial 2D translations working. |
| 408 // We'll need to actually create more cc transform nodes to do any | 381 // We'll need to actually create more cc transform nodes to do any |
| 409 // more; then we'll express offset-to-transform-parent relative to | 382 // more; then we'll express offset-to-transform-parent relative to |
| 410 // that transform node. | 383 // that transform node. |
| 411 // TODO(jbroman): ^ Do that. | 384 // TODO(jbroman): ^ Do that. |
| 412 layer->set_offset_to_transform_parent( | 385 layer->set_offset_to_transform_parent( |
| 413 transformToTransformSpace(paintChunk.properties.transform.get(), nul lptr).To2dTranslation() | 386 transformToTransformSpace(paintChunk.properties.transform.get(), nul lptr).To2dTranslation() |
| 414 + layerOffset); | 387 + layerOffset); |
| 415 | 388 |
| 416 m_rootLayer->AddChild(layer); | 389 m_rootLayer->AddChild(layer); |
| 417 layer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); | 390 layer->set_property_tree_sequence_number(sequenceNumber); |
| 418 layer->SetTransformTreeIndex(kSecondaryRootNodeId); | 391 layer->SetTransformTreeIndex(kSecondaryRootNodeId); |
| 419 layer->SetClipTreeIndex(kSecondaryRootNodeId); | 392 layer->SetClipTreeIndex(kSecondaryRootNodeId); |
| 420 layer->SetEffectTreeIndex(kSecondaryRootNodeId); | 393 layer->SetEffectTreeIndex(kSecondaryRootNodeId); |
| 421 layer->SetScrollTreeIndex(kSecondaryRootNodeId); | 394 layer->SetScrollTreeIndex(kRealRootNodeId); |
| 422 } | 395 } |
| 423 | 396 |
| 424 // Mark the property trees as having been rebuilt. | 397 // Mark the property trees as having been rebuilt. |
| 425 host->property_trees()->sequence_number = kPropertyTreeSequenceNumber; | 398 host->property_trees()->sequence_number = sequenceNumber; |
| 426 host->property_trees()->needs_rebuild = false; | 399 host->property_trees()->needs_rebuild = false; |
| 427 } | 400 } |
| 428 | 401 |
| 429 } // namespace blink | 402 } // namespace blink |
| OLD | NEW |