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