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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
10 #include "cc/animation/animation_host.h" | 10 #include "cc/animation/animation_host.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 using ::testing::StrictMock; | 46 using ::testing::StrictMock; |
47 using ::testing::_; | 47 using ::testing::_; |
48 | 48 |
49 #define EXPECT_SET_NEEDS_FULL_TREE_SYNC(expect, code_to_test) \ | 49 #define EXPECT_SET_NEEDS_FULL_TREE_SYNC(expect, code_to_test) \ |
50 do { \ | 50 do { \ |
51 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times((expect)); \ | 51 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times((expect)); \ |
52 code_to_test; \ | 52 code_to_test; \ |
53 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \ | 53 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \ |
54 } while (false) | 54 } while (false) |
55 | 55 |
56 #define EXECUTE_AND_VERIFY_SUBTREE_CHANGED(code_to_test) \ | |
57 code_to_test; \ | |
58 root->layer_tree_host()->BuildPropertyTreesForTesting(); \ | |
59 EXPECT_TRUE(root->subtree_property_changed()); \ | |
60 EXPECT_TRUE(root->needs_push_properties()); \ | |
61 EXPECT_TRUE(child->subtree_property_changed()); \ | |
62 EXPECT_TRUE(child->needs_push_properties()); \ | |
63 EXPECT_TRUE(grand_child->subtree_property_changed()); \ | |
64 EXPECT_TRUE(grand_child->needs_push_properties()); | |
65 | |
66 #define EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET(code_to_test) \ | |
67 code_to_test; \ | |
68 EXPECT_FALSE(root->subtree_property_changed()); \ | |
69 EXPECT_FALSE(root->needs_push_properties()); \ | |
70 EXPECT_FALSE(child->subtree_property_changed()); \ | |
71 EXPECT_FALSE(child->needs_push_properties()); \ | |
72 EXPECT_FALSE(grand_child->subtree_property_changed()); \ | |
73 EXPECT_FALSE(grand_child->needs_push_properties()); | |
74 | |
56 namespace cc { | 75 namespace cc { |
57 | 76 |
58 // This class is a friend of Layer, and is used as a wrapper for all the tests | 77 // This class is a friend of Layer, and is used as a wrapper for all the tests |
59 // related to proto serialization. This is done so that it is unnecessary to | 78 // related to proto serialization. This is done so that it is unnecessary to |
60 // add FRIEND_TEST_ALL_PREFIXES in //cc/layers/layer.h for all the tests. | 79 // add FRIEND_TEST_ALL_PREFIXES in //cc/layers/layer.h for all the tests. |
61 // It is in the cc namespace so that it can be a friend of Layer. | 80 // It is in the cc namespace so that it can be a friend of Layer. |
62 // The tests still have helpful names, and a test with the name FooBar would | 81 // The tests still have helpful names, and a test with the name FooBar would |
63 // have a wrapper method in this class called RunFooBarTest. | 82 // have a wrapper method in this class called RunFooBarTest. |
64 class LayerSerializationTest : public testing::Test { | 83 class LayerSerializationTest : public testing::Test { |
65 public: | 84 public: |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
494 ASSERT_TRUE(test_layer.get()); | 513 ASSERT_TRUE(test_layer.get()); |
495 | 514 |
496 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); | 515 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); |
497 test_layer->SetLayerTreeHost(layer_tree_host_.get()); | 516 test_layer->SetLayerTreeHost(layer_tree_host_.get()); |
498 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 517 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
499 | 518 |
500 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); | 519 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); |
501 test_layer->SetLayerTreeHost(nullptr); | 520 test_layer->SetLayerTreeHost(nullptr); |
502 } | 521 } |
503 | 522 |
523 TEST_F(LayerTest, LayerPropertyChangedForSubtree) { | |
524 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AtLeast(1)); | |
525 scoped_refptr<Layer> root = Layer::Create(layer_settings_); | |
526 scoped_refptr<Layer> child = Layer::Create(layer_settings_); | |
527 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings_); | |
528 scoped_refptr<Layer> dummy_layer1 = Layer::Create(layer_settings_); | |
529 scoped_refptr<Layer> dummy_layer2 = Layer::Create(layer_settings_); | |
530 | |
531 layer_tree_host_->SetRootLayer(root); | |
532 root->AddChild(child); | |
533 child->AddChild(grand_child); | |
534 SkXfermode::Mode arbitrary_blend_mode = SkXfermode::kMultiply_Mode; | |
535 scoped_ptr<LayerImpl> root_impl = | |
536 LayerImpl::Create(host_impl_.active_tree(), 1); | |
537 scoped_ptr<LayerImpl> child_impl = | |
538 LayerImpl::Create(host_impl_.active_tree(), 2); | |
539 scoped_ptr<LayerImpl> grand_child_impl = | |
540 LayerImpl::Create(host_impl_.active_tree(), 3); | |
541 scoped_ptr<LayerImpl> dummy_layer1_impl = | |
542 LayerImpl::Create(host_impl_.active_tree(), 4); | |
543 scoped_ptr<LayerImpl> dummy_layer2_impl = | |
544 LayerImpl::Create(host_impl_.active_tree(), 5); | |
545 | |
546 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(1); | |
547 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetMaskLayer(dummy_layer1.get())); | |
548 EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET( | |
549 root->PushPropertiesTo(root_impl.get()); | |
550 child->PushPropertiesTo(child_impl.get()); | |
551 grand_child->PushPropertiesTo(grand_child_impl.get()); | |
552 dummy_layer1->PushPropertiesTo(dummy_layer1_impl.get())); | |
jaydasika
2016/02/11 01:48:38
When we add the mask layer, we need to push it als
| |
553 | |
554 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); | |
555 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetMasksToBounds(true)); | |
556 EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET( | |
557 root->PushPropertiesTo(root_impl.get()); | |
558 child->PushPropertiesTo(child_impl.get()); | |
559 grand_child->PushPropertiesTo(grand_child_impl.get())); | |
560 | |
561 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); | |
562 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetContentsOpaque(true)); | |
563 EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET( | |
564 root->PushPropertiesTo(root_impl.get()); | |
565 child->PushPropertiesTo(child_impl.get()); | |
566 grand_child->PushPropertiesTo(grand_child_impl.get())); | |
567 | |
568 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(1); | |
569 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetReplicaLayer(dummy_layer2.get())); | |
570 EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET( | |
571 root->PushPropertiesTo(root_impl.get()); | |
572 child->PushPropertiesTo(child_impl.get()); | |
573 grand_child->PushPropertiesTo(grand_child_impl.get()); | |
574 dummy_layer2->PushPropertiesTo(dummy_layer1_impl.get())); | |
jaydasika
2016/02/11 01:48:38
Adding replica layer and we need to push its prope
ajuma
2016/02/11 14:22:16
Nit: push to layer2, not layer1. Actually, it migh
| |
575 | |
576 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); | |
577 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetShouldFlattenTransform(false)); | |
578 EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET( | |
579 root->PushPropertiesTo(root_impl.get()); | |
580 child->PushPropertiesTo(child_impl.get()); | |
581 grand_child->PushPropertiesTo(grand_child_impl.get())); | |
582 | |
583 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); | |
584 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->Set3dSortingContextId(1)); | |
585 EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET( | |
586 root->PushPropertiesTo(root_impl.get()); | |
587 child->PushPropertiesTo(child_impl.get()); | |
588 grand_child->PushPropertiesTo(grand_child_impl.get()); | |
589 dummy_layer2->PushPropertiesTo(dummy_layer1_impl.get())); | |
jaydasika
2016/02/11 01:48:38
Replica layer gets a transform node (because its a
ajuma
2016/02/11 14:22:16
Here too, push to layer2, and it might be clearer
jaydasika
2016/02/11 19:24:24
Done.
| |
590 | |
591 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); | |
592 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetDoubleSided(false)); | |
593 EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET( | |
594 root->PushPropertiesTo(root_impl.get()); | |
595 child->PushPropertiesTo(child_impl.get()); | |
596 grand_child->PushPropertiesTo(grand_child_impl.get())); | |
597 | |
598 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); | |
599 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetHideLayerAndSubtree(true)); | |
600 EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET( | |
601 root->PushPropertiesTo(root_impl.get()); | |
602 child->PushPropertiesTo(child_impl.get()); | |
603 grand_child->PushPropertiesTo(grand_child_impl.get())); | |
604 | |
605 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); | |
606 EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetBlendMode(arbitrary_blend_mode)); | |
607 } | |
608 | |
504 TEST_F(LayerTest, AddAndRemoveChild) { | 609 TEST_F(LayerTest, AddAndRemoveChild) { |
505 scoped_refptr<Layer> parent = Layer::Create(layer_settings_); | 610 scoped_refptr<Layer> parent = Layer::Create(layer_settings_); |
506 scoped_refptr<Layer> child = Layer::Create(layer_settings_); | 611 scoped_refptr<Layer> child = Layer::Create(layer_settings_); |
507 | 612 |
508 // Upon creation, layers should not have children or parent. | 613 // Upon creation, layers should not have children or parent. |
509 ASSERT_EQ(0U, parent->children().size()); | 614 ASSERT_EQ(0U, parent->children().size()); |
510 EXPECT_FALSE(child->parent()); | 615 EXPECT_FALSE(child->parent()); |
511 | 616 |
512 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); | 617 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); |
513 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->AddChild(child)); | 618 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->AddChild(child)); |
(...skipping 1604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2118 EXPECT_EQ(MutableProperty::kNone, impl_layer->mutable_properties()); | 2223 EXPECT_EQ(MutableProperty::kNone, impl_layer->mutable_properties()); |
2119 | 2224 |
2120 test_layer->PushPropertiesTo(impl_layer.get()); | 2225 test_layer->PushPropertiesTo(impl_layer.get()); |
2121 | 2226 |
2122 EXPECT_EQ(2lu, impl_layer->element_id()); | 2227 EXPECT_EQ(2lu, impl_layer->element_id()); |
2123 EXPECT_EQ(MutableProperty::kTransform, impl_layer->mutable_properties()); | 2228 EXPECT_EQ(MutableProperty::kTransform, impl_layer->mutable_properties()); |
2124 } | 2229 } |
2125 | 2230 |
2126 } // namespace | 2231 } // namespace |
2127 } // namespace cc | 2232 } // namespace cc |
OLD | NEW |