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

Side by Side Diff: cc/trees/remote_channel_impl.cc

Issue 1513643010: cc:: Add remote mode to the compositor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing comments. Created 4 years, 11 months 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
OLDNEW
(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 #include "cc/trees/remote_channel_impl.h"
6
7 #include "base/bind_helpers.h"
8 #include "base/single_thread_task_runner.h"
9 #include "cc/proto/compositor_message.pb.h"
10 #include "cc/proto/compositor_message_to_impl.pb.h"
11 #include "cc/proto/compositor_message_to_main.pb.h"
12 #include "cc/trees/layer_tree_host.h"
13 #include "cc/trees/layer_tree_settings.h"
14
15 namespace cc {
16
17 scoped_ptr<RemoteChannelImpl> RemoteChannelImpl::Create(
18 LayerTreeHost* layer_tree_host,
19 RemoteProtoChannel* remote_proto_channel,
20 TaskRunnerProvider* task_runner_provider) {
21 return make_scoped_ptr(new RemoteChannelImpl(
22 layer_tree_host, remote_proto_channel, task_runner_provider));
23 }
24
25 RemoteChannelImpl::RemoteChannelImpl(LayerTreeHost* layer_tree_host,
26 RemoteProtoChannel* remote_proto_channel,
27 TaskRunnerProvider* task_runner_provider)
28 : main_thread_vars_unsafe_(layer_tree_host, remote_proto_channel),
29 task_runner_provider_(task_runner_provider) {
30 DCHECK(task_runner_provider_->IsMainThread());
31
32 main().remote_proto_channel->SetProtoReceiver(this);
33 }
34
35 RemoteChannelImpl::~RemoteChannelImpl() {
36 DCHECK(task_runner_provider_->IsMainThread());
37 DCHECK(!main().started);
38
39 main().remote_proto_channel->SetProtoReceiver(nullptr);
40 }
41
42 scoped_ptr<ProxyImpl> RemoteChannelImpl::CreateProxyImpl(
43 ChannelImpl* channel_impl,
44 LayerTreeHost* layer_tree_host,
45 TaskRunnerProvider* task_runner_provider,
46 scoped_ptr<BeginFrameSource> external_begin_frame_source) {
47 DCHECK(task_runner_provider_->IsImplThread());
48 DCHECK(!external_begin_frame_source);
49 return ProxyImpl::Create(channel_impl, layer_tree_host, task_runner_provider,
50 std::move(external_begin_frame_source));
51 }
52
53 void RemoteChannelImpl::OnProtoReceived(
54 scoped_ptr<proto::CompositorMessage> proto) {
55 DCHECK(task_runner_provider_->IsMainThread());
56 DCHECK(main().started);
57 DCHECK(proto->has_to_impl());
58
59 HandleProto(proto->to_impl());
60 }
61
62 void RemoteChannelImpl::HandleProto(
63 const proto::CompositorMessageToImpl& proto) {
64 DCHECK(task_runner_provider_->IsMainThread());
65
66 switch (proto.message_type()) {
67 case proto::CompositorMessageToImpl::
68 MAIN_THREAD_HAS_STOPPED_FLINGING_ON_IMPL:
69 ImplThreadTaskRunner()->PostTask(
70 FROM_HERE, base::Bind(&ProxyImpl::MainThreadHasStoppedFlingingOnImpl,
71 proxy_impl_weak_ptr_));
72 break;
73 default:
74 // TODO(khushalsagar): Add more types here.
75 NOTIMPLEMENTED();
76 }
77 }
78
79 void RemoteChannelImpl::FinishAllRendering() {
80 NOTREACHED() << "Should not be called on the remote client LayerTreeHost";
81 }
82
83 bool RemoteChannelImpl::IsStarted() const {
84 DCHECK(task_runner_provider_->IsMainThread());
85 return main().started;
86 }
87
88 bool RemoteChannelImpl::CommitToActiveTree() const {
89 return false;
90 }
91
92 void RemoteChannelImpl::SetOutputSurface(OutputSurface* output_surface) {
93 DCHECK(task_runner_provider_->IsMainThread());
94 ImplThreadTaskRunner()->PostTask(
95 FROM_HERE, base::Bind(&ProxyImpl::InitializeOutputSurfaceOnImpl,
96 proxy_impl_weak_ptr_, output_surface));
97 }
98
99 void RemoteChannelImpl::ReleaseOutputSurface() {
100 DCHECK(task_runner_provider_->IsMainThread());
101 CompletionEvent completion;
102 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
103 ImplThreadTaskRunner()->PostTask(
104 FROM_HERE, base::Bind(&ProxyImpl::ReleaseOutputSurfaceOnImpl,
105 proxy_impl_weak_ptr_, &completion));
106 completion.Wait();
107 }
108
109 void RemoteChannelImpl::SetVisible(bool visible) {
110 DCHECK(task_runner_provider_->IsMainThread());
111 ImplThreadTaskRunner()->PostTask(
112 FROM_HERE,
113 base::Bind(&ProxyImpl::SetVisibleOnImpl, proxy_impl_weak_ptr_, visible));
114 }
115
116 void RemoteChannelImpl::SetThrottleFrameProduction(bool throttle) {
117 NOTREACHED() << "Should not be called on the remote client LayerTreeHost";
118 }
119
120 const RendererCapabilities& RemoteChannelImpl::GetRendererCapabilities() const {
121 NOTREACHED() << "Should not be called on the remote client LayerTreeHost";
122 return main().renderer_capabilities;
123 }
124
125 void RemoteChannelImpl::SetNeedsAnimate() {
126 NOTREACHED() << "Should not be called on the remote client LayerTreeHost";
127 }
128
129 void RemoteChannelImpl::SetNeedsUpdateLayers() {
130 NOTREACHED() << "Should not be called on the remote client LayerTreeHost";
131 }
132
133 void RemoteChannelImpl::SetNeedsCommit() {
134 NOTREACHED() << "Should not be called on the remote client LayerTreeHost";
135 }
136
137 void RemoteChannelImpl::SetNeedsRedraw(const gfx::Rect& damage_rect) {
138 NOTREACHED() << "Should not be called on the remote client LayerTreeHost";
139 }
140
141 void RemoteChannelImpl::SetNextCommitWaitsForActivation() {
142 NOTREACHED() << "Should not be called on the remote client LayerTreeHost";
143 }
144
145 void RemoteChannelImpl::NotifyInputThrottledUntilCommit() {
146 NOTREACHED() << "Should not be called on the remote client LayerTreeHost";
147 }
148
149 void RemoteChannelImpl::SetDeferCommits(bool defer_commits) {
150 NOTREACHED() << "Should not be called on the remote client LayerTreeHost";
151 }
152
153 void RemoteChannelImpl::MainThreadHasStoppedFlinging() {
154 NOTREACHED() << "Should not be called on the remote client LayerTreeHost";
155 }
156
157 bool RemoteChannelImpl::CommitRequested() const {
158 NOTREACHED() << "Should not be called on the remote client LayerTreeHost";
159 return false;
160 }
161
162 bool RemoteChannelImpl::BeginMainFrameRequested() const {
163 NOTREACHED() << "Should not be called on the remote client LayerTreeHost";
164 return false;
165 }
166
167 void RemoteChannelImpl::Start(
168 scoped_ptr<BeginFrameSource> external_begin_frame_source) {
169 DCHECK(task_runner_provider_->IsMainThread());
170 DCHECK(!main().started);
171 DCHECK(!external_begin_frame_source);
172
173 CompletionEvent completion;
174 {
175 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
176 ImplThreadTaskRunner()->PostTask(
177 FROM_HERE, base::Bind(&RemoteChannelImpl::InitializeImplOnImpl,
178 base::Unretained(this), &completion,
179 main().layer_tree_host));
180 completion.Wait();
181 }
182 main().started = true;
183 }
184
185 void RemoteChannelImpl::Stop() {
186 DCHECK(task_runner_provider_->IsMainThread());
187 DCHECK(main().started);
188
189 {
190 CompletionEvent completion;
191 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
192 ImplThreadTaskRunner()->PostTask(
193 FROM_HERE, base::Bind(&ProxyImpl::FinishGLOnImpl, proxy_impl_weak_ptr_,
194 &completion));
195 completion.Wait();
196 }
197 {
198 CompletionEvent completion;
199 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
200 ImplThreadTaskRunner()->PostTask(
201 FROM_HERE, base::Bind(&RemoteChannelImpl::ShutdownImplOnImpl,
202 base::Unretained(this), &completion));
203 completion.Wait();
204 }
205
206 main().started = false;
207 }
208
209 bool RemoteChannelImpl::SupportsImplScrolling() const {
210 return true;
211 }
212
213 void RemoteChannelImpl::SetChildrenNeedBeginFrames(
214 bool children_need_begin_frames) {
215 NOTREACHED() << "Should not be called on the remote client LayerTreeHost";
216 }
217
218 void RemoteChannelImpl::SetAuthoritativeVSyncInterval(
219 const base::TimeDelta& interval) {
220 NOTREACHED() << "Should not be called on the remote client LayerTreeHost";
221 }
222
223 void RemoteChannelImpl::UpdateTopControlsState(TopControlsState constraints,
224 TopControlsState current,
225 bool animate) {
226 NOTREACHED() << "Should not be called on the remote client LayerTreeHost";
227 }
228
229 bool RemoteChannelImpl::MainFrameWillHappenForTesting() {
230 DCHECK(task_runner_provider_->IsMainThread());
231 bool main_frame_will_happen;
232 {
233 CompletionEvent completion;
234 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_);
235 ImplThreadTaskRunner()->PostTask(
236 FROM_HERE,
237 base::Bind(&ProxyImpl::MainFrameWillHappenOnImplForTesting,
238 proxy_impl_weak_ptr_, &completion, &main_frame_will_happen));
239 completion.Wait();
240 }
241 return main_frame_will_happen;
242 }
243
244 void RemoteChannelImpl::DidCompleteSwapBuffers() {}
245
246 void RemoteChannelImpl::SetRendererCapabilitiesMainCopy(
247 const RendererCapabilities& capabilities) {}
248
249 void RemoteChannelImpl::BeginMainFrameNotExpectedSoon() {}
250
251 void RemoteChannelImpl::DidCommitAndDrawFrame() {}
252
253 void RemoteChannelImpl::SetAnimationEvents(
254 scoped_ptr<AnimationEventsVector> queue) {}
255
256 void RemoteChannelImpl::DidLoseOutputSurface() {}
257
258 void RemoteChannelImpl::RequestNewOutputSurface() {}
259
260 void RemoteChannelImpl::DidInitializeOutputSurface(
261 bool success,
262 const RendererCapabilities& capabilities) {}
263
264 void RemoteChannelImpl::DidCompletePageScaleAnimation() {}
265
266 void RemoteChannelImpl::PostFrameTimingEventsOnMain(
267 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events,
268 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) {}
269
270 void RemoteChannelImpl::BeginMainFrame(
271 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) {}
272
273 void RemoteChannelImpl::InitializeImplOnImpl(CompletionEvent* completion,
274 LayerTreeHost* layer_tree_host) {
275 DCHECK(task_runner_provider_->IsMainThreadBlocked());
276 DCHECK(task_runner_provider_->IsImplThread());
277
278 impl().proxy_impl =
279 CreateProxyImpl(this, layer_tree_host, task_runner_provider_, nullptr);
280 impl().proxy_impl_weak_factory = make_scoped_ptr(
281 new base::WeakPtrFactory<ProxyImpl>(impl().proxy_impl.get()));
282 proxy_impl_weak_ptr_ = impl().proxy_impl_weak_factory->GetWeakPtr();
283 completion->Signal();
284 }
285
286 void RemoteChannelImpl::ShutdownImplOnImpl(CompletionEvent* completion) {
287 DCHECK(task_runner_provider_->IsMainThreadBlocked());
288 DCHECK(task_runner_provider_->IsImplThread());
289
290 // We must invalidate the proxy_impl weak ptrs and destroy the weak ptr
291 // factory before destroying proxy_impl.
292 impl().proxy_impl_weak_factory->InvalidateWeakPtrs();
293 impl().proxy_impl_weak_factory.reset();
294
295 impl().proxy_impl.reset();
296 completion->Signal();
297 }
298
299 RemoteChannelImpl::MainThreadOnly& RemoteChannelImpl::main() {
300 DCHECK(task_runner_provider_->IsMainThread());
301 return main_thread_vars_unsafe_;
302 }
303
304 const RemoteChannelImpl::MainThreadOnly& RemoteChannelImpl::main() const {
305 DCHECK(task_runner_provider_->IsMainThread());
306 return main_thread_vars_unsafe_;
307 }
308
309 RemoteChannelImpl::CompositorThreadOnly& RemoteChannelImpl::impl() {
310 DCHECK(task_runner_provider_->IsImplThread());
311 return compositor_thread_vars_unsafe_;
312 }
313
314 const RemoteChannelImpl::CompositorThreadOnly& RemoteChannelImpl::impl() const {
315 DCHECK(task_runner_provider_->IsImplThread());
316 return compositor_thread_vars_unsafe_;
317 }
318
319 base::SingleThreadTaskRunner* RemoteChannelImpl::MainThreadTaskRunner() const {
320 return task_runner_provider_->MainThreadTaskRunner();
321 }
322
323 base::SingleThreadTaskRunner* RemoteChannelImpl::ImplThreadTaskRunner() const {
324 return task_runner_provider_->ImplThreadTaskRunner();
325 }
326
327 RemoteChannelImpl::MainThreadOnly::MainThreadOnly(
328 LayerTreeHost* layer_tree_host,
329 RemoteProtoChannel* remote_proto_channel)
330 : layer_tree_host(layer_tree_host),
331 remote_proto_channel(remote_proto_channel),
332 started(false) {
333 DCHECK(layer_tree_host);
334 DCHECK(remote_proto_channel);
335 }
336
337 RemoteChannelImpl::MainThreadOnly::~MainThreadOnly() {}
338
339 RemoteChannelImpl::CompositorThreadOnly::CompositorThreadOnly()
340 : proxy_impl(nullptr), proxy_impl_weak_factory(nullptr) {}
341
342 RemoteChannelImpl::CompositorThreadOnly::~CompositorThreadOnly() {}
343
344 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698