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 */ |
| 1360 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); |
| 1361 scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); |
| 1362 scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); |
| 1363 scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings()); |
| 1364 scoped_refptr<Layer> layer_src_c_mask = Layer::Create(LayerSettings()); |
| 1365 scoped_refptr<Layer> layer_src_c_replica = Layer::Create(LayerSettings()); |
| 1366 layer_src_root->AddChild(layer_src_a); |
| 1367 layer_src_root->AddChild(layer_src_b); |
| 1368 layer_src_b->AddChild(layer_src_c); |
| 1369 layer_src_c->SetMaskLayer(layer_src_c_mask.get()); |
| 1370 layer_src_c->SetReplicaLayer(layer_src_c_replica.get()); |
| 1371 |
| 1372 proto::LayerNode proto; |
| 1373 layer_src_root->ToLayerNodeProto(&proto); |
| 1374 |
| 1375 Layer::LayerIdMap empty_dest_layer_map; |
| 1376 scoped_refptr<Layer> layer_dest_root = Layer::Create(LayerSettings()); |
| 1377 layer_dest_root->FromLayerNodeProto(proto, empty_dest_layer_map); |
| 1378 |
| 1379 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); |
| 1380 EXPECT_EQ(nullptr, layer_dest_root->parent()); |
| 1381 ASSERT_EQ(2u, layer_dest_root->children().size()); |
| 1382 |
| 1383 scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; |
| 1384 EXPECT_EQ(layer_src_a->id(), layer_dest_a->id()); |
| 1385 EXPECT_EQ(layer_src_root->id(), layer_dest_a->parent()->id()); |
| 1386 EXPECT_EQ(0u, layer_dest_a->children().size()); |
| 1387 |
| 1388 scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1]; |
| 1389 EXPECT_EQ(layer_src_b->id(), layer_dest_b->id()); |
| 1390 EXPECT_EQ(layer_src_root->id(), layer_dest_b->parent()->id()); |
| 1391 ASSERT_EQ(1u, layer_dest_b->children().size()); |
| 1392 |
| 1393 scoped_refptr<Layer> layer_dest_c = layer_dest_b->children()[0]; |
| 1394 EXPECT_EQ(layer_src_c->id(), layer_dest_c->id()); |
| 1395 EXPECT_EQ(layer_src_b->id(), layer_dest_c->parent()->id()); |
| 1396 EXPECT_EQ(0u, layer_dest_c->children().size()); |
| 1397 EXPECT_EQ(layer_src_c_mask->id(), layer_dest_c->mask_layer()->id()); |
| 1398 EXPECT_EQ(layer_src_c_replica->id(), layer_dest_c->replica_layer()->id()); |
| 1399 } |
| 1400 |
| 1401 TEST_F(LayerTest, RecursiveHierarchySerializationWithNodeReuse) { |
| 1402 /* Testing serialization and deserialization of a tree that initially looks |
| 1403 like this: |
| 1404 root |
| 1405 / |
| 1406 a |
| 1407 The source tree is then updated by adding layer |b|: |
| 1408 root |
| 1409 / \ |
| 1410 a b |
| 1411 The deserialization should then re-use the Layers from last |
| 1412 deserialization. |
| 1413 */ |
| 1414 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); |
| 1415 scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); |
| 1416 layer_src_root->AddChild(layer_src_a); |
| 1417 |
| 1418 proto::LayerNode root_proto_1; |
| 1419 layer_src_root->ToLayerNodeProto(&root_proto_1); |
| 1420 |
| 1421 Layer::LayerIdMap dest_layer_map_1; |
| 1422 scoped_refptr<Layer> layer_dest_root = Layer::Create(LayerSettings()); |
| 1423 layer_dest_root->FromLayerNodeProto(root_proto_1, dest_layer_map_1); |
| 1424 |
| 1425 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); |
| 1426 ASSERT_EQ(1u, layer_dest_root->children().size()); |
| 1427 scoped_refptr<Layer> layer_dest_a_1 = layer_dest_root->children()[0]; |
| 1428 EXPECT_EQ(layer_src_a->id(), layer_dest_a_1->id()); |
| 1429 |
| 1430 // Setup new destination layer map. |
| 1431 Layer::LayerIdMap dest_layer_map_2; |
| 1432 dest_layer_map_2[layer_dest_root->id()] = layer_dest_root; |
| 1433 dest_layer_map_2[layer_dest_a_1->id()] = layer_dest_a_1; |
| 1434 |
| 1435 // Add Layer |b|. |
| 1436 scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); |
| 1437 layer_src_root->AddChild(layer_src_b); |
| 1438 |
| 1439 // Second serialization. |
| 1440 proto::LayerNode root_proto_2; |
| 1441 layer_src_root->ToLayerNodeProto(&root_proto_2); |
| 1442 |
| 1443 // Second deserialization. |
| 1444 layer_dest_root->FromLayerNodeProto(root_proto_2, dest_layer_map_2); |
| 1445 |
| 1446 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); |
| 1447 ASSERT_EQ(2u, layer_dest_root->children().size()); |
| 1448 |
| 1449 scoped_refptr<Layer> layer_dest_a_2 = layer_dest_root->children()[0]; |
| 1450 EXPECT_EQ(layer_src_a->id(), layer_dest_a_2->id()); |
| 1451 EXPECT_EQ(layer_src_root->id(), layer_dest_a_2->parent()->id()); |
| 1452 EXPECT_EQ(0u, layer_dest_a_2->children().size()); |
| 1453 |
| 1454 scoped_refptr<Layer> layer_dest_b_2 = layer_dest_root->children()[1]; |
| 1455 EXPECT_EQ(layer_src_b->id(), layer_dest_b_2->id()); |
| 1456 EXPECT_EQ(layer_src_root->id(), layer_dest_b_2->parent()->id()); |
| 1457 EXPECT_EQ(0u, layer_dest_b_2->children().size()); |
| 1458 |
| 1459 // Layer |a| should be the same. |
| 1460 EXPECT_EQ(layer_dest_a_1.get(), layer_dest_a_2.get()); |
| 1461 } |
| 1462 |
| 1463 TEST_F(LayerTest, DeletingSubtreeDeletesLayers) { |
| 1464 /* Testing serialization and deserialization of a tree that initially |
| 1465 looks like this: |
| 1466 root |
| 1467 / \ |
| 1468 a b |
| 1469 \ |
| 1470 c |
| 1471 \ |
| 1472 d |
| 1473 Then the subtree rooted at node |b| is deleted in the next update. |
| 1474 */ |
| 1475 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); |
| 1476 scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings()); |
| 1477 scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings()); |
| 1478 scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings()); |
| 1479 scoped_refptr<Layer> layer_src_d = Layer::Create(LayerSettings()); |
| 1480 layer_src_root->AddChild(layer_src_a); |
| 1481 layer_src_root->AddChild(layer_src_b); |
| 1482 layer_src_b->AddChild(layer_src_c); |
| 1483 layer_src_c->AddChild(layer_src_d); |
| 1484 |
| 1485 // Serialization 1. |
| 1486 proto::LayerNode proto1; |
| 1487 layer_src_root->ToLayerNodeProto(&proto1); |
| 1488 |
| 1489 // Deserialization 1. |
| 1490 Layer::LayerIdMap empty_dest_layer_map; |
| 1491 scoped_refptr<Layer> layer_dest_root = Layer::Create(LayerSettings()); |
| 1492 layer_dest_root->FromLayerNodeProto(proto1, empty_dest_layer_map); |
| 1493 |
| 1494 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); |
| 1495 ASSERT_EQ(2u, layer_dest_root->children().size()); |
| 1496 scoped_refptr<Layer> layer_dest_a = layer_dest_root->children()[0]; |
| 1497 scoped_refptr<Layer> layer_dest_b = layer_dest_root->children()[1]; |
| 1498 ASSERT_EQ(1u, layer_dest_b->children().size()); |
| 1499 scoped_refptr<Layer> layer_dest_c = layer_dest_b->children()[0]; |
| 1500 ASSERT_EQ(1u, layer_dest_c->children().size()); |
| 1501 scoped_refptr<Layer> layer_dest_d = layer_dest_c->children()[0]; |
| 1502 |
| 1503 // Delete the Layer |b| subtree. |
| 1504 layer_src_b->RemoveAllChildren(); |
| 1505 |
| 1506 // Serialization 2. |
| 1507 proto::LayerNode proto2; |
| 1508 layer_src_root->ToLayerNodeProto(&proto2); |
| 1509 |
| 1510 // Deserialization 2. |
| 1511 Layer::LayerIdMap dest_layer_map_2; |
| 1512 dest_layer_map_2[layer_dest_root->id()] = layer_dest_root; |
| 1513 dest_layer_map_2[layer_dest_a->id()] = layer_dest_a; |
| 1514 dest_layer_map_2[layer_dest_b->id()] = layer_dest_b; |
| 1515 layer_dest_root->FromLayerNodeProto(proto2, dest_layer_map_2); |
| 1516 |
| 1517 EXPECT_EQ(0u, layer_dest_a->children().size()); |
| 1518 EXPECT_EQ(0u, layer_dest_b->children().size()); |
| 1519 } |
| 1520 |
| 1521 TEST_F(LayerTest, DeleteMaskAndReplicaLayer) { |
| 1522 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings()); |
| 1523 scoped_refptr<Layer> layer_src_mask = Layer::Create(LayerSettings()); |
| 1524 scoped_refptr<Layer> layer_src_replica = Layer::Create(LayerSettings()); |
| 1525 layer_src_root->SetMaskLayer(layer_src_mask.get()); |
| 1526 layer_src_root->SetReplicaLayer(layer_src_replica.get()); |
| 1527 |
| 1528 // Serialization 1. |
| 1529 proto::LayerNode proto1; |
| 1530 layer_src_root->ToLayerNodeProto(&proto1); |
| 1531 |
| 1532 // Deserialization 1. |
| 1533 Layer::LayerIdMap dest_layer_map; |
| 1534 scoped_refptr<Layer> layer_dest_root = Layer::Create(LayerSettings()); |
| 1535 layer_dest_root->FromLayerNodeProto(proto1, dest_layer_map); |
| 1536 |
| 1537 EXPECT_EQ(layer_src_root->id(), layer_dest_root->id()); |
| 1538 ASSERT_TRUE(layer_dest_root->mask_layer()); |
| 1539 ASSERT_TRUE(layer_dest_root->replica_layer()); |
| 1540 EXPECT_EQ(layer_src_root->mask_layer()->id(), |
| 1541 layer_dest_root->mask_layer()->id()); |
| 1542 EXPECT_EQ(layer_src_root->replica_layer()->id(), |
| 1543 layer_dest_root->replica_layer()->id()); |
| 1544 |
| 1545 // Store the newly constructed layer structure in the id map. |
| 1546 dest_layer_map[layer_dest_root->id()] = layer_dest_root; |
| 1547 dest_layer_map[layer_dest_root->mask_layer()->id()] = |
| 1548 layer_dest_root->mask_layer(); |
| 1549 dest_layer_map[layer_dest_root->replica_layer()->id()] = |
| 1550 layer_dest_root->replica_layer(); |
| 1551 |
| 1552 // Clear mask and replica layers. |
| 1553 layer_src_root->mask_layer()->RemoveFromParent(); |
| 1554 layer_src_root->replica_layer()->RemoveFromParent(); |
| 1555 |
| 1556 // Serialization 2. |
| 1557 proto::LayerNode proto2; |
| 1558 layer_src_root->ToLayerNodeProto(&proto2); |
| 1559 |
| 1560 // Deserialization 2. |
| 1561 layer_dest_root->FromLayerNodeProto(proto2, dest_layer_map); |
| 1562 |
| 1563 EXPECT_EQ(nullptr, layer_dest_root->mask_layer()); |
| 1564 EXPECT_EQ(nullptr, layer_dest_root->replica_layer()); |
| 1565 } |
| 1566 |
1350 } // namespace | 1567 } // namespace |
1351 } // namespace cc | 1568 } // namespace cc |
OLD | NEW |