Index: cc/scheduler/scheduler.cc |
diff --git a/cc/scheduler/scheduler.cc b/cc/scheduler/scheduler.cc |
index cd0d37ea2a81c32d1d37d6698b3cf04c296d6e47..523102cd5899599cb128d012b3abd7fd62816dad 100644 |
--- a/cc/scheduler/scheduler.cc |
+++ b/cc/scheduler/scheduler.cc |
@@ -459,14 +459,21 @@ void Scheduler::BeginImplFrameWithDeadline(const BeginFrameArgs& args) { |
BeginFrameArgs adjusted_args = args; |
adjusted_args.deadline -= compositor_timing_history_->DrawDurationEstimate(); |
+ begin_impl_frame_tracker_.Start(adjusted_args); |
- if (!state_machine_.impl_latency_takes_priority() && |
- main_thread_is_in_high_latency_mode && |
- CanCommitAndActivateBeforeDeadline()) { |
+ if (ShouldRecoverMainLatency()) { |
+ TRACE_EVENT_INSTANT0("cc", "SkipBeginMainFrameToReduceLatency", |
+ TRACE_EVENT_SCOPE_THREAD); |
state_machine_.SetSkipNextBeginMainFrameToReduceLatency(); |
+ } else if (ShouldRecoverImplLatency()) { |
+ TRACE_EVENT_INSTANT0("cc", "SkipBeginImplFrameToReduceLatency", |
+ TRACE_EVENT_SCOPE_THREAD); |
+ frame_source_->DidFinishFrame(begin_retro_frame_args_.size()); |
+ begin_impl_frame_tracker_.Finish(); |
+ return; |
} |
- BeginImplFrame(adjusted_args); |
+ BeginImplFrame(); |
mithro-old
2015/07/06 11:58:42
As discussed, you were going to change this code b
brianderson
2015/07/07 02:04:49
Done.
|
// The deadline will be scheduled in ProcessScheduledActions. |
state_machine_.OnBeginImplFrameDeadlinePending(); |
@@ -476,7 +483,8 @@ void Scheduler::BeginImplFrameWithDeadline(const BeginFrameArgs& args) { |
void Scheduler::BeginImplFrameSynchronous(const BeginFrameArgs& args) { |
TRACE_EVENT1("cc,benchmark", "Scheduler::BeginImplFrame", "args", |
args.AsValue()); |
- BeginImplFrame(args); |
+ begin_impl_frame_tracker_.Start(args); |
+ BeginImplFrame(); |
FinishImplFrame(); |
} |
@@ -492,13 +500,12 @@ void Scheduler::FinishImplFrame() { |
// BeginImplFrame starts a compositor frame that will wait up until a deadline |
// for a BeginMainFrame+activation to complete before it times out and draws |
// any asynchronous animation and scroll/pinch updates. |
-void Scheduler::BeginImplFrame(const BeginFrameArgs& args) { |
+void Scheduler::BeginImplFrame() { |
DCHECK_EQ(state_machine_.begin_impl_frame_state(), |
SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); |
DCHECK(!BeginImplFrameDeadlinePending()); |
DCHECK(state_machine_.HasInitializedOutputSurface()); |
- begin_impl_frame_tracker_.Start(args); |
state_machine_.OnBeginImplFrame(); |
devtools_instrumentation::DidBeginFrame(layer_tree_host_id_); |
client_->WillBeginImplFrame(begin_impl_frame_tracker_.Current()); |
@@ -515,7 +522,6 @@ void Scheduler::ScheduleBeginImplFrameDeadline() { |
begin_impl_frame_deadline_mode_ = |
state_machine_.CurrentBeginImplFrameDeadlineMode(); |
- |
base::TimeTicks deadline; |
switch (begin_impl_frame_deadline_mode_) { |
case SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE: |
@@ -697,6 +703,8 @@ scoped_refptr<base::trace_event::ConvertableToTraceFormat> Scheduler::AsValue() |
} |
void Scheduler::AsValueInto(base::trace_event::TracedValue* state) const { |
+ base::TimeTicks now = Now(); |
+ |
state->BeginDictionary("state_machine"); |
state_machine_.AsValueInto(state); |
state->EndDictionary(); |
@@ -725,9 +733,14 @@ void Scheduler::AsValueInto(base::trace_event::TracedValue* state) const { |
!begin_impl_frame_deadline_task_.IsCancelled()); |
state->SetString("inside_action", |
SchedulerStateMachine::ActionToString(inside_action_)); |
+ |
state->BeginDictionary("begin_impl_frame_args"); |
- begin_impl_frame_tracker_.AsValueInto(Now(), state); |
+ begin_impl_frame_tracker_.AsValueInto(now, state); |
state->EndDictionary(); |
+ |
+ state->SetString("begin_impl_frame_deadline_mode_", |
+ SchedulerStateMachine::BeginImplFrameDeadlineModeToString( |
+ begin_impl_frame_deadline_mode_)); |
state->EndDictionary(); |
state->BeginDictionary("compositor_timing_history"); |
@@ -740,6 +753,46 @@ void Scheduler::UpdateCompositorTimingHistoryRecordingEnabled() { |
state_machine_.HasInitializedOutputSurface() && state_machine_.visible()); |
} |
+bool Scheduler::ShouldRecoverMainLatency() const { |
+ if (!state_machine_.MainThreadIsInHighLatencyMode()) |
+ return false; |
+ |
+ if (state_machine_.impl_latency_takes_priority()) |
+ return false; |
+ |
+ return CanCommitAndActivateBeforeDeadline(); |
+} |
+ |
+bool Scheduler::ShouldRecoverImplLatency() const { |
+ if (!state_machine_.SwapThrottled()) |
+ return false; |
+ |
+ BeginFrameArgs args = |
+ begin_impl_frame_tracker_.DangerousMethodCurrentOrLast(); |
mithro-old
2015/07/06 11:58:42
This seems wrong? Why does this need the *last* Be
brianderson
2015/07/07 02:04:49
Yeah, I should have just called Current(). Latest
|
+ |
+ // The deadline may be in the past if our draw time is too long. |
+ bool frame_time_is_before_deadline = args.frame_time < args.deadline; |
+ |
+ SchedulerStateMachine::BeginImplFrameDeadlineMode |
+ next_begin_impl_frame_deadline_mode = |
+ state_machine_.CurrentBeginImplFrameDeadlineMode(); |
+ switch (next_begin_impl_frame_deadline_mode) { |
+ case SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE: |
+ return false; |
+ case SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_IMMEDIATE: |
+ return frame_time_is_before_deadline; |
+ case SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_REGULAR: |
+ return frame_time_is_before_deadline; |
+ case SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_LATE: |
+ return CanCommitAndActivateBeforeDeadline(); |
+ case SchedulerStateMachine:: |
+ BEGIN_IMPL_FRAME_DEADLINE_MODE_BLOCKED_ON_READY_TO_DRAW: |
+ return false; |
+ } |
+ NOTREACHED(); |
+ return false; |
+} |
+ |
bool Scheduler::CanCommitAndActivateBeforeDeadline() const { |
BeginFrameArgs args = |
begin_impl_frame_tracker_.DangerousMethodCurrentOrLast(); |
@@ -752,12 +805,6 @@ bool Scheduler::CanCommitAndActivateBeforeDeadline() const { |
compositor_timing_history_->CommitToReadyToActivateDurationEstimate() + |
compositor_timing_history_->ActivateDurationEstimate(); |
- TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), |
- "CanCommitAndActivateBeforeDeadline", |
- "time_left_after_drawing_ms", |
- (args.deadline - estimated_draw_time).InMillisecondsF(), "state", |
- AsValue()); |
- |
return estimated_draw_time < args.deadline; |
} |