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/layers/layer.h" | 5 #include "cc/layers/layer.h" |
6 | 6 |
7 #include "cc/animation/keyframed_animation_curve.h" | 7 #include "cc/animation/keyframed_animation_curve.h" |
8 #include "cc/base/math_util.h" | 8 #include "cc/base/math_util.h" |
9 #include "cc/layers/layer_impl.h" | 9 #include "cc/layers/layer_impl.h" |
10 #include "cc/resources/layer_painter.h" | 10 #include "cc/resources/layer_painter.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 code_to_test; \ | 33 code_to_test; \ |
34 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \ | 34 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \ |
35 } while (false) | 35 } while (false) |
36 | 36 |
37 namespace cc { | 37 namespace cc { |
38 namespace { | 38 namespace { |
39 | 39 |
40 class MockLayerTreeHost : public LayerTreeHost { | 40 class MockLayerTreeHost : public LayerTreeHost { |
41 public: | 41 public: |
42 explicit MockLayerTreeHost(FakeLayerTreeHostClient* client) | 42 explicit MockLayerTreeHost(FakeLayerTreeHostClient* client) |
43 : LayerTreeHost(client, NULL, LayerTreeSettings()) { | 43 : LayerTreeHost(client, nullptr, LayerTreeSettings()) { |
44 InitializeSingleThreaded(client, base::MessageLoopProxy::current()); | 44 InitializeSingleThreaded(client, base::MessageLoopProxy::current()); |
45 } | 45 } |
46 | 46 |
47 MOCK_METHOD0(SetNeedsCommit, void()); | 47 MOCK_METHOD0(SetNeedsCommit, void()); |
48 MOCK_METHOD0(SetNeedsUpdateLayers, void()); | 48 MOCK_METHOD0(SetNeedsUpdateLayers, void()); |
49 MOCK_METHOD0(SetNeedsFullTreeSync, void()); | 49 MOCK_METHOD0(SetNeedsFullTreeSync, void()); |
50 }; | 50 }; |
51 | 51 |
52 class MockLayerPainter : public LayerPainter { | 52 class MockLayerPainter : public LayerPainter { |
53 public: | 53 public: |
54 virtual void Paint(SkCanvas* canvas, const gfx::Rect& content_rect) override { | 54 virtual void Paint(SkCanvas* canvas, const gfx::Rect& content_rect) override { |
55 } | 55 } |
56 }; | 56 }; |
57 | 57 |
58 class LayerTest : public testing::Test { | 58 class LayerTest : public testing::Test { |
59 public: | 59 public: |
60 LayerTest() | 60 LayerTest() |
61 : host_impl_(&proxy_, &shared_bitmap_manager_), | 61 : host_impl_(&proxy_, &shared_bitmap_manager_), |
62 fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} | 62 fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} |
63 | 63 |
64 protected: | 64 protected: |
65 virtual void SetUp() override { | 65 virtual void SetUp() override { |
66 layer_tree_host_.reset(new StrictMock<MockLayerTreeHost>(&fake_client_)); | 66 layer_tree_host_.reset(new StrictMock<MockLayerTreeHost>(&fake_client_)); |
67 } | 67 } |
68 | 68 |
69 virtual void TearDown() override { | 69 virtual void TearDown() override { |
70 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 70 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
71 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AnyNumber()); | 71 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AnyNumber()); |
72 parent_ = NULL; | 72 parent_ = nullptr; |
73 child1_ = NULL; | 73 child1_ = nullptr; |
74 child2_ = NULL; | 74 child2_ = nullptr; |
75 child3_ = NULL; | 75 child3_ = nullptr; |
76 grand_child1_ = NULL; | 76 grand_child1_ = nullptr; |
77 grand_child2_ = NULL; | 77 grand_child2_ = nullptr; |
78 grand_child3_ = NULL; | 78 grand_child3_ = nullptr; |
79 | 79 |
80 layer_tree_host_->SetRootLayer(NULL); | 80 layer_tree_host_->SetRootLayer(nullptr); |
81 layer_tree_host_ = nullptr; | 81 layer_tree_host_ = nullptr; |
82 } | 82 } |
83 | 83 |
84 void VerifyTestTreeInitialState() const { | 84 void VerifyTestTreeInitialState() const { |
85 ASSERT_EQ(3U, parent_->children().size()); | 85 ASSERT_EQ(3U, parent_->children().size()); |
86 EXPECT_EQ(child1_, parent_->children()[0]); | 86 EXPECT_EQ(child1_, parent_->children()[0]); |
87 EXPECT_EQ(child2_, parent_->children()[1]); | 87 EXPECT_EQ(child2_, parent_->children()[1]); |
88 EXPECT_EQ(child3_, parent_->children()[2]); | 88 EXPECT_EQ(child3_, parent_->children()[2]); |
89 EXPECT_EQ(parent_.get(), child1_->parent()); | 89 EXPECT_EQ(parent_.get(), child1_->parent()); |
90 EXPECT_EQ(parent_.get(), child2_->parent()); | 90 EXPECT_EQ(parent_.get(), child2_->parent()); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 144 |
145 TEST_F(LayerTest, BasicCreateAndDestroy) { | 145 TEST_F(LayerTest, BasicCreateAndDestroy) { |
146 scoped_refptr<Layer> test_layer = Layer::Create(); | 146 scoped_refptr<Layer> test_layer = Layer::Create(); |
147 ASSERT_TRUE(test_layer.get()); | 147 ASSERT_TRUE(test_layer.get()); |
148 | 148 |
149 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); | 149 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); |
150 test_layer->SetLayerTreeHost(layer_tree_host_.get()); | 150 test_layer->SetLayerTreeHost(layer_tree_host_.get()); |
151 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 151 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
152 | 152 |
153 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); | 153 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); |
154 test_layer->SetLayerTreeHost(NULL); | 154 test_layer->SetLayerTreeHost(nullptr); |
155 } | 155 } |
156 | 156 |
157 TEST_F(LayerTest, AddAndRemoveChild) { | 157 TEST_F(LayerTest, AddAndRemoveChild) { |
158 scoped_refptr<Layer> parent = Layer::Create(); | 158 scoped_refptr<Layer> parent = Layer::Create(); |
159 scoped_refptr<Layer> child = Layer::Create(); | 159 scoped_refptr<Layer> child = Layer::Create(); |
160 | 160 |
161 // Upon creation, layers should not have children or parent. | 161 // Upon creation, layers should not have children or parent. |
162 ASSERT_EQ(0U, parent->children().size()); | 162 ASSERT_EQ(0U, parent->children().size()); |
163 EXPECT_FALSE(child->parent()); | 163 EXPECT_FALSE(child->parent()); |
164 | 164 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 // Case 4: inserting to end of list | 227 // Case 4: inserting to end of list |
228 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child4, 3)); | 228 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child4, 3)); |
229 | 229 |
230 ASSERT_EQ(4U, parent->children().size()); | 230 ASSERT_EQ(4U, parent->children().size()); |
231 EXPECT_EQ(child1, parent->children()[0]); | 231 EXPECT_EQ(child1, parent->children()[0]); |
232 EXPECT_EQ(child2, parent->children()[1]); | 232 EXPECT_EQ(child2, parent->children()[1]); |
233 EXPECT_EQ(child3, parent->children()[2]); | 233 EXPECT_EQ(child3, parent->children()[2]); |
234 EXPECT_EQ(child4, parent->children()[3]); | 234 EXPECT_EQ(child4, parent->children()[3]); |
235 EXPECT_EQ(parent.get(), child4->parent()); | 235 EXPECT_EQ(parent.get(), child4->parent()); |
236 | 236 |
237 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(NULL)); | 237 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); |
238 } | 238 } |
239 | 239 |
240 TEST_F(LayerTest, InsertChildPastEndOfList) { | 240 TEST_F(LayerTest, InsertChildPastEndOfList) { |
241 scoped_refptr<Layer> parent = Layer::Create(); | 241 scoped_refptr<Layer> parent = Layer::Create(); |
242 scoped_refptr<Layer> child1 = Layer::Create(); | 242 scoped_refptr<Layer> child1 = Layer::Create(); |
243 scoped_refptr<Layer> child2 = Layer::Create(); | 243 scoped_refptr<Layer> child2 = Layer::Create(); |
244 | 244 |
245 ASSERT_EQ(0U, parent->children().size()); | 245 ASSERT_EQ(0U, parent->children().size()); |
246 | 246 |
247 // insert to an out-of-bounds index | 247 // insert to an out-of-bounds index |
(...skipping 28 matching lines...) Expand all Loading... |
276 | 276 |
277 // Inserting the same child again should cause the child to be removed and | 277 // Inserting the same child again should cause the child to be removed and |
278 // re-inserted at the new location. | 278 // re-inserted at the new location. |
279 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), parent->InsertChild(child1, 1)); | 279 EXPECT_SET_NEEDS_FULL_TREE_SYNC(AtLeast(1), parent->InsertChild(child1, 1)); |
280 | 280 |
281 // child1 should now be at the end of the list. | 281 // child1 should now be at the end of the list. |
282 ASSERT_EQ(2U, parent->children().size()); | 282 ASSERT_EQ(2U, parent->children().size()); |
283 EXPECT_EQ(child2, parent->children()[0]); | 283 EXPECT_EQ(child2, parent->children()[0]); |
284 EXPECT_EQ(child1, parent->children()[1]); | 284 EXPECT_EQ(child1, parent->children()[1]); |
285 | 285 |
286 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(NULL)); | 286 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); |
287 } | 287 } |
288 | 288 |
289 TEST_F(LayerTest, ReplaceChildWithNewChild) { | 289 TEST_F(LayerTest, ReplaceChildWithNewChild) { |
290 CreateSimpleTestTree(); | 290 CreateSimpleTestTree(); |
291 scoped_refptr<Layer> child4 = Layer::Create(); | 291 scoped_refptr<Layer> child4 = Layer::Create(); |
292 | 292 |
293 EXPECT_FALSE(child4->parent()); | 293 EXPECT_FALSE(child4->parent()); |
294 | 294 |
295 EXPECT_SET_NEEDS_FULL_TREE_SYNC( | 295 EXPECT_SET_NEEDS_FULL_TREE_SYNC( |
296 AtLeast(1), parent_->ReplaceChild(child2_.get(), child4)); | 296 AtLeast(1), parent_->ReplaceChild(child2_.get(), child4)); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 ASSERT_EQ(2U, parent->children().size()); | 350 ASSERT_EQ(2U, parent->children().size()); |
351 EXPECT_EQ(child1, parent->children()[0]); | 351 EXPECT_EQ(child1, parent->children()[0]); |
352 EXPECT_EQ(child2, parent->children()[1]); | 352 EXPECT_EQ(child2, parent->children()[1]); |
353 | 353 |
354 EXPECT_SET_NEEDS_COMMIT(2, child1->SetScrollParent(child2.get())); | 354 EXPECT_SET_NEEDS_COMMIT(2, child1->SetScrollParent(child2.get())); |
355 | 355 |
356 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, child2->RemoveFromParent()); | 356 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, child2->RemoveFromParent()); |
357 | 357 |
358 child1->reset_needs_push_properties_for_testing(); | 358 child1->reset_needs_push_properties_for_testing(); |
359 | 359 |
360 EXPECT_SET_NEEDS_COMMIT(1, child2 = NULL); | 360 EXPECT_SET_NEEDS_COMMIT(1, child2 = nullptr); |
361 | 361 |
362 EXPECT_TRUE(child1->needs_push_properties()); | 362 EXPECT_TRUE(child1->needs_push_properties()); |
363 | 363 |
364 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(NULL)); | 364 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); |
365 } | 365 } |
366 | 366 |
367 TEST_F(LayerTest, DeleteRemovedScrollChild) { | 367 TEST_F(LayerTest, DeleteRemovedScrollChild) { |
368 scoped_refptr<Layer> parent = Layer::Create(); | 368 scoped_refptr<Layer> parent = Layer::Create(); |
369 scoped_refptr<Layer> child1 = Layer::Create(); | 369 scoped_refptr<Layer> child1 = Layer::Create(); |
370 scoped_refptr<Layer> child2 = Layer::Create(); | 370 scoped_refptr<Layer> child2 = Layer::Create(); |
371 | 371 |
372 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); | 372 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); |
373 | 373 |
374 ASSERT_EQ(0U, parent->children().size()); | 374 ASSERT_EQ(0U, parent->children().size()); |
375 | 375 |
376 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child1, 0)); | 376 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child1, 0)); |
377 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child2, 1)); | 377 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child2, 1)); |
378 | 378 |
379 ASSERT_EQ(2U, parent->children().size()); | 379 ASSERT_EQ(2U, parent->children().size()); |
380 EXPECT_EQ(child1, parent->children()[0]); | 380 EXPECT_EQ(child1, parent->children()[0]); |
381 EXPECT_EQ(child2, parent->children()[1]); | 381 EXPECT_EQ(child2, parent->children()[1]); |
382 | 382 |
383 EXPECT_SET_NEEDS_COMMIT(2, child1->SetScrollParent(child2.get())); | 383 EXPECT_SET_NEEDS_COMMIT(2, child1->SetScrollParent(child2.get())); |
384 | 384 |
385 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, child1->RemoveFromParent()); | 385 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, child1->RemoveFromParent()); |
386 | 386 |
387 child2->reset_needs_push_properties_for_testing(); | 387 child2->reset_needs_push_properties_for_testing(); |
388 | 388 |
389 EXPECT_SET_NEEDS_COMMIT(1, child1 = NULL); | 389 EXPECT_SET_NEEDS_COMMIT(1, child1 = nullptr); |
390 | 390 |
391 EXPECT_TRUE(child2->needs_push_properties()); | 391 EXPECT_TRUE(child2->needs_push_properties()); |
392 | 392 |
393 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(NULL)); | 393 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); |
394 } | 394 } |
395 | 395 |
396 TEST_F(LayerTest, ReplaceChildWithSameChild) { | 396 TEST_F(LayerTest, ReplaceChildWithSameChild) { |
397 CreateSimpleTestTree(); | 397 CreateSimpleTestTree(); |
398 | 398 |
399 // SetNeedsFullTreeSync / SetNeedsCommit should not be called because its the | 399 // SetNeedsFullTreeSync / SetNeedsCommit should not be called because its the |
400 // same child. | 400 // same child. |
401 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); | 401 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); |
402 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(0); | 402 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(0); |
403 parent_->ReplaceChild(child2_.get(), child2_); | 403 parent_->ReplaceChild(child2_.get(), child2_); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 EXPECT_SET_NEEDS_FULL_TREE_SYNC( | 437 EXPECT_SET_NEEDS_FULL_TREE_SYNC( |
438 1, layer_tree_host_->SetRootLayer(new_parent)); | 438 1, layer_tree_host_->SetRootLayer(new_parent)); |
439 | 439 |
440 EXPECT_SET_NEEDS_FULL_TREE_SYNC( | 440 EXPECT_SET_NEEDS_FULL_TREE_SYNC( |
441 AtLeast(1), new_parent->SetChildren(new_children)); | 441 AtLeast(1), new_parent->SetChildren(new_children)); |
442 | 442 |
443 ASSERT_EQ(2U, new_parent->children().size()); | 443 ASSERT_EQ(2U, new_parent->children().size()); |
444 EXPECT_EQ(new_parent.get(), child1->parent()); | 444 EXPECT_EQ(new_parent.get(), child1->parent()); |
445 EXPECT_EQ(new_parent.get(), child2->parent()); | 445 EXPECT_EQ(new_parent.get(), child2->parent()); |
446 | 446 |
447 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(NULL)); | 447 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); |
448 } | 448 } |
449 | 449 |
450 TEST_F(LayerTest, HasAncestor) { | 450 TEST_F(LayerTest, HasAncestor) { |
451 scoped_refptr<Layer> parent = Layer::Create(); | 451 scoped_refptr<Layer> parent = Layer::Create(); |
452 EXPECT_FALSE(parent->HasAncestor(parent.get())); | 452 EXPECT_FALSE(parent->HasAncestor(parent.get())); |
453 | 453 |
454 scoped_refptr<Layer> child = Layer::Create(); | 454 scoped_refptr<Layer> child = Layer::Create(); |
455 parent->AddChild(child); | 455 parent->AddChild(child); |
456 | 456 |
457 EXPECT_FALSE(child->HasAncestor(child.get())); | 457 EXPECT_FALSE(child->HasAncestor(child.get())); |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
838 child->SetMaskLayer(mask.get()); | 838 child->SetMaskLayer(mask.get()); |
839 child->SetReplicaLayer(replica.get()); | 839 child->SetReplicaLayer(replica.get()); |
840 replica->SetMaskLayer(replica_mask.get()); | 840 replica->SetMaskLayer(replica_mask.get()); |
841 | 841 |
842 EXPECT_EQ(parent.get(), child->parent()); | 842 EXPECT_EQ(parent.get(), child->parent()); |
843 EXPECT_EQ(child.get(), mask->parent()); | 843 EXPECT_EQ(child.get(), mask->parent()); |
844 EXPECT_EQ(child.get(), replica->parent()); | 844 EXPECT_EQ(child.get(), replica->parent()); |
845 EXPECT_EQ(replica.get(), replica_mask->parent()); | 845 EXPECT_EQ(replica.get(), replica_mask->parent()); |
846 | 846 |
847 replica->SetMaskLayer(replica_mask_replacement.get()); | 847 replica->SetMaskLayer(replica_mask_replacement.get()); |
848 EXPECT_EQ(NULL, replica_mask->parent()); | 848 EXPECT_EQ(nullptr, replica_mask->parent()); |
849 EXPECT_EQ(replica.get(), replica_mask_replacement->parent()); | 849 EXPECT_EQ(replica.get(), replica_mask_replacement->parent()); |
850 | 850 |
851 child->SetMaskLayer(mask_replacement.get()); | 851 child->SetMaskLayer(mask_replacement.get()); |
852 EXPECT_EQ(NULL, mask->parent()); | 852 EXPECT_EQ(nullptr, mask->parent()); |
853 EXPECT_EQ(child.get(), mask_replacement->parent()); | 853 EXPECT_EQ(child.get(), mask_replacement->parent()); |
854 | 854 |
855 child->SetReplicaLayer(replica_replacement.get()); | 855 child->SetReplicaLayer(replica_replacement.get()); |
856 EXPECT_EQ(NULL, replica->parent()); | 856 EXPECT_EQ(nullptr, replica->parent()); |
857 EXPECT_EQ(child.get(), replica_replacement->parent()); | 857 EXPECT_EQ(child.get(), replica_replacement->parent()); |
858 | 858 |
859 EXPECT_EQ(replica.get(), replica->mask_layer()->parent()); | 859 EXPECT_EQ(replica.get(), replica->mask_layer()->parent()); |
860 } | 860 } |
861 | 861 |
862 TEST_F(LayerTest, CheckTranformIsInvertible) { | 862 TEST_F(LayerTest, CheckTranformIsInvertible) { |
863 scoped_refptr<Layer> layer = Layer::Create(); | 863 scoped_refptr<Layer> layer = Layer::Create(); |
864 scoped_ptr<LayerImpl> impl_layer = | 864 scoped_ptr<LayerImpl> impl_layer = |
865 LayerImpl::Create(host_impl_.active_tree(), 1); | 865 LayerImpl::Create(host_impl_.active_tree(), 1); |
866 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(1); | 866 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(1); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 scoped_refptr<Layer> replica = Layer::Create(); | 971 scoped_refptr<Layer> replica = Layer::Create(); |
972 scoped_refptr<Layer> replica_mask = Layer::Create(); | 972 scoped_refptr<Layer> replica_mask = Layer::Create(); |
973 | 973 |
974 // Set up a detached tree of layers. The host pointer should be nil for these | 974 // Set up a detached tree of layers. The host pointer should be nil for these |
975 // layers. | 975 // layers. |
976 parent->AddChild(child); | 976 parent->AddChild(child); |
977 child->SetMaskLayer(mask.get()); | 977 child->SetMaskLayer(mask.get()); |
978 child->SetReplicaLayer(replica.get()); | 978 child->SetReplicaLayer(replica.get()); |
979 replica->SetMaskLayer(replica_mask.get()); | 979 replica->SetMaskLayer(replica_mask.get()); |
980 | 980 |
981 AssertLayerTreeHostMatchesForSubtree(parent.get(), NULL); | 981 AssertLayerTreeHostMatchesForSubtree(parent.get(), nullptr); |
982 | 982 |
983 LayerTreeHostFactory factory; | 983 LayerTreeHostFactory factory; |
984 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); | 984 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); |
985 // Setting the root layer should set the host pointer for all layers in the | 985 // Setting the root layer should set the host pointer for all layers in the |
986 // tree. | 986 // tree. |
987 layer_tree_host->SetRootLayer(parent.get()); | 987 layer_tree_host->SetRootLayer(parent.get()); |
988 | 988 |
989 AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get()); | 989 AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get()); |
990 | 990 |
991 // Clearing the root layer should also clear out the host pointers for all | 991 // Clearing the root layer should also clear out the host pointers for all |
992 // layers in the tree. | 992 // layers in the tree. |
993 layer_tree_host->SetRootLayer(NULL); | 993 layer_tree_host->SetRootLayer(nullptr); |
994 | 994 |
995 AssertLayerTreeHostMatchesForSubtree(parent.get(), NULL); | 995 AssertLayerTreeHostMatchesForSubtree(parent.get(), nullptr); |
996 } | 996 } |
997 | 997 |
998 TEST(LayerLayerTreeHostTest, AddingLayerSubtree) { | 998 TEST(LayerLayerTreeHostTest, AddingLayerSubtree) { |
999 scoped_refptr<Layer> parent = Layer::Create(); | 999 scoped_refptr<Layer> parent = Layer::Create(); |
1000 LayerTreeHostFactory factory; | 1000 LayerTreeHostFactory factory; |
1001 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); | 1001 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); |
1002 | 1002 |
1003 layer_tree_host->SetRootLayer(parent.get()); | 1003 layer_tree_host->SetRootLayer(parent.get()); |
1004 | 1004 |
1005 EXPECT_EQ(parent->layer_tree_host(), layer_tree_host.get()); | 1005 EXPECT_EQ(parent->layer_tree_host(), layer_tree_host.get()); |
1006 | 1006 |
1007 // Adding a subtree to a layer already associated with a host should set the | 1007 // Adding a subtree to a layer already associated with a host should set the |
1008 // host pointer on all layers in that subtree. | 1008 // host pointer on all layers in that subtree. |
1009 scoped_refptr<Layer> child = Layer::Create(); | 1009 scoped_refptr<Layer> child = Layer::Create(); |
1010 scoped_refptr<Layer> grand_child = Layer::Create(); | 1010 scoped_refptr<Layer> grand_child = Layer::Create(); |
1011 child->AddChild(grand_child); | 1011 child->AddChild(grand_child); |
1012 | 1012 |
1013 // Masks, replicas, and replica masks should pick up the new host too. | 1013 // Masks, replicas, and replica masks should pick up the new host too. |
1014 scoped_refptr<Layer> child_mask = Layer::Create(); | 1014 scoped_refptr<Layer> child_mask = Layer::Create(); |
1015 child->SetMaskLayer(child_mask.get()); | 1015 child->SetMaskLayer(child_mask.get()); |
1016 scoped_refptr<Layer> child_replica = Layer::Create(); | 1016 scoped_refptr<Layer> child_replica = Layer::Create(); |
1017 child->SetReplicaLayer(child_replica.get()); | 1017 child->SetReplicaLayer(child_replica.get()); |
1018 scoped_refptr<Layer> child_replica_mask = Layer::Create(); | 1018 scoped_refptr<Layer> child_replica_mask = Layer::Create(); |
1019 child_replica->SetMaskLayer(child_replica_mask.get()); | 1019 child_replica->SetMaskLayer(child_replica_mask.get()); |
1020 | 1020 |
1021 parent->AddChild(child); | 1021 parent->AddChild(child); |
1022 AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get()); | 1022 AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get()); |
1023 | 1023 |
1024 layer_tree_host->SetRootLayer(NULL); | 1024 layer_tree_host->SetRootLayer(nullptr); |
1025 } | 1025 } |
1026 | 1026 |
1027 TEST(LayerLayerTreeHostTest, ChangeHost) { | 1027 TEST(LayerLayerTreeHostTest, ChangeHost) { |
1028 scoped_refptr<Layer> parent = Layer::Create(); | 1028 scoped_refptr<Layer> parent = Layer::Create(); |
1029 scoped_refptr<Layer> child = Layer::Create(); | 1029 scoped_refptr<Layer> child = Layer::Create(); |
1030 scoped_refptr<Layer> mask = Layer::Create(); | 1030 scoped_refptr<Layer> mask = Layer::Create(); |
1031 scoped_refptr<Layer> replica = Layer::Create(); | 1031 scoped_refptr<Layer> replica = Layer::Create(); |
1032 scoped_refptr<Layer> replica_mask = Layer::Create(); | 1032 scoped_refptr<Layer> replica_mask = Layer::Create(); |
1033 | 1033 |
1034 // Same setup as the previous test. | 1034 // Same setup as the previous test. |
(...skipping 10 matching lines...) Expand all Loading... |
1045 first_layer_tree_host.get()); | 1045 first_layer_tree_host.get()); |
1046 | 1046 |
1047 // Now re-root the tree to a new host (simulating what we do on a context lost | 1047 // Now re-root the tree to a new host (simulating what we do on a context lost |
1048 // event). This should update the host pointers for all layers in the tree. | 1048 // event). This should update the host pointers for all layers in the tree. |
1049 scoped_ptr<LayerTreeHost> second_layer_tree_host = factory.Create(); | 1049 scoped_ptr<LayerTreeHost> second_layer_tree_host = factory.Create(); |
1050 second_layer_tree_host->SetRootLayer(parent.get()); | 1050 second_layer_tree_host->SetRootLayer(parent.get()); |
1051 | 1051 |
1052 AssertLayerTreeHostMatchesForSubtree(parent.get(), | 1052 AssertLayerTreeHostMatchesForSubtree(parent.get(), |
1053 second_layer_tree_host.get()); | 1053 second_layer_tree_host.get()); |
1054 | 1054 |
1055 second_layer_tree_host->SetRootLayer(NULL); | 1055 second_layer_tree_host->SetRootLayer(nullptr); |
1056 } | 1056 } |
1057 | 1057 |
1058 TEST(LayerLayerTreeHostTest, ChangeHostInSubtree) { | 1058 TEST(LayerLayerTreeHostTest, ChangeHostInSubtree) { |
1059 scoped_refptr<Layer> first_parent = Layer::Create(); | 1059 scoped_refptr<Layer> first_parent = Layer::Create(); |
1060 scoped_refptr<Layer> first_child = Layer::Create(); | 1060 scoped_refptr<Layer> first_child = Layer::Create(); |
1061 scoped_refptr<Layer> second_parent = Layer::Create(); | 1061 scoped_refptr<Layer> second_parent = Layer::Create(); |
1062 scoped_refptr<Layer> second_child = Layer::Create(); | 1062 scoped_refptr<Layer> second_child = Layer::Create(); |
1063 scoped_refptr<Layer> second_grand_child = Layer::Create(); | 1063 scoped_refptr<Layer> second_grand_child = Layer::Create(); |
1064 | 1064 |
1065 // First put all children under the first parent and set the first host. | 1065 // First put all children under the first parent and set the first host. |
(...skipping 14 matching lines...) Expand all Loading... |
1080 second_layer_tree_host->SetRootLayer(second_parent.get()); | 1080 second_layer_tree_host->SetRootLayer(second_parent.get()); |
1081 | 1081 |
1082 second_parent->AddChild(second_child); | 1082 second_parent->AddChild(second_child); |
1083 | 1083 |
1084 // The moved layer and its children should point to the new host. | 1084 // The moved layer and its children should point to the new host. |
1085 EXPECT_EQ(second_layer_tree_host.get(), second_child->layer_tree_host()); | 1085 EXPECT_EQ(second_layer_tree_host.get(), second_child->layer_tree_host()); |
1086 EXPECT_EQ(second_layer_tree_host.get(), | 1086 EXPECT_EQ(second_layer_tree_host.get(), |
1087 second_grand_child->layer_tree_host()); | 1087 second_grand_child->layer_tree_host()); |
1088 | 1088 |
1089 // Test over, cleanup time. | 1089 // Test over, cleanup time. |
1090 first_layer_tree_host->SetRootLayer(NULL); | 1090 first_layer_tree_host->SetRootLayer(nullptr); |
1091 second_layer_tree_host->SetRootLayer(NULL); | 1091 second_layer_tree_host->SetRootLayer(nullptr); |
1092 } | 1092 } |
1093 | 1093 |
1094 TEST(LayerLayerTreeHostTest, ReplaceMaskAndReplicaLayer) { | 1094 TEST(LayerLayerTreeHostTest, ReplaceMaskAndReplicaLayer) { |
1095 scoped_refptr<Layer> parent = Layer::Create(); | 1095 scoped_refptr<Layer> parent = Layer::Create(); |
1096 scoped_refptr<Layer> mask = Layer::Create(); | 1096 scoped_refptr<Layer> mask = Layer::Create(); |
1097 scoped_refptr<Layer> replica = Layer::Create(); | 1097 scoped_refptr<Layer> replica = Layer::Create(); |
1098 scoped_refptr<Layer> mask_child = Layer::Create(); | 1098 scoped_refptr<Layer> mask_child = Layer::Create(); |
1099 scoped_refptr<Layer> replica_child = Layer::Create(); | 1099 scoped_refptr<Layer> replica_child = Layer::Create(); |
1100 scoped_refptr<Layer> mask_replacement = Layer::Create(); | 1100 scoped_refptr<Layer> mask_replacement = Layer::Create(); |
1101 scoped_refptr<Layer> replica_replacement = Layer::Create(); | 1101 scoped_refptr<Layer> replica_replacement = Layer::Create(); |
1102 | 1102 |
1103 parent->SetMaskLayer(mask.get()); | 1103 parent->SetMaskLayer(mask.get()); |
1104 parent->SetReplicaLayer(replica.get()); | 1104 parent->SetReplicaLayer(replica.get()); |
1105 mask->AddChild(mask_child); | 1105 mask->AddChild(mask_child); |
1106 replica->AddChild(replica_child); | 1106 replica->AddChild(replica_child); |
1107 | 1107 |
1108 LayerTreeHostFactory factory; | 1108 LayerTreeHostFactory factory; |
1109 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); | 1109 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); |
1110 layer_tree_host->SetRootLayer(parent.get()); | 1110 layer_tree_host->SetRootLayer(parent.get()); |
1111 | 1111 |
1112 AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get()); | 1112 AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get()); |
1113 | 1113 |
1114 // Replacing the mask should clear out the old mask's subtree's host pointers. | 1114 // Replacing the mask should clear out the old mask's subtree's host pointers. |
1115 parent->SetMaskLayer(mask_replacement.get()); | 1115 parent->SetMaskLayer(mask_replacement.get()); |
1116 EXPECT_EQ(NULL, mask->layer_tree_host()); | 1116 EXPECT_EQ(nullptr, mask->layer_tree_host()); |
1117 EXPECT_EQ(NULL, mask_child->layer_tree_host()); | 1117 EXPECT_EQ(nullptr, mask_child->layer_tree_host()); |
1118 | 1118 |
1119 // Same for replacing a replica layer. | 1119 // Same for replacing a replica layer. |
1120 parent->SetReplicaLayer(replica_replacement.get()); | 1120 parent->SetReplicaLayer(replica_replacement.get()); |
1121 EXPECT_EQ(NULL, replica->layer_tree_host()); | 1121 EXPECT_EQ(nullptr, replica->layer_tree_host()); |
1122 EXPECT_EQ(NULL, replica_child->layer_tree_host()); | 1122 EXPECT_EQ(nullptr, replica_child->layer_tree_host()); |
1123 | 1123 |
1124 // Test over, cleanup time. | 1124 // Test over, cleanup time. |
1125 layer_tree_host->SetRootLayer(NULL); | 1125 layer_tree_host->SetRootLayer(nullptr); |
1126 } | 1126 } |
1127 | 1127 |
1128 TEST(LayerLayerTreeHostTest, DestroyHostWithNonNullRootLayer) { | 1128 TEST(LayerLayerTreeHostTest, DestroyHostWithNonNullRootLayer) { |
1129 scoped_refptr<Layer> root = Layer::Create(); | 1129 scoped_refptr<Layer> root = Layer::Create(); |
1130 scoped_refptr<Layer> child = Layer::Create(); | 1130 scoped_refptr<Layer> child = Layer::Create(); |
1131 root->AddChild(child); | 1131 root->AddChild(child); |
1132 LayerTreeHostFactory factory; | 1132 LayerTreeHostFactory factory; |
1133 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); | 1133 scoped_ptr<LayerTreeHost> layer_tree_host = factory.Create(); |
1134 layer_tree_host->SetRootLayer(root); | 1134 layer_tree_host->SetRootLayer(root); |
1135 } | 1135 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1245 root_layer->AddChild(becomes_not_draws_content); | 1245 root_layer->AddChild(becomes_not_draws_content); |
1246 EXPECT_EQ(0, root_layer->NumDescendantsThatDrawContent()); | 1246 EXPECT_EQ(0, root_layer->NumDescendantsThatDrawContent()); |
1247 | 1247 |
1248 becomes_draws_content->SetIsDrawable(true); | 1248 becomes_draws_content->SetIsDrawable(true); |
1249 root_layer->AddChild(becomes_draws_content); | 1249 root_layer->AddChild(becomes_draws_content); |
1250 EXPECT_EQ(1, root_layer->NumDescendantsThatDrawContent()); | 1250 EXPECT_EQ(1, root_layer->NumDescendantsThatDrawContent()); |
1251 } | 1251 } |
1252 | 1252 |
1253 } // namespace | 1253 } // namespace |
1254 } // namespace cc | 1254 } // namespace cc |
OLD | NEW |