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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 DCHECK_EQ(state_machine_.NextAction(), SchedulerStateMachine::ACTION_NONE); | 206 DCHECK_EQ(state_machine_.NextAction(), SchedulerStateMachine::ACTION_NONE); |
207 } | 207 } |
208 } | 208 } |
209 | 209 |
210 void Scheduler::DidSwapBuffersComplete() { | 210 void Scheduler::DidSwapBuffersComplete() { |
211 DCHECK_GT(state_machine_.pending_swaps(), 0) << AsValue()->ToString(); | 211 DCHECK_GT(state_machine_.pending_swaps(), 0) << AsValue()->ToString(); |
212 state_machine_.DidSwapBuffersComplete(); | 212 state_machine_.DidSwapBuffersComplete(); |
213 ProcessScheduledActions(); | 213 ProcessScheduledActions(); |
214 } | 214 } |
215 | 215 |
216 void Scheduler::SetImplLatencyTakesPriority(bool impl_latency_takes_priority) { | 216 void Scheduler::SetSmoothnessMode(bool smoothness_takes_priority, |
217 state_machine_.SetImplLatencyTakesPriority(impl_latency_takes_priority); | 217 bool scroll_affects_scroll_handler) { |
218 state_machine_.SetSmoothnessMode(smoothness_takes_priority, | |
219 scroll_affects_scroll_handler); | |
218 ProcessScheduledActions(); | 220 ProcessScheduledActions(); |
219 } | 221 } |
220 | 222 |
221 void Scheduler::NotifyReadyToCommit() { | 223 void Scheduler::NotifyReadyToCommit() { |
222 TRACE_EVENT0("cc", "Scheduler::NotifyReadyToCommit"); | 224 TRACE_EVENT0("cc", "Scheduler::NotifyReadyToCommit"); |
223 state_machine_.NotifyReadyToCommit(); | 225 state_machine_.NotifyReadyToCommit(); |
224 ProcessScheduledActions(); | 226 ProcessScheduledActions(); |
225 } | 227 } |
226 | 228 |
227 void Scheduler::DidCommit() { | 229 void Scheduler::DidCommit() { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
304 TRACE_EVENT1("cc,benchmark", "Scheduler::BeginFrame", "args", args.AsValue()); | 306 TRACE_EVENT1("cc,benchmark", "Scheduler::BeginFrame", "args", args.AsValue()); |
305 | 307 |
306 // Trace this begin frame time through the Chrome stack | 308 // Trace this begin frame time through the Chrome stack |
307 TRACE_EVENT_FLOW_BEGIN0( | 309 TRACE_EVENT_FLOW_BEGIN0( |
308 TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), "BeginFrameArgs", | 310 TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), "BeginFrameArgs", |
309 args.frame_time.ToInternalValue()); | 311 args.frame_time.ToInternalValue()); |
310 | 312 |
311 // TODO(brianderson): Adjust deadline in the DisplayScheduler. | 313 // TODO(brianderson): Adjust deadline in the DisplayScheduler. |
312 BeginFrameArgs adjusted_args(args); | 314 BeginFrameArgs adjusted_args(args); |
313 adjusted_args.deadline -= EstimatedParentDrawTime(); | 315 adjusted_args.deadline -= EstimatedParentDrawTime(); |
314 adjusted_args.on_critical_path = !ImplLatencyTakesPriority(); | |
315 | 316 |
316 // Deliver BeginFrames to children. | 317 // Deliver BeginFrames to children. |
317 // TODO(brianderson): Move this responsibility to the DisplayScheduler. | 318 // TODO(brianderson): Move this responsibility to the DisplayScheduler. |
318 if (state_machine_.children_need_begin_frames()) | 319 if (state_machine_.children_need_begin_frames()) |
319 client_->SendBeginFramesToChildren(adjusted_args); | 320 client_->SendBeginFramesToChildren(adjusted_args); |
320 | 321 |
321 if (settings_.using_synchronous_renderer_compositor) { | 322 if (settings_.using_synchronous_renderer_compositor) { |
322 BeginImplFrameSynchronous(adjusted_args); | 323 BeginImplFrameSynchronous(adjusted_args); |
323 return true; | 324 return true; |
324 } | 325 } |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
461 TRACE_EVENT2("cc,benchmark", "Scheduler::BeginImplFrame", "args", | 462 TRACE_EVENT2("cc,benchmark", "Scheduler::BeginImplFrame", "args", |
462 args.AsValue(), "main_thread_missed_last_deadline", | 463 args.AsValue(), "main_thread_missed_last_deadline", |
463 main_thread_is_in_high_latency_mode); | 464 main_thread_is_in_high_latency_mode); |
464 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), | 465 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), |
465 "MainThreadLatency", main_thread_is_in_high_latency_mode); | 466 "MainThreadLatency", main_thread_is_in_high_latency_mode); |
466 | 467 |
467 BeginFrameArgs adjusted_args = args; | 468 BeginFrameArgs adjusted_args = args; |
468 adjusted_args.deadline -= compositor_timing_history_->DrawDurationEstimate(); | 469 adjusted_args.deadline -= compositor_timing_history_->DrawDurationEstimate(); |
469 adjusted_args.deadline -= kDeadlineFudgeFactor; | 470 adjusted_args.deadline -= kDeadlineFudgeFactor; |
470 | 471 |
471 if (ShouldRecoverMainLatency(adjusted_args)) { | 472 base::TimeDelta bmf_start_to_activate = |
473 compositor_timing_history_ | |
474 ->BeginMainFrameStartToCommitDurationEstimate() + | |
475 compositor_timing_history_->CommitToReadyToActivateDurationEstimate() + | |
476 compositor_timing_history_->ActivateDurationEstimate(); | |
477 | |
478 base::TimeDelta bmf_to_activate_estimate_if_critical = | |
479 bmf_start_to_activate + | |
480 compositor_timing_history_->BeginMainFrameQueueDurationCriticalEstimate(); | |
481 state_machine_.SetCriticalBeginMainFrameToActivateIsFast( | |
482 bmf_to_activate_estimate_if_critical < args.interval); | |
Sami
2015/11/06 11:54:42
Should we be comparing against the adjusted deadli
brianderson
2015/11/12 20:22:04
Yeah. For the purposes of this patch, I think we s
| |
483 | |
484 // Update the BeginMainFrame args now that we know whether the main | |
485 // thread will be on the critical path or not. | |
486 begin_main_frame_args_ = adjusted_args; | |
487 begin_main_frame_args_.on_critical_path = !ImplLatencyTakesPriority(); | |
488 | |
489 base::TimeDelta bmf_to_activate_estimate = | |
490 begin_main_frame_args_.on_critical_path | |
491 ? bmf_to_activate_estimate_if_critical | |
492 : bmf_start_to_activate + | |
493 compositor_timing_history_ | |
494 ->BeginMainFrameQueueDurationNotCriticalEstimate(); | |
495 | |
496 bool can_activate_before_deadline = CanCommitAndActivateBeforeDeadline( | |
497 adjusted_args, bmf_to_activate_estimate); | |
498 if (ShouldRecoverMainLatency(adjusted_args, can_activate_before_deadline)) { | |
472 TRACE_EVENT_INSTANT0("cc", "SkipBeginMainFrameToReduceLatency", | 499 TRACE_EVENT_INSTANT0("cc", "SkipBeginMainFrameToReduceLatency", |
473 TRACE_EVENT_SCOPE_THREAD); | 500 TRACE_EVENT_SCOPE_THREAD); |
474 state_machine_.SetSkipNextBeginMainFrameToReduceLatency(); | 501 state_machine_.SetSkipNextBeginMainFrameToReduceLatency(); |
475 } else if (ShouldRecoverImplLatency(adjusted_args)) { | 502 } else if (ShouldRecoverImplLatency(adjusted_args, |
503 can_activate_before_deadline)) { | |
476 TRACE_EVENT_INSTANT0("cc", "SkipBeginImplFrameToReduceLatency", | 504 TRACE_EVENT_INSTANT0("cc", "SkipBeginImplFrameToReduceLatency", |
477 TRACE_EVENT_SCOPE_THREAD); | 505 TRACE_EVENT_SCOPE_THREAD); |
478 frame_source_->DidFinishFrame(begin_retro_frame_args_.size()); | 506 frame_source_->DidFinishFrame(begin_retro_frame_args_.size()); |
479 return; | 507 return; |
480 } | 508 } |
481 | 509 |
482 BeginImplFrame(adjusted_args); | 510 BeginImplFrame(adjusted_args); |
483 | 511 |
484 // The deadline will be scheduled in ProcessScheduledActions. | 512 // The deadline will be scheduled in ProcessScheduledActions. |
485 state_machine_.OnBeginImplFrameDeadlinePending(); | 513 state_machine_.OnBeginImplFrameDeadlinePending(); |
486 ProcessScheduledActions(); | 514 ProcessScheduledActions(); |
487 } | 515 } |
488 | 516 |
489 void Scheduler::BeginImplFrameSynchronous(const BeginFrameArgs& args) { | 517 void Scheduler::BeginImplFrameSynchronous(const BeginFrameArgs& args) { |
490 TRACE_EVENT1("cc,benchmark", "Scheduler::BeginImplFrame", "args", | 518 TRACE_EVENT1("cc,benchmark", "Scheduler::BeginImplFrame", "args", |
491 args.AsValue()); | 519 args.AsValue()); |
520 | |
521 // The main thread currently can't commit before we draw with the | |
522 // synchronous compositor, so never consider the BeginMainFrame fast. | |
523 state_machine_.SetCriticalBeginMainFrameToActivateIsFast(false); | |
524 begin_main_frame_args_ = args; | |
525 begin_main_frame_args_.on_critical_path = !ImplLatencyTakesPriority(); | |
526 | |
492 BeginImplFrame(args); | 527 BeginImplFrame(args); |
493 FinishImplFrame(); | 528 FinishImplFrame(); |
494 } | 529 } |
495 | 530 |
496 void Scheduler::FinishImplFrame() { | 531 void Scheduler::FinishImplFrame() { |
497 state_machine_.OnBeginImplFrameIdle(); | 532 state_machine_.OnBeginImplFrameIdle(); |
498 ProcessScheduledActions(); | 533 ProcessScheduledActions(); |
499 | 534 |
500 client_->DidFinishImplFrame(); | 535 client_->DidFinishImplFrame(); |
501 frame_source_->DidFinishFrame(begin_retro_frame_args_.size()); | 536 frame_source_->DidFinishFrame(begin_retro_frame_args_.size()); |
502 begin_impl_frame_tracker_.Finish(); | 537 begin_impl_frame_tracker_.Finish(); |
503 } | 538 } |
504 | 539 |
505 // BeginImplFrame starts a compositor frame that will wait up until a deadline | 540 // BeginImplFrame starts a compositor frame that will wait up until a deadline |
506 // for a BeginMainFrame+activation to complete before it times out and draws | 541 // for a BeginMainFrame+activation to complete before it times out and draws |
507 // any asynchronous animation and scroll/pinch updates. | 542 // any asynchronous animation and scroll/pinch updates. |
508 void Scheduler::BeginImplFrame(const BeginFrameArgs& args) { | 543 void Scheduler::BeginImplFrame(const BeginFrameArgs& args) { |
509 DCHECK_EQ(state_machine_.begin_impl_frame_state(), | 544 DCHECK_EQ(state_machine_.begin_impl_frame_state(), |
510 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); | 545 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); |
511 DCHECK(!BeginImplFrameDeadlinePending()); | 546 DCHECK(!BeginImplFrameDeadlinePending()); |
512 DCHECK(state_machine_.HasInitializedOutputSurface()); | 547 DCHECK(state_machine_.HasInitializedOutputSurface()); |
513 | 548 |
514 begin_impl_frame_tracker_.Start(args); | 549 begin_impl_frame_tracker_.Start(args); |
515 begin_main_frame_args_ = args; | |
516 state_machine_.OnBeginImplFrame(); | 550 state_machine_.OnBeginImplFrame(); |
517 devtools_instrumentation::DidBeginFrame(layer_tree_host_id_); | 551 devtools_instrumentation::DidBeginFrame(layer_tree_host_id_); |
518 client_->WillBeginImplFrame(begin_impl_frame_tracker_.Current()); | 552 client_->WillBeginImplFrame(begin_impl_frame_tracker_.Current()); |
519 | 553 |
520 ProcessScheduledActions(); | 554 ProcessScheduledActions(); |
521 } | 555 } |
522 | 556 |
523 void Scheduler::ScheduleBeginImplFrameDeadline() { | 557 void Scheduler::ScheduleBeginImplFrameDeadline() { |
524 // The synchronous compositor does not post a deadline task. | 558 // The synchronous compositor does not post a deadline task. |
525 DCHECK(!settings_.using_synchronous_renderer_compositor); | 559 DCHECK(!settings_.using_synchronous_renderer_compositor); |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
777 state->BeginDictionary("compositor_timing_history"); | 811 state->BeginDictionary("compositor_timing_history"); |
778 compositor_timing_history_->AsValueInto(state); | 812 compositor_timing_history_->AsValueInto(state); |
779 state->EndDictionary(); | 813 state->EndDictionary(); |
780 } | 814 } |
781 | 815 |
782 void Scheduler::UpdateCompositorTimingHistoryRecordingEnabled() { | 816 void Scheduler::UpdateCompositorTimingHistoryRecordingEnabled() { |
783 compositor_timing_history_->SetRecordingEnabled( | 817 compositor_timing_history_->SetRecordingEnabled( |
784 state_machine_.HasInitializedOutputSurface() && state_machine_.visible()); | 818 state_machine_.HasInitializedOutputSurface() && state_machine_.visible()); |
785 } | 819 } |
786 | 820 |
787 bool Scheduler::ShouldRecoverMainLatency(const BeginFrameArgs& args) const { | 821 bool Scheduler::ShouldRecoverMainLatency( |
822 const BeginFrameArgs& args, | |
823 bool can_activate_before_deadline) const { | |
788 DCHECK(!settings_.using_synchronous_renderer_compositor); | 824 DCHECK(!settings_.using_synchronous_renderer_compositor); |
789 | 825 |
790 if (!state_machine_.main_thread_missed_last_deadline()) | 826 if (!state_machine_.main_thread_missed_last_deadline()) |
791 return false; | 827 return false; |
792 | 828 |
793 // When prioritizing impl thread latency, we currently put the | 829 // When prioritizing impl thread latency, we currently put the |
794 // main thread in a high latency mode. Don't try to fight it. | 830 // main thread in a high latency mode. Don't try to fight it. |
795 if (state_machine_.impl_latency_takes_priority()) | 831 if (state_machine_.ImplLatencyTakesPriority()) |
796 return false; | 832 return false; |
797 | 833 |
798 return CanCommitAndActivateBeforeDeadline(args); | 834 return can_activate_before_deadline; |
799 } | 835 } |
800 | 836 |
801 bool Scheduler::ShouldRecoverImplLatency(const BeginFrameArgs& args) const { | 837 bool Scheduler::ShouldRecoverImplLatency( |
838 const BeginFrameArgs& args, | |
839 bool can_activate_before_deadline) const { | |
802 DCHECK(!settings_.using_synchronous_renderer_compositor); | 840 DCHECK(!settings_.using_synchronous_renderer_compositor); |
803 | 841 |
804 // Disable impl thread latency recovery when using the unthrottled | 842 // Disable impl thread latency recovery when using the unthrottled |
805 // begin frame source since we will always get a BeginFrame before | 843 // begin frame source since we will always get a BeginFrame before |
806 // the swap ack and our heuristics below will not work. | 844 // the swap ack and our heuristics below will not work. |
807 if (!throttle_frame_production_) | 845 if (!throttle_frame_production_) |
808 return false; | 846 return false; |
809 | 847 |
810 // If we are swap throttled at the BeginFrame, that means the impl thread is | 848 // If we are swap throttled at the BeginFrame, that means the impl thread is |
811 // very likely in a high latency mode. | 849 // very likely in a high latency mode. |
812 bool impl_thread_is_likely_high_latency = state_machine_.SwapThrottled(); | 850 bool impl_thread_is_likely_high_latency = state_machine_.SwapThrottled(); |
813 if (!impl_thread_is_likely_high_latency) | 851 if (!impl_thread_is_likely_high_latency) |
814 return false; | 852 return false; |
815 | 853 |
816 // The deadline may be in the past if our draw time is too long. | 854 // The deadline may be in the past if our draw time is too long. |
817 bool can_draw_before_deadline = args.frame_time < args.deadline; | 855 bool can_draw_before_deadline = args.frame_time < args.deadline; |
818 | 856 |
819 // When prioritizing impl thread latency, the deadline doesn't wait | 857 // When prioritizing impl thread latency, the deadline doesn't wait |
820 // for the main thread. | 858 // for the main thread. |
821 if (state_machine_.impl_latency_takes_priority()) | 859 if (state_machine_.ImplLatencyTakesPriority()) |
822 return can_draw_before_deadline; | 860 return can_draw_before_deadline; |
823 | 861 |
824 // If we only have impl-side updates, the deadline doesn't wait for | 862 // If we only have impl-side updates, the deadline doesn't wait for |
825 // the main thread. | 863 // the main thread. |
826 if (state_machine_.OnlyImplSideUpdatesExpected()) | 864 if (state_machine_.OnlyImplSideUpdatesExpected()) |
827 return can_draw_before_deadline; | 865 return can_draw_before_deadline; |
828 | 866 |
829 // If we get here, we know the main thread is in a low-latency mode relative | 867 // If we get here, we know the main thread is in a low-latency mode relative |
830 // to the impl thread. In this case, only try to also recover impl thread | 868 // to the impl thread. In this case, only try to also recover impl thread |
831 // latency if both the main and impl threads can run serially before the | 869 // latency if both the main and impl threads can run serially before the |
832 // deadline. | 870 // deadline. |
833 return CanCommitAndActivateBeforeDeadline(args); | 871 return can_activate_before_deadline; |
834 } | 872 } |
835 | 873 |
836 bool Scheduler::CanCommitAndActivateBeforeDeadline( | 874 bool Scheduler::CanCommitAndActivateBeforeDeadline( |
837 const BeginFrameArgs& args) const { | 875 const BeginFrameArgs& args, |
876 base::TimeDelta bmf_to_activate_estimate) const { | |
838 // Check if the main thread computation and commit can be finished before the | 877 // Check if the main thread computation and commit can be finished before the |
839 // impl thread's deadline. | 878 // impl thread's deadline. |
840 base::TimeTicks estimated_draw_time = | 879 base::TimeTicks estimated_draw_time = |
841 args.frame_time + | 880 args.frame_time + bmf_to_activate_estimate; |
842 compositor_timing_history_->BeginMainFrameToCommitDurationEstimate() + | |
843 compositor_timing_history_->CommitToReadyToActivateDurationEstimate() + | |
844 compositor_timing_history_->ActivateDurationEstimate(); | |
845 | 881 |
846 return estimated_draw_time < args.deadline; | 882 return estimated_draw_time < args.deadline; |
847 } | 883 } |
848 | 884 |
849 bool Scheduler::IsBeginMainFrameSentOrStarted() const { | 885 bool Scheduler::IsBeginMainFrameSentOrStarted() const { |
850 return (state_machine_.begin_main_frame_state() == | 886 return (state_machine_.begin_main_frame_state() == |
851 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT || | 887 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT || |
852 state_machine_.begin_main_frame_state() == | 888 state_machine_.begin_main_frame_state() == |
853 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_STARTED); | 889 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_STARTED); |
854 } | 890 } |
855 | 891 |
856 } // namespace cc | 892 } // namespace cc |
OLD | NEW |