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

Side by Side Diff: cc/trees/tree_synchronizer.cc

Issue 1808373002: cc : Make tree synchronization independent of layer tree hierarchy (2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « cc/trees/tree_synchronizer.h ('k') | cc/trees/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/trees/tree_synchronizer.h" 5 #include "cc/trees/tree_synchronizer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <set> 9 #include <set>
10 #include <unordered_map> 10 #include <unordered_map>
11 11
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/trace_event/trace_event.h" 13 #include "base/trace_event/trace_event.h"
14 #include "cc/layers/layer.h" 14 #include "cc/layers/layer.h"
15 #include "cc/layers/layer_impl.h" 15 #include "cc/layers/layer_impl.h"
16 #include "cc/trees/layer_tree_host.h"
17 #include "cc/trees/layer_tree_impl.h"
16 18
17 namespace cc { 19 namespace cc {
18 20
19 using ScopedPtrLayerImplMap = std::unordered_map<int, scoped_ptr<LayerImpl>>; 21 using ScopedPtrLayerImplMap = std::unordered_map<int, scoped_ptr<LayerImpl>>;
20 using RawPtrLayerImplMap = std::unordered_map<int, LayerImpl*>; 22 using RawPtrLayerImplMap = std::unordered_map<int, LayerImpl*>;
21 23
22 void CollectExistingLayerImplRecursive(ScopedPtrLayerImplMap* old_layers, 24 void CollectExistingLayerImplRecursive(ScopedPtrLayerImplMap* old_layers,
23 scoped_ptr<LayerImpl> layer_impl) { 25 scoped_ptr<LayerImpl> layer_impl) {
24 if (!layer_impl) 26 if (!layer_impl)
25 return; 27 return;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 124
123 scoped_ptr<LayerImpl> SynchronizeTreesRecursive( 125 scoped_ptr<LayerImpl> SynchronizeTreesRecursive(
124 RawPtrLayerImplMap* new_layers, 126 RawPtrLayerImplMap* new_layers,
125 ScopedPtrLayerImplMap* old_layers, 127 ScopedPtrLayerImplMap* old_layers,
126 LayerImpl* layer, 128 LayerImpl* layer,
127 LayerTreeImpl* tree_impl) { 129 LayerTreeImpl* tree_impl) {
128 return SynchronizeTreesRecursiveInternal( 130 return SynchronizeTreesRecursiveInternal(
129 new_layers, old_layers, layer, tree_impl); 131 new_layers, old_layers, layer, tree_impl);
130 } 132 }
131 133
132 void TreeSynchronizer::PushPropertiesInternal(
133 Layer* layer,
134 LayerImpl* layer_impl,
135 int* num_dependents_need_push_properties_for_parent) {
136 if (!layer) {
137 DCHECK(!layer_impl);
138 return;
139 }
140
141 DCHECK_EQ(layer->id(), layer_impl->id());
142
143 bool push_layer = layer->needs_push_properties();
144 bool recurse_on_children_and_dependents =
145 layer->descendant_needs_push_properties();
146
147 if (push_layer)
148 layer->PushPropertiesTo(layer_impl);
149
150 int num_dependents_need_push_properties = 0;
151 if (recurse_on_children_and_dependents) {
152 PushPropertiesInternal(layer->mask_layer(),
153 layer_impl->mask_layer(),
154 &num_dependents_need_push_properties);
155 PushPropertiesInternal(layer->replica_layer(),
156 layer_impl->replica_layer(),
157 &num_dependents_need_push_properties);
158
159 const OwnedLayerImplList& impl_children = layer_impl->children();
160 DCHECK_EQ(layer->children().size(), impl_children.size());
161
162 for (size_t i = 0; i < layer->children().size(); ++i) {
163 PushPropertiesInternal(layer->child_at(i), impl_children[i].get(),
164 &num_dependents_need_push_properties);
165 }
166
167 // When PushPropertiesTo completes for a layer, it may still keep
168 // its needs_push_properties() state if the layer must push itself
169 // every PushProperties tree walk. Here we keep track of those layers, and
170 // ensure that their ancestors know about them for the next PushProperties
171 // tree walk.
172 layer->num_dependents_need_push_properties_ =
173 num_dependents_need_push_properties;
174 }
175
176 bool add_self_to_parent = num_dependents_need_push_properties > 0 ||
177 layer->needs_push_properties();
178 *num_dependents_need_push_properties_for_parent += add_self_to_parent ? 1 : 0;
179 }
180
181 static void CheckScrollAndClipPointersRecursive(Layer* layer, 134 static void CheckScrollAndClipPointersRecursive(Layer* layer,
182 LayerImpl* layer_impl) { 135 LayerImpl* layer_impl) {
183 DCHECK_EQ(!!layer, !!layer_impl); 136 DCHECK_EQ(!!layer, !!layer_impl);
184 if (!layer) 137 if (!layer)
185 return; 138 return;
186 139
187 // Having a scroll parent on the impl thread implies having one the main 140 // Having a scroll parent on the impl thread implies having one the main
188 // thread, too. The main thread may have a scroll parent that is not in the 141 // thread, too. The main thread may have a scroll parent that is not in the
189 // tree because it's been removed but not deleted. In this case, the layer 142 // tree because it's been removed but not deleted. In this case, the layer
190 // impl will have no scroll parent. Same argument applies for clip parents and 143 // impl will have no scroll parent. Same argument applies for clip parents and
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 DCHECK_EQ((*it)->clip_parent(), layer_impl); 180 DCHECK_EQ((*it)->clip_parent(), layer_impl);
228 } 181 }
229 } 182 }
230 183
231 for (size_t i = 0u; i < layer->children().size(); ++i) { 184 for (size_t i = 0u; i < layer->children().size(); ++i) {
232 CheckScrollAndClipPointersRecursive(layer->child_at(i), 185 CheckScrollAndClipPointersRecursive(layer->child_at(i),
233 layer_impl->child_at(i)); 186 layer_impl->child_at(i));
234 } 187 }
235 } 188 }
236 189
237 void TreeSynchronizer::PushProperties(Layer* layer, 190 template <typename LayerType>
238 LayerImpl* layer_impl) { 191 static void PushLayerPropertiesInternal(
239 int num_dependents_need_push_properties = 0; 192 std::unordered_set<LayerType*> layers_that_should_push_properties,
240 PushPropertiesInternal( 193 LayerTreeImpl* impl_tree) {
241 layer, layer_impl, &num_dependents_need_push_properties); 194 for (auto layer : layers_that_should_push_properties) {
195 LayerImpl* layer_impl = impl_tree->LayerById(layer->id());
196 DCHECK(layer_impl);
197 layer->PushPropertiesTo(layer_impl);
198 }
199 }
200
201 void TreeSynchronizer::PushLayerProperties(LayerTreeImpl* pending_tree,
202 LayerTreeImpl* active_tree) {
203 PushLayerPropertiesInternal(pending_tree->LayersThatShouldPushProperties(),
204 active_tree);
205 }
206
207 void TreeSynchronizer::PushLayerProperties(LayerTreeHost* host_tree,
208 LayerTreeImpl* impl_tree) {
209 PushLayerPropertiesInternal(host_tree->LayersThatShouldPushProperties(),
210 impl_tree);
211
242 #if DCHECK_IS_ON() 212 #if DCHECK_IS_ON()
243 CheckScrollAndClipPointersRecursive(layer, layer_impl); 213 if (host_tree->root_layer() && impl_tree->root_layer())
214 CheckScrollAndClipPointersRecursive(host_tree->root_layer(),
215 impl_tree->root_layer());
244 #endif 216 #endif
245 } 217 }
246 218
247 } // namespace cc 219 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/tree_synchronizer.h ('k') | cc/trees/tree_synchronizer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698