OLD | NEW |
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 #include "cc/trees/proxy_impl.h" | 5 #include "cc/trees/proxy_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 new ProxyImpl(channel_impl, layer_tree_host, task_runner_provider, | 44 new ProxyImpl(channel_impl, layer_tree_host, task_runner_provider, |
45 std::move(external_begin_frame_source))); | 45 std::move(external_begin_frame_source))); |
46 } | 46 } |
47 | 47 |
48 ProxyImpl::ProxyImpl( | 48 ProxyImpl::ProxyImpl( |
49 ChannelImpl* channel_impl, | 49 ChannelImpl* channel_impl, |
50 LayerTreeHost* layer_tree_host, | 50 LayerTreeHost* layer_tree_host, |
51 TaskRunnerProvider* task_runner_provider, | 51 TaskRunnerProvider* task_runner_provider, |
52 std::unique_ptr<BeginFrameSource> external_begin_frame_source) | 52 std::unique_ptr<BeginFrameSource> external_begin_frame_source) |
53 : layer_tree_host_id_(layer_tree_host->id()), | 53 : layer_tree_host_id_(layer_tree_host->id()), |
54 next_commit_waits_for_activation_(false), | 54 commit_completion_waits_for_activation_(false), |
55 commit_completion_event_(nullptr), | 55 commit_completion_event_(nullptr), |
| 56 activation_completion_event_(nullptr), |
56 next_frame_is_newly_committed_frame_(false), | 57 next_frame_is_newly_committed_frame_(false), |
57 inside_draw_(false), | 58 inside_draw_(false), |
58 input_throttled_until_commit_(false), | 59 input_throttled_until_commit_(false), |
59 task_runner_provider_(task_runner_provider), | 60 task_runner_provider_(task_runner_provider), |
60 smoothness_priority_expiration_notifier_( | 61 smoothness_priority_expiration_notifier_( |
61 task_runner_provider->ImplThreadTaskRunner(), | 62 task_runner_provider->ImplThreadTaskRunner(), |
62 base::Bind(&ProxyImpl::RenewTreePriority, base::Unretained(this)), | 63 base::Bind(&ProxyImpl::RenewTreePriority, base::Unretained(this)), |
63 base::TimeDelta::FromSecondsD( | 64 base::TimeDelta::FromSecondsD( |
64 kSmoothnessTakesPriorityExpirationDelay)), | 65 kSmoothnessTakesPriorityExpirationDelay)), |
65 external_begin_frame_source_(std::move(external_begin_frame_source)), | 66 external_begin_frame_source_(std::move(external_begin_frame_source)), |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 bool* main_frame_will_happen) { | 235 bool* main_frame_will_happen) { |
235 DCHECK(IsImplThread()); | 236 DCHECK(IsImplThread()); |
236 if (layer_tree_host_impl_->output_surface()) { | 237 if (layer_tree_host_impl_->output_surface()) { |
237 *main_frame_will_happen = scheduler_->MainFrameForTestingWillHappen(); | 238 *main_frame_will_happen = scheduler_->MainFrameForTestingWillHappen(); |
238 } else { | 239 } else { |
239 *main_frame_will_happen = false; | 240 *main_frame_will_happen = false; |
240 } | 241 } |
241 completion->Signal(); | 242 completion->Signal(); |
242 } | 243 } |
243 | 244 |
| 245 void ProxyImpl::BlockNotifyReadyToActivateForTesting(bool block) { |
| 246 DCHECK(IsImplThread()); |
| 247 layer_tree_host_impl_->BlockNotifyReadyToActivateForTesting(block); |
| 248 } |
| 249 |
| 250 CompletionEvent* ProxyImpl::ActivationCompletionEventForTesting() { |
| 251 DCHECK(IsImplThread()); |
| 252 return activation_completion_event_; |
| 253 } |
| 254 |
244 void ProxyImpl::StartCommitOnImpl(CompletionEvent* completion, | 255 void ProxyImpl::StartCommitOnImpl(CompletionEvent* completion, |
245 LayerTreeHost* layer_tree_host, | 256 LayerTreeHost* layer_tree_host, |
246 base::TimeTicks main_thread_start_time, | 257 base::TimeTicks main_thread_start_time, |
247 bool hold_commit_for_activation) { | 258 bool hold_commit_for_activation) { |
248 TRACE_EVENT0("cc", "ProxyImpl::StartCommitOnImplThread"); | 259 TRACE_EVENT0("cc", "ProxyImpl::StartCommitOnImplThread"); |
249 DCHECK(!commit_completion_event_); | 260 DCHECK(!commit_completion_event_); |
250 DCHECK(IsImplThread() && IsMainThreadBlocked()); | 261 DCHECK(IsImplThread() && IsMainThreadBlocked()); |
251 DCHECK(scheduler_); | 262 DCHECK(scheduler_); |
252 DCHECK(scheduler_->CommitPending()); | 263 DCHECK(scheduler_->CommitPending()); |
253 | 264 |
254 if (hold_commit_for_activation) { | |
255 // This commit may be aborted. Store the value for | |
256 // hold_commit_for_activation so that whenever the next commit is started, | |
257 // the main thread will be unblocked only after pending tree activation. | |
258 next_commit_waits_for_activation_ = hold_commit_for_activation; | |
259 } | |
260 | |
261 if (!layer_tree_host_impl_) { | 265 if (!layer_tree_host_impl_) { |
262 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NoLayerTree", | 266 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NoLayerTree", |
263 TRACE_EVENT_SCOPE_THREAD); | 267 TRACE_EVENT_SCOPE_THREAD); |
264 completion->Signal(); | 268 completion->Signal(); |
265 return; | 269 return; |
266 } | 270 } |
267 | 271 |
268 // Ideally, we should inform to impl thread when BeginMainFrame is started. | 272 // Ideally, we should inform to impl thread when BeginMainFrame is started. |
269 // But, we can avoid a PostTask in here. | 273 // But, we can avoid a PostTask in here. |
270 scheduler_->NotifyBeginMainFrameStarted(main_thread_start_time); | 274 scheduler_->NotifyBeginMainFrameStarted(main_thread_start_time); |
| 275 |
271 commit_completion_event_ = completion; | 276 commit_completion_event_ = completion; |
| 277 commit_completion_waits_for_activation_ = hold_commit_for_activation; |
| 278 |
272 DCHECK(!blocked_main_commit().layer_tree_host); | 279 DCHECK(!blocked_main_commit().layer_tree_host); |
273 blocked_main_commit().layer_tree_host = layer_tree_host; | 280 blocked_main_commit().layer_tree_host = layer_tree_host; |
274 scheduler_->NotifyReadyToCommit(); | 281 scheduler_->NotifyReadyToCommit(); |
275 } | 282 } |
276 | 283 |
277 void ProxyImpl::UpdateRendererCapabilitiesOnImplThread() { | 284 void ProxyImpl::UpdateRendererCapabilitiesOnImplThread() { |
278 DCHECK(IsImplThread()); | 285 DCHECK(IsImplThread()); |
279 channel_impl_->SetRendererCapabilitiesMainCopy( | 286 channel_impl_->SetRendererCapabilitiesMainCopy( |
280 layer_tree_host_impl_->GetRendererCapabilities() | 287 layer_tree_host_impl_->GetRendererCapabilities() |
281 .MainThreadCapabilities()); | 288 .MainThreadCapabilities()); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 base::TimeDelta delay) { | 446 base::TimeDelta delay) { |
440 DCHECK(IsImplThread()); | 447 DCHECK(IsImplThread()); |
441 task_runner_provider_->ImplThreadTaskRunner()->PostDelayedTask(FROM_HERE, | 448 task_runner_provider_->ImplThreadTaskRunner()->PostDelayedTask(FROM_HERE, |
442 task, delay); | 449 task, delay); |
443 } | 450 } |
444 | 451 |
445 void ProxyImpl::DidActivateSyncTree() { | 452 void ProxyImpl::DidActivateSyncTree() { |
446 TRACE_EVENT0("cc", "ProxyImpl::DidActivateSyncTreeOnImplThread"); | 453 TRACE_EVENT0("cc", "ProxyImpl::DidActivateSyncTreeOnImplThread"); |
447 DCHECK(IsImplThread()); | 454 DCHECK(IsImplThread()); |
448 | 455 |
449 if (next_commit_waits_for_activation_) { | 456 if (activation_completion_event_) { |
450 TRACE_EVENT_INSTANT0("cc", "ReleaseCommitbyActivation", | 457 TRACE_EVENT_INSTANT0("cc", "ReleaseCommitbyActivation", |
451 TRACE_EVENT_SCOPE_THREAD); | 458 TRACE_EVENT_SCOPE_THREAD); |
452 DCHECK(commit_completion_event_); | 459 activation_completion_event_->Signal(); |
453 commit_completion_event_->Signal(); | 460 activation_completion_event_ = nullptr; |
454 commit_completion_event_ = nullptr; | |
455 next_commit_waits_for_activation_ = false; | |
456 } | 461 } |
457 } | 462 } |
458 | 463 |
459 void ProxyImpl::WillPrepareTiles() { | 464 void ProxyImpl::WillPrepareTiles() { |
460 DCHECK(IsImplThread()); | 465 DCHECK(IsImplThread()); |
461 scheduler_->WillPrepareTiles(); | 466 scheduler_->WillPrepareTiles(); |
462 } | 467 } |
463 | 468 |
464 void ProxyImpl::DidPrepareTiles() { | 469 void ProxyImpl::DidPrepareTiles() { |
465 DCHECK(IsImplThread()); | 470 DCHECK(IsImplThread()); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 layer_tree_host_impl_->BeginCommit(); | 547 layer_tree_host_impl_->BeginCommit(); |
543 blocked_main_commit().layer_tree_host->FinishCommitOnImplThread( | 548 blocked_main_commit().layer_tree_host->FinishCommitOnImplThread( |
544 layer_tree_host_impl_.get()); | 549 layer_tree_host_impl_.get()); |
545 | 550 |
546 // Remove the LayerTreeHost reference before the completion event is signaled | 551 // Remove the LayerTreeHost reference before the completion event is signaled |
547 // and cleared. This is necessary since blocked_main_commit() allows access | 552 // and cleared. This is necessary since blocked_main_commit() allows access |
548 // only while we have the completion event to ensure the main thread is | 553 // only while we have the completion event to ensure the main thread is |
549 // blocked for a commit. | 554 // blocked for a commit. |
550 blocked_main_commit().layer_tree_host = nullptr; | 555 blocked_main_commit().layer_tree_host = nullptr; |
551 | 556 |
552 if (next_commit_waits_for_activation_) { | 557 if (commit_completion_waits_for_activation_) { |
553 // For some layer types in impl-side painting, the commit is held until | 558 // For some layer types in impl-side painting, the commit is held until the |
554 // the sync tree is activated. It's also possible that the | 559 // sync tree is activated. It's also possible that the sync tree has |
555 // sync tree has already activated if there was no work to be done. | 560 // already activated if there was no work to be done. |
556 TRACE_EVENT_INSTANT0("cc", "HoldCommit", TRACE_EVENT_SCOPE_THREAD); | 561 TRACE_EVENT_INSTANT0("cc", "HoldCommit", TRACE_EVENT_SCOPE_THREAD); |
| 562 commit_completion_waits_for_activation_ = false; |
| 563 activation_completion_event_ = commit_completion_event_; |
557 } else { | 564 } else { |
558 commit_completion_event_->Signal(); | 565 commit_completion_event_->Signal(); |
559 commit_completion_event_ = nullptr; | |
560 } | 566 } |
| 567 commit_completion_event_ = nullptr; |
561 | 568 |
562 scheduler_->DidCommit(); | 569 scheduler_->DidCommit(); |
563 | 570 |
564 // Delay this step until afer the main thread has been released as it's | 571 // Delay this step until afer the main thread has been released as it's |
565 // often a good bit of work to update the tree and prepare the new frame. | 572 // often a good bit of work to update the tree and prepare the new frame. |
566 layer_tree_host_impl_->CommitComplete(); | 573 layer_tree_host_impl_->CommitComplete(); |
567 | 574 |
568 SetInputThrottledUntilCommitOnImpl(false); | 575 SetInputThrottledUntilCommitOnImpl(false); |
569 | 576 |
570 next_frame_is_newly_committed_frame_ = true; | 577 next_frame_is_newly_committed_frame_ = true; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 bool ProxyImpl::IsMainThreadBlocked() const { | 674 bool ProxyImpl::IsMainThreadBlocked() const { |
668 return task_runner_provider_->IsMainThreadBlocked(); | 675 return task_runner_provider_->IsMainThreadBlocked(); |
669 } | 676 } |
670 | 677 |
671 ProxyImpl::BlockedMainCommitOnly& ProxyImpl::blocked_main_commit() { | 678 ProxyImpl::BlockedMainCommitOnly& ProxyImpl::blocked_main_commit() { |
672 DCHECK(IsMainThreadBlocked() && commit_completion_event_); | 679 DCHECK(IsMainThreadBlocked() && commit_completion_event_); |
673 return main_thread_blocked_commit_vars_unsafe_; | 680 return main_thread_blocked_commit_vars_unsafe_; |
674 } | 681 } |
675 | 682 |
676 } // namespace cc | 683 } // namespace cc |
OLD | NEW |