| 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "cc/tree_synchronizer.h" | 7 #include "cc/tree_synchronizer.h" |
| 8 | 8 |
| 9 #include "CCLayerImpl.h" | 9 #include "CCLayerImpl.h" |
| 10 #include "CCScrollbarAnimationController.h" | 10 #include "CCScrollbarAnimationController.h" |
| 11 #include "CCScrollbarLayerImpl.h" | 11 #include "CCScrollbarLayerImpl.h" |
| 12 #include "cc/layer.h" | 12 #include "cc/layer.h" |
| 13 #include "cc/scrollbar_layer.h" | 13 #include "cc/scrollbar_layer.h" |
| 14 | 14 |
| 15 namespace cc { | 15 namespace cc { |
| 16 | 16 |
| 17 scoped_ptr<CCLayerImpl> TreeSynchronizer::synchronizeTrees(LayerChromium* layerC
hromiumRoot, scoped_ptr<CCLayerImpl> oldCCLayerImplRoot, CCLayerTreeHostImpl* ho
stImpl) | 17 scoped_ptr<LayerImpl> TreeSynchronizer::synchronizeTrees(Layer* layerRoot, scope
d_ptr<LayerImpl> oldLayerImplRoot, LayerTreeHostImpl* hostImpl) |
| 18 { | 18 { |
| 19 ScopedPtrCCLayerImplMap oldLayers; | 19 ScopedPtrLayerImplMap oldLayers; |
| 20 RawPtrCCLayerImplMap newLayers; | 20 RawPtrLayerImplMap newLayers; |
| 21 | 21 |
| 22 collectExistingCCLayerImplRecursive(oldLayers, oldCCLayerImplRoot.Pass()); | 22 collectExistingLayerImplRecursive(oldLayers, oldLayerImplRoot.Pass()); |
| 23 | 23 |
| 24 scoped_ptr<CCLayerImpl> newTree = synchronizeTreeRecursive(newLayers, oldLay
ers, layerChromiumRoot, hostImpl); | 24 scoped_ptr<LayerImpl> newTree = synchronizeTreeRecursive(newLayers, oldLayer
s, layerRoot, hostImpl); |
| 25 | 25 |
| 26 updateScrollbarLayerPointersRecursive(newLayers, layerChromiumRoot); | 26 updateScrollbarLayerPointersRecursive(newLayers, layerRoot); |
| 27 | 27 |
| 28 return newTree.Pass(); | 28 return newTree.Pass(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 void TreeSynchronizer::collectExistingCCLayerImplRecursive(ScopedPtrCCLayerImplM
ap& oldLayers, scoped_ptr<CCLayerImpl> ccLayerImpl) | 31 void TreeSynchronizer::collectExistingLayerImplRecursive(ScopedPtrLayerImplMap&
oldLayers, scoped_ptr<LayerImpl> layerImpl) |
| 32 { | 32 { |
| 33 if (!ccLayerImpl) | 33 if (!layerImpl) |
| 34 return; | 34 return; |
| 35 | 35 |
| 36 ScopedPtrVector<CCLayerImpl>& children = ccLayerImpl->m_children; | 36 ScopedPtrVector<LayerImpl>& children = layerImpl->m_children; |
| 37 for (size_t i = 0; i < children.size(); ++i) | 37 for (size_t i = 0; i < children.size(); ++i) |
| 38 collectExistingCCLayerImplRecursive(oldLayers, children.take(i)); | 38 collectExistingLayerImplRecursive(oldLayers, children.take(i)); |
| 39 | 39 |
| 40 collectExistingCCLayerImplRecursive(oldLayers, ccLayerImpl->m_maskLayer.Pass
()); | 40 collectExistingLayerImplRecursive(oldLayers, layerImpl->m_maskLayer.Pass()); |
| 41 collectExistingCCLayerImplRecursive(oldLayers, ccLayerImpl->m_replicaLayer.P
ass()); | 41 collectExistingLayerImplRecursive(oldLayers, layerImpl->m_replicaLayer.Pass(
)); |
| 42 | 42 |
| 43 int id = ccLayerImpl->id(); | 43 int id = layerImpl->id(); |
| 44 oldLayers.set(id, ccLayerImpl.Pass()); | 44 oldLayers.set(id, layerImpl.Pass()); |
| 45 } | 45 } |
| 46 | 46 |
| 47 scoped_ptr<CCLayerImpl> TreeSynchronizer::reuseOrCreateCCLayerImpl(RawPtrCCLayer
ImplMap& newLayers, ScopedPtrCCLayerImplMap& oldLayers, LayerChromium* layer) | 47 scoped_ptr<LayerImpl> TreeSynchronizer::reuseOrCreateLayerImpl(RawPtrLayerImplMa
p& newLayers, ScopedPtrLayerImplMap& oldLayers, Layer* layer) |
| 48 { | 48 { |
| 49 scoped_ptr<CCLayerImpl> ccLayerImpl = oldLayers.take(layer->id()); | 49 scoped_ptr<LayerImpl> layerImpl = oldLayers.take(layer->id()); |
| 50 | 50 |
| 51 if (!ccLayerImpl) | 51 if (!layerImpl) |
| 52 ccLayerImpl = layer->createCCLayerImpl(); | 52 layerImpl = layer->createLayerImpl(); |
| 53 | 53 |
| 54 newLayers[layer->id()] = ccLayerImpl.get(); | 54 newLayers[layer->id()] = layerImpl.get(); |
| 55 return ccLayerImpl.Pass(); | 55 return layerImpl.Pass(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 scoped_ptr<CCLayerImpl> TreeSynchronizer::synchronizeTreeRecursive(RawPtrCCLayer
ImplMap& newLayers, ScopedPtrCCLayerImplMap& oldLayers, LayerChromium* layer, CC
LayerTreeHostImpl* hostImpl) | 58 scoped_ptr<LayerImpl> TreeSynchronizer::synchronizeTreeRecursive(RawPtrLayerImpl
Map& newLayers, ScopedPtrLayerImplMap& oldLayers, Layer* layer, LayerTreeHostImp
l* hostImpl) |
| 59 { | 59 { |
| 60 if (!layer) | 60 if (!layer) |
| 61 return scoped_ptr<CCLayerImpl>(); | 61 return scoped_ptr<LayerImpl>(); |
| 62 | 62 |
| 63 scoped_ptr<CCLayerImpl> ccLayerImpl = reuseOrCreateCCLayerImpl(newLayers, ol
dLayers, layer); | 63 scoped_ptr<LayerImpl> layerImpl = reuseOrCreateLayerImpl(newLayers, oldLayer
s, layer); |
| 64 | 64 |
| 65 ccLayerImpl->clearChildList(); | 65 layerImpl->clearChildList(); |
| 66 const std::vector<scoped_refptr<LayerChromium> >& children = layer->children
(); | 66 const std::vector<scoped_refptr<Layer> >& children = layer->children(); |
| 67 for (size_t i = 0; i < children.size(); ++i) | 67 for (size_t i = 0; i < children.size(); ++i) |
| 68 ccLayerImpl->addChild(synchronizeTreeRecursive(newLayers, oldLayers, chi
ldren[i].get(), hostImpl)); | 68 layerImpl->addChild(synchronizeTreeRecursive(newLayers, oldLayers, child
ren[i].get(), hostImpl)); |
| 69 | 69 |
| 70 ccLayerImpl->setMaskLayer(synchronizeTreeRecursive(newLayers, oldLayers, lay
er->maskLayer(), hostImpl)); | 70 layerImpl->setMaskLayer(synchronizeTreeRecursive(newLayers, oldLayers, layer
->maskLayer(), hostImpl)); |
| 71 ccLayerImpl->setReplicaLayer(synchronizeTreeRecursive(newLayers, oldLayers,
layer->replicaLayer(), hostImpl)); | 71 layerImpl->setReplicaLayer(synchronizeTreeRecursive(newLayers, oldLayers, la
yer->replicaLayer(), hostImpl)); |
| 72 | 72 |
| 73 layer->pushPropertiesTo(ccLayerImpl.get()); | 73 layer->pushPropertiesTo(layerImpl.get()); |
| 74 ccLayerImpl->setLayerTreeHostImpl(hostImpl); | 74 layerImpl->setLayerTreeHostImpl(hostImpl); |
| 75 | 75 |
| 76 // Remove all dangling pointers. The pointers will be setup later in updateS
crollbarLayerPointersRecursive phase | 76 // Remove all dangling pointers. The pointers will be setup later in updateS
crollbarLayerPointersRecursive phase |
| 77 if (CCScrollbarAnimationController* scrollbarController = ccLayerImpl->scrol
lbarAnimationController()) { | 77 if (ScrollbarAnimationController* scrollbarController = layerImpl->scrollbar
AnimationController()) { |
| 78 scrollbarController->setHorizontalScrollbarLayer(0); | 78 scrollbarController->setHorizontalScrollbarLayer(0); |
| 79 scrollbarController->setVerticalScrollbarLayer(0); | 79 scrollbarController->setVerticalScrollbarLayer(0); |
| 80 } | 80 } |
| 81 | 81 |
| 82 return ccLayerImpl.Pass(); | 82 return layerImpl.Pass(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void TreeSynchronizer::updateScrollbarLayerPointersRecursive(const RawPtrCCLayer
ImplMap& newLayers, LayerChromium* layer) | 85 void TreeSynchronizer::updateScrollbarLayerPointersRecursive(const RawPtrLayerIm
plMap& newLayers, Layer* layer) |
| 86 { | 86 { |
| 87 if (!layer) | 87 if (!layer) |
| 88 return; | 88 return; |
| 89 | 89 |
| 90 const std::vector<scoped_refptr<LayerChromium> >& children = layer->children
(); | 90 const std::vector<scoped_refptr<Layer> >& children = layer->children(); |
| 91 for (size_t i = 0; i < children.size(); ++i) | 91 for (size_t i = 0; i < children.size(); ++i) |
| 92 updateScrollbarLayerPointersRecursive(newLayers, children[i].get()); | 92 updateScrollbarLayerPointersRecursive(newLayers, children[i].get()); |
| 93 | 93 |
| 94 ScrollbarLayerChromium* scrollbarLayer = layer->toScrollbarLayerChromium(); | 94 ScrollbarLayer* scrollbarLayer = layer->toScrollbarLayer(); |
| 95 if (!scrollbarLayer) | 95 if (!scrollbarLayer) |
| 96 return; | 96 return; |
| 97 | 97 |
| 98 RawPtrCCLayerImplMap::const_iterator iter = newLayers.find(scrollbarLayer->i
d()); | 98 RawPtrLayerImplMap::const_iterator iter = newLayers.find(scrollbarLayer->id(
)); |
| 99 CCScrollbarLayerImpl* ccScrollbarLayerImpl = iter != newLayers.end() ? stati
c_cast<CCScrollbarLayerImpl*>(iter->second) : NULL; | 99 ScrollbarLayerImpl* scrollbarLayerImpl = iter != newLayers.end() ? static_ca
st<ScrollbarLayerImpl*>(iter->second) : NULL; |
| 100 iter = newLayers.find(scrollbarLayer->scrollLayerId()); | 100 iter = newLayers.find(scrollbarLayer->scrollLayerId()); |
| 101 CCLayerImpl* ccScrollLayerImpl = iter != newLayers.end() ? iter->second : NU
LL; | 101 LayerImpl* scrollLayerImpl = iter != newLayers.end() ? iter->second : NULL; |
| 102 | 102 |
| 103 ASSERT(ccScrollbarLayerImpl); | 103 ASSERT(scrollbarLayerImpl); |
| 104 ASSERT(ccScrollLayerImpl); | 104 ASSERT(scrollLayerImpl); |
| 105 | 105 |
| 106 if (ccScrollbarLayerImpl->orientation() == WebKit::WebScrollbar::Horizontal) | 106 if (scrollbarLayerImpl->orientation() == WebKit::WebScrollbar::Horizontal) |
| 107 ccScrollLayerImpl->setHorizontalScrollbarLayer(ccScrollbarLayerImpl); | 107 scrollLayerImpl->setHorizontalScrollbarLayer(scrollbarLayerImpl); |
| 108 else | 108 else |
| 109 ccScrollLayerImpl->setVerticalScrollbarLayer(ccScrollbarLayerImpl); | 109 scrollLayerImpl->setVerticalScrollbarLayer(scrollbarLayerImpl); |
| 110 } | 110 } |
| 111 | 111 |
| 112 } // namespace cc | 112 } // namespace cc |
| OLD | NEW |