OLD | NEW |
---|---|
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 Loading... | |
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 const scoped_refptr<Layer> root_layer, | |
47 proto::LayerUpdate* layer_update) { | |
48 RecursivelySerializeLayerProperties(root_layer, layer_update); | |
49 } | |
50 | |
51 // static | |
52 void LayerProtoConverter::DeserializeLayerProperties( | |
53 scoped_refptr<Layer> existing_root, | |
vmpstr
2015/11/18 04:05:25
Can you pass a raw pointer here instead?
nyquist
2015/11/18 07:15:59
Done.
| |
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 const scoped_refptr<Layer> layer, | |
72 proto::LayerUpdate* layer_update) { | |
73 bool serialize_descendants = layer->ToLayerPropertiesProto(layer_update); | |
74 if (!serialize_descendants) | |
vmpstr
2015/11/18 04:05:25
Are mask/replica considered descendants? That is,
nyquist
2015/11/18 07:15:59
According to Layer::SetMaskLayer(...) ( https://ch
| |
75 return; | |
76 | |
77 for (const auto& child : layer->children()) { | |
78 RecursivelySerializeLayerProperties(child, 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 |
OLD | NEW |