Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CC_TREES_PROPERTY_TREE_H_ | 5 #ifndef CC_TREES_PROPERTY_TREE_H_ |
| 6 #define CC_TREES_PROPERTY_TREE_H_ | 6 #define CC_TREES_PROPERTY_TREE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 template <typename T> | 46 template <typename T> |
| 47 class CC_EXPORT PropertyTree { | 47 class CC_EXPORT PropertyTree { |
| 48 public: | 48 public: |
| 49 PropertyTree(); | 49 PropertyTree(); |
| 50 PropertyTree(const PropertyTree& other) = delete; | 50 PropertyTree(const PropertyTree& other) = delete; |
| 51 | 51 |
| 52 // These C++ special member functions cannot be implicit inline because | 52 // These C++ special member functions cannot be implicit inline because |
| 53 // they are exported by CC_EXPORT. They will be instantiated in every | 53 // they are exported by CC_EXPORT. They will be instantiated in every |
| 54 // compilation units that included this header, and compilation can fail | 54 // compilation units that included this header, and compilation can fail |
| 55 // because T may be incomplete. | 55 // because T may be incomplete. |
| 56 ~PropertyTree(); | 56 virtual ~PropertyTree(); |
| 57 PropertyTree<T>& operator=(const PropertyTree<T>&); | 57 PropertyTree<T>& operator=(const PropertyTree<T>&); |
| 58 | 58 |
| 59 // Property tree node starts from index 0. | 59 // Property tree node starts from index 0. |
| 60 static const int kInvalidNodeId = -1; | 60 static const int kInvalidNodeId = -1; |
| 61 static const int kRootNodeId = 0; | 61 static const int kRootNodeId = 0; |
| 62 | 62 |
| 63 bool operator==(const PropertyTree<T>& other) const; | 63 bool operator==(const PropertyTree<T>& other) const; |
| 64 | 64 |
| 65 int Insert(const T& tree_node, int parent_id); | 65 int Insert(const T& tree_node, int parent_id); |
| 66 | 66 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 90 | 90 |
| 91 int next_available_id() const { return static_cast<int>(size()); } | 91 int next_available_id() const { return static_cast<int>(size()); } |
| 92 | 92 |
| 93 void SetPropertyTrees(PropertyTrees* property_trees) { | 93 void SetPropertyTrees(PropertyTrees* property_trees) { |
| 94 property_trees_ = property_trees; | 94 property_trees_ = property_trees; |
| 95 } | 95 } |
| 96 PropertyTrees* property_trees() const { return property_trees_; } | 96 PropertyTrees* property_trees() const { return property_trees_; } |
| 97 | 97 |
| 98 void AsValueInto(base::trace_event::TracedValue* value) const; | 98 void AsValueInto(base::trace_event::TracedValue* value) const; |
| 99 | 99 |
| 100 T* FindNodeFromOwningId(int id) { | |
| 101 return Node(FindNodeIndexFromOwningId(id)); | |
| 102 } | |
| 103 int FindNodeIndexFromOwningId(int id) const { | |
|
pdr.
2017/03/16 20:30:28
I think we should move away from using the "owning
| |
| 104 auto iter = layer_id_to_node_index.find(id); | |
| 105 if (iter == layer_id_to_node_index.end()) | |
| 106 return kInvalidNodeId; | |
| 107 else | |
| 108 return iter->second; | |
| 109 } | |
| 110 | |
| 111 void InsertOwningIdForNode(const T* node, int id) { | |
|
pdr.
2017/03/16 20:30:28
WDYT of using Set* instead of Insert*?
| |
| 112 if (!node) { | |
| 113 layer_id_to_node_index[id] = kInvalidNodeId; | |
| 114 return; | |
| 115 } | |
| 116 | |
| 117 DCHECK(node == Node(node->id)); | |
| 118 layer_id_to_node_index[id] = node->id; | |
| 119 } | |
| 120 | |
| 100 private: | 121 private: |
| 101 std::vector<T> nodes_; | 122 std::vector<T> nodes_; |
| 102 | 123 |
| 124 // These maps map from layer id to the property tree node index. | |
| 125 std::unordered_map<int, int> layer_id_to_node_index; | |
| 126 | |
| 103 bool needs_update_; | 127 bool needs_update_; |
| 104 PropertyTrees* property_trees_; | 128 PropertyTrees* property_trees_; |
| 105 }; | 129 }; |
| 106 | 130 |
| 107 struct StickyPositionNodeData { | 131 struct StickyPositionNodeData { |
| 108 int scroll_ancestor; | 132 int scroll_ancestor; |
| 109 LayerStickyPositionConstraint constraints; | 133 LayerStickyPositionConstraint constraints; |
| 110 | 134 |
| 111 // This is the offset that blink has already applied to counteract the main | 135 // This is the offset that blink has already applied to counteract the main |
| 112 // thread scroll offset of the scroll ancestor. We need to account for this | 136 // thread scroll offset of the scroll ancestor. We need to account for this |
| 113 // by computing the additional offset necessary to keep the element stuck. | 137 // by computing the additional offset necessary to keep the element stuck. |
| 114 gfx::Vector2dF main_thread_offset; | 138 gfx::Vector2dF main_thread_offset; |
| 115 | 139 |
| 116 StickyPositionNodeData() : scroll_ancestor(-1) {} | 140 StickyPositionNodeData() : scroll_ancestor(-1) {} |
| 117 }; | 141 }; |
| 118 | 142 |
| 119 class CC_EXPORT TransformTree final : public PropertyTree<TransformNode> { | 143 class CC_EXPORT TransformTree final : public PropertyTree<TransformNode> { |
| 120 public: | 144 public: |
| 121 TransformTree(); | 145 TransformTree(); |
| 122 | 146 |
| 123 // These C++ special member functions cannot be implicit inline because | 147 // These C++ special member functions cannot be implicit inline because |
| 124 // they are exported by CC_EXPORT. They will be instantiated in every | 148 // they are exported by CC_EXPORT. They will be instantiated in every |
| 125 // compilation units that included this header, and compilation can fail | 149 // compilation units that included this header, and compilation can fail |
| 126 // because TransformCachedNodeData may be incomplete. | 150 // because TransformCachedNodeData may be incomplete. |
| 127 TransformTree(const TransformTree&) = delete; | 151 TransformTree(const TransformTree&) = delete; |
| 128 ~TransformTree(); | 152 ~TransformTree() final; |
| 129 TransformTree& operator=(const TransformTree&); | 153 TransformTree& operator=(const TransformTree&); |
| 130 | 154 |
| 131 bool operator==(const TransformTree& other) const; | 155 bool operator==(const TransformTree& other) const; |
| 132 | 156 |
| 133 static const int kContentsRootNodeId = 1; | 157 static const int kContentsRootNodeId = 1; |
| 134 | 158 |
| 135 int Insert(const TransformNode& tree_node, int parent_id); | 159 int Insert(const TransformNode& tree_node, int parent_id); |
| 136 | 160 |
| 137 void clear(); | 161 void clear(); |
| 138 | 162 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 | 307 |
| 284 static const int kViewportNodeId = 1; | 308 static const int kViewportNodeId = 1; |
| 285 | 309 |
| 286 void SetViewportClip(gfx::RectF viewport_rect); | 310 void SetViewportClip(gfx::RectF viewport_rect); |
| 287 gfx::RectF ViewportClip() const; | 311 gfx::RectF ViewportClip() const; |
| 288 }; | 312 }; |
| 289 | 313 |
| 290 class CC_EXPORT EffectTree final : public PropertyTree<EffectNode> { | 314 class CC_EXPORT EffectTree final : public PropertyTree<EffectNode> { |
| 291 public: | 315 public: |
| 292 EffectTree(); | 316 EffectTree(); |
| 293 ~EffectTree(); | 317 ~EffectTree() final; |
| 294 | 318 |
| 295 EffectTree& operator=(const EffectTree& from); | 319 EffectTree& operator=(const EffectTree& from); |
| 296 bool operator==(const EffectTree& other) const; | 320 bool operator==(const EffectTree& other) const; |
| 297 | 321 |
| 298 static const int kContentsRootNodeId = 1; | 322 static const int kContentsRootNodeId = 1; |
| 299 | 323 |
| 300 int Insert(const EffectNode& tree_node, int parent_id); | 324 int Insert(const EffectNode& tree_node, int parent_id); |
| 301 | 325 |
| 302 void clear(); | 326 void clear(); |
| 303 | 327 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 // Unsorted list of all mask layer ids that effect nodes refer to. | 387 // Unsorted list of all mask layer ids that effect nodes refer to. |
| 364 std::vector<int> mask_layer_ids_; | 388 std::vector<int> mask_layer_ids_; |
| 365 | 389 |
| 366 // Indexed by node id. | 390 // Indexed by node id. |
| 367 std::vector<std::unique_ptr<RenderSurfaceImpl>> render_surfaces_; | 391 std::vector<std::unique_ptr<RenderSurfaceImpl>> render_surfaces_; |
| 368 }; | 392 }; |
| 369 | 393 |
| 370 class CC_EXPORT ScrollTree final : public PropertyTree<ScrollNode> { | 394 class CC_EXPORT ScrollTree final : public PropertyTree<ScrollNode> { |
| 371 public: | 395 public: |
| 372 ScrollTree(); | 396 ScrollTree(); |
| 373 ~ScrollTree(); | 397 ~ScrollTree() final; |
| 374 | 398 |
| 375 ScrollTree& operator=(const ScrollTree& from); | 399 ScrollTree& operator=(const ScrollTree& from); |
| 376 bool operator==(const ScrollTree& other) const; | 400 bool operator==(const ScrollTree& other) const; |
| 377 | 401 |
| 378 void clear(); | 402 void clear(); |
| 379 | 403 |
| 380 gfx::ScrollOffset MaxScrollOffset(int scroll_node_id) const; | 404 gfx::ScrollOffset MaxScrollOffset(int scroll_node_id) const; |
| 381 void OnScrollOffsetAnimated(int layer_id, | 405 void OnScrollOffsetAnimated(int layer_id, |
| 382 int scroll_tree_index, | 406 int scroll_tree_index, |
| 383 const gfx::ScrollOffset& scroll_offset, | 407 const gfx::ScrollOffset& scroll_offset, |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 558 | 582 |
| 559 class CC_EXPORT PropertyTrees final { | 583 class CC_EXPORT PropertyTrees final { |
| 560 public: | 584 public: |
| 561 PropertyTrees(); | 585 PropertyTrees(); |
| 562 PropertyTrees(const PropertyTrees& other) = delete; | 586 PropertyTrees(const PropertyTrees& other) = delete; |
| 563 ~PropertyTrees(); | 587 ~PropertyTrees(); |
| 564 | 588 |
| 565 bool operator==(const PropertyTrees& other) const; | 589 bool operator==(const PropertyTrees& other) const; |
| 566 PropertyTrees& operator=(const PropertyTrees& from); | 590 PropertyTrees& operator=(const PropertyTrees& from); |
| 567 | 591 |
| 568 // These maps map from layer id to the index for each of the respective | |
| 569 // property node types. | |
| 570 std::unordered_map<int, int> layer_id_to_transform_node_index; | |
| 571 std::unordered_map<int, int> layer_id_to_effect_node_index; | |
| 572 std::unordered_map<int, int> layer_id_to_clip_node_index; | |
| 573 std::unordered_map<int, int> layer_id_to_scroll_node_index; | |
| 574 enum TreeType { TRANSFORM, EFFECT, CLIP, SCROLL }; | |
| 575 | |
| 576 // These maps allow mapping directly from a compositor element id to the | 592 // These maps allow mapping directly from a compositor element id to the |
| 577 // respective property node. This will eventually allow simplifying logic in | 593 // respective property node. This will eventually allow simplifying logic in |
| 578 // various places that today has to map from element id to layer id, and then | 594 // various places that today has to map from element id to layer id, and then |
| 579 // from layer id to the respective property node. Completing that work is | 595 // from layer id to the respective property node. Completing that work is |
| 580 // pending the launch of Slimming Paint v2 and reworking UI compositor logic | 596 // pending the launch of Slimming Paint v2 and reworking UI compositor logic |
| 581 // to produce cc property trees and these maps. | 597 // to produce cc property trees and these maps. |
| 582 std::unordered_map<ElementId, int, ElementIdHash> | 598 std::unordered_map<ElementId, int, ElementIdHash> |
| 583 element_id_to_effect_node_index; | 599 element_id_to_effect_node_index; |
| 584 std::unordered_map<ElementId, int, ElementIdHash> | 600 std::unordered_map<ElementId, int, ElementIdHash> |
| 585 element_id_to_scroll_node_index; | 601 element_id_to_scroll_node_index; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 608 bool is_main_thread; | 624 bool is_main_thread; |
| 609 bool is_active; | 625 bool is_active; |
| 610 | 626 |
| 611 void clear(); | 627 void clear(); |
| 612 | 628 |
| 613 void SetInnerViewportContainerBoundsDelta(gfx::Vector2dF bounds_delta); | 629 void SetInnerViewportContainerBoundsDelta(gfx::Vector2dF bounds_delta); |
| 614 void SetOuterViewportContainerBoundsDelta(gfx::Vector2dF bounds_delta); | 630 void SetOuterViewportContainerBoundsDelta(gfx::Vector2dF bounds_delta); |
| 615 void SetInnerViewportScrollBoundsDelta(gfx::Vector2dF bounds_delta); | 631 void SetInnerViewportScrollBoundsDelta(gfx::Vector2dF bounds_delta); |
| 616 void PushOpacityIfNeeded(PropertyTrees* target_tree); | 632 void PushOpacityIfNeeded(PropertyTrees* target_tree); |
| 617 void RemoveIdFromIdToIndexMaps(int id); | 633 void RemoveIdFromIdToIndexMaps(int id); |
| 618 bool IsInIdToIndexMap(TreeType tree_type, int id); | |
| 619 void UpdateChangeTracking(); | 634 void UpdateChangeTracking(); |
| 620 void PushChangeTrackingTo(PropertyTrees* tree); | 635 void PushChangeTrackingTo(PropertyTrees* tree); |
| 621 void ResetAllChangeTracking(); | 636 void ResetAllChangeTracking(); |
| 622 | 637 |
| 623 gfx::Vector2dF inner_viewport_container_bounds_delta() const { | 638 gfx::Vector2dF inner_viewport_container_bounds_delta() const { |
| 624 return inner_viewport_container_bounds_delta_; | 639 return inner_viewport_container_bounds_delta_; |
| 625 } | 640 } |
| 626 | 641 |
| 627 gfx::Vector2dF outer_viewport_container_bounds_delta() const { | 642 gfx::Vector2dF outer_viewport_container_bounds_delta() const { |
| 628 return outer_viewport_container_bounds_delta_; | 643 return outer_viewport_container_bounds_delta_; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 662 DrawTransforms& GetDrawTransforms(int transform_id, int effect_id) const; | 677 DrawTransforms& GetDrawTransforms(int transform_id, int effect_id) const; |
| 663 DrawTransformData& FetchDrawTransformsDataFromCache(int transform_id, | 678 DrawTransformData& FetchDrawTransformsDataFromCache(int transform_id, |
| 664 int effect_id) const; | 679 int effect_id) const; |
| 665 | 680 |
| 666 PropertyTreesCachedData cached_data_; | 681 PropertyTreesCachedData cached_data_; |
| 667 }; | 682 }; |
| 668 | 683 |
| 669 } // namespace cc | 684 } // namespace cc |
| 670 | 685 |
| 671 #endif // CC_TREES_PROPERTY_TREE_H_ | 686 #endif // CC_TREES_PROPERTY_TREE_H_ |
| OLD | NEW |