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

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

Issue 1808373002: cc : Make tree synchronization independent of layer tree hierarchy (2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
« 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/empty_content_layer_client.h" 8 #include "cc/layers/empty_content_layer_client.h"
9 #include "cc/layers/heads_up_display_layer.h" 9 #include "cc/layers/heads_up_display_layer.h"
10 #include "cc/layers/layer.h" 10 #include "cc/layers/layer.h"
11 #include "cc/layers/picture_layer.h" 11 #include "cc/layers/picture_layer.h"
12 #include "cc/proto/layer.pb.h" 12 #include "cc/proto/layer.pb.h"
13 #include "cc/trees/layer_tree_host.h"
13 #include "cc/trees/layer_tree_host_common.h" 14 #include "cc/trees/layer_tree_host_common.h"
14 #include "cc/trees/layer_tree_settings.h" 15 #include "cc/trees/layer_tree_settings.h"
15 16
16 namespace cc { 17 namespace cc {
17 18
18 LayerProtoConverter::LayerProtoConverter() {} 19 LayerProtoConverter::LayerProtoConverter() {}
19 20
20 LayerProtoConverter::~LayerProtoConverter() {} 21 LayerProtoConverter::~LayerProtoConverter() {}
21 22
22 // static 23 // static
(...skipping 17 matching lines...) Expand all
40 // The root node has changed or there was no root node, 41 // The root node has changed or there was no root node,
41 // so find or create the new root. 42 // so find or create the new root.
42 new_root = FindOrAllocateAndConstruct(root_node, layer_id_map); 43 new_root = FindOrAllocateAndConstruct(root_node, layer_id_map);
43 } 44 }
44 new_root->FromLayerNodeProto(root_node, layer_id_map); 45 new_root->FromLayerNodeProto(root_node, layer_id_map);
45 return new_root; 46 return new_root;
46 } 47 }
47 48
48 // static 49 // static
49 void LayerProtoConverter::SerializeLayerProperties( 50 void LayerProtoConverter::SerializeLayerProperties(
50 Layer* root_layer, 51 LayerTreeHost* host,
51 proto::LayerUpdate* layer_update) { 52 proto::LayerUpdate* layer_update) {
52 RecursivelySerializeLayerProperties(root_layer, layer_update); 53 for (auto layer : host->LayersThatShouldPushProperties())
54 layer->ToLayerPropertiesProto(layer_update);
55 host->LayersThatShouldPushProperties().clear();
53 } 56 }
54 57
55 // static 58 // static
56 void LayerProtoConverter::DeserializeLayerProperties( 59 void LayerProtoConverter::DeserializeLayerProperties(
57 Layer* existing_root, 60 Layer* existing_root,
58 const proto::LayerUpdate& layer_update) { 61 const proto::LayerUpdate& layer_update) {
59 DCHECK(existing_root); 62 DCHECK(existing_root);
60 LayerIdMap layer_id_map; 63 LayerIdMap layer_id_map;
61 RecursivelyFindAllLayers(existing_root, &layer_id_map); 64 RecursivelyFindAllLayers(existing_root, &layer_id_map);
62 65
63 for (int i = 0; i < layer_update.layers_size(); ++i) { 66 for (int i = 0; i < layer_update.layers_size(); ++i) {
64 const proto::LayerProperties& layer_properties = layer_update.layers(i); 67 const proto::LayerProperties& layer_properties = layer_update.layers(i);
65 68
66 Layer::LayerIdMap::const_iterator iter = 69 Layer::LayerIdMap::const_iterator iter =
67 layer_id_map.find(layer_properties.id()); 70 layer_id_map.find(layer_properties.id());
68 DCHECK(iter != layer_id_map.end()); 71 DCHECK(iter != layer_id_map.end());
69 72
70 iter->second->FromLayerPropertiesProto(layer_properties); 73 iter->second->FromLayerPropertiesProto(layer_properties);
71 } 74 }
72 } 75 }
73 76
74 // static 77 // static
75 void LayerProtoConverter::RecursivelySerializeLayerProperties(
76 Layer* layer,
77 proto::LayerUpdate* layer_update) {
78 bool serialize_descendants = layer->ToLayerPropertiesProto(layer_update);
79 if (!serialize_descendants)
80 return;
81
82 for (const auto& child : layer->children()) {
83 RecursivelySerializeLayerProperties(child.get(), layer_update);
84 }
85 if (layer->mask_layer())
86 RecursivelySerializeLayerProperties(layer->mask_layer(), layer_update);
87 if (layer->replica_layer())
88 RecursivelySerializeLayerProperties(layer->replica_layer(), layer_update);
89 }
90
91 // static
92 void LayerProtoConverter::RecursivelyFindAllLayers(Layer* root_layer, 78 void LayerProtoConverter::RecursivelyFindAllLayers(Layer* root_layer,
93 LayerIdMap* layer_id_map) { 79 LayerIdMap* layer_id_map) {
94 LayerTreeHostCommon::CallFunctionForSubtree( 80 LayerTreeHostCommon::CallFunctionForSubtree(
95 root_layer, 81 root_layer,
96 [layer_id_map](Layer* layer) { (*layer_id_map)[layer->id()] = layer; }); 82 [layer_id_map](Layer* layer) { (*layer_id_map)[layer->id()] = layer; });
97 } 83 }
98 84
99 // static 85 // static
100 scoped_refptr<Layer> LayerProtoConverter::FindOrAllocateAndConstruct( 86 scoped_refptr<Layer> LayerProtoConverter::FindOrAllocateAndConstruct(
101 const proto::LayerNode& proto, 87 const proto::LayerNode& proto,
(...skipping 15 matching lines...) Expand all
117 case proto::LayerNode::HEADS_UP_DISPLAY_LAYER: 103 case proto::LayerNode::HEADS_UP_DISPLAY_LAYER:
118 return HeadsUpDisplayLayer::Create(); 104 return HeadsUpDisplayLayer::Create();
119 } 105 }
120 // TODO(nyquist): Add the rest of the necessary LayerTypes. This function 106 // TODO(nyquist): Add the rest of the necessary LayerTypes. This function
121 // should not return null. 107 // should not return null.
122 NOTREACHED(); 108 NOTREACHED();
123 return nullptr; 109 return nullptr;
124 } 110 }
125 111
126 } // namespace cc 112 } // 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