Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(324)

Side by Side Diff: blimp/client/core/compositor/blimp_compositor.h

Issue 2445093002: cc/blimp: Add synchronization for scroll/scale state. (Closed)
Patch Set: test compile Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « blimp/client/core/compositor/BUILD.gn ('k') | blimp/client/core/compositor/blimp_compositor.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 BLIMP_CLIENT_CORE_COMPOSITOR_BLIMP_COMPOSITOR_H_ 5 #ifndef BLIMP_CLIENT_CORE_COMPOSITOR_BLIMP_COMPOSITOR_H_
6 #define BLIMP_CLIENT_CORE_COMPOSITOR_BLIMP_COMPOSITOR_H_ 6 #define BLIMP_CLIENT_CORE_COMPOSITOR_BLIMP_COMPOSITOR_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/threading/thread_checker.h" 13 #include "base/threading/thread_checker.h"
14 #include "blimp/client/core/compositor/blimp_compositor_frame_sink_proxy.h" 14 #include "blimp/client/core/compositor/blimp_compositor_frame_sink_proxy.h"
15 #include "blimp/client/public/compositor/compositor_dependencies.h" 15 #include "blimp/client/public/compositor/compositor_dependencies.h"
16 #include "cc/blimp/compositor_state_deserializer_client.h" 16 #include "cc/blimp/compositor_state_deserializer.h"
17 #include "cc/surfaces/surface_factory_client.h" 17 #include "cc/surfaces/surface_factory_client.h"
18 #include "cc/trees/layer_tree_host.h" 18 #include "cc/trees/layer_tree_host.h"
19 #include "cc/trees/layer_tree_host_client.h" 19 #include "cc/trees/layer_tree_host_client.h"
20 #include "cc/trees/layer_tree_settings.h" 20 #include "cc/trees/layer_tree_settings.h"
21 #include "cc/trees/remote_proto_channel.h" 21 #include "cc/trees/remote_proto_channel.h"
22 #include "ui/gfx/geometry/size.h" 22 #include "ui/gfx/geometry/size.h"
23 #include "ui/gfx/native_widget_types.h" 23 #include "ui/gfx/native_widget_types.h"
24 24
25 namespace base { 25 namespace base {
26 class SingleThreadTaskRunner; 26 class SingleThreadTaskRunner;
27 class Thread; 27 class Thread;
28 } // namespace base 28 } // namespace base
29 29
30 namespace cc { 30 namespace cc {
31 class InputHandler; 31 class InputHandler;
32 32
33 namespace proto { 33 namespace proto {
34 class CompositorMessage; 34 class CompositorMessage;
35 } // namespace proto 35 } // namespace proto
36 36
37 class CompositorStateDeserializer;
38 class ContextProvider; 37 class ContextProvider;
39 class CopyOutputRequest; 38 class CopyOutputRequest;
40 class Layer; 39 class Layer;
41 class LayerTreeHost; 40 class LayerTreeHostInProcess;
42 class LayerTreeSettings; 41 class LayerTreeSettings;
43 class LocalFrameid; 42 class LocalFrameid;
44 class Surface; 43 class Surface;
45 class SurfaceFactory; 44 class SurfaceFactory;
46 class SurfaceIdAllocator; 45 class SurfaceIdAllocator;
47 } // namespace cc 46 } // namespace cc
48 47
49 namespace blimp { 48 namespace blimp {
50 class BlimpMessage; 49 class BlimpMessage;
51 50
(...skipping 24 matching lines...) Expand all
76 // RenderWidget, identified by a custom |render_widget_id| generated on the 75 // RenderWidget, identified by a custom |render_widget_id| generated on the
77 // engine. The lifetime of this compositor is controlled by its corresponding 76 // engine. The lifetime of this compositor is controlled by its corresponding
78 // RenderWidget. 77 // RenderWidget.
79 // This class should only be accessed from the main thread. 78 // This class should only be accessed from the main thread.
80 class BlimpCompositor : public cc::LayerTreeHostClient, 79 class BlimpCompositor : public cc::LayerTreeHostClient,
81 public cc::RemoteProtoChannel, 80 public cc::RemoteProtoChannel,
82 public BlimpCompositorFrameSinkProxy, 81 public BlimpCompositorFrameSinkProxy,
83 public cc::SurfaceFactoryClient, 82 public cc::SurfaceFactoryClient,
84 public cc::CompositorStateDeserializerClient { 83 public cc::CompositorStateDeserializerClient {
85 public: 84 public:
86 BlimpCompositor(BlimpCompositorDependencies* compositor_dependencies, 85 static std::unique_ptr<BlimpCompositor> Create(
87 BlimpCompositorClient* client, 86 BlimpCompositorDependencies* compositor_dependencies,
88 bool use_threaded_layer_tree_host); 87 BlimpCompositorClient* client,
88 bool use_threaded_layer_tree_host);
89 89
90 ~BlimpCompositor() override; 90 ~BlimpCompositor() override;
91 91
92 virtual void SetVisible(bool visible); 92 void SetVisible(bool visible);
93 bool IsVisible() const;
93 94
94 // Requests a copy of the compositor frame. 95 // Requests a copy of the compositor frame.
95 // Setting |flush_pending_update| to true ensures that if a frame update on 96 // Setting |flush_pending_update| to true ensures that if a frame update on
96 // the main thread is pending, then it is drawn before copying from the 97 // the main thread is pending, then it is drawn before copying from the
97 // surface. 98 // surface.
98 void RequestCopyOfOutput(std::unique_ptr<cc::CopyOutputRequest> copy_request, 99 void RequestCopyOfOutput(std::unique_ptr<cc::CopyOutputRequest> copy_request,
99 bool flush_pending_update); 100 bool flush_pending_update);
100 101
101 // Called to forward the compositor message from the remote server 102 // Called to forward the compositor message from the remote server
102 // LayerTreeHost of the render widget for this compositor. 103 // LayerTreeHost of the render widget for this compositor.
103 // virtual for testing. 104 // virtual for testing.
104 virtual void OnCompositorMessageReceived( 105 void OnCompositorMessageReceived(
105 std::unique_ptr<cc::proto::CompositorMessage> message); 106 std::unique_ptr<cc::proto::CompositorMessage> message);
106 107
107 scoped_refptr<cc::Layer> layer() const { return layer_; } 108 scoped_refptr<cc::Layer> layer() const { return layer_; }
108 109
109 // Returns a reference to the InputHandler used to respond to input events on 110 // Returns a reference to the InputHandler used to respond to input events on
110 // the compositor thread. 111 // the compositor thread.
111 const base::WeakPtr<cc::InputHandler>& GetInputHandler(); 112 const base::WeakPtr<cc::InputHandler>& GetInputHandler();
112 113
113 private: 114 cc::CompositorStateDeserializer* compositor_state_deserializer_for_testing() {
114 friend class BlimpCompositorForTesting; 115 return compositor_state_deserializer_.get();
115 class FrameTrackingSwapPromise; 116 }
117
118 bool HasPendingFrameUpdateFromEngine() const;
116 119
117 // LayerTreeHostClient implementation. 120 // LayerTreeHostClient implementation.
118 void WillBeginMainFrame() override {} 121 void WillBeginMainFrame() override {}
119 void DidBeginMainFrame() override {} 122 void DidBeginMainFrame() override {}
120 void BeginMainFrame(const cc::BeginFrameArgs& args) override {} 123 void BeginMainFrame(const cc::BeginFrameArgs& args) override {}
121 void BeginMainFrameNotExpectedSoon() override {} 124 void BeginMainFrameNotExpectedSoon() override {}
122 void UpdateLayerTreeHost() override; 125 void UpdateLayerTreeHost() override;
123 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, 126 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta,
124 const gfx::Vector2dF& outer_delta, 127 const gfx::Vector2dF& outer_delta,
125 const gfx::Vector2dF& elastic_overscroll_delta, 128 const gfx::Vector2dF& elastic_overscroll_delta,
126 float page_scale, 129 float page_scale,
127 float top_controls_delta) override {} 130 float top_controls_delta) override;
128 void RequestNewCompositorFrameSink() override; 131 void RequestNewCompositorFrameSink() override;
129 void DidInitializeCompositorFrameSink() override; 132 void DidInitializeCompositorFrameSink() override;
130 // TODO(khushalsagar): Need to handle context initialization failures. 133 // TODO(khushalsagar): Need to handle context initialization failures.
131 void DidFailToInitializeCompositorFrameSink() override {} 134 void DidFailToInitializeCompositorFrameSink() override {}
132 void WillCommit() override {} 135 void WillCommit() override {}
133 void DidCommit() override {} 136 void DidCommit() override {}
134 void DidCommitAndDrawFrame() override; 137 void DidCommitAndDrawFrame() override;
135 void DidReceiveCompositorFrameAck() override {} 138 void DidReceiveCompositorFrameAck() override {}
136 void DidCompletePageScaleAnimation() override {} 139 void DidCompletePageScaleAnimation() override {}
137 140
141 // CompositorStateDeserializerClient implementation.
142 void DidUpdateLocalState() override;
143
144 protected:
145 BlimpCompositor(BlimpCompositorDependencies* compositor_dependencies,
146 BlimpCompositorClient* client,
147 bool use_threaded_layer_tree_host);
148
149 void Initialize();
150 virtual std::unique_ptr<cc::LayerTreeHostInProcess> CreateLayerTreeHost();
151
152 private:
153 class FrameTrackingSwapPromise;
154
138 // RemoteProtoChannel implementation. 155 // RemoteProtoChannel implementation.
139 void SetProtoReceiver(ProtoReceiver* receiver) override; 156 void SetProtoReceiver(ProtoReceiver* receiver) override;
140 void SendCompositorProto(const cc::proto::CompositorMessage& proto) override; 157 void SendCompositorProto(const cc::proto::CompositorMessage& proto) override;
141 158
142 // BlimpCompositorFrameSinkProxy implementation. 159 // BlimpCompositorFrameSinkProxy implementation.
143 void BindToProxyClient( 160 void BindToProxyClient(
144 base::WeakPtr<BlimpCompositorFrameSinkProxyClient> proxy_client) override; 161 base::WeakPtr<BlimpCompositorFrameSinkProxyClient> proxy_client) override;
145 void SubmitCompositorFrame(cc::CompositorFrame frame) override; 162 void SubmitCompositorFrame(cc::CompositorFrame frame) override;
146 void UnbindProxyClient() override; 163 void UnbindProxyClient() override;
147 164
148 // SurfaceFactoryClient implementation. 165 // SurfaceFactoryClient implementation.
149 void ReturnResources(const cc::ReturnedResourceArray& resources) override; 166 void ReturnResources(const cc::ReturnedResourceArray& resources) override;
150 void SetBeginFrameSource(cc::BeginFrameSource* begin_frame_source) override {} 167 void SetBeginFrameSource(cc::BeginFrameSource* begin_frame_source) override {}
151 168
152 // CompositorStateDeserializerClient implementation.
153 bool ShouldRetainClientScroll(int engine_layer_id,
154 const gfx::ScrollOffset& new_offset) override;
155 bool ShouldRetainClientPageScale(float new_page_scale) override;
156
157 void HandleCompositorMessageToImpl( 169 void HandleCompositorMessageToImpl(
158 std::unique_ptr<cc::proto::CompositorMessage> message); 170 std::unique_ptr<cc::proto::CompositorMessage> message);
159 171
160 // Called when the a ContextProvider has been created by the 172 // Called when the a ContextProvider has been created by the
161 // CompositorDependencies class. If |host_| is waiting on an 173 // CompositorDependencies class. If |host_| is waiting on an
162 // CompositorFrameSink this will build one for it. 174 // CompositorFrameSink this will build one for it.
163 void OnContextProvidersCreated( 175 void OnContextProvidersCreated(
164 const scoped_refptr<cc::ContextProvider>& compositor_context_provider, 176 const scoped_refptr<cc::ContextProvider>& compositor_context_provider,
165 const scoped_refptr<cc::ContextProvider>& worker_context_provider); 177 const scoped_refptr<cc::ContextProvider>& worker_context_provider);
166 178
167 // Helper method to get the embedder dependencies. 179 // Helper method to get the embedder dependencies.
168 CompositorDependencies* GetEmbedderDeps(); 180 CompositorDependencies* GetEmbedderDeps();
169 181
170 // TODO(khushalsagar): Move all of this to the |DocumentView| or another 182 // TODO(khushalsagar): Move all of this to the |DocumentView| or another
171 // platform specific class. So we use the DelegatedFrameHostAndroid like the 183 // platform specific class. So we use the DelegatedFrameHostAndroid like the
172 // RenderWidgetHostViewAndroid. 184 // RenderWidgetHostViewAndroid.
173 void DestroyDelegatedContent(); 185 void DestroyDelegatedContent();
174 186
175 // Helper method to build the internal CC LayerTreeHost instance from
176 // |message|.
177 void CreateLayerTreeHost();
178
179 // Helper method to destroy the internal CC LayerTreeHost instance and all its 187 // Helper method to destroy the internal CC LayerTreeHost instance and all its
180 // associated state. 188 // associated state.
181 void DestroyLayerTreeHost(); 189 void DestroyLayerTreeHost();
182 190
183 // Acks a submitted CompositorFrame when it has been processed and another 191 // Acks a submitted CompositorFrame when it has been processed and another
184 // frame should be started. 192 // frame should be started.
185 void SubmitCompositorFrameAck(); 193 void SubmitCompositorFrameAck();
186 194
187 // Called when the local copy of the layer with |engine_layer_id| on the 195 // Sends an update to the engine if the state on the client was modified and
188 // engine was scrolled on the compositor thread. 196 // an ack for a previous update sent is not pending.
189 void LayerScrolled(int engine_layer_id); 197 void FlushClientState();
190 198
191 // Set to true if we are using a LayerTreeHostInProcess to process frame 199 // Set to true if we are using a LayerTreeHostInProcess to process frame
192 // updates from the engine. 200 // updates from the engine.
193 const bool use_threaded_layer_tree_host_; 201 const bool use_threaded_layer_tree_host_;
194 202
195 void MakeCopyRequestOnNextSwap( 203 void MakeCopyRequestOnNextSwap(
196 std::unique_ptr<cc::CopyOutputRequest> copy_request); 204 std::unique_ptr<cc::CopyOutputRequest> copy_request);
197 205
198 void RequestCopyOfOutputDeprecated( 206 void RequestCopyOfOutputDeprecated(
199 std::unique_ptr<cc::CopyOutputRequest> copy_request); 207 std::unique_ptr<cc::CopyOutputRequest> copy_request);
200 208
201 BlimpCompositorClient* client_; 209 BlimpCompositorClient* client_;
202 210
203 BlimpCompositorDependencies* compositor_dependencies_; 211 BlimpCompositorDependencies* compositor_dependencies_;
204 212
205 cc::FrameSinkId frame_sink_id_; 213 cc::FrameSinkId frame_sink_id_;
206 214
207 std::unique_ptr<cc::LayerTreeHost> host_; 215 std::unique_ptr<cc::LayerTreeHostInProcess> host_;
208 216
209 // The SurfaceFactory is bound to the lifetime of the |proxy_client_|. When 217 // The SurfaceFactory is bound to the lifetime of the |proxy_client_|. When
210 // detached, the surface factory will be destroyed. 218 // detached, the surface factory will be destroyed.
211 std::unique_ptr<cc::SurfaceFactory> surface_factory_; 219 std::unique_ptr<cc::SurfaceFactory> surface_factory_;
212 base::WeakPtr<BlimpCompositorFrameSinkProxyClient> proxy_client_; 220 base::WeakPtr<BlimpCompositorFrameSinkProxyClient> proxy_client_;
213 221
214 // Whether or not |host_| has asked for a new CompositorFrameSink. 222 // Whether or not |host_| has asked for a new CompositorFrameSink.
215 bool compositor_frame_sink_request_pending_; 223 bool compositor_frame_sink_request_pending_;
216 224
217 // Data for the current frame. 225 // Data for the current frame.
(...skipping 30 matching lines...) Expand all
248 // Stores a frame update received from the engine, when a threaded 256 // Stores a frame update received from the engine, when a threaded
249 // LayerTreeHost is used. There can only be a single frame in flight at any 257 // LayerTreeHost is used. There can only be a single frame in flight at any
250 // point. 258 // point.
251 std::unique_ptr<cc::proto::CompositorMessage> pending_frame_update_; 259 std::unique_ptr<cc::proto::CompositorMessage> pending_frame_update_;
252 260
253 // Used with a threaded LayerTreeHost to deserialize proto updates from the 261 // Used with a threaded LayerTreeHost to deserialize proto updates from the
254 // engine into the LayerTree. 262 // engine into the LayerTree.
255 std::unique_ptr<cc::CompositorStateDeserializer> 263 std::unique_ptr<cc::CompositorStateDeserializer>
256 compositor_state_deserializer_; 264 compositor_state_deserializer_;
257 265
266 // Set to true if the compositor state on the client was modified on the impl
267 // thread and an update needs to be sent to the engine.
268 bool client_state_dirty_ = false;
269
270 // Set to true if a client state update was sent to the engine and an ack for
271 // this update from the engine is pending.
272 bool client_state_update_ack_pending_ = false;
273
258 base::WeakPtrFactory<BlimpCompositor> weak_ptr_factory_; 274 base::WeakPtrFactory<BlimpCompositor> weak_ptr_factory_;
259 275
260 DISALLOW_COPY_AND_ASSIGN(BlimpCompositor); 276 DISALLOW_COPY_AND_ASSIGN(BlimpCompositor);
261 }; 277 };
262 278
263 } // namespace client 279 } // namespace client
264 } // namespace blimp 280 } // namespace blimp
265 281
266 #endif // BLIMP_CLIENT_CORE_COMPOSITOR_BLIMP_COMPOSITOR_H_ 282 #endif // BLIMP_CLIENT_CORE_COMPOSITOR_BLIMP_COMPOSITOR_H_
OLDNEW
« no previous file with comments | « blimp/client/core/compositor/BUILD.gn ('k') | blimp/client/core/compositor/blimp_compositor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698