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

Unified Diff: cc/scheduler_state_machine_unittest.cc

Issue 11416043: Merge 167537 - Use message passing for BeginFrameAndCommitState and clean up forced commit logic (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1312/src/
Patch Set: Created 8 years, 1 month 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
« no previous file with comments | « cc/scheduler_state_machine.cc ('k') | cc/thread_proxy.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/scheduler_state_machine_unittest.cc
===================================================================
--- cc/scheduler_state_machine_unittest.cc (revision 168251)
+++ cc/scheduler_state_machine_unittest.cc (working copy)
@@ -25,12 +25,8 @@
void setCommitState(CommitState cs) { m_commitState = cs; }
CommitState commitState() const { return m_commitState; }
- void setNeedsCommit(bool b) { m_needsCommit = b; }
bool needsCommit() const { return m_needsCommit; }
- void setNeedsForcedCommit(bool b) { m_needsForcedCommit = b; }
- bool needsForcedCommit() const { return m_needsForcedCommit; }
-
void setNeedsRedraw(bool b) { m_needsRedraw = b; }
bool needsRedraw() const { return m_needsRedraw; }
@@ -50,7 +46,6 @@
state.setCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE);
state.setCanBeginFrame(true);
state.setNeedsRedraw(false);
- state.setNeedsCommit(false);
state.setVisible(true);
EXPECT_FALSE(state.vsyncCallbackNeeded());
@@ -67,7 +62,6 @@
StateMachine state;
state.setCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE);
state.setNeedsRedraw(false);
- state.setNeedsCommit(false);
state.setVisible(true);
EXPECT_FALSE(state.vsyncCallbackNeeded());
@@ -86,7 +80,6 @@
state.setCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE);
state.setCanBeginFrame(true);
state.setNeedsRedraw(false);
- state.setNeedsCommit(true);
state.setVisible(true);
EXPECT_FALSE(state.vsyncCallbackNeeded());
}
@@ -369,11 +362,10 @@
state.setVisible(true);
// Case 1: needsCommit=false
- state.setNeedsCommit(false);
EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction());
// Case 2: needsCommit=true
- state.setNeedsCommit(true);
+ state.setNeedsCommit();
EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction());
}
}
@@ -399,12 +391,11 @@
expectedAction = SchedulerStateMachine::ACTION_COMMIT;
// Case 1: needsCommit=false.
- state.setNeedsCommit(false);
EXPECT_TRUE(state.vsyncCallbackNeeded());
EXPECT_EQ(expectedAction, state.nextAction());
// Case 2: needsCommit=true.
- state.setNeedsCommit(true);
+ state.setNeedsCommit();
EXPECT_TRUE(state.vsyncCallbackNeeded());
EXPECT_EQ(expectedAction, state.nextAction());
}
@@ -426,11 +417,10 @@
state.didEnterVSync();
// Case 1: needsCommit=false.
- state.setNeedsCommit(false);
EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction());
// Case 2: needsCommit=true.
- state.setNeedsCommit(true);
+ state.setNeedsCommit();
EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction());
}
}
@@ -461,7 +451,7 @@
StateMachine state;
state.setCommitState(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
state.setCanBeginFrame(true);
- state.setNeedsCommit(true);
+ state.setNeedsCommit();
state.setNeedsRedraw(true);
state.setVisible(true);
state.setCanDraw(false);
@@ -472,7 +462,7 @@
{
StateMachine state;
state.setCanBeginFrame(true);
- state.setNeedsCommit(true);
+ state.setNeedsCommit();
state.setVisible(true);
state.setCanDraw(true);
@@ -482,7 +472,7 @@
EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commitState());
// Now, while the frame is in progress, set another commit.
- state.setNeedsCommit(true);
+ state.setNeedsCommit();
EXPECT_TRUE(state.needsCommit());
// Let the frame finish.
@@ -515,7 +505,7 @@
state.setCanDraw(true);
// Start clean and set commit.
- state.setNeedsCommit(true);
+ state.setNeedsCommit();
EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
// Begin the frame.
@@ -558,7 +548,7 @@
state.setCanDraw(true);
// Start clean and set commit.
- state.setNeedsCommit(true);
+ state.setNeedsCommit();
EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
// Begin the frame.
@@ -568,7 +558,7 @@
EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
// Request another commit while the commit is in flight.
- state.setNeedsCommit(true);
+ state.setNeedsCommit();
EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
// Tell the scheduler the frame finished.
@@ -600,7 +590,7 @@
TEST(SchedulerStateMachineTest, TestRequestCommitInvisible)
{
StateMachine state;
- state.setNeedsCommit(true);
+ state.setNeedsCommit();
EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
}
@@ -612,7 +602,7 @@
state.setCanDraw(true);
// Start clean and set commit.
- state.setNeedsCommit(true);
+ state.setNeedsCommit();
EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
// Begin the frame while visible.
@@ -682,7 +672,7 @@
EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
// While context is recreating, commits shouldn't begin.
- state.setNeedsCommit(true);
+ state.setNeedsCommit();
EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
// Recreate the context
@@ -711,7 +701,7 @@
state.setCanDraw(true);
// Get a commit in flight.
- state.setNeedsCommit(true);
+ state.setNeedsCommit();
EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
state.updateState(state.nextAction());
@@ -754,7 +744,7 @@
state.setCanDraw(true);
// Get a commit in flight.
- state.setNeedsCommit(true);
+ state.setNeedsCommit();
EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
state.updateState(state.nextAction());
@@ -770,7 +760,7 @@
// Ask for another draw and also set needs commit. Expect nothing happens.
state.setNeedsRedraw(true);
- state.setNeedsCommit(true);
+ state.setNeedsCommit();
EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.nextAction());
// Finish the frame, and commit.
@@ -825,8 +815,8 @@
StateMachine state;
state.setCanBeginFrame(true);
state.setVisible(false);
- state.setNeedsCommit(true);
- state.setNeedsForcedCommit(true);
+ state.setNeedsCommit();
+ state.setNeedsForcedCommit();
EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
}
@@ -835,8 +825,8 @@
StateMachine state;
state.setVisible(true);
state.setCanDraw(true);
- state.setNeedsCommit(true);
- state.setNeedsForcedCommit(true);
+ state.setNeedsCommit();
+ state.setNeedsForcedCommit();
EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
}
@@ -846,8 +836,8 @@
state.setCanBeginFrame(true);
state.setVisible(false);
state.setCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS);
- state.setNeedsCommit(true);
- state.setNeedsForcedCommit(true);
+ state.setNeedsCommit();
+ state.setNeedsForcedCommit();
state.beginFrameComplete();
EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction());
@@ -864,10 +854,104 @@
state.setCanBeginFrame(true);
state.setVisible(true);
state.setCanDraw(true);
- state.setNeedsCommit(true);
- state.setNeedsForcedCommit(true);
+ state.setNeedsCommit();
+ state.setNeedsForcedCommit();
state.didLoseContext();
EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction());
}
+TEST(SchedulerStateMachineTest, TestImmediateBeginFrame)
+{
+ StateMachine state;
+ state.setCanBeginFrame(true);
+ state.setVisible(true);
+ state.setCanDraw(true);
+
+ // Schedule a forced frame, commit it, draw it.
+ state.setNeedsCommit();
+ state.setNeedsForcedCommit();
+ state.updateState(state.nextAction());
+ state.beginFrameComplete();
+ EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction());
+ EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitState());
+ state.updateState(state.nextAction());
+
+ state.didEnterVSync();
+ EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction());
+ state.updateState(state.nextAction());
+ state.didDrawIfPossibleCompleted(true);
+ state.didLeaveVSync();
+
+ // Should be waiting for the normal begin frame
+ EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commitState());
}
+
+TEST(SchedulerStateMachineTest, TestImmediateBeginFrameDuringCommit)
+{
+ StateMachine state;
+ state.setCanBeginFrame(true);
+ state.setVisible(true);
+ state.setCanDraw(true);
+
+ // Start a normal commit.
+ state.setNeedsCommit();
+ state.updateState(state.nextAction());
+
+ // Schedule a forced frame, commit it, draw it.
+ state.setNeedsCommit();
+ state.setNeedsForcedCommit();
+ state.updateState(state.nextAction());
+ state.beginFrameComplete();
+ EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction());
+ EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitState());
+ state.updateState(state.nextAction());
+
+ state.didEnterVSync();
+ EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction());
+ state.updateState(state.nextAction());
+ state.didDrawIfPossibleCompleted(true);
+ state.didLeaveVSync();
+
+ // Should be waiting for the normal begin frame
+ EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commitState()) << state.toString();
+}
+
+TEST(SchedulerStateMachineTest, ImmediateBeginFrameWhileInvisible)
+{
+ StateMachine state;
+ state.setCanBeginFrame(true);
+ state.setVisible(true);
+ state.setCanDraw(true);
+
+ state.setNeedsCommit();
+ state.updateState(state.nextAction());
+
+ state.setNeedsCommit();
+ state.setNeedsForcedCommit();
+ state.updateState(state.nextAction());
+ state.beginFrameComplete();
+
+ EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.nextAction());
+ EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitState());
+ state.updateState(state.nextAction());
+
+ state.didEnterVSync();
+ EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE, state.nextAction());
+ state.updateState(state.nextAction());
+ state.didDrawIfPossibleCompleted(true);
+ state.didLeaveVSync();
+
+ // Should be waiting for the normal begin frame
+ EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commitState()) << state.toString();
+
+
+ // Become invisible and abort the "normal" begin frame.
+ state.setVisible(false);
+ state.beginFrameAborted();
+
+ // Should be back in the idle state, but needing a commit.
+ EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.commitState());
+ EXPECT_TRUE(state.needsCommit());
+}
+
+} // namespace
« no previous file with comments | « cc/scheduler_state_machine.cc ('k') | cc/thread_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698