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 "base/thread_task_runner_handle.h" | 7 #include "base/thread_task_runner_handle.h" |
8 #include "cc/animation/keyframed_animation_curve.h" | 8 #include "cc/animation/keyframed_animation_curve.h" |
9 #include "cc/base/math_util.h" | 9 #include "cc/base/math_util.h" |
10 #include "cc/layers/layer_impl.h" | 10 #include "cc/layers/layer_impl.h" |
11 #include "cc/output/copy_output_request.h" | 11 #include "cc/output/copy_output_request.h" |
12 #include "cc/output/copy_output_result.h" | 12 #include "cc/output/copy_output_result.h" |
13 #include "cc/proto/layer.pb.h" | |
13 #include "cc/test/animation_test_common.h" | 14 #include "cc/test/animation_test_common.h" |
14 #include "cc/test/fake_impl_proxy.h" | 15 #include "cc/test/fake_impl_proxy.h" |
15 #include "cc/test/fake_layer_tree_host_client.h" | 16 #include "cc/test/fake_layer_tree_host_client.h" |
16 #include "cc/test/fake_layer_tree_host_impl.h" | 17 #include "cc/test/fake_layer_tree_host_impl.h" |
17 #include "cc/test/geometry_test_utils.h" | 18 #include "cc/test/geometry_test_utils.h" |
18 #include "cc/test/layer_test_common.h" | 19 #include "cc/test/layer_test_common.h" |
19 #include "cc/test/test_gpu_memory_buffer_manager.h" | 20 #include "cc/test/test_gpu_memory_buffer_manager.h" |
20 #include "cc/test/test_shared_bitmap_manager.h" | 21 #include "cc/test/test_shared_bitmap_manager.h" |
21 #include "cc/test/test_task_graph_runner.h" | 22 #include "cc/test/test_task_graph_runner.h" |
22 #include "cc/trees/layer_tree_host.h" | 23 #include "cc/trees/layer_tree_host.h" |
(...skipping 1317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1340 layer->OnTransformAnimated(transform); | 1341 layer->OnTransformAnimated(transform); |
1341 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 1342 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
1342 | 1343 |
1343 // Scroll offset animation should not schedule a layer update since it is | 1344 // Scroll offset animation should not schedule a layer update since it is |
1344 // handled similarly to normal compositor scroll updates. | 1345 // handled similarly to normal compositor scroll updates. |
1345 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(0); | 1346 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(0); |
1346 layer->OnScrollOffsetAnimated(gfx::ScrollOffset(10, 10)); | 1347 layer->OnScrollOffsetAnimated(gfx::ScrollOffset(10, 10)); |
1347 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 1348 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
1348 } | 1349 } |
1349 | 1350 |
1351 TEST_F(LayerTest, RecursiveHierarchySerialization) { | |
1352 // Testing serialization and deserialization of a tree that looks like this: | |
1353 // root | |
1354 // / \ | |
1355 // a b | |
1356 // \ | |
1357 // c | |
1358 // Layer c also has a mask layer and a replica layer. | |
1359 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); | |
1360 scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); | |
1361 scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); | |
1362 scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings()); | |
1363 scoped_refptr<Layer> layer_src_c_mask = Layer::Create(LayerSettings()); | |
1364 scoped_refptr<Layer> layer_src_c_replica = Layer::Create(LayerSettings()); | |
1365 layer_src_root->AddChild(layer_src_a); | |
1366 layer_src_root->AddChild(layer_src_b); | |
1367 layer_src_b->AddChild(layer_src_c); | |
1368 layer_src_c->SetMaskLayer(layer_src_c_mask.get()); | |
1369 layer_src_c->SetReplicaLayer(layer_src_c_replica.get()); | |
1370 | |
1371 proto::LayerNode proto; | |
1372 layer_src_root->ToLayerNodeProto(&proto); | |
1373 | |
1374 Layer::LayerIdMap empty_dest_layer_map; | |
1375 scoped_refptr<Layer> layer_dest_root = Layer::Create(LayerSettings()); | |
1376 layer_dest_root->FromLayerNodeProto(proto, empty_dest_layer_map); | |
1377 | |
1378 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); | |
1379 EXPECT_EQ(nullptr, layer_dest_root->parent()); | |
1380 ASSERT_EQ(2UL, layer_dest_root->children().size()); | |
vmpstr
2015/10/21 22:34:14
nit: we just usually lower case u, like 2u
nyquist
2015/10/23 00:12:31
Done.
| |
1381 | |
1382 scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; | |
1383 EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); | |
1384 EXPECT_EQ(layer_src_root->id(), layer_dest_a->parent()->id()); | |
1385 EXPECT_EQ(0UL, layer_dest_a->children().size()); | |
1386 | |
1387 scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1]; | |
1388 EXPECT_EQ(layer_src_b->id(), layer_dest_b->id()); | |
1389 EXPECT_EQ(layer_src_root->id(), layer_dest_b->parent()->id()); | |
1390 ASSERT_EQ(1UL, layer_dest_b->children().size()); | |
1391 | |
1392 scoped_refptr<Layer> layer_dest_c = layer_dest_b->children()[0]; | |
1393 EXPECT_EQ(layer_src_c->id(), layer_dest_c->id()); | |
1394 EXPECT_EQ(layer_src_b->id(), layer_dest_c->parent()->id()); | |
1395 EXPECT_EQ(0UL, layer_dest_c->children().size()); | |
1396 EXPECT_EQ(layer_src_c_mask->id(), layer_dest_c->mask_layer()->id()); | |
1397 EXPECT_EQ(layer_src_c_replica->id(), layer_dest_c->replica_layer()->id()); | |
1398 } | |
1399 | |
1400 TEST_F(LayerTest, RecursiveHierarchySerializationWithNodeReuse) { | |
1401 // Testing serialization and deserialization of a tree that initially looks | |
1402 // like this: | |
1403 // root | |
1404 // / | |
1405 // a | |
1406 // The source tree is then updated by adding layer |b|: | |
1407 // root | |
1408 // / \ | |
1409 // a b | |
1410 // The deserialization should then re-use the Layers from last | |
1411 // deserialization. | |
1412 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); | |
1413 scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); | |
1414 layer_src_root->AddChild(layer_src_a); | |
1415 | |
1416 proto::LayerNode root_proto_1; | |
1417 layer_src_root->ToLayerNodeProto(&root_proto_1); | |
1418 | |
1419 Layer::LayerIdMap dest_layer_map_1; | |
1420 scoped_refptr<Layer> layer_dest_root = Layer::Create(LayerSettings()); | |
1421 layer_dest_root->FromLayerNodeProto(root_proto_1, dest_layer_map_1); | |
1422 | |
1423 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); | |
1424 ASSERT_EQ(1UL, layer_dest_root->children().size()); | |
1425 scoped_refptr<Layer> layer_dest_a_1 = layer_dest_root->children()[0]; | |
1426 EXPECT_EQ(layer_src_a->id(), layer_dest_a_1->id()); | |
1427 | |
1428 // Setup new destination layer map. | |
1429 Layer::LayerIdMap dest_layer_map_2; | |
1430 dest_layer_map_2[layer_dest_root->id()] = layer_dest_root; | |
1431 dest_layer_map_2[layer_dest_a_1->id()] = layer_dest_a_1; | |
1432 | |
1433 // Add Layer |b|. | |
1434 scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); | |
1435 layer_src_root->AddChild(layer_src_b); | |
1436 | |
1437 // Second serialization. | |
1438 proto::LayerNode root_proto_2; | |
1439 layer_src_root->ToLayerNodeProto(&root_proto_2); | |
1440 | |
1441 // Second deserialization. | |
1442 layer_dest_root->FromLayerNodeProto(root_proto_2, dest_layer_map_2); | |
1443 | |
1444 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); | |
1445 ASSERT_EQ(2UL, layer_dest_root->children().size()); | |
1446 | |
1447 scoped_refptr<Layer> layer_dest_a_2 = layer_dest_root->children()[0]; | |
1448 EXPECT_EQ(layer_src_a->id(), layer_dest_a_2->id()); | |
1449 EXPECT_EQ(layer_src_root->id(), layer_dest_a_2->parent()->id()); | |
1450 EXPECT_EQ(0UL, layer_dest_a_2->children().size()); | |
1451 | |
1452 scoped_refptr<Layer> layer_dest_b_2 = layer_dest_root->children()[1]; | |
1453 EXPECT_EQ(layer_src_b->id(), layer_dest_b_2->id()); | |
1454 EXPECT_EQ(layer_src_root->id(), layer_dest_b_2->parent()->id()); | |
1455 EXPECT_EQ(0UL, layer_dest_b_2->children().size()); | |
1456 | |
1457 // Layer |a| should be the same. | |
1458 EXPECT_EQ(layer_dest_a_1.get(), layer_dest_a_2.get()); | |
1459 } | |
1460 | |
1461 TEST_F(LayerTest, DeletingSubtreeDeletesLayers) { | |
1462 // Testing serialization and deserialization of a tree that initially | |
1463 // looks like this: | |
1464 // root | |
1465 // / \ | |
1466 // a b | |
1467 // \ | |
1468 // c | |
1469 // \ | |
1470 // d | |
1471 // Then the subtree rooted at node |b| is deleted in the next update. | |
1472 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); | |
1473 scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); | |
1474 scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); | |
1475 scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings()); | |
1476 scoped_refptr<Layer> layer_src_d = Layer::Create(LayerSettings()); | |
1477 layer_src_root->AddChild(layer_src_a); | |
1478 layer_src_root->AddChild(layer_src_b); | |
1479 layer_src_b->AddChild(layer_src_c); | |
1480 layer_src_c->AddChild(layer_src_d); | |
1481 | |
1482 // Serialization 1. | |
1483 proto::LayerNode proto1; | |
1484 layer_src_root->ToLayerNodeProto(&proto1); | |
1485 | |
1486 // Deserialization 1. | |
1487 Layer::LayerIdMap empty_dest_layer_map; | |
1488 scoped_refptr<Layer> layer_dest_root = Layer::Create(LayerSettings()); | |
1489 layer_dest_root->FromLayerNodeProto(proto1, empty_dest_layer_map); | |
1490 | |
1491 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); | |
1492 ASSERT_EQ(2UL, layer_dest_root->children().size()); | |
1493 scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; | |
1494 scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1]; | |
1495 ASSERT_EQ(1UL, layer_dest_b->children().size()); | |
1496 scoped_refptr<Layer> layer_dest_c = layer_dest_b->children()[0]; | |
1497 ASSERT_EQ(1UL, layer_dest_c->children().size()); | |
1498 scoped_refptr<Layer> layer_dest_d = layer_dest_c->children()[0]; | |
1499 | |
1500 // Delete the Layer |b| subtree. | |
1501 layer_src_b->RemoveAllChildren(); | |
1502 | |
1503 // Serialization 2. | |
1504 proto::LayerNode proto2; | |
1505 layer_src_root->ToLayerNodeProto(&proto2); | |
1506 | |
1507 // Deserialization 2. | |
1508 Layer::LayerIdMap dest_layer_map_2; | |
1509 dest_layer_map_2[layer_dest_root->id()] = layer_dest_root; | |
1510 dest_layer_map_2[layer_dest_a->id()] = layer_dest_a; | |
1511 dest_layer_map_2[layer_dest_b->id()] = layer_dest_b; | |
1512 layer_dest_root->FromLayerNodeProto(proto2, dest_layer_map_2); | |
1513 | |
1514 EXPECT_EQ(0UL, layer_dest_a->children().size()); | |
1515 EXPECT_EQ(0UL, layer_dest_b->children().size()); | |
1516 } | |
1517 | |
1518 TEST_F(LayerTest, DeleteMaskAndReplicaLayer) { | |
1519 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); | |
1520 scoped_refptr<Layer> layer_src_mask = Layer::Create(LayerSettings()); | |
1521 scoped_refptr<Layer> layer_src_replica = Layer::Create(LayerSettings()); | |
1522 layer_src_root->SetMaskLayer(layer_src_mask.get()); | |
1523 layer_src_root->SetReplicaLayer(layer_src_replica.get()); | |
1524 | |
1525 // Serialization 1. | |
1526 proto::LayerNode proto1; | |
1527 layer_src_root->ToLayerNodeProto(&proto1); | |
1528 | |
1529 // Deserialization 1. | |
1530 Layer::LayerIdMap dest_layer_map; | |
1531 scoped_refptr<Layer> layer_dest_root = Layer::Create(LayerSettings()); | |
1532 layer_dest_root->FromLayerNodeProto(proto1, dest_layer_map); | |
1533 | |
1534 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); | |
1535 ASSERT_TRUE(layer_dest_root->mask_layer()); | |
1536 ASSERT_TRUE(layer_dest_root->replica_layer()); | |
1537 EXPECT_EQ(layer_src_root->mask_layer()->id(), | |
1538 layer_dest_root->mask_layer()->id()); | |
1539 EXPECT_EQ(layer_src_root->replica_layer()->id(), | |
1540 layer_dest_root->replica_layer()->id()); | |
1541 | |
1542 // Store the newly constructed layer structure in the id map. | |
1543 dest_layer_map[layer_dest_root->id()] = layer_dest_root; | |
1544 dest_layer_map[layer_dest_root->mask_layer()->id()] = | |
1545 layer_dest_root->mask_layer(); | |
1546 dest_layer_map[layer_dest_root->replica_layer()->id()] = | |
1547 layer_dest_root->replica_layer(); | |
1548 | |
1549 // Clear mask and replica layers. | |
1550 layer_src_root->mask_layer()->RemoveFromParent(); | |
1551 layer_src_root->replica_layer()->RemoveFromParent(); | |
1552 | |
1553 // Serialization 2. | |
1554 proto::LayerNode proto2; | |
1555 layer_src_root->ToLayerNodeProto(&proto2); | |
1556 | |
1557 // Deserialization 2. | |
1558 layer_dest_root->FromLayerNodeProto(proto2, dest_layer_map); | |
1559 | |
1560 EXPECT_EQ(nullptr, layer_dest_root->mask_layer()); | |
1561 EXPECT_EQ(nullptr, layer_dest_root->replica_layer()); | |
1562 } | |
1563 | |
1350 } // namespace | 1564 } // namespace |
1351 } // namespace cc | 1565 } // namespace cc |
OLD | NEW |