| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_BLIMP_COMPOSITOR_STATE_DESERIALIZER_H_ | 5 #ifndef CC_BLIMP_COMPOSITOR_STATE_DESERIALIZER_H_ |
| 6 #define CC_BLIMP_COMPOSITOR_STATE_DESERIALIZER_H_ | 6 #define CC_BLIMP_COMPOSITOR_STATE_DESERIALIZER_H_ |
| 7 | 7 |
| 8 #include <unordered_map> | 8 #include <unordered_map> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "cc/base/cc_export.h" | 12 #include "cc/base/cc_export.h" |
| 13 | 13 |
| 14 namespace cc { | 14 namespace cc { |
| 15 namespace proto { | 15 namespace proto { |
| 16 class LayerNode; | 16 class LayerNode; |
| 17 class LayerProperties; | 17 class LayerProperties; |
| 18 class LayerTree; | 18 class LayerTree; |
| 19 class LayerTreeHost; | 19 class LayerTreeHost; |
| 20 } // namespace proto | 20 } // namespace proto |
| 21 | 21 |
| 22 class ClientPictureCache; |
| 22 class CompositorStateDeserializerClient; | 23 class CompositorStateDeserializerClient; |
| 24 class DeserializedContentLayerClient; |
| 23 class Layer; | 25 class Layer; |
| 24 class LayerFactory; | 26 class LayerFactory; |
| 25 class LayerTreeHost; | 27 class LayerTreeHost; |
| 26 | 28 |
| 27 // Deserializes the compositor updates into the LayerTreeHost. | 29 // Deserializes the compositor updates into the LayerTreeHost. |
| 28 class CC_EXPORT CompositorStateDeserializer { | 30 class CC_EXPORT CompositorStateDeserializer { |
| 29 public: | 31 public: |
| 30 // ScrollCallback used to notify the client when the scroll offset for a layer | 32 // ScrollCallback used to notify the client when the scroll offset for a layer |
| 31 // is updated. | 33 // is updated. |
| 32 using ScrollCallback = base::Callback<void(int engine_layer_id)>; | 34 using ScrollCallback = base::Callback<void(int engine_layer_id)>; |
| 33 | 35 |
| 34 CompositorStateDeserializer(LayerTreeHost* layer_tree_host, | 36 CompositorStateDeserializer( |
| 35 ScrollCallback scroll_callback, | 37 LayerTreeHost* layer_tree_host, |
| 36 CompositorStateDeserializerClient* client); | 38 std::unique_ptr<ClientPictureCache> client_picture_cache, |
| 39 const ScrollCallback& scroll_callback, |
| 40 CompositorStateDeserializerClient* client); |
| 37 ~CompositorStateDeserializer(); | 41 ~CompositorStateDeserializer(); |
| 38 | 42 |
| 39 // Returns the local layer on the client for the given |engine_layer_id|. | 43 // Returns the local layer on the client for the given |engine_layer_id|. |
| 40 Layer* GetLayerForEngineId(int engine_layer_id) const; | 44 Layer* GetLayerForEngineId(int engine_layer_id) const; |
| 41 | 45 |
| 46 // Returns the local layer id on the client for the given |engine_layer_id|. |
| 47 int GetClientIdFromEngineId(int engine_layer_id) const; |
| 48 |
| 42 // Deserializes the |layer_tree_host_proto| into the LayerTreeHost. | 49 // Deserializes the |layer_tree_host_proto| into the LayerTreeHost. |
| 43 void DeserializeCompositorUpdate( | 50 void DeserializeCompositorUpdate( |
| 44 const proto::LayerTreeHost& layer_tree_host_proto); | 51 const proto::LayerTreeHost& layer_tree_host_proto); |
| 45 | 52 |
| 46 // Allows tests to inject the LayerFactory. | 53 // Allows tests to inject the LayerFactory. |
| 47 void SetLayerFactoryForTesting(std::unique_ptr<LayerFactory> layer_factory); | 54 void SetLayerFactoryForTesting(std::unique_ptr<LayerFactory> layer_factory); |
| 48 | 55 |
| 49 private: | 56 private: |
| 50 using EngineIdToLayerMap = std::unordered_map<int, scoped_refptr<Layer>>; | 57 // A holder for the Layer and any data tied to it. |
| 58 struct LayerData { |
| 59 LayerData(); |
| 60 LayerData(LayerData&& other); |
| 61 ~LayerData(); |
| 62 |
| 63 LayerData& operator=(LayerData&& other); |
| 64 |
| 65 scoped_refptr<Layer> layer; |
| 66 |
| 67 // Set only for PictureLayers. |
| 68 std::unique_ptr<DeserializedContentLayerClient> content_layer_client; |
| 69 |
| 70 private: |
| 71 DISALLOW_COPY_AND_ASSIGN(LayerData); |
| 72 }; |
| 73 |
| 74 using EngineIdToLayerMap = std::unordered_map<int, LayerData>; |
| 75 // Map of the scrollbar layer id to the corresponding scroll layer id. Both |
| 76 // ids refer to the engine layer id. |
| 77 using ScrollbarLayerToScrollLayerId = std::unordered_map<int, int>; |
| 51 | 78 |
| 52 void SychronizeLayerTreeState(const proto::LayerTree& layer_tree_proto); | 79 void SychronizeLayerTreeState(const proto::LayerTree& layer_tree_proto); |
| 53 void SynchronizeLayerState( | 80 void SynchronizeLayerState( |
| 54 const proto::LayerProperties& layer_properties_proto); | 81 const proto::LayerProperties& layer_properties_proto); |
| 55 void SynchronizeLayerHierarchyRecursive(Layer* layer, | 82 void SynchronizeLayerHierarchyRecursive( |
| 56 const proto::LayerNode& layer_node, | 83 Layer* layer, |
| 57 EngineIdToLayerMap* new_layer_map); | 84 const proto::LayerNode& layer_node, |
| 85 EngineIdToLayerMap* new_layer_map, |
| 86 ScrollbarLayerToScrollLayerId* scrollbar_layer_to_scroll_layer); |
| 58 scoped_refptr<Layer> GetLayerAndAddToNewMap( | 87 scoped_refptr<Layer> GetLayerAndAddToNewMap( |
| 59 const proto::LayerNode& layer_node, | 88 const proto::LayerNode& layer_node, |
| 60 EngineIdToLayerMap* new_layer_map); | 89 EngineIdToLayerMap* new_layer_map, |
| 90 ScrollbarLayerToScrollLayerId* scrollbar_layer_to_scroll_layer); |
| 61 | 91 |
| 62 int GetClientIdFromEngineId(int engine_layer_id); | 92 scoped_refptr<Layer> GetLayer(int engine_layer_id) const; |
| 63 scoped_refptr<Layer> GetLayer(int engine_layer_id); | 93 DeserializedContentLayerClient* GetContentLayerClient( |
| 94 int engine_layer_id) const; |
| 64 | 95 |
| 65 std::unique_ptr<LayerFactory> layer_factory_; | 96 std::unique_ptr<LayerFactory> layer_factory_; |
| 97 |
| 66 LayerTreeHost* layer_tree_host_; | 98 LayerTreeHost* layer_tree_host_; |
| 99 std::unique_ptr<ClientPictureCache> client_picture_cache_; |
| 67 ScrollCallback scroll_callback_; | 100 ScrollCallback scroll_callback_; |
| 68 CompositorStateDeserializerClient* client_; | 101 CompositorStateDeserializerClient* client_; |
| 69 | 102 |
| 70 EngineIdToLayerMap engine_id_to_layer_; | 103 EngineIdToLayerMap engine_id_to_layer_; |
| 71 | 104 |
| 72 DISALLOW_COPY_AND_ASSIGN(CompositorStateDeserializer); | 105 DISALLOW_COPY_AND_ASSIGN(CompositorStateDeserializer); |
| 73 }; | 106 }; |
| 74 | 107 |
| 75 } // namespace cc | 108 } // namespace cc |
| 76 | 109 |
| 77 #endif // CC_BLIMP_COMPOSITOR_STATE_DESERIALIZER_H_ | 110 #endif // CC_BLIMP_COMPOSITOR_STATE_DESERIALIZER_H_ |
| OLD | NEW |