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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: cc/layers/layer_unittest.cc
diff --git a/cc/layers/layer_unittest.cc b/cc/layers/layer_unittest.cc
index 12aa514fee68d60fb1934eca34e53cd16c9e5bc5..f296faf9c1c259048f6c7855f43ed9a0b56f972a 100644
--- a/cc/layers/layer_unittest.cc
+++ b/cc/layers/layer_unittest.cc
@@ -1567,5 +1567,119 @@ TEST_F(LayerTest, DeleteMaskAndReplicaLayer) {
EXPECT_EQ(nullptr, layer_dest_root->replica_layer());
}
+TEST_F(LayerTest, RecursivePropertiesSerialization) {
+ /* Testing serialization of properties for a tree that looks like this:
+ root+
+ / \
+ 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.
+ / \
+ c d*
+ 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).
+ Layers marked with + have descendants with changed properties.
+ Layer b also has a mask layer and a replica layer.
+ */
+ scoped_refptr<Layer> layer_src_root = Layer::Create(LayerSettings());
+ scoped_refptr<Layer> layer_src_a = Layer::Create(LayerSettings());
+ scoped_refptr<Layer> layer_src_b = Layer::Create(LayerSettings());
+ scoped_refptr<Layer> layer_src_b_mask = Layer::Create(LayerSettings());
+ scoped_refptr<Layer> layer_src_b_replica = Layer::Create(LayerSettings());
+ scoped_refptr<Layer> layer_src_c = Layer::Create(LayerSettings());
+ scoped_refptr<Layer> layer_src_d = Layer::Create(LayerSettings());
+ layer_src_root->AddChild(layer_src_a);
+ layer_src_root->AddChild(layer_src_b);
+ layer_src_a->AddChild(layer_src_c);
+ layer_src_b->AddChild(layer_src_d);
+ layer_src_b->SetMaskLayer(layer_src_b_mask.get());
+ layer_src_b->SetReplicaLayer(layer_src_b_replica.get());
+
+ layer_src_a->SetNeedsPushProperties();
+ layer_src_b->SetNeedsPushProperties();
+ layer_src_b_mask->SetNeedsPushProperties();
+ layer_src_d->SetNeedsPushProperties();
+
+ proto::LayerUpdate layer_update;
+ layer_src_root->ToLayerPropertiesProto(&layer_update);
+
+ // All flags for pushing properties should have been cleared.
+ EXPECT_FALSE(layer_src_root->needs_push_properties());
+ EXPECT_FALSE(layer_src_root->descendant_needs_push_properties());
+ EXPECT_FALSE(layer_src_a->needs_push_properties());
+ EXPECT_FALSE(layer_src_a->descendant_needs_push_properties());
+ EXPECT_FALSE(layer_src_b->needs_push_properties());
+ EXPECT_FALSE(layer_src_b->descendant_needs_push_properties());
+ EXPECT_FALSE(layer_src_b_mask->needs_push_properties());
+ EXPECT_FALSE(layer_src_b_mask->descendant_needs_push_properties());
+ EXPECT_FALSE(layer_src_b_replica->needs_push_properties());
+ EXPECT_FALSE(layer_src_b_replica->descendant_needs_push_properties());
+ EXPECT_FALSE(layer_src_c->needs_push_properties());
+ EXPECT_FALSE(layer_src_c->descendant_needs_push_properties());
+ EXPECT_FALSE(layer_src_d->needs_push_properties());
+ EXPECT_FALSE(layer_src_d->descendant_needs_push_properties());
+
+ // Only 5 of the layers should have been serialized.
+ ASSERT_EQ(5, layer_update.layers_size());
+ EXPECT_EQ(layer_src_root->id(), layer_update.layers(0).id());
+ proto::LayerProperties dest_root = layer_update.layers(0);
+ EXPECT_EQ(layer_src_a->id(), layer_update.layers(1).id());
+ proto::LayerProperties dest_a = layer_update.layers(1);
+ EXPECT_EQ(layer_src_b->id(), layer_update.layers(2).id());
+ proto::LayerProperties dest_b = layer_update.layers(2);
+ EXPECT_EQ(layer_src_d->id(), layer_update.layers(3).id());
+ proto::LayerProperties dest_d = layer_update.layers(3);
+ EXPECT_EQ(layer_src_b_mask->id(), layer_update.layers(4).id());
+ proto::LayerProperties dest_b_mask = layer_update.layers(4);
+
+ // Ensure the properties and dependants metadata is correctly serialized.
+ EXPECT_FALSE(dest_root.needs_push_properties());
+ EXPECT_EQ(2, dest_root.num_dependents_need_push_properties());
+ EXPECT_FALSE(dest_root.has_base());
+
+ EXPECT_TRUE(dest_a.needs_push_properties());
+ EXPECT_EQ(0, dest_a.num_dependents_need_push_properties());
+ EXPECT_TRUE(dest_a.has_base());
+
+ EXPECT_TRUE(dest_b.needs_push_properties());
+ EXPECT_EQ(2, dest_b.num_dependents_need_push_properties());
+ EXPECT_TRUE(dest_b.has_base());
+
+ EXPECT_TRUE(dest_d.needs_push_properties());
+ EXPECT_EQ(0, dest_d.num_dependents_need_push_properties());
+ EXPECT_TRUE(dest_d.has_base());
+
+ EXPECT_TRUE(dest_b_mask.needs_push_properties());
+ EXPECT_EQ(0, dest_b_mask.num_dependents_need_push_properties());
+ EXPECT_TRUE(dest_b_mask.has_base());
+}
+
+TEST_F(LayerTest, SimplePropertiesDeserialization) {
+ scoped_refptr<Layer> layer = Layer::Create(LayerSettings());
+ proto::LayerProperties properties;
+ properties.set_id(layer->id());
+
+ properties.set_needs_push_properties(true);
+ properties.set_num_dependents_need_push_properties(2);
+ properties.mutable_base();
+ layer->FromLayerPropertiesProto(properties);
+ EXPECT_TRUE(layer->needs_push_properties());
+ EXPECT_TRUE(layer->descendant_needs_push_properties());
+
+ properties.set_needs_push_properties(false);
+ properties.mutable_base()->Clear();
+ layer->FromLayerPropertiesProto(properties);
+ EXPECT_FALSE(layer->needs_push_properties());
+ EXPECT_TRUE(layer->descendant_needs_push_properties());
+
+ properties.set_num_dependents_need_push_properties(0);
+ layer->FromLayerPropertiesProto(properties);
+ EXPECT_FALSE(layer->needs_push_properties());
+ EXPECT_FALSE(layer->descendant_needs_push_properties());
+
+ properties.set_needs_push_properties(true);
+ properties.mutable_base();
+ layer->FromLayerPropertiesProto(properties);
+ EXPECT_TRUE(layer->needs_push_properties());
+ EXPECT_FALSE(layer->descendant_needs_push_properties());
+}
+
} // namespace
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698