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* FindNodeFromId(int id) { return Node(FindNodeIndexFromId(id)); } | |
101 int FindNodeIndexFromId(int id) const { | |
ajuma
2017/03/16 17:15:32
Would 'FromOwningId' instead of 'FromId' be cleare
| |
102 auto iter = layer_id_to_node_index.find(id); | |
103 if (iter == layer_id_to_node_index.end()) | |
104 return kInvalidNodeId; | |
105 else | |
106 return iter->second; | |
107 } | |
108 | |
109 void InsertOwningIdForNode(const T* node, int id) { | |
110 if (!node) { | |
111 layer_id_to_node_index[id] = kInvalidNodeId; | |
112 return; | |
113 } | |
114 | |
115 DCHECK(node == Node(node->id)); | |
116 layer_id_to_node_index[id] = node->id; | |
117 } | |
118 | |
100 private: | 119 private: |
101 std::vector<T> nodes_; | 120 std::vector<T> nodes_; |
102 | 121 |
122 // These maps map from layer id to the property tree node index. | |
123 std::unordered_map<int, int> layer_id_to_node_index; | |
124 | |
103 bool needs_update_; | 125 bool needs_update_; |
104 PropertyTrees* property_trees_; | 126 PropertyTrees* property_trees_; |
105 }; | 127 }; |
106 | 128 |
107 struct StickyPositionNodeData { | 129 struct StickyPositionNodeData { |
108 int scroll_ancestor; | 130 int scroll_ancestor; |
109 LayerStickyPositionConstraint constraints; | 131 LayerStickyPositionConstraint constraints; |
110 | 132 |
111 // This is the offset that blink has already applied to counteract the main | 133 // 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 | 134 // 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. | 135 // by computing the additional offset necessary to keep the element stuck. |
114 gfx::Vector2dF main_thread_offset; | 136 gfx::Vector2dF main_thread_offset; |
115 | 137 |
116 StickyPositionNodeData() : scroll_ancestor(-1) {} | 138 StickyPositionNodeData() : scroll_ancestor(-1) {} |
117 }; | 139 }; |
118 | 140 |
119 class CC_EXPORT TransformTree final : public PropertyTree<TransformNode> { | 141 class CC_EXPORT TransformTree final : public PropertyTree<TransformNode> { |
120 public: | 142 public: |
121 TransformTree(); | 143 TransformTree(); |
122 | 144 |
123 // These C++ special member functions cannot be implicit inline because | 145 // These C++ special member functions cannot be implicit inline because |
124 // they are exported by CC_EXPORT. They will be instantiated in every | 146 // they are exported by CC_EXPORT. They will be instantiated in every |
125 // compilation units that included this header, and compilation can fail | 147 // compilation units that included this header, and compilation can fail |
126 // because TransformCachedNodeData may be incomplete. | 148 // because TransformCachedNodeData may be incomplete. |
127 TransformTree(const TransformTree&) = delete; | 149 TransformTree(const TransformTree&) = delete; |
128 ~TransformTree(); | 150 ~TransformTree() final; |
129 TransformTree& operator=(const TransformTree&); | 151 TransformTree& operator=(const TransformTree&); |
130 | 152 |
131 bool operator==(const TransformTree& other) const; | 153 bool operator==(const TransformTree& other) const; |
132 | 154 |
133 static const int kContentsRootNodeId = 1; | 155 static const int kContentsRootNodeId = 1; |
134 | 156 |
135 int Insert(const TransformNode& tree_node, int parent_id); | 157 int Insert(const TransformNode& tree_node, int parent_id); |
136 | 158 |
137 void clear(); | 159 void clear(); |
138 | 160 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
283 | 305 |
284 static const int kViewportNodeId = 1; | 306 static const int kViewportNodeId = 1; |
285 | 307 |
286 void SetViewportClip(gfx::RectF viewport_rect); | 308 void SetViewportClip(gfx::RectF viewport_rect); |
287 gfx::RectF ViewportClip() const; | 309 gfx::RectF ViewportClip() const; |
288 }; | 310 }; |
289 | 311 |
290 class CC_EXPORT EffectTree final : public PropertyTree<EffectNode> { | 312 class CC_EXPORT EffectTree final : public PropertyTree<EffectNode> { |
291 public: | 313 public: |
292 EffectTree(); | 314 EffectTree(); |
293 ~EffectTree(); | 315 ~EffectTree() final; |
294 | 316 |
295 EffectTree& operator=(const EffectTree& from); | 317 EffectTree& operator=(const EffectTree& from); |
296 bool operator==(const EffectTree& other) const; | 318 bool operator==(const EffectTree& other) const; |
297 | 319 |
298 static const int kContentsRootNodeId = 1; | 320 static const int kContentsRootNodeId = 1; |
299 | 321 |
300 int Insert(const EffectNode& tree_node, int parent_id); | 322 int Insert(const EffectNode& tree_node, int parent_id); |
301 | 323 |
302 void clear(); | 324 void clear(); |
303 | 325 |
(...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. | 385 // Unsorted list of all mask layer ids that effect nodes refer to. |
364 std::vector<int> mask_layer_ids_; | 386 std::vector<int> mask_layer_ids_; |
365 | 387 |
366 // Indexed by node id. | 388 // Indexed by node id. |
367 std::vector<std::unique_ptr<RenderSurfaceImpl>> render_surfaces_; | 389 std::vector<std::unique_ptr<RenderSurfaceImpl>> render_surfaces_; |
368 }; | 390 }; |
369 | 391 |
370 class CC_EXPORT ScrollTree final : public PropertyTree<ScrollNode> { | 392 class CC_EXPORT ScrollTree final : public PropertyTree<ScrollNode> { |
371 public: | 393 public: |
372 ScrollTree(); | 394 ScrollTree(); |
373 ~ScrollTree(); | 395 ~ScrollTree() final; |
374 | 396 |
375 ScrollTree& operator=(const ScrollTree& from); | 397 ScrollTree& operator=(const ScrollTree& from); |
376 bool operator==(const ScrollTree& other) const; | 398 bool operator==(const ScrollTree& other) const; |
377 | 399 |
378 void clear(); | 400 void clear(); |
379 | 401 |
380 gfx::ScrollOffset MaxScrollOffset(int scroll_node_id) const; | 402 gfx::ScrollOffset MaxScrollOffset(int scroll_node_id) const; |
381 void OnScrollOffsetAnimated(int layer_id, | 403 void OnScrollOffsetAnimated(int layer_id, |
382 int scroll_tree_index, | 404 int scroll_tree_index, |
383 const gfx::ScrollOffset& scroll_offset, | 405 const gfx::ScrollOffset& scroll_offset, |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
558 | 580 |
559 class CC_EXPORT PropertyTrees final { | 581 class CC_EXPORT PropertyTrees final { |
560 public: | 582 public: |
561 PropertyTrees(); | 583 PropertyTrees(); |
562 PropertyTrees(const PropertyTrees& other) = delete; | 584 PropertyTrees(const PropertyTrees& other) = delete; |
563 ~PropertyTrees(); | 585 ~PropertyTrees(); |
564 | 586 |
565 bool operator==(const PropertyTrees& other) const; | 587 bool operator==(const PropertyTrees& other) const; |
566 PropertyTrees& operator=(const PropertyTrees& from); | 588 PropertyTrees& operator=(const PropertyTrees& from); |
567 | 589 |
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 | 590 // These maps allow mapping directly from a compositor element id to the |
577 // respective property node. This will eventually allow simplifying logic in | 591 // 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 | 592 // 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 | 593 // 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 | 594 // pending the launch of Slimming Paint v2 and reworking UI compositor logic |
581 // to produce cc property trees and these maps. | 595 // to produce cc property trees and these maps. |
582 std::unordered_map<ElementId, int, ElementIdHash> | 596 std::unordered_map<ElementId, int, ElementIdHash> |
583 element_id_to_effect_node_index; | 597 element_id_to_effect_node_index; |
584 std::unordered_map<ElementId, int, ElementIdHash> | 598 std::unordered_map<ElementId, int, ElementIdHash> |
585 element_id_to_scroll_node_index; | 599 element_id_to_scroll_node_index; |
(...skipping 22 matching lines...) Expand all Loading... | |
608 bool is_main_thread; | 622 bool is_main_thread; |
609 bool is_active; | 623 bool is_active; |
610 | 624 |
611 void clear(); | 625 void clear(); |
612 | 626 |
613 void SetInnerViewportContainerBoundsDelta(gfx::Vector2dF bounds_delta); | 627 void SetInnerViewportContainerBoundsDelta(gfx::Vector2dF bounds_delta); |
614 void SetOuterViewportContainerBoundsDelta(gfx::Vector2dF bounds_delta); | 628 void SetOuterViewportContainerBoundsDelta(gfx::Vector2dF bounds_delta); |
615 void SetInnerViewportScrollBoundsDelta(gfx::Vector2dF bounds_delta); | 629 void SetInnerViewportScrollBoundsDelta(gfx::Vector2dF bounds_delta); |
616 void PushOpacityIfNeeded(PropertyTrees* target_tree); | 630 void PushOpacityIfNeeded(PropertyTrees* target_tree); |
617 void RemoveIdFromIdToIndexMaps(int id); | 631 void RemoveIdFromIdToIndexMaps(int id); |
618 bool IsInIdToIndexMap(TreeType tree_type, int id); | |
619 void UpdateChangeTracking(); | 632 void UpdateChangeTracking(); |
620 void PushChangeTrackingTo(PropertyTrees* tree); | 633 void PushChangeTrackingTo(PropertyTrees* tree); |
621 void ResetAllChangeTracking(); | 634 void ResetAllChangeTracking(); |
622 | 635 |
623 gfx::Vector2dF inner_viewport_container_bounds_delta() const { | 636 gfx::Vector2dF inner_viewport_container_bounds_delta() const { |
624 return inner_viewport_container_bounds_delta_; | 637 return inner_viewport_container_bounds_delta_; |
625 } | 638 } |
626 | 639 |
627 gfx::Vector2dF outer_viewport_container_bounds_delta() const { | 640 gfx::Vector2dF outer_viewport_container_bounds_delta() const { |
628 return outer_viewport_container_bounds_delta_; | 641 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; | 675 DrawTransforms& GetDrawTransforms(int transform_id, int effect_id) const; |
663 DrawTransformData& FetchDrawTransformsDataFromCache(int transform_id, | 676 DrawTransformData& FetchDrawTransformsDataFromCache(int transform_id, |
664 int effect_id) const; | 677 int effect_id) const; |
665 | 678 |
666 PropertyTreesCachedData cached_data_; | 679 PropertyTreesCachedData cached_data_; |
667 }; | 680 }; |
668 | 681 |
669 } // namespace cc | 682 } // namespace cc |
670 | 683 |
671 #endif // CC_TREES_PROPERTY_TREE_H_ | 684 #endif // CC_TREES_PROPERTY_TREE_H_ |
OLD | NEW |