OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CC_BLIMP_COMPOSITOR_STATE_DESERIALIZER_H_ | |
6 #define CC_BLIMP_COMPOSITOR_STATE_DESERIALIZER_H_ | |
7 | |
8 #include <unordered_map> | |
9 | |
10 #include "base/callback.h" | |
11 #include "base/macros.h" | |
12 #include "base/memory/weak_ptr.h" | |
13 #include "cc/base/cc_export.h" | |
14 #include "cc/blimp/synced_property_remote.h" | |
15 #include "ui/gfx/geometry/scroll_offset.h" | |
16 | |
17 namespace cc { | |
18 namespace proto { | |
19 class ClientStateUpdate; | |
20 class LayerNode; | |
21 class LayerProperties; | |
22 class LayerTree; | |
23 class LayerTreeHost; | |
24 } // namespace proto | |
25 | |
26 class ClientPictureCache; | |
27 class DeserializedContentLayerClient; | |
28 class Layer; | |
29 class LayerFactory; | |
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 }; | |
41 | |
42 // Deserializes the compositor updates into the LayerTreeHost. | |
43 class CC_EXPORT CompositorStateDeserializer { | |
44 public: | |
45 CompositorStateDeserializer( | |
46 LayerTreeHostInProcess* layer_tree_host, | |
47 std::unique_ptr<ClientPictureCache> client_picture_cache, | |
48 CompositorStateDeserializerClient* client); | |
49 ~CompositorStateDeserializer(); | |
50 | |
51 // Returns the local layer on the client for the given |engine_layer_id|. | |
52 Layer* GetLayerForEngineId(int engine_layer_id) const; | |
53 | |
54 // Deserializes the |layer_tree_host_proto| into the LayerTreeHost. | |
55 void DeserializeCompositorUpdate( | |
56 const proto::LayerTreeHost& layer_tree_host_proto); | |
57 | |
58 // Allows tests to inject the LayerFactory. | |
59 void SetLayerFactoryForTesting(std::unique_ptr<LayerFactory> layer_factory); | |
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 | |
87 private: | |
88 using SyncedRemoteScrollOffset = | |
89 SyncedPropertyRemote<AdditionGroup<gfx::ScrollOffset>>; | |
90 | |
91 // A holder for the Layer and any data tied to it. | |
92 struct LayerData { | |
93 LayerData(); | |
94 LayerData(LayerData&& other); | |
95 ~LayerData(); | |
96 | |
97 LayerData& operator=(LayerData&& other); | |
98 | |
99 scoped_refptr<Layer> layer; | |
100 | |
101 // Set only for PictureLayers. | |
102 std::unique_ptr<DeserializedContentLayerClient> content_layer_client; | |
103 | |
104 SyncedRemoteScrollOffset synced_scroll_offset; | |
105 | |
106 private: | |
107 DISALLOW_COPY_AND_ASSIGN(LayerData); | |
108 }; | |
109 | |
110 using EngineIdToLayerMap = std::unordered_map<int, LayerData>; | |
111 // Map of the scrollbar layer id to the corresponding scroll layer id. Both | |
112 // ids refer to the engine layer id. | |
113 using ScrollbarLayerToScrollLayerId = std::unordered_map<int, int>; | |
114 | |
115 void SychronizeLayerTreeState(const proto::LayerTree& layer_tree_proto); | |
116 void SynchronizeLayerState( | |
117 const proto::LayerProperties& layer_properties_proto); | |
118 void SynchronizeLayerHierarchyRecursive( | |
119 Layer* layer, | |
120 const proto::LayerNode& layer_node, | |
121 EngineIdToLayerMap* new_layer_map, | |
122 ScrollbarLayerToScrollLayerId* scrollbar_layer_to_scroll_layer); | |
123 scoped_refptr<Layer> GetLayerAndAddToNewMap( | |
124 const proto::LayerNode& layer_node, | |
125 EngineIdToLayerMap* new_layer_map, | |
126 ScrollbarLayerToScrollLayerId* scrollbar_layer_to_scroll_layer); | |
127 | |
128 void LayerScrolled(int engine_layer_id); | |
129 | |
130 scoped_refptr<Layer> GetLayer(int engine_layer_id) const; | |
131 DeserializedContentLayerClient* GetContentLayerClient( | |
132 int engine_layer_id) const; | |
133 int GetClientIdFromEngineId(int engine_layer_id) const; | |
134 LayerData* GetLayerData(int engine_layer_id); | |
135 | |
136 std::unique_ptr<LayerFactory> layer_factory_; | |
137 | |
138 LayerTreeHostInProcess* layer_tree_host_; | |
139 std::unique_ptr<ClientPictureCache> client_picture_cache_; | |
140 CompositorStateDeserializerClient* client_; | |
141 | |
142 EngineIdToLayerMap engine_id_to_layer_; | |
143 SyncedPropertyRemote<ScaleGroup> synced_page_scale_; | |
144 | |
145 base::WeakPtrFactory<CompositorStateDeserializer> weak_factory_; | |
146 | |
147 DISALLOW_COPY_AND_ASSIGN(CompositorStateDeserializer); | |
148 }; | |
149 | |
150 } // namespace cc | |
151 | |
152 #endif // CC_BLIMP_COMPOSITOR_STATE_DESERIALIZER_H_ | |
OLD | NEW |