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

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

Issue 2829853009: cc : Add DCHECKs to ensure we have valid proprety tree indices at commit (Closed)
Patch Set: test failure and comments Created 3 years, 8 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.cc ('k') | no next file » | 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 <algorithm> 9 #include <algorithm>
10 #include <set> 10 #include <set>
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 } 158 }
159 159
160 // Constructs a very simple tree and synchronizes it without trying to reuse any 160 // Constructs a very simple tree and synchronizes it without trying to reuse any
161 // preexisting layers. 161 // preexisting layers.
162 TEST_F(TreeSynchronizerTest, SyncSimpleTreeFromEmpty) { 162 TEST_F(TreeSynchronizerTest, SyncSimpleTreeFromEmpty) {
163 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 163 scoped_refptr<Layer> layer_tree_root = Layer::Create();
164 layer_tree_root->AddChild(Layer::Create()); 164 layer_tree_root->AddChild(Layer::Create());
165 layer_tree_root->AddChild(Layer::Create()); 165 layer_tree_root->AddChild(Layer::Create());
166 166
167 host_->SetRootLayer(layer_tree_root); 167 host_->SetRootLayer(layer_tree_root);
168 host_->BuildPropertyTreesForTesting();
168 169
169 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), 170 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
170 host_->active_tree()); 171 host_->active_tree());
171 172
172 ExpectTreesAreIdentical(layer_tree_root.get(), 173 ExpectTreesAreIdentical(layer_tree_root.get(),
173 host_->active_tree()->root_layer_for_testing(), 174 host_->active_tree()->root_layer_for_testing(),
174 host_->active_tree()); 175 host_->active_tree());
175 } 176 }
176 177
177 // Constructs a very simple tree and synchronizes it attempting to reuse some 178 // Constructs a very simple tree and synchronizes it attempting to reuse some
178 // layers 179 // layers
179 TEST_F(TreeSynchronizerTest, SyncSimpleTreeReusingLayers) { 180 TEST_F(TreeSynchronizerTest, SyncSimpleTreeReusingLayers) {
180 std::vector<int> layer_impl_destruction_list; 181 std::vector<int> layer_impl_destruction_list;
181 182
182 scoped_refptr<Layer> layer_tree_root = 183 scoped_refptr<Layer> layer_tree_root =
183 MockLayer::Create(&layer_impl_destruction_list); 184 MockLayer::Create(&layer_impl_destruction_list);
184 layer_tree_root->AddChild(MockLayer::Create(&layer_impl_destruction_list)); 185 layer_tree_root->AddChild(MockLayer::Create(&layer_impl_destruction_list));
185 layer_tree_root->AddChild(MockLayer::Create(&layer_impl_destruction_list)); 186 layer_tree_root->AddChild(MockLayer::Create(&layer_impl_destruction_list));
186 int second_layer_impl_id = layer_tree_root->children()[1]->id(); 187 int second_layer_impl_id = layer_tree_root->children()[1]->id();
187 188
188 host_->SetRootLayer(layer_tree_root); 189 host_->SetRootLayer(layer_tree_root);
190 host_->BuildPropertyTreesForTesting();
189 191
190 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), 192 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
191 host_->active_tree()); 193 host_->active_tree());
192 LayerImpl* layer_impl_tree_root = 194 LayerImpl* layer_impl_tree_root =
193 host_->active_tree()->root_layer_for_testing(); 195 host_->active_tree()->root_layer_for_testing();
194 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root, 196 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root,
195 host_->active_tree()); 197 host_->active_tree());
196 198
197 // We have to push properties to pick up the destruction list pointer. 199 // We have to push properties to pick up the destruction list pointer.
198 TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(), 200 TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(),
199 host_->active_tree()); 201 host_->active_tree());
200 202
201 // Add a new layer to the Layer side 203 // Add a new layer to the Layer side
202 layer_tree_root->children()[0]->AddChild( 204 layer_tree_root->children()[0]->AddChild(
203 MockLayer::Create(&layer_impl_destruction_list)); 205 MockLayer::Create(&layer_impl_destruction_list));
204 // Remove one. 206 // Remove one.
205 layer_tree_root->children()[1]->RemoveFromParent(); 207 layer_tree_root->children()[1]->RemoveFromParent();
206 208
207 // Synchronize again. After the sync the trees should be equivalent and we 209 // Synchronize again. After the sync the trees should be equivalent and we
208 // should have created and destroyed one LayerImpl. 210 // should have created and destroyed one LayerImpl.
211 host_->BuildPropertyTreesForTesting();
209 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), 212 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
210 host_->active_tree()); 213 host_->active_tree());
211 layer_impl_tree_root = host_->active_tree()->root_layer_for_testing(); 214 layer_impl_tree_root = host_->active_tree()->root_layer_for_testing();
212 215
213 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root, 216 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root,
214 host_->active_tree()); 217 host_->active_tree());
215 218
216 ASSERT_EQ(1u, layer_impl_destruction_list.size()); 219 ASSERT_EQ(1u, layer_impl_destruction_list.size());
217 EXPECT_EQ(second_layer_impl_id, layer_impl_destruction_list[0]); 220 EXPECT_EQ(second_layer_impl_id, layer_impl_destruction_list[0]);
218 221
(...skipping 10 matching lines...) Expand all
229 scoped_refptr<Layer> layer_tree_root = 232 scoped_refptr<Layer> layer_tree_root =
230 MockLayer::Create(&layer_impl_destruction_list); 233 MockLayer::Create(&layer_impl_destruction_list);
231 scoped_refptr<Layer> child2 = MockLayer::Create(&layer_impl_destruction_list); 234 scoped_refptr<Layer> child2 = MockLayer::Create(&layer_impl_destruction_list);
232 layer_tree_root->AddChild(MockLayer::Create(&layer_impl_destruction_list)); 235 layer_tree_root->AddChild(MockLayer::Create(&layer_impl_destruction_list));
233 layer_tree_root->AddChild(child2); 236 layer_tree_root->AddChild(child2);
234 int child1_id = layer_tree_root->children()[0]->id(); 237 int child1_id = layer_tree_root->children()[0]->id();
235 int child2_id = layer_tree_root->children()[1]->id(); 238 int child2_id = layer_tree_root->children()[1]->id();
236 239
237 host_->SetRootLayer(layer_tree_root); 240 host_->SetRootLayer(layer_tree_root);
238 241
242 host_->BuildPropertyTreesForTesting();
239 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), 243 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
240 host_->active_tree()); 244 host_->active_tree());
241 LayerImpl* layer_impl_tree_root = 245 LayerImpl* layer_impl_tree_root =
242 host_->active_tree()->root_layer_for_testing(); 246 host_->active_tree()->root_layer_for_testing();
243 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root, 247 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root,
244 host_->active_tree()); 248 host_->active_tree());
245 249
246 // We have to push properties to pick up the destruction list pointer. 250 // We have to push properties to pick up the destruction list pointer.
247 TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(), 251 TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(),
248 host_->active_tree()); 252 host_->active_tree());
249 253
250 host_->active_tree()->ResetAllChangeTracking(); 254 host_->active_tree()->ResetAllChangeTracking();
251 255
252 // re-insert the layer and sync again. 256 // re-insert the layer and sync again.
253 child2->RemoveFromParent(); 257 child2->RemoveFromParent();
254 layer_tree_root->AddChild(child2); 258 layer_tree_root->AddChild(child2);
259 host_->BuildPropertyTreesForTesting();
255 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), 260 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
256 host_->active_tree()); 261 host_->active_tree());
257 layer_impl_tree_root = host_->active_tree()->root_layer_for_testing(); 262 layer_impl_tree_root = host_->active_tree()->root_layer_for_testing();
258 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root, 263 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root,
259 host_->active_tree()); 264 host_->active_tree());
260 265
266 host_->active_tree()->SetPropertyTrees(
267 layer_tree_root->layer_tree_host()->property_trees());
261 TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(), 268 TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(),
262 host_->active_tree()); 269 host_->active_tree());
263 270
264 // Check that the impl thread properly tracked the change. 271 // Check that the impl thread properly tracked the change.
265 EXPECT_FALSE(layer_impl_tree_root->LayerPropertyChanged()); 272 EXPECT_FALSE(layer_impl_tree_root->LayerPropertyChanged());
266 EXPECT_FALSE( 273 EXPECT_FALSE(
267 host_->active_tree()->LayerById(child1_id)->LayerPropertyChanged()); 274 host_->active_tree()->LayerById(child1_id)->LayerPropertyChanged());
268 EXPECT_TRUE( 275 EXPECT_TRUE(
269 host_->active_tree()->LayerById(child2_id)->LayerPropertyChanged()); 276 host_->active_tree()->LayerById(child2_id)->LayerPropertyChanged());
270 host_->active_tree()->DetachLayers(); 277 host_->active_tree()->DetachLayers();
271 } 278 }
272 279
273 TEST_F(TreeSynchronizerTest, SyncSimpleTreeAndProperties) { 280 TEST_F(TreeSynchronizerTest, SyncSimpleTreeAndProperties) {
274 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 281 scoped_refptr<Layer> layer_tree_root = Layer::Create();
275 layer_tree_root->AddChild(Layer::Create()); 282 layer_tree_root->AddChild(Layer::Create());
276 layer_tree_root->AddChild(Layer::Create()); 283 layer_tree_root->AddChild(Layer::Create());
277 284
278 host_->SetRootLayer(layer_tree_root); 285 host_->SetRootLayer(layer_tree_root);
279 286
280 // Pick some random properties to set. The values are not important, we're 287 // Pick some random properties to set. The values are not important, we're
281 // just testing that at least some properties are making it through. 288 // just testing that at least some properties are making it through.
282 gfx::PointF root_position = gfx::PointF(2.3f, 7.4f); 289 gfx::PointF root_position = gfx::PointF(2.3f, 7.4f);
283 layer_tree_root->SetPosition(root_position); 290 layer_tree_root->SetPosition(root_position);
284 291
285 gfx::Size second_child_bounds = gfx::Size(25, 53); 292 gfx::Size second_child_bounds = gfx::Size(25, 53);
286 layer_tree_root->children()[1]->SetBounds(second_child_bounds); 293 layer_tree_root->children()[1]->SetBounds(second_child_bounds);
287 layer_tree_root->children()[1]->SavePaintProperties(); 294 layer_tree_root->children()[1]->SavePaintProperties();
288 int second_child_id = layer_tree_root->children()[1]->id(); 295 int second_child_id = layer_tree_root->children()[1]->id();
289 296
297 host_->BuildPropertyTreesForTesting();
290 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), 298 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
291 host_->active_tree()); 299 host_->active_tree());
292 LayerImpl* layer_impl_tree_root = 300 LayerImpl* layer_impl_tree_root =
293 host_->active_tree()->root_layer_for_testing(); 301 host_->active_tree()->root_layer_for_testing();
294 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root, 302 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root,
295 host_->active_tree()); 303 host_->active_tree());
296 304
297 TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(), 305 TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(),
298 host_->active_tree()); 306 host_->active_tree());
299 307
(...skipping 28 matching lines...) Expand all
328 layer_a->AddChild(MockLayer::Create(&layer_impl_destruction_list)); 336 layer_a->AddChild(MockLayer::Create(&layer_impl_destruction_list));
329 337
330 scoped_refptr<Layer> layer_b = layer_a->children()[0]; 338 scoped_refptr<Layer> layer_b = layer_a->children()[0];
331 layer_b->AddChild(MockLayer::Create(&layer_impl_destruction_list)); 339 layer_b->AddChild(MockLayer::Create(&layer_impl_destruction_list));
332 340
333 scoped_refptr<Layer> layer_c = layer_b->children()[0]; 341 scoped_refptr<Layer> layer_c = layer_b->children()[0];
334 layer_b->AddChild(MockLayer::Create(&layer_impl_destruction_list)); 342 layer_b->AddChild(MockLayer::Create(&layer_impl_destruction_list));
335 scoped_refptr<Layer> layer_d = layer_b->children()[1]; 343 scoped_refptr<Layer> layer_d = layer_b->children()[1];
336 344
337 host_->SetRootLayer(layer_tree_root); 345 host_->SetRootLayer(layer_tree_root);
346 host_->BuildPropertyTreesForTesting();
338 347
339 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), 348 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
340 host_->active_tree()); 349 host_->active_tree());
341 LayerImpl* layer_impl_tree_root = 350 LayerImpl* layer_impl_tree_root =
342 host_->active_tree()->root_layer_for_testing(); 351 host_->active_tree()->root_layer_for_testing();
343 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root, 352 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root,
344 host_->active_tree()); 353 host_->active_tree());
345 354
346 // We have to push properties to pick up the destruction list pointer. 355 // We have to push properties to pick up the destruction list pointer.
347 TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(), 356 TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(),
348 host_->active_tree()); 357 host_->active_tree());
349 358
350 // Now restructure the tree to look like this: 359 // Now restructure the tree to look like this:
351 // root --- D ---+--- A 360 // root --- D ---+--- A
352 // | 361 // |
353 // +--- C --- B 362 // +--- C --- B
354 layer_tree_root->RemoveAllChildren(); 363 layer_tree_root->RemoveAllChildren();
355 layer_d->RemoveAllChildren(); 364 layer_d->RemoveAllChildren();
356 layer_tree_root->AddChild(layer_d); 365 layer_tree_root->AddChild(layer_d);
357 layer_a->RemoveAllChildren(); 366 layer_a->RemoveAllChildren();
358 layer_d->AddChild(layer_a); 367 layer_d->AddChild(layer_a);
359 layer_c->RemoveAllChildren(); 368 layer_c->RemoveAllChildren();
360 layer_d->AddChild(layer_c); 369 layer_d->AddChild(layer_c);
361 layer_b->RemoveAllChildren(); 370 layer_b->RemoveAllChildren();
362 layer_c->AddChild(layer_b); 371 layer_c->AddChild(layer_b);
363 372
364 // After another synchronize our trees should match and we should not have 373 // After another synchronize our trees should match and we should not have
365 // destroyed any LayerImpls 374 // destroyed any LayerImpls
375 host_->BuildPropertyTreesForTesting();
366 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), 376 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
367 host_->active_tree()); 377 host_->active_tree());
368 layer_impl_tree_root = host_->active_tree()->root_layer_for_testing(); 378 layer_impl_tree_root = host_->active_tree()->root_layer_for_testing();
369 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root, 379 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root,
370 host_->active_tree()); 380 host_->active_tree());
371 381
372 EXPECT_EQ(0u, layer_impl_destruction_list.size()); 382 EXPECT_EQ(0u, layer_impl_destruction_list.size());
373 383
374 host_->active_tree()->DetachLayers(); 384 host_->active_tree()->DetachLayers();
375 } 385 }
376 386
377 // Constructs a very simple tree, synchronizes it, then synchronizes to a 387 // Constructs a very simple tree, synchronizes it, then synchronizes to a
378 // totally new tree. All layers from the old tree should be deleted. 388 // totally new tree. All layers from the old tree should be deleted.
379 TEST_F(TreeSynchronizerTest, SyncSimpleTreeThenDestroy) { 389 TEST_F(TreeSynchronizerTest, SyncSimpleTreeThenDestroy) {
380 std::vector<int> layer_impl_destruction_list; 390 std::vector<int> layer_impl_destruction_list;
381 391
382 scoped_refptr<Layer> old_layer_tree_root = 392 scoped_refptr<Layer> old_layer_tree_root =
383 MockLayer::Create(&layer_impl_destruction_list); 393 MockLayer::Create(&layer_impl_destruction_list);
384 old_layer_tree_root->AddChild( 394 old_layer_tree_root->AddChild(
385 MockLayer::Create(&layer_impl_destruction_list)); 395 MockLayer::Create(&layer_impl_destruction_list));
386 old_layer_tree_root->AddChild( 396 old_layer_tree_root->AddChild(
387 MockLayer::Create(&layer_impl_destruction_list)); 397 MockLayer::Create(&layer_impl_destruction_list));
388 398
389 host_->SetRootLayer(old_layer_tree_root); 399 host_->SetRootLayer(old_layer_tree_root);
390 400
391 int old_tree_root_layer_id = old_layer_tree_root->id(); 401 int old_tree_root_layer_id = old_layer_tree_root->id();
392 int old_tree_first_child_layer_id = old_layer_tree_root->children()[0]->id(); 402 int old_tree_first_child_layer_id = old_layer_tree_root->children()[0]->id();
393 int old_tree_second_child_layer_id = old_layer_tree_root->children()[1]->id(); 403 int old_tree_second_child_layer_id = old_layer_tree_root->children()[1]->id();
394 404
405 host_->BuildPropertyTreesForTesting();
395 TreeSynchronizer::SynchronizeTrees(old_layer_tree_root.get(), 406 TreeSynchronizer::SynchronizeTrees(old_layer_tree_root.get(),
396 host_->active_tree()); 407 host_->active_tree());
397 LayerImpl* layer_impl_tree_root = 408 LayerImpl* layer_impl_tree_root =
398 host_->active_tree()->root_layer_for_testing(); 409 host_->active_tree()->root_layer_for_testing();
399 ExpectTreesAreIdentical(old_layer_tree_root.get(), layer_impl_tree_root, 410 ExpectTreesAreIdentical(old_layer_tree_root.get(), layer_impl_tree_root,
400 host_->active_tree()); 411 host_->active_tree());
401 412
402 // We have to push properties to pick up the destruction list pointer. 413 // We have to push properties to pick up the destruction list pointer.
403 TreeSynchronizer::PushLayerProperties(old_layer_tree_root->layer_tree_host(), 414 TreeSynchronizer::PushLayerProperties(old_layer_tree_root->layer_tree_host(),
404 host_->active_tree()); 415 host_->active_tree());
405 416
406 // Remove all children on the Layer side. 417 // Remove all children on the Layer side.
407 old_layer_tree_root->RemoveAllChildren(); 418 old_layer_tree_root->RemoveAllChildren();
408 419
409 // Synchronize again. After the sync all LayerImpls from the old tree should 420 // Synchronize again. After the sync all LayerImpls from the old tree should
410 // be deleted. 421 // be deleted.
411 scoped_refptr<Layer> new_layer_tree_root = Layer::Create(); 422 scoped_refptr<Layer> new_layer_tree_root = Layer::Create();
412 host_->SetRootLayer(new_layer_tree_root); 423 host_->SetRootLayer(new_layer_tree_root);
413 424
425 host_->BuildPropertyTreesForTesting();
414 TreeSynchronizer::SynchronizeTrees(new_layer_tree_root.get(), 426 TreeSynchronizer::SynchronizeTrees(new_layer_tree_root.get(),
415 host_->active_tree()); 427 host_->active_tree());
416 layer_impl_tree_root = host_->active_tree()->root_layer_for_testing(); 428 layer_impl_tree_root = host_->active_tree()->root_layer_for_testing();
417 ExpectTreesAreIdentical(new_layer_tree_root.get(), layer_impl_tree_root, 429 ExpectTreesAreIdentical(new_layer_tree_root.get(), layer_impl_tree_root,
418 host_->active_tree()); 430 host_->active_tree());
419 431
420 ASSERT_EQ(3u, layer_impl_destruction_list.size()); 432 ASSERT_EQ(3u, layer_impl_destruction_list.size());
421 433
422 EXPECT_TRUE(std::find(layer_impl_destruction_list.begin(), 434 EXPECT_TRUE(std::find(layer_impl_destruction_list.begin(),
423 layer_impl_destruction_list.end(), 435 layer_impl_destruction_list.end(),
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 host_->CommitAndCreatePendingTree(); 687 host_->CommitAndCreatePendingTree();
676 host_impl->ActivateSyncTree(); 688 host_impl->ActivateSyncTree();
677 EXPECT_EQ( 689 EXPECT_EQ(
678 CombinedAnimationScale(0.f, 0.f), 690 CombinedAnimationScale(0.f, 0.f),
679 host_impl->active_tree()->property_trees()->GetAnimationScales( 691 host_impl->active_tree()->property_trees()->GetAnimationScales(
680 transform_layer->transform_tree_index(), host_impl->active_tree())); 692 transform_layer->transform_tree_index(), host_impl->active_tree()));
681 } 693 }
682 694
683 } // namespace 695 } // namespace
684 } // namespace cc 696 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/tree_synchronizer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698