| 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/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "cc/animation/animation_host.h" | 10 #include "cc/animation/animation_host.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 using ::testing::StrictMock; | 49 using ::testing::StrictMock; |
| 50 using ::testing::_; | 50 using ::testing::_; |
| 51 | 51 |
| 52 #define EXPECT_SET_NEEDS_FULL_TREE_SYNC(expect, code_to_test) \ | 52 #define EXPECT_SET_NEEDS_FULL_TREE_SYNC(expect, code_to_test) \ |
| 53 do { \ | 53 do { \ |
| 54 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times((expect)); \ | 54 EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times((expect)); \ |
| 55 code_to_test; \ | 55 code_to_test; \ |
| 56 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \ | 56 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \ |
| 57 } while (false) | 57 } while (false) |
| 58 | 58 |
| 59 #define EXECUTE_AND_VERIFY_SUBTREE_CHANGED(code_to_test) \ | 59 #define EXECUTE_AND_VERIFY_SUBTREE_CHANGED(code_to_test) \ |
| 60 code_to_test; \ | 60 code_to_test; \ |
| 61 root->layer_tree_host()->BuildPropertyTreesForTesting(); \ | 61 root->layer_tree_host()->BuildPropertyTreesForTesting(); \ |
| 62 EXPECT_TRUE(root->subtree_property_changed()); \ | 62 EXPECT_TRUE(root->subtree_property_changed()); \ |
| 63 EXPECT_TRUE(root->layer_tree_host()->LayerNeedsPushPropertiesForTesting( \ | 63 EXPECT_TRUE( \ |
| 64 root.get())); \ | 64 root->GetLayerTree()->LayerNeedsPushPropertiesForTesting(root.get())); \ |
| 65 EXPECT_TRUE(child->subtree_property_changed()); \ | 65 EXPECT_TRUE(child->subtree_property_changed()); \ |
| 66 EXPECT_TRUE(child->layer_tree_host()->LayerNeedsPushPropertiesForTesting( \ | 66 EXPECT_TRUE( \ |
| 67 child.get())); \ | 67 child->GetLayerTree()->LayerNeedsPushPropertiesForTesting(child.get())); \ |
| 68 EXPECT_TRUE(grand_child->subtree_property_changed()); \ | 68 EXPECT_TRUE(grand_child->subtree_property_changed()); \ |
| 69 EXPECT_TRUE( \ | 69 EXPECT_TRUE(grand_child->GetLayerTree()->LayerNeedsPushPropertiesForTesting( \ |
| 70 grand_child->layer_tree_host()->LayerNeedsPushPropertiesForTesting( \ | 70 grand_child.get())); |
| 71 |
| 72 #define EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET(code_to_test) \ |
| 73 code_to_test; \ |
| 74 EXPECT_FALSE(root->subtree_property_changed()); \ |
| 75 EXPECT_FALSE( \ |
| 76 root->GetLayerTree()->LayerNeedsPushPropertiesForTesting(root.get())); \ |
| 77 EXPECT_FALSE(child->subtree_property_changed()); \ |
| 78 EXPECT_FALSE( \ |
| 79 child->GetLayerTree()->LayerNeedsPushPropertiesForTesting(child.get())); \ |
| 80 EXPECT_FALSE(grand_child->subtree_property_changed()); \ |
| 81 EXPECT_FALSE( \ |
| 82 grand_child->GetLayerTree()->LayerNeedsPushPropertiesForTesting( \ |
| 71 grand_child.get())); | 83 grand_child.get())); |
| 72 | 84 |
| 73 #define EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET(code_to_test) \ | 85 #define EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(code_to_test) \ |
| 74 code_to_test; \ | 86 code_to_test; \ |
| 75 EXPECT_FALSE(root->subtree_property_changed()); \ | 87 root->layer_tree_host()->BuildPropertyTreesForTesting(); \ |
| 76 EXPECT_FALSE(root->layer_tree_host()->LayerNeedsPushPropertiesForTesting( \ | 88 EXPECT_TRUE(root->layer_property_changed()); \ |
| 77 root.get())); \ | 89 EXPECT_FALSE(root->subtree_property_changed()); \ |
| 78 EXPECT_FALSE(child->subtree_property_changed()); \ | 90 EXPECT_TRUE( \ |
| 79 EXPECT_FALSE(child->layer_tree_host()->LayerNeedsPushPropertiesForTesting( \ | 91 root->GetLayerTree()->LayerNeedsPushPropertiesForTesting(root.get())); \ |
| 80 child.get())); \ | 92 EXPECT_FALSE(child->layer_property_changed()); \ |
| 81 EXPECT_FALSE(grand_child->subtree_property_changed()); \ | 93 EXPECT_FALSE(child->subtree_property_changed()); \ |
| 82 EXPECT_FALSE( \ | 94 EXPECT_FALSE( \ |
| 83 grand_child->layer_tree_host()->LayerNeedsPushPropertiesForTesting( \ | 95 child->GetLayerTree()->LayerNeedsPushPropertiesForTesting(child.get())); \ |
| 84 grand_child.get())); | 96 EXPECT_FALSE(grand_child->layer_property_changed()); \ |
| 85 | 97 EXPECT_FALSE(grand_child->subtree_property_changed()); \ |
| 86 #define EXECUTE_AND_VERIFY_ONLY_LAYER_CHANGED(code_to_test) \ | 98 EXPECT_FALSE( \ |
| 87 code_to_test; \ | 99 grand_child->GetLayerTree()->LayerNeedsPushPropertiesForTesting( \ |
| 88 root->layer_tree_host()->BuildPropertyTreesForTesting(); \ | |
| 89 EXPECT_TRUE(root->layer_property_changed()); \ | |
| 90 EXPECT_FALSE(root->subtree_property_changed()); \ | |
| 91 EXPECT_TRUE(root->layer_tree_host()->LayerNeedsPushPropertiesForTesting( \ | |
| 92 root.get())); \ | |
| 93 EXPECT_FALSE(child->layer_property_changed()); \ | |
| 94 EXPECT_FALSE(child->subtree_property_changed()); \ | |
| 95 EXPECT_FALSE(child->layer_tree_host()->LayerNeedsPushPropertiesForTesting( \ | |
| 96 child.get())); \ | |
| 97 EXPECT_FALSE(grand_child->layer_property_changed()); \ | |
| 98 EXPECT_FALSE(grand_child->subtree_property_changed()); \ | |
| 99 EXPECT_FALSE( \ | |
| 100 grand_child->layer_tree_host()->LayerNeedsPushPropertiesForTesting( \ | |
| 101 grand_child.get())); | 100 grand_child.get())); |
| 102 | 101 |
| 103 namespace cc { | 102 namespace cc { |
| 104 | 103 |
| 105 // This class is a friend of Layer, and is used as a wrapper for all the tests | 104 // This class is a friend of Layer, and is used as a wrapper for all the tests |
| 106 // related to proto serialization. This is done so that it is unnecessary to | 105 // related to proto serialization. This is done so that it is unnecessary to |
| 107 // add FRIEND_TEST_ALL_PREFIXES in //cc/layers/layer.h for all the tests. | 106 // add FRIEND_TEST_ALL_PREFIXES in //cc/layers/layer.h for all the tests. |
| 108 // It is in the cc namespace so that it can be a friend of Layer. | 107 // It is in the cc namespace so that it can be a friend of Layer. |
| 109 // The tests still have helpful names, and a test with the name FooBar would | 108 // The tests still have helpful names, and a test with the name FooBar would |
| 110 // have a wrapper method in this class called RunFooBarTest. | 109 // have a wrapper method in this class called RunFooBarTest. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 133 | 132 |
| 134 // Serialize |src| to protobuf and read the first entry in the | 133 // Serialize |src| to protobuf and read the first entry in the |
| 135 // LayerUpdate. There are no descendants, so the serialization | 134 // LayerUpdate. There are no descendants, so the serialization |
| 136 // of |src| is the only entry. | 135 // of |src| is the only entry. |
| 137 proto::LayerUpdate layer_update; | 136 proto::LayerUpdate layer_update; |
| 138 src->ToLayerPropertiesProto(&layer_update); | 137 src->ToLayerPropertiesProto(&layer_update); |
| 139 ASSERT_EQ(1, layer_update.layers_size()); | 138 ASSERT_EQ(1, layer_update.layers_size()); |
| 140 proto::LayerProperties props = layer_update.layers(0); | 139 proto::LayerProperties props = layer_update.layers(0); |
| 141 | 140 |
| 142 // The |dest| layer needs to be able to lookup the scroll and clip parents. | 141 // The |dest| layer needs to be able to lookup the scroll and clip parents. |
| 142 LayerTree* layer_tree = layer_tree_host_->GetLayerTree(); |
| 143 if (src->inputs_.scroll_parent) | 143 if (src->inputs_.scroll_parent) |
| 144 layer_tree_host_->RegisterLayer(src->inputs_.scroll_parent); | 144 layer_tree->RegisterLayer(src->inputs_.scroll_parent); |
| 145 if (src->scroll_children_) { | 145 if (src->scroll_children_) { |
| 146 for (auto* child : *(src->scroll_children_)) | 146 for (auto* child : *(src->scroll_children_)) |
| 147 layer_tree_host_->RegisterLayer(child); | 147 layer_tree->RegisterLayer(child); |
| 148 } | 148 } |
| 149 if (src->inputs_.clip_parent) | 149 if (src->inputs_.clip_parent) |
| 150 layer_tree_host_->RegisterLayer(src->inputs_.clip_parent); | 150 layer_tree->RegisterLayer(src->inputs_.clip_parent); |
| 151 if (src->clip_children_) { | 151 if (src->clip_children_) { |
| 152 for (auto* child : *(src->clip_children_)) | 152 for (auto* child : *(src->clip_children_)) |
| 153 layer_tree_host_->RegisterLayer(child); | 153 layer_tree->RegisterLayer(child); |
| 154 } | 154 } |
| 155 // Reset the LayerTreeHost registration for the |src| layer so | 155 // Reset the LayerTreeHost registration for the |src| layer so |
| 156 // it can be re-used for the |dest| layer. | 156 // it can be re-used for the |dest| layer. |
| 157 src->SetLayerTreeHost(nullptr); | 157 src->SetLayerTreeHost(nullptr); |
| 158 | 158 |
| 159 scoped_refptr<Layer> dest = Layer::Create(); | 159 scoped_refptr<Layer> dest = Layer::Create(); |
| 160 dest->inputs_.layer_id = src->inputs_.layer_id; | 160 dest->inputs_.layer_id = src->inputs_.layer_id; |
| 161 dest->SetLayerTreeHost(layer_tree_host_.get()); | 161 dest->SetLayerTreeHost(layer_tree_host_.get()); |
| 162 dest->FromLayerPropertiesProto(props); | 162 dest->FromLayerPropertiesProto(props); |
| 163 | 163 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 } | 241 } |
| 242 | 242 |
| 243 // The following member should have been reset during serialization. | 243 // The following member should have been reset during serialization. |
| 244 EXPECT_EQ(gfx::Rect(), src->inputs_.update_rect); | 244 EXPECT_EQ(gfx::Rect(), src->inputs_.update_rect); |
| 245 | 245 |
| 246 // Before deleting |dest|, the LayerTreeHost must be unset. | 246 // Before deleting |dest|, the LayerTreeHost must be unset. |
| 247 dest->SetLayerTreeHost(nullptr); | 247 dest->SetLayerTreeHost(nullptr); |
| 248 | 248 |
| 249 // Cleanup scroll tree. | 249 // Cleanup scroll tree. |
| 250 if (src->inputs_.scroll_parent) | 250 if (src->inputs_.scroll_parent) |
| 251 layer_tree_host_->UnregisterLayer(src->inputs_.scroll_parent); | 251 layer_tree->UnregisterLayer(src->inputs_.scroll_parent); |
| 252 src->inputs_.scroll_parent = nullptr; | 252 src->inputs_.scroll_parent = nullptr; |
| 253 dest->inputs_.scroll_parent = nullptr; | 253 dest->inputs_.scroll_parent = nullptr; |
| 254 if (src->scroll_children_) { | 254 if (src->scroll_children_) { |
| 255 for (auto* child : *(src->scroll_children_)) | 255 for (auto* child : *(src->scroll_children_)) |
| 256 layer_tree_host_->UnregisterLayer(child); | 256 layer_tree->UnregisterLayer(child); |
| 257 src->scroll_children_.reset(); | 257 src->scroll_children_.reset(); |
| 258 dest->scroll_children_.reset(); | 258 dest->scroll_children_.reset(); |
| 259 } | 259 } |
| 260 | 260 |
| 261 // Cleanup clip tree. | 261 // Cleanup clip tree. |
| 262 if (src->inputs_.clip_parent) | 262 if (src->inputs_.clip_parent) |
| 263 layer_tree_host_->UnregisterLayer(src->inputs_.clip_parent); | 263 layer_tree->UnregisterLayer(src->inputs_.clip_parent); |
| 264 src->inputs_.clip_parent = nullptr; | 264 src->inputs_.clip_parent = nullptr; |
| 265 dest->inputs_.clip_parent = nullptr; | 265 dest->inputs_.clip_parent = nullptr; |
| 266 if (src->clip_children_) { | 266 if (src->clip_children_) { |
| 267 for (auto* child : *(src->clip_children_)) | 267 for (auto* child : *(src->clip_children_)) |
| 268 layer_tree_host_->UnregisterLayer(child); | 268 layer_tree->UnregisterLayer(child); |
| 269 src->clip_children_.reset(); | 269 src->clip_children_.reset(); |
| 270 dest->clip_children_.reset(); | 270 dest->clip_children_.reset(); |
| 271 } | 271 } |
| 272 } | 272 } |
| 273 | 273 |
| 274 void RunNoMembersChangedTest() { | 274 void RunNoMembersChangedTest() { |
| 275 scoped_refptr<Layer> layer = Layer::Create(); | 275 scoped_refptr<Layer> layer = Layer::Create(); |
| 276 VerifyBaseLayerPropertiesSerializationAndDeserialization(layer.get()); | 276 VerifyBaseLayerPropertiesSerializationAndDeserialization(layer.get()); |
| 277 } | 277 } |
| 278 | 278 |
| (...skipping 1123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1402 | 1402 |
| 1403 EXPECT_SET_NEEDS_COMMIT(2, child1->SetScrollParent(child2.get())); | 1403 EXPECT_SET_NEEDS_COMMIT(2, child1->SetScrollParent(child2.get())); |
| 1404 | 1404 |
| 1405 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, child2->RemoveFromParent()); | 1405 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, child2->RemoveFromParent()); |
| 1406 | 1406 |
| 1407 child1->ResetNeedsPushPropertiesForTesting(); | 1407 child1->ResetNeedsPushPropertiesForTesting(); |
| 1408 | 1408 |
| 1409 EXPECT_SET_NEEDS_COMMIT(1, child2 = nullptr); | 1409 EXPECT_SET_NEEDS_COMMIT(1, child2 = nullptr); |
| 1410 | 1410 |
| 1411 EXPECT_TRUE( | 1411 EXPECT_TRUE( |
| 1412 layer_tree_host_->LayerNeedsPushPropertiesForTesting(child1.get())); | 1412 layer_tree_host_->GetLayerTree()->LayerNeedsPushPropertiesForTesting( |
| 1413 child1.get())); |
| 1413 | 1414 |
| 1414 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); | 1415 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); |
| 1415 } | 1416 } |
| 1416 | 1417 |
| 1417 TEST_F(LayerTest, DeleteRemovedScrollChild) { | 1418 TEST_F(LayerTest, DeleteRemovedScrollChild) { |
| 1418 scoped_refptr<Layer> parent = Layer::Create(); | 1419 scoped_refptr<Layer> parent = Layer::Create(); |
| 1419 scoped_refptr<Layer> child1 = Layer::Create(); | 1420 scoped_refptr<Layer> child1 = Layer::Create(); |
| 1420 scoped_refptr<Layer> child2 = Layer::Create(); | 1421 scoped_refptr<Layer> child2 = Layer::Create(); |
| 1421 | 1422 |
| 1422 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); | 1423 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); |
| 1423 | 1424 |
| 1424 ASSERT_EQ(0U, parent->children().size()); | 1425 ASSERT_EQ(0U, parent->children().size()); |
| 1425 | 1426 |
| 1426 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child1, 0)); | 1427 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child1, 0)); |
| 1427 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child2, 1)); | 1428 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->InsertChild(child2, 1)); |
| 1428 | 1429 |
| 1429 ASSERT_EQ(2U, parent->children().size()); | 1430 ASSERT_EQ(2U, parent->children().size()); |
| 1430 EXPECT_EQ(child1, parent->children()[0]); | 1431 EXPECT_EQ(child1, parent->children()[0]); |
| 1431 EXPECT_EQ(child2, parent->children()[1]); | 1432 EXPECT_EQ(child2, parent->children()[1]); |
| 1432 | 1433 |
| 1433 EXPECT_SET_NEEDS_COMMIT(2, child1->SetScrollParent(child2.get())); | 1434 EXPECT_SET_NEEDS_COMMIT(2, child1->SetScrollParent(child2.get())); |
| 1434 | 1435 |
| 1435 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, child1->RemoveFromParent()); | 1436 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, child1->RemoveFromParent()); |
| 1436 | 1437 |
| 1437 child2->ResetNeedsPushPropertiesForTesting(); | 1438 child2->ResetNeedsPushPropertiesForTesting(); |
| 1438 | 1439 |
| 1439 EXPECT_SET_NEEDS_COMMIT(1, child1 = nullptr); | 1440 EXPECT_SET_NEEDS_COMMIT(1, child1 = nullptr); |
| 1440 | 1441 |
| 1441 EXPECT_TRUE( | 1442 EXPECT_TRUE( |
| 1442 layer_tree_host_->LayerNeedsPushPropertiesForTesting(child2.get())); | 1443 layer_tree_host_->GetLayerTree()->LayerNeedsPushPropertiesForTesting( |
| 1444 child2.get())); |
| 1443 | 1445 |
| 1444 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); | 1446 EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); |
| 1445 } | 1447 } |
| 1446 | 1448 |
| 1447 TEST_F(LayerTest, ReplaceChildWithSameChild) { | 1449 TEST_F(LayerTest, ReplaceChildWithSameChild) { |
| 1448 CreateSimpleTestTree(); | 1450 CreateSimpleTestTree(); |
| 1449 | 1451 |
| 1450 // SetNeedsFullTreeSync / SetNeedsCommit should not be called because its the | 1452 // SetNeedsFullTreeSync / SetNeedsCommit should not be called because its the |
| 1451 // same child. | 1453 // same child. |
| 1452 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); | 1454 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); |
| (...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2531 EXPECT_EQ(MutableProperty::kNone, impl_layer->mutable_properties()); | 2533 EXPECT_EQ(MutableProperty::kNone, impl_layer->mutable_properties()); |
| 2532 | 2534 |
| 2533 test_layer->PushPropertiesTo(impl_layer.get()); | 2535 test_layer->PushPropertiesTo(impl_layer.get()); |
| 2534 | 2536 |
| 2535 EXPECT_EQ(ElementId(2, 0), impl_layer->element_id()); | 2537 EXPECT_EQ(ElementId(2, 0), impl_layer->element_id()); |
| 2536 EXPECT_EQ(MutableProperty::kTransform, impl_layer->mutable_properties()); | 2538 EXPECT_EQ(MutableProperty::kTransform, impl_layer->mutable_properties()); |
| 2537 } | 2539 } |
| 2538 | 2540 |
| 2539 } // namespace | 2541 } // namespace |
| 2540 } // namespace cc | 2542 } // namespace cc |
| OLD | NEW |