Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(696)

Side by Side Diff: cc/layers/layer_unittest.cc

Issue 1423523002: Add support for (de)serializing cc::Layer properties. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@serialize-layer-hierarchy
Patch Set: Add framework for base Layer class properties Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 1549 matching lines...) Expand 10 before | Expand all | Expand 10 after
1560 proto::LayerNode proto2; 1560 proto::LayerNode proto2;
1561 layer_src_root->ToLayerNodeProto(&proto2); 1561 layer_src_root->ToLayerNodeProto(&proto2);
1562 1562
1563 // Deserialization 2. 1563 // Deserialization 2.
1564 layer_dest_root->FromLayerNodeProto(proto2, dest_layer_map); 1564 layer_dest_root->FromLayerNodeProto(proto2, dest_layer_map);
1565 1565
1566 EXPECT_EQ(nullptr, layer_dest_root->mask_layer()); 1566 EXPECT_EQ(nullptr, layer_dest_root->mask_layer());
1567 EXPECT_EQ(nullptr, layer_dest_root->replica_layer()); 1567 EXPECT_EQ(nullptr, layer_dest_root->replica_layer());
1568 } 1568 }
1569 1569
1570 TEST_F(LayerTest, RecursivePropertiesSerialization) {
1571 /* Testing serialization of properties for a tree that looks like this:
1572 root+
1573 / \
1574 a* b*+[mask:*]
David Trainor- moved to gerrit 2015/11/11 15:34:22 [mask:*,replica]?
nyquist 2015/11/11 18:31:57 Good idea! Done.
1575 / \
1576 c d*
1577 Layers marked with * have changed properties.
David Trainor- moved to gerrit 2015/11/11 15:34:22 Add the same description to the layer_proto_conver
nyquist 2015/11/11 18:31:57 Done (with the values from that test of course).
1578 Layers marked with + have descendants with changed properties.
1579 Layer b also has a mask layer and a replica layer.
1580 */
1581 scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings());
1582 scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings());
1583 scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings());
1584 scoped_refptr<Layer> layer_src_b_mask = Layer::Create(LayerSettings());
1585 scoped_refptr<Layer> layer_src_b_replica = Layer::Create(LayerSettings());
1586 scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings());
1587 scoped_refptr<Layer> layer_src_d = Layer::Create(LayerSettings());
1588 layer_src_root->AddChild(layer_src_a);
1589 layer_src_root->AddChild(layer_src_b);
1590 layer_src_a->AddChild(layer_src_c);
1591 layer_src_b->AddChild(layer_src_d);
1592 layer_src_b->SetMaskLayer(layer_src_b_mask.get());
1593 layer_src_b->SetReplicaLayer(layer_src_b_replica.get());
1594
1595 layer_src_a->SetNeedsPushProperties();
1596 layer_src_b->SetNeedsPushProperties();
1597 layer_src_b_mask->SetNeedsPushProperties();
1598 layer_src_d->SetNeedsPushProperties();
1599
1600 proto::LayerUpdate layer_update;
1601 layer_src_root->ToLayerPropertiesProto(&layer_update);
1602
1603 // All flags for pushing properties should have been cleared.
1604 EXPECT_FALSE(layer_src_root->needs_push_properties());
1605 EXPECT_FALSE(layer_src_root->descendant_needs_push_properties());
1606 EXPECT_FALSE(layer_src_a->needs_push_properties());
1607 EXPECT_FALSE(layer_src_a->descendant_needs_push_properties());
1608 EXPECT_FALSE(layer_src_b->needs_push_properties());
1609 EXPECT_FALSE(layer_src_b->descendant_needs_push_properties());
1610 EXPECT_FALSE(layer_src_b_mask->needs_push_properties());
1611 EXPECT_FALSE(layer_src_b_mask->descendant_needs_push_properties());
1612 EXPECT_FALSE(layer_src_b_replica->needs_push_properties());
1613 EXPECT_FALSE(layer_src_b_replica->descendant_needs_push_properties());
1614 EXPECT_FALSE(layer_src_c->needs_push_properties());
1615 EXPECT_FALSE(layer_src_c->descendant_needs_push_properties());
1616 EXPECT_FALSE(layer_src_d->needs_push_properties());
1617 EXPECT_FALSE(layer_src_d->descendant_needs_push_properties());
1618
1619 // Only 5 of the layers should have been serialized.
1620 ASSERT_EQ(5, layer_update.layers_size());
1621 EXPECT_EQ(layer_src_root->id(), layer_update.layers(0).id());
1622 proto::LayerProperties dest_root = layer_update.layers(0);
1623 EXPECT_EQ(layer_src_a->id(), layer_update.layers(1).id());
1624 proto::LayerProperties dest_a = layer_update.layers(1);
1625 EXPECT_EQ(layer_src_b->id(), layer_update.layers(2).id());
1626 proto::LayerProperties dest_b = layer_update.layers(2);
1627 EXPECT_EQ(layer_src_d->id(), layer_update.layers(3).id());
1628 proto::LayerProperties dest_d = layer_update.layers(3);
1629 EXPECT_EQ(layer_src_b_mask->id(), layer_update.layers(4).id());
1630 proto::LayerProperties dest_b_mask = layer_update.layers(4);
1631
1632 // Ensure the properties and dependants metadata is correctly serialized.
1633 EXPECT_FALSE(dest_root.needs_push_properties());
1634 EXPECT_EQ(2, dest_root.num_dependents_need_push_properties());
1635 EXPECT_FALSE(dest_root.has_base());
1636
1637 EXPECT_TRUE(dest_a.needs_push_properties());
1638 EXPECT_EQ(0, dest_a.num_dependents_need_push_properties());
1639 EXPECT_TRUE(dest_a.has_base());
1640
1641 EXPECT_TRUE(dest_b.needs_push_properties());
1642 EXPECT_EQ(2, dest_b.num_dependents_need_push_properties());
1643 EXPECT_TRUE(dest_b.has_base());
1644
1645 EXPECT_TRUE(dest_d.needs_push_properties());
1646 EXPECT_EQ(0, dest_d.num_dependents_need_push_properties());
1647 EXPECT_TRUE(dest_d.has_base());
1648
1649 EXPECT_TRUE(dest_b_mask.needs_push_properties());
1650 EXPECT_EQ(0, dest_b_mask.num_dependents_need_push_properties());
1651 EXPECT_TRUE(dest_b_mask.has_base());
1652 }
1653
1654 TEST_F(LayerTest, SimplePropertiesDeserialization) {
1655 scoped_refptr<Layer> layer = Layer::Create(LayerSettings());
1656 proto::LayerProperties properties;
1657 properties.set_id(layer->id());
1658
1659 properties.set_needs_push_properties(true);
1660 properties.set_num_dependents_need_push_properties(2);
1661 properties.mutable_base();
1662 layer->FromLayerPropertiesProto(properties);
1663 EXPECT_TRUE(layer->needs_push_properties());
1664 EXPECT_TRUE(layer->descendant_needs_push_properties());
1665
1666 properties.set_needs_push_properties(false);
1667 properties.mutable_base()->Clear();
1668 layer->FromLayerPropertiesProto(properties);
1669 EXPECT_FALSE(layer->needs_push_properties());
1670 EXPECT_TRUE(layer->descendant_needs_push_properties());
1671
1672 properties.set_num_dependents_need_push_properties(0);
1673 layer->FromLayerPropertiesProto(properties);
1674 EXPECT_FALSE(layer->needs_push_properties());
1675 EXPECT_FALSE(layer->descendant_needs_push_properties());
1676
1677 properties.set_needs_push_properties(true);
1678 properties.mutable_base();
1679 layer->FromLayerPropertiesProto(properties);
1680 EXPECT_TRUE(layer->needs_push_properties());
1681 EXPECT_FALSE(layer->descendant_needs_push_properties());
1682 }
1683
1570 } // namespace 1684 } // namespace
1571 } // namespace cc 1685 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698