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