OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "cc/trees/tree_synchronizer.h" | 5 #include "cc/trees/tree_synchronizer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <set> | 9 #include <set> |
| 10 #include <unordered_map> |
10 | 11 |
11 #include "base/containers/hash_tables.h" | |
12 #include "base/containers/scoped_ptr_hash_map.h" | |
13 #include "base/logging.h" | 12 #include "base/logging.h" |
14 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
15 #include "cc/layers/layer.h" | 14 #include "cc/layers/layer.h" |
16 #include "cc/layers/layer_impl.h" | 15 #include "cc/layers/layer_impl.h" |
17 | 16 |
18 namespace cc { | 17 namespace cc { |
19 | 18 |
20 typedef base::ScopedPtrHashMap<int, scoped_ptr<LayerImpl>> | 19 using ScopedPtrLayerImplMap = std::unordered_map<int, scoped_ptr<LayerImpl>>; |
21 ScopedPtrLayerImplMap; | 20 using RawPtrLayerImplMap = std::unordered_map<int, LayerImpl*>; |
22 typedef base::hash_map<int, LayerImpl*> RawPtrLayerImplMap; | |
23 | 21 |
24 void CollectExistingLayerImplRecursive(ScopedPtrLayerImplMap* old_layers, | 22 void CollectExistingLayerImplRecursive(ScopedPtrLayerImplMap* old_layers, |
25 scoped_ptr<LayerImpl> layer_impl) { | 23 scoped_ptr<LayerImpl> layer_impl) { |
26 if (!layer_impl) | 24 if (!layer_impl) |
27 return; | 25 return; |
28 | 26 |
29 OwnedLayerImplList& children = layer_impl->children(); | 27 OwnedLayerImplList& children = layer_impl->children(); |
30 for (auto& child : children) | 28 for (auto& child : children) |
31 CollectExistingLayerImplRecursive(old_layers, std::move(child)); | 29 CollectExistingLayerImplRecursive(old_layers, std::move(child)); |
32 | 30 |
33 CollectExistingLayerImplRecursive(old_layers, layer_impl->TakeMaskLayer()); | 31 CollectExistingLayerImplRecursive(old_layers, layer_impl->TakeMaskLayer()); |
34 CollectExistingLayerImplRecursive(old_layers, layer_impl->TakeReplicaLayer()); | 32 CollectExistingLayerImplRecursive(old_layers, layer_impl->TakeReplicaLayer()); |
35 | 33 |
36 int id = layer_impl->id(); | 34 int id = layer_impl->id(); |
37 old_layers->set(id, std::move(layer_impl)); | 35 (*old_layers)[id] = std::move(layer_impl); |
38 } | 36 } |
39 | 37 |
40 template <typename LayerType> | 38 template <typename LayerType> |
41 scoped_ptr<LayerImpl> SynchronizeTreesInternal( | 39 scoped_ptr<LayerImpl> SynchronizeTreesInternal( |
42 LayerType* layer_root, | 40 LayerType* layer_root, |
43 scoped_ptr<LayerImpl> old_layer_impl_root, | 41 scoped_ptr<LayerImpl> old_layer_impl_root, |
44 LayerTreeImpl* tree_impl) { | 42 LayerTreeImpl* tree_impl) { |
45 DCHECK(tree_impl); | 43 DCHECK(tree_impl); |
46 | 44 |
47 TRACE_EVENT0("cc", "TreeSynchronizer::SynchronizeTrees"); | 45 TRACE_EVENT0("cc", "TreeSynchronizer::SynchronizeTrees"); |
(...skipping 23 matching lines...) Expand all Loading... |
71 LayerTreeImpl* tree_impl) { | 69 LayerTreeImpl* tree_impl) { |
72 return SynchronizeTreesInternal(layer_root, std::move(old_layer_impl_root), | 70 return SynchronizeTreesInternal(layer_root, std::move(old_layer_impl_root), |
73 tree_impl); | 71 tree_impl); |
74 } | 72 } |
75 | 73 |
76 template <typename LayerType> | 74 template <typename LayerType> |
77 scoped_ptr<LayerImpl> ReuseOrCreateLayerImpl(RawPtrLayerImplMap* new_layers, | 75 scoped_ptr<LayerImpl> ReuseOrCreateLayerImpl(RawPtrLayerImplMap* new_layers, |
78 ScopedPtrLayerImplMap* old_layers, | 76 ScopedPtrLayerImplMap* old_layers, |
79 LayerType* layer, | 77 LayerType* layer, |
80 LayerTreeImpl* tree_impl) { | 78 LayerTreeImpl* tree_impl) { |
81 scoped_ptr<LayerImpl> layer_impl = old_layers->take(layer->id()); | 79 scoped_ptr<LayerImpl> layer_impl = std::move((*old_layers)[layer->id()]); |
82 | 80 |
83 if (!layer_impl) | 81 if (!layer_impl) |
84 layer_impl = layer->CreateLayerImpl(tree_impl); | 82 layer_impl = layer->CreateLayerImpl(tree_impl); |
85 | 83 |
86 (*new_layers)[layer->id()] = layer_impl.get(); | 84 (*new_layers)[layer->id()] = layer_impl.get(); |
87 return layer_impl; | 85 return layer_impl; |
88 } | 86 } |
89 | 87 |
90 template <typename LayerType> | 88 template <typename LayerType> |
91 scoped_ptr<LayerImpl> SynchronizeTreesRecursiveInternal( | 89 scoped_ptr<LayerImpl> SynchronizeTreesRecursiveInternal( |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 #endif | 246 #endif |
249 } | 247 } |
250 | 248 |
251 void TreeSynchronizer::PushProperties(LayerImpl* layer, LayerImpl* layer_impl) { | 249 void TreeSynchronizer::PushProperties(LayerImpl* layer, LayerImpl* layer_impl) { |
252 int num_dependents_need_push_properties = 0; | 250 int num_dependents_need_push_properties = 0; |
253 PushPropertiesInternal( | 251 PushPropertiesInternal( |
254 layer, layer_impl, &num_dependents_need_push_properties); | 252 layer, layer_impl, &num_dependents_need_push_properties); |
255 } | 253 } |
256 | 254 |
257 } // namespace cc | 255 } // namespace cc |
OLD | NEW |