| 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 "base/memory/weak_ptr.h" |
| 12 #include "cc/base/cc_export.h" | 13 #include "cc/base/cc_export.h" |
| 14 #include "cc/blimp/synced_property_remote.h" |
| 15 #include "ui/gfx/geometry/scroll_offset.h" |
| 13 | 16 |
| 14 namespace cc { | 17 namespace cc { |
| 15 namespace proto { | 18 namespace proto { |
| 19 class ClientStateUpdate; |
| 16 class LayerNode; | 20 class LayerNode; |
| 17 class LayerProperties; | 21 class LayerProperties; |
| 18 class LayerTree; | 22 class LayerTree; |
| 19 class LayerTreeHost; | 23 class LayerTreeHost; |
| 20 } // namespace proto | 24 } // namespace proto |
| 21 | 25 |
| 22 class ClientPictureCache; | 26 class ClientPictureCache; |
| 23 class CompositorStateDeserializerClient; | |
| 24 class DeserializedContentLayerClient; | 27 class DeserializedContentLayerClient; |
| 25 class Layer; | 28 class Layer; |
| 26 class LayerFactory; | 29 class LayerFactory; |
| 27 class LayerTreeHost; | 30 class LayerTreeHostInProcess; |
| 31 |
| 32 class CC_EXPORT CompositorStateDeserializerClient { |
| 33 public: |
| 34 virtual ~CompositorStateDeserializerClient() {} |
| 35 |
| 36 // Used to inform the client that the local state received from the engine was |
| 37 // modified on the impl thread and a ClientStateUpdate needs to be scheduled |
| 38 // to synchronize it with the main thread on the engine. |
| 39 virtual void DidUpdateLocalState() = 0; |
| 40 }; |
| 28 | 41 |
| 29 // Deserializes the compositor updates into the LayerTreeHost. | 42 // Deserializes the compositor updates into the LayerTreeHost. |
| 30 class CC_EXPORT CompositorStateDeserializer { | 43 class CC_EXPORT CompositorStateDeserializer { |
| 31 public: | 44 public: |
| 32 // ScrollCallback used to notify the client when the scroll offset for a layer | |
| 33 // is updated. | |
| 34 using ScrollCallback = base::Callback<void(int engine_layer_id)>; | |
| 35 | |
| 36 CompositorStateDeserializer( | 45 CompositorStateDeserializer( |
| 37 LayerTreeHost* layer_tree_host, | 46 LayerTreeHostInProcess* layer_tree_host, |
| 38 std::unique_ptr<ClientPictureCache> client_picture_cache, | 47 std::unique_ptr<ClientPictureCache> client_picture_cache, |
| 39 const ScrollCallback& scroll_callback, | |
| 40 CompositorStateDeserializerClient* client); | 48 CompositorStateDeserializerClient* client); |
| 41 ~CompositorStateDeserializer(); | 49 ~CompositorStateDeserializer(); |
| 42 | 50 |
| 43 // Returns the local layer on the client for the given |engine_layer_id|. | 51 // Returns the local layer on the client for the given |engine_layer_id|. |
| 44 Layer* GetLayerForEngineId(int engine_layer_id) const; | 52 Layer* GetLayerForEngineId(int engine_layer_id) const; |
| 45 | 53 |
| 46 // Returns the local layer id on the client for the given |engine_layer_id|. | |
| 47 int GetClientIdFromEngineId(int engine_layer_id) const; | |
| 48 | |
| 49 // Deserializes the |layer_tree_host_proto| into the LayerTreeHost. | 54 // Deserializes the |layer_tree_host_proto| into the LayerTreeHost. |
| 50 void DeserializeCompositorUpdate( | 55 void DeserializeCompositorUpdate( |
| 51 const proto::LayerTreeHost& layer_tree_host_proto); | 56 const proto::LayerTreeHost& layer_tree_host_proto); |
| 52 | 57 |
| 53 // Allows tests to inject the LayerFactory. | 58 // Allows tests to inject the LayerFactory. |
| 54 void SetLayerFactoryForTesting(std::unique_ptr<LayerFactory> layer_factory); | 59 void SetLayerFactoryForTesting(std::unique_ptr<LayerFactory> layer_factory); |
| 55 | 60 |
| 61 // Updates any viewport related deltas that have been reported to the main |
| 62 // thread from the impl thread. |
| 63 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, |
| 64 const gfx::Vector2dF& outer_delta, |
| 65 const gfx::Vector2dF& elastic_overscroll_delta, |
| 66 float page_scale, |
| 67 float top_controls_delta); |
| 68 |
| 69 // Pulls a state update for changes reported to the main thread, that need to |
| 70 // be synchronized with the associated state on the engine main thread. |
| 71 void PullClientStateUpdate(proto::ClientStateUpdate* client_state_update); |
| 72 |
| 73 // Informs that the client state update pulled was applied to the main thread |
| 74 // on the engine. |
| 75 // Note that this assumes that the state update provided to the engine was |
| 76 // reflected back by the engine. If the application of this update resulted in |
| 77 // any changes to the main thread state on the engine, these must be |
| 78 // de-serialized and applied to the LayerTreeHost before a frame is committed |
| 79 // to the impl thread. |
| 80 void DidApplyStateUpdatesOnEngine(); |
| 81 |
| 82 // Sends any deltas that have been received on the main thread, but have not |
| 83 // yet been applied to the main thread state back to the impl thread. This |
| 84 // must be called for every main frame sent to the impl thread. |
| 85 void SendUnappliedDeltasToLayerTreeHost(); |
| 86 |
| 56 private: | 87 private: |
| 88 using SyncedRemoteScrollOffset = |
| 89 SyncedPropertyRemote<AdditionGroup<gfx::ScrollOffset>>; |
| 90 |
| 57 // A holder for the Layer and any data tied to it. | 91 // A holder for the Layer and any data tied to it. |
| 58 struct LayerData { | 92 struct LayerData { |
| 59 LayerData(); | 93 LayerData(); |
| 60 LayerData(LayerData&& other); | 94 LayerData(LayerData&& other); |
| 61 ~LayerData(); | 95 ~LayerData(); |
| 62 | 96 |
| 63 LayerData& operator=(LayerData&& other); | 97 LayerData& operator=(LayerData&& other); |
| 64 | 98 |
| 65 scoped_refptr<Layer> layer; | 99 scoped_refptr<Layer> layer; |
| 66 | 100 |
| 67 // Set only for PictureLayers. | 101 // Set only for PictureLayers. |
| 68 std::unique_ptr<DeserializedContentLayerClient> content_layer_client; | 102 std::unique_ptr<DeserializedContentLayerClient> content_layer_client; |
| 69 | 103 |
| 104 SyncedRemoteScrollOffset synced_scroll_offset; |
| 105 |
| 70 private: | 106 private: |
| 71 DISALLOW_COPY_AND_ASSIGN(LayerData); | 107 DISALLOW_COPY_AND_ASSIGN(LayerData); |
| 72 }; | 108 }; |
| 73 | 109 |
| 74 using EngineIdToLayerMap = std::unordered_map<int, LayerData>; | 110 using EngineIdToLayerMap = std::unordered_map<int, LayerData>; |
| 75 // Map of the scrollbar layer id to the corresponding scroll layer id. Both | 111 // Map of the scrollbar layer id to the corresponding scroll layer id. Both |
| 76 // ids refer to the engine layer id. | 112 // ids refer to the engine layer id. |
| 77 using ScrollbarLayerToScrollLayerId = std::unordered_map<int, int>; | 113 using ScrollbarLayerToScrollLayerId = std::unordered_map<int, int>; |
| 78 | 114 |
| 79 void SychronizeLayerTreeState(const proto::LayerTree& layer_tree_proto); | 115 void SychronizeLayerTreeState(const proto::LayerTree& layer_tree_proto); |
| 80 void SynchronizeLayerState( | 116 void SynchronizeLayerState( |
| 81 const proto::LayerProperties& layer_properties_proto); | 117 const proto::LayerProperties& layer_properties_proto); |
| 82 void SynchronizeLayerHierarchyRecursive( | 118 void SynchronizeLayerHierarchyRecursive( |
| 83 Layer* layer, | 119 Layer* layer, |
| 84 const proto::LayerNode& layer_node, | 120 const proto::LayerNode& layer_node, |
| 85 EngineIdToLayerMap* new_layer_map, | 121 EngineIdToLayerMap* new_layer_map, |
| 86 ScrollbarLayerToScrollLayerId* scrollbar_layer_to_scroll_layer); | 122 ScrollbarLayerToScrollLayerId* scrollbar_layer_to_scroll_layer); |
| 87 scoped_refptr<Layer> GetLayerAndAddToNewMap( | 123 scoped_refptr<Layer> GetLayerAndAddToNewMap( |
| 88 const proto::LayerNode& layer_node, | 124 const proto::LayerNode& layer_node, |
| 89 EngineIdToLayerMap* new_layer_map, | 125 EngineIdToLayerMap* new_layer_map, |
| 90 ScrollbarLayerToScrollLayerId* scrollbar_layer_to_scroll_layer); | 126 ScrollbarLayerToScrollLayerId* scrollbar_layer_to_scroll_layer); |
| 91 | 127 |
| 128 void LayerScrolled(int engine_layer_id); |
| 129 |
| 92 scoped_refptr<Layer> GetLayer(int engine_layer_id) const; | 130 scoped_refptr<Layer> GetLayer(int engine_layer_id) const; |
| 93 DeserializedContentLayerClient* GetContentLayerClient( | 131 DeserializedContentLayerClient* GetContentLayerClient( |
| 94 int engine_layer_id) const; | 132 int engine_layer_id) const; |
| 133 int GetClientIdFromEngineId(int engine_layer_id) const; |
| 134 LayerData* GetLayerData(int engine_layer_id); |
| 95 | 135 |
| 96 std::unique_ptr<LayerFactory> layer_factory_; | 136 std::unique_ptr<LayerFactory> layer_factory_; |
| 97 | 137 |
| 98 LayerTreeHost* layer_tree_host_; | 138 LayerTreeHostInProcess* layer_tree_host_; |
| 99 std::unique_ptr<ClientPictureCache> client_picture_cache_; | 139 std::unique_ptr<ClientPictureCache> client_picture_cache_; |
| 100 ScrollCallback scroll_callback_; | |
| 101 CompositorStateDeserializerClient* client_; | 140 CompositorStateDeserializerClient* client_; |
| 102 | 141 |
| 103 EngineIdToLayerMap engine_id_to_layer_; | 142 EngineIdToLayerMap engine_id_to_layer_; |
| 143 SyncedPropertyRemote<ScaleGroup> synced_page_scale_; |
| 144 |
| 145 base::WeakPtrFactory<CompositorStateDeserializer> weak_factory_; |
| 104 | 146 |
| 105 DISALLOW_COPY_AND_ASSIGN(CompositorStateDeserializer); | 147 DISALLOW_COPY_AND_ASSIGN(CompositorStateDeserializer); |
| 106 }; | 148 }; |
| 107 | 149 |
| 108 } // namespace cc | 150 } // namespace cc |
| 109 | 151 |
| 110 #endif // CC_BLIMP_COMPOSITOR_STATE_DESERIALIZER_H_ | 152 #endif // CC_BLIMP_COMPOSITOR_STATE_DESERIALIZER_H_ |
| OLD | NEW |