| 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" |
| 11 #include "cc/playback/display_item_list_settings.h" | 11 #include "cc/playback/display_item_list_settings.h" |
| 12 #include "cc/playback/drawing_display_item.h" | 12 #include "cc/playback/drawing_display_item.h" |
| 13 #include "cc/playback/transform_display_item.h" | 13 #include "cc/playback/transform_display_item.h" |
| 14 #include "cc/trees/clip_node.h" | 14 #include "cc/trees/clip_node.h" |
| 15 #include "cc/trees/effect_node.h" | 15 #include "cc/trees/effect_node.h" |
| 16 #include "cc/trees/layer_tree_host.h" | 16 #include "cc/trees/layer_tree_host.h" |
| 17 #include "cc/trees/property_tree.h" | 17 #include "cc/trees/property_tree.h" |
| 18 #include "cc/trees/scroll_node.h" |
| 18 #include "cc/trees/transform_node.h" | 19 #include "cc/trees/transform_node.h" |
| 19 #include "platform/RuntimeEnabledFeatures.h" | 20 #include "platform/RuntimeEnabledFeatures.h" |
| 20 #include "platform/graphics/paint/ClipPaintPropertyNode.h" | 21 #include "platform/graphics/paint/ClipPaintPropertyNode.h" |
| 21 #include "platform/graphics/paint/DisplayItem.h" | 22 #include "platform/graphics/paint/DisplayItem.h" |
| 22 #include "platform/graphics/paint/DrawingDisplayItem.h" | 23 #include "platform/graphics/paint/DrawingDisplayItem.h" |
| 23 #include "platform/graphics/paint/ForeignLayerDisplayItem.h" | 24 #include "platform/graphics/paint/ForeignLayerDisplayItem.h" |
| 24 #include "platform/graphics/paint/PaintArtifact.h" | 25 #include "platform/graphics/paint/PaintArtifact.h" |
| 25 #include "platform/graphics/paint/PropertyTreeState.h" | 26 #include "platform/graphics/paint/PropertyTreeState.h" |
| 27 #include "platform/graphics/paint/ScrollPaintPropertyNode.h" |
| 26 #include "platform/graphics/paint/TransformPaintPropertyNode.h" | 28 #include "platform/graphics/paint/TransformPaintPropertyNode.h" |
| 27 #include "public/platform/Platform.h" | 29 #include "public/platform/Platform.h" |
| 28 #include "public/platform/WebCompositorSupport.h" | 30 #include "public/platform/WebCompositorSupport.h" |
| 29 #include "public/platform/WebLayer.h" | 31 #include "public/platform/WebLayer.h" |
| 30 #include "ui/gfx/geometry/point.h" | 32 #include "ui/gfx/geometry/point.h" |
| 31 #include "ui/gfx/geometry/point_f.h" | 33 #include "ui/gfx/geometry/point_f.h" |
| 32 #include "ui/gfx/geometry/rect.h" | 34 #include "ui/gfx/geometry/rect.h" |
| 33 #include "ui/gfx/geometry/rect_f.h" | 35 #include "ui/gfx/geometry/rect_f.h" |
| 34 #include "ui/gfx/geometry/size.h" | 36 #include "ui/gfx/geometry/size.h" |
| 35 #include "ui/gfx/geometry/size_conversions.h" | 37 #include "ui/gfx/geometry/size_conversions.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 return nullptr; | 135 return nullptr; |
| 134 | 136 |
| 135 const auto& foreignLayerDisplayItem = static_cast<const ForeignLayerDisplayI
tem&>(displayItem); | 137 const auto& foreignLayerDisplayItem = static_cast<const ForeignLayerDisplayI
tem&>(displayItem); |
| 136 layerOffset = gfx::Vector2dF(foreignLayerDisplayItem.location().x(), foreign
LayerDisplayItem.location().y()); | 138 layerOffset = gfx::Vector2dF(foreignLayerDisplayItem.location().x(), foreign
LayerDisplayItem.location().y()); |
| 137 scoped_refptr<cc::Layer> layer = foreignLayerDisplayItem.layer(); | 139 scoped_refptr<cc::Layer> layer = foreignLayerDisplayItem.layer(); |
| 138 layer->SetBounds(foreignLayerDisplayItem.bounds()); | 140 layer->SetBounds(foreignLayerDisplayItem.bounds()); |
| 139 layer->SetIsDrawable(true); | 141 layer->SetIsDrawable(true); |
| 140 return layer; | 142 return layer; |
| 141 } | 143 } |
| 142 | 144 |
| 143 | 145 // cc's property trees use 0 for the root node (always non-null). |
| 144 constexpr int kRealRootNodeId = 0; | 146 constexpr int kRealRootNodeId = 0; |
| 147 // cc allocates special nodes for root effects such as the device scale. |
| 145 constexpr int kSecondaryRootNodeId = 1; | 148 constexpr int kSecondaryRootNodeId = 1; |
| 146 constexpr int kPropertyTreeSequenceNumber = 1; | 149 constexpr int kPropertyTreeSequenceNumber = 1; |
| 147 | 150 |
| 148 // Creates a minimal set of property trees for the compositor. | 151 // Creates a minimal set of property trees for the compositor. |
| 149 void setMinimalPropertyTrees(cc::PropertyTrees* propertyTrees, int ownerId) | 152 void setMinimalPropertyTrees(cc::PropertyTrees* propertyTrees, int ownerId) |
| 150 { | 153 { |
| 151 // cc is hardcoded to use transform node index 1 for device scale and transf
orm. | 154 // cc is hardcoded to use transform node index 1 for device scale and transf
orm. |
| 152 cc::TransformTree& transformTree = propertyTrees->transform_tree; | 155 cc::TransformTree& transformTree = propertyTrees->transform_tree; |
| 153 transformTree.clear(); | 156 transformTree.clear(); |
| 154 cc::TransformNode& transformNode = *transformTree.Node(transformTree.Insert(
cc::TransformNode(), kRealRootNodeId)); | 157 cc::TransformNode& transformNode = *transformTree.Node(transformTree.Insert(
cc::TransformNode(), kRealRootNodeId)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 168 cc::EffectTree& effectTree = propertyTrees->effect_tree; | 171 cc::EffectTree& effectTree = propertyTrees->effect_tree; |
| 169 effectTree.clear(); | 172 effectTree.clear(); |
| 170 cc::EffectNode& effectNode = *effectTree.Node(effectTree.Insert(cc::EffectNo
de(), kRealRootNodeId)); | 173 cc::EffectNode& effectNode = *effectTree.Node(effectTree.Insert(cc::EffectNo
de(), kRealRootNodeId)); |
| 171 DCHECK_EQ(effectNode.id, kSecondaryRootNodeId); | 174 DCHECK_EQ(effectNode.id, kSecondaryRootNodeId); |
| 172 effectNode.owner_id = ownerId; | 175 effectNode.owner_id = ownerId; |
| 173 effectNode.clip_id = clipNode.id; | 176 effectNode.clip_id = clipNode.id; |
| 174 effectNode.has_render_surface = true; | 177 effectNode.has_render_surface = true; |
| 175 | 178 |
| 176 cc::ScrollTree& scrollTree = propertyTrees->scroll_tree; | 179 cc::ScrollTree& scrollTree = propertyTrees->scroll_tree; |
| 177 scrollTree.clear(); | 180 scrollTree.clear(); |
| 181 cc::ScrollNode& scrollNode = *scrollTree.Node(scrollTree.Insert(cc::ScrollNo
de(), kRealRootNodeId)); |
| 182 DCHECK_EQ(scrollNode.id, kSecondaryRootNodeId); |
| 183 scrollNode.owner_id = ownerId; |
| 184 scrollNode.transform_id = kRealRootNodeId; |
| 178 } | 185 } |
| 179 | 186 |
| 180 } // namespace | 187 } // namespace |
| 181 | 188 |
| 182 scoped_refptr<cc::Layer> PaintArtifactCompositor::layerForPaintChunk(const Paint
Artifact& paintArtifact, const PaintChunk& paintChunk, gfx::Vector2dF& layerOffs
et) | 189 scoped_refptr<cc::Layer> PaintArtifactCompositor::layerForPaintChunk(const Paint
Artifact& paintArtifact, const PaintChunk& paintChunk, gfx::Vector2dF& layerOffs
et) |
| 183 { | 190 { |
| 184 DCHECK(paintChunk.size()); | 191 DCHECK(paintChunk.size()); |
| 185 | 192 |
| 186 // If the paint chunk is a foreign layer, just return that layer. | 193 // If the paint chunk is a foreign layer, just return that layer. |
| 187 if (scoped_refptr<cc::Layer> foreignLayer = foreignLayerForPaintChunk(paintA
rtifact, paintChunk, layerOffset)) | 194 if (scoped_refptr<cc::Layer> foreignLayer = foreignLayerForPaintChunk(paintA
rtifact, paintChunk, layerOffset)) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 218 m_effectStack.append(BlinkEffectAndCcIdPair{nullptr, kSecondaryRootNodeI
d}); | 225 m_effectStack.append(BlinkEffectAndCcIdPair{nullptr, kSecondaryRootNodeI
d}); |
| 219 } | 226 } |
| 220 | 227 |
| 221 // TODO(pdr): This will need to be unified with how viewport scale works. | 228 // TODO(pdr): This will need to be unified with how viewport scale works. |
| 222 void setDeviceScaleFactor(float); | 229 void setDeviceScaleFactor(float); |
| 223 | 230 |
| 224 int compositorIdForTransformNode(const TransformPaintPropertyNode*); | 231 int compositorIdForTransformNode(const TransformPaintPropertyNode*); |
| 225 int compositorIdForClipNode(const ClipPaintPropertyNode*); | 232 int compositorIdForClipNode(const ClipPaintPropertyNode*); |
| 226 int switchToEffectNode(const EffectPaintPropertyNode& nextEffect); | 233 int switchToEffectNode(const EffectPaintPropertyNode& nextEffect); |
| 227 int compositorIdForCurrentEffectNode() const { return m_effectStack.last().i
d; } | 234 int compositorIdForCurrentEffectNode() const { return m_effectStack.last().i
d; } |
| 235 int compositorIdForScrollNode(const ScrollPaintPropertyNode*); |
| 236 |
| 237 // Scroll offset has special treatment in the transform and scroll trees. |
| 238 void updateScrollOffset(int layerId, int scrollId); |
| 228 | 239 |
| 229 private: | 240 private: |
| 230 void buildEffectNodesRecursively(const EffectPaintPropertyNode* nextEffect); | 241 void buildEffectNodesRecursively(const EffectPaintPropertyNode* nextEffect); |
| 231 | 242 |
| 232 cc::TransformTree& transformTree() { return m_propertyTrees.transform_tree;
} | 243 cc::TransformTree& transformTree() { return m_propertyTrees.transform_tree;
} |
| 233 cc::ClipTree& clipTree() { return m_propertyTrees.clip_tree; } | 244 cc::ClipTree& clipTree() { return m_propertyTrees.clip_tree; } |
| 234 cc::EffectTree& effectTree() { return m_propertyTrees.effect_tree; } | 245 cc::EffectTree& effectTree() { return m_propertyTrees.effect_tree; } |
| 246 cc::ScrollTree& scrollTree() { return m_propertyTrees.scroll_tree; } |
| 235 | 247 |
| 236 const EffectPaintPropertyNode* currentEffectNode() const { return m_effectSt
ack.last().effect; } | 248 const EffectPaintPropertyNode* currentEffectNode() const { return m_effectSt
ack.last().effect; } |
| 237 | 249 |
| 238 // Property trees which should be updated by the manager. | 250 // Property trees which should be updated by the manager. |
| 239 cc::PropertyTrees& m_propertyTrees; | 251 cc::PropertyTrees& m_propertyTrees; |
| 240 | 252 |
| 241 // Layer to which transform "owner" layers should be added. These will not | 253 // Layer to which transform "owner" layers should be added. These will not |
| 242 // have any actual children, but at present must exist in the tree. | 254 // have any actual children, but at present must exist in the tree. |
| 243 cc::Layer* m_rootLayer; | 255 cc::Layer* m_rootLayer; |
| 244 | 256 |
| 245 // Maps from Blink-side property tree nodes to cc property node indices. | 257 // Maps from Blink-side property tree nodes to cc property node indices. |
| 246 HashMap<const TransformPaintPropertyNode*, int> m_transformNodeMap; | 258 HashMap<const TransformPaintPropertyNode*, int> m_transformNodeMap; |
| 247 HashMap<const ClipPaintPropertyNode*, int> m_clipNodeMap; | 259 HashMap<const ClipPaintPropertyNode*, int> m_clipNodeMap; |
| 260 HashMap<const ScrollPaintPropertyNode*, int> m_scrollNodeMap; |
| 248 | 261 |
| 249 struct BlinkEffectAndCcIdPair { | 262 struct BlinkEffectAndCcIdPair { |
| 250 const EffectPaintPropertyNode* effect; | 263 const EffectPaintPropertyNode* effect; |
| 251 int id; | 264 int id; |
| 252 }; | 265 }; |
| 253 Vector<BlinkEffectAndCcIdPair> m_effectStack; | 266 Vector<BlinkEffectAndCcIdPair> m_effectStack; |
| 254 | 267 |
| 255 #if DCHECK_IS_ON() | 268 #if DCHECK_IS_ON() |
| 256 HashSet<const EffectPaintPropertyNode*> m_effectNodesConverted; | 269 HashSet<const EffectPaintPropertyNode*> m_effectNodesConverted; |
| 257 bool m_isFirstEffectEver; | 270 bool m_isFirstEffectEver; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 dummyLayer->SetEffectTreeIndex(kSecondaryRootNodeId); | 348 dummyLayer->SetEffectTreeIndex(kSecondaryRootNodeId); |
| 336 dummyLayer->SetScrollTreeIndex(kRealRootNodeId); | 349 dummyLayer->SetScrollTreeIndex(kRealRootNodeId); |
| 337 dummyLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); | 350 dummyLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); |
| 338 | 351 |
| 339 auto result = m_clipNodeMap.set(clipNode, id); | 352 auto result = m_clipNodeMap.set(clipNode, id); |
| 340 DCHECK(result.isNewEntry); | 353 DCHECK(result.isNewEntry); |
| 341 clipTree().set_needs_update(true); | 354 clipTree().set_needs_update(true); |
| 342 return id; | 355 return id; |
| 343 } | 356 } |
| 344 | 357 |
| 358 int PropertyTreeManager::compositorIdForScrollNode(const ScrollPaintPropertyNode
* scrollNode) |
| 359 { |
| 360 if (!scrollNode) |
| 361 return kSecondaryRootNodeId; |
| 362 |
| 363 auto it = m_scrollNodeMap.find(scrollNode); |
| 364 if (it != m_scrollNodeMap.end()) |
| 365 return it->value; |
| 366 |
| 367 int parentId = compositorIdForScrollNode(scrollNode->parent()); |
| 368 int id = scrollTree().Insert(cc::ScrollNode(), parentId); |
| 369 |
| 370 cc::ScrollNode& compositorNode = *scrollTree().Node(id); |
| 371 compositorNode.owner_id = parentId; |
| 372 |
| 373 compositorNode.scrollable = true; |
| 374 |
| 375 // TODO(pdr): Set main thread scrolling reasons. |
| 376 compositorNode.scroll_clip_layer_bounds.SetSize(scrollNode->clip().width(),
scrollNode->clip().height()); |
| 377 compositorNode.bounds.SetSize(scrollNode->bounds().width(), scrollNode->boun
ds().height()); |
| 378 compositorNode.user_scrollable_horizontal = scrollNode->userScrollableHorizo
ntal(); |
| 379 compositorNode.user_scrollable_vertical = scrollNode->userScrollableVertical
(); |
| 380 compositorNode.transform_id = compositorIdForTransformNode(scrollNode->scrol
lOffsetTranslation()); |
| 381 |
| 382 auto result = m_scrollNodeMap.set(scrollNode, id); |
| 383 DCHECK(result.isNewEntry); |
| 384 scrollTree().set_needs_update(true); |
| 385 |
| 386 return id; |
| 387 } |
| 388 |
| 389 void PropertyTreeManager::updateScrollOffset(int layerId, int scrollId) |
| 390 { |
| 391 cc::ScrollNode& scrollNode = *scrollTree().Node(scrollId); |
| 392 cc::TransformNode& transformNode = *transformTree().Node(scrollNode.transfor
m_id); |
| 393 |
| 394 transformNode.scrolls = true; |
| 395 |
| 396 // Blink creates a 2d transform node just for scroll offset whereas cc's |
| 397 // transform node has a special scroll offset field. To handle this we |
| 398 // adjust cc's transform node to remove the 2d scroll translation and |
| 399 // let the cc scroll tree update the cc scroll offset. |
| 400 DCHECK(transformNode.local.IsIdentityOr2DTranslation()); |
| 401 auto offset = transformNode.local.To2dTranslation(); |
| 402 transformNode.local.MakeIdentity(); |
| 403 scrollTree().SetScrollOffset(layerId, gfx::ScrollOffset(-offset.x(), -offset
.y())); |
| 404 scrollTree().set_needs_update(true); |
| 405 } |
| 406 |
| 345 unsigned depth(const EffectPaintPropertyNode* node) | 407 unsigned depth(const EffectPaintPropertyNode* node) |
| 346 { | 408 { |
| 347 unsigned result = 0; | 409 unsigned result = 0; |
| 348 for (; node; node = node->parent()) | 410 for (; node; node = node->parent()) |
| 349 result++; | 411 result++; |
| 350 return result; | 412 return result; |
| 351 } | 413 } |
| 352 | 414 |
| 353 const EffectPaintPropertyNode* lowestCommonAncestor(const EffectPaintPropertyNod
e* nodeA, const EffectPaintPropertyNode* nodeB) | 415 const EffectPaintPropertyNode* lowestCommonAncestor(const EffectPaintPropertyNod
e* nodeA, const EffectPaintPropertyNode* nodeB) |
| 354 { | 416 { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 PropertyTreeManager propertyTreeManager(*host->GetLayerTree()->property_tree
s(), m_rootLayer.get()); | 516 PropertyTreeManager propertyTreeManager(*host->GetLayerTree()->property_tree
s(), m_rootLayer.get()); |
| 455 propertyTreeManager.setDeviceScaleFactor(host->GetLayerTree()->device_scale_
factor()); | 517 propertyTreeManager.setDeviceScaleFactor(host->GetLayerTree()->device_scale_
factor()); |
| 456 | 518 |
| 457 m_contentLayerClients.clear(); | 519 m_contentLayerClients.clear(); |
| 458 m_contentLayerClients.reserveCapacity(paintArtifact.paintChunks().size()); | 520 m_contentLayerClients.reserveCapacity(paintArtifact.paintChunks().size()); |
| 459 for (const PaintChunk& paintChunk : paintArtifact.paintChunks()) { | 521 for (const PaintChunk& paintChunk : paintArtifact.paintChunks()) { |
| 460 gfx::Vector2dF layerOffset; | 522 gfx::Vector2dF layerOffset; |
| 461 scoped_refptr<cc::Layer> layer = layerForPaintChunk(paintArtifact, paint
Chunk, layerOffset); | 523 scoped_refptr<cc::Layer> layer = layerForPaintChunk(paintArtifact, paint
Chunk, layerOffset); |
| 462 | 524 |
| 463 int transformId = propertyTreeManager.compositorIdForTransformNode(paint
Chunk.properties.transform.get()); | 525 int transformId = propertyTreeManager.compositorIdForTransformNode(paint
Chunk.properties.transform.get()); |
| 526 int scrollId = propertyTreeManager.compositorIdForScrollNode(paintChunk.
properties.scroll.get()); |
| 464 int clipId = propertyTreeManager.compositorIdForClipNode(paintChunk.prop
erties.clip.get()); | 527 int clipId = propertyTreeManager.compositorIdForClipNode(paintChunk.prop
erties.clip.get()); |
| 465 int effectId = propertyTreeManager.switchToEffectNode(*paintChunk.proper
ties.effect.get()); | 528 int effectId = propertyTreeManager.switchToEffectNode(*paintChunk.proper
ties.effect.get()); |
| 466 | 529 |
| 530 propertyTreeManager.updateScrollOffset(layer->id(), scrollId); |
| 531 |
| 467 layer->set_offset_to_transform_parent(layerOffset); | 532 layer->set_offset_to_transform_parent(layerOffset); |
| 468 | 533 |
| 469 m_rootLayer->AddChild(layer); | 534 m_rootLayer->AddChild(layer); |
| 470 layer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); | 535 layer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); |
| 471 layer->SetTransformTreeIndex(transformId); | 536 layer->SetTransformTreeIndex(transformId); |
| 472 layer->SetClipTreeIndex(clipId); | 537 layer->SetClipTreeIndex(clipId); |
| 473 layer->SetEffectTreeIndex(effectId); | 538 layer->SetEffectTreeIndex(effectId); |
| 474 layer->SetScrollTreeIndex(kRealRootNodeId); | 539 layer->SetScrollTreeIndex(scrollId); |
| 475 | 540 |
| 476 // TODO(jbroman): This probably shouldn't be necessary, but it is still | 541 // TODO(jbroman): This probably shouldn't be necessary, but it is still |
| 477 // queried by RenderSurfaceImpl. | 542 // queried by RenderSurfaceImpl. |
| 478 layer->Set3dSortingContextId(host->GetLayerTree()->property_trees()->tra
nsform_tree.Node(transformId)->sorting_context_id); | 543 layer->Set3dSortingContextId(host->GetLayerTree()->property_trees()->tra
nsform_tree.Node(transformId)->sorting_context_id); |
| 479 | 544 |
| 480 layer->SetShouldCheckBackfaceVisibility(paintChunk.properties.backfaceHi
dden); | 545 layer->SetShouldCheckBackfaceVisibility(paintChunk.properties.backfaceHi
dden); |
| 481 | 546 |
| 482 if (m_extraDataForTestingEnabled) | 547 if (m_extraDataForTestingEnabled) |
| 483 m_extraDataForTesting->contentLayers.append(layer); | 548 m_extraDataForTesting->contentLayers.append(layer); |
| 484 } | 549 } |
| 485 | 550 |
| 486 // Mark the property trees as having been rebuilt. | 551 // Mark the property trees as having been rebuilt. |
| 487 host->GetLayerTree()->property_trees()->sequence_number = kPropertyTreeSeque
nceNumber; | 552 host->GetLayerTree()->property_trees()->sequence_number = kPropertyTreeSeque
nceNumber; |
| 488 host->GetLayerTree()->property_trees()->needs_rebuild = false; | 553 host->GetLayerTree()->property_trees()->needs_rebuild = false; |
| 489 } | 554 } |
| 490 | 555 |
| 491 } // namespace blink | 556 } // namespace blink |
| OLD | NEW |