Chromium Code Reviews| Index: cc/layers/layer_deserializer.cc |
| diff --git a/cc/layers/layer_deserializer.cc b/cc/layers/layer_deserializer.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..199cb467dfb2c1a69f7e93a8900eaf28a54406cd |
| --- /dev/null |
| +++ b/cc/layers/layer_deserializer.cc |
| @@ -0,0 +1,51 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "cc/layers/layer_deserializer.h" |
| + |
| +#include "base/stl_util.h" |
| +#include "cc/layers/layer.h" |
| +#include "cc/layers/layer_proto_factory.h" |
| +#include "cc/proto/layer.pb.h" |
| + |
| +namespace cc { |
| + |
| +LayerDeserializer::LayerDeserializer() {} |
| + |
| +LayerDeserializer::~LayerDeserializer() {} |
| + |
| +// static |
| +scoped_refptr<Layer> LayerDeserializer::DeserializeLayerHierarchy( |
| + scoped_refptr<Layer> existing_root, |
| + const proto::LayerNode& root_node) { |
| + LayerIdMap layer_id_map; |
| + RecursivelyFindAllLayers(existing_root, &layer_id_map); |
| + |
| + scoped_refptr<Layer> new_root = existing_root; |
| + if (!existing_root || |
| + (root_node.has_id() && root_node.id() != (uint32)existing_root->id())) { |
|
vmpstr
2015/10/21 22:34:14
no c-style casts, is the type of the id in the pro
nyquist
2015/10/23 00:12:30
My bad. Fixed proto.
|
| + // The root node has changed or there was no root node, |
| + // so find or create the new root. |
| + new_root = |
| + LayerProtoFactory::FindOrAllocateAndConstruct(root_node, layer_id_map); |
| + } |
| + new_root->FromLayerNodeProto(root_node, layer_id_map); |
| + return new_root; |
| +} |
| + |
| +// static |
| +void LayerDeserializer::RecursivelyFindAllLayers(scoped_refptr<Layer> layer, |
|
vmpstr
2015/10/21 22:34:14
Can you use LayerTreeHostComon::CallFunctionForSub
nyquist
2015/10/23 00:12:30
Awesome! Thanks!
|
| + LayerIdMap* layer_id_map) { |
| + (*layer_id_map)[layer->id()] = layer; |
| + for (auto child : layer->children()) { |
| + RecursivelyFindAllLayers(child, layer_id_map); |
| + } |
| + |
| + if (layer->mask_layer()) |
| + RecursivelyFindAllLayers(layer->mask_layer(), layer_id_map); |
| + if (layer->replica_layer()) |
| + RecursivelyFindAllLayers(layer->replica_layer(), layer_id_map); |
| +} |
| + |
| +} // namespace cc |