| 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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 cc::EffectTree& effectTree = propertyTrees->effect_tree; | 264 cc::EffectTree& effectTree = propertyTrees->effect_tree; |
| 263 effectTree.clear(); | 265 effectTree.clear(); |
| 264 cc::EffectNode& effectNode = *effectTree.Node(effectTree.Insert(cc::EffectNo
de(), kRealRootNodeId)); | 266 cc::EffectNode& effectNode = *effectTree.Node(effectTree.Insert(cc::EffectNo
de(), kRealRootNodeId)); |
| 265 DCHECK_EQ(effectNode.id, kSecondaryRootNodeId); | 267 DCHECK_EQ(effectNode.id, kSecondaryRootNodeId); |
| 266 effectNode.owner_id = ownerId; | 268 effectNode.owner_id = ownerId; |
| 267 effectNode.clip_id = clipNode.id; | 269 effectNode.clip_id = clipNode.id; |
| 268 effectNode.has_render_surface = true; | 270 effectNode.has_render_surface = true; |
| 269 | 271 |
| 270 cc::ScrollTree& scrollTree = propertyTrees->scroll_tree; | 272 cc::ScrollTree& scrollTree = propertyTrees->scroll_tree; |
| 271 scrollTree.clear(); | 273 scrollTree.clear(); |
| 274 cc::ScrollNode& scrollNode = *scrollTree.Node(scrollTree.Insert(cc::ScrollNo
de(), kRealRootNodeId)); |
| 275 DCHECK_EQ(scrollNode.id, kSecondaryRootNodeId); |
| 276 scrollNode.owner_id = ownerId; |
| 277 scrollNode.transform_id = kRealRootNodeId; |
| 272 } | 278 } |
| 273 | 279 |
| 274 } // namespace | 280 } // namespace |
| 275 | 281 |
| 276 void PaintArtifactCompositor::update(const PaintArtifact& paintArtifact) | 282 void PaintArtifactCompositor::update(const PaintArtifact& paintArtifact) |
| 277 { | 283 { |
| 278 DCHECK(m_rootLayer); | 284 DCHECK(m_rootLayer); |
| 279 | 285 |
| 280 if (m_extraDataForTestingEnabled) | 286 if (m_extraDataForTestingEnabled) |
| 281 m_extraDataForTesting = wrapUnique(new ExtraDataForTesting); | 287 m_extraDataForTesting = wrapUnique(new ExtraDataForTesting); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 , m_isFirstEffectEver(true) | 364 , m_isFirstEffectEver(true) |
| 359 #endif | 365 #endif |
| 360 { | 366 { |
| 361 m_effectStack.append(BlinkEffectAndCcIdPair{nullptr, kSecondaryRootNodeI
d}); | 367 m_effectStack.append(BlinkEffectAndCcIdPair{nullptr, kSecondaryRootNodeI
d}); |
| 362 } | 368 } |
| 363 | 369 |
| 364 int compositorIdForTransformNode(const TransformPaintPropertyNode*); | 370 int compositorIdForTransformNode(const TransformPaintPropertyNode*); |
| 365 int compositorIdForClipNode(const ClipPaintPropertyNode*); | 371 int compositorIdForClipNode(const ClipPaintPropertyNode*); |
| 366 int switchToEffectNode(const EffectPaintPropertyNode& nextEffect); | 372 int switchToEffectNode(const EffectPaintPropertyNode& nextEffect); |
| 367 int compositorIdForCurrentEffectNode() const { return m_effectStack.last().i
d; } | 373 int compositorIdForCurrentEffectNode() const { return m_effectStack.last().i
d; } |
| 374 int compositorIdForScrollNode(const ScrollPaintPropertyNode*); |
| 375 bool compositorIdExistsForScrollNode(const ScrollPaintPropertyNode* scrollNo
de) |
| 376 { |
| 377 return m_scrollNodeMap.contains(scrollNode); |
| 378 } |
| 379 |
| 380 // Scroll offset has special treatment in the compositor and needs an |
| 381 // adjustment to the transform node (to switch from a transform to a scroll |
| 382 // offset) as well as an update to the ScrollTree scroll offset. |
| 383 void updateScrollOffset(int layerId, int scrollId); |
| 368 | 384 |
| 369 private: | 385 private: |
| 370 void buildEffectNodesRecursively(const EffectPaintPropertyNode* nextEffect); | 386 void buildEffectNodesRecursively(const EffectPaintPropertyNode* nextEffect); |
| 371 | 387 |
| 372 cc::TransformTree& transformTree() { return m_propertyTrees.transform_tree;
} | 388 cc::TransformTree& transformTree() { return m_propertyTrees.transform_tree;
} |
| 373 cc::ClipTree& clipTree() { return m_propertyTrees.clip_tree; } | 389 cc::ClipTree& clipTree() { return m_propertyTrees.clip_tree; } |
| 374 cc::EffectTree& effectTree() { return m_propertyTrees.effect_tree; } | 390 cc::EffectTree& effectTree() { return m_propertyTrees.effect_tree; } |
| 391 cc::ScrollTree& scrollTree() { return m_propertyTrees.scroll_tree; } |
| 375 | 392 |
| 376 const EffectPaintPropertyNode* currentEffectNode() const { return m_effectSt
ack.last().effect; } | 393 const EffectPaintPropertyNode* currentEffectNode() const { return m_effectSt
ack.last().effect; } |
| 377 | 394 |
| 378 // Property trees which should be updated by the manager. | 395 // Property trees which should be updated by the manager. |
| 379 cc::PropertyTrees& m_propertyTrees; | 396 cc::PropertyTrees& m_propertyTrees; |
| 380 | 397 |
| 381 // Layer to which transform "owner" layers should be added. These will not | 398 // Layer to which transform "owner" layers should be added. These will not |
| 382 // have any actual children, but at present must exist in the tree. | 399 // have any actual children, but at present must exist in the tree. |
| 383 cc::Layer* m_rootLayer; | 400 cc::Layer* m_rootLayer; |
| 384 | 401 |
| 385 // Maps from Blink-side property tree nodes to cc property node indices. | 402 // Maps from Blink-side property tree nodes to cc property node indices. |
| 386 HashMap<const TransformPaintPropertyNode*, int> m_transformNodeMap; | 403 HashMap<const TransformPaintPropertyNode*, int> m_transformNodeMap; |
| 387 HashMap<const ClipPaintPropertyNode*, int> m_clipNodeMap; | 404 HashMap<const ClipPaintPropertyNode*, int> m_clipNodeMap; |
| 405 HashMap<const ScrollPaintPropertyNode*, int> m_scrollNodeMap; |
| 388 | 406 |
| 389 struct BlinkEffectAndCcIdPair { | 407 struct BlinkEffectAndCcIdPair { |
| 390 const EffectPaintPropertyNode* effect; | 408 const EffectPaintPropertyNode* effect; |
| 391 int id; | 409 int id; |
| 392 }; | 410 }; |
| 393 Vector<BlinkEffectAndCcIdPair> m_effectStack; | 411 Vector<BlinkEffectAndCcIdPair> m_effectStack; |
| 394 | 412 |
| 395 #if DCHECK_IS_ON() | 413 #if DCHECK_IS_ON() |
| 396 HashSet<const EffectPaintPropertyNode*> m_effectNodesConverted; | 414 HashSet<const EffectPaintPropertyNode*> m_effectNodesConverted; |
| 397 bool m_isFirstEffectEver; | 415 bool m_isFirstEffectEver; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 dummyLayer->SetEffectTreeIndex(kSecondaryRootNodeId); | 487 dummyLayer->SetEffectTreeIndex(kSecondaryRootNodeId); |
| 470 dummyLayer->SetScrollTreeIndex(kRealRootNodeId); | 488 dummyLayer->SetScrollTreeIndex(kRealRootNodeId); |
| 471 dummyLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); | 489 dummyLayer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); |
| 472 | 490 |
| 473 auto result = m_clipNodeMap.set(clipNode, id); | 491 auto result = m_clipNodeMap.set(clipNode, id); |
| 474 DCHECK(result.isNewEntry); | 492 DCHECK(result.isNewEntry); |
| 475 clipTree().set_needs_update(true); | 493 clipTree().set_needs_update(true); |
| 476 return id; | 494 return id; |
| 477 } | 495 } |
| 478 | 496 |
| 497 int PropertyTreeManager::compositorIdForScrollNode(const ScrollPaintPropertyNode
* scrollNode) |
| 498 { |
| 499 if (!scrollNode) |
| 500 return kSecondaryRootNodeId; |
| 501 |
| 502 auto it = m_scrollNodeMap.find(scrollNode); |
| 503 if (it != m_scrollNodeMap.end()) |
| 504 return it->value; |
| 505 |
| 506 int parentId = compositorIdForScrollNode(scrollNode->parent()); |
| 507 int id = scrollTree().Insert(cc::ScrollNode(), parentId); |
| 508 |
| 509 cc::ScrollNode& compositorNode = *scrollTree().Node(id); |
| 510 compositorNode.owner_id = parentId; |
| 511 |
| 512 // TODO(pdr): Set scrollable properly. |
| 513 compositorNode.scrollable = true; |
| 514 |
| 515 // TODO(pdr): Set main thread scrolling reasons. |
| 516 IntSize snappedClip = roundedIntSize(scrollNode->clip()); |
| 517 compositorNode.scroll_clip_layer_bounds.SetSize(snappedClip.width(), snapped
Clip.height()); |
| 518 IntSize snappedBounds = roundedIntSize(scrollNode->bounds()); |
| 519 compositorNode.scroll_clip_layer_bounds.SetSize(snappedBounds.width(), snapp
edBounds.height()); |
| 520 compositorNode.user_scrollable_horizontal = scrollNode->userScrollableHorizo
ntal(); |
| 521 compositorNode.user_scrollable_vertical = scrollNode->userScrollableVertical
(); |
| 522 compositorNode.transform_id = compositorIdForTransformNode(scrollNode->trans
form()); |
| 523 |
| 524 auto result = m_scrollNodeMap.set(scrollNode, id); |
| 525 DCHECK(result.isNewEntry); |
| 526 scrollTree().set_needs_update(true); |
| 527 |
| 528 return id; |
| 529 } |
| 530 |
| 531 void PropertyTreeManager::updateScrollOffset(int layerId, int scrollId) |
| 532 { |
| 533 cc::ScrollNode& scrollNode = *scrollTree().Node(scrollId); |
| 534 cc::TransformNode& transformNode = *transformTree().Node(scrollNode.transfor
m_id); |
| 535 |
| 536 // The transform associated with a scroll should only contain a 2d scroll of
fset. |
| 537 DCHECK(transformNode.local.IsIdentityOr2DTranslation()); |
| 538 |
| 539 // TODO(pdr): Set the transform node's scrollable bit from scrollNode. |
| 540 |
| 541 auto scrollOffsetVector = transformNode.local.To2dTranslation(); |
| 542 |
| 543 // Remove the 2d scroll translation set from blink's transform paint propert
y |
| 544 // node. |
| 545 transformNode.local.MakeIdentity(); |
| 546 |
| 547 gfx::ScrollOffset scrollOffset(scrollOffsetVector.x(), -scrollOffsetVector.y
()); |
| 548 scrollTree().SetScrollOffset(layerId, scrollOffset); |
| 549 |
| 550 // TODO(pdr): Is this needed or can we rely on SetScrollOffset handling it? |
| 551 transformNode.scroll_offset = scrollOffset; |
| 552 } |
| 553 |
| 479 unsigned depth(const EffectPaintPropertyNode* node) | 554 unsigned depth(const EffectPaintPropertyNode* node) |
| 480 { | 555 { |
| 481 unsigned result = 0; | 556 unsigned result = 0; |
| 482 for (; node; node = node->parent()) | 557 for (; node; node = node->parent()) |
| 483 result++; | 558 result++; |
| 484 return result; | 559 return result; |
| 485 } | 560 } |
| 486 | 561 |
| 487 const EffectPaintPropertyNode* lowestCommonAncestor(const EffectPaintPropertyNod
e* nodeA, const EffectPaintPropertyNode* nodeB) | 562 const EffectPaintPropertyNode* lowestCommonAncestor(const EffectPaintPropertyNod
e* nodeA, const EffectPaintPropertyNode* nodeB) |
| 488 { | 563 { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 m_rootLayer->SetScrollTreeIndex(kRealRootNodeId); | 650 m_rootLayer->SetScrollTreeIndex(kRealRootNodeId); |
| 576 | 651 |
| 577 PropertyTreeManager propertyTreeManager(*host->GetLayerTree()->property_tree
s(), m_rootLayer.get()); | 652 PropertyTreeManager propertyTreeManager(*host->GetLayerTree()->property_tree
s(), m_rootLayer.get()); |
| 578 m_contentLayerClients.clear(); | 653 m_contentLayerClients.clear(); |
| 579 m_contentLayerClients.reserveCapacity(paintArtifact.paintChunks().size()); | 654 m_contentLayerClients.reserveCapacity(paintArtifact.paintChunks().size()); |
| 580 for (const PaintChunk& paintChunk : paintArtifact.paintChunks()) { | 655 for (const PaintChunk& paintChunk : paintArtifact.paintChunks()) { |
| 581 gfx::Vector2dF layerOffset; | 656 gfx::Vector2dF layerOffset; |
| 582 scoped_refptr<cc::Layer> layer = layerForPaintChunk(paintArtifact, paint
Chunk, layerOffset); | 657 scoped_refptr<cc::Layer> layer = layerForPaintChunk(paintArtifact, paint
Chunk, layerOffset); |
| 583 | 658 |
| 584 int transformId = propertyTreeManager.compositorIdForTransformNode(paint
Chunk.properties.transform.get()); | 659 int transformId = propertyTreeManager.compositorIdForTransformNode(paint
Chunk.properties.transform.get()); |
| 660 int scrollId = propertyTreeManager.compositorIdForScrollNode(paintChunk.
properties.scroll.get()); |
| 585 int clipId = propertyTreeManager.compositorIdForClipNode(paintChunk.prop
erties.clip.get()); | 661 int clipId = propertyTreeManager.compositorIdForClipNode(paintChunk.prop
erties.clip.get()); |
| 586 int effectId = propertyTreeManager.switchToEffectNode(*paintChunk.proper
ties.effect.get()); | 662 int effectId = propertyTreeManager.switchToEffectNode(*paintChunk.proper
ties.effect.get()); |
| 587 | 663 |
| 664 propertyTreeManager.updateScrollOffset(layer->id(), scrollId); |
| 665 |
| 588 layer->set_offset_to_transform_parent(layerOffset); | 666 layer->set_offset_to_transform_parent(layerOffset); |
| 589 | 667 |
| 590 m_rootLayer->AddChild(layer); | 668 m_rootLayer->AddChild(layer); |
| 591 layer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); | 669 layer->set_property_tree_sequence_number(kPropertyTreeSequenceNumber); |
| 592 layer->SetTransformTreeIndex(transformId); | 670 layer->SetTransformTreeIndex(transformId); |
| 593 layer->SetClipTreeIndex(clipId); | 671 layer->SetClipTreeIndex(clipId); |
| 594 layer->SetEffectTreeIndex(effectId); | 672 layer->SetEffectTreeIndex(effectId); |
| 595 layer->SetScrollTreeIndex(kRealRootNodeId); | 673 layer->SetScrollTreeIndex(scrollId); |
| 596 | 674 |
| 597 // TODO(jbroman): This probably shouldn't be necessary, but it is still | 675 // TODO(jbroman): This probably shouldn't be necessary, but it is still |
| 598 // queried by RenderSurfaceImpl. | 676 // queried by RenderSurfaceImpl. |
| 599 layer->Set3dSortingContextId(host->GetLayerTree()->property_trees()->tra
nsform_tree.Node(transformId)->sorting_context_id); | 677 layer->Set3dSortingContextId(host->GetLayerTree()->property_trees()->tra
nsform_tree.Node(transformId)->sorting_context_id); |
| 600 | 678 |
| 601 layer->SetShouldCheckBackfaceVisibility(paintChunk.properties.backfaceHi
dden); | 679 layer->SetShouldCheckBackfaceVisibility(paintChunk.properties.backfaceHi
dden); |
| 602 | 680 |
| 603 if (m_extraDataForTestingEnabled) | 681 if (m_extraDataForTestingEnabled) |
| 604 m_extraDataForTesting->contentLayers.append(layer); | 682 m_extraDataForTesting->contentLayers.append(layer); |
| 605 } | 683 } |
| 606 | 684 |
| 607 // Mark the property trees as having been rebuilt. | 685 // Mark the property trees as having been rebuilt. |
| 608 host->GetLayerTree()->property_trees()->sequence_number = kPropertyTreeSeque
nceNumber; | 686 host->GetLayerTree()->property_trees()->sequence_number = kPropertyTreeSeque
nceNumber; |
| 609 host->GetLayerTree()->property_trees()->needs_rebuild = false; | 687 host->GetLayerTree()->property_trees()->needs_rebuild = false; |
| 610 } | 688 } |
| 611 | 689 |
| 612 } // namespace blink | 690 } // namespace blink |
| OLD | NEW |