diff options
author | nyquist <nyquist@chromium.org> | 2016-01-14 16:52:33 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-15 00:53:56 +0000 |
commit | 08b217a012c56f5e02ca17388a6a3c905c77bcd6 (patch) | |
tree | 15f1b2b7548ef6dd1ea4b84c81617c5f20bed664 | |
parent | b840e2f4ec9132b931f7ad54fd8fd20285e4eaa3 (diff) | |
download | chromium_src-08b217a012c56f5e02ca17388a6a3c905c77bcd6.zip chromium_src-08b217a012c56f5e02ca17388a6a3c905c77bcd6.tar.gz chromium_src-08b217a012c56f5e02ca17388a6a3c905c77bcd6.tar.bz2 |
Add support for deserializing without existing root node
When deserializing a layer tree for the first time, there is no
existing root. Not all parts of the code supported this scenario,
and this CL adds support for this use-case for the hierarchy
deserialization.
They property deserialization still requires an existing root
since the deserialization should have happened before.
This also adds a test for the initial deserialization.
BUG=577310
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel
Review URL: https://codereview.chromium.org/1584263002
Cr-Commit-Position: refs/heads/master@{#369636}
-rw-r--r-- | cc/layers/layer_proto_converter.cc | 4 | ||||
-rw-r--r-- | cc/layers/layer_proto_converter.h | 6 | ||||
-rw-r--r-- | cc/layers/layer_proto_converter_unittest.cc | 29 |
3 files changed, 36 insertions, 3 deletions
diff --git a/cc/layers/layer_proto_converter.cc b/cc/layers/layer_proto_converter.cc index 6564e0b..086ad99 100644 --- a/cc/layers/layer_proto_converter.cc +++ b/cc/layers/layer_proto_converter.cc @@ -31,7 +31,8 @@ scoped_refptr<Layer> LayerProtoConverter::DeserializeLayerHierarchy( scoped_refptr<Layer> existing_root, const proto::LayerNode& root_node) { LayerIdMap layer_id_map; - RecursivelyFindAllLayers(existing_root, &layer_id_map); + if (existing_root) + RecursivelyFindAllLayers(existing_root, &layer_id_map); scoped_refptr<Layer> new_root = existing_root; if (!existing_root || @@ -55,6 +56,7 @@ void LayerProtoConverter::SerializeLayerProperties( void LayerProtoConverter::DeserializeLayerProperties( Layer* existing_root, const proto::LayerUpdate& layer_update) { + DCHECK(existing_root); LayerIdMap layer_id_map; RecursivelyFindAllLayers(existing_root, &layer_id_map); diff --git a/cc/layers/layer_proto_converter.h b/cc/layers/layer_proto_converter.h index 7f2742b..f821a5d 100644 --- a/cc/layers/layer_proto_converter.h +++ b/cc/layers/layer_proto_converter.h @@ -27,7 +27,8 @@ class CC_EXPORT LayerProtoConverter { // Recursively iterate over the given LayerNode proto and read the structure // into a local Layer structure, re-using existing Layers. returns the new // root Layer after updating the hierarchy (may be the same as - // |existing_root|). + // |existing_root|). |existing_root| may be null, which might happen during + // the first deserialize. static scoped_refptr<Layer> DeserializeLayerHierarchy( const scoped_refptr<Layer> existing_root, const proto::LayerNode& root_node); @@ -40,7 +41,8 @@ class CC_EXPORT LayerProtoConverter { proto::LayerUpdate* layer_update); // Iterate over all updated layers from the LayerUpdate, and update the - // local Layers. + // local Layers. |existing_root| must not be null, as that will make it + // impossible to find the layer to apply the properties to. static void DeserializeLayerProperties( Layer* existing_root, const proto::LayerUpdate& layer_update); diff --git a/cc/layers/layer_proto_converter_unittest.cc b/cc/layers/layer_proto_converter_unittest.cc index e1a30e6..3aa74d3 100644 --- a/cc/layers/layer_proto_converter_unittest.cc +++ b/cc/layers/layer_proto_converter_unittest.cc @@ -86,6 +86,35 @@ TEST_F(LayerProtoConverterTest, TestKeepingRoot) { EXPECT_EQ(child_c_node->id(), child_c->id()); } +TEST_F(LayerProtoConverterTest, TestNoExistingRoot) { + /* Test deserialization of a tree that looks like: + root + / + a + There is no existing root node before serialization. + */ + int new_root_id = 244; + proto::LayerNode root_node; + root_node.set_id(new_root_id); + root_node.set_type(proto::LayerType::LAYER); + + proto::LayerNode* child_a_node = root_node.add_children(); + child_a_node->set_id(442); + child_a_node->set_type(proto::LayerType::LAYER); + child_a_node->set_parent_id(new_root_id); // root_node + + scoped_refptr<Layer> new_root = + LayerProtoConverter::DeserializeLayerHierarchy(nullptr, root_node); + + // The new root should not be the same as the old root. + EXPECT_EQ(new_root_id, new_root->id()); + ASSERT_EQ(1u, new_root->children().size()); + scoped_refptr<Layer> child_a = new_root->children()[0]; + + EXPECT_EQ(child_a_node->id(), child_a->id()); + EXPECT_EQ(0u, child_a->children().size()); +} + TEST_F(LayerProtoConverterTest, TestSwappingRoot) { /* Test deserialization of a tree that looks like: root |