| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/scheduler/scheduler.h" | 5 #include "cc/scheduler/scheduler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 estimated_parent_draw_time_ = draw_time; | 124 estimated_parent_draw_time_ = draw_time; |
| 125 } | 125 } |
| 126 | 126 |
| 127 void Scheduler::SetCanStart() { | 127 void Scheduler::SetCanStart() { |
| 128 state_machine_.SetCanStart(); | 128 state_machine_.SetCanStart(); |
| 129 ProcessScheduledActions(); | 129 ProcessScheduledActions(); |
| 130 } | 130 } |
| 131 | 131 |
| 132 void Scheduler::SetVisible(bool visible) { | 132 void Scheduler::SetVisible(bool visible) { |
| 133 state_machine_.SetVisible(visible); | 133 state_machine_.SetVisible(visible); |
| 134 UpdateCompositorTimingHistoryRecordingEnabled(); |
| 134 ProcessScheduledActions(); | 135 ProcessScheduledActions(); |
| 135 } | 136 } |
| 136 | 137 |
| 137 void Scheduler::SetCanDraw(bool can_draw) { | 138 void Scheduler::SetCanDraw(bool can_draw) { |
| 138 state_machine_.SetCanDraw(can_draw); | 139 state_machine_.SetCanDraw(can_draw); |
| 139 ProcessScheduledActions(); | 140 ProcessScheduledActions(); |
| 140 } | 141 } |
| 141 | 142 |
| 142 void Scheduler::NotifyReadyToActivate() { | 143 void Scheduler::NotifyReadyToActivate() { |
| 144 compositor_timing_history_->ReadyToActivate(); |
| 143 state_machine_.NotifyReadyToActivate(); | 145 state_machine_.NotifyReadyToActivate(); |
| 144 ProcessScheduledActions(); | 146 ProcessScheduledActions(); |
| 145 } | 147 } |
| 146 | 148 |
| 147 void Scheduler::NotifyReadyToDraw() { | 149 void Scheduler::NotifyReadyToDraw() { |
| 148 // Future work might still needed for crbug.com/352894. | 150 // Future work might still needed for crbug.com/352894. |
| 149 state_machine_.NotifyReadyToDraw(); | 151 state_machine_.NotifyReadyToDraw(); |
| 150 ProcessScheduledActions(); | 152 ProcessScheduledActions(); |
| 151 } | 153 } |
| 152 | 154 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 state_machine_.SetImplLatencyTakesPriority(impl_latency_takes_priority); | 212 state_machine_.SetImplLatencyTakesPriority(impl_latency_takes_priority); |
| 211 ProcessScheduledActions(); | 213 ProcessScheduledActions(); |
| 212 } | 214 } |
| 213 | 215 |
| 214 void Scheduler::NotifyReadyToCommit() { | 216 void Scheduler::NotifyReadyToCommit() { |
| 215 TRACE_EVENT0("cc", "Scheduler::NotifyReadyToCommit"); | 217 TRACE_EVENT0("cc", "Scheduler::NotifyReadyToCommit"); |
| 216 state_machine_.NotifyReadyToCommit(); | 218 state_machine_.NotifyReadyToCommit(); |
| 217 ProcessScheduledActions(); | 219 ProcessScheduledActions(); |
| 218 } | 220 } |
| 219 | 221 |
| 222 void Scheduler::DidCommit() { |
| 223 compositor_timing_history_->DidCommit(); |
| 224 } |
| 225 |
| 220 void Scheduler::BeginMainFrameAborted(CommitEarlyOutReason reason) { | 226 void Scheduler::BeginMainFrameAborted(CommitEarlyOutReason reason) { |
| 221 TRACE_EVENT1("cc", "Scheduler::BeginMainFrameAborted", "reason", | 227 TRACE_EVENT1("cc", "Scheduler::BeginMainFrameAborted", "reason", |
| 222 CommitEarlyOutReasonToString(reason)); | 228 CommitEarlyOutReasonToString(reason)); |
| 229 compositor_timing_history_->BeginMainFrameAborted(); |
| 223 state_machine_.BeginMainFrameAborted(reason); | 230 state_machine_.BeginMainFrameAborted(reason); |
| 224 ProcessScheduledActions(); | 231 ProcessScheduledActions(); |
| 225 } | 232 } |
| 226 | 233 |
| 234 void Scheduler::WillPrepareTiles() { |
| 235 compositor_timing_history_->WillPrepareTiles(); |
| 236 } |
| 237 |
| 227 void Scheduler::DidPrepareTiles() { | 238 void Scheduler::DidPrepareTiles() { |
| 239 compositor_timing_history_->DidPrepareTiles(); |
| 228 state_machine_.DidPrepareTiles(); | 240 state_machine_.DidPrepareTiles(); |
| 229 } | 241 } |
| 230 | 242 |
| 231 void Scheduler::DidLoseOutputSurface() { | 243 void Scheduler::DidLoseOutputSurface() { |
| 232 TRACE_EVENT0("cc", "Scheduler::DidLoseOutputSurface"); | 244 TRACE_EVENT0("cc", "Scheduler::DidLoseOutputSurface"); |
| 233 begin_retro_frame_args_.clear(); | 245 begin_retro_frame_args_.clear(); |
| 234 begin_retro_frame_task_.Cancel(); | 246 begin_retro_frame_task_.Cancel(); |
| 235 state_machine_.DidLoseOutputSurface(); | 247 state_machine_.DidLoseOutputSurface(); |
| 248 UpdateCompositorTimingHistoryRecordingEnabled(); |
| 236 ProcessScheduledActions(); | 249 ProcessScheduledActions(); |
| 237 } | 250 } |
| 238 | 251 |
| 239 void Scheduler::DidCreateAndInitializeOutputSurface() { | 252 void Scheduler::DidCreateAndInitializeOutputSurface() { |
| 240 TRACE_EVENT0("cc", "Scheduler::DidCreateAndInitializeOutputSurface"); | 253 TRACE_EVENT0("cc", "Scheduler::DidCreateAndInitializeOutputSurface"); |
| 241 DCHECK(!frame_source_->NeedsBeginFrames()); | 254 DCHECK(!frame_source_->NeedsBeginFrames()); |
| 242 DCHECK(begin_impl_frame_deadline_task_.IsCancelled()); | 255 DCHECK(begin_impl_frame_deadline_task_.IsCancelled()); |
| 243 state_machine_.DidCreateAndInitializeOutputSurface(); | 256 state_machine_.DidCreateAndInitializeOutputSurface(); |
| 257 UpdateCompositorTimingHistoryRecordingEnabled(); |
| 244 ProcessScheduledActions(); | 258 ProcessScheduledActions(); |
| 245 } | 259 } |
| 246 | 260 |
| 247 void Scheduler::NotifyBeginMainFrameStarted() { | 261 void Scheduler::NotifyBeginMainFrameStarted() { |
| 248 TRACE_EVENT0("cc", "Scheduler::NotifyBeginMainFrameStarted"); | 262 TRACE_EVENT0("cc", "Scheduler::NotifyBeginMainFrameStarted"); |
| 249 state_machine_.NotifyBeginMainFrameStarted(); | 263 state_machine_.NotifyBeginMainFrameStarted(); |
| 250 } | 264 } |
| 251 | 265 |
| 252 base::TimeTicks Scheduler::LastBeginImplFrameTime() { | 266 base::TimeTicks Scheduler::LastBeginImplFrameTime() { |
| 253 return begin_impl_frame_tracker_.Current().frame_time; | 267 return begin_impl_frame_tracker_.Current().frame_time; |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is fixed. | 586 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is fixed. |
| 573 tracked_objects::ScopedTracker tracking_profile1( | 587 tracked_objects::ScopedTracker tracking_profile1( |
| 574 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 588 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 575 "461509 Scheduler::OnBeginImplFrameDeadline1")); | 589 "461509 Scheduler::OnBeginImplFrameDeadline1")); |
| 576 state_machine_.OnBeginImplFrameDeadline(); | 590 state_machine_.OnBeginImplFrameDeadline(); |
| 577 ProcessScheduledActions(); | 591 ProcessScheduledActions(); |
| 578 FinishImplFrame(); | 592 FinishImplFrame(); |
| 579 } | 593 } |
| 580 | 594 |
| 581 void Scheduler::DrawAndSwapIfPossible() { | 595 void Scheduler::DrawAndSwapIfPossible() { |
| 582 compositor_timing_history_->DidStartDrawing(); | 596 compositor_timing_history_->WillDraw(); |
| 583 DrawResult result = client_->ScheduledActionDrawAndSwapIfPossible(); | 597 DrawResult result = client_->ScheduledActionDrawAndSwapIfPossible(); |
| 584 state_machine_.DidDrawIfPossibleCompleted(result); | 598 state_machine_.DidDrawIfPossibleCompleted(result); |
| 585 compositor_timing_history_->DidFinishDrawing(); | 599 compositor_timing_history_->DidDraw(); |
| 586 } | 600 } |
| 587 | 601 |
| 588 void Scheduler::DrawAndSwapForced() { | 602 void Scheduler::DrawAndSwapForced() { |
| 589 compositor_timing_history_->DidStartDrawing(); | 603 compositor_timing_history_->WillDraw(); |
| 590 client_->ScheduledActionDrawAndSwapForced(); | 604 client_->ScheduledActionDrawAndSwapForced(); |
| 591 compositor_timing_history_->DidFinishDrawing(); | 605 compositor_timing_history_->DidDraw(); |
| 592 } | 606 } |
| 593 | 607 |
| 594 void Scheduler::SetDeferCommits(bool defer_commits) { | 608 void Scheduler::SetDeferCommits(bool defer_commits) { |
| 595 TRACE_EVENT1("cc", "Scheduler::SetDeferCommits", | 609 TRACE_EVENT1("cc", "Scheduler::SetDeferCommits", |
| 596 "defer_commits", | 610 "defer_commits", |
| 597 defer_commits); | 611 defer_commits); |
| 598 state_machine_.SetDeferCommits(defer_commits); | 612 state_machine_.SetDeferCommits(defer_commits); |
| 599 ProcessScheduledActions(); | 613 ProcessScheduledActions(); |
| 600 } | 614 } |
| 601 | 615 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 630 compositor_timing_history_->WillBeginMainFrame(); | 644 compositor_timing_history_->WillBeginMainFrame(); |
| 631 client_->ScheduledActionSendBeginMainFrame(); | 645 client_->ScheduledActionSendBeginMainFrame(); |
| 632 break; | 646 break; |
| 633 case SchedulerStateMachine::ACTION_COMMIT: { | 647 case SchedulerStateMachine::ACTION_COMMIT: { |
| 634 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is | 648 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is |
| 635 // fixed. | 649 // fixed. |
| 636 tracked_objects::ScopedTracker tracking_profile4( | 650 tracked_objects::ScopedTracker tracking_profile4( |
| 637 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 651 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 638 "461509 Scheduler::ProcessScheduledActions4")); | 652 "461509 Scheduler::ProcessScheduledActions4")); |
| 639 client_->ScheduledActionCommit(); | 653 client_->ScheduledActionCommit(); |
| 640 compositor_timing_history_->DidCommit(); | |
| 641 break; | 654 break; |
| 642 } | 655 } |
| 643 case SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE: | 656 case SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE: |
| 657 compositor_timing_history_->WillActivate(); |
| 644 client_->ScheduledActionActivateSyncTree(); | 658 client_->ScheduledActionActivateSyncTree(); |
| 645 compositor_timing_history_->DidActivateSyncTree(); | 659 compositor_timing_history_->DidActivate(); |
| 646 break; | 660 break; |
| 647 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE: { | 661 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE: { |
| 648 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is | 662 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is |
| 649 // fixed. | 663 // fixed. |
| 650 tracked_objects::ScopedTracker tracking_profile6( | 664 tracked_objects::ScopedTracker tracking_profile6( |
| 651 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 665 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 652 "461509 Scheduler::ProcessScheduledActions6")); | 666 "461509 Scheduler::ProcessScheduledActions6")); |
| 653 DrawAndSwapIfPossible(); | 667 DrawAndSwapIfPossible(); |
| 654 break; | 668 break; |
| 655 } | 669 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 state->BeginDictionary("begin_impl_frame_args"); | 731 state->BeginDictionary("begin_impl_frame_args"); |
| 718 begin_impl_frame_tracker_.AsValueInto(Now(), state); | 732 begin_impl_frame_tracker_.AsValueInto(Now(), state); |
| 719 state->EndDictionary(); | 733 state->EndDictionary(); |
| 720 state->EndDictionary(); | 734 state->EndDictionary(); |
| 721 | 735 |
| 722 state->BeginDictionary("compositor_timing_history"); | 736 state->BeginDictionary("compositor_timing_history"); |
| 723 compositor_timing_history_->AsValueInto(state); | 737 compositor_timing_history_->AsValueInto(state); |
| 724 state->EndDictionary(); | 738 state->EndDictionary(); |
| 725 } | 739 } |
| 726 | 740 |
| 741 void Scheduler::UpdateCompositorTimingHistoryRecordingEnabled() { |
| 742 compositor_timing_history_->SetRecordingEnabled( |
| 743 state_machine_.HasInitializedOutputSurface() && state_machine_.visible()); |
| 744 } |
| 745 |
| 727 bool Scheduler::CanCommitAndActivateBeforeDeadline() const { | 746 bool Scheduler::CanCommitAndActivateBeforeDeadline() const { |
| 728 BeginFrameArgs args = | 747 BeginFrameArgs args = |
| 729 begin_impl_frame_tracker_.DangerousMethodCurrentOrLast(); | 748 begin_impl_frame_tracker_.DangerousMethodCurrentOrLast(); |
| 730 | 749 |
| 731 // Check if the main thread computation and commit can be finished before the | 750 // Check if the main thread computation and commit can be finished before the |
| 732 // impl thread's deadline. | 751 // impl thread's deadline. |
| 733 base::TimeTicks estimated_draw_time = | 752 base::TimeTicks estimated_draw_time = |
| 734 args.frame_time + | 753 args.frame_time + |
| 735 compositor_timing_history_->BeginMainFrameToCommitDurationEstimate() + | 754 compositor_timing_history_->BeginMainFrameToCommitDurationEstimate() + |
| 736 compositor_timing_history_->CommitToActivateDurationEstimate(); | 755 compositor_timing_history_ |
| 756 ->PrepareTilesBeginToReadyToActivateDurationEstimate() + |
| 757 compositor_timing_history_->ActivateDurationEstimate(); |
| 737 | 758 |
| 738 TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), | 759 TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), |
| 739 "CanCommitAndActivateBeforeDeadline", | 760 "CanCommitAndActivateBeforeDeadline", |
| 740 "time_left_after_drawing_ms", | 761 "time_left_after_drawing_ms", |
| 741 (args.deadline - estimated_draw_time).InMillisecondsF(), "state", | 762 (args.deadline - estimated_draw_time).InMillisecondsF(), "state", |
| 742 AsValue()); | 763 AsValue()); |
| 743 | 764 |
| 744 return estimated_draw_time < args.deadline; | 765 return estimated_draw_time < args.deadline; |
| 745 } | 766 } |
| 746 | 767 |
| 747 bool Scheduler::IsBeginMainFrameSentOrStarted() const { | 768 bool Scheduler::IsBeginMainFrameSentOrStarted() const { |
| 748 return (state_machine_.commit_state() == | 769 return (state_machine_.commit_state() == |
| 749 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || | 770 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || |
| 750 state_machine_.commit_state() == | 771 state_machine_.commit_state() == |
| 751 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); | 772 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); |
| 752 } | 773 } |
| 753 | 774 |
| 754 } // namespace cc | 775 } // namespace cc |
| OLD | NEW |