| 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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 } | 310 } |
| 311 | 311 |
| 312 void Scheduler::BeginImplFrameWithDeadline(const BeginFrameArgs& args) { | 312 void Scheduler::BeginImplFrameWithDeadline(const BeginFrameArgs& args) { |
| 313 // The storage for |args| is owned by the missed begin frame task. Therefore | 313 // The storage for |args| is owned by the missed begin frame task. Therefore |
| 314 // save |args| before cancelling the task either here or in the deadline. | 314 // save |args| before cancelling the task either here or in the deadline. |
| 315 BeginFrameArgs adjusted_args = args; | 315 BeginFrameArgs adjusted_args = args; |
| 316 // Cancel the missed begin frame task in case the BFS sends a begin frame | 316 // Cancel the missed begin frame task in case the BFS sends a begin frame |
| 317 // before the missed frame task runs. | 317 // before the missed frame task runs. |
| 318 missed_begin_frame_task_.Cancel(); | 318 missed_begin_frame_task_.Cancel(); |
| 319 | 319 |
| 320 base::TimeTicks now = Now(); |
| 321 |
| 320 // Discard missed begin frames if they are too late. | 322 // Discard missed begin frames if they are too late. |
| 321 if (adjusted_args.type == BeginFrameArgs::MISSED && | 323 if (adjusted_args.type == BeginFrameArgs::MISSED && |
| 322 Now() > adjusted_args.deadline) { | 324 now > adjusted_args.deadline) { |
| 323 begin_frame_source_->DidFinishFrame(this, 0); | 325 begin_frame_source_->DidFinishFrame(this, 0); |
| 324 return; | 326 return; |
| 325 } | 327 } |
| 326 | 328 |
| 327 // Run the previous deadline if any. | 329 // Run the previous deadline if any. |
| 328 if (state_machine_.begin_impl_frame_state() == | 330 if (state_machine_.begin_impl_frame_state() == |
| 329 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME) { | 331 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME) { |
| 330 OnBeginImplFrameDeadline(); | 332 OnBeginImplFrameDeadline(); |
| 331 // We may not need begin frames any longer. | 333 // We may not need begin frames any longer. |
| 332 if (!observing_begin_frame_source_) { | 334 if (!observing_begin_frame_source_) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 base::TimeDelta bmf_to_activate_estimate = bmf_to_activate_estimate_critical; | 374 base::TimeDelta bmf_to_activate_estimate = bmf_to_activate_estimate_critical; |
| 373 if (!begin_main_frame_args_.on_critical_path) { | 375 if (!begin_main_frame_args_.on_critical_path) { |
| 374 bmf_to_activate_estimate = | 376 bmf_to_activate_estimate = |
| 375 bmf_start_to_activate + | 377 bmf_start_to_activate + |
| 376 compositor_timing_history_ | 378 compositor_timing_history_ |
| 377 ->BeginMainFrameQueueDurationNotCriticalEstimate(); | 379 ->BeginMainFrameQueueDurationNotCriticalEstimate(); |
| 378 } | 380 } |
| 379 | 381 |
| 380 bool can_activate_before_deadline = | 382 bool can_activate_before_deadline = |
| 381 CanBeginMainFrameAndActivateBeforeDeadline(adjusted_args, | 383 CanBeginMainFrameAndActivateBeforeDeadline(adjusted_args, |
| 382 bmf_to_activate_estimate); | 384 bmf_to_activate_estimate, now); |
| 383 | 385 |
| 384 if (ShouldRecoverMainLatency(adjusted_args, can_activate_before_deadline)) { | 386 if (ShouldRecoverMainLatency(adjusted_args, can_activate_before_deadline)) { |
| 385 TRACE_EVENT_INSTANT0("cc", "SkipBeginMainFrameToReduceLatency", | 387 TRACE_EVENT_INSTANT0("cc", "SkipBeginMainFrameToReduceLatency", |
| 386 TRACE_EVENT_SCOPE_THREAD); | 388 TRACE_EVENT_SCOPE_THREAD); |
| 387 state_machine_.SetSkipNextBeginMainFrameToReduceLatency(); | 389 state_machine_.SetSkipNextBeginMainFrameToReduceLatency(); |
| 388 } else if (ShouldRecoverImplLatency(adjusted_args, | 390 } else if (ShouldRecoverImplLatency(adjusted_args, |
| 389 can_activate_before_deadline)) { | 391 can_activate_before_deadline)) { |
| 390 TRACE_EVENT_INSTANT0("cc", "SkipBeginImplFrameToReduceLatency", | 392 TRACE_EVENT_INSTANT0("cc", "SkipBeginImplFrameToReduceLatency", |
| 391 TRACE_EVENT_SCOPE_THREAD); | 393 TRACE_EVENT_SCOPE_THREAD); |
| 392 if (begin_frame_source_) | 394 if (begin_frame_source_) |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 | 734 |
| 733 // If we get here, we know the main thread is in a low-latency mode relative | 735 // If we get here, we know the main thread is in a low-latency mode relative |
| 734 // to the impl thread. In this case, only try to also recover impl thread | 736 // to the impl thread. In this case, only try to also recover impl thread |
| 735 // latency if both the main and impl threads can run serially before the | 737 // latency if both the main and impl threads can run serially before the |
| 736 // deadline. | 738 // deadline. |
| 737 return can_activate_before_deadline; | 739 return can_activate_before_deadline; |
| 738 } | 740 } |
| 739 | 741 |
| 740 bool Scheduler::CanBeginMainFrameAndActivateBeforeDeadline( | 742 bool Scheduler::CanBeginMainFrameAndActivateBeforeDeadline( |
| 741 const BeginFrameArgs& args, | 743 const BeginFrameArgs& args, |
| 742 base::TimeDelta bmf_to_activate_estimate) const { | 744 base::TimeDelta bmf_to_activate_estimate, |
| 745 base::TimeTicks now) const { |
| 743 // Check if the main thread computation and commit can be finished before the | 746 // Check if the main thread computation and commit can be finished before the |
| 744 // impl thread's deadline. | 747 // impl thread's deadline. |
| 745 base::TimeTicks estimated_draw_time = | 748 base::TimeTicks estimated_draw_time = now + bmf_to_activate_estimate; |
| 746 args.frame_time + bmf_to_activate_estimate; | |
| 747 | 749 |
| 748 return estimated_draw_time < args.deadline; | 750 return estimated_draw_time < args.deadline; |
| 749 } | 751 } |
| 750 | 752 |
| 751 bool Scheduler::IsBeginMainFrameSentOrStarted() const { | 753 bool Scheduler::IsBeginMainFrameSentOrStarted() const { |
| 752 return (state_machine_.begin_main_frame_state() == | 754 return (state_machine_.begin_main_frame_state() == |
| 753 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT || | 755 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT || |
| 754 state_machine_.begin_main_frame_state() == | 756 state_machine_.begin_main_frame_state() == |
| 755 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_STARTED); | 757 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_STARTED); |
| 756 } | 758 } |
| 757 | 759 |
| 758 } // namespace cc | 760 } // namespace cc |
| OLD | NEW |