| 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/tree_synchronizer.h" | 5 #include "cc/tree_synchronizer.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "cc/layer.h" | 9 #include "cc/layer.h" |
| 10 #include "cc/layer_impl.h" | 10 #include "cc/layer_impl.h" |
| 11 #include "cc/scrollbar_animation_controller.h" | 11 #include "cc/scrollbar_animation_controller.h" |
| 12 #include "cc/scrollbar_layer.h" | 12 #include "cc/scrollbar_layer.h" |
| 13 #include "cc/scrollbar_layer_impl.h" | 13 #include "cc/scrollbar_layer_impl.h" |
| 14 | 14 |
| 15 namespace cc { | 15 namespace cc { |
| 16 | 16 |
| 17 typedef ScopedPtrHashMap<int, LayerImpl> ScopedPtrLayerImplMap; | 17 typedef ScopedPtrHashMap<int, LayerImpl> ScopedPtrLayerImplMap; |
| 18 typedef base::hash_map<int, LayerImpl*> RawPtrLayerImplMap; | 18 typedef base::hash_map<int, LayerImpl*> RawPtrLayerImplMap; |
| 19 | 19 |
| 20 void collectExistingLayerImplRecursive(ScopedPtrLayerImplMap& oldLayers, scoped_
ptr<LayerImpl> layerImpl) | 20 void collectExistingLayerImplRecursive(ScopedPtrLayerImplMap& oldLayers, scoped_
ptr<LayerImpl> layerImpl) |
| 21 { | 21 { |
| 22 if (!layerImpl) | 22 if (!layerImpl) |
| 23 return; | 23 return; |
| 24 | 24 |
| 25 ScopedPtrVector<LayerImpl>& children = layerImpl->children(); | 25 ScopedPtrVector<LayerImpl>& children = layerImpl->children(); |
| 26 for (ScopedPtrVector<LayerImpl>::iterator it = children.begin(); it != child
ren.end(); ++it) | 26 for (ScopedPtrVector<LayerImpl>::iterator it = children.begin(); it != child
ren.end(); ++it) |
| 27 collectExistingLayerImplRecursive(oldLayers, children.take(it)); | 27 collectExistingLayerImplRecursive(oldLayers, children.take(it)); |
| 28 | 28 |
| 29 collectExistingLayerImplRecursive(oldLayers, layerImpl->takeMaskLayer()); | 29 collectExistingLayerImplRecursive(oldLayers, layerImpl->TakeMaskLayer()); |
| 30 collectExistingLayerImplRecursive(oldLayers, layerImpl->takeReplicaLayer()); | 30 collectExistingLayerImplRecursive(oldLayers, layerImpl->TakeReplicaLayer()); |
| 31 | 31 |
| 32 int id = layerImpl->id(); | 32 int id = layerImpl->id(); |
| 33 oldLayers.set(id, layerImpl.Pass()); | 33 oldLayers.set(id, layerImpl.Pass()); |
| 34 } | 34 } |
| 35 | 35 |
| 36 template <typename LayerType> | 36 template <typename LayerType> |
| 37 scoped_ptr<LayerImpl> synchronizeTreesInternal(LayerType* layerRoot, scoped_ptr<
LayerImpl> oldLayerImplRoot, LayerTreeImpl* treeImpl) | 37 scoped_ptr<LayerImpl> synchronizeTreesInternal(LayerType* layerRoot, scoped_ptr<
LayerImpl> oldLayerImplRoot, LayerTreeImpl* treeImpl) |
| 38 { | 38 { |
| 39 DCHECK(treeImpl); | 39 DCHECK(treeImpl); |
| 40 | 40 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 60 { | 60 { |
| 61 return synchronizeTreesInternal(layerRoot, oldLayerImplRoot.Pass(), treeImpl
); | 61 return synchronizeTreesInternal(layerRoot, oldLayerImplRoot.Pass(), treeImpl
); |
| 62 } | 62 } |
| 63 | 63 |
| 64 template <typename LayerType> | 64 template <typename LayerType> |
| 65 scoped_ptr<LayerImpl> reuseOrCreateLayerImpl(RawPtrLayerImplMap& newLayers, Scop
edPtrLayerImplMap& oldLayers, LayerType* layer, LayerTreeImpl* treeImpl) | 65 scoped_ptr<LayerImpl> reuseOrCreateLayerImpl(RawPtrLayerImplMap& newLayers, Scop
edPtrLayerImplMap& oldLayers, LayerType* layer, LayerTreeImpl* treeImpl) |
| 66 { | 66 { |
| 67 scoped_ptr<LayerImpl> layerImpl = oldLayers.take(layer->id()); | 67 scoped_ptr<LayerImpl> layerImpl = oldLayers.take(layer->id()); |
| 68 | 68 |
| 69 if (!layerImpl) | 69 if (!layerImpl) |
| 70 layerImpl = layer->createLayerImpl(treeImpl); | 70 layerImpl = layer->CreateLayerImpl(treeImpl); |
| 71 | 71 |
| 72 newLayers[layer->id()] = layerImpl.get(); | 72 newLayers[layer->id()] = layerImpl.get(); |
| 73 return layerImpl.Pass(); | 73 return layerImpl.Pass(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 template <typename LayerType> | 76 template <typename LayerType> |
| 77 scoped_ptr<LayerImpl> synchronizeTreesRecursiveInternal(RawPtrLayerImplMap& newL
ayers, ScopedPtrLayerImplMap& oldLayers, LayerType* layer, LayerTreeImpl* treeIm
pl) | 77 scoped_ptr<LayerImpl> synchronizeTreesRecursiveInternal(RawPtrLayerImplMap& newL
ayers, ScopedPtrLayerImplMap& oldLayers, LayerType* layer, LayerTreeImpl* treeIm
pl) |
| 78 { | 78 { |
| 79 if (!layer) | 79 if (!layer) |
| 80 return scoped_ptr<LayerImpl>(); | 80 return scoped_ptr<LayerImpl>(); |
| 81 | 81 |
| 82 scoped_ptr<LayerImpl> layerImpl = reuseOrCreateLayerImpl(newLayers, oldLayer
s, layer, treeImpl); | 82 scoped_ptr<LayerImpl> layerImpl = reuseOrCreateLayerImpl(newLayers, oldLayer
s, layer, treeImpl); |
| 83 | 83 |
| 84 layerImpl->clearChildList(); | 84 layerImpl->ClearChildList(); |
| 85 for (size_t i = 0; i < layer->children().size(); ++i) | 85 for (size_t i = 0; i < layer->children().size(); ++i) |
| 86 layerImpl->addChild(synchronizeTreesRecursiveInternal(newLayers, oldLaye
rs, layer->childAt(i), treeImpl)); | 86 layerImpl->AddChild(synchronizeTreesRecursiveInternal(newLayers, oldLaye
rs, layer->child_at(i), treeImpl)); |
| 87 | 87 |
| 88 layerImpl->setMaskLayer(synchronizeTreesRecursiveInternal(newLayers, oldLaye
rs, layer->maskLayer(), treeImpl)); | 88 layerImpl->SetMaskLayer(synchronizeTreesRecursiveInternal(newLayers, oldLaye
rs, layer->mask_layer(), treeImpl)); |
| 89 layerImpl->setReplicaLayer(synchronizeTreesRecursiveInternal(newLayers, oldL
ayers, layer->replicaLayer(), treeImpl)); | 89 layerImpl->SetReplicaLayer(synchronizeTreesRecursiveInternal(newLayers, oldL
ayers, layer->replica_layer(), treeImpl)); |
| 90 | 90 |
| 91 // Remove all dangling pointers. The pointers will be setup later in updateS
crollbarLayerPointersRecursive phase | 91 // Remove all dangling pointers. The pointers will be setup later in updateS
crollbarLayerPointersRecursive phase |
| 92 layerImpl->setHorizontalScrollbarLayer(0); | 92 layerImpl->SetHorizontalScrollbarLayer(NULL); |
| 93 layerImpl->setVerticalScrollbarLayer(0); | 93 layerImpl->SetVerticalScrollbarLayer(NULL); |
| 94 | 94 |
| 95 return layerImpl.Pass(); | 95 return layerImpl.Pass(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 scoped_ptr<LayerImpl> synchronizeTreesRecursive(RawPtrLayerImplMap& newLayers, S
copedPtrLayerImplMap& oldLayers, Layer* layer, LayerTreeImpl* treeImpl) | 98 scoped_ptr<LayerImpl> synchronizeTreesRecursive(RawPtrLayerImplMap& newLayers, S
copedPtrLayerImplMap& oldLayers, Layer* layer, LayerTreeImpl* treeImpl) |
| 99 { | 99 { |
| 100 return synchronizeTreesRecursiveInternal(newLayers, oldLayers, layer, treeIm
pl); | 100 return synchronizeTreesRecursiveInternal(newLayers, oldLayers, layer, treeIm
pl); |
| 101 } | 101 } |
| 102 | 102 |
| 103 scoped_ptr<LayerImpl> synchronizeTreesRecursive(RawPtrLayerImplMap& newLayers, S
copedPtrLayerImplMap& oldLayers, LayerImpl* layer, LayerTreeImpl* treeImpl) | 103 scoped_ptr<LayerImpl> synchronizeTreesRecursive(RawPtrLayerImplMap& newLayers, S
copedPtrLayerImplMap& oldLayers, LayerImpl* layer, LayerTreeImpl* treeImpl) |
| 104 { | 104 { |
| 105 return synchronizeTreesRecursiveInternal(newLayers, oldLayers, layer, treeIm
pl); | 105 return synchronizeTreesRecursiveInternal(newLayers, oldLayers, layer, treeIm
pl); |
| 106 } | 106 } |
| 107 | 107 |
| 108 template <typename LayerType, typename ScrollbarLayerType> | 108 template <typename LayerType, typename ScrollbarLayerType> |
| 109 void updateScrollbarLayerPointersRecursiveInternal(const RawPtrLayerImplMap& new
Layers, LayerType* layer) | 109 void updateScrollbarLayerPointersRecursiveInternal(const RawPtrLayerImplMap& new
Layers, LayerType* layer) |
| 110 { | 110 { |
| 111 if (!layer) | 111 if (!layer) |
| 112 return; | 112 return; |
| 113 | 113 |
| 114 for (size_t i = 0; i < layer->children().size(); ++i) | 114 for (size_t i = 0; i < layer->children().size(); ++i) |
| 115 updateScrollbarLayerPointersRecursiveInternal<LayerType, ScrollbarLayerT
ype>(newLayers, layer->childAt(i)); | 115 updateScrollbarLayerPointersRecursiveInternal<LayerType, ScrollbarLayerT
ype>(newLayers, layer->child_at(i)); |
| 116 | 116 |
| 117 ScrollbarLayerType* scrollbarLayer = layer->toScrollbarLayer(); | 117 ScrollbarLayerType* scrollbarLayer = layer->ToScrollbarLayer(); |
| 118 if (!scrollbarLayer) | 118 if (!scrollbarLayer) |
| 119 return; | 119 return; |
| 120 | 120 |
| 121 RawPtrLayerImplMap::const_iterator iter = newLayers.find(scrollbarLayer->id(
)); | 121 RawPtrLayerImplMap::const_iterator iter = newLayers.find(scrollbarLayer->id(
)); |
| 122 ScrollbarLayerImpl* scrollbarLayerImpl = iter != newLayers.end() ? static_ca
st<ScrollbarLayerImpl*>(iter->second) : NULL; | 122 ScrollbarLayerImpl* scrollbarLayerImpl = iter != newLayers.end() ? static_ca
st<ScrollbarLayerImpl*>(iter->second) : NULL; |
| 123 iter = newLayers.find(scrollbarLayer->scroll_layer_id()); | 123 iter = newLayers.find(scrollbarLayer->scroll_layer_id()); |
| 124 LayerImpl* scrollLayerImpl = iter != newLayers.end() ? iter->second : NULL; | 124 LayerImpl* scrollLayerImpl = iter != newLayers.end() ? iter->second : NULL; |
| 125 | 125 |
| 126 DCHECK(scrollbarLayerImpl); | 126 DCHECK(scrollbarLayerImpl); |
| 127 DCHECK(scrollLayerImpl); | 127 DCHECK(scrollLayerImpl); |
| 128 | 128 |
| 129 if (scrollbarLayer->Orientation() == WebKit::WebScrollbar::Horizontal) | 129 if (scrollbarLayer->Orientation() == WebKit::WebScrollbar::Horizontal) |
| 130 scrollLayerImpl->setHorizontalScrollbarLayer(scrollbarLayerImpl); | 130 scrollLayerImpl->SetHorizontalScrollbarLayer(scrollbarLayerImpl); |
| 131 else | 131 else |
| 132 scrollLayerImpl->setVerticalScrollbarLayer(scrollbarLayerImpl); | 132 scrollLayerImpl->SetVerticalScrollbarLayer(scrollbarLayerImpl); |
| 133 } | 133 } |
| 134 | 134 |
| 135 void updateScrollbarLayerPointersRecursive(const RawPtrLayerImplMap& newLayers,
Layer* layer) | 135 void updateScrollbarLayerPointersRecursive(const RawPtrLayerImplMap& newLayers,
Layer* layer) |
| 136 { | 136 { |
| 137 updateScrollbarLayerPointersRecursiveInternal<Layer, ScrollbarLayer>(newLaye
rs, layer); | 137 updateScrollbarLayerPointersRecursiveInternal<Layer, ScrollbarLayer>(newLaye
rs, layer); |
| 138 } | 138 } |
| 139 | 139 |
| 140 void updateScrollbarLayerPointersRecursive(const RawPtrLayerImplMap& newLayers,
LayerImpl* layer) | 140 void updateScrollbarLayerPointersRecursive(const RawPtrLayerImplMap& newLayers,
LayerImpl* layer) |
| 141 { | 141 { |
| 142 updateScrollbarLayerPointersRecursiveInternal<LayerImpl, ScrollbarLayerImpl>
(newLayers, layer); | 142 updateScrollbarLayerPointersRecursiveInternal<LayerImpl, ScrollbarLayerImpl>
(newLayers, layer); |
| 143 } | 143 } |
| 144 | 144 |
| 145 template <typename LayerType> | 145 template <typename LayerType> |
| 146 void pushPropertiesInternal(LayerType* layer, LayerImpl* layerImpl) | 146 void pushPropertiesInternal(LayerType* layer, LayerImpl* layerImpl) |
| 147 { | 147 { |
| 148 if (!layer) { | 148 if (!layer) { |
| 149 DCHECK(!layerImpl); | 149 DCHECK(!layerImpl); |
| 150 return; | 150 return; |
| 151 } | 151 } |
| 152 | 152 |
| 153 DCHECK_EQ(layer->id(), layerImpl->id()); | 153 DCHECK_EQ(layer->id(), layerImpl->id()); |
| 154 layer->pushPropertiesTo(layerImpl); | 154 layer->PushPropertiesTo(layerImpl); |
| 155 | 155 |
| 156 pushPropertiesInternal(layer->maskLayer(), layerImpl->maskLayer()); | 156 pushPropertiesInternal(layer->mask_layer(), layerImpl->mask_layer()); |
| 157 pushPropertiesInternal(layer->replicaLayer(), layerImpl->replicaLayer()); | 157 pushPropertiesInternal(layer->replica_layer(), layerImpl->replica_layer()); |
| 158 | 158 |
| 159 const ScopedPtrVector<LayerImpl>& implChildren = layerImpl->children(); | 159 const ScopedPtrVector<LayerImpl>& implChildren = layerImpl->children(); |
| 160 DCHECK_EQ(layer->children().size(), implChildren.size()); | 160 DCHECK_EQ(layer->children().size(), implChildren.size()); |
| 161 | 161 |
| 162 for (size_t i = 0; i < layer->children().size(); ++i) { | 162 for (size_t i = 0; i < layer->children().size(); ++i) { |
| 163 pushPropertiesInternal(layer->childAt(i), implChildren[i]); | 163 pushPropertiesInternal(layer->child_at(i), implChildren[i]); |
| 164 } | 164 } |
| 165 } | 165 } |
| 166 | 166 |
| 167 void TreeSynchronizer::pushProperties(Layer* layer, LayerImpl* layerImpl) | 167 void TreeSynchronizer::pushProperties(Layer* layer, LayerImpl* layerImpl) |
| 168 { | 168 { |
| 169 pushPropertiesInternal(layer, layerImpl); | 169 pushPropertiesInternal(layer, layerImpl); |
| 170 } | 170 } |
| 171 | 171 |
| 172 void TreeSynchronizer::pushProperties(LayerImpl* layer, LayerImpl* layerImpl) | 172 void TreeSynchronizer::pushProperties(LayerImpl* layer, LayerImpl* layerImpl) |
| 173 { | 173 { |
| 174 pushPropertiesInternal(layer, layerImpl); | 174 pushPropertiesInternal(layer, layerImpl); |
| 175 } | 175 } |
| 176 | 176 |
| 177 | 177 |
| 178 } // namespace cc | 178 } // namespace cc |
| OLD | NEW |