Chromium Code Reviews| Index: cc/scheduler/scheduler_state_machine.cc |
| diff --git a/cc/scheduler/scheduler_state_machine.cc b/cc/scheduler/scheduler_state_machine.cc |
| index 954ad1c04d9cee337b1068d670594bf36edd6b2b..9e43ef434dbed9294b5c5d4aaf66dd28827ad1c9 100644 |
| --- a/cc/scheduler/scheduler_state_machine.cc |
| +++ b/cc/scheduler/scheduler_state_machine.cc |
| @@ -15,9 +15,10 @@ SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) |
| commit_state_(COMMIT_STATE_IDLE), |
| commit_count_(0), |
| current_frame_number_(0), |
| - last_frame_number_where_draw_was_called_(-1), |
| - last_frame_number_where_tree_activation_attempted_(-1), |
| - last_frame_number_where_check_for_completed_tile_uploads_called_(-1), |
| + current_frame_attempt_(0), |
| + last_frame_attempt_draw_was_called_(-1), |
| + last_frame_attempt_tree_activation_attempted_(-1), |
| + last_frame_attempt_check_for_completed_tile_uploads_called_(-1), |
| consecutive_failed_draws_(0), |
| maximum_number_of_failed_draws_before_draw_is_forced_(3), |
| needs_redraw_(false), |
| @@ -28,7 +29,8 @@ SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) |
| needs_forced_commit_(false), |
| expect_immediate_begin_frame_for_main_thread_(false), |
| main_thread_needs_layer_textures_(false), |
| - inside_begin_frame_(false), |
| + begin_frame_state_(BEGIN_FRAME_IDLE), |
| + active_tree_has_been_drawn_(true), |
|
Sami
2013/06/14 15:59:20
Should this be false?
brianderson
2013/06/14 18:42:36
If the active tree has been drawn, then this patch
|
| visible_(false), |
| can_start_(false), |
| can_draw_(false), |
| @@ -45,19 +47,21 @@ std::string SchedulerStateMachine::ToString() { |
| settings_.impl_side_painting); |
| base::StringAppendF(&str, "commit_state_ = %d; ", commit_state_); |
| base::StringAppendF(&str, "commit_count_ = %d; ", commit_count_); |
| - base::StringAppendF( |
| - &str, "current_frame_number_ = %d; ", current_frame_number_); |
| + base::StringAppendF(&str, "current_frame_number_ = %d; ", |
| + current_frame_number_); |
| + base::StringAppendF(&str, "current_frame_attempt_ = %d; ", |
| + current_frame_attempt_); |
| base::StringAppendF(&str, |
| - "last_frame_number_where_draw_was_called_ = %d; ", |
| - last_frame_number_where_draw_was_called_); |
| + "last_frame_attempt_draw_was_called_ = %d; ", |
| + last_frame_attempt_draw_was_called_); |
| base::StringAppendF( |
| &str, |
| - "last_frame_number_where_tree_activation_attempted_ = %d; ", |
| - last_frame_number_where_tree_activation_attempted_); |
| + "last_frame_attempt_tree_activation_attempted_ = %d; ", |
| + last_frame_attempt_tree_activation_attempted_); |
| base::StringAppendF( |
| &str, |
| - "last_frame_number_where_check_for_completed_tile_uploads_called_ = %d; ", |
| - last_frame_number_where_check_for_completed_tile_uploads_called_); |
| + "last_frame_attempt_check_for_completed_tile_uploads_called_ = %d; ", |
| + last_frame_attempt_check_for_completed_tile_uploads_called_); |
| base::StringAppendF( |
| &str, "consecutive_failed_draws_ = %d; ", consecutive_failed_draws_); |
| base::StringAppendF( |
| @@ -81,8 +85,7 @@ std::string SchedulerStateMachine::ToString() { |
| base::StringAppendF(&str, |
| "main_thread_needs_layer_textures_ = %d; ", |
| main_thread_needs_layer_textures_); |
| - base::StringAppendF(&str, "inside_begin_frame_ = %d; ", |
| - inside_begin_frame_); |
| + base::StringAppendF(&str, "begin_frame_state_ = %d; ", begin_frame_state_); |
| base::StringAppendF(&str, "last_frame_time_ = %"PRId64"; ", |
| (last_begin_frame_args_.frame_time() - base::TimeTicks()) |
| .InMilliseconds()); |
| @@ -96,6 +99,8 @@ std::string SchedulerStateMachine::ToString() { |
| base::StringAppendF( |
| &str, "draw_if_possible_failed_ = %d; ", draw_if_possible_failed_); |
| base::StringAppendF(&str, "has_pending_tree_ = %d; ", has_pending_tree_); |
| + base::StringAppendF(&str, "active_tree_has_been_drawn_ = %d; ", |
| + active_tree_has_been_drawn_); |
| base::StringAppendF(&str, "texture_state_ = %d; ", texture_state_); |
| base::StringAppendF( |
| &str, "output_surface_state_ = %d; ", output_surface_state_); |
| @@ -103,17 +108,17 @@ std::string SchedulerStateMachine::ToString() { |
| } |
| bool SchedulerStateMachine::HasDrawnThisFrame() const { |
| - return current_frame_number_ == last_frame_number_where_draw_was_called_; |
| + return current_frame_attempt_ == last_frame_attempt_draw_was_called_; |
|
brianderson
2013/06/14 18:42:36
I should change back to use current_frame_number s
|
| } |
| bool SchedulerStateMachine::HasAttemptedTreeActivationThisFrame() const { |
|
ajuma
2013/06/14 15:22:32
Calling this HasAttemptedTreeActivationThisFrameAt
brianderson
2013/06/14 18:42:36
Will do.
|
| - return current_frame_number_ == |
| - last_frame_number_where_tree_activation_attempted_; |
| + return current_frame_attempt_ == |
| + last_frame_attempt_tree_activation_attempted_; |
| } |
| bool SchedulerStateMachine::HasCheckedForCompletedTileUploadsThisFrame() const { |
| - return current_frame_number_ == |
| - last_frame_number_where_check_for_completed_tile_uploads_called_; |
| + return current_frame_attempt_ == |
| + last_frame_attempt_check_for_completed_tile_uploads_called_; |
| } |
| bool SchedulerStateMachine::DrawSuspendedUntilCommit() const { |
| @@ -140,7 +145,7 @@ bool SchedulerStateMachine::ShouldDraw() const { |
| if (!ScheduledToDraw()) |
| return false; |
| - if (!inside_begin_frame_) |
| + if (begin_frame_state_ != BEGIN_FRAME_DRAWING) |
| return false; |
| if (HasDrawnThisFrame()) |
| return false; |
| @@ -150,7 +155,11 @@ bool SchedulerStateMachine::ShouldDraw() const { |
| } |
| bool SchedulerStateMachine::ShouldAttemptTreeActivation() const { |
| - return has_pending_tree_ && inside_begin_frame_ && |
| + return active_tree_has_been_drawn_ && |
| + has_pending_tree_ && |
| + (begin_frame_state_ == BEGIN_FRAME_STARTING || |
| + begin_frame_state_ == BEGIN_FRAME_WAITING || |
| + begin_frame_state_ == BEGIN_FRAME_DRAWING) && |
| !HasAttemptedTreeActivationThisFrame(); |
| } |
| @@ -207,10 +216,11 @@ SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { |
| } |
| if (needs_commit_ && |
| ((visible_ && output_surface_state_ == OUTPUT_SURFACE_ACTIVE) |
| - || needs_forced_commit_)) |
| + || needs_forced_commit_) && |
| + !has_pending_tree_ && |
| + begin_frame_state_ == BEGIN_FRAME_STARTING) |
| // TODO(enne): Should probably drop the active tree on force commit. |
| - return has_pending_tree_ ? ACTION_NONE |
| - : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; |
| + return ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; |
| return ACTION_NONE; |
| case COMMIT_STATE_FRAME_IN_PROGRESS: |
| @@ -240,9 +250,9 @@ SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { |
| // can_draw_ is false or textures are not available, proceed to the next |
| // step (similar as in COMMIT_STATE_IDLE). |
| bool can_commit = visible_ || needs_forced_commit_; |
| - if (needs_commit_ && can_commit && DrawSuspendedUntilCommit()) |
| - return has_pending_tree_ ? ACTION_NONE |
| - : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; |
| + if (needs_commit_ && can_commit && DrawSuspendedUntilCommit() && |
| + !has_pending_tree_ && begin_frame_state_ == BEGIN_FRAME_STARTING) |
| + return ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; |
| return ACTION_NONE; |
| } |
| @@ -262,16 +272,20 @@ SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { |
| void SchedulerStateMachine::UpdateState(Action action) { |
| switch (action) { |
| case ACTION_NONE: |
| + if (begin_frame_state_ == BEGIN_FRAME_STARTING) |
| + begin_frame_state_ = BEGIN_FRAME_WAITING; |
| + if (begin_frame_state_ == BEGIN_FRAME_DRAWING) |
| + begin_frame_state_ = BEGIN_FRAME_IDLE; |
| return; |
| case ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS: |
| - last_frame_number_where_check_for_completed_tile_uploads_called_ = |
| - current_frame_number_; |
| + last_frame_attempt_check_for_completed_tile_uploads_called_ = |
| + current_frame_attempt_; |
| return; |
| case ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED: |
| - last_frame_number_where_tree_activation_attempted_ = |
| - current_frame_number_; |
| + last_frame_attempt_tree_activation_attempted_ = |
| + current_frame_attempt_; |
| return; |
| case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: |
| @@ -292,7 +306,7 @@ void SchedulerStateMachine::UpdateState(Action action) { |
| if (!settings_.impl_side_painting) |
| needs_redraw_ = true; |
| if (draw_if_possible_failed_) |
| - last_frame_number_where_draw_was_called_ = -1; |
| + last_frame_attempt_draw_was_called_ = -1; |
| if (needs_forced_redraw_after_next_commit_) { |
| needs_forced_redraw_after_next_commit_ = false; |
| @@ -308,8 +322,7 @@ void SchedulerStateMachine::UpdateState(Action action) { |
| needs_forced_redraw_ = false; |
| draw_if_possible_failed_ = false; |
| swap_used_incomplete_tile_ = false; |
| - if (inside_begin_frame_) |
| - last_frame_number_where_draw_was_called_ = current_frame_number_; |
| + last_frame_attempt_draw_was_called_ = current_frame_attempt_; |
| if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW) { |
| DCHECK(expect_immediate_begin_frame_for_main_thread_); |
| commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; |
| @@ -319,6 +332,7 @@ void SchedulerStateMachine::UpdateState(Action action) { |
| } |
| if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) |
| texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; |
| + active_tree_has_been_drawn_ = true; |
| return; |
| case ACTION_BEGIN_OUTPUT_SURFACE_CREATION: |
| @@ -367,14 +381,20 @@ bool SchedulerStateMachine::BeginFrameNeededByImplThread() const { |
| output_surface_state_ == OUTPUT_SURFACE_ACTIVE; |
| } |
| -void SchedulerStateMachine::DidEnterBeginFrame(BeginFrameArgs args) { |
| - inside_begin_frame_ = true; |
| +void SchedulerStateMachine::StartBeginFrame(BeginFrameArgs args) { |
| + current_frame_number_++; |
| + current_frame_attempt_++; |
| last_begin_frame_args_ = args; |
| + if (active_tree_has_been_drawn_ && base::TimeTicks::Now() < args.deadline()) |
| + begin_frame_state_ = BEGIN_FRAME_STARTING; |
| + else |
| + begin_frame_state_ = BEGIN_FRAME_DRAWING; |
| } |
| -void SchedulerStateMachine::DidLeaveBeginFrame() { |
| - current_frame_number_++; |
| - inside_begin_frame_ = false; |
| +void SchedulerStateMachine::OnBeginFrameDeadline() { |
| + current_frame_attempt_++; |
| + if (begin_frame_state_ == BEGIN_FRAME_WAITING) |
| + begin_frame_state_ = BEGIN_FRAME_DRAWING; |
|
Sami
2013/06/14 15:59:20
Let me see if I got this right:
1. BeginFrame =>
brianderson
2013/06/14 18:42:36
Almost:
2.a Main thread processing starts => BEGIN
|
| } |
| void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } |
| @@ -441,6 +461,20 @@ void SchedulerStateMachine::DidLoseOutputSurface() { |
| } |
| void SchedulerStateMachine::SetHasPendingTree(bool has_pending_tree) { |
| + if (has_pending_tree_ && !has_pending_tree) { |
| + // This is a new activation. |
| + current_frame_attempt_++; |
| + active_tree_has_been_drawn_ = false; |
| + if (begin_frame_state_ == BEGIN_FRAME_STARTING) { |
| + begin_frame_state_ = BEGIN_FRAME_DRAWING; |
| + } else if (begin_frame_state_ == BEGIN_FRAME_WAITING) { |
| + if (base::TimeTicks::Now() < last_begin_frame_args_.deadline()) |
| + begin_frame_state_ = BEGIN_FRAME_DRAWING; |
| + else |
| + begin_frame_state_ = BEGIN_FRAME_IDLE; |
| + } |
| + } |
| + |
| has_pending_tree_ = has_pending_tree; |
| } |