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

Side by Side Diff: cc/layers/layer_proto_converter.cc

Issue 1398443008: Add support for (de)serializing cc::Layer hierarchy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@review-1394353002
Patch Set: Moved functionality outside of Layer to LayerProtoConverter. Updated test-comments to be multiline. Created 5 years, 2 months 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
OLDNEW
(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:
vmpstr 2015/10/23 21:26:10 Do other cases exist already? If there's only Base
nyquist 2015/10/26 03:14:29 Done. For now it's only base (until the TODO is i
vmpstr 2015/10/26 17:51:45 Yep, that's perfect.
64 return Layer::Create(LayerSettings()).get();
65 default:
66 // TODO(nyquist): Add the rest of the necessary LayerTypes. This function
67 // should not return null.
68 return nullptr;
69 }
70 }
71
72 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698