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