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

Unified Diff: cc/layers/layer_deserializer.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: Fixed CC_EXPORT 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698