| 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 <unordered_map> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "cc/base/cc_export.h" | |
| 12 #include "cc/layers/layer.h" | |
| 13 | |
| 14 namespace cc { | |
| 15 | |
| 16 namespace proto { | |
| 17 class LayerNode; | |
| 18 class LayerUpdate; | |
| 19 } | |
| 20 | |
| 21 // A class to faciliate (de)serialization of a Layer tree to protocol buffers. | |
| 22 class CC_EXPORT LayerProtoConverter { | |
| 23 public: | |
| 24 // Recursively iterate over the given LayerNode proto and read the structure | |
| 25 // into a local Layer structure, re-using existing Layers. returns the new | |
| 26 // root Layer after updating the hierarchy (may be the same as | |
| 27 // |existing_root|). |existing_root| may be null, which might happen during | |
| 28 // the first deserialize. | |
| 29 static scoped_refptr<Layer> DeserializeLayerHierarchy( | |
| 30 const scoped_refptr<Layer> existing_root, | |
| 31 const proto::LayerNode& root_node, | |
| 32 LayerTreeHost* layer_tree); | |
| 33 | |
| 34 // Serializes the properties of all the dirty nodes in the Layer hierarchy. | |
| 35 // The proto::LayerUpdate will contain all nodes that are dirty. These nodes | |
| 36 // will contain the list of dirty properties. This function also resets the | |
| 37 // layers that need push properties set. | |
| 38 static void SerializeLayerProperties(LayerTreeHost* host, | |
| 39 proto::LayerUpdate* layer_update); | |
| 40 | |
| 41 // Iterate over all updated layers from the LayerUpdate, and update the | |
| 42 // local Layers. |existing_root| must not be null, as that will make it | |
| 43 // impossible to find the layer to apply the properties to. | |
| 44 static void DeserializeLayerProperties( | |
| 45 Layer* existing_root, | |
| 46 const proto::LayerUpdate& layer_update); | |
| 47 | |
| 48 // Returns the Layer with proto.id() as the Layer id, if it exists in | |
| 49 // |layer_id_map|. Otherwise, a new Layer is constructed of the type given | |
| 50 // from proto.type(). | |
| 51 static scoped_refptr<Layer> FindOrAllocateAndConstruct( | |
| 52 const proto::LayerNode& proto, | |
| 53 const Layer::LayerIdMap& layer_id_map); | |
| 54 | |
| 55 private: | |
| 56 LayerProtoConverter(); | |
| 57 ~LayerProtoConverter(); | |
| 58 | |
| 59 // This method is the inner recursive function for SerializeLayerProperties | |
| 60 // declared above. | |
| 61 static void RecursivelySerializeLayerProperties( | |
| 62 Layer* root_layer, | |
| 63 proto::LayerUpdate* layer_update); | |
| 64 | |
| 65 using LayerIdMap = std::unordered_map<int, scoped_refptr<Layer>>; | |
| 66 // Start at |root_layer| and recursively add the layer and all its children | |
| 67 // and special layers to |layer_id_map|. | |
| 68 // TODO(vmpstr): LayerIdMap ref counts layers, so this function needs to deal | |
| 69 // with ref counted objects instead of iterating over raw pointers. | |
| 70 static void RecursivelyFindAllLayers(Layer* root_layer, | |
| 71 LayerIdMap* layer_id_map); | |
| 72 }; | |
| 73 | |
| 74 } // namespace cc | |
| 75 | |
| 76 #endif // CC_LAYERS_LAYER_PROTO_CONVERTER_H_ | |
| OLD | NEW |