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

Side by Side Diff: cc/layers/layer_proto_converter.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: Addressed comments about raw pointers and new test. 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
« no previous file with comments | « cc/layers/layer_proto_converter.h ('k') | cc/layers/layer_proto_converter_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_proto_converter.h" 5 #include "cc/layers/layer_proto_converter.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "cc/layers/layer.h" 8 #include "cc/layers/layer.h"
9 #include "cc/proto/layer.pb.h" 9 #include "cc/proto/layer.pb.h"
10 #include "cc/trees/layer_tree_host_common.h" 10 #include "cc/trees/layer_tree_host_common.h"
(...skipping 24 matching lines...) Expand all
35 (root_node.has_id() && root_node.id() != existing_root->id())) { 35 (root_node.has_id() && root_node.id() != existing_root->id())) {
36 // The root node has changed or there was no root node, 36 // The root node has changed or there was no root node,
37 // so find or create the new root. 37 // so find or create the new root.
38 new_root = FindOrAllocateAndConstruct(root_node, layer_id_map); 38 new_root = FindOrAllocateAndConstruct(root_node, layer_id_map);
39 } 39 }
40 new_root->FromLayerNodeProto(root_node, layer_id_map); 40 new_root->FromLayerNodeProto(root_node, layer_id_map);
41 return new_root; 41 return new_root;
42 } 42 }
43 43
44 // static 44 // static
45 void LayerProtoConverter::SerializeLayerProperties(
46 Layer* root_layer,
47 proto::LayerUpdate* layer_update) {
48 RecursivelySerializeLayerProperties(root_layer, layer_update);
49 }
50
51 // static
52 void LayerProtoConverter::DeserializeLayerProperties(
53 Layer* existing_root,
54 const proto::LayerUpdate& layer_update) {
55 LayerIdMap layer_id_map;
56 RecursivelyFindAllLayers(existing_root, &layer_id_map);
57
58 for (int i = 0; i < layer_update.layers_size(); ++i) {
59 const proto::LayerProperties& layer_properties = layer_update.layers(i);
60
61 Layer::LayerIdMap::const_iterator iter =
62 layer_id_map.find(layer_properties.id());
63 DCHECK(iter != layer_id_map.end());
64
65 iter->second->FromLayerPropertiesProto(layer_properties);
66 }
67 }
68
69 // static
70 void LayerProtoConverter::RecursivelySerializeLayerProperties(
71 Layer* layer,
72 proto::LayerUpdate* layer_update) {
73 bool serialize_descendants = layer->ToLayerPropertiesProto(layer_update);
74 if (!serialize_descendants)
75 return;
76
77 for (const auto& child : layer->children()) {
78 RecursivelySerializeLayerProperties(child.get(), layer_update);
79 }
80 if (layer->mask_layer())
81 RecursivelySerializeLayerProperties(layer->mask_layer(), layer_update);
82 if (layer->replica_layer())
83 RecursivelySerializeLayerProperties(layer->replica_layer(), layer_update);
84 }
85
86 // static
45 void LayerProtoConverter::RecursivelyFindAllLayers( 87 void LayerProtoConverter::RecursivelyFindAllLayers(
46 const scoped_refptr<Layer>& layer, 88 const scoped_refptr<Layer>& layer,
47 LayerIdMap* layer_id_map) { 89 LayerIdMap* layer_id_map) {
48 LayerTreeHostCommon::CallFunctionForSubtree( 90 LayerTreeHostCommon::CallFunctionForSubtree(
49 layer.get(), 91 layer.get(),
50 [layer_id_map](Layer* layer) { (*layer_id_map)[layer->id()] = layer; }); 92 [layer_id_map](Layer* layer) { (*layer_id_map)[layer->id()] = layer; });
51 } 93 }
52 94
53 // static 95 // static
54 scoped_refptr<Layer> LayerProtoConverter::FindOrAllocateAndConstruct( 96 scoped_refptr<Layer> LayerProtoConverter::FindOrAllocateAndConstruct(
55 const proto::LayerNode& proto, 97 const proto::LayerNode& proto,
56 const Layer::LayerIdMap& layer_id_map) { 98 const Layer::LayerIdMap& layer_id_map) {
57 DCHECK(proto.has_id()); 99 DCHECK(proto.has_id());
58 Layer::LayerIdMap::const_iterator iter = layer_id_map.find(proto.id()); 100 Layer::LayerIdMap::const_iterator iter = layer_id_map.find(proto.id());
59 if (iter != layer_id_map.end()) 101 if (iter != layer_id_map.end())
60 return iter->second; 102 return iter->second;
61 DCHECK(proto.has_type()); 103 DCHECK(proto.has_type());
62 switch (proto.type()) { 104 switch (proto.type()) {
63 case proto::Base: 105 case proto::Base:
64 return Layer::Create(LayerSettings()).get(); 106 return Layer::Create(LayerSettings()).get();
65 } 107 }
66 // TODO(nyquist): Add the rest of the necessary LayerTypes. This function 108 // TODO(nyquist): Add the rest of the necessary LayerTypes. This function
67 // should not return null. 109 // should not return null.
68 NOTREACHED(); 110 NOTREACHED();
69 return nullptr; 111 return nullptr;
70 } 112 }
71 113
72 } // namespace cc 114 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/layer_proto_converter.h ('k') | cc/layers/layer_proto_converter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698