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 root_layer->ToLayerPropertiesProto(layer_update); |
| 49 } |
| 50 |
| 51 // static |
| 52 void LayerProtoConverter::DeserializeLayerProperties( |
| 53 scoped_refptr<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 |
45 void LayerProtoConverter::RecursivelyFindAllLayers( | 70 void LayerProtoConverter::RecursivelyFindAllLayers( |
46 const scoped_refptr<Layer>& layer, | 71 const scoped_refptr<Layer>& layer, |
47 LayerIdMap* layer_id_map) { | 72 LayerIdMap* layer_id_map) { |
48 LayerTreeHostCommon::CallFunctionForSubtree( | 73 LayerTreeHostCommon::CallFunctionForSubtree( |
49 layer.get(), | 74 layer.get(), |
50 [layer_id_map](Layer* layer) { (*layer_id_map)[layer->id()] = layer; }); | 75 [layer_id_map](Layer* layer) { (*layer_id_map)[layer->id()] = layer; }); |
51 } | 76 } |
52 | 77 |
53 // static | 78 // static |
54 scoped_refptr<Layer> LayerProtoConverter::FindOrAllocateAndConstruct( | 79 scoped_refptr<Layer> LayerProtoConverter::FindOrAllocateAndConstruct( |
55 const proto::LayerNode& proto, | 80 const proto::LayerNode& proto, |
56 const Layer::LayerIdMap& layer_id_map) { | 81 const Layer::LayerIdMap& layer_id_map) { |
57 DCHECK(proto.has_id()); | 82 DCHECK(proto.has_id()); |
58 Layer::LayerIdMap::const_iterator iter = layer_id_map.find(proto.id()); | 83 Layer::LayerIdMap::const_iterator iter = layer_id_map.find(proto.id()); |
59 if (iter != layer_id_map.end()) | 84 if (iter != layer_id_map.end()) |
60 return iter->second; | 85 return iter->second; |
61 DCHECK(proto.has_type()); | 86 DCHECK(proto.has_type()); |
62 switch (proto.type()) { | 87 switch (proto.type()) { |
63 case proto::Base: | 88 case proto::Base: |
64 return Layer::Create(LayerSettings()).get(); | 89 return Layer::Create(LayerSettings()).get(); |
65 } | 90 } |
66 // TODO(nyquist): Add the rest of the necessary LayerTypes. This function | 91 // TODO(nyquist): Add the rest of the necessary LayerTypes. This function |
67 // should not return null. | 92 // should not return null. |
68 NOTREACHED(); | 93 NOTREACHED(); |
69 return nullptr; | 94 return nullptr; |
70 } | 95 } |
71 | 96 |
72 } // namespace cc | 97 } // namespace cc |
OLD | NEW |