| 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 "base/containers/hash_tables.h" | 7 #include "base/containers/hash_tables.h" |
| 8 #include "base/containers/scoped_ptr_hash_map.h" | 8 #include "base/containers/scoped_ptr_hash_map.h" |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "cc/animation/scrollbar_animation_controller.h" | 11 #include "cc/animation/scrollbar_animation_controller.h" |
| 12 #include "cc/input/scrollbar.h" | 12 #include "cc/input/scrollbar.h" |
| 13 #include "cc/layers/layer.h" | 13 #include "cc/layers/layer.h" |
| 14 #include "cc/layers/layer_impl.h" | 14 #include "cc/layers/layer_impl.h" |
| 15 #include "cc/layers/scrollbar_layer_impl_base.h" | 15 #include "cc/layers/scrollbar_layer_impl_base.h" |
| 16 #include "cc/layers/scrollbar_layer_interface.h" | 16 #include "cc/layers/scrollbar_layer_interface.h" |
| 17 | 17 |
| 18 namespace cc { | 18 namespace cc { |
| 19 | 19 |
| 20 typedef base::ScopedPtrHashMap<int, LayerImpl> ScopedPtrLayerImplMap; | 20 typedef base::ScopedPtrHashMap<int, LayerImpl> ScopedPtrLayerImplMap; |
| 21 typedef base::hash_map<int, LayerImpl*> RawPtrLayerImplMap; | 21 typedef base::hash_map<int, LayerImpl*> RawPtrLayerImplMap; |
| 22 | 22 |
| 23 void CollectExistingLayerImplRecursive(ScopedPtrLayerImplMap* old_layers, | 23 void CollectExistingLayerImplRecursive(ScopedPtrLayerImplMap* old_layers, |
| 24 scoped_ptr<LayerImpl> layer_impl) { | 24 scoped_ptr<LayerImpl> layer_impl) { |
| 25 if (!layer_impl) | 25 if (!layer_impl) |
| 26 return; | 26 return; |
| 27 | 27 |
| 28 layer_impl->ClearScrollbars(); |
| 29 if (ScrollbarLayerImplBase* scrollbar_layer = |
| 30 layer_impl->ToScrollbarLayer()) { |
| 31 scrollbar_layer->ClearClipLayer(); |
| 32 scrollbar_layer->ClearScrollLayer(); |
| 33 } |
| 34 |
| 28 OwnedLayerImplList& children = layer_impl->children(); | 35 OwnedLayerImplList& children = layer_impl->children(); |
| 29 for (OwnedLayerImplList::iterator it = children.begin(); | 36 for (OwnedLayerImplList::iterator it = children.begin(); |
| 30 it != children.end(); | 37 it != children.end(); |
| 31 ++it) | 38 ++it) |
| 32 CollectExistingLayerImplRecursive(old_layers, children.take(it)); | 39 CollectExistingLayerImplRecursive(old_layers, children.take(it)); |
| 33 | 40 |
| 34 CollectExistingLayerImplRecursive(old_layers, layer_impl->TakeMaskLayer()); | 41 CollectExistingLayerImplRecursive(old_layers, layer_impl->TakeMaskLayer()); |
| 35 CollectExistingLayerImplRecursive(old_layers, layer_impl->TakeReplicaLayer()); | 42 CollectExistingLayerImplRecursive(old_layers, layer_impl->TakeReplicaLayer()); |
| 36 | 43 |
| 37 int id = layer_impl->id(); | 44 int id = layer_impl->id(); |
| 38 old_layers->set(id, layer_impl.Pass()); | 45 old_layers->set(id, layer_impl.Pass()); |
| 39 } | 46 } |
| 40 | 47 |
| 41 template <typename LayerType> | 48 template <typename LayerType> |
| 42 scoped_ptr<LayerImpl> SynchronizeTreesInternal( | 49 scoped_ptr<LayerImpl> SynchronizeTreesInternal( |
| 43 LayerType* layer_root, | 50 LayerType* layer_root, |
| 44 scoped_ptr<LayerImpl> old_layer_impl_root, | 51 scoped_ptr<LayerImpl> old_layer_impl_root, |
| 45 LayerTreeImpl* tree_impl) { | 52 LayerTreeImpl* tree_impl) { |
| 46 DCHECK(tree_impl); | 53 DCHECK(tree_impl); |
| 47 | 54 |
| 48 TRACE_EVENT0("cc", "TreeSynchronizer::SynchronizeTrees"); | 55 TRACE_EVENT0("cc", "TreeSynchronizer::SynchronizeTrees"); |
| 49 ScopedPtrLayerImplMap old_layers; | 56 ScopedPtrLayerImplMap old_layers; |
| 50 RawPtrLayerImplMap new_layers; | 57 RawPtrLayerImplMap new_layers; |
| 51 | 58 |
| 52 CollectExistingLayerImplRecursive(&old_layers, old_layer_impl_root.Pass()); | 59 CollectExistingLayerImplRecursive(&old_layers, old_layer_impl_root.Pass()); |
| 53 | 60 |
| 54 scoped_ptr<LayerImpl> new_tree = SynchronizeTreesRecursive( | 61 scoped_ptr<LayerImpl> new_tree = SynchronizeTreesRecursive( |
| 55 &new_layers, &old_layers, layer_root, tree_impl); | 62 &new_layers, &old_layers, layer_root, tree_impl); |
| 56 | 63 |
| 57 UpdateScrollbarLayerPointersRecursive(&new_layers, layer_root); | |
| 58 | |
| 59 return new_tree.Pass(); | 64 return new_tree.Pass(); |
| 60 } | 65 } |
| 61 | 66 |
| 62 scoped_ptr<LayerImpl> TreeSynchronizer::SynchronizeTrees( | 67 scoped_ptr<LayerImpl> TreeSynchronizer::SynchronizeTrees( |
| 63 Layer* layer_root, | 68 Layer* layer_root, |
| 64 scoped_ptr<LayerImpl> old_layer_impl_root, | 69 scoped_ptr<LayerImpl> old_layer_impl_root, |
| 65 LayerTreeImpl* tree_impl) { | 70 LayerTreeImpl* tree_impl) { |
| 66 return SynchronizeTreesInternal( | 71 return SynchronizeTreesInternal( |
| 67 layer_root, old_layer_impl_root.Pass(), tree_impl); | 72 layer_root, old_layer_impl_root.Pass(), tree_impl); |
| 68 } | 73 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 for (size_t i = 0; i < layer->children().size(); ++i) { | 110 for (size_t i = 0; i < layer->children().size(); ++i) { |
| 106 layer_impl->AddChild(SynchronizeTreesRecursiveInternal( | 111 layer_impl->AddChild(SynchronizeTreesRecursiveInternal( |
| 107 new_layers, old_layers, layer->child_at(i), tree_impl)); | 112 new_layers, old_layers, layer->child_at(i), tree_impl)); |
| 108 } | 113 } |
| 109 | 114 |
| 110 layer_impl->SetMaskLayer(SynchronizeTreesRecursiveInternal( | 115 layer_impl->SetMaskLayer(SynchronizeTreesRecursiveInternal( |
| 111 new_layers, old_layers, layer->mask_layer(), tree_impl)); | 116 new_layers, old_layers, layer->mask_layer(), tree_impl)); |
| 112 layer_impl->SetReplicaLayer(SynchronizeTreesRecursiveInternal( | 117 layer_impl->SetReplicaLayer(SynchronizeTreesRecursiveInternal( |
| 113 new_layers, old_layers, layer->replica_layer(), tree_impl)); | 118 new_layers, old_layers, layer->replica_layer(), tree_impl)); |
| 114 | 119 |
| 115 // Remove all dangling pointers. The pointers will be setup later in | |
| 116 // UpdateScrollbarLayerPointersRecursive phase | |
| 117 layer_impl->SetHorizontalScrollbarLayer(NULL); | |
| 118 layer_impl->SetVerticalScrollbarLayer(NULL); | |
| 119 | |
| 120 return layer_impl.Pass(); | 120 return layer_impl.Pass(); |
| 121 } | 121 } |
| 122 | 122 |
| 123 scoped_ptr<LayerImpl> SynchronizeTreesRecursive( | 123 scoped_ptr<LayerImpl> SynchronizeTreesRecursive( |
| 124 RawPtrLayerImplMap* new_layers, | 124 RawPtrLayerImplMap* new_layers, |
| 125 ScopedPtrLayerImplMap* old_layers, | 125 ScopedPtrLayerImplMap* old_layers, |
| 126 Layer* layer, | 126 Layer* layer, |
| 127 LayerTreeImpl* tree_impl) { | 127 LayerTreeImpl* tree_impl) { |
| 128 return SynchronizeTreesRecursiveInternal( | 128 return SynchronizeTreesRecursiveInternal( |
| 129 new_layers, old_layers, layer, tree_impl); | 129 new_layers, old_layers, layer, tree_impl); |
| 130 } | 130 } |
| 131 | 131 |
| 132 scoped_ptr<LayerImpl> SynchronizeTreesRecursive( | 132 scoped_ptr<LayerImpl> SynchronizeTreesRecursive( |
| 133 RawPtrLayerImplMap* new_layers, | 133 RawPtrLayerImplMap* new_layers, |
| 134 ScopedPtrLayerImplMap* old_layers, | 134 ScopedPtrLayerImplMap* old_layers, |
| 135 LayerImpl* layer, | 135 LayerImpl* layer, |
| 136 LayerTreeImpl* tree_impl) { | 136 LayerTreeImpl* tree_impl) { |
| 137 return SynchronizeTreesRecursiveInternal( | 137 return SynchronizeTreesRecursiveInternal( |
| 138 new_layers, old_layers, layer, tree_impl); | 138 new_layers, old_layers, layer, tree_impl); |
| 139 } | 139 } |
| 140 | 140 |
| 141 template <typename LayerType, typename ScrollbarLayerType> | |
| 142 void UpdateScrollbarLayerPointersRecursiveInternal( | |
| 143 const RawPtrLayerImplMap* new_layers, | |
| 144 LayerType* layer) { | |
| 145 if (!layer) | |
| 146 return; | |
| 147 | |
| 148 for (size_t i = 0; i < layer->children().size(); ++i) { | |
| 149 UpdateScrollbarLayerPointersRecursiveInternal< | |
| 150 LayerType, ScrollbarLayerType>(new_layers, layer->child_at(i)); | |
| 151 } | |
| 152 | |
| 153 ScrollbarLayerType* scrollbar_layer = layer->ToScrollbarLayer(); | |
| 154 if (!scrollbar_layer) | |
| 155 return; | |
| 156 | |
| 157 RawPtrLayerImplMap::const_iterator iter = | |
| 158 new_layers->find(layer->id()); | |
| 159 ScrollbarLayerImplBase* scrollbar_layer_impl = | |
| 160 iter != new_layers->end() | |
| 161 ? static_cast<ScrollbarLayerImplBase*>(iter->second) | |
| 162 : NULL; | |
| 163 iter = new_layers->find(scrollbar_layer->ScrollLayerId()); | |
| 164 LayerImpl* scroll_layer_impl = | |
| 165 iter != new_layers->end() ? iter->second : NULL; | |
| 166 | |
| 167 DCHECK(scrollbar_layer_impl); | |
| 168 DCHECK(scroll_layer_impl); | |
| 169 | |
| 170 if (scrollbar_layer->orientation() == HORIZONTAL) | |
| 171 scroll_layer_impl->SetHorizontalScrollbarLayer(scrollbar_layer_impl); | |
| 172 else | |
| 173 scroll_layer_impl->SetVerticalScrollbarLayer(scrollbar_layer_impl); | |
| 174 } | |
| 175 | |
| 176 void UpdateScrollbarLayerPointersRecursive(const RawPtrLayerImplMap* new_layers, | |
| 177 Layer* layer) { | |
| 178 UpdateScrollbarLayerPointersRecursiveInternal<Layer, ScrollbarLayerInterface>( | |
| 179 new_layers, layer); | |
| 180 } | |
| 181 | |
| 182 void UpdateScrollbarLayerPointersRecursive(const RawPtrLayerImplMap* new_layers, | |
| 183 LayerImpl* layer) { | |
| 184 UpdateScrollbarLayerPointersRecursiveInternal< | |
| 185 LayerImpl, | |
| 186 ScrollbarLayerImplBase>(new_layers, layer); | |
| 187 } | |
| 188 | |
| 189 // static | 141 // static |
| 190 void TreeSynchronizer::SetNumDependentsNeedPushProperties( | 142 void TreeSynchronizer::SetNumDependentsNeedPushProperties( |
| 191 Layer* layer, size_t num) { | 143 Layer* layer, size_t num) { |
| 192 layer->num_dependents_need_push_properties_ = num; | 144 layer->num_dependents_need_push_properties_ = num; |
| 193 } | 145 } |
| 194 | 146 |
| 195 // static | 147 // static |
| 196 void TreeSynchronizer::SetNumDependentsNeedPushProperties( | 148 void TreeSynchronizer::SetNumDependentsNeedPushProperties( |
| 197 LayerImpl* layer, size_t num) { | 149 LayerImpl* layer, size_t num) { |
| 198 } | 150 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 layer, layer_impl, &num_dependents_need_push_properties); | 208 layer, layer_impl, &num_dependents_need_push_properties); |
| 257 } | 209 } |
| 258 | 210 |
| 259 void TreeSynchronizer::PushProperties(LayerImpl* layer, LayerImpl* layer_impl) { | 211 void TreeSynchronizer::PushProperties(LayerImpl* layer, LayerImpl* layer_impl) { |
| 260 size_t num_dependents_need_push_properties = 0; | 212 size_t num_dependents_need_push_properties = 0; |
| 261 PushPropertiesInternal( | 213 PushPropertiesInternal( |
| 262 layer, layer_impl, &num_dependents_need_push_properties); | 214 layer, layer_impl, &num_dependents_need_push_properties); |
| 263 } | 215 } |
| 264 | 216 |
| 265 } // namespace cc | 217 } // namespace cc |
| OLD | NEW |