OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "cc/layers/layer_proto_converter.h" |
| 6 |
| 7 #include "base/stl_util.h" |
| 8 #include "cc/layers/layer.h" |
| 9 #include "cc/proto/layer.pb.h" |
| 10 #include "cc/trees/layer_tree_host_common.h" |
| 11 #include "cc/trees/layer_tree_settings.h" |
| 12 |
| 13 namespace cc { |
| 14 |
| 15 LayerProtoConverter::LayerProtoConverter() {} |
| 16 |
| 17 LayerProtoConverter::~LayerProtoConverter() {} |
| 18 |
| 19 // static |
| 20 void LayerProtoConverter::SerializeLayerHierarchy( |
| 21 const scoped_refptr<Layer> root_layer, |
| 22 proto::LayerNode* root_node) { |
| 23 root_layer->ToLayerNodeProto(root_node); |
| 24 } |
| 25 |
| 26 // static |
| 27 scoped_refptr<Layer> LayerProtoConverter::DeserializeLayerHierarchy( |
| 28 scoped_refptr<Layer> existing_root, |
| 29 const proto::LayerNode& root_node) { |
| 30 LayerIdMap layer_id_map; |
| 31 RecursivelyFindAllLayers(existing_root, &layer_id_map); |
| 32 |
| 33 scoped_refptr<Layer> new_root = existing_root; |
| 34 if (!existing_root || |
| 35 (root_node.has_id() && root_node.id() != existing_root->id())) { |
| 36 // The root node has changed or there was no root node, |
| 37 // so find or create the new root. |
| 38 new_root = FindOrAllocateAndConstruct(root_node, layer_id_map); |
| 39 } |
| 40 new_root->FromLayerNodeProto(root_node, layer_id_map); |
| 41 return new_root; |
| 42 } |
| 43 |
| 44 // static |
| 45 void LayerProtoConverter::RecursivelyFindAllLayers( |
| 46 const scoped_refptr<Layer>& layer, |
| 47 LayerIdMap* layer_id_map) { |
| 48 LayerTreeHostCommon::CallFunctionForSubtree( |
| 49 layer.get(), |
| 50 [layer_id_map](Layer* layer) { (*layer_id_map)[layer->id()] = layer; }); |
| 51 } |
| 52 |
| 53 // static |
| 54 scoped_refptr<Layer> LayerProtoConverter::FindOrAllocateAndConstruct( |
| 55 const proto::LayerNode& proto, |
| 56 const Layer::LayerIdMap& layer_id_map) { |
| 57 DCHECK(proto.has_id()); |
| 58 Layer::LayerIdMap::const_iterator iter = layer_id_map.find(proto.id()); |
| 59 if (iter != layer_id_map.end()) |
| 60 return iter->second; |
| 61 DCHECK(proto.has_type()); |
| 62 switch (proto.type()) { |
| 63 case proto::Base: |
| 64 return Layer::Create(LayerSettings()).get(); |
| 65 } |
| 66 // TODO(nyquist): Add the rest of the necessary LayerTypes. This function |
| 67 // should not return null. |
| 68 NOTREACHED(); |
| 69 return nullptr; |
| 70 } |
| 71 |
| 72 } // namespace cc |
OLD | NEW |