Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Unified Diff: cc/scheduler/scheduler.cc

Issue 1133673004: cc: Heuristic for Renderer latency recovery (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Better names and durations Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/scheduler/scheduler.cc
diff --git a/cc/scheduler/scheduler.cc b/cc/scheduler/scheduler.cc
index cd0d37ea2a81c32d1d37d6698b3cf04c296d6e47..647340af077e7b4e3185e5b13175f92dfaa79f19 100644
--- a/cc/scheduler/scheduler.cc
+++ b/cc/scheduler/scheduler.cc
@@ -460,10 +460,15 @@ void Scheduler::BeginImplFrameWithDeadline(const BeginFrameArgs& args) {
BeginFrameArgs adjusted_args = args;
adjusted_args.deadline -= compositor_timing_history_->DrawDurationEstimate();
- if (!state_machine_.impl_latency_takes_priority() &&
- main_thread_is_in_high_latency_mode &&
- CanCommitAndActivateBeforeDeadline()) {
+ if (ShouldRecoverMainLatency(adjusted_args)) {
+ TRACE_EVENT_INSTANT0("cc", "SkipBeginMainFrameToReduceLatency",
+ TRACE_EVENT_SCOPE_THREAD);
state_machine_.SetSkipNextBeginMainFrameToReduceLatency();
+ } else if (ShouldRecoverImplLatency(adjusted_args)) {
+ TRACE_EVENT_INSTANT0("cc", "SkipBeginImplFrameToReduceLatency",
+ TRACE_EVENT_SCOPE_THREAD);
+ frame_source_->DidFinishFrame(begin_retro_frame_args_.size());
+ return;
}
BeginImplFrame(adjusted_args);
@@ -515,7 +520,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 +701,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 +731,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,10 +751,45 @@ void Scheduler::UpdateCompositorTimingHistoryRecordingEnabled() {
state_machine_.HasInitializedOutputSurface() && state_machine_.visible());
}
-bool Scheduler::CanCommitAndActivateBeforeDeadline() const {
- BeginFrameArgs args =
- begin_impl_frame_tracker_.DangerousMethodCurrentOrLast();
+bool Scheduler::ShouldRecoverMainLatency(const BeginFrameArgs& args) const {
+ if (!state_machine_.MainThreadIsInHighLatencyMode())
+ return false;
+
+ if (state_machine_.impl_latency_takes_priority())
sunnyps 2015/07/08 22:37:12 Might be better to check if deadline mode != LATE.
sunnyps 2015/07/08 22:40:07 I should clarify what I mean here: we should check
brianderson 2015/07/09 01:28:11 We might not wait for the commit because active_tr
+ return false;
+
+ return CanCommitAndActivateBeforeDeadline(args);
+}
+
+bool Scheduler::ShouldRecoverImplLatency(const BeginFrameArgs& args) const {
+ if (!state_machine_.SwapThrottled())
+ return false;
+ // 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(args);
+ case SchedulerStateMachine::
+ BEGIN_IMPL_FRAME_DEADLINE_MODE_BLOCKED_ON_READY_TO_DRAW:
sunnyps 2015/07/08 22:37:12 Would be great if we had comments explaining each
brianderson 2015/07/09 01:28:11 In writing the comments, I realized I can't rely d
sunnyps 2015/07/09 23:44:30 Oh yeah! Nice catch.
+ return false;
+ }
+ NOTREACHED();
+ return false;
+}
+
+bool Scheduler::CanCommitAndActivateBeforeDeadline(
+ const BeginFrameArgs& args) const {
// Check if the main thread computation and commit can be finished before the
// impl thread's deadline.
base::TimeTicks estimated_draw_time =
@@ -752,12 +798,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;
}

Powered by Google App Engine
This is Rietveld 408576698