OLD | NEW |
(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 #ifndef CC_LAYERS_LAYER_PROTO_CONVERTER_H_ |
| 6 #define CC_LAYERS_LAYER_PROTO_CONVERTER_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "cc/base/cc_export.h" |
| 10 #include "cc/layers/layer.h" |
| 11 |
| 12 namespace cc { |
| 13 |
| 14 namespace proto { |
| 15 class LayerNode; |
| 16 } |
| 17 |
| 18 // A class to faciliate (de)serialization of a Layer tree to protocol buffers. |
| 19 class CC_EXPORT LayerProtoConverter { |
| 20 public: |
| 21 // Starting at |root_layer|, serializes the layer hierarchy into the |
| 22 // proto::LayerNode. |
| 23 static void SerializeLayerHierarchy(const scoped_refptr<Layer> root_layer, |
| 24 proto::LayerNode* root_node); |
| 25 |
| 26 // Recursively iterate over the given LayerNode proto and read the structure |
| 27 // into a local Layer structure, re-using existing Layers. returns the new |
| 28 // root Layer after updating the hierarchy (may be the same as |
| 29 // |existing_root|). |
| 30 static scoped_refptr<Layer> DeserializeLayerHierarchy( |
| 31 scoped_refptr<Layer> existing_root, |
| 32 const proto::LayerNode& root_node); |
| 33 |
| 34 // Returns the Layer with proto.id() as the Layer id, if it exists in |
| 35 // |layer_id_map|. Otherwise, a new Layer is constructed of the type given |
| 36 // from proto.type(). |
| 37 static scoped_refptr<Layer> FindOrAllocateAndConstruct( |
| 38 const proto::LayerNode& proto, |
| 39 const Layer::LayerIdMap& layer_id_map); |
| 40 |
| 41 private: |
| 42 LayerProtoConverter(); |
| 43 ~LayerProtoConverter(); |
| 44 |
| 45 using LayerIdMap = base::hash_map<int, scoped_refptr<Layer>>; |
| 46 // Start at |layer| and recursively add |layer| and all its children and |
| 47 // special layers to |layer_id_map|. |
| 48 static void RecursivelyFindAllLayers(const scoped_refptr<Layer>& layer, |
| 49 LayerIdMap* layer_id_map); |
| 50 }; |
| 51 |
| 52 } // namespace cc |
| 53 |
| 54 #endif // CC_LAYERS_LAYER_PROTO_CONVERTER_H_ |
OLD | NEW |