| 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 #include "cc/trees/remote_channel_impl.h" | 5 #include "cc/trees/remote_channel_impl.h" |
| 6 | 6 |
| 7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "cc/animation/animation_events.h" | 10 #include "cc/animation/animation_events.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 task_runner_provider, | 47 task_runner_provider, |
| 48 std::move(external_begin_frame_source)); | 48 std::move(external_begin_frame_source)); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void RemoteChannelImpl::OnProtoReceived( | 51 void RemoteChannelImpl::OnProtoReceived( |
| 52 std::unique_ptr<proto::CompositorMessage> proto) { | 52 std::unique_ptr<proto::CompositorMessage> proto) { |
| 53 DCHECK(task_runner_provider_->IsMainThread()); | 53 DCHECK(task_runner_provider_->IsMainThread()); |
| 54 DCHECK(main().started); | 54 DCHECK(main().started); |
| 55 DCHECK(proto->has_to_impl()); | 55 DCHECK(proto->has_to_impl()); |
| 56 | 56 |
| 57 // If we don't have an output surface, queue the message and defer processing | 57 // If we don't have an CompositorFrameSink, queue the message and defer |
| 58 // it till we initialize a new output surface. | 58 // processing it till we initialize a new CompositorFrameSink. |
| 59 if (main().waiting_for_output_surface_initialization) { | 59 if (main().waiting_for_compositor_frame_sink_initialization) { |
| 60 VLOG(1) << "Queueing message proto since output surface was released."; | 60 VLOG(1) << "Queueing message proto since CompositorFrameSink was released."; |
| 61 main().pending_messages.push(proto->to_impl()); | 61 main().pending_messages.push(proto->to_impl()); |
| 62 } else { | 62 } else { |
| 63 HandleProto(proto->to_impl()); | 63 HandleProto(proto->to_impl()); |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 | 66 |
| 67 void RemoteChannelImpl::HandleProto( | 67 void RemoteChannelImpl::HandleProto( |
| 68 const proto::CompositorMessageToImpl& proto) { | 68 const proto::CompositorMessageToImpl& proto) { |
| 69 DCHECK(task_runner_provider_->IsMainThread()); | 69 DCHECK(task_runner_provider_->IsMainThread()); |
| 70 DCHECK(proto.has_message_type()); | 70 DCHECK(proto.has_message_type()); |
| 71 DCHECK(!main().waiting_for_output_surface_initialization); | 71 DCHECK(!main().waiting_for_compositor_frame_sink_initialization); |
| 72 | 72 |
| 73 switch (proto.message_type()) { | 73 switch (proto.message_type()) { |
| 74 case proto::CompositorMessageToImpl::UNKNOWN: | 74 case proto::CompositorMessageToImpl::UNKNOWN: |
| 75 NOTIMPLEMENTED() << "Ignoring message of UNKNOWN type"; | 75 NOTIMPLEMENTED() << "Ignoring message of UNKNOWN type"; |
| 76 break; | 76 break; |
| 77 case proto::CompositorMessageToImpl::SET_NEEDS_COMMIT: | 77 case proto::CompositorMessageToImpl::SET_NEEDS_COMMIT: |
| 78 VLOG(1) << "Received commit request from the engine."; | 78 VLOG(1) << "Received commit request from the engine."; |
| 79 ImplThreadTaskRunner()->PostTask( | 79 ImplThreadTaskRunner()->PostTask( |
| 80 FROM_HERE, | 80 FROM_HERE, |
| 81 base::Bind(&ProxyImpl::SetNeedsCommitOnImpl, proxy_impl_weak_ptr_)); | 81 base::Bind(&ProxyImpl::SetNeedsCommitOnImpl, proxy_impl_weak_ptr_)); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 | 140 |
| 141 bool RemoteChannelImpl::IsStarted() const { | 141 bool RemoteChannelImpl::IsStarted() const { |
| 142 DCHECK(task_runner_provider_->IsMainThread()); | 142 DCHECK(task_runner_provider_->IsMainThread()); |
| 143 return main().started; | 143 return main().started; |
| 144 } | 144 } |
| 145 | 145 |
| 146 bool RemoteChannelImpl::CommitToActiveTree() const { | 146 bool RemoteChannelImpl::CommitToActiveTree() const { |
| 147 return false; | 147 return false; |
| 148 } | 148 } |
| 149 | 149 |
| 150 void RemoteChannelImpl::SetOutputSurface(OutputSurface* output_surface) { | 150 void RemoteChannelImpl::SetCompositorFrameSink( |
| 151 CompositorFrameSink* compositor_frame_sink) { |
| 151 DCHECK(task_runner_provider_->IsMainThread()); | 152 DCHECK(task_runner_provider_->IsMainThread()); |
| 152 | 153 |
| 153 ImplThreadTaskRunner()->PostTask( | 154 ImplThreadTaskRunner()->PostTask( |
| 154 FROM_HERE, base::Bind(&ProxyImpl::InitializeOutputSurfaceOnImpl, | 155 FROM_HERE, base::Bind(&ProxyImpl::InitializeCompositorFrameSinkOnImpl, |
| 155 proxy_impl_weak_ptr_, output_surface)); | 156 proxy_impl_weak_ptr_, compositor_frame_sink)); |
| 156 } | 157 } |
| 157 | 158 |
| 158 void RemoteChannelImpl::ReleaseOutputSurface() { | 159 void RemoteChannelImpl::ReleaseCompositorFrameSink() { |
| 159 DCHECK(task_runner_provider_->IsMainThread()); | 160 DCHECK(task_runner_provider_->IsMainThread()); |
| 160 DCHECK(!main().waiting_for_output_surface_initialization); | 161 DCHECK(!main().waiting_for_compositor_frame_sink_initialization); |
| 161 VLOG(1) << "Releasing Output Surface"; | 162 VLOG(1) << "Releasing CompositorFrameSink"; |
| 162 | 163 |
| 163 { | 164 { |
| 164 CompletionEvent completion; | 165 CompletionEvent completion; |
| 165 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); | 166 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); |
| 166 ImplThreadTaskRunner()->PostTask( | 167 ImplThreadTaskRunner()->PostTask( |
| 167 FROM_HERE, base::Bind(&ProxyImpl::ReleaseOutputSurfaceOnImpl, | 168 FROM_HERE, base::Bind(&ProxyImpl::ReleaseCompositorFrameSinkOnImpl, |
| 168 proxy_impl_weak_ptr_, &completion)); | 169 proxy_impl_weak_ptr_, &completion)); |
| 169 completion.Wait(); | 170 completion.Wait(); |
| 170 } | 171 } |
| 171 | 172 |
| 172 main().waiting_for_output_surface_initialization = true; | 173 main().waiting_for_compositor_frame_sink_initialization = true; |
| 173 } | 174 } |
| 174 | 175 |
| 175 void RemoteChannelImpl::SetVisible(bool visible) { | 176 void RemoteChannelImpl::SetVisible(bool visible) { |
| 176 DCHECK(task_runner_provider_->IsMainThread()); | 177 DCHECK(task_runner_provider_->IsMainThread()); |
| 177 VLOG(1) << "Setting visibility to: " << visible; | 178 VLOG(1) << "Setting visibility to: " << visible; |
| 178 | 179 |
| 179 ImplThreadTaskRunner()->PostTask( | 180 ImplThreadTaskRunner()->PostTask( |
| 180 FROM_HERE, | 181 FROM_HERE, |
| 181 base::Bind(&ProxyImpl::SetVisibleOnImpl, proxy_impl_weak_ptr_, visible)); | 182 base::Bind(&ProxyImpl::SetVisibleOnImpl, proxy_impl_weak_ptr_, visible)); |
| 182 } | 183 } |
| 183 | 184 |
| 184 void RemoteChannelImpl::SetNeedsAnimate() { | 185 void RemoteChannelImpl::SetNeedsAnimate() { |
| 185 NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; | 186 NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; |
| 186 } | 187 } |
| 187 | 188 |
| 188 void RemoteChannelImpl::SetNeedsUpdateLayers() { | 189 void RemoteChannelImpl::SetNeedsUpdateLayers() { |
| 189 NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; | 190 NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; |
| 190 } | 191 } |
| 191 | 192 |
| 192 void RemoteChannelImpl::SetNeedsCommit() { | 193 void RemoteChannelImpl::SetNeedsCommit() { |
| 193 // Ideally commits should be requested only on the server. But we have to | 194 // Ideally commits should be requested only on the server. But we have to |
| 194 // allow this call since the LayerTreeHost will currently ask for a commit in | 195 // allow this call since the LayerTreeHost will currently ask for a commit in |
| 195 // 2 cases: | 196 // 2 cases: |
| 196 // 1) When it is being initialized from a protobuf for a commit. | 197 // 1) When it is being initialized from a protobuf for a commit. |
| 197 // 2) When it loses the output surface. | 198 // 2) When it loses the CompositorFrameSink. |
| 198 NOTIMPLEMENTED() << "Commits should not be requested on the client"; | 199 NOTIMPLEMENTED() << "Commits should not be requested on the client"; |
| 199 } | 200 } |
| 200 | 201 |
| 201 void RemoteChannelImpl::SetNeedsRedraw(const gfx::Rect& damage_rect) { | 202 void RemoteChannelImpl::SetNeedsRedraw(const gfx::Rect& damage_rect) { |
| 202 NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; | 203 NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; |
| 203 } | 204 } |
| 204 | 205 |
| 205 void RemoteChannelImpl::SetNextCommitWaitsForActivation() { | 206 void RemoteChannelImpl::SetNextCommitWaitsForActivation() { |
| 206 NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; | 207 NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; |
| 207 } | 208 } |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 void RemoteChannelImpl::DidCommitAndDrawFrame() { | 313 void RemoteChannelImpl::DidCommitAndDrawFrame() { |
| 313 DCHECK(task_runner_provider_->IsImplThread()); | 314 DCHECK(task_runner_provider_->IsImplThread()); |
| 314 MainThreadTaskRunner()->PostTask( | 315 MainThreadTaskRunner()->PostTask( |
| 315 FROM_HERE, base::Bind(&RemoteChannelImpl::DidCommitAndDrawFrameOnMain, | 316 FROM_HERE, base::Bind(&RemoteChannelImpl::DidCommitAndDrawFrameOnMain, |
| 316 impl().remote_channel_weak_ptr)); | 317 impl().remote_channel_weak_ptr)); |
| 317 } | 318 } |
| 318 | 319 |
| 319 void RemoteChannelImpl::SetAnimationEvents( | 320 void RemoteChannelImpl::SetAnimationEvents( |
| 320 std::unique_ptr<AnimationEvents> queue) {} | 321 std::unique_ptr<AnimationEvents> queue) {} |
| 321 | 322 |
| 322 void RemoteChannelImpl::DidLoseOutputSurface() { | 323 void RemoteChannelImpl::DidLoseCompositorFrameSink() { |
| 323 DCHECK(task_runner_provider_->IsImplThread()); | |
| 324 | |
| 325 MainThreadTaskRunner()->PostTask( | |
| 326 FROM_HERE, base::Bind(&RemoteChannelImpl::DidLoseOutputSurfaceOnMain, | |
| 327 impl().remote_channel_weak_ptr)); | |
| 328 } | |
| 329 | |
| 330 void RemoteChannelImpl::RequestNewOutputSurface() { | |
| 331 DCHECK(task_runner_provider_->IsImplThread()); | |
| 332 | |
| 333 MainThreadTaskRunner()->PostTask( | |
| 334 FROM_HERE, base::Bind(&RemoteChannelImpl::RequestNewOutputSurfaceOnMain, | |
| 335 impl().remote_channel_weak_ptr)); | |
| 336 } | |
| 337 | |
| 338 void RemoteChannelImpl::DidInitializeOutputSurface(bool success) { | |
| 339 DCHECK(task_runner_provider_->IsImplThread()); | 324 DCHECK(task_runner_provider_->IsImplThread()); |
| 340 | 325 |
| 341 MainThreadTaskRunner()->PostTask( | 326 MainThreadTaskRunner()->PostTask( |
| 342 FROM_HERE, | 327 FROM_HERE, |
| 343 base::Bind(&RemoteChannelImpl::DidInitializeOutputSurfaceOnMain, | 328 base::Bind(&RemoteChannelImpl::DidLoseCompositorFrameSinkOnMain, |
| 329 impl().remote_channel_weak_ptr)); |
| 330 } |
| 331 |
| 332 void RemoteChannelImpl::RequestNewCompositorFrameSink() { |
| 333 DCHECK(task_runner_provider_->IsImplThread()); |
| 334 |
| 335 MainThreadTaskRunner()->PostTask( |
| 336 FROM_HERE, |
| 337 base::Bind(&RemoteChannelImpl::RequestNewCompositorFrameSinkOnMain, |
| 338 impl().remote_channel_weak_ptr)); |
| 339 } |
| 340 |
| 341 void RemoteChannelImpl::DidInitializeCompositorFrameSink(bool success) { |
| 342 DCHECK(task_runner_provider_->IsImplThread()); |
| 343 |
| 344 MainThreadTaskRunner()->PostTask( |
| 345 FROM_HERE, |
| 346 base::Bind(&RemoteChannelImpl::DidInitializeCompositorFrameSinkOnMain, |
| 344 impl().remote_channel_weak_ptr, success)); | 347 impl().remote_channel_weak_ptr, success)); |
| 345 } | 348 } |
| 346 | 349 |
| 347 void RemoteChannelImpl::DidCompletePageScaleAnimation() {} | 350 void RemoteChannelImpl::DidCompletePageScaleAnimation() {} |
| 348 | 351 |
| 349 void RemoteChannelImpl::BeginMainFrame( | 352 void RemoteChannelImpl::BeginMainFrame( |
| 350 std::unique_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) { | 353 std::unique_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) { |
| 351 std::unique_ptr<proto::CompositorMessage> proto; | 354 std::unique_ptr<proto::CompositorMessage> proto; |
| 352 proto.reset(new proto::CompositorMessage); | 355 proto.reset(new proto::CompositorMessage); |
| 353 proto::CompositorMessageToMain* to_main_proto = proto->mutable_to_main(); | 356 proto::CompositorMessageToMain* to_main_proto = proto->mutable_to_main(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 375 void RemoteChannelImpl::DidCompleteSwapBuffersOnMain() { | 378 void RemoteChannelImpl::DidCompleteSwapBuffersOnMain() { |
| 376 DCHECK(task_runner_provider_->IsMainThread()); | 379 DCHECK(task_runner_provider_->IsMainThread()); |
| 377 main().layer_tree_host->DidCompleteSwapBuffers(); | 380 main().layer_tree_host->DidCompleteSwapBuffers(); |
| 378 } | 381 } |
| 379 | 382 |
| 380 void RemoteChannelImpl::DidCommitAndDrawFrameOnMain() { | 383 void RemoteChannelImpl::DidCommitAndDrawFrameOnMain() { |
| 381 DCHECK(task_runner_provider_->IsMainThread()); | 384 DCHECK(task_runner_provider_->IsMainThread()); |
| 382 main().layer_tree_host->DidCommitAndDrawFrame(); | 385 main().layer_tree_host->DidCommitAndDrawFrame(); |
| 383 } | 386 } |
| 384 | 387 |
| 385 void RemoteChannelImpl::DidLoseOutputSurfaceOnMain() { | 388 void RemoteChannelImpl::DidLoseCompositorFrameSinkOnMain() { |
| 386 DCHECK(task_runner_provider_->IsMainThread()); | 389 DCHECK(task_runner_provider_->IsMainThread()); |
| 387 | 390 |
| 388 main().layer_tree_host->DidLoseOutputSurface(); | 391 main().layer_tree_host->DidLoseCompositorFrameSink(); |
| 389 } | 392 } |
| 390 | 393 |
| 391 void RemoteChannelImpl::RequestNewOutputSurfaceOnMain() { | 394 void RemoteChannelImpl::RequestNewCompositorFrameSinkOnMain() { |
| 392 DCHECK(task_runner_provider_->IsMainThread()); | 395 DCHECK(task_runner_provider_->IsMainThread()); |
| 393 | 396 |
| 394 main().layer_tree_host->RequestNewOutputSurface(); | 397 main().layer_tree_host->RequestNewCompositorFrameSink(); |
| 395 } | 398 } |
| 396 | 399 |
| 397 void RemoteChannelImpl::DidInitializeOutputSurfaceOnMain(bool success) { | 400 void RemoteChannelImpl::DidInitializeCompositorFrameSinkOnMain(bool success) { |
| 398 DCHECK(task_runner_provider_->IsMainThread()); | 401 DCHECK(task_runner_provider_->IsMainThread()); |
| 399 | 402 |
| 400 if (!success) { | 403 if (!success) { |
| 401 main().layer_tree_host->DidFailToInitializeOutputSurface(); | 404 main().layer_tree_host->DidFailToInitializeCompositorFrameSink(); |
| 402 return; | 405 return; |
| 403 } | 406 } |
| 404 | 407 |
| 405 VLOG(1) << "OutputSurface initialized successfully"; | 408 VLOG(1) << "CompositorFrameSink initialized successfully"; |
| 406 main().layer_tree_host->DidInitializeOutputSurface(); | 409 main().layer_tree_host->DidInitializeCompositorFrameSink(); |
| 407 | 410 |
| 408 // If we were waiting for output surface initialization, we might have queued | 411 // If we were waiting for CompositorFrameSink initialization, we might have |
| 409 // some messages. Relay them now that a new output surface has been | 412 // queued some messages. Relay them now that a new CompositorFrameSink has |
| 410 // initialized. | 413 // been initialized. |
| 411 main().waiting_for_output_surface_initialization = false; | 414 main().waiting_for_compositor_frame_sink_initialization = false; |
| 412 while (!main().pending_messages.empty()) { | 415 while (!main().pending_messages.empty()) { |
| 413 VLOG(1) << "Handling queued message"; | 416 VLOG(1) << "Handling queued message"; |
| 414 HandleProto(main().pending_messages.front()); | 417 HandleProto(main().pending_messages.front()); |
| 415 main().pending_messages.pop(); | 418 main().pending_messages.pop(); |
| 416 } | 419 } |
| 417 | 420 |
| 418 // The commit after a new output surface can early out, in which case we will | 421 // The commit after a new CompositorFrameSink can early out, in which case we |
| 419 // never redraw. Schedule one just to be safe. | 422 // will never redraw. Schedule one just to be safe. |
| 420 PostSetNeedsRedrawToImpl(gfx::Rect( | 423 PostSetNeedsRedrawToImpl(gfx::Rect( |
| 421 main().layer_tree_host->GetLayerTree()->device_viewport_size())); | 424 main().layer_tree_host->GetLayerTree()->device_viewport_size())); |
| 422 } | 425 } |
| 423 | 426 |
| 424 void RemoteChannelImpl::SendMessageProtoOnMain( | 427 void RemoteChannelImpl::SendMessageProtoOnMain( |
| 425 std::unique_ptr<proto::CompositorMessage> proto) { | 428 std::unique_ptr<proto::CompositorMessage> proto) { |
| 426 DCHECK(task_runner_provider_->IsMainThread()); | 429 DCHECK(task_runner_provider_->IsMainThread()); |
| 427 VLOG(1) << "Sending BeginMainFrame request to the engine."; | 430 VLOG(1) << "Sending BeginMainFrame request to the engine."; |
| 428 | 431 |
| 429 main().remote_proto_channel->SendCompositorProto(*proto); | 432 main().remote_proto_channel->SendCompositorProto(*proto); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 return task_runner_provider_->ImplThreadTaskRunner(); | 496 return task_runner_provider_->ImplThreadTaskRunner(); |
| 494 } | 497 } |
| 495 | 498 |
| 496 RemoteChannelImpl::MainThreadOnly::MainThreadOnly( | 499 RemoteChannelImpl::MainThreadOnly::MainThreadOnly( |
| 497 RemoteChannelImpl* remote_channel_impl, | 500 RemoteChannelImpl* remote_channel_impl, |
| 498 LayerTreeHost* layer_tree_host, | 501 LayerTreeHost* layer_tree_host, |
| 499 RemoteProtoChannel* remote_proto_channel) | 502 RemoteProtoChannel* remote_proto_channel) |
| 500 : layer_tree_host(layer_tree_host), | 503 : layer_tree_host(layer_tree_host), |
| 501 remote_proto_channel(remote_proto_channel), | 504 remote_proto_channel(remote_proto_channel), |
| 502 started(false), | 505 started(false), |
| 503 waiting_for_output_surface_initialization(false), | 506 waiting_for_compositor_frame_sink_initialization(false), |
| 504 remote_channel_weak_factory(remote_channel_impl) { | 507 remote_channel_weak_factory(remote_channel_impl) { |
| 505 DCHECK(layer_tree_host); | 508 DCHECK(layer_tree_host); |
| 506 DCHECK(remote_proto_channel); | 509 DCHECK(remote_proto_channel); |
| 507 } | 510 } |
| 508 | 511 |
| 509 RemoteChannelImpl::MainThreadOnly::~MainThreadOnly() {} | 512 RemoteChannelImpl::MainThreadOnly::~MainThreadOnly() {} |
| 510 | 513 |
| 511 RemoteChannelImpl::CompositorThreadOnly::CompositorThreadOnly( | 514 RemoteChannelImpl::CompositorThreadOnly::CompositorThreadOnly( |
| 512 base::WeakPtr<RemoteChannelImpl> remote_channel_weak_ptr) | 515 base::WeakPtr<RemoteChannelImpl> remote_channel_weak_ptr) |
| 513 : proxy_impl(nullptr), | 516 : proxy_impl(nullptr), |
| 514 proxy_impl_weak_factory(nullptr), | 517 proxy_impl_weak_factory(nullptr), |
| 515 remote_channel_weak_ptr(remote_channel_weak_ptr) {} | 518 remote_channel_weak_ptr(remote_channel_weak_ptr) {} |
| 516 | 519 |
| 517 RemoteChannelImpl::CompositorThreadOnly::~CompositorThreadOnly() {} | 520 RemoteChannelImpl::CompositorThreadOnly::~CompositorThreadOnly() {} |
| 518 | 521 |
| 519 } // namespace cc | 522 } // namespace cc |
| OLD | NEW |