Chromium Code Reviews| 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/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> |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 | 122 |
| 123 scoped_ptr<LayerImpl> SynchronizeTreesRecursive( | 123 scoped_ptr<LayerImpl> SynchronizeTreesRecursive( |
| 124 RawPtrLayerImplMap* new_layers, | 124 RawPtrLayerImplMap* new_layers, |
| 125 ScopedPtrLayerImplMap* old_layers, | 125 ScopedPtrLayerImplMap* old_layers, |
| 126 LayerImpl* layer, | 126 LayerImpl* layer, |
| 127 LayerTreeImpl* tree_impl) { | 127 LayerTreeImpl* tree_impl) { |
| 128 return SynchronizeTreesRecursiveInternal( | 128 return SynchronizeTreesRecursiveInternal( |
| 129 new_layers, old_layers, layer, tree_impl); | 129 new_layers, old_layers, layer, tree_impl); |
| 130 } | 130 } |
| 131 | 131 |
| 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, | |
|
ajuma
2016/03/18 14:33:16
This checks are pretty useful. It'd be nice to kee
jaydasika
2016/03/19 02:17:58
Done.
| |
| 182 LayerImpl* layer_impl) { | |
| 183 DCHECK_EQ(!!layer, !!layer_impl); | |
| 184 if (!layer) | |
| 185 return; | |
| 186 | |
| 187 // 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 | |
| 189 // 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 | |
| 191 // scroll/clip children. | |
| 192 DCHECK(!layer_impl->scroll_parent() || !!layer->scroll_parent()); | |
| 193 DCHECK(!layer_impl->clip_parent() || !!layer->clip_parent()); | |
| 194 DCHECK(!layer_impl->scroll_children() || !!layer->scroll_children()); | |
| 195 DCHECK(!layer_impl->clip_children() || !!layer->clip_children()); | |
| 196 | |
| 197 if (layer_impl->scroll_parent()) | |
| 198 DCHECK_EQ(layer->scroll_parent()->id(), layer_impl->scroll_parent()->id()); | |
| 199 | |
| 200 if (layer_impl->clip_parent()) | |
| 201 DCHECK_EQ(layer->clip_parent()->id(), layer_impl->clip_parent()->id()); | |
| 202 | |
| 203 if (layer_impl->scroll_children()) { | |
| 204 for (std::set<Layer*>::iterator it = layer->scroll_children()->begin(); | |
| 205 it != layer->scroll_children()->end(); | |
| 206 ++it) { | |
| 207 DCHECK_EQ((*it)->scroll_parent(), layer); | |
| 208 } | |
| 209 for (std::set<LayerImpl*>::iterator it = | |
| 210 layer_impl->scroll_children()->begin(); | |
| 211 it != layer_impl->scroll_children()->end(); | |
| 212 ++it) { | |
| 213 DCHECK_EQ((*it)->scroll_parent(), layer_impl); | |
| 214 } | |
| 215 } | |
| 216 | |
| 217 if (layer_impl->clip_children()) { | |
| 218 for (std::set<Layer*>::iterator it = layer->clip_children()->begin(); | |
| 219 it != layer->clip_children()->end(); | |
| 220 ++it) { | |
| 221 DCHECK_EQ((*it)->clip_parent(), layer); | |
| 222 } | |
| 223 for (std::set<LayerImpl*>::iterator it = | |
| 224 layer_impl->clip_children()->begin(); | |
| 225 it != layer_impl->clip_children()->end(); | |
| 226 ++it) { | |
| 227 DCHECK_EQ((*it)->clip_parent(), layer_impl); | |
| 228 } | |
| 229 } | |
| 230 | |
| 231 for (size_t i = 0u; i < layer->children().size(); ++i) { | |
| 232 CheckScrollAndClipPointersRecursive(layer->child_at(i), | |
| 233 layer_impl->child_at(i)); | |
| 234 } | |
| 235 } | |
| 236 | |
| 237 void TreeSynchronizer::PushProperties(Layer* layer, | |
| 238 LayerImpl* layer_impl) { | |
| 239 int num_dependents_need_push_properties = 0; | |
| 240 PushPropertiesInternal( | |
| 241 layer, layer_impl, &num_dependents_need_push_properties); | |
| 242 #if DCHECK_IS_ON() | |
| 243 CheckScrollAndClipPointersRecursive(layer, layer_impl); | |
| 244 #endif | |
| 245 } | |
| 246 | |
| 247 } // namespace cc | 132 } // namespace cc |
| OLD | NEW |