Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: cc/trees/property_tree.h

Issue 2801603010: Convert cc::PropertyTree to use a flat_map. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | cc/trees/property_tree.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11 #include <unordered_map> 11 #include <unordered_map>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/containers/flat_map.h"
14 #include "cc/base/filter_operations.h" 15 #include "cc/base/filter_operations.h"
15 #include "cc/base/synced_property.h" 16 #include "cc/base/synced_property.h"
16 #include "cc/cc_export.h" 17 #include "cc/cc_export.h"
17 #include "cc/layers/layer_sticky_position_constraint.h" 18 #include "cc/layers/layer_sticky_position_constraint.h"
18 #include "cc/trees/element_id.h" 19 #include "cc/trees/element_id.h"
19 #include "ui/gfx/geometry/rect_f.h" 20 #include "ui/gfx/geometry/rect_f.h"
20 #include "ui/gfx/geometry/scroll_offset.h" 21 #include "ui/gfx/geometry/scroll_offset.h"
21 #include "ui/gfx/transform.h" 22 #include "ui/gfx/transform.h"
22 23
23 namespace base { 24 namespace base {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 int index = FindNodeIndexFromOwningLayerId(id); 107 int index = FindNodeIndexFromOwningLayerId(id);
107 if (index == kInvalidNodeId) { 108 if (index == kInvalidNodeId) {
108 DCHECK(property_trees()->is_main_thread); 109 DCHECK(property_trees()->is_main_thread);
109 property_trees()->needs_rebuild = true; 110 property_trees()->needs_rebuild = true;
110 } 111 }
111 112
112 return Node(index); 113 return Node(index);
113 } 114 }
114 115
115 int FindNodeIndexFromOwningLayerId(int id) const { 116 int FindNodeIndexFromOwningLayerId(int id) const {
116 auto iter = owning_layer_id_to_node_index.find(id); 117 auto iter = owning_layer_id_to_node_index_.find(id);
117 if (iter == owning_layer_id_to_node_index.end()) 118 if (iter == owning_layer_id_to_node_index_.end())
118 return kInvalidNodeId; 119 return kInvalidNodeId;
119 else 120 else
120 return iter->second; 121 return iter->second;
121 } 122 }
122 123
123 void SetOwningLayerIdForNode(const T* node, int id) { 124 void SetOwningLayerIdForNode(const T* node, int id) {
124 if (!node) { 125 if (!node) {
125 owning_layer_id_to_node_index[id] = kInvalidNodeId; 126 owning_layer_id_to_node_index_[id] = kInvalidNodeId;
126 return; 127 return;
127 } 128 }
128 129
129 DCHECK(node == Node(node->id)); 130 DCHECK(node == Node(node->id));
130 owning_layer_id_to_node_index[id] = node->id; 131 owning_layer_id_to_node_index_[id] = node->id;
131 } 132 }
132 133
133 private: 134 private:
134 std::vector<T> nodes_; 135 std::vector<T> nodes_;
135 136
136 // These maps map from layer id to the property tree node index. 137 // Maps from layer id to the property tree node index. This container is
137 std::unordered_map<int, int> owning_layer_id_to_node_index; 138 // typically very small and the memory overhead of unordered_map will
139 // dominate so use a flat_map. See http://crbug.com/709243
140 base::flat_map<int, int> owning_layer_id_to_node_index_;
138 141
139 bool needs_update_; 142 bool needs_update_;
140 PropertyTrees* property_trees_; 143 PropertyTrees* property_trees_;
141 }; 144 };
142 145
143 struct StickyPositionNodeData; 146 struct StickyPositionNodeData;
144 147
145 class CC_EXPORT TransformTree final : public PropertyTree<TransformNode> { 148 class CC_EXPORT TransformTree final : public PropertyTree<TransformNode> {
146 public: 149 public:
147 TransformTree(); 150 TransformTree();
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 DrawTransforms& GetDrawTransforms(int transform_id, int effect_id) const; 723 DrawTransforms& GetDrawTransforms(int transform_id, int effect_id) const;
721 DrawTransformData& FetchDrawTransformsDataFromCache(int transform_id, 724 DrawTransformData& FetchDrawTransformsDataFromCache(int transform_id,
722 int effect_id) const; 725 int effect_id) const;
723 726
724 PropertyTreesCachedData cached_data_; 727 PropertyTreesCachedData cached_data_;
725 }; 728 };
726 729
727 } // namespace cc 730 } // namespace cc
728 731
729 #endif // CC_TREES_PROPERTY_TREE_H_ 732 #endif // CC_TREES_PROPERTY_TREE_H_
OLDNEW
« no previous file with comments | « no previous file | cc/trees/property_tree.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698