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

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
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"
(...skipping 30 matching lines...) Expand all
41 // The root node has changed or there was no root node, 41 // The root node has changed or there was no root node,
42 // so find or create the new root. 42 // so find or create the new root.
43 new_root = FindOrAllocateAndConstruct(root_node, layer_id_map); 43 new_root = FindOrAllocateAndConstruct(root_node, layer_id_map);
44 } 44 }
45 new_root->FromLayerNodeProto(root_node, layer_id_map); 45 new_root->FromLayerNodeProto(root_node, layer_id_map);
46 return new_root; 46 return new_root;
47 } 47 }
48 48
49 // static 49 // static
50 void LayerProtoConverter::SerializeLayerProperties( 50 void LayerProtoConverter::SerializeLayerProperties(
51 Layer* root_layer, 51 LayerTreeHost* host,
52 proto::LayerUpdate* layer_update) { 52 proto::LayerUpdate* layer_update) {
53 RecursivelySerializeLayerProperties(root_layer, layer_update); 53 for (auto layer : host->LayersThatShouldPushProperties())
54 layer->ToLayerPropertiesProto(layer_update);
55 host->LayersThatShouldPushProperties().clear();
54 } 56 }
55 57
56 // static 58 // static
57 void LayerProtoConverter::DeserializeLayerProperties( 59 void LayerProtoConverter::DeserializeLayerProperties(
58 Layer* existing_root, 60 Layer* existing_root,
59 const proto::LayerUpdate& layer_update) { 61 const proto::LayerUpdate& layer_update) {
60 DCHECK(existing_root); 62 DCHECK(existing_root);
61 LayerIdMap layer_id_map; 63 LayerIdMap layer_id_map;
62 RecursivelyFindAllLayers(existing_root, &layer_id_map); 64 RecursivelyFindAllLayers(existing_root, &layer_id_map);
63 65
64 for (int i = 0; i < layer_update.layers_size(); ++i) { 66 for (int i = 0; i < layer_update.layers_size(); ++i) {
65 const proto::LayerProperties& layer_properties = layer_update.layers(i); 67 const proto::LayerProperties& layer_properties = layer_update.layers(i);
66 68
67 Layer::LayerIdMap::const_iterator iter = 69 Layer::LayerIdMap::const_iterator iter =
68 layer_id_map.find(layer_properties.id()); 70 layer_id_map.find(layer_properties.id());
69 DCHECK(iter != layer_id_map.end()); 71 DCHECK(iter != layer_id_map.end());
70 72
71 iter->second->FromLayerPropertiesProto(layer_properties); 73 iter->second->FromLayerPropertiesProto(layer_properties);
72 } 74 }
73 } 75 }
74 76
75 // static 77 // static
76 void LayerProtoConverter::RecursivelySerializeLayerProperties(
77 Layer* layer,
78 proto::LayerUpdate* layer_update) {
79 bool serialize_descendants = layer->ToLayerPropertiesProto(layer_update);
80 if (!serialize_descendants)
81 return;
82
83 for (const auto& child : layer->children()) {
84 RecursivelySerializeLayerProperties(child.get(), layer_update);
85 }
86 if (layer->mask_layer())
87 RecursivelySerializeLayerProperties(layer->mask_layer(), layer_update);
88 if (layer->replica_layer())
89 RecursivelySerializeLayerProperties(layer->replica_layer(), layer_update);
90 }
91
92 // static
93 void LayerProtoConverter::RecursivelyFindAllLayers( 78 void LayerProtoConverter::RecursivelyFindAllLayers(
94 const scoped_refptr<Layer>& layer, 79 const scoped_refptr<Layer>& layer,
95 LayerIdMap* layer_id_map) { 80 LayerIdMap* layer_id_map) {
96 LayerTreeHostCommon::CallFunctionForSubtree( 81 LayerTreeHostCommon::CallFunctionForSubtree(
97 layer.get(), 82 layer.get(),
98 [layer_id_map](Layer* layer) { (*layer_id_map)[layer->id()] = layer; }); 83 [layer_id_map](Layer* layer) { (*layer_id_map)[layer->id()] = layer; });
99 } 84 }
100 85
101 // static 86 // static
102 scoped_refptr<Layer> LayerProtoConverter::FindOrAllocateAndConstruct( 87 scoped_refptr<Layer> LayerProtoConverter::FindOrAllocateAndConstruct(
(...skipping 17 matching lines...) Expand all
120 case proto::LayerNode::HEADS_UP_DISPLAY_LAYER: 105 case proto::LayerNode::HEADS_UP_DISPLAY_LAYER:
121 return HeadsUpDisplayLayer::Create(LayerSettings()); 106 return HeadsUpDisplayLayer::Create(LayerSettings());
122 } 107 }
123 // TODO(nyquist): Add the rest of the necessary LayerTypes. This function 108 // TODO(nyquist): Add the rest of the necessary LayerTypes. This function
124 // should not return null. 109 // should not return null.
125 NOTREACHED(); 110 NOTREACHED();
126 return nullptr; 111 return nullptr;
127 } 112 }
128 113
129 } // namespace cc 114 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698