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 "cc/layer.h" | 8 #include "cc/layer.h" |
9 #include "cc/layer_impl.h" | 9 #include "cc/layer_impl.h" |
10 #include "cc/scrollbar_animation_controller.h" | 10 #include "cc/scrollbar_animation_controller.h" |
11 #include "cc/scrollbar_layer.h" | 11 #include "cc/scrollbar_layer.h" |
12 #include "cc/scrollbar_layer_impl.h" | 12 #include "cc/scrollbar_layer_impl.h" |
13 | 13 |
14 namespace cc { | 14 namespace cc { |
15 | 15 |
16 scoped_ptr<LayerImpl> TreeSynchronizer::synchronizeTrees(Layer* layerRoot, scope
d_ptr<LayerImpl> oldLayerImplRoot, LayerTreeHostImpl* hostImpl) | 16 scoped_ptr<LayerImpl> TreeSynchronizer::synchronizeTrees(Layer* layerRoot, scope
d_ptr<LayerImpl> oldLayerImplRoot, LayerTreeImpl* treeImpl) |
17 { | 17 { |
18 TRACE_EVENT0("cc", "TreeSynchronizer::synchronizeTrees"); | 18 TRACE_EVENT0("cc", "TreeSynchronizer::synchronizeTrees"); |
19 ScopedPtrLayerImplMap oldLayers; | 19 ScopedPtrLayerImplMap oldLayers; |
20 RawPtrLayerImplMap newLayers; | 20 RawPtrLayerImplMap newLayers; |
21 | 21 |
22 collectExistingLayerImplRecursive(oldLayers, oldLayerImplRoot.Pass()); | 22 collectExistingLayerImplRecursive(oldLayers, oldLayerImplRoot.Pass()); |
23 | 23 |
24 scoped_ptr<LayerImpl> newTree = synchronizeTreeRecursive(newLayers, oldLayer
s, layerRoot, hostImpl); | 24 scoped_ptr<LayerImpl> newTree = synchronizeTreeRecursive(newLayers, oldLayer
s, layerRoot, treeImpl); |
25 | 25 |
26 updateScrollbarLayerPointersRecursive(newLayers, layerRoot); | 26 updateScrollbarLayerPointersRecursive(newLayers, layerRoot); |
27 | 27 |
28 return newTree.Pass(); | 28 return newTree.Pass(); |
29 } | 29 } |
30 | 30 |
31 void TreeSynchronizer::collectExistingLayerImplRecursive(ScopedPtrLayerImplMap&
oldLayers, scoped_ptr<LayerImpl> layerImpl) | 31 void TreeSynchronizer::collectExistingLayerImplRecursive(ScopedPtrLayerImplMap&
oldLayers, scoped_ptr<LayerImpl> layerImpl) |
32 { | 32 { |
33 if (!layerImpl) | 33 if (!layerImpl) |
34 return; | 34 return; |
35 | 35 |
36 ScopedPtrVector<LayerImpl>& children = layerImpl->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 collectExistingLayerImplRecursive(oldLayers, children.take(i)); | 38 collectExistingLayerImplRecursive(oldLayers, children.take(i)); |
39 | 39 |
40 collectExistingLayerImplRecursive(oldLayers, layerImpl->m_maskLayer.Pass()); | 40 collectExistingLayerImplRecursive(oldLayers, layerImpl->m_maskLayer.Pass()); |
41 collectExistingLayerImplRecursive(oldLayers, layerImpl->m_replicaLayer.Pass(
)); | 41 collectExistingLayerImplRecursive(oldLayers, layerImpl->m_replicaLayer.Pass(
)); |
42 | 42 |
43 int id = layerImpl->id(); | 43 int id = layerImpl->id(); |
44 oldLayers.set(id, layerImpl.Pass()); | 44 oldLayers.set(id, layerImpl.Pass()); |
45 } | 45 } |
46 | 46 |
47 scoped_ptr<LayerImpl> TreeSynchronizer::reuseOrCreateLayerImpl(RawPtrLayerImplMa
p& newLayers, ScopedPtrLayerImplMap& oldLayers, Layer* layer, LayerTreeHostImpl*
hostImpl) | 47 scoped_ptr<LayerImpl> TreeSynchronizer::reuseOrCreateLayerImpl(RawPtrLayerImplMa
p& newLayers, ScopedPtrLayerImplMap& oldLayers, Layer* layer, LayerTreeImpl* tre
eImpl) |
48 { | 48 { |
49 scoped_ptr<LayerImpl> layerImpl = oldLayers.take(layer->id()); | 49 scoped_ptr<LayerImpl> layerImpl = oldLayers.take(layer->id()); |
50 | 50 |
51 if (!layerImpl) | 51 if (!layerImpl) |
52 layerImpl = layer->createLayerImpl(hostImpl); | 52 layerImpl = layer->createLayerImpl(treeImpl); |
53 | 53 |
54 newLayers[layer->id()] = layerImpl.get(); | 54 newLayers[layer->id()] = layerImpl.get(); |
55 return layerImpl.Pass(); | 55 return layerImpl.Pass(); |
56 } | 56 } |
57 | 57 |
58 scoped_ptr<LayerImpl> TreeSynchronizer::synchronizeTreeRecursive(RawPtrLayerImpl
Map& newLayers, ScopedPtrLayerImplMap& oldLayers, Layer* layer, LayerTreeHostImp
l* hostImpl) | 58 scoped_ptr<LayerImpl> TreeSynchronizer::synchronizeTreeRecursive(RawPtrLayerImpl
Map& newLayers, ScopedPtrLayerImplMap& oldLayers, Layer* layer, LayerTreeImpl* t
reeImpl) |
59 { | 59 { |
60 if (!layer) | 60 if (!layer) |
61 return scoped_ptr<LayerImpl>(); | 61 return scoped_ptr<LayerImpl>(); |
62 | 62 |
63 scoped_ptr<LayerImpl> layerImpl = reuseOrCreateLayerImpl(newLayers, oldLayer
s, layer, hostImpl); | 63 scoped_ptr<LayerImpl> layerImpl = reuseOrCreateLayerImpl(newLayers, oldLayer
s, layer, treeImpl); |
64 | 64 |
65 layerImpl->clearChildList(); | 65 layerImpl->clearChildList(); |
66 const std::vector<scoped_refptr<Layer> >& 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 layerImpl->addChild(synchronizeTreeRecursive(newLayers, oldLayers, child
ren[i].get(), hostImpl)); | 68 layerImpl->addChild(synchronizeTreeRecursive(newLayers, oldLayers, child
ren[i].get(), treeImpl)); |
69 | 69 |
70 layerImpl->setMaskLayer(synchronizeTreeRecursive(newLayers, oldLayers, layer
->maskLayer(), hostImpl)); | 70 layerImpl->setMaskLayer(synchronizeTreeRecursive(newLayers, oldLayers, layer
->maskLayer(), treeImpl)); |
71 layerImpl->setReplicaLayer(synchronizeTreeRecursive(newLayers, oldLayers, la
yer->replicaLayer(), hostImpl)); | 71 layerImpl->setReplicaLayer(synchronizeTreeRecursive(newLayers, oldLayers, la
yer->replicaLayer(), treeImpl)); |
72 | 72 |
73 layer->pushPropertiesTo(layerImpl.get()); | 73 layer->pushPropertiesTo(layerImpl.get()); |
74 | 74 |
75 // Remove all dangling pointers. The pointers will be setup later in updateS
crollbarLayerPointersRecursive phase | 75 // Remove all dangling pointers. The pointers will be setup later in updateS
crollbarLayerPointersRecursive phase |
76 if (ScrollbarAnimationController* scrollbarController = layerImpl->scrollbar
AnimationController()) { | 76 if (ScrollbarAnimationController* scrollbarController = layerImpl->scrollbar
AnimationController()) { |
77 scrollbarController->setHorizontalScrollbarLayer(0); | 77 scrollbarController->setHorizontalScrollbarLayer(0); |
78 scrollbarController->setVerticalScrollbarLayer(0); | 78 scrollbarController->setVerticalScrollbarLayer(0); |
79 } | 79 } |
80 | 80 |
81 return layerImpl.Pass(); | 81 return layerImpl.Pass(); |
(...skipping 20 matching lines...) Expand all Loading... |
102 DCHECK(scrollbarLayerImpl); | 102 DCHECK(scrollbarLayerImpl); |
103 DCHECK(scrollLayerImpl); | 103 DCHECK(scrollLayerImpl); |
104 | 104 |
105 if (scrollbarLayerImpl->orientation() == WebKit::WebScrollbar::Horizontal) | 105 if (scrollbarLayerImpl->orientation() == WebKit::WebScrollbar::Horizontal) |
106 scrollLayerImpl->setHorizontalScrollbarLayer(scrollbarLayerImpl); | 106 scrollLayerImpl->setHorizontalScrollbarLayer(scrollbarLayerImpl); |
107 else | 107 else |
108 scrollLayerImpl->setVerticalScrollbarLayer(scrollbarLayerImpl); | 108 scrollLayerImpl->setVerticalScrollbarLayer(scrollbarLayerImpl); |
109 } | 109 } |
110 | 110 |
111 } // namespace cc | 111 } // namespace cc |
OLD | NEW |