| 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/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
| 9 #include "cc/animation/animation_events.h" | 9 #include "cc/animation/animation_events.h" |
| 10 #include "cc/proto/compositor_message.pb.h" | 10 #include "cc/proto/compositor_message.pb.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 56 |
| 57 void RemoteChannelImpl::OnProtoReceived( | 57 void RemoteChannelImpl::OnProtoReceived( |
| 58 scoped_ptr<proto::CompositorMessage> proto) { | 58 scoped_ptr<proto::CompositorMessage> proto) { |
| 59 DCHECK(task_runner_provider_->IsMainThread()); | 59 DCHECK(task_runner_provider_->IsMainThread()); |
| 60 DCHECK(main().started); | 60 DCHECK(main().started); |
| 61 DCHECK(proto->has_to_impl()); | 61 DCHECK(proto->has_to_impl()); |
| 62 | 62 |
| 63 // If we don't have an output surface, queue the message and defer processing | 63 // If we don't have an output surface, queue the message and defer processing |
| 64 // it till we initialize a new output surface. | 64 // it till we initialize a new output surface. |
| 65 if (main().waiting_for_output_surface_initialization) { | 65 if (main().waiting_for_output_surface_initialization) { |
| 66 VLOG(1) << "Queueing message proto since output surface was released."; |
| 66 main().pending_messages.push(proto->to_impl()); | 67 main().pending_messages.push(proto->to_impl()); |
| 67 } else { | 68 } else { |
| 68 HandleProto(proto->to_impl()); | 69 HandleProto(proto->to_impl()); |
| 69 } | 70 } |
| 70 } | 71 } |
| 71 | 72 |
| 72 void RemoteChannelImpl::HandleProto( | 73 void RemoteChannelImpl::HandleProto( |
| 73 const proto::CompositorMessageToImpl& proto) { | 74 const proto::CompositorMessageToImpl& proto) { |
| 74 DCHECK(task_runner_provider_->IsMainThread()); | 75 DCHECK(task_runner_provider_->IsMainThread()); |
| 75 DCHECK(proto.has_message_type()); | 76 DCHECK(proto.has_message_type()); |
| 76 DCHECK(!main().waiting_for_output_surface_initialization); | 77 DCHECK(!main().waiting_for_output_surface_initialization); |
| 77 | 78 |
| 78 switch (proto.message_type()) { | 79 switch (proto.message_type()) { |
| 79 case proto::CompositorMessageToImpl::UNKNOWN: | 80 case proto::CompositorMessageToImpl::UNKNOWN: |
| 80 NOTIMPLEMENTED() << "Ignoring message of UNKNOWN type"; | 81 NOTIMPLEMENTED() << "Ignoring message of UNKNOWN type"; |
| 81 break; | 82 break; |
| 82 case proto::CompositorMessageToImpl::INITIALIZE_IMPL: | 83 case proto::CompositorMessageToImpl::INITIALIZE_IMPL: |
| 83 NOTREACHED() << "Should be handled by the embedder"; | 84 NOTREACHED() << "Should be handled by the embedder"; |
| 84 break; | 85 break; |
| 85 case proto::CompositorMessageToImpl::CLOSE_IMPL: | 86 case proto::CompositorMessageToImpl::CLOSE_IMPL: |
| 86 NOTREACHED() << "Should be handled by the embedder"; | 87 NOTREACHED() << "Should be handled by the embedder"; |
| 87 break; | 88 break; |
| 88 case proto::CompositorMessageToImpl:: | 89 case proto::CompositorMessageToImpl:: |
| 89 MAIN_THREAD_HAS_STOPPED_FLINGING_ON_IMPL: | 90 MAIN_THREAD_HAS_STOPPED_FLINGING_ON_IMPL: |
| 90 ImplThreadTaskRunner()->PostTask( | 91 ImplThreadTaskRunner()->PostTask( |
| 91 FROM_HERE, base::Bind(&ProxyImpl::MainThreadHasStoppedFlingingOnImpl, | 92 FROM_HERE, base::Bind(&ProxyImpl::MainThreadHasStoppedFlingingOnImpl, |
| 92 proxy_impl_weak_ptr_)); | 93 proxy_impl_weak_ptr_)); |
| 93 break; | 94 break; |
| 94 case proto::CompositorMessageToImpl::SET_NEEDS_COMMIT: | 95 case proto::CompositorMessageToImpl::SET_NEEDS_COMMIT: |
| 96 VLOG(1) << "Received commit request from the engine."; |
| 95 ImplThreadTaskRunner()->PostTask( | 97 ImplThreadTaskRunner()->PostTask( |
| 96 FROM_HERE, | 98 FROM_HERE, |
| 97 base::Bind(&ProxyImpl::SetNeedsCommitOnImpl, proxy_impl_weak_ptr_)); | 99 base::Bind(&ProxyImpl::SetNeedsCommitOnImpl, proxy_impl_weak_ptr_)); |
| 98 break; | 100 break; |
| 99 case proto::CompositorMessageToImpl::SET_DEFER_COMMITS: { | 101 case proto::CompositorMessageToImpl::SET_DEFER_COMMITS: { |
| 100 const proto::SetDeferCommits& defer_commits_message = | 102 const proto::SetDeferCommits& defer_commits_message = |
| 101 proto.defer_commits_message(); | 103 proto.defer_commits_message(); |
| 102 bool defer_commits = defer_commits_message.defer_commits(); | 104 bool defer_commits = defer_commits_message.defer_commits(); |
| 105 VLOG(1) << "Received set defer commits to: " << defer_commits |
| 106 << " from the engine."; |
| 103 ImplThreadTaskRunner()->PostTask( | 107 ImplThreadTaskRunner()->PostTask( |
| 104 FROM_HERE, base::Bind(&ProxyImpl::SetDeferCommitsOnImpl, | 108 FROM_HERE, base::Bind(&ProxyImpl::SetDeferCommitsOnImpl, |
| 105 proxy_impl_weak_ptr_, defer_commits)); | 109 proxy_impl_weak_ptr_, defer_commits)); |
| 106 } break; | 110 } break; |
| 107 case proto::CompositorMessageToImpl::START_COMMIT: { | 111 case proto::CompositorMessageToImpl::START_COMMIT: { |
| 112 VLOG(1) << "Received commit proto from the engine."; |
| 108 base::TimeTicks main_thread_start_time = base::TimeTicks::Now(); | 113 base::TimeTicks main_thread_start_time = base::TimeTicks::Now(); |
| 109 const proto::StartCommit& start_commit_message = | 114 const proto::StartCommit& start_commit_message = |
| 110 proto.start_commit_message(); | 115 proto.start_commit_message(); |
| 111 | 116 |
| 112 main().layer_tree_host->FromProtobufForCommit( | 117 main().layer_tree_host->FromProtobufForCommit( |
| 113 start_commit_message.layer_tree_host()); | 118 start_commit_message.layer_tree_host()); |
| 114 { | 119 { |
| 115 DebugScopedSetMainThreadBlocked main_thread_blocked( | 120 DebugScopedSetMainThreadBlocked main_thread_blocked( |
| 116 task_runner_provider_); | 121 task_runner_provider_); |
| 117 CompletionEvent completion; | 122 CompletionEvent completion; |
| 123 VLOG(1) << "Starting commit."; |
| 118 ImplThreadTaskRunner()->PostTask( | 124 ImplThreadTaskRunner()->PostTask( |
| 119 FROM_HERE, | 125 FROM_HERE, |
| 120 base::Bind(&ProxyImpl::StartCommitOnImpl, proxy_impl_weak_ptr_, | 126 base::Bind(&ProxyImpl::StartCommitOnImpl, proxy_impl_weak_ptr_, |
| 121 &completion, main().layer_tree_host, | 127 &completion, main().layer_tree_host, |
| 122 main_thread_start_time, false)); | 128 main_thread_start_time, false)); |
| 123 completion.Wait(); | 129 completion.Wait(); |
| 124 } | 130 } |
| 125 } break; | 131 } break; |
| 126 case proto::CompositorMessageToImpl::BEGIN_MAIN_FRAME_ABORTED: { | 132 case proto::CompositorMessageToImpl::BEGIN_MAIN_FRAME_ABORTED: { |
| 127 base::TimeTicks main_thread_start_time = base::TimeTicks::Now(); | 133 base::TimeTicks main_thread_start_time = base::TimeTicks::Now(); |
| 128 const proto::BeginMainFrameAborted& begin_main_frame_aborted_message = | 134 const proto::BeginMainFrameAborted& begin_main_frame_aborted_message = |
| 129 proto.begin_main_frame_aborted_message(); | 135 proto.begin_main_frame_aborted_message(); |
| 130 CommitEarlyOutReason reason = CommitEarlyOutReasonFromProtobuf( | 136 CommitEarlyOutReason reason = CommitEarlyOutReasonFromProtobuf( |
| 131 begin_main_frame_aborted_message.reason()); | 137 begin_main_frame_aborted_message.reason()); |
| 138 VLOG(1) << "Received BeginMainFrameAborted from the engine with reason: " |
| 139 << CommitEarlyOutReasonToString(reason); |
| 132 ImplThreadTaskRunner()->PostTask( | 140 ImplThreadTaskRunner()->PostTask( |
| 133 FROM_HERE, | 141 FROM_HERE, |
| 134 base::Bind(&ProxyImpl::BeginMainFrameAbortedOnImpl, | 142 base::Bind(&ProxyImpl::BeginMainFrameAbortedOnImpl, |
| 135 proxy_impl_weak_ptr_, reason, main_thread_start_time)); | 143 proxy_impl_weak_ptr_, reason, main_thread_start_time)); |
| 136 } break; | 144 } break; |
| 137 case proto::CompositorMessageToImpl::SET_NEEDS_REDRAW: { | 145 case proto::CompositorMessageToImpl::SET_NEEDS_REDRAW: { |
| 146 VLOG(1) << "Received redraw request from the engine."; |
| 138 const proto::SetNeedsRedraw& set_needs_redraw_message = | 147 const proto::SetNeedsRedraw& set_needs_redraw_message = |
| 139 proto.set_needs_redraw_message(); | 148 proto.set_needs_redraw_message(); |
| 140 gfx::Rect damaged_rect = | 149 gfx::Rect damaged_rect = |
| 141 ProtoToRect(set_needs_redraw_message.damaged_rect()); | 150 ProtoToRect(set_needs_redraw_message.damaged_rect()); |
| 142 PostSetNeedsRedrawToImpl(damaged_rect); | 151 PostSetNeedsRedrawToImpl(damaged_rect); |
| 143 } break; | 152 } break; |
| 144 } | 153 } |
| 145 } | 154 } |
| 146 | 155 |
| 147 void RemoteChannelImpl::FinishAllRendering() { | 156 void RemoteChannelImpl::FinishAllRendering() { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 161 DCHECK(task_runner_provider_->IsMainThread()); | 170 DCHECK(task_runner_provider_->IsMainThread()); |
| 162 | 171 |
| 163 ImplThreadTaskRunner()->PostTask( | 172 ImplThreadTaskRunner()->PostTask( |
| 164 FROM_HERE, base::Bind(&ProxyImpl::InitializeOutputSurfaceOnImpl, | 173 FROM_HERE, base::Bind(&ProxyImpl::InitializeOutputSurfaceOnImpl, |
| 165 proxy_impl_weak_ptr_, output_surface)); | 174 proxy_impl_weak_ptr_, output_surface)); |
| 166 } | 175 } |
| 167 | 176 |
| 168 void RemoteChannelImpl::ReleaseOutputSurface() { | 177 void RemoteChannelImpl::ReleaseOutputSurface() { |
| 169 DCHECK(task_runner_provider_->IsMainThread()); | 178 DCHECK(task_runner_provider_->IsMainThread()); |
| 170 DCHECK(!main().waiting_for_output_surface_initialization); | 179 DCHECK(!main().waiting_for_output_surface_initialization); |
| 180 VLOG(1) << "Releasing Output Surface"; |
| 171 | 181 |
| 172 { | 182 { |
| 173 CompletionEvent completion; | 183 CompletionEvent completion; |
| 174 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); | 184 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); |
| 175 ImplThreadTaskRunner()->PostTask( | 185 ImplThreadTaskRunner()->PostTask( |
| 176 FROM_HERE, base::Bind(&ProxyImpl::ReleaseOutputSurfaceOnImpl, | 186 FROM_HERE, base::Bind(&ProxyImpl::ReleaseOutputSurfaceOnImpl, |
| 177 proxy_impl_weak_ptr_, &completion)); | 187 proxy_impl_weak_ptr_, &completion)); |
| 178 completion.Wait(); | 188 completion.Wait(); |
| 179 } | 189 } |
| 180 | 190 |
| 181 main().waiting_for_output_surface_initialization = true; | 191 main().waiting_for_output_surface_initialization = true; |
| 182 } | 192 } |
| 183 | 193 |
| 184 void RemoteChannelImpl::SetVisible(bool visible) { | 194 void RemoteChannelImpl::SetVisible(bool visible) { |
| 185 DCHECK(task_runner_provider_->IsMainThread()); | 195 DCHECK(task_runner_provider_->IsMainThread()); |
| 196 VLOG(1) << "Setting visibility to: " << visible; |
| 186 | 197 |
| 187 ImplThreadTaskRunner()->PostTask( | 198 ImplThreadTaskRunner()->PostTask( |
| 188 FROM_HERE, | 199 FROM_HERE, |
| 189 base::Bind(&ProxyImpl::SetVisibleOnImpl, proxy_impl_weak_ptr_, visible)); | 200 base::Bind(&ProxyImpl::SetVisibleOnImpl, proxy_impl_weak_ptr_, visible)); |
| 190 } | 201 } |
| 191 | 202 |
| 192 const RendererCapabilities& RemoteChannelImpl::GetRendererCapabilities() const { | 203 const RendererCapabilities& RemoteChannelImpl::GetRendererCapabilities() const { |
| 193 NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; | 204 NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; |
| 194 return main().renderer_capabilities; | 205 return main().renderer_capabilities; |
| 195 } | 206 } |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 void RemoteChannelImpl::DidInitializeOutputSurfaceOnMain( | 419 void RemoteChannelImpl::DidInitializeOutputSurfaceOnMain( |
| 409 bool success, | 420 bool success, |
| 410 const RendererCapabilities& capabilities) { | 421 const RendererCapabilities& capabilities) { |
| 411 DCHECK(task_runner_provider_->IsMainThread()); | 422 DCHECK(task_runner_provider_->IsMainThread()); |
| 412 | 423 |
| 413 if (!success) { | 424 if (!success) { |
| 414 main().layer_tree_host->DidFailToInitializeOutputSurface(); | 425 main().layer_tree_host->DidFailToInitializeOutputSurface(); |
| 415 return; | 426 return; |
| 416 } | 427 } |
| 417 | 428 |
| 429 VLOG(1) << "OutputSurface initialized successfully"; |
| 418 main().renderer_capabilities = capabilities; | 430 main().renderer_capabilities = capabilities; |
| 419 main().layer_tree_host->DidInitializeOutputSurface(); | 431 main().layer_tree_host->DidInitializeOutputSurface(); |
| 420 | 432 |
| 421 // If we were waiting for output surface initialization, we might have queued | 433 // If we were waiting for output surface initialization, we might have queued |
| 422 // some messages. Relay them now that a new output surface has been | 434 // some messages. Relay them now that a new output surface has been |
| 423 // initialized. | 435 // initialized. |
| 424 main().waiting_for_output_surface_initialization = false; | 436 main().waiting_for_output_surface_initialization = false; |
| 425 while (!main().pending_messages.empty()) { | 437 while (!main().pending_messages.empty()) { |
| 438 VLOG(1) << "Handling queued message"; |
| 426 HandleProto(main().pending_messages.front()); | 439 HandleProto(main().pending_messages.front()); |
| 427 main().pending_messages.pop(); | 440 main().pending_messages.pop(); |
| 428 } | 441 } |
| 429 | 442 |
| 430 // The commit after a new output surface can early out, in which case we will | 443 // The commit after a new output surface can early out, in which case we will |
| 431 // never redraw. Schedule one just to be safe. | 444 // never redraw. Schedule one just to be safe. |
| 432 PostSetNeedsRedrawToImpl( | 445 PostSetNeedsRedrawToImpl( |
| 433 gfx::Rect(main().layer_tree_host->device_viewport_size())); | 446 gfx::Rect(main().layer_tree_host->device_viewport_size())); |
| 434 } | 447 } |
| 435 | 448 |
| 436 void RemoteChannelImpl::SendMessageProtoOnMain( | 449 void RemoteChannelImpl::SendMessageProtoOnMain( |
| 437 scoped_ptr<proto::CompositorMessage> proto) { | 450 scoped_ptr<proto::CompositorMessage> proto) { |
| 438 DCHECK(task_runner_provider_->IsMainThread()); | 451 DCHECK(task_runner_provider_->IsMainThread()); |
| 452 VLOG(1) << "Sending BeginMainFrame request to the engine."; |
| 439 | 453 |
| 440 main().remote_proto_channel->SendCompositorProto(*proto); | 454 main().remote_proto_channel->SendCompositorProto(*proto); |
| 441 } | 455 } |
| 442 | 456 |
| 443 void RemoteChannelImpl::PostSetNeedsRedrawToImpl( | 457 void RemoteChannelImpl::PostSetNeedsRedrawToImpl( |
| 444 const gfx::Rect& damaged_rect) { | 458 const gfx::Rect& damaged_rect) { |
| 445 DCHECK(task_runner_provider_->IsMainThread()); | 459 DCHECK(task_runner_provider_->IsMainThread()); |
| 446 | 460 |
| 447 ImplThreadTaskRunner()->PostTask( | 461 ImplThreadTaskRunner()->PostTask( |
| 448 FROM_HERE, base::Bind(&ProxyImpl::SetNeedsRedrawOnImpl, | 462 FROM_HERE, base::Bind(&ProxyImpl::SetNeedsRedrawOnImpl, |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 | 534 |
| 521 RemoteChannelImpl::CompositorThreadOnly::CompositorThreadOnly( | 535 RemoteChannelImpl::CompositorThreadOnly::CompositorThreadOnly( |
| 522 base::WeakPtr<RemoteChannelImpl> remote_channel_weak_ptr) | 536 base::WeakPtr<RemoteChannelImpl> remote_channel_weak_ptr) |
| 523 : proxy_impl(nullptr), | 537 : proxy_impl(nullptr), |
| 524 proxy_impl_weak_factory(nullptr), | 538 proxy_impl_weak_factory(nullptr), |
| 525 remote_channel_weak_ptr(remote_channel_weak_ptr) {} | 539 remote_channel_weak_ptr(remote_channel_weak_ptr) {} |
| 526 | 540 |
| 527 RemoteChannelImpl::CompositorThreadOnly::~CompositorThreadOnly() {} | 541 RemoteChannelImpl::CompositorThreadOnly::~CompositorThreadOnly() {} |
| 528 | 542 |
| 529 } // namespace cc | 543 } // namespace cc |
| OLD | NEW |