| Index: cc/scheduler/scheduler_state_machine.cc
|
| diff --git a/cc/scheduler/scheduler_state_machine.cc b/cc/scheduler/scheduler_state_machine.cc
|
| index 0b6383af5490d11804cbca162dff256b27af503a..95cb5bc0296467a5849900fe4d37c72fe6a8fbd5 100644
|
| --- a/cc/scheduler/scheduler_state_machine.cc
|
| +++ b/cc/scheduler/scheduler_state_machine.cc
|
| @@ -8,27 +8,39 @@
|
| #include "base/logging.h"
|
| #include "base/strings/stringprintf.h"
|
|
|
| +
|
| +class DEVNULL {};
|
| +template <typename A>
|
| +DEVNULL& operator <<(DEVNULL &d, A a) { return d; }
|
| +//static DEVNULL gDevNull;
|
| +//#undef VLOG
|
| +//#define VLOG(x) gDevNull
|
| +
|
| namespace cc {
|
|
|
| SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings)
|
| : settings_(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),
|
| + begin_frame_count_(0),
|
| + begin_frame_deadline_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),
|
| + readback_state_(READBACK_STATE_IDLE),
|
| + forced_redraw_state_(FORCED_REDRAW_STATE_IDLE),
|
| 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),
|
| + begin_frame_state_(BEGIN_FRAME_STATE_IDLE),
|
| + commit_tree_has_been_drawn_(true),
|
| + active_tree_has_been_drawn_(false),
|
| + active_tree_is_null_(true),
|
| visible_(false),
|
| can_start_(false),
|
| can_draw_(false),
|
| @@ -45,19 +57,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, "begin_frame_count_ = %d; ",
|
| + begin_frame_count_);
|
| + base::StringAppendF(&str, "draw_attempt_count_ = %d; ",
|
| + draw_attempt_count_);
|
| base::StringAppendF(&str,
|
| - "last_frame_number_where_draw_was_called_ = %d; ",
|
| - last_frame_number_where_draw_was_called_);
|
| + "last_begin_frame_count_draw_was_called_ = %d; ",
|
| + last_begin_frame_count_draw_was_called_);
|
| base::StringAppendF(
|
| &str,
|
| - "last_frame_number_where_tree_activation_attempted_ = %d; ",
|
| - last_frame_number_where_tree_activation_attempted_);
|
| + "last_draw_attempt_count_tree_activation_attempted_ = %d; ",
|
| + last_draw_attempt_count_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_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 +81,15 @@ 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, "readback_state_ = %d; ", readback_state_);
|
| base::StringAppendF(&str,
|
| - "needs_forced_redraw_after_next_commit_ = %d; ",
|
| - needs_forced_redraw_after_next_commit_);
|
| + "forced_redraw_state_ = %d; ",
|
| + forced_redraw_state_);
|
| 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, "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 +103,12 @@ 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, "commit_tree_has_been_drawn_ = %d; ",
|
| + commit_tree_has_been_drawn_);
|
| + 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_);
|
| base::StringAppendF(&str, "texture_state_ = %d; ", texture_state_);
|
| base::StringAppendF(
|
| &str, "output_surface_state_ = %d; ", output_surface_state_);
|
| @@ -103,17 +116,23 @@ std::string SchedulerStateMachine::ToString() {
|
| }
|
|
|
| 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,12 +154,28 @@ bool SchedulerStateMachine::ScheduledToDraw() const {
|
| }
|
|
|
| bool SchedulerStateMachine::ShouldDraw() const {
|
| - if (needs_forced_redraw_)
|
| - return true;
|
| + // 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;
|
|
|
| - if (!ScheduledToDraw())
|
| + // Only draw outside of the BeginFrame deadline for readbacks or if we've
|
| + // lost the outpust surface or are waiting for a forced draw.
|
| + if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK)
|
| + return commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW;
|
| + if (output_surface_state_ == OUTPUT_SURFACE_LOST)
|
| + return commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW ||
|
| + commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW;
|
| +
|
| + // Never draw outside of the BeginFrame deadline (except for readbacks).
|
| + if (begin_frame_state_ != BEGIN_FRAME_STATE_INSIDE_DEADLINE)
|
| return false;
|
| - if (!inside_begin_frame_)
|
| + if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW)
|
| + return commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW;
|
| + if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW)
|
| + return false;
|
| + if (!ScheduledToDraw())
|
| return false;
|
| if (HasDrawnThisFrame())
|
| return false;
|
| @@ -150,14 +185,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,17 +218,60 @@ bool SchedulerStateMachine::ShouldAcquireLayerTexturesForMainThread() const {
|
| return false;
|
| }
|
|
|
| +bool SchedulerStateMachine::ShouldSendBeginFrameToMainThread() const {
|
| + if (HasSentBeginFrameToMainThreadThisFrame())
|
| + return false;
|
| +
|
| + if (readback_state_ == READBACK_STATE_FORCED_COMMIT_REQUESTED)
|
| + return true;
|
| +
|
| + // TODO(brianderson): 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.
|
| + if (begin_frame_state_ == BEGIN_FRAME_STATE_INSIDE_DEADLINE &&
|
| + !HasDrawnThisFrame())
|
| + return false;
|
| +
|
| + // We can't accept a commit if we have a pending tree.
|
| + if (has_pending_tree_)
|
| + return false;
|
| +
|
| + bool can_commit = needs_commit_ &&
|
| + (visible_ ||
|
| + forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT);
|
| + switch (commit_state_) {
|
| + case COMMIT_STATE_IDLE:
|
| + return can_commit &&
|
| + (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT ||
|
| + output_surface_state_ == OUTPUT_SURFACE_ACTIVE);
|
| +
|
| + // COMMIT_STATE_WAITING_FOR_ACTIVATION wants to enforce activation and
|
| + // eventually a draw.
|
| + // 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).
|
| + case COMMIT_STATE_WAITING_FOR_ACTIVATION:
|
| + case COMMIT_STATE_WAITING_FOR_FIRST_DRAW:
|
| + return can_commit && DrawSuspendedUntilCommit();
|
| + default:
|
| + return false;
|
| + }
|
| +
|
| + return false;
|
| +}
|
| +
|
| SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const {
|
| if (ShouldAcquireLayerTexturesForMainThread())
|
| return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD;
|
|
|
| switch (commit_state_) {
|
| - case COMMIT_STATE_IDLE:
|
| - if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE &&
|
| - needs_forced_redraw_)
|
| - return ACTION_DRAW_FORCED;
|
| + case COMMIT_STATE_IDLE: VLOG(0) << __LINE__ << "COMMIT_STATE_IDLE\n";
|
| if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE &&
|
| - needs_forced_commit_)
|
| + readback_state_ == READBACK_STATE_FORCED_COMMIT_REQUESTED)
|
| // TODO(enne): Should probably drop the active tree on force commit.
|
| return has_pending_tree_ ? ACTION_NONE
|
| : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD;
|
| @@ -202,57 +284,73 @@ SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const {
|
| if (ShouldAttemptTreeActivation())
|
| return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED;
|
| if (ShouldDraw()) {
|
| - return needs_forced_redraw_ ? ACTION_DRAW_FORCED
|
| - : ACTION_DRAW_IF_POSSIBLE;
|
| + DCHECK_NE(forced_redraw_state_, FORCED_REDRAW_STATE_WAITING_FOR_DRAW);
|
| + DCHECK_NE(readback_state_, READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK);
|
| + return ACTION_DRAW_IF_POSSIBLE;
|
| }
|
| - if (needs_commit_ &&
|
| - ((visible_ && output_surface_state_ == OUTPUT_SURFACE_ACTIVE)
|
| - || needs_forced_commit_))
|
| + if (ShouldSendBeginFrameToMainThread()) {
|
| // 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:
|
| + case COMMIT_STATE_FRAME_IN_PROGRESS:VLOG(0) << __LINE__ << "COMMIT_STATE_FRAME_IN_PROGRESS\n";
|
| if (ShouldCheckForCompletedTileUploads())
|
| 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;
|
| + DCHECK_NE(forced_redraw_state_, FORCED_REDRAW_STATE_WAITING_FOR_DRAW);
|
| + DCHECK_NE(readback_state_, READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK);
|
| + return ACTION_DRAW_IF_POSSIBLE;
|
| }
|
| return ACTION_NONE;
|
|
|
| - case COMMIT_STATE_READY_TO_COMMIT:
|
| + case COMMIT_STATE_READY_TO_COMMIT:VLOG(0) << __LINE__ << "COMMIT_STATE_READY_TO_COMMIT\n";
|
| return ACTION_COMMIT;
|
|
|
| - case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: {
|
| + case COMMIT_STATE_WAITING_FOR_ACTIVATION: { VLOG(0) << __LINE__ << "COMMIT_STATE_WAITING_FOR_ACTIVATION\n";
|
| 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()) {
|
| + DCHECK_NE(forced_redraw_state_, FORCED_REDRAW_STATE_WAITING_FOR_DRAW);
|
| + DCHECK_NE(readback_state_, READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK);
|
| + return ACTION_DRAW_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;
|
| + if (ShouldSendBeginFrameToMainThread())
|
| + return 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: { VLOG(0) << __LINE__ << "COMMIT_STATE_WAITING_FOR_FIRST_DRAW\n";
|
| 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()) {
|
| + DCHECK_NE(forced_redraw_state_, FORCED_REDRAW_STATE_WAITING_FOR_DRAW);
|
| + DCHECK_NE(readback_state_, READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK);
|
| + return ACTION_DRAW_IF_POSSIBLE;
|
| + }
|
| + if (ShouldSendBeginFrameToMainThread())
|
| + return ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD;
|
| + return ACTION_NONE;
|
| + }
|
| +
|
| + case COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW: VLOG(0) << __LINE__ << "COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW\n";
|
| + if (ShouldCheckForCompletedTileUploads())
|
| + return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS;
|
| + if (ShouldAttemptTreeActivation())
|
| + return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED;
|
| + if (ShouldDraw()) {
|
| + if(forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW)
|
| + return ACTION_DRAW_FORCED;
|
| + else if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK)
|
| + return ACTION_DRAW_AND_READBACK;
|
| + NOTREACHED();
|
| + }
|
| return ACTION_NONE;
|
| }
|
| NOTREACHED();
|
| @@ -265,60 +363,88 @@ 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) << ToString();
|
| 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
|
| - 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)
|
| - 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 (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;
|
| + commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW;
|
| + } else if (readback_state_ == READBACK_STATE_FORCED_COMMIT_PENDING ||
|
| + readback_state_ == READBACK_STATE_FORCED_COMMIT_REQUESTED) {
|
| + readback_state_ = READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK;
|
| + commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW;
|
| + } 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) {
|
| + needs_redraw_ = true;
|
| + if (draw_if_possible_failed_)
|
| + last_begin_frame_count_draw_was_called_ = -1;
|
| + }
|
| + commit_tree_has_been_drawn_ = false;
|
| 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_;
|
| + case ACTION_DRAW_FORCED:
|
| + case ACTION_DRAW_AND_READBACK:
|
| 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;
|
| - expect_immediate_begin_frame_for_main_thread_ = false;
|
| + if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) {
|
| + forced_redraw_state_ = FORCED_REDRAW_STATE_IDLE;
|
| + } else if (readback_state_ ==
|
| + READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) {
|
| + commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS;
|
| + readback_state_ = has_pending_tree_ ?
|
| + READBACK_STATE_REPLACEMENT_COMMIT_ACTIVATING :
|
| + 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;
|
| + commit_tree_has_been_drawn_ = true;
|
| return;
|
|
|
| case ACTION_BEGIN_OUTPUT_SURFACE_CREATION:
|
| @@ -336,18 +462,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_)
|
| @@ -357,28 +502,57 @@ 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;
|
| +}
|
| +
|
| +bool SchedulerStateMachine::ShouldTriggerBeginFrameDeadlineEarly() const {
|
| + // TODO(brianderson): This should take into account multiple commit sources.
|
| + return begin_frame_state_ == BEGIN_FRAME_STATE_DEADLINE_PENDING &&
|
| + WillDrawNewTree();
|
| +}
|
| +
|
| +bool SchedulerStateMachine::InsideBeginFrame() const {
|
| + return begin_frame_state_ != BEGIN_FRAME_STATE_IDLE;
|
| +}
|
| +
|
| +bool SchedulerStateMachine::WillDrawNewTree() const {
|
| + if (settings_.impl_side_painting)
|
| + return !active_tree_has_been_drawn_;
|
| + else
|
| + return !commit_tree_has_been_drawn_;
|
| }
|
|
|
| -void SchedulerStateMachine::DidLeaveBeginFrame() {
|
| - current_frame_number_++;
|
| - inside_begin_frame_ = false;
|
| +void SchedulerStateMachine::OnBeginFrameDeadline() {
|
| + DCHECK_EQ(begin_frame_state_, BEGIN_FRAME_STATE_DEADLINE_PENDING);
|
| + begin_frame_deadline_count_++;
|
| + draw_attempt_count_++;
|
| + begin_frame_state_ = BEGIN_FRAME_STATE_INSIDE_DEADLINE;
|
| }
|
|
|
| -void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; }
|
| +void SchedulerStateMachine::SetVisible(bool visible) {
|
| + visible_ = visible;
|
| +}
|
|
|
| void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; }
|
|
|
| @@ -386,10 +560,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_) {
|
| @@ -402,7 +572,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;
|
| @@ -411,23 +581,24 @@ 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() {
|
| + VLOG(0) << __LINE__ << "SetNeedsForcedCommitForReadback\n";
|
| + DCHECK_EQ(readback_state_, READBACK_STATE_IDLE);
|
| + 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_ &&
|
| + (readback_state_ == READBACK_STATE_FORCED_COMMIT_REQUESTED &&
|
| commit_state_ != COMMIT_STATE_IDLE))
|
| << 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();
|
| @@ -441,11 +612,40 @@ 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) {
|
| + if (has_pending_tree_ && !has_pending_tree) {
|
| + // This is a new activation.
|
| + VLOG(0) << __LINE__ << "ACTIVATED!\n";
|
| + draw_attempt_count_++;
|
| + active_tree_has_been_drawn_ = false;
|
| +
|
| + if (draw_if_possible_failed_)
|
| + last_begin_frame_count_draw_was_called_ = -1;
|
| +
|
| + if (COMMIT_STATE_WAITING_FOR_ACTIVATION == commit_state_) {
|
| + if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION) {
|
| + commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_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_FORCED_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;
|
| + active_tree_is_null_ = active_tree_is_null;
|
| }
|
|
|
| -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);
|
|
|