Index: cc/scheduler/scheduler_state_machine.cc |
diff --git a/cc/scheduler/scheduler_state_machine.cc b/cc/scheduler/scheduler_state_machine.cc |
index 2fbeca2d8a992d87cd118a09a78eeb5db8b61d3b..fb602609f2d4cb7cf72313149dd2ab8ef8ccce1a 100644 |
--- a/cc/scheduler/scheduler_state_machine.cc |
+++ b/cc/scheduler/scheduler_state_machine.cc |
@@ -35,6 +35,8 @@ SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) |
consecutive_checkerboard_animations_(0), |
max_pending_swaps_(1), |
pending_swaps_(0), |
+ swaps_are_likely_high_latency_(false), |
+ was_swap_throttled_on_begin_impl_frame_(false), |
needs_redraw_(false), |
needs_animate_(false), |
needs_prepare_tiles_(false), |
@@ -48,7 +50,7 @@ SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) |
did_create_and_initialize_first_output_surface_(false), |
impl_latency_takes_priority_(false), |
skip_next_begin_main_frame_to_reduce_latency_(false), |
- skip_begin_main_frame_to_reduce_latency_(false), |
+ skip_next_swap_to_reduce_latency_(false), |
continuous_painting_(false), |
children_need_begin_frames_(false), |
defer_commits_(false), |
@@ -238,8 +240,6 @@ void SchedulerStateMachine::AsValueInto( |
impl_latency_takes_priority_); |
state->SetBoolean("main_thread_is_in_high_latency_mode", |
MainThreadIsInHighLatencyMode()); |
- state->SetBoolean("skip_begin_main_frame_to_reduce_latency", |
- skip_begin_main_frame_to_reduce_latency_); |
state->SetBoolean("skip_next_begin_main_frame_to_reduce_latency", |
skip_next_begin_main_frame_to_reduce_latency_); |
state->SetBoolean("continuous_painting", continuous_painting_); |
@@ -345,6 +345,10 @@ bool SchedulerStateMachine::ShouldDraw() const { |
if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) |
return false; |
+ // We are intentionally skipping this swap to reduce our latency. |
+ if (skip_next_swap_to_reduce_latency_) |
+ return false; |
+ |
// Only handle forced redraws due to timeouts on the regular deadline. |
if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) |
return true; |
@@ -447,7 +451,7 @@ bool SchedulerStateMachine::ShouldSendBeginMainFrame() const { |
if (pending_swaps_ >= max_pending_swaps_ && !just_swapped_in_deadline) |
return false; |
- if (skip_begin_main_frame_to_reduce_latency_) |
+ if (skip_next_begin_main_frame_to_reduce_latency_) |
return false; |
return true; |
@@ -727,6 +731,21 @@ void SchedulerStateMachine::SetSkipNextBeginMainFrameToReduceLatency() { |
skip_next_begin_main_frame_to_reduce_latency_ = true; |
} |
+void SchedulerStateMachine::SetSkipNextSwapToReduceLatency() { |
+ TRACE_EVENT_INSTANT0("cc", "Scheduler: SetSkipNextSwapToReduceLatency", |
+ TRACE_EVENT_SCOPE_THREAD); |
+ // We need to skip both the BeginMainFrame and swap to make sure we |
+ // don't keep stuffing the pipeline. |
+ skip_next_swap_to_reduce_latency_ = true; |
+ skip_next_begin_main_frame_to_reduce_latency_ = true; |
+ |
+ // If there are no swap ack's pending to update swaps_are_likely_high_latency |
+ // later, reset it now. |
+ // TODO(brianderson): A unittest that fails without this. |
+ if (!pending_swaps_) |
sunnyps
2015/05/21 23:42:23
nit: Don't use boolean operators on numeric types.
brianderson
2015/05/22 01:12:53
Done.
|
+ swaps_are_likely_high_latency_ = false; |
+} |
+ |
bool SchedulerStateMachine::BeginFrameRequiredForChildren() const { |
return children_need_begin_frames_; |
} |
@@ -834,9 +853,13 @@ void SchedulerStateMachine::OnBeginImplFrame() { |
if (prepare_tiles_funnel_ > 0) |
prepare_tiles_funnel_--; |
- skip_begin_main_frame_to_reduce_latency_ = |
- skip_next_begin_main_frame_to_reduce_latency_; |
+ was_swap_throttled_on_begin_impl_frame_ = |
+ pending_swaps_ >= max_pending_swaps_; |
+ swaps_are_likely_high_latency_ = |
+ swaps_are_likely_high_latency_ || was_swap_throttled_on_begin_impl_frame_; |
+ |
skip_next_begin_main_frame_to_reduce_latency_ = false; |
+ skip_next_swap_to_reduce_latency_ = false; |
} |
void SchedulerStateMachine::OnBeginImplFrameDeadlinePending() { |
@@ -882,7 +905,6 @@ SchedulerStateMachine::CurrentBeginImplFrameDeadlineMode() const { |
bool SchedulerStateMachine::ShouldTriggerBeginImplFrameDeadlineImmediately() |
const { |
- // TODO(brianderson): This should take into account multiple commit sources. |
if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME) |
return false; |
@@ -890,6 +912,11 @@ bool SchedulerStateMachine::ShouldTriggerBeginImplFrameDeadlineImmediately() |
if (PendingActivationsShouldBeForced() && !has_pending_tree_) |
return true; |
+ // We aren't going to draw in the deadline if we want to reduce our latency, |
+ // so we might as well trigger the deadline immediately. |
+ if (skip_next_swap_to_reduce_latency_) |
+ return true; |
+ |
// SwapAck throttle the deadline since we wont draw and swap anyway. |
if (pending_swaps_ >= max_pending_swaps_) |
return false; |
@@ -993,6 +1020,11 @@ void SchedulerStateMachine::DidSwapBuffers() { |
void SchedulerStateMachine::DidSwapBuffersComplete() { |
DCHECK_GT(pending_swaps_, 0); |
pending_swaps_--; |
+ |
+ // If we just skipped a swap, assume the attempt to reduce latency |
+ // was successful. |
+ swaps_are_likely_high_latency_ = was_swap_throttled_on_begin_impl_frame_ && |
+ !skip_next_swap_to_reduce_latency_; |
} |
void SchedulerStateMachine::SetImplLatencyTakesPriority( |