Index: cc/scheduler/scheduler_state_machine.cc |
diff --git a/cc/scheduler/scheduler_state_machine.cc b/cc/scheduler/scheduler_state_machine.cc |
index 4a9a2e0991914bfea1843ceea75f23397ea56d63..c50272d02af5a60a2261d945aa6a8fb8c2f3e12e 100644 |
--- a/cc/scheduler/scheduler_state_machine.cc |
+++ b/cc/scheduler/scheduler_state_machine.cc |
@@ -60,7 +60,8 @@ SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) |
last_commit_had_no_updates_(false), |
wait_for_ready_to_draw_(false), |
did_draw_in_last_frame_(false), |
- did_submit_in_last_frame_(false) {} |
+ did_submit_in_last_frame_(false), |
+ begin_frame_allows_latency_optimizations_(true) {} |
const char* SchedulerStateMachine::CompositorFrameSinkStateToString( |
CompositorFrameSinkState state) { |
@@ -374,13 +375,34 @@ bool SchedulerStateMachine::ShouldDraw() const { |
if (settings_.commit_to_active_tree && CommitPending()) |
return false; |
- // Only handle forced redraws due to timeouts on the regular deadline. |
- if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) |
+ // Only handle forced redraws due to timeouts on the regular deadline and |
+ // (temporarily) for |!begin_frame_allows_latency_optimizations_|. |
+ if (ShouldForceDraw()) |
return true; |
return needs_redraw_; |
} |
+bool SchedulerStateMachine::ShouldForceDraw() const { |
+ // Browser compositor doesn't support forced draws. |
+ if (settings_.commit_to_active_tree) |
+ return false; |
+ |
+ if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) |
+ return true; |
+ |
+ // |!begin_frame_allows_latency_optimizations_| is typically used with long |
+ // deadlines, for which we depend on a timely acknowledgment of the BeginFrame |
+ // in the browser. Since we currently don't have a unified acknowledgment for |
+ // unsuccessful draws, we force a draw and wait for surface damage in the |
+ // browser's DisplayScheduler. |
+ // TODO(eseckler): Remove once we have unified BeginFrame acknowledgments. |
+ if (!begin_frame_allows_latency_optimizations_) |
+ return true; |
+ |
+ return false; |
+} |
+ |
bool SchedulerStateMachine::ShouldActivatePendingTree() const { |
// There is nothing to activate. |
if (!has_pending_tree_) |
@@ -554,7 +576,7 @@ SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { |
if (ShouldDraw()) { |
if (PendingDrawsShouldBeAborted()) |
return ACTION_DRAW_ABORT; |
- else if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) |
+ else if (ShouldForceDraw()) |
return ACTION_DRAW_FORCED; |
else |
return ACTION_DRAW_IF_POSSIBLE; |
@@ -767,6 +789,21 @@ void SchedulerStateMachine::SetDeferCommits(bool defer_commits) { |
defer_commits_ = defer_commits; |
} |
+void SchedulerStateMachine::SetBeginFrameAllowsLatencyOptimizations( |
+ bool allow_latency_optimizations) { |
+ // In this mode, we ensure that we don't skip the BeginFrame/BeginMainFrame |
+ // and that we don't prioritize impl thread latency. Thus, we first give the |
+ // main thread a chance to produce updates, and only if it doesn't (or doesn't |
+ // respond in time for the deadline), we produce an impl frame. |
+ |
+ // |!allow_latency_optimizations| is often used in combination with long or |
+ // infinite BeginFrame deadlines. To respond timely, we rely on triggering the |
+ // BeginFrame deadline immediately if the main frame has no updates or as soon |
+ // as it was activated (see ShouldTriggerBeginImplFrameDeadlineImmediately()). |
+ |
+ begin_frame_allows_latency_optimizations_ = allow_latency_optimizations; |
+} |
+ |
// These are the cases where we require a BeginFrame message to make progress |
// on requested actions. |
bool SchedulerStateMachine::BeginFrameRequiredForAction() const { |
@@ -882,7 +919,7 @@ SchedulerStateMachine::CurrentBeginImplFrameDeadlineMode() const { |
return BEGIN_IMPL_FRAME_DEADLINE_MODE_BLOCKED_ON_READY_TO_DRAW; |
} else if (ShouldTriggerBeginImplFrameDeadlineImmediately()) { |
return BEGIN_IMPL_FRAME_DEADLINE_MODE_IMMEDIATE; |
- } else if (needs_redraw_) { |
+ } else if (needs_redraw_ && begin_frame_allows_latency_optimizations_) { |
// We have an animation or fast input path on the impl thread that wants |
// to draw, so don't wait too long for a new active tree. |
return BEGIN_IMPL_FRAME_DEADLINE_MODE_REGULAR; |
@@ -907,17 +944,19 @@ bool SchedulerStateMachine::ShouldTriggerBeginImplFrameDeadlineImmediately() |
if (active_tree_needs_first_draw_) |
return true; |
- if (!needs_redraw_) |
- return false; |
- |
- // This is used to prioritize impl-thread draws when the main thread isn't |
- // producing anything, e.g., after an aborted commit. We also check that we |
- // don't have a pending tree -- otherwise we should give it a chance to |
- // activate. |
+ // Immediately respond to the BeginFrame if the main frame isn't producing |
+ // anything, e.g., after an aborted commit. We also check that we don't have a |
+ // pending tree -- otherwise we should give it a chance to activate. We |
+ // trigger an immediate deadline even if the impl thread doesn't want to draw |
+ // anything either, because we don't want to stall the BeginFrame |
+ // acknowledgment unnecessarily. |
// TODO(skyostil): Revisit this when we have more accurate deadline estimates. |
if (!CommitPending() && !has_pending_tree_) |
return true; |
+ if (!needs_redraw_) |
+ return false; |
+ |
// Prioritize impl-thread draws in ImplLatencyTakesPriority mode. |
if (ImplLatencyTakesPriority()) |
return true; |
@@ -1006,6 +1045,10 @@ void SchedulerStateMachine::SetCriticalBeginMainFrameToActivateIsFast( |
} |
bool SchedulerStateMachine::ImplLatencyTakesPriority() const { |
+ // Wait for main frame if requested by BeginFrameArgs. |
+ if (!begin_frame_allows_latency_optimizations_) |
+ return false; |
+ |
// Attempt to synchronize with the main thread if it has a scroll listener |
// and is fast. |
if (ScrollHandlerState::SCROLL_AFFECTS_SCROLL_HANDLER == |