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

Unified Diff: cc/scheduler/scheduler_state_machine.cc

Issue 23907006: cc: Allow sending BeginMainFrame before draw or activation (Closed) Base URL: http://git.chromium.org/chromium/src.git@schedDeadline3
Patch Set: Block main thread from state machine; remove completion event; Created 7 years, 3 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 20d2ce37d7ee9ab0323d82738bade1a3ac5e04c2..c6ac74d1b32b869938e8bc7e590a57e0207e2a45 100644
--- a/cc/scheduler/scheduler_state_machine.cc
+++ b/cc/scheduler/scheduler_state_machine.cc
@@ -83,8 +83,6 @@ const char* SchedulerStateMachine::CommitStateToString(CommitState state) {
return "COMMIT_STATE_FRAME_IN_PROGRESS";
case COMMIT_STATE_READY_TO_COMMIT:
return "COMMIT_STATE_READY_TO_COMMIT";
- case COMMIT_STATE_WAITING_FOR_FIRST_DRAW:
- return "COMMIT_STATE_WAITING_FOR_FIRST_DRAW";
}
NOTREACHED();
return "???";
@@ -351,10 +349,8 @@ bool SchedulerStateMachine::ShouldDraw() const {
return false;
// Draw immediately for readbacks to unblock the main thread quickly.
- if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) {
- DCHECK_EQ(commit_state_, COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
danakj 2013/09/17 17:05:07 Should we DCHECK(active_tree_waiting_for_first_dra
brianderson 2013/10/03 14:44:38 Yes, that would be a good DCHECK to add.
+ if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK)
return true;
- }
// If we need to abort draws, we should do so ASAP since the draw could
// be blocking other important actions (like output surface initialization),
@@ -373,10 +369,8 @@ bool SchedulerStateMachine::ShouldDraw() const {
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);
danakj 2013/09/17 17:05:07 Should we DCHECK(active_tree_waiting_for_first_dra
+ if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW)
return true;
- }
return needs_redraw_;
}
@@ -443,8 +437,19 @@ bool SchedulerStateMachine::ShouldSendBeginFrameToMainThread() const {
if (commit_state_ != COMMIT_STATE_IDLE)
return false;
- // We can't accept a commit if we have a pending tree.
- if (has_pending_tree_)
+ // Starting the commit while we still have a pending tree will block the
+ // main thread until the pending tree activates.
+ if (has_pending_tree_ &&
+ !settings_.start_commit_before_activate_enabled)
+ return false;
+
+ // If we are not impl-side-painting, starting the commit before the active
+ // tree has drawn will block the main thread until the first draw occurs.
+ // If we are impl-side-painting however, we will not block the main thread
+ // by starting the commit before the active tree has drawn since the pending
+ // tree is free to accept the commit.
+ if (active_tree_needs_first_draw_ &&
Sami 2013/10/03 13:31:11 It's a little hard to see how this condition relat
brianderson 2013/10/03 14:44:38 The decision to be made here is the same regardles
+ !settings_.start_commit_before_draw_enabled)
return false;
// We want to handle readback commits immediately to unblock the main thread.
@@ -490,7 +495,23 @@ bool SchedulerStateMachine::ShouldSendBeginFrameToMainThread() const {
}
bool SchedulerStateMachine::ShouldCommit() const {
- return commit_state_ == COMMIT_STATE_READY_TO_COMMIT;
+ if (commit_state_ != COMMIT_STATE_READY_TO_COMMIT)
+ return false;
+
+ // We must not finish the commit until the pending tree is free.
+ if (has_pending_tree_) {
+ DCHECK(settings_.start_commit_before_activate_enabled);
+ return false;
+ }
+
+ // If not impl-side-painting, we must not finish the commit until the
+ // previous commit has been drawn.
+ if (active_tree_needs_first_draw_ && !settings_.impl_side_painting) {
+ DCHECK(settings_.start_commit_before_draw_enabled);
+ return false;
+ }
+
+ return true;
}
SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const {
@@ -541,7 +562,10 @@ void SchedulerStateMachine::UpdateState(Action action) {
return;
case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD:
- DCHECK(!has_pending_tree_);
+ DCHECK(!has_pending_tree_ ||
+ settings_.start_commit_before_activate_enabled);
+ DCHECK(!active_tree_needs_first_draw_ ||
+ settings_.start_commit_before_draw_enabled);
DCHECK(visible_ || readback_state_ == READBACK_STATE_NEEDS_BEGIN_FRAME);
commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS;
needs_commit_ = false;
@@ -594,6 +618,9 @@ void SchedulerStateMachine::UpdateStateOnCommit(bool commit_was_aborted) {
commit_count_++;
draw_attempt_count_++;
+ // Transition directly to idle.
+ commit_state_ = COMMIT_STATE_IDLE;
+
// If we are impl-side-painting but the commit was aborted, then we behave
// mostly as if we are not impl-side-painting since there is no pending tree.
has_pending_tree_ = settings_.impl_side_painting && !commit_was_aborted;
@@ -639,16 +666,6 @@ void SchedulerStateMachine::UpdateStateOnCommit(bool commit_was_aborted) {
}
}
- // Update the commit state. We expect and wait for a draw if the commit
- // was not aborted or if we are in a readback or forced draw.
- if (!commit_was_aborted)
- commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW;
- else if (readback_state_ != READBACK_STATE_IDLE ||
- forced_redraw_state_ != FORCED_REDRAW_STATE_IDLE)
- commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW;
- else
- commit_state_ = COMMIT_STATE_IDLE;
-
// Update state if we have a new active tree to draw, or if the active tree
// was unchanged but we need to do a readback or forced draw.
if (!has_pending_tree_ &&
@@ -705,8 +722,7 @@ void SchedulerStateMachine::UpdateStateOnDraw(bool did_swap) {
<< *AsValue();
if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) {
- // The draw correspons to a readback commit.
- DCHECK_EQ(commit_state_, COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
+ // The draw corresponds to a readback commit.
// We are blocking commits from the main thread until after this draw, so
// we should not have a pending tree.
DCHECK(!has_pending_tree_);
@@ -715,12 +731,7 @@ void SchedulerStateMachine::UpdateStateOnDraw(bool did_swap) {
commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS;
readback_state_ = READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT;
} else if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) {
- DCHECK_EQ(commit_state_, COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
- commit_state_ = COMMIT_STATE_IDLE;
forced_redraw_state_ = FORCED_REDRAW_STATE_IDLE;
- } else if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW &&
- !has_pending_tree_) {
- commit_state_ = COMMIT_STATE_IDLE;
}
if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD)
@@ -905,7 +916,7 @@ void SchedulerStateMachine::SetNeedsForcedCommitForReadback() {
}
void SchedulerStateMachine::FinishCommit() {
- DCHECK(commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS) << *AsValue();
+ DCHECK(commit_state_ != COMMIT_STATE_IDLE) << *AsValue();
commit_state_ = COMMIT_STATE_READY_TO_COMMIT;
}

Powered by Google App Engine
This is Rietveld 408576698