Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: cc/tree_synchronizer.cc

Issue 11882037: Activate LayerImpl tree with sync+push instead of pointer swap (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/tree_synchronizer.h ('k') | cc/tree_synchronizer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 scoped_ptr<LayerImpl> TreeSynchronizer::synchronizeTrees(Layer* layerRoot, scope d_ptr<LayerImpl> oldLayerImplRoot, LayerTreeImpl* treeImpl) 17 typedef ScopedPtrHashMap<int, LayerImpl> ScopedPtrLayerImplMap;
18 typedef base::hash_map<int, LayerImpl*> RawPtrLayerImplMap;
19
20 void collectExistingLayerImplRecursive(ScopedPtrLayerImplMap& oldLayers, scoped_ ptr<LayerImpl> layerImpl)
21 {
22 if (!layerImpl)
23 return;
24
25 ScopedPtrVector<LayerImpl>& children = layerImpl->children();
26 for (ScopedPtrVector<LayerImpl>::iterator it = children.begin(); it != child ren.end(); ++it)
27 collectExistingLayerImplRecursive(oldLayers, children.take(it));
28
29 collectExistingLayerImplRecursive(oldLayers, layerImpl->takeMaskLayer());
30 collectExistingLayerImplRecursive(oldLayers, layerImpl->takeReplicaLayer());
31
32 int id = layerImpl->id();
33 oldLayers.set(id, layerImpl.Pass());
34 }
35
36 template <typename LayerType>
37 scoped_ptr<LayerImpl> synchronizeTreesInternal(LayerType* layerRoot, scoped_ptr< LayerImpl> oldLayerImplRoot, LayerTreeImpl* treeImpl)
18 { 38 {
19 DCHECK(treeImpl); 39 DCHECK(treeImpl);
20 40
21 TRACE_EVENT0("cc", "TreeSynchronizer::synchronizeTrees"); 41 TRACE_EVENT0("cc", "TreeSynchronizer::synchronizeTrees");
22 ScopedPtrLayerImplMap oldLayers; 42 ScopedPtrLayerImplMap oldLayers;
23 RawPtrLayerImplMap newLayers; 43 RawPtrLayerImplMap newLayers;
24 44
25 collectExistingLayerImplRecursive(oldLayers, oldLayerImplRoot.Pass()); 45 collectExistingLayerImplRecursive(oldLayers, oldLayerImplRoot.Pass());
26 46
27 scoped_ptr<LayerImpl> newTree = synchronizeTreeRecursive(newLayers, oldLayer s, layerRoot, treeImpl); 47 scoped_ptr<LayerImpl> newTree = synchronizeTreesRecursive(newLayers, oldLaye rs, layerRoot, treeImpl);
28 48
29 updateScrollbarLayerPointersRecursive(newLayers, layerRoot); 49 updateScrollbarLayerPointersRecursive(newLayers, layerRoot);
30 50
31 return newTree.Pass(); 51 return newTree.Pass();
32 } 52 }
33 53
34 void TreeSynchronizer::collectExistingLayerImplRecursive(ScopedPtrLayerImplMap& oldLayers, scoped_ptr<LayerImpl> layerImpl) 54 scoped_ptr<LayerImpl> TreeSynchronizer::synchronizeTrees(Layer* layerRoot, scope d_ptr<LayerImpl> oldLayerImplRoot, LayerTreeImpl* treeImpl)
35 { 55 {
36 if (!layerImpl) 56 return synchronizeTreesInternal(layerRoot, oldLayerImplRoot.Pass(), treeImpl );
37 return;
38
39 ScopedPtrVector<LayerImpl>& children = layerImpl->m_children;
40 for (ScopedPtrVector<LayerImpl>::iterator it = children.begin(); it != child ren.end(); ++it)
41 collectExistingLayerImplRecursive(oldLayers, children.take(it));
42
43 collectExistingLayerImplRecursive(oldLayers, layerImpl->takeMaskLayer());
44 collectExistingLayerImplRecursive(oldLayers, layerImpl->takeReplicaLayer());
45
46 int id = layerImpl->id();
47 oldLayers.set(id, layerImpl.Pass());
48 } 57 }
49 58
50 scoped_ptr<LayerImpl> TreeSynchronizer::reuseOrCreateLayerImpl(RawPtrLayerImplMa p& newLayers, ScopedPtrLayerImplMap& oldLayers, Layer* layer, LayerTreeImpl* tre eImpl) 59 scoped_ptr<LayerImpl> TreeSynchronizer::synchronizeTrees(LayerImpl* layerRoot, s coped_ptr<LayerImpl> oldLayerImplRoot, LayerTreeImpl* treeImpl)
60 {
61 return synchronizeTreesInternal(layerRoot, oldLayerImplRoot.Pass(), treeImpl );
62 }
63
64 template <typename LayerType>
65 scoped_ptr<LayerImpl> reuseOrCreateLayerImpl(RawPtrLayerImplMap& newLayers, Scop edPtrLayerImplMap& oldLayers, LayerType* layer, LayerTreeImpl* treeImpl)
51 { 66 {
52 scoped_ptr<LayerImpl> layerImpl = oldLayers.take(layer->id()); 67 scoped_ptr<LayerImpl> layerImpl = oldLayers.take(layer->id());
53 68
54 if (!layerImpl) 69 if (!layerImpl)
55 layerImpl = layer->createLayerImpl(treeImpl); 70 layerImpl = layer->createLayerImpl(treeImpl);
56 71
57 newLayers[layer->id()] = layerImpl.get(); 72 newLayers[layer->id()] = layerImpl.get();
58 return layerImpl.Pass(); 73 return layerImpl.Pass();
59 } 74 }
60 75
61 scoped_ptr<LayerImpl> TreeSynchronizer::synchronizeTreeRecursive(RawPtrLayerImpl Map& newLayers, ScopedPtrLayerImplMap& oldLayers, Layer* layer, LayerTreeImpl* t reeImpl) 76 template <typename LayerType>
77 scoped_ptr<LayerImpl> synchronizeTreesRecursiveInternal(RawPtrLayerImplMap& newL ayers, ScopedPtrLayerImplMap& oldLayers, LayerType* layer, LayerTreeImpl* treeIm pl)
62 { 78 {
63 if (!layer) 79 if (!layer)
64 return scoped_ptr<LayerImpl>(); 80 return scoped_ptr<LayerImpl>();
65 81
66 scoped_ptr<LayerImpl> layerImpl = reuseOrCreateLayerImpl(newLayers, oldLayer s, layer, treeImpl); 82 scoped_ptr<LayerImpl> layerImpl = reuseOrCreateLayerImpl(newLayers, oldLayer s, layer, treeImpl);
67 83
68 layerImpl->clearChildList(); 84 layerImpl->clearChildList();
69 const std::vector<scoped_refptr<Layer> >& children = layer->children(); 85 for (size_t i = 0; i < layer->children().size(); ++i)
70 for (size_t i = 0; i < children.size(); ++i) 86 layerImpl->addChild(synchronizeTreesRecursiveInternal(newLayers, oldLaye rs, layer->childAt(i), treeImpl));
71 layerImpl->addChild(synchronizeTreeRecursive(newLayers, oldLayers, child ren[i].get(), treeImpl));
72 87
73 layerImpl->setMaskLayer(synchronizeTreeRecursive(newLayers, oldLayers, layer ->maskLayer(), treeImpl)); 88 layerImpl->setMaskLayer(synchronizeTreesRecursiveInternal(newLayers, oldLaye rs, layer->maskLayer(), treeImpl));
74 layerImpl->setReplicaLayer(synchronizeTreeRecursive(newLayers, oldLayers, la yer->replicaLayer(), treeImpl)); 89 layerImpl->setReplicaLayer(synchronizeTreesRecursiveInternal(newLayers, oldL ayers, layer->replicaLayer(), treeImpl));
75 90
76 // 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
77 layerImpl->setHorizontalScrollbarLayer(0); 92 layerImpl->setHorizontalScrollbarLayer(0);
78 layerImpl->setVerticalScrollbarLayer(0); 93 layerImpl->setVerticalScrollbarLayer(0);
79 94
80 return layerImpl.Pass(); 95 return layerImpl.Pass();
81 } 96 }
82 97
83 void TreeSynchronizer::updateScrollbarLayerPointersRecursive(const RawPtrLayerIm plMap& newLayers, Layer* layer) 98 scoped_ptr<LayerImpl> synchronizeTreesRecursive(RawPtrLayerImplMap& newLayers, S copedPtrLayerImplMap& oldLayers, Layer* layer, LayerTreeImpl* treeImpl)
99 {
100 return synchronizeTreesRecursiveInternal(newLayers, oldLayers, layer, treeIm pl);
101 }
102
103 scoped_ptr<LayerImpl> synchronizeTreesRecursive(RawPtrLayerImplMap& newLayers, S copedPtrLayerImplMap& oldLayers, LayerImpl* layer, LayerTreeImpl* treeImpl)
104 {
105 return synchronizeTreesRecursiveInternal(newLayers, oldLayers, layer, treeIm pl);
106 }
107
108 template <typename LayerType, typename ScrollbarLayerType>
109 void updateScrollbarLayerPointersRecursiveInternal(const RawPtrLayerImplMap& new Layers, LayerType* layer)
84 { 110 {
85 if (!layer) 111 if (!layer)
86 return; 112 return;
87 113
88 const std::vector<scoped_refptr<Layer> >& children = layer->children(); 114 for (size_t i = 0; i < layer->children().size(); ++i)
89 for (size_t i = 0; i < children.size(); ++i) 115 updateScrollbarLayerPointersRecursiveInternal<LayerType, ScrollbarLayerT ype>(newLayers, layer->childAt(i));
90 updateScrollbarLayerPointersRecursive(newLayers, children[i].get());
91 116
92 ScrollbarLayer* scrollbarLayer = layer->toScrollbarLayer(); 117 ScrollbarLayerType* scrollbarLayer = layer->toScrollbarLayer();
93 if (!scrollbarLayer) 118 if (!scrollbarLayer)
94 return; 119 return;
95 120
96 RawPtrLayerImplMap::const_iterator iter = newLayers.find(scrollbarLayer->id( )); 121 RawPtrLayerImplMap::const_iterator iter = newLayers.find(scrollbarLayer->id( ));
97 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;
98 iter = newLayers.find(scrollbarLayer->scrollLayerId()); 123 iter = newLayers.find(scrollbarLayer->scrollLayerId());
99 LayerImpl* scrollLayerImpl = iter != newLayers.end() ? iter->second : NULL; 124 LayerImpl* scrollLayerImpl = iter != newLayers.end() ? iter->second : NULL;
100 125
101 DCHECK(scrollbarLayerImpl); 126 DCHECK(scrollbarLayerImpl);
102 DCHECK(scrollLayerImpl); 127 DCHECK(scrollLayerImpl);
103 128
104 if (scrollbarLayer->orientation() == WebKit::WebScrollbar::Horizontal) 129 if (scrollbarLayer->orientation() == WebKit::WebScrollbar::Horizontal)
105 scrollLayerImpl->setHorizontalScrollbarLayer(scrollbarLayerImpl); 130 scrollLayerImpl->setHorizontalScrollbarLayer(scrollbarLayerImpl);
106 else 131 else
107 scrollLayerImpl->setVerticalScrollbarLayer(scrollbarLayerImpl); 132 scrollLayerImpl->setVerticalScrollbarLayer(scrollbarLayerImpl);
108 } 133 }
109 134
110 void TreeSynchronizer::pushProperties(Layer* layer, LayerImpl* layerImpl) 135 void updateScrollbarLayerPointersRecursive(const RawPtrLayerImplMap& newLayers, Layer* layer)
136 {
137 updateScrollbarLayerPointersRecursiveInternal<Layer, ScrollbarLayer>(newLaye rs, layer);
138 }
139
140 void updateScrollbarLayerPointersRecursive(const RawPtrLayerImplMap& newLayers, LayerImpl* layer)
141 {
142 updateScrollbarLayerPointersRecursiveInternal<LayerImpl, ScrollbarLayerImpl> (newLayers, layer);
143 }
144
145 template <typename LayerType>
146 void pushPropertiesInternal(LayerType* layer, LayerImpl* layerImpl)
111 { 147 {
112 if (!layer) { 148 if (!layer) {
113 DCHECK(!layerImpl); 149 DCHECK(!layerImpl);
114 return; 150 return;
115 } 151 }
116 152
117 DCHECK_EQ(layer->id(), layerImpl->id()); 153 DCHECK_EQ(layer->id(), layerImpl->id());
118 layer->pushPropertiesTo(layerImpl); 154 layer->pushPropertiesTo(layerImpl);
119 155
120 pushProperties(layer->maskLayer(), layerImpl->maskLayer()); 156 pushPropertiesInternal(layer->maskLayer(), layerImpl->maskLayer());
121 pushProperties(layer->replicaLayer(), layerImpl->replicaLayer()); 157 pushPropertiesInternal(layer->replicaLayer(), layerImpl->replicaLayer());
122 158
123 const std::vector<scoped_refptr<Layer> >& children = layer->children();
124 const ScopedPtrVector<LayerImpl>& implChildren = layerImpl->children(); 159 const ScopedPtrVector<LayerImpl>& implChildren = layerImpl->children();
125 DCHECK_EQ(children.size(), implChildren.size()); 160 DCHECK_EQ(layer->children().size(), implChildren.size());
126 161
127 for (size_t i = 0; i < children.size(); ++i) { 162 for (size_t i = 0; i < layer->children().size(); ++i) {
128 pushProperties(children[i].get(), implChildren[i]); 163 pushPropertiesInternal(layer->childAt(i), implChildren[i]);
129 } 164 }
130 } 165 }
131 166
167 void TreeSynchronizer::pushProperties(Layer* layer, LayerImpl* layerImpl)
168 {
169 pushPropertiesInternal(layer, layerImpl);
170 }
171
172 void TreeSynchronizer::pushProperties(LayerImpl* layer, LayerImpl* layerImpl)
173 {
174 pushPropertiesInternal(layer, layerImpl);
175 }
176
177
132 } // namespace cc 178 } // namespace cc
OLDNEW
« no previous file with comments | « cc/tree_synchronizer.h ('k') | cc/tree_synchronizer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698