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

Unified Diff: cc/scheduler/scheduler_state_machine.cc

Issue 16871016: cc: Use BeginFrameArgs (Closed) Base URL: http://git.chromium.org/chromium/src.git@bfargs2
Patch Set: A bit of cleanup Created 7 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_state_machine.cc
diff --git a/cc/scheduler/scheduler_state_machine.cc b/cc/scheduler/scheduler_state_machine.cc
index cb14cadf52acd3beeb3a7f91f6b7c89c8f4308f1..6e6800cb4d2b3b4cd250832e4ef817bb16ccb3c4 100644
--- a/cc/scheduler/scheduler_state_machine.cc
+++ b/cc/scheduler/scheduler_state_machine.cc
@@ -12,52 +12,57 @@ namespace cc {
SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings)
: settings_(settings),
+ output_surface_state_(OUTPUT_SURFACE_LOST),
+ begin_frame_state_(BEGIN_FRAME_STATE_IDLE),
commit_state_(COMMIT_STATE_IDLE),
+ texture_state_(LAYER_TEXTURE_STATE_UNLOCKED),
+ readback_state_(READBACK_STATE_IDLE),
+ forced_redraw_state_(FORCED_REDRAW_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),
+ begin_frame_count_(0),
+ draw_attempt_count_(0),
+ last_begin_frame_count_draw_was_called_(-1),
+ last_begin_frame_count_begin_frame_sent_to_main_thread_(-1),
+ last_draw_attempt_count_tree_activation_attempted_(-1),
+ last_draw_attempt_count_completed_tile_uploads_checked_(-1),
consecutive_failed_draws_(0),
maximum_number_of_failed_draws_before_draw_is_forced_(3),
needs_redraw_(false),
swap_used_incomplete_tile_(false),
- needs_forced_redraw_(false),
- needs_forced_redraw_after_next_commit_(false),
needs_commit_(false),
- needs_forced_commit_(false),
- expect_immediate_begin_frame_for_main_thread_(false),
main_thread_needs_layer_textures_(false),
- inside_begin_frame_(false),
+ active_tree_has_been_drawn_(false),
+ active_tree_is_null_(true),
visible_(false),
can_start_(false),
can_draw_(false),
has_pending_tree_(false),
draw_if_possible_failed_(false),
- texture_state_(LAYER_TEXTURE_STATE_UNLOCKED),
- output_surface_state_(OUTPUT_SURFACE_LOST),
did_create_and_initialize_first_output_surface_(false) {}
std::string SchedulerStateMachine::ToString() {
std::string str;
- base::StringAppendF(&str,
- "settings_.impl_side_painting = %d; ",
+ base::StringAppendF(&str, "settings_.impl_side_painting = %d; ",
settings_.impl_side_painting);
+ base::StringAppendF(&str, "output_surface_state_ = %d; ",
+ output_surface_state_);
+ base::StringAppendF(&str, "begin_frame_state_ = %d; ", begin_frame_state_);
base::StringAppendF(&str, "commit_state_ = %d; ", commit_state_);
+ base::StringAppendF(&str, "texture_state_ = %d; ", texture_state_);
+ base::StringAppendF(&str, "readback_state_ = %d; ", readback_state_);
+ base::StringAppendF(&str, "forced_redraw_state_ = %d; ",
+ forced_redraw_state_);
base::StringAppendF(&str, "commit_count_ = %d; ", commit_count_);
- base::StringAppendF(
- &str, "current_frame_number_ = %d; ", current_frame_number_);
+ base::StringAppendF(&str, "begin_frame_count_ = %d; ", begin_frame_count_);
+ base::StringAppendF(&str, "draw_attempt_count_ = %d; ", draw_attempt_count_);
+ base::StringAppendF(&str, "last_begin_frame_count_draw_was_called_ = %d; ",
+ last_begin_frame_count_draw_was_called_);
base::StringAppendF(&str,
- "last_frame_number_where_draw_was_called_ = %d; ",
- last_frame_number_where_draw_was_called_);
- base::StringAppendF(
- &str,
- "last_frame_number_where_tree_activation_attempted_ = %d; ",
- last_frame_number_where_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_draw_attempt_count_tree_activation_attempted_ = %d; ",
+ last_draw_attempt_count_tree_activation_attempted_);
+ base::StringAppendF(&str,
+ "last_draw_attempt_count_completed_tile_uploads_checked_ = %d; ",
+ last_draw_attempt_count_completed_tile_uploads_checked_);
base::StringAppendF(
&str, "consecutive_failed_draws_ = %d; ", consecutive_failed_draws_);
base::StringAppendF(
@@ -67,22 +72,10 @@ std::string SchedulerStateMachine::ToString() {
base::StringAppendF(&str, "needs_redraw_ = %d; ", needs_redraw_);
base::StringAppendF(
&str, "swap_used_incomplete_tile_ = %d; ", swap_used_incomplete_tile_);
- base::StringAppendF(
- &str, "needs_forced_redraw_ = %d; ", needs_forced_redraw_);
- base::StringAppendF(&str,
- "needs_forced_redraw_after_next_commit_ = %d; ",
- needs_forced_redraw_after_next_commit_);
base::StringAppendF(&str, "needs_commit_ = %d; ", needs_commit_);
- base::StringAppendF(
- &str, "needs_forced_commit_ = %d; ", needs_forced_commit_);
- base::StringAppendF(&str,
- "expect_immediate_begin_frame_for_main_thread_ = %d; ",
- expect_immediate_begin_frame_for_main_thread_);
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, "last_frame_time_ = %"PRId64"; ",
(last_begin_frame_args_.frame_time - base::TimeTicks())
.InMilliseconds());
@@ -96,24 +89,31 @@ 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, "texture_state_ = %d; ", texture_state_);
- base::StringAppendF(
- &str, "output_surface_state_ = %d; ", output_surface_state_);
+ base::StringAppendF(&str, "active_tree_has_been_drawn_ = %d; ",
+ active_tree_has_been_drawn_);
+ base::StringAppendF(&str, "active_tree_is_null_ = %d; ",
+ active_tree_is_null_);
return str;
}
bool SchedulerStateMachine::HasDrawnThisFrame() const {
- return current_frame_number_ == last_frame_number_where_draw_was_called_;
+ return begin_frame_count_ == last_begin_frame_count_draw_was_called_;
}
-bool SchedulerStateMachine::HasAttemptedTreeActivationThisFrame() const {
- return current_frame_number_ ==
- last_frame_number_where_tree_activation_attempted_;
+bool SchedulerStateMachine::HasSentBeginFrameToMainThreadThisFrame() const {
+ return begin_frame_count_ ==
+ last_begin_frame_count_begin_frame_sent_to_main_thread_;
}
-bool SchedulerStateMachine::HasCheckedForCompletedTileUploadsThisFrame() const {
- return current_frame_number_ ==
- last_frame_number_where_check_for_completed_tile_uploads_called_;
+bool SchedulerStateMachine::HasAttemptedTreeActivationThisDrawAttempt() const {
+ return draw_attempt_count_ ==
+ last_draw_attempt_count_tree_activation_attempted_;
+}
+
+bool SchedulerStateMachine::
+ HasCheckedForCompletedTileUploadsThisDrawAttempt() const {
+ return draw_attempt_count_ ==
+ last_draw_attempt_count_completed_tile_uploads_checked_;
}
bool SchedulerStateMachine::DrawSuspendedUntilCommit() const {
@@ -135,13 +135,39 @@ bool SchedulerStateMachine::ScheduledToDraw() const {
}
bool SchedulerStateMachine::ShouldDraw() const {
- if (needs_forced_redraw_)
+ // After a readback, make sure not to draw again until we've replaced the
+ // readback commit with a real one.
+ if (readback_state_ == READBACK_STATE_REPLACEMENT_COMMIT_PENDING ||
+ readback_state_ == READBACK_STATE_REPLACEMENT_COMMIT_ACTIVATING)
+ return false;
+
+ // Draw outside of the BeginFrame deadline for readbacks.
+ if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) {
+ DCHECK_EQ(commit_state_, COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
+ return true;
+ }
+
+ // If we've lost the output surface or draw is suspended, we want to be able
+ // to abort a draw and make forward progress to unblock the main thread.
+ if (output_surface_state_ == OUTPUT_SURFACE_LOST ||
+ DrawSuspendedUntilCommit()) {
+ return (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW ||
+ (commit_state_ == COMMIT_STATE_WAITING_FOR_ACTIVATION &&
+ !active_tree_has_been_drawn_));
+ }
+
+ // Except for the cases above, do not draw outside of the BeginFrame deadline.
+ if (begin_frame_state_ != BEGIN_FRAME_STATE_INSIDE_DEADLINE)
+ return false;
+
+ // Only handle forced redraws due to timeouts on the regular deadline.
+ if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) {
+ DCHECK_EQ(commit_state_, COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
return true;
+ }
if (!ScheduledToDraw())
return false;
- if (!inside_begin_frame_)
- return false;
if (HasDrawnThisFrame())
return false;
if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE)
@@ -150,14 +176,18 @@ bool SchedulerStateMachine::ShouldDraw() const {
}
bool SchedulerStateMachine::ShouldAttemptTreeActivation() const {
- return has_pending_tree_ && inside_begin_frame_ &&
- !HasAttemptedTreeActivationThisFrame();
+ return !HasAttemptedTreeActivationThisDrawAttempt() &&
+ has_pending_tree_ &&
+ (!can_draw_ || !visible_ ||
+ output_surface_state_ != OUTPUT_SURFACE_ACTIVE ||
+ ((active_tree_has_been_drawn_ || active_tree_is_null_) &&
+ begin_frame_state_ != BEGIN_FRAME_STATE_IDLE));
}
bool SchedulerStateMachine::ShouldCheckForCompletedTileUploads() const {
if (!settings_.impl_side_painting)
return false;
- if (HasCheckedForCompletedTileUploadsThisFrame())
+ if (HasCheckedForCompletedTileUploadsThisDrawAttempt())
return false;
return ShouldAttemptTreeActivation() || ShouldDraw() ||
@@ -179,6 +209,54 @@ bool SchedulerStateMachine::ShouldAcquireLayerTexturesForMainThread() const {
return false;
}
+bool SchedulerStateMachine::ShouldSendBeginFrameToMainThread() const {
+ if (HasSentBeginFrameToMainThreadThisFrame())
+ return false;
+
+ // Only send BeginFrame to the main thread when idle.
+ if (commit_state_ != COMMIT_STATE_IDLE)
+ return false;
+
+ // We can't accept a commit if we have a pending tree.
+ if (has_pending_tree_)
+ return false;
+
+ // We want to handle readback commits ASAP.
+ if (readback_state_ == READBACK_STATE_FORCED_COMMIT_REQUESTED)
+ return !CommitPending();
+
+ // We usually want to slave the main thread's BeginFrame to the impl thread's
+ // BeginFrame. However, if we aren't expecting a BeginFrame on the impl
+ // thread, we should send a BeginFrame to the main thread anyway to make
+ // progress.
+ // TODO(brianderson): Also allow sending BeginFrame to main thread while idle
+ // when the main thread isn't consuming user input.
+ if (begin_frame_state_ == BEGIN_FRAME_STATE_IDLE &&
+ BeginFrameNeededByImplThread())
+ return false;
+
+ // Do not send begin frame to main thread in the deadline until we have drawn.
+ // We have a train to catch!
+ if (begin_frame_state_ == BEGIN_FRAME_STATE_INSIDE_DEADLINE &&
+ !HasDrawnThisFrame())
+ return false;
+
+ // If not impl-side-painting, do not send a BeginFrame to the main thread if
+ // we haven't drawn the active tree. Otherwise, the commit overwrite the
+ // active tree before we have a chance to draw it.
+ if (!settings_.impl_side_painting &&
+ !active_tree_has_been_drawn_ &&
+ !active_tree_is_null_)
+ return false;
+
+ bool can_commit = needs_commit_ &&
+ (visible_ ||
+ forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT);
+ return can_commit &&
+ (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT ||
+ output_surface_state_ == OUTPUT_SURFACE_ACTIVE);
+}
+
SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const {
if (ShouldAcquireLayerTexturesForMainThread())
return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD;
@@ -186,11 +264,7 @@ SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const {
switch (commit_state_) {
case COMMIT_STATE_IDLE:
if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE &&
- needs_forced_redraw_)
- return ACTION_DRAW_FORCED;
- if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE &&
- needs_forced_commit_)
- // TODO(enne): Should probably drop the active tree on force commit.
+ readback_state_ == READBACK_STATE_FORCED_COMMIT_REQUESTED)
return has_pending_tree_ ? ACTION_NONE
: ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD;
if (output_surface_state_ == OUTPUT_SURFACE_LOST && can_start_)
@@ -201,16 +275,11 @@ SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const {
return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS;
if (ShouldAttemptTreeActivation())
return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED;
- if (ShouldDraw()) {
- return needs_forced_redraw_ ? ACTION_DRAW_FORCED
- : ACTION_DRAW_IF_POSSIBLE;
+ if (ShouldDraw())
+ return ACTION_DRAW_AND_SWAP_IF_POSSIBLE;
+ if (ShouldSendBeginFrameToMainThread()) {
+ return ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD;
}
- if (needs_commit_ &&
- ((visible_ && output_surface_state_ == OUTPUT_SURFACE_ACTIVE)
- || needs_forced_commit_))
- // 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_NONE;
case COMMIT_STATE_FRAME_IN_PROGRESS:
@@ -218,42 +287,47 @@ SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const {
return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS;
if (ShouldAttemptTreeActivation())
return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED;
- if (ShouldDraw()) {
- return needs_forced_redraw_ ? ACTION_DRAW_FORCED
- : ACTION_DRAW_IF_POSSIBLE;
- }
+ if (ShouldDraw())
+ return ACTION_DRAW_AND_SWAP_IF_POSSIBLE;
return ACTION_NONE;
case COMMIT_STATE_READY_TO_COMMIT:
return ACTION_COMMIT;
- case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: {
+ case COMMIT_STATE_WAITING_FOR_ACTIVATION: {
if (ShouldCheckForCompletedTileUploads())
return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS;
if (ShouldAttemptTreeActivation())
return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED;
- if (ShouldDraw() || output_surface_state_ == OUTPUT_SURFACE_LOST) {
- return needs_forced_redraw_ ? ACTION_DRAW_FORCED
- : ACTION_DRAW_IF_POSSIBLE;
+ if (ShouldDraw()) {
+ if (output_surface_state_ == OUTPUT_SURFACE_LOST ||
+ DrawSuspendedUntilCommit())
+ return ACTION_DRAW_AND_SWAP_ABORT;
+ else
+ return ACTION_DRAW_AND_SWAP_IF_POSSIBLE;
}
- // COMMIT_STATE_WAITING_FOR_FIRST_DRAW wants to enforce a draw. If
- // 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;
return ACTION_NONE;
}
- case COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW:
+ case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: {
if (ShouldCheckForCompletedTileUploads())
return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS;
if (ShouldAttemptTreeActivation())
return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED;
- if (needs_forced_redraw_)
- return ACTION_DRAW_FORCED;
+ if (ShouldDraw()) {
+ if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW)
+ return ACTION_DRAW_AND_SWAP_FORCED;
+ else if (readback_state_ ==
+ READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK)
+ return ACTION_DRAW_AND_READBACK;
+ else if (output_surface_state_ == OUTPUT_SURFACE_LOST ||
+ DrawSuspendedUntilCommit())
+ return ACTION_DRAW_AND_SWAP_ABORT;
+ else
+ return ACTION_DRAW_AND_SWAP_IF_POSSIBLE;
+ }
return ACTION_NONE;
+ }
}
NOTREACHED();
return ACTION_NONE;
@@ -265,60 +339,81 @@ void SchedulerStateMachine::UpdateState(Action action) {
return;
case ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS:
- last_frame_number_where_check_for_completed_tile_uploads_called_ =
- current_frame_number_;
+ last_draw_attempt_count_completed_tile_uploads_checked_ =
+ draw_attempt_count_;
return;
case ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED:
- last_frame_number_where_tree_activation_attempted_ =
- current_frame_number_;
+ last_draw_attempt_count_tree_activation_attempted_ =
+ draw_attempt_count_;
return;
case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD:
DCHECK(!has_pending_tree_);
- DCHECK(visible_ || needs_forced_commit_);
+ DCHECK(visible_ ||
+ readback_state_ == READBACK_STATE_FORCED_COMMIT_REQUESTED ||
+ forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT);
commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS;
needs_commit_ = false;
- needs_forced_commit_ = false;
+ if (readback_state_ == READBACK_STATE_FORCED_COMMIT_REQUESTED)
+ readback_state_ = READBACK_STATE_FORCED_COMMIT_PENDING;
+ last_begin_frame_count_begin_frame_sent_to_main_thread_ =
+ begin_frame_count_;
return;
case ACTION_COMMIT:
commit_count_++;
- if (expect_immediate_begin_frame_for_main_thread_)
- commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW;
- else
+
+ if (settings_.impl_side_painting) {
+ if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT)
+ forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION;
+ else if (readback_state_ == READBACK_STATE_FORCED_COMMIT_PENDING)
+ readback_state_ = READBACK_STATE_WAITING_FOR_ACTIVATION;
+ else if (readback_state_ == READBACK_STATE_REPLACEMENT_COMMIT_PENDING)
+ readback_state_ = READBACK_STATE_REPLACEMENT_COMMIT_ACTIVATING;
+ commit_state_ = COMMIT_STATE_WAITING_FOR_ACTIVATION;
+ } else {
+ if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT)
+ forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_DRAW;
+ else if (readback_state_ == READBACK_STATE_FORCED_COMMIT_PENDING)
+ readback_state_ = READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK;
+ else if (readback_state_ == READBACK_STATE_REPLACEMENT_COMMIT_PENDING)
+ readback_state_ = READBACK_STATE_IDLE;
commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW;
+ }
+
// When impl-side painting, we draw on activation instead of on commit.
- if (!settings_.impl_side_painting)
+ if (!settings_.impl_side_painting) {
+ active_tree_has_been_drawn_ = false;
needs_redraw_ = true;
- if (draw_if_possible_failed_)
- last_frame_number_where_draw_was_called_ = -1;
-
- if (needs_forced_redraw_after_next_commit_) {
- needs_forced_redraw_after_next_commit_ = false;
- needs_forced_redraw_ = true;
+ if (draw_if_possible_failed_)
+ last_begin_frame_count_draw_was_called_ = -1;
}
-
texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD;
return;
- case ACTION_DRAW_FORCED:
- case ACTION_DRAW_IF_POSSIBLE:
- needs_redraw_ = false;
- 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_;
- if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW) {
- DCHECK(expect_immediate_begin_frame_for_main_thread_);
+ case ACTION_DRAW_AND_SWAP_IF_POSSIBLE:
+ case ACTION_DRAW_AND_SWAP_FORCED:
+ case ACTION_DRAW_AND_READBACK:
+ case ACTION_DRAW_AND_SWAP_ABORT:
+ if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) {
+ commit_state_ = COMMIT_STATE_IDLE;
+ forced_redraw_state_ = FORCED_REDRAW_STATE_IDLE;
+ } else if (readback_state_ ==
+ READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) {
+ DCHECK(!has_pending_tree_);
commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS;
- expect_immediate_begin_frame_for_main_thread_ = false;
+ readback_state_ = READBACK_STATE_REPLACEMENT_COMMIT_PENDING;
} else if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW) {
commit_state_ = COMMIT_STATE_IDLE;
}
+ needs_redraw_ = false;
+ draw_if_possible_failed_ = false;
+ swap_used_incomplete_tile_ = false;
+ last_begin_frame_count_draw_was_called_ = begin_frame_count_;
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:
@@ -334,18 +429,37 @@ void SchedulerStateMachine::UpdateState(Action action) {
}
}
+void SchedulerStateMachine::AdvanceBeginFrameStateWhenNoActionsRemain() {
+ switch (begin_frame_state_) {
+ case BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME:
+ begin_frame_state_ = BEGIN_FRAME_STATE_DEADLINE_PENDING;
+ break;
+ case BEGIN_FRAME_STATE_INSIDE_DEADLINE:
+ begin_frame_state_ = BEGIN_FRAME_STATE_IDLE;
+ break;
+ case BEGIN_FRAME_STATE_IDLE:
+ case BEGIN_FRAME_STATE_DEADLINE_PENDING:
+ break;
+ }
+}
+
void SchedulerStateMachine::SetMainThreadNeedsLayerTextures() {
DCHECK(!main_thread_needs_layer_textures_);
DCHECK_NE(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD);
main_thread_needs_layer_textures_ = true;
}
+bool SchedulerStateMachine::BeginFrameNeededByImplThread() const {
+ return BeginFrameNeededToDrawByImplThread() ||
+ BeginFrameProactivelyNeededByImplThread();
+}
+
bool SchedulerStateMachine::BeginFrameNeededToDrawByImplThread() const {
// If we can't draw, don't tick until we are notified that we can draw again.
if (!can_draw_)
return false;
- if (needs_forced_redraw_)
+ if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW)
return true;
if (visible_ && swap_used_incomplete_tile_)
@@ -355,28 +469,49 @@ bool SchedulerStateMachine::BeginFrameNeededToDrawByImplThread() const {
output_surface_state_ == OUTPUT_SURFACE_ACTIVE;
}
-bool SchedulerStateMachine::ProactiveBeginFrameWantedByImplThread() const {
- // Do not be proactive when invisible.
+bool SchedulerStateMachine::BeginFrameProactivelyNeededByImplThread() const {
+ if (settings_.using_synchronous_renderer_compositor)
+ return false;
+
+ if (!settings_.throttle_frame_production)
+ return false;
+
if (!visible_ || output_surface_state_ != OUTPUT_SURFACE_ACTIVE)
return false;
// We should proactively request a BeginFrame if a commit or a tree activation
// is pending.
- return (needs_commit_ || needs_forced_commit_ ||
- commit_state_ != COMMIT_STATE_IDLE || has_pending_tree_);
+ return (needs_commit_ ||
+ commit_state_ != COMMIT_STATE_IDLE ||
+ has_pending_tree_);
}
-void SchedulerStateMachine::DidEnterBeginFrame(const BeginFrameArgs& args) {
- inside_begin_frame_ = true;
+void SchedulerStateMachine::OnBeginFrame(const BeginFrameArgs& args) {
+ begin_frame_count_++;
+ draw_attempt_count_++;
last_begin_frame_args_ = args;
+ begin_frame_state_ = BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME;
}
-void SchedulerStateMachine::DidLeaveBeginFrame() {
- current_frame_number_++;
- inside_begin_frame_ = false;
+bool SchedulerStateMachine::ShouldTriggerBeginFrameDeadlineEarly() const {
+ // TODO(brianderson): This should take into account multiple commit sources.
+ return begin_frame_state_ == BEGIN_FRAME_STATE_DEADLINE_PENDING &&
+ !active_tree_has_been_drawn_;
}
-void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; }
+bool SchedulerStateMachine::InsideBeginFrame() const {
+ return begin_frame_state_ != BEGIN_FRAME_STATE_IDLE;
+}
+
+void SchedulerStateMachine::OnBeginFrameDeadline() {
+ DCHECK_EQ(begin_frame_state_, BEGIN_FRAME_STATE_DEADLINE_PENDING);
+ draw_attempt_count_++;
+ begin_frame_state_ = BEGIN_FRAME_STATE_INSIDE_DEADLINE;
+}
+
+void SchedulerStateMachine::SetVisible(bool visible) {
+ visible_ = visible;
+}
void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; }
@@ -384,10 +519,6 @@ void SchedulerStateMachine::DidSwapUseIncompleteTile() {
swap_used_incomplete_tile_ = true;
}
-void SchedulerStateMachine::SetNeedsForcedRedraw() {
- needs_forced_redraw_ = true;
-}
-
void SchedulerStateMachine::DidDrawIfPossibleCompleted(bool success) {
draw_if_possible_failed_ = !success;
if (draw_if_possible_failed_) {
@@ -400,7 +531,7 @@ void SchedulerStateMachine::DidDrawIfPossibleCompleted(bool success) {
consecutive_failed_draws_ = 0;
// We need to force a draw, but it doesn't make sense to do this until
// we've committed and have new textures.
- needs_forced_redraw_after_next_commit_ = true;
+ forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_COMMIT;
}
} else {
consecutive_failed_draws_ = 0;
@@ -409,23 +540,25 @@ void SchedulerStateMachine::DidDrawIfPossibleCompleted(bool success) {
void SchedulerStateMachine::SetNeedsCommit() { needs_commit_ = true; }
-void SchedulerStateMachine::SetNeedsForcedCommit() {
- needs_forced_commit_ = true;
- expect_immediate_begin_frame_for_main_thread_ = true;
+void SchedulerStateMachine::SetNeedsForcedCommitForReadback() {
+ DCHECK_EQ(readback_state_, READBACK_STATE_IDLE);
+ if (commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS)
+ readback_state_ = READBACK_STATE_FORCED_COMMIT_PENDING;
+ else
+ readback_state_ = READBACK_STATE_FORCED_COMMIT_REQUESTED;
}
void SchedulerStateMachine::FinishCommit() {
DCHECK(commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS ||
- (expect_immediate_begin_frame_for_main_thread_ &&
- commit_state_ != COMMIT_STATE_IDLE))
+ readback_state_ == READBACK_STATE_FORCED_COMMIT_PENDING)
<< ToString();
commit_state_ = COMMIT_STATE_READY_TO_COMMIT;
}
void SchedulerStateMachine::BeginFrameAbortedByMainThread() {
- DCHECK_EQ(commit_state_, COMMIT_STATE_FRAME_IN_PROGRESS);
- if (expect_immediate_begin_frame_for_main_thread_) {
- expect_immediate_begin_frame_for_main_thread_ = false;
+ DCHECK_EQ(commit_state_, COMMIT_STATE_FRAME_IN_PROGRESS) << ToString();
+ if (readback_state_ == READBACK_STATE_FORCED_COMMIT_REQUESTED) {
+ readback_state_ = READBACK_STATE_IDLE;
} else {
commit_state_ = COMMIT_STATE_IDLE;
SetNeedsCommit();
@@ -439,11 +572,37 @@ void SchedulerStateMachine::DidLoseOutputSurface() {
output_surface_state_ = OUTPUT_SURFACE_LOST;
}
-void SchedulerStateMachine::SetHasPendingTree(bool has_pending_tree) {
+void SchedulerStateMachine::SetHasTrees(bool has_pending_tree,
+ bool active_tree_is_null) {
+ active_tree_is_null_ = active_tree_is_null;
+ if (has_pending_tree_ && !has_pending_tree) {
+ // This is a new activation.
+ draw_attempt_count_++;
+ active_tree_has_been_drawn_ = false;
+
+ if (draw_if_possible_failed_)
+ last_begin_frame_count_draw_was_called_ = -1;
+
+ DCHECK_EQ(COMMIT_STATE_WAITING_FOR_ACTIVATION, commit_state_);
+ if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION) {
+ commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW;
+ forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_DRAW;
+ } else if (readback_state_ == READBACK_STATE_WAITING_FOR_ACTIVATION) {
+ commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW;
+ readback_state_ = READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK;
+ } else {
+ commit_state_ = COMMIT_STATE_IDLE;
+ if (readback_state_ == READBACK_STATE_REPLACEMENT_COMMIT_ACTIVATING)
+ readback_state_ = READBACK_STATE_IDLE;
+ }
+ }
+
has_pending_tree_ = has_pending_tree;
}
-void SchedulerStateMachine::SetCanDraw(bool can) { can_draw_ = can; }
+void SchedulerStateMachine::SetCanDraw(bool can_draw) {
+ can_draw_ = can_draw;
+}
void SchedulerStateMachine::DidCreateAndInitializeOutputSurface() {
DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_CREATING);

Powered by Google App Engine
This is Rietveld 408576698