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

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

Issue 2661523003: cc: Merge LayerTree into the LayerTreeHost. (Closed)
Patch Set: auto Created 3 years, 10 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') | content/browser/renderer_host/compositor_impl_android.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 <algorithm> 9 #include <algorithm>
10 #include <set> 10 #include <set>
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 explicit MockLayer(std::vector<int>* layer_impl_destruction_list) 84 explicit MockLayer(std::vector<int>* layer_impl_destruction_list)
85 : layer_impl_destruction_list_(layer_impl_destruction_list) {} 85 : layer_impl_destruction_list_(layer_impl_destruction_list) {}
86 ~MockLayer() override {} 86 ~MockLayer() override {}
87 87
88 std::vector<int>* layer_impl_destruction_list_; 88 std::vector<int>* layer_impl_destruction_list_;
89 }; 89 };
90 90
91 void ExpectTreesAreIdentical(Layer* root_layer, 91 void ExpectTreesAreIdentical(Layer* root_layer,
92 LayerImpl* root_layer_impl, 92 LayerImpl* root_layer_impl,
93 LayerTreeImpl* tree_impl) { 93 LayerTreeImpl* tree_impl) {
94 auto layer_iter = root_layer->GetLayerTree()->begin(); 94 auto layer_iter = root_layer->layer_tree_host()->begin();
95 auto layer_impl_iter = tree_impl->begin(); 95 auto layer_impl_iter = tree_impl->begin();
96 for (; layer_iter != root_layer->GetLayerTree()->end(); 96 for (; layer_iter != root_layer->layer_tree_host()->end();
97 ++layer_iter, ++layer_impl_iter) { 97 ++layer_iter, ++layer_impl_iter) {
98 Layer* layer = *layer_iter; 98 Layer* layer = *layer_iter;
99 LayerImpl* layer_impl = *layer_impl_iter; 99 LayerImpl* layer_impl = *layer_impl_iter;
100 ASSERT_TRUE(layer); 100 ASSERT_TRUE(layer);
101 ASSERT_TRUE(layer_impl); 101 ASSERT_TRUE(layer_impl);
102 102
103 EXPECT_EQ(layer->id(), layer_impl->id()); 103 EXPECT_EQ(layer->id(), layer_impl->id());
104 EXPECT_EQ(layer_impl->layer_tree_impl(), tree_impl); 104 EXPECT_EQ(layer_impl->layer_tree_impl(), tree_impl);
105 105
106 EXPECT_EQ(layer->non_fast_scrollable_region(), 106 EXPECT_EQ(layer->non_fast_scrollable_region(),
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 host_->SetRootLayer(layer_tree_root); 187 host_->SetRootLayer(layer_tree_root);
188 188
189 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), 189 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
190 host_->active_tree()); 190 host_->active_tree());
191 LayerImpl* layer_impl_tree_root = 191 LayerImpl* layer_impl_tree_root =
192 host_->active_tree()->root_layer_for_testing(); 192 host_->active_tree()->root_layer_for_testing();
193 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root, 193 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root,
194 host_->active_tree()); 194 host_->active_tree());
195 195
196 // We have to push properties to pick up the destruction list pointer. 196 // We have to push properties to pick up the destruction list pointer.
197 TreeSynchronizer::PushLayerProperties(layer_tree_root->GetLayerTree(), 197 TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(),
198 host_->active_tree()); 198 host_->active_tree());
199 199
200 // Add a new layer to the Layer side 200 // Add a new layer to the Layer side
201 layer_tree_root->children()[0]->AddChild( 201 layer_tree_root->children()[0]->AddChild(
202 MockLayer::Create(&layer_impl_destruction_list)); 202 MockLayer::Create(&layer_impl_destruction_list));
203 // Remove one. 203 // Remove one.
204 layer_tree_root->children()[1]->RemoveFromParent(); 204 layer_tree_root->children()[1]->RemoveFromParent();
205 205
206 // Synchronize again. After the sync the trees should be equivalent and we 206 // Synchronize again. After the sync the trees should be equivalent and we
207 // should have created and destroyed one LayerImpl. 207 // should have created and destroyed one LayerImpl.
(...skipping 28 matching lines...) Expand all
236 host_->SetRootLayer(layer_tree_root); 236 host_->SetRootLayer(layer_tree_root);
237 237
238 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), 238 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
239 host_->active_tree()); 239 host_->active_tree());
240 LayerImpl* layer_impl_tree_root = 240 LayerImpl* layer_impl_tree_root =
241 host_->active_tree()->root_layer_for_testing(); 241 host_->active_tree()->root_layer_for_testing();
242 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root, 242 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root,
243 host_->active_tree()); 243 host_->active_tree());
244 244
245 // We have to push properties to pick up the destruction list pointer. 245 // We have to push properties to pick up the destruction list pointer.
246 TreeSynchronizer::PushLayerProperties(layer_tree_root->GetLayerTree(), 246 TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(),
247 host_->active_tree()); 247 host_->active_tree());
248 248
249 host_->active_tree()->ResetAllChangeTracking(); 249 host_->active_tree()->ResetAllChangeTracking();
250 250
251 // re-insert the layer and sync again. 251 // re-insert the layer and sync again.
252 child2->RemoveFromParent(); 252 child2->RemoveFromParent();
253 layer_tree_root->AddChild(child2); 253 layer_tree_root->AddChild(child2);
254 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), 254 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
255 host_->active_tree()); 255 host_->active_tree());
256 layer_impl_tree_root = host_->active_tree()->root_layer_for_testing(); 256 layer_impl_tree_root = host_->active_tree()->root_layer_for_testing();
257 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root, 257 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root,
258 host_->active_tree()); 258 host_->active_tree());
259 259
260 TreeSynchronizer::PushLayerProperties(layer_tree_root->GetLayerTree(), 260 TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(),
261 host_->active_tree()); 261 host_->active_tree());
262 262
263 // Check that the impl thread properly tracked the change. 263 // Check that the impl thread properly tracked the change.
264 EXPECT_FALSE(layer_impl_tree_root->LayerPropertyChanged()); 264 EXPECT_FALSE(layer_impl_tree_root->LayerPropertyChanged());
265 EXPECT_FALSE( 265 EXPECT_FALSE(
266 host_->active_tree()->LayerById(child1_id)->LayerPropertyChanged()); 266 host_->active_tree()->LayerById(child1_id)->LayerPropertyChanged());
267 EXPECT_TRUE( 267 EXPECT_TRUE(
268 host_->active_tree()->LayerById(child2_id)->LayerPropertyChanged()); 268 host_->active_tree()->LayerById(child2_id)->LayerPropertyChanged());
269 host_->active_tree()->DetachLayers(); 269 host_->active_tree()->DetachLayers();
270 } 270 }
(...skipping 15 matching lines...) Expand all
286 layer_tree_root->children()[1]->SavePaintProperties(); 286 layer_tree_root->children()[1]->SavePaintProperties();
287 int second_child_id = layer_tree_root->children()[1]->id(); 287 int second_child_id = layer_tree_root->children()[1]->id();
288 288
289 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), 289 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
290 host_->active_tree()); 290 host_->active_tree());
291 LayerImpl* layer_impl_tree_root = 291 LayerImpl* layer_impl_tree_root =
292 host_->active_tree()->root_layer_for_testing(); 292 host_->active_tree()->root_layer_for_testing();
293 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root, 293 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root,
294 host_->active_tree()); 294 host_->active_tree());
295 295
296 TreeSynchronizer::PushLayerProperties(layer_tree_root->GetLayerTree(), 296 TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(),
297 host_->active_tree()); 297 host_->active_tree());
298 298
299 // Check that the property values we set on the Layer tree are reflected in 299 // Check that the property values we set on the Layer tree are reflected in
300 // the LayerImpl tree. 300 // the LayerImpl tree.
301 gfx::PointF root_layer_impl_position = layer_impl_tree_root->position(); 301 gfx::PointF root_layer_impl_position = layer_impl_tree_root->position();
302 EXPECT_EQ(root_position.x(), root_layer_impl_position.x()); 302 EXPECT_EQ(root_position.x(), root_layer_impl_position.x());
303 EXPECT_EQ(root_position.y(), root_layer_impl_position.y()); 303 EXPECT_EQ(root_position.y(), root_layer_impl_position.y());
304 304
305 gfx::Size second_layer_impl_child_bounds = 305 gfx::Size second_layer_impl_child_bounds =
306 layer_impl_tree_root->layer_tree_impl() 306 layer_impl_tree_root->layer_tree_impl()
(...skipping 29 matching lines...) Expand all
336 host_->SetRootLayer(layer_tree_root); 336 host_->SetRootLayer(layer_tree_root);
337 337
338 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(), 338 TreeSynchronizer::SynchronizeTrees(layer_tree_root.get(),
339 host_->active_tree()); 339 host_->active_tree());
340 LayerImpl* layer_impl_tree_root = 340 LayerImpl* layer_impl_tree_root =
341 host_->active_tree()->root_layer_for_testing(); 341 host_->active_tree()->root_layer_for_testing();
342 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root, 342 ExpectTreesAreIdentical(layer_tree_root.get(), layer_impl_tree_root,
343 host_->active_tree()); 343 host_->active_tree());
344 344
345 // We have to push properties to pick up the destruction list pointer. 345 // We have to push properties to pick up the destruction list pointer.
346 TreeSynchronizer::PushLayerProperties(layer_tree_root->GetLayerTree(), 346 TreeSynchronizer::PushLayerProperties(layer_tree_root->layer_tree_host(),
347 host_->active_tree()); 347 host_->active_tree());
348 348
349 // Now restructure the tree to look like this: 349 // Now restructure the tree to look like this:
350 // root --- D ---+--- A 350 // root --- D ---+--- A
351 // | 351 // |
352 // +--- C --- B 352 // +--- C --- B
353 layer_tree_root->RemoveAllChildren(); 353 layer_tree_root->RemoveAllChildren();
354 layer_d->RemoveAllChildren(); 354 layer_d->RemoveAllChildren();
355 layer_tree_root->AddChild(layer_d); 355 layer_tree_root->AddChild(layer_d);
356 layer_a->RemoveAllChildren(); 356 layer_a->RemoveAllChildren();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 int old_tree_second_child_layer_id = old_layer_tree_root->children()[1]->id(); 392 int old_tree_second_child_layer_id = old_layer_tree_root->children()[1]->id();
393 393
394 TreeSynchronizer::SynchronizeTrees(old_layer_tree_root.get(), 394 TreeSynchronizer::SynchronizeTrees(old_layer_tree_root.get(),
395 host_->active_tree()); 395 host_->active_tree());
396 LayerImpl* layer_impl_tree_root = 396 LayerImpl* layer_impl_tree_root =
397 host_->active_tree()->root_layer_for_testing(); 397 host_->active_tree()->root_layer_for_testing();
398 ExpectTreesAreIdentical(old_layer_tree_root.get(), layer_impl_tree_root, 398 ExpectTreesAreIdentical(old_layer_tree_root.get(), layer_impl_tree_root,
399 host_->active_tree()); 399 host_->active_tree());
400 400
401 // We have to push properties to pick up the destruction list pointer. 401 // We have to push properties to pick up the destruction list pointer.
402 TreeSynchronizer::PushLayerProperties(old_layer_tree_root->GetLayerTree(), 402 TreeSynchronizer::PushLayerProperties(old_layer_tree_root->layer_tree_host(),
403 host_->active_tree()); 403 host_->active_tree());
404 404
405 // Remove all children on the Layer side. 405 // Remove all children on the Layer side.
406 old_layer_tree_root->RemoveAllChildren(); 406 old_layer_tree_root->RemoveAllChildren();
407 407
408 // Synchronize again. After the sync all LayerImpls from the old tree should 408 // Synchronize again. After the sync all LayerImpls from the old tree should
409 // be deleted. 409 // be deleted.
410 scoped_refptr<Layer> new_layer_tree_root = Layer::Create(); 410 scoped_refptr<Layer> new_layer_tree_root = Layer::Create();
411 host_->SetRootLayer(new_layer_tree_root); 411 host_->SetRootLayer(new_layer_tree_root);
412 412
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 host_->CommitAndCreatePendingTree(); 665 host_->CommitAndCreatePendingTree();
666 host_impl->ActivateSyncTree(); 666 host_impl->ActivateSyncTree();
667 EXPECT_EQ( 667 EXPECT_EQ(
668 CombinedAnimationScale(0.f, 0.f), 668 CombinedAnimationScale(0.f, 0.f),
669 host_impl->active_tree()->property_trees()->GetAnimationScales( 669 host_impl->active_tree()->property_trees()->GetAnimationScales(
670 transform_layer->transform_tree_index(), host_impl->active_tree())); 670 transform_layer->transform_tree_index(), host_impl->active_tree()));
671 } 671 }
672 672
673 } // namespace 673 } // namespace
674 } // namespace cc 674 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/tree_synchronizer.cc ('k') | content/browser/renderer_host/compositor_impl_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698