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