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

Side by Side Diff: cc/scheduler/scheduler_state_machine_unittest.cc

Issue 23796002: cc: Implement deadine scheduling disabled by default (Closed) Base URL: http://git.chromium.org/chromium/src.git@schedReadback4
Patch Set: Fix animations, but still sample timestamp in BeginFrame. 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 unified diff | Download patch
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/scheduler/scheduler_state_machine.h" 5 #include "cc/scheduler/scheduler_state_machine.h"
6 6
7 #include "cc/scheduler/scheduler.h" 7 #include "cc/scheduler/scheduler.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 #define EXPECT_ACTION_UPDATE_STATE(action) \ 10 #define EXPECT_ACTION_UPDATE_STATE(action) \
11 EXPECT_EQ(action, state.NextAction()) << *state.AsValue(); \ 11 EXPECT_EQ(action, state.NextAction()) << *state.AsValue(); \
12 state.UpdateState(action); 12 if (action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE || \
13 action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED) { \
14 if (SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW == \
15 state.CommitState() && \
16 SchedulerStateMachine::OUTPUT_SURFACE_ACTIVE != \
17 state.output_surface_state()) \
18 return; \
19 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_DEADLINE, \
20 state.begin_frame_state()) \
21 << *state.AsValue(); \
22 } \
23 state.UpdateState(action); \
24 if (action == SchedulerStateMachine::ACTION_NONE) { \
25 if (state.begin_frame_state() == \
26 SchedulerStateMachine::BEGIN_FRAME_STATE_BEGIN_FRAME_STARTING) \
27 state.OnBeginFrameDeadlinePending(); \
28 if (state.begin_frame_state() == \
29 SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_DEADLINE) \
30 state.OnBeginFrameIdle(); \
31 }
13 32
14 namespace cc { 33 namespace cc {
15 34
16 namespace { 35 namespace {
17 36
37 const SchedulerStateMachine::BeginFrameState all_begin_frame_states[] = {
38 SchedulerStateMachine::BEGIN_FRAME_STATE_IDLE,
39 SchedulerStateMachine::BEGIN_FRAME_STATE_BEGIN_FRAME_STARTING,
40 SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME,
41 SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_DEADLINE, };
42
18 const SchedulerStateMachine::CommitState all_commit_states[] = { 43 const SchedulerStateMachine::CommitState all_commit_states[] = {
19 SchedulerStateMachine::COMMIT_STATE_IDLE, 44 SchedulerStateMachine::COMMIT_STATE_IDLE,
20 SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 45 SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
21 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 46 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
22 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW 47 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, };
23 };
24 48
25 // Exposes the protected state fields of the SchedulerStateMachine for testing 49 // Exposes the protected state fields of the SchedulerStateMachine for testing
26 class StateMachine : public SchedulerStateMachine { 50 class StateMachine : public SchedulerStateMachine {
27 public: 51 public:
28 explicit StateMachine(const SchedulerSettings& scheduler_settings) 52 explicit StateMachine(const SchedulerSettings& scheduler_settings)
29 : SchedulerStateMachine(scheduler_settings) {} 53 : SchedulerStateMachine(scheduler_settings) {}
30 54
31 void CreateAndInitializeOutputSurfaceWithActivatedCommit() { 55 void CreateAndInitializeOutputSurfaceWithActivatedCommit() {
32 DidCreateAndInitializeOutputSurface(); 56 DidCreateAndInitializeOutputSurface();
33 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; 57 output_surface_state_ = OUTPUT_SURFACE_ACTIVE;
34 } 58 }
35 59
36 void SetCommitState(CommitState cs) { commit_state_ = cs; } 60 void SetCommitState(CommitState cs) { commit_state_ = cs; }
37 CommitState CommitState() const { return commit_state_; } 61 CommitState CommitState() const { return commit_state_; }
38 62
63 void SetBeginFrameState(BeginFrameState bfs) { begin_frame_state_ = bfs; }
64
65 BeginFrameState begin_frame_state() const { return begin_frame_state_; }
66
39 OutputSurfaceState output_surface_state() const { 67 OutputSurfaceState output_surface_state() const {
40 return output_surface_state_; 68 return output_surface_state_;
41 } 69 }
42 70
43 bool NeedsCommit() const { return needs_commit_; } 71 bool NeedsCommit() const { return needs_commit_; }
44 72
45 void SetNeedsRedraw(bool b) { needs_redraw_ = b; } 73 void SetNeedsRedraw(bool b) { needs_redraw_ = b; }
46 bool NeedsRedraw() const { return needs_redraw_; } 74 bool NeedsRedraw() const { return needs_redraw_; }
47 75
48 void SetNeedsForcedRedrawForTimeout(bool b) { 76 void SetNeedsForcedRedrawForTimeout(bool b) {
49 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_COMMIT; 77 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_COMMIT;
50 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; 78 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW;
51 } 79 }
52 bool NeedsForcedRedrawForTimeout() const { 80 bool NeedsForcedRedrawForTimeout() const {
53 return forced_redraw_state_ != FORCED_REDRAW_STATE_IDLE; 81 return forced_redraw_state_ != FORCED_REDRAW_STATE_IDLE;
54 } 82 }
55 83
56 void SetNeedsForcedRedrawForReadback() { 84 void SetNeedsForcedRedrawForReadback() {
57 readback_state_ = READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK; 85 readback_state_ = READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK;
58 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; 86 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW;
59 } 87 }
60 88
61 bool NeedsForcedRedrawForReadback() const { 89 bool NeedsForcedRedrawForReadback() const {
62 return readback_state_ != READBACK_STATE_IDLE; 90 return readback_state_ != READBACK_STATE_IDLE;
63 } 91 }
64 92
93 void SetActiveTreeNeedsFirstDraw(bool needs_first_draw) {
94 active_tree_needs_first_draw_ = needs_first_draw;
95 }
96
65 bool CanDraw() const { return can_draw_; } 97 bool CanDraw() const { return can_draw_; }
66 bool Visible() const { return visible_; } 98 bool Visible() const { return visible_; }
99
100 bool PendingActivationsShouldBeForced() const {
101 return SchedulerStateMachine::PendingActivationsShouldBeForced();
102 }
67 }; 103 };
68 104
69 TEST(SchedulerStateMachineTest, TestNextActionBeginsMainFrameIfNeeded) { 105 TEST(SchedulerStateMachineTest, TestNextActionBeginsMainFrameIfNeeded) {
70 SchedulerSettings default_scheduler_settings; 106 SchedulerSettings default_scheduler_settings;
71 107
72 // If no commit needed, do nothing. 108 // If no commit needed, do nothing.
73 { 109 {
74 StateMachine state(default_scheduler_settings); 110 StateMachine state(default_scheduler_settings);
75 state.SetCanStart(); 111 state.SetCanStart();
76 EXPECT_ACTION_UPDATE_STATE( 112 EXPECT_ACTION_UPDATE_STATE(
77 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION) 113 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION)
78 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 114 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
79 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); 115 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE);
80 state.SetNeedsRedraw(false); 116 state.SetNeedsRedraw(false);
81 state.SetVisible(true); 117 state.SetVisible(true);
82 118
83 EXPECT_FALSE(state.BeginFrameNeededToDrawByImplThread()); 119 EXPECT_FALSE(state.BeginFrameNeededByImplThread());
84 120
85 state.DidLeaveBeginFrame(); 121 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
86 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 122 EXPECT_FALSE(state.BeginFrameNeededByImplThread());
87 EXPECT_FALSE(state.BeginFrameNeededToDrawByImplThread()); 123 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
88 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); 124
89 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 125 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
126 state.OnBeginFrameDeadline();
90 } 127 }
91 128
92 // If commit requested but can_start is still false, do nothing. 129 // If commit requested but can_start is still false, do nothing.
93 { 130 {
94 StateMachine state(default_scheduler_settings); 131 StateMachine state(default_scheduler_settings);
95 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); 132 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE);
96 state.SetNeedsRedraw(false); 133 state.SetNeedsRedraw(false);
97 state.SetVisible(true); 134 state.SetVisible(true);
98 135
99 EXPECT_FALSE(state.BeginFrameNeededToDrawByImplThread()); 136 EXPECT_FALSE(state.BeginFrameNeededByImplThread());
100 137
101 state.DidLeaveBeginFrame(); 138 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
102 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 139 EXPECT_FALSE(state.BeginFrameNeededByImplThread());
103 EXPECT_FALSE(state.BeginFrameNeededToDrawByImplThread()); 140 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
104 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); 141 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
105 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 142 state.OnBeginFrameDeadline();
106 } 143 }
107 144
108 // If commit requested, begin a main frame. 145 // If commit requested, begin a main frame.
109 { 146 {
110 StateMachine state(default_scheduler_settings); 147 StateMachine state(default_scheduler_settings);
111 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); 148 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE);
112 state.SetCanStart(); 149 state.SetCanStart();
113 state.SetNeedsRedraw(false); 150 state.SetNeedsRedraw(false);
114 state.SetVisible(true); 151 state.SetVisible(true);
115 EXPECT_FALSE(state.BeginFrameNeededToDrawByImplThread()); 152 EXPECT_FALSE(state.BeginFrameNeededByImplThread());
116 } 153 }
117 154
118 // Begin the frame, make sure needs_commit and commit_state update correctly. 155 // Begin the frame, make sure needs_commit and commit_state update correctly.
119 { 156 {
120 StateMachine state(default_scheduler_settings); 157 StateMachine state(default_scheduler_settings);
121 state.SetCanStart(); 158 state.SetCanStart();
122 state.UpdateState(state.NextAction()); 159 state.UpdateState(state.NextAction());
123 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 160 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
124 state.SetVisible(true); 161 state.SetVisible(true);
125 state.UpdateState( 162 state.UpdateState(
126 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); 163 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
127 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 164 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
128 state.CommitState()); 165 state.CommitState());
129 EXPECT_FALSE(state.NeedsCommit()); 166 EXPECT_FALSE(state.NeedsCommit());
130 EXPECT_FALSE(state.BeginFrameNeededToDrawByImplThread());
131 } 167 }
132 } 168 }
133 169
134 TEST(SchedulerStateMachineTest, 170 TEST(SchedulerStateMachineTest,
135 TestFailedDrawSetsNeedsCommitAndDoesNotDrawAgain) { 171 TestFailedDrawSetsNeedsCommitAndDoesNotDrawAgain) {
136 SchedulerSettings default_scheduler_settings; 172 SchedulerSettings default_scheduler_settings;
137 StateMachine state(default_scheduler_settings); 173 StateMachine state(default_scheduler_settings);
138 state.SetCanStart(); 174 state.SetCanStart();
139 state.UpdateState(state.NextAction()); 175 state.UpdateState(state.NextAction());
140 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 176 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
141 state.SetVisible(true); 177 state.SetVisible(true);
142 state.SetCanDraw(true); 178 state.SetCanDraw(true);
143 state.SetNeedsRedraw(true); 179 state.SetNeedsRedraw(true);
144 EXPECT_TRUE(state.RedrawPending()); 180 EXPECT_TRUE(state.RedrawPending());
145 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); 181 EXPECT_TRUE(state.BeginFrameNeededByImplThread());
146 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); 182 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
183 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
184 state.OnBeginFrameDeadline();
147 185
148 // We're drawing now. 186 // We're drawing now.
149 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 187 EXPECT_ACTION_UPDATE_STATE(
150 state.NextAction()); 188 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
151 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 189 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
152 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 190
153 EXPECT_FALSE(state.RedrawPending()); 191 EXPECT_FALSE(state.RedrawPending());
154 EXPECT_FALSE(state.CommitPending()); 192 EXPECT_FALSE(state.CommitPending());
155 193
156 // Failing the draw makes us require a commit. 194 // Failing the draw makes us require a commit.
157 state.DidDrawIfPossibleCompleted(false); 195 state.DidDrawIfPossibleCompleted(false);
158 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, 196 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
159 state.NextAction()); 197 EXPECT_ACTION_UPDATE_STATE(
160 state.UpdateState(
161 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); 198 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
162 EXPECT_TRUE(state.RedrawPending()); 199 EXPECT_TRUE(state.RedrawPending());
163 EXPECT_TRUE(state.CommitPending()); 200 EXPECT_TRUE(state.CommitPending());
164 } 201 }
165 202
166 TEST(SchedulerStateMachineTest, 203 TEST(SchedulerStateMachineTest,
167 TestsetNeedsRedrawDuringFailedDrawDoesNotRemoveNeedsRedraw) { 204 TestsetNeedsRedrawDuringFailedDrawDoesNotRemoveNeedsRedraw) {
168 SchedulerSettings default_scheduler_settings; 205 SchedulerSettings default_scheduler_settings;
169 StateMachine state(default_scheduler_settings); 206 StateMachine state(default_scheduler_settings);
170 state.SetCanStart(); 207 state.SetCanStart();
171 state.UpdateState(state.NextAction()); 208 state.UpdateState(state.NextAction());
172 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 209 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
173 210
174 state.SetVisible(true); 211 state.SetVisible(true);
175 state.SetCanDraw(true); 212 state.SetCanDraw(true);
176 state.SetNeedsRedraw(true); 213 state.SetNeedsRedraw(true);
177 EXPECT_TRUE(state.RedrawPending()); 214 EXPECT_TRUE(state.RedrawPending());
178 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); 215 EXPECT_TRUE(state.BeginFrameNeededByImplThread());
179 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); 216 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
217 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
218 state.OnBeginFrameDeadline();
180 219
181 // We're drawing now. 220 // We're drawing now.
182 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 221 EXPECT_ACTION_UPDATE_STATE(
183 state.NextAction()); 222 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
184 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 223 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
185 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
186 EXPECT_FALSE(state.RedrawPending()); 224 EXPECT_FALSE(state.RedrawPending());
187 EXPECT_FALSE(state.CommitPending()); 225 EXPECT_FALSE(state.CommitPending());
188 226
189 // While still in the same begin frame callback on the main thread, 227 // While still in the same begin frame callback on the main thread,
190 // set needs redraw again. This should not redraw. 228 // set needs redraw again. This should not redraw.
191 state.SetNeedsRedraw(true); 229 state.SetNeedsRedraw(true);
192 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 230 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
193 231
194 // Failing the draw makes us require a commit. 232 // Failing the draw makes us require a commit.
195 state.DidDrawIfPossibleCompleted(false); 233 state.DidDrawIfPossibleCompleted(false);
196 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, 234 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
197 state.NextAction()); 235 EXPECT_ACTION_UPDATE_STATE(
236 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
198 EXPECT_TRUE(state.RedrawPending()); 237 EXPECT_TRUE(state.RedrawPending());
199 } 238 }
200 239
201 TEST(SchedulerStateMachineTest, 240 TEST(SchedulerStateMachineTest,
202 TestCommitAfterFailedDrawAllowsDrawInSameFrame) {
203 SchedulerSettings default_scheduler_settings;
204 StateMachine state(default_scheduler_settings);
205 state.SetCanStart();
206 state.UpdateState(state.NextAction());
207 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
208 state.SetVisible(true);
209 state.SetCanDraw(true);
210
211 // Start a commit.
212 state.SetNeedsCommit();
213 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
214 state.NextAction());
215 state.UpdateState(
216 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
217 EXPECT_TRUE(state.CommitPending());
218
219 // Then initiate a draw.
220 state.SetNeedsRedraw(true);
221 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread());
222 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting());
223 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
224 state.NextAction());
225 EXPECT_TRUE(state.RedrawPending());
226
227 // Fail the draw.
228 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
229 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
230 state.DidDrawIfPossibleCompleted(false);
231 EXPECT_TRUE(state.RedrawPending());
232 // But the commit is ongoing.
233 EXPECT_TRUE(state.CommitPending());
234
235 // Finish the commit.
236 state.FinishCommit();
237 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
238 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT);
239 EXPECT_TRUE(state.RedrawPending());
240
241 // And we should be allowed to draw again.
242 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
243 state.NextAction());
244 }
245
246 TEST(SchedulerStateMachineTest,
247 TestFailedDrawsWillEventuallyForceADrawAfterTheNextCommit) { 241 TestFailedDrawsWillEventuallyForceADrawAfterTheNextCommit) {
248 SchedulerSettings scheduler_settings; 242 SchedulerSettings scheduler_settings;
249 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced_ = 1; 243 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced_ = 1;
250 StateMachine state(scheduler_settings); 244 StateMachine state(scheduler_settings);
251 state.SetCanStart(); 245 state.SetCanStart();
252 state.UpdateState(state.NextAction()); 246 state.UpdateState(state.NextAction());
253 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 247 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
254 state.SetVisible(true); 248 state.SetVisible(true);
255 state.SetCanDraw(true); 249 state.SetCanDraw(true);
256 250
257 // Start a commit. 251 // Start a commit.
258 state.SetNeedsCommit(); 252 state.SetNeedsCommit();
259 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, 253 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
260 state.NextAction()); 254 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
261 state.UpdateState( 255 EXPECT_ACTION_UPDATE_STATE(
262 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); 256 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
257 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
263 EXPECT_TRUE(state.CommitPending()); 258 EXPECT_TRUE(state.CommitPending());
264 259
265 // Then initiate a draw. 260 // Then initiate a draw.
266 state.SetNeedsRedraw(true); 261 state.SetNeedsRedraw(true);
267 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); 262 state.OnBeginFrameDeadline();
268 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); 263 EXPECT_ACTION_UPDATE_STATE(
269 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 264 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
270 state.NextAction());
271 EXPECT_TRUE(state.RedrawPending());
272 265
273 // Fail the draw. 266 // Fail the draw.
274 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
275 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
276 state.DidDrawIfPossibleCompleted(false); 267 state.DidDrawIfPossibleCompleted(false);
268 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
269 EXPECT_TRUE(state.BeginFrameNeededByImplThread());
277 EXPECT_TRUE(state.RedrawPending()); 270 EXPECT_TRUE(state.RedrawPending());
278 // But the commit is ongoing. 271 // But the commit is ongoing.
279 EXPECT_TRUE(state.CommitPending()); 272 EXPECT_TRUE(state.CommitPending());
280 273
281 // Finish the commit. Note, we should not yet be forcing a draw, but should 274 // Finish the commit. Note, we should not yet be forcing a draw, but should
282 // continue the commit as usual. 275 // continue the commit as usual.
283 state.FinishCommit(); 276 state.FinishCommit();
284 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 277 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
285 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); 278 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
286 EXPECT_TRUE(state.RedrawPending()); 279 EXPECT_TRUE(state.RedrawPending());
287 280
288 // The redraw should be forced in this case. 281 // The redraw should be forced at the end of the next BeginFrame.
289 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED, 282 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
290 state.NextAction()); 283 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
284 state.OnBeginFrameDeadline();
285 EXPECT_ACTION_UPDATE_STATE(
286 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED);
291 } 287 }
292 288
293 TEST(SchedulerStateMachineTest, 289 TEST(SchedulerStateMachineTest,
294 TestFailedDrawIsRetriedInNextBeginFrameForImplThread) { 290 TestFailedDrawIsRetriedInNextBeginFrameForImplThread) {
295 SchedulerSettings default_scheduler_settings; 291 SchedulerSettings default_scheduler_settings;
296 StateMachine state(default_scheduler_settings); 292 StateMachine state(default_scheduler_settings);
297 state.SetCanStart(); 293 state.SetCanStart();
298 state.UpdateState(state.NextAction()); 294 state.UpdateState(state.NextAction());
299 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 295 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
300 state.SetVisible(true); 296 state.SetVisible(true);
301 state.SetCanDraw(true); 297 state.SetCanDraw(true);
302 298
303 // Start a draw. 299 // Start a draw.
304 state.SetNeedsRedraw(true); 300 state.SetNeedsRedraw(true);
305 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); 301 EXPECT_TRUE(state.BeginFrameNeededByImplThread());
306 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); 302 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
307 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 303 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
308 state.NextAction()); 304 state.OnBeginFrameDeadline();
309 EXPECT_TRUE(state.RedrawPending()); 305 EXPECT_TRUE(state.RedrawPending());
306 EXPECT_ACTION_UPDATE_STATE(
307 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
310 308
311 // Fail the draw. 309 // Fail the draw
312 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
313 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
314 state.DidDrawIfPossibleCompleted(false); 310 state.DidDrawIfPossibleCompleted(false);
311 EXPECT_ACTION_UPDATE_STATE(
312 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
313 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
315 EXPECT_TRUE(state.RedrawPending()); 314 EXPECT_TRUE(state.RedrawPending());
316 315
317 // We should not be trying to draw again now, but we have a commit pending. 316 // We should not be trying to draw again now, but we have a commit pending.
318 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, 317 EXPECT_TRUE(state.BeginFrameNeededByImplThread());
319 state.NextAction()); 318 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
319 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
320 320
321 state.DidLeaveBeginFrame(); 321 // We should try to draw again at the end of the next BeginFrame on
322 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread()); 322 // the impl thread.
323 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); 323 state.OnBeginFrameDeadline();
324 324 EXPECT_ACTION_UPDATE_STATE(
325 // We should try to draw again in the next begin frame on the impl thread. 325 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
326 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 326 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
327 state.NextAction());
328 } 327 }
329 328
330 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) { 329 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) {
331 SchedulerSettings default_scheduler_settings; 330 SchedulerSettings default_scheduler_settings;
332 StateMachine state(default_scheduler_settings); 331 StateMachine state(default_scheduler_settings);
333 state.SetCanStart(); 332 state.SetCanStart();
334 state.UpdateState(state.NextAction()); 333 state.UpdateState(state.NextAction());
335 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 334 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
336 state.SetVisible(true); 335 state.SetVisible(true);
337 state.SetCanDraw(true); 336 state.SetCanDraw(true);
338 state.SetNeedsRedraw(true); 337 state.SetNeedsRedraw(true);
339 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread());
340 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting());
341 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
342 state.NextAction());
343 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
344 338
345 // While still in the same begin frame for the impl thread, set needs redraw 339 // Draw the first frame.
346 // again. This should not redraw. 340 EXPECT_TRUE(state.BeginFrameNeededByImplThread());
341 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
342 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
343
344 state.OnBeginFrameDeadline();
345 EXPECT_ACTION_UPDATE_STATE(
346 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
347 state.DidDrawIfPossibleCompleted(true);
348 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
349
350 // Before the next begin frame for the impl thread, set needs redraw
351 // again. This should not redraw until the next begin frame.
347 state.SetNeedsRedraw(true); 352 state.SetNeedsRedraw(true);
348 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 353 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
349 354
350 // Move to another frame. This should now draw. 355 // Move to another frame. This should now draw.
356 EXPECT_TRUE(state.BeginFrameNeededByImplThread());
357 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
358
359 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
360
361 state.OnBeginFrameDeadline();
362 EXPECT_ACTION_UPDATE_STATE(
363 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
351 state.DidDrawIfPossibleCompleted(true); 364 state.DidDrawIfPossibleCompleted(true);
352 state.DidLeaveBeginFrame(); 365 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
353 EXPECT_TRUE(state.BeginFrameNeededToDrawByImplThread());
354 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting());
355 366
356 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 367 // We just swapped, so we should proactively request another BeginFrame.
357 state.NextAction()); 368 EXPECT_TRUE(state.BeginFrameNeededByImplThread());
358 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
359 state.DidDrawIfPossibleCompleted(true);
360 EXPECT_FALSE(state.BeginFrameNeededToDrawByImplThread());
361 } 369 }
362 370
363 TEST(SchedulerStateMachineTest, TestNextActionDrawsOnBeginFrame) { 371 TEST(SchedulerStateMachineTest, TestNextActionDrawsOnBeginFrame) {
364 SchedulerSettings default_scheduler_settings; 372 SchedulerSettings default_scheduler_settings;
365 373
366 // When not in BeginFrame, or in BeginFrame but not visible, 374 // When not in BeginFrame deadline, or in BeginFrame deadline but not visible,
367 // don't draw. 375 // don't draw.
368 size_t num_commit_states = 376 size_t num_commit_states =
369 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); 377 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState);
378 size_t num_begin_frame_states =
379 sizeof(all_begin_frame_states) /
380 sizeof(SchedulerStateMachine::BeginFrameState);
370 for (size_t i = 0; i < num_commit_states; ++i) { 381 for (size_t i = 0; i < num_commit_states; ++i) {
371 for (size_t j = 0; j < 2; ++j) { 382 for (size_t j = 0; j < num_begin_frame_states; ++j) {
372 StateMachine state(default_scheduler_settings); 383 StateMachine state(default_scheduler_settings);
373 state.SetCanStart(); 384 state.SetCanStart();
374 state.UpdateState(state.NextAction()); 385 state.UpdateState(state.NextAction());
375 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 386 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
376 state.SetCommitState(all_commit_states[i]); 387 state.SetCommitState(all_commit_states[i]);
377 bool visible = j; 388 state.SetBeginFrameState(all_begin_frame_states[j]);
378 if (!visible) { 389 bool visible = (all_begin_frame_states[j] !=
379 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); 390 SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_DEADLINE);
380 state.SetVisible(false); 391 state.SetVisible(visible);
381 } else {
382 state.SetVisible(true);
383 }
384 392
385 // Case 1: needs_commit=false 393 // Case 1: needs_commit=false
386 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 394 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
387 state.NextAction()); 395 state.NextAction());
388 396
389 // Case 2: needs_commit=true 397 // Case 2: needs_commit=true
390 state.SetNeedsCommit(); 398 state.SetNeedsCommit();
391 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 399 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
392 state.NextAction()); 400 state.NextAction())
401 << *state.AsValue();
393 } 402 }
394 } 403 }
395 404
396 // When in BeginFrame, or not in BeginFrame but needs_forced_dedraw 405 // When in BeginFrame deadline we should always draw for SetNeedsRedraw or
397 // set, should always draw except if you're ready to commit, in which case 406 // SetNeedsForcedRedrawForReadback have been called... except if we're
398 // commit. 407 // ready to commit, in which case we expect a commit first.
399 for (size_t i = 0; i < num_commit_states; ++i) { 408 for (size_t i = 0; i < num_commit_states; ++i) {
400 for (size_t j = 0; j < 2; ++j) { 409 for (size_t j = 0; j < 2; ++j) {
401 bool request_readback = j; 410 bool request_readback = j;
402 411
403 // Skip invalid states 412 // Skip invalid states
404 if (request_readback && 413 if (request_readback &&
405 (SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW != 414 (SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW !=
406 all_commit_states[i])) 415 all_commit_states[i]))
407 continue; 416 continue;
408 417
409 StateMachine state(default_scheduler_settings); 418 StateMachine state(default_scheduler_settings);
410 state.SetCanStart(); 419 state.SetCanStart();
411 state.UpdateState(state.NextAction()); 420 state.UpdateState(state.NextAction());
412 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 421 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
413 state.SetCanDraw(true); 422 state.SetCanDraw(true);
414 state.SetCommitState(all_commit_states[i]); 423 state.SetCommitState(all_commit_states[i]);
415 if (!request_readback) { 424 state.SetBeginFrameState(
416 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); 425 SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_DEADLINE);
426 if (request_readback) {
427 state.SetNeedsForcedRedrawForReadback();
428 } else {
417 state.SetNeedsRedraw(true); 429 state.SetNeedsRedraw(true);
418 state.SetVisible(true); 430 state.SetVisible(true);
419 } else {
420 state.SetNeedsForcedRedrawForReadback();
421 } 431 }
422 432
423 SchedulerStateMachine::Action expected_action; 433 SchedulerStateMachine::Action expected_action;
424 if (all_commit_states[i] != 434 if (all_commit_states[i] ==
425 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) { 435 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) {
436 expected_action = SchedulerStateMachine::ACTION_COMMIT;
437 } else if (request_readback) {
438 if (all_commit_states[i] ==
439 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW)
440 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_READBACK;
441 else
442 expected_action = SchedulerStateMachine::ACTION_NONE;
443 } else {
426 expected_action = 444 expected_action =
427 request_readback 445 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE;
428 ? SchedulerStateMachine::ACTION_DRAW_AND_READBACK
429 : SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE;
430 } else {
431 expected_action = SchedulerStateMachine::ACTION_COMMIT;
432 } 446 }
433 447
434 // Case 1: needs_commit=false. 448 // Case 1: needs_commit=false.
435 EXPECT_NE(state.BeginFrameNeededToDrawByImplThread(), request_readback) 449 EXPECT_NE(state.BeginFrameNeededByImplThread(), request_readback)
436 << *state.AsValue(); 450 << *state.AsValue();
437 EXPECT_EQ(expected_action, state.NextAction()) << *state.AsValue(); 451 EXPECT_EQ(expected_action, state.NextAction()) << *state.AsValue();
438 452
439 // Case 2: needs_commit=true. 453 // Case 2: needs_commit=true.
440 state.SetNeedsCommit(); 454 state.SetNeedsCommit();
441 EXPECT_NE(state.BeginFrameNeededToDrawByImplThread(), request_readback) 455 EXPECT_NE(state.BeginFrameNeededByImplThread(), request_readback)
442 << *state.AsValue(); 456 << *state.AsValue();
443 EXPECT_EQ(expected_action, state.NextAction()) << *state.AsValue(); 457 EXPECT_EQ(expected_action, state.NextAction()) << *state.AsValue();
444 } 458 }
445 } 459 }
446 } 460 }
447 461
448 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) { 462 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) {
449 SchedulerSettings default_scheduler_settings; 463 SchedulerSettings default_scheduler_settings;
450 464
451 size_t num_commit_states = 465 size_t num_commit_states =
452 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); 466 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState);
453 for (size_t i = 0; i < num_commit_states; ++i) { 467 for (size_t i = 0; i < num_commit_states; ++i) {
454 // There shouldn't be any drawing regardless of BeginFrame. 468 // There shouldn't be any drawing regardless of BeginFrame.
455 for (size_t j = 0; j < 2; ++j) { 469 for (size_t j = 0; j < 2; ++j) {
456 StateMachine state(default_scheduler_settings); 470 StateMachine state(default_scheduler_settings);
457 state.SetCanStart(); 471 state.SetCanStart();
458 state.UpdateState(state.NextAction()); 472 state.UpdateState(state.NextAction());
459 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 473 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
460 state.SetCommitState(all_commit_states[i]); 474 state.SetCommitState(all_commit_states[i]);
461 state.SetVisible(false); 475 state.SetVisible(false);
462 state.SetNeedsRedraw(true); 476 state.SetNeedsRedraw(true);
463 if (j == 1) 477 if (j == 1) {
464 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); 478 state.SetBeginFrameState(
479 SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_DEADLINE);
480 }
465 481
466 // Case 1: needs_commit=false. 482 // Case 1: needs_commit=false.
467 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 483 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
468 state.NextAction()); 484 state.NextAction());
469 485
470 // Case 2: needs_commit=true. 486 // Case 2: needs_commit=true.
471 state.SetNeedsCommit(); 487 state.SetNeedsCommit();
472 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 488 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
473 state.NextAction()); 489 state.NextAction())
490 << *state.AsValue();
474 } 491 }
475 } 492 }
476 } 493 }
477 494
478 TEST(SchedulerStateMachineTest, TestCanRedraw_StopsDraw) { 495 TEST(SchedulerStateMachineTest, TestCanRedraw_StopsDraw) {
479 SchedulerSettings default_scheduler_settings; 496 SchedulerSettings default_scheduler_settings;
480 497
481 size_t num_commit_states = 498 size_t num_commit_states =
482 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); 499 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState);
483 for (size_t i = 0; i < num_commit_states; ++i) { 500 for (size_t i = 0; i < num_commit_states; ++i) {
484 // There shouldn't be any drawing regardless of BeginFrame. 501 // There shouldn't be any drawing regardless of BeginFrame.
485 for (size_t j = 0; j < 2; ++j) { 502 for (size_t j = 0; j < 2; ++j) {
486 StateMachine state(default_scheduler_settings); 503 StateMachine state(default_scheduler_settings);
487 state.SetCanStart(); 504 state.SetCanStart();
488 state.UpdateState(state.NextAction()); 505 state.UpdateState(state.NextAction());
489 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 506 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
490 state.SetCommitState(all_commit_states[i]); 507 state.SetCommitState(all_commit_states[i]);
491 state.SetVisible(false); 508 state.SetVisible(false);
492 state.SetNeedsRedraw(true); 509 state.SetNeedsRedraw(true);
493 if (j == 1) 510 if (j == 1)
494 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); 511 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
495 512
496 state.SetCanDraw(false); 513 state.SetCanDraw(false);
497 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 514 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
498 state.NextAction()); 515 state.NextAction());
499 } 516 }
500 } 517 }
501 } 518 }
502 519
503 TEST(SchedulerStateMachineTest, 520 TEST(SchedulerStateMachineTest,
504 TestCanRedrawWithWaitingForFirstDrawMakesProgress) { 521 TestCanRedrawWithWaitingForFirstDrawMakesProgress) {
505 SchedulerSettings default_scheduler_settings; 522 SchedulerSettings default_scheduler_settings;
506 StateMachine state(default_scheduler_settings); 523 StateMachine state(default_scheduler_settings);
507 state.SetCanStart(); 524 state.SetCanStart();
508 state.UpdateState(state.NextAction()); 525 state.UpdateState(state.NextAction());
509 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 526 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
510 527
511 state.SetVisible(true); 528 state.SetCommitState(
512 state.SetNeedsCommit(); 529 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
513 EXPECT_ACTION_UPDATE_STATE( 530 state.SetActiveTreeNeedsFirstDraw(true);
514 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
515 state.FinishCommit();
516 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
517 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW,
518 state.CommitState());
519
520 state.SetNeedsCommit(); 531 state.SetNeedsCommit();
521 state.SetNeedsRedraw(true); 532 state.SetNeedsRedraw(true);
522 state.SetVisible(true); 533 state.SetVisible(true);
523 state.SetCanDraw(false); 534 state.SetCanDraw(false);
524 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT) 535 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
525 536 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
526 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting());
527 EXPECT_ACTION_UPDATE_STATE( 537 EXPECT_ACTION_UPDATE_STATE(
528 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); 538 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
529 state.DidLeaveBeginFrame(); 539 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
540 state.FinishCommit();
541 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
542 state.OnBeginFrameDeadline();
543 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
530 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 544 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
531 } 545 }
532 546
533 TEST(SchedulerStateMachineTest, TestsetNeedsCommitIsNotLost) { 547 TEST(SchedulerStateMachineTest, TestsetNeedsCommitIsNotLost) {
534 SchedulerSettings default_scheduler_settings; 548 SchedulerSettings default_scheduler_settings;
535 StateMachine state(default_scheduler_settings); 549 StateMachine state(default_scheduler_settings);
536 state.SetCanStart(); 550 state.SetCanStart();
537 state.UpdateState(state.NextAction()); 551 state.UpdateState(state.NextAction());
538 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 552 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
539 state.SetNeedsCommit(); 553 state.SetNeedsCommit();
540 state.SetVisible(true); 554 state.SetVisible(true);
541 state.SetCanDraw(true); 555 state.SetCanDraw(true);
542 556
557 EXPECT_TRUE(state.BeginFrameNeededByImplThread());
558
543 // Begin the frame. 559 // Begin the frame.
544 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, 560 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
545 state.NextAction()); 561 EXPECT_ACTION_UPDATE_STATE(
546 state.UpdateState(state.NextAction()); 562 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
547 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 563 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
548 state.CommitState()); 564 state.CommitState());
549 565
550 // Now, while the frame is in progress, set another commit. 566 // Now, while the frame is in progress, set another commit.
551 state.SetNeedsCommit(); 567 state.SetNeedsCommit();
552 EXPECT_TRUE(state.NeedsCommit()); 568 EXPECT_TRUE(state.NeedsCommit());
553 569
554 // Let the frame finish. 570 // Let the frame finish.
555 state.FinishCommit(); 571 state.FinishCommit();
556 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 572 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
557 state.CommitState()); 573 state.CommitState());
558 574
559 // Expect to commit regardless of BeginFrame state. 575 // Expect to commit regardless of BeginFrame state.
560 state.DidLeaveBeginFrame(); 576 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_BEGIN_FRAME_STARTING,
577 state.begin_frame_state());
561 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 578 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
562 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); 579
580 state.OnBeginFrameDeadlinePending();
581 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME,
582 state.begin_frame_state());
583 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
584
585 state.OnBeginFrameDeadline();
586 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_DEADLINE,
587 state.begin_frame_state());
588 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
589
590 state.OnBeginFrameIdle();
591 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_IDLE,
592 state.begin_frame_state());
593 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
594
595 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
596 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_BEGIN_FRAME_STARTING,
597 state.begin_frame_state());
563 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 598 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
564 599
565 // Commit and make sure we draw on next BeginFrame 600 // Commit and make sure we draw on next BeginFrame
566 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); 601 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
567 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 602 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
568 state.NextAction()); 603 state.OnBeginFrameDeadline();
569 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 604 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW,
570 state.CommitState()); 605 state.CommitState());
571 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 606 EXPECT_ACTION_UPDATE_STATE(
607 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
572 state.DidDrawIfPossibleCompleted(true); 608 state.DidDrawIfPossibleCompleted(true);
573 609
574 // Verify that another commit will begin. 610 // Verify that another commit will start immediately after draw.
575 state.DidLeaveBeginFrame(); 611 EXPECT_ACTION_UPDATE_STATE(
576 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, 612 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
577 state.NextAction()); 613 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
578 } 614 }
579 615
580 TEST(SchedulerStateMachineTest, TestFullCycle) { 616 TEST(SchedulerStateMachineTest, TestFullCycle) {
581 SchedulerSettings default_scheduler_settings; 617 SchedulerSettings default_scheduler_settings;
582 StateMachine state(default_scheduler_settings); 618 StateMachine state(default_scheduler_settings);
583 state.SetCanStart(); 619 state.SetCanStart();
584 state.UpdateState(state.NextAction()); 620 state.UpdateState(state.NextAction());
585 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 621 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
586 state.SetVisible(true); 622 state.SetVisible(true);
587 state.SetCanDraw(true); 623 state.SetCanDraw(true);
588 624
589 // Start clean and set commit. 625 // Start clean and set commit.
590 state.SetNeedsCommit(); 626 state.SetNeedsCommit();
591 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
592 state.NextAction());
593 627
594 // Begin the frame. 628 // Begin the frame.
595 state.UpdateState( 629 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
630 EXPECT_ACTION_UPDATE_STATE(
596 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); 631 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
597 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 632 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
598 state.CommitState()); 633 state.CommitState());
599 EXPECT_FALSE(state.NeedsCommit()); 634 EXPECT_FALSE(state.NeedsCommit());
600 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 635 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
601 636
602 // Tell the scheduler the frame finished. 637 // Tell the scheduler the frame finished.
603 state.FinishCommit(); 638 state.FinishCommit();
604 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 639 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
605 state.CommitState()); 640 state.CommitState());
606 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
607 641
608 // Commit. 642 // Commit.
609 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); 643 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
610 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 644 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW,
611 state.CommitState()); 645 state.CommitState());
612 EXPECT_TRUE(state.NeedsRedraw()); 646 EXPECT_TRUE(state.NeedsRedraw());
613 647
614 // Expect to do nothing until BeginFrame. 648 // Expect to do nothing until BeginFrame deadline
615 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 649 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
616 650
617 // At BeginFrame, draw. 651 // At BeginFrame deadline, draw.
618 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); 652 state.OnBeginFrameDeadline();
619 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 653 EXPECT_ACTION_UPDATE_STATE(
620 state.NextAction()); 654 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
621 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
622 state.DidDrawIfPossibleCompleted(true); 655 state.DidDrawIfPossibleCompleted(true);
623 state.DidLeaveBeginFrame();
624 656
625 // Should be synchronized, no draw needed, no action needed. 657 // Should be synchronized, no draw needed, no action needed.
658 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
626 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 659 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
627 EXPECT_FALSE(state.NeedsRedraw()); 660 EXPECT_FALSE(state.NeedsRedraw());
628 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
629 } 661 }
630 662
631 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) { 663 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) {
632 SchedulerSettings default_scheduler_settings; 664 SchedulerSettings default_scheduler_settings;
633 StateMachine state(default_scheduler_settings); 665 StateMachine state(default_scheduler_settings);
634 state.SetCanStart(); 666 state.SetCanStart();
635 state.UpdateState(state.NextAction()); 667 state.UpdateState(state.NextAction());
636 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 668 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
637 state.SetVisible(true); 669 state.SetVisible(true);
638 state.SetCanDraw(true); 670 state.SetCanDraw(true);
639 671
640 // Start clean and set commit. 672 // Start clean and set commit.
641 state.SetNeedsCommit(); 673 state.SetNeedsCommit();
642 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
643 state.NextAction());
644 674
645 // Begin the frame. 675 // Begin the frame.
646 state.UpdateState( 676 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
677 EXPECT_ACTION_UPDATE_STATE(
647 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); 678 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
648 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 679 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
649 state.CommitState()); 680 state.CommitState());
650 EXPECT_FALSE(state.NeedsCommit()); 681 EXPECT_FALSE(state.NeedsCommit());
651 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 682 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
652 683
653 // Request another commit while the commit is in flight. 684 // Request another commit while the commit is in flight.
654 state.SetNeedsCommit(); 685 state.SetNeedsCommit();
655 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 686 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
656 687
657 // Tell the scheduler the frame finished. 688 // Tell the scheduler the frame finished.
658 state.FinishCommit(); 689 state.FinishCommit();
659 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 690 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
660 state.CommitState()); 691 state.CommitState());
661 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
662 692
663 // Commit. 693 // First commit.
664 state.UpdateState(SchedulerStateMachine::ACTION_COMMIT); 694 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
665 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 695 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW,
666 state.CommitState()); 696 state.CommitState());
667 EXPECT_TRUE(state.NeedsRedraw()); 697 EXPECT_TRUE(state.NeedsRedraw());
668 698
669 // Expect to do nothing until BeginFrame. 699 // Expect to do nothing until BeginFrame deadline.
670 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 700 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
671 701
672 // At BeginFrame, draw. 702 // At BeginFrame deadline, draw.
673 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); 703 state.OnBeginFrameDeadline();
674 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 704 EXPECT_ACTION_UPDATE_STATE(
675 state.NextAction()); 705 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
676 state.UpdateState(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
677 state.DidDrawIfPossibleCompleted(true); 706 state.DidDrawIfPossibleCompleted(true);
678 state.DidLeaveBeginFrame();
679 707
680 // Should be synchronized, no draw needed, no action needed. 708 // Should be synchronized, no draw needed, no action needed.
709 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
681 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 710 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
682 EXPECT_FALSE(state.NeedsRedraw()); 711 EXPECT_FALSE(state.NeedsRedraw());
683 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, 712
684 state.NextAction()); 713 // Next BeginFrame should initiate second commit.
714 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
715 EXPECT_ACTION_UPDATE_STATE(
716 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
685 } 717 }
686 718
687 TEST(SchedulerStateMachineTest, TestRequestCommitInvisible) { 719 TEST(SchedulerStateMachineTest, TestRequestCommitInvisible) {
688 SchedulerSettings default_scheduler_settings; 720 SchedulerSettings default_scheduler_settings;
689 StateMachine state(default_scheduler_settings); 721 StateMachine state(default_scheduler_settings);
690 state.SetCanStart(); 722 state.SetCanStart();
691 state.UpdateState(state.NextAction()); 723 state.UpdateState(state.NextAction());
692 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 724 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
693 state.SetNeedsCommit(); 725 state.SetNeedsCommit();
694 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 726 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
695 } 727 }
696 728
697 TEST(SchedulerStateMachineTest, TestGoesInvisibleBeforeFinishCommit) { 729 TEST(SchedulerStateMachineTest, TestGoesInvisibleBeforeFinishCommit) {
698 SchedulerSettings default_scheduler_settings; 730 SchedulerSettings default_scheduler_settings;
699 StateMachine state(default_scheduler_settings); 731 StateMachine state(default_scheduler_settings);
700 state.SetCanStart(); 732 state.SetCanStart();
701 state.UpdateState(state.NextAction()); 733 state.UpdateState(state.NextAction());
702 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 734 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
703 state.SetVisible(true); 735 state.SetVisible(true);
704 state.SetCanDraw(true); 736 state.SetCanDraw(true);
705 737
706 // Start clean and set commit. 738 // Start clean and set commit.
707 state.SetNeedsCommit(); 739 state.SetNeedsCommit();
708 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
709 state.NextAction());
710 740
711 // Begin the frame while visible. 741 // Begin the frame while visible.
712 state.UpdateState( 742 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
743 EXPECT_ACTION_UPDATE_STATE(
713 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); 744 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
714 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 745 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
715 state.CommitState()); 746 state.CommitState());
716 EXPECT_FALSE(state.NeedsCommit()); 747 EXPECT_FALSE(state.NeedsCommit());
717 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 748 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
718 749
719 // Become invisible and abort the main thread's begin frame. 750 // Become invisible and abort the main thread's begin frame.
720 state.SetVisible(false); 751 state.SetVisible(false);
721 state.BeginFrameAbortedByMainThread(false); 752 state.BeginFrameAbortedByMainThread(false);
722 753
723 // We should now be back in the idle state as if we didn't start a frame at 754 // We should now be back in the idle state as if we never started the frame.
724 // all.
725 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 755 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
726 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 756 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
757
758 // We shouldn't do anything on the BeginFrame deadline.
759 state.OnBeginFrameDeadline();
760 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
727 761
728 // Become visible again. 762 // Become visible again.
729 state.SetVisible(true); 763 state.SetVisible(true);
730 764
731 // Although we have aborted on this frame and haven't cancelled the commit 765 // Although we have aborted on this frame and haven't cancelled the commit
732 // (i.e. need another), don't send another begin frame yet. 766 // (i.e. need another), don't send another begin frame yet.
733 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 767 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
734 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 768 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
735 EXPECT_TRUE(state.NeedsCommit()); 769 EXPECT_TRUE(state.NeedsCommit());
736 770
737 // Start a new frame. 771 // Start a new frame.
738 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); 772 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
739 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, 773 EXPECT_ACTION_UPDATE_STATE(
740 state.NextAction()); 774 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
741
742 // Begin the frame.
743 state.UpdateState(state.NextAction());
744 775
745 // We should be starting the commit now. 776 // We should be starting the commit now.
746 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 777 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
747 state.CommitState()); 778 state.CommitState());
779 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
748 } 780 }
749 781
750 TEST(SchedulerStateMachineTest, AbortBeginFrameAndCancelCommit) { 782 TEST(SchedulerStateMachineTest, AbortBeginFrameAndCancelCommit) {
751 SchedulerSettings default_scheduler_settings; 783 SchedulerSettings default_scheduler_settings;
752 StateMachine state(default_scheduler_settings); 784 StateMachine state(default_scheduler_settings);
753 state.SetCanStart(); 785 state.SetCanStart();
754 state.UpdateState(state.NextAction()); 786 state.UpdateState(state.NextAction());
755 state.DidCreateAndInitializeOutputSurface(); 787 state.DidCreateAndInitializeOutputSurface();
756 state.SetVisible(true); 788 state.SetVisible(true);
757 state.SetCanDraw(true); 789 state.SetCanDraw(true);
758 790
759 // Get into a begin frame / commit state. 791 // Get into a begin frame / commit state.
760 state.SetNeedsCommit(); 792 state.SetNeedsCommit();
761 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, 793
762 state.NextAction()); 794 EXPECT_ACTION_UPDATE_STATE(
763 state.UpdateState(
764 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); 795 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
765 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 796 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
766 state.CommitState()); 797 state.CommitState());
767 EXPECT_FALSE(state.NeedsCommit()); 798 EXPECT_FALSE(state.NeedsCommit());
768 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 799 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
769 800
770 // Abort the commit, cancelling future commits. 801 // Abort the commit, cancelling future commits.
771 state.BeginFrameAbortedByMainThread(true); 802 state.BeginFrameAbortedByMainThread(true);
772 803
773 // Verify that another commit doesn't start on the same frame. 804 // Verify that another commit doesn't start on the same frame.
774 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 805 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
775 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 806 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
776 EXPECT_FALSE(state.NeedsCommit()); 807 EXPECT_FALSE(state.NeedsCommit());
777 808
778 // Start a new frame; draw because this is the first frame since output 809 // Start a new frame; draw because this is the first frame since output
779 // surface init'd. 810 // surface init'd.
780 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); 811 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
781 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 812 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
782 state.NextAction()) 813 state.OnBeginFrameDeadline();
783 << *state.AsValue(); 814 EXPECT_ACTION_UPDATE_STATE(
784 state.DidLeaveBeginFrame(); 815 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
785 816
786 // Verify another commit doesn't start on another frame either. 817 // Verify another commit doesn't start on another frame either.
787 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 818 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
788 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 819 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
789 EXPECT_FALSE(state.NeedsCommit()); 820 EXPECT_FALSE(state.NeedsCommit());
790 821
791 // Verify another commit can start if requested, though. 822 // Verify another commit can start if requested, though.
792 state.SetNeedsCommit(); 823 state.SetNeedsCommit();
793 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 824 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
794 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, 825 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
795 state.NextAction()); 826 state.NextAction());
796 } 827 }
797 828
798 TEST(SchedulerStateMachineTest, TestFirstContextCreation) { 829 TEST(SchedulerStateMachineTest, TestFirstContextCreation) {
799 SchedulerSettings default_scheduler_settings; 830 SchedulerSettings default_scheduler_settings;
800 StateMachine state(default_scheduler_settings); 831 StateMachine state(default_scheduler_settings);
801 state.SetCanStart(); 832 state.SetCanStart();
802 state.SetVisible(true); 833 state.SetVisible(true);
803 state.SetCanDraw(true); 834 state.SetCanDraw(true);
804 835
805 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 836 EXPECT_ACTION_UPDATE_STATE(
806 state.NextAction()); 837 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
807 state.UpdateState(state.NextAction()); 838 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
808 state.DidCreateAndInitializeOutputSurface(); 839 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
809 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
810 840
811 // Check that the first init does not SetNeedsCommit. 841 // Check that the first init does not SetNeedsCommit.
842 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
843 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
844 state.OnBeginFrameDeadline();
845 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
846
847 // Check that a needs commit initiates a BeginFrame to the main thread.
812 state.SetNeedsCommit(); 848 state.SetNeedsCommit();
813 EXPECT_NE(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 849 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
850 EXPECT_ACTION_UPDATE_STATE(
851 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
814 } 852 }
815 853
816 TEST(SchedulerStateMachineTest, TestContextLostWhenCompletelyIdle) { 854 TEST(SchedulerStateMachineTest, TestContextLostWhenCompletelyIdle) {
817 SchedulerSettings default_scheduler_settings; 855 SchedulerSettings default_scheduler_settings;
818 StateMachine state(default_scheduler_settings); 856 StateMachine state(default_scheduler_settings);
819 state.SetCanStart(); 857 state.SetCanStart();
820 state.UpdateState(state.NextAction()); 858 state.UpdateState(state.NextAction());
821 state.DidCreateAndInitializeOutputSurface(); 859 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
822 860
823 state.SetVisible(true); 861 state.SetVisible(true);
824 state.SetCanDraw(true); 862 state.SetCanDraw(true);
825 863
826 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 864 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
827 state.NextAction()); 865 state.NextAction());
828 state.DidLoseOutputSurface(); 866 state.DidLoseOutputSurface();
829 867
830 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 868 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
831 state.NextAction()); 869 state.NextAction());
832 state.UpdateState(state.NextAction()); 870 state.UpdateState(state.NextAction());
833 871
834 // Once context recreation begins, nothing should happen. 872 // Once context recreation begins, nothing should happen.
835 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 873 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
836 874
837 // Recreate the context. 875 // Recreate the context.
838 state.DidCreateAndInitializeOutputSurface(); 876 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
839 877
840 // When the context is recreated, we should begin a commit. 878 // When the context is recreated, we should begin a commit.
841 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, 879 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
842 state.NextAction()); 880 EXPECT_ACTION_UPDATE_STATE(
843 state.UpdateState(state.NextAction()); 881 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
844 } 882 }
845 883
846 TEST(SchedulerStateMachineTest, 884 TEST(SchedulerStateMachineTest,
847 TestContextLostWhenIdleAndCommitRequestedWhileRecreating) { 885 TestContextLostWhenIdleAndCommitRequestedWhileRecreating) {
848 SchedulerSettings default_scheduler_settings; 886 SchedulerSettings default_scheduler_settings;
849 StateMachine state(default_scheduler_settings); 887 StateMachine state(default_scheduler_settings);
850 state.SetCanStart(); 888 state.SetCanStart();
851 state.UpdateState(state.NextAction()); 889 state.UpdateState(state.NextAction());
852 state.DidCreateAndInitializeOutputSurface(); 890 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
853 state.SetVisible(true); 891 state.SetVisible(true);
854 state.SetCanDraw(true); 892 state.SetCanDraw(true);
855 893
856 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 894 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
857 state.NextAction()); 895 state.NextAction());
858 state.DidLoseOutputSurface(); 896 state.DidLoseOutputSurface();
859 897
860 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 898 EXPECT_ACTION_UPDATE_STATE(
861 state.NextAction()); 899 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
862 state.UpdateState(state.NextAction()); 900 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
863 901
864 // Once context recreation begins, nothing should happen. 902 // Once context recreation begins, nothing should happen.
865 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 903 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
904 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
905 state.OnBeginFrameDeadline();
906 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
866 907
867 // While context is recreating, commits shouldn't begin. 908 // While context is recreating, commits shouldn't begin.
868 state.SetNeedsCommit(); 909 state.SetNeedsCommit();
869 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 910 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
911 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
912 state.OnBeginFrameDeadline();
913 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
870 914
871 // Recreate the context 915 // Recreate the context
872 state.DidCreateAndInitializeOutputSurface(); 916 state.DidCreateAndInitializeOutputSurface();
873 EXPECT_FALSE(state.RedrawPending()); 917 EXPECT_FALSE(state.RedrawPending());
874 918
875 // When the context is recreated, we should begin a commit 919 // When the context is recreated, we should begin a commit
876 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, 920 EXPECT_ACTION_UPDATE_STATE(
877 state.NextAction()); 921 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
878 state.UpdateState(state.NextAction()); 922 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
879 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 923 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
880 state.CommitState()); 924 state.CommitState());
881 state.FinishCommit(); 925 state.FinishCommit();
882 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 926 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
883 state.UpdateState(state.NextAction()); 927 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
884 // Finishing the first commit after initializing an output surface should 928 // Finishing the first commit after initializing an output surface should
885 // automatically cause a redraw. 929 // automatically cause a redraw.
886 EXPECT_TRUE(state.RedrawPending()); 930 EXPECT_TRUE(state.RedrawPending());
887 931
888 // Once the context is recreated, whether we draw should be based on 932 // Once the context is recreated, whether we draw should be based on
889 // SetCanDraw. 933 // SetCanDraw.
890 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); 934 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
935 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
936 state.OnBeginFrameDeadline();
891 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 937 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
892 state.NextAction()); 938 state.NextAction());
893 state.SetCanDraw(false); 939 state.SetCanDraw(false);
894 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT, 940 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT,
895 state.NextAction()); 941 state.NextAction());
896 state.SetCanDraw(true); 942 state.SetCanDraw(true);
897 state.DidLeaveBeginFrame(); 943 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
944 state.NextAction());
898 } 945 }
899 946
900 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) { 947 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) {
901 SchedulerSettings default_scheduler_settings; 948 SchedulerSettings default_scheduler_settings;
902 StateMachine state(default_scheduler_settings); 949 StateMachine state(default_scheduler_settings);
903 state.SetCanStart(); 950 state.SetCanStart();
904 state.UpdateState(state.NextAction()); 951 state.UpdateState(state.NextAction());
905 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 952 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
906 state.SetVisible(true); 953 state.SetVisible(true);
907 state.SetCanDraw(true); 954 state.SetCanDraw(true);
908 955
909 // Get a commit in flight. 956 // Get a commit in flight.
910 state.SetNeedsCommit(); 957 state.SetNeedsCommit();
911 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, 958 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
912 state.NextAction());
913 state.UpdateState(state.NextAction());
914 959
915 // Set damage and expect a draw. 960 // Set damage and expect a draw.
916 state.SetNeedsRedraw(true); 961 state.SetNeedsRedraw(true);
917 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); 962 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
918 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 963 EXPECT_ACTION_UPDATE_STATE(
919 state.NextAction()); 964 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
920 state.UpdateState(state.NextAction()); 965 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
921 state.DidLeaveBeginFrame(); 966 state.OnBeginFrameDeadline();
967 EXPECT_ACTION_UPDATE_STATE(
968 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
969 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
922 970
923 // Cause a lost context while the begin frame is in flight 971 // Cause a lost context while the begin frame is in flight
924 // for the main thread. 972 // for the main thread.
925 state.DidLoseOutputSurface(); 973 state.DidLoseOutputSurface();
926 974
927 // Ask for another draw. Expect nothing happens. 975 // Ask for another draw. Expect nothing happens.
928 state.SetNeedsRedraw(true); 976 state.SetNeedsRedraw(true);
929 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 977 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
930 978
931 // Finish the frame, and commit. 979 // Finish the frame, and commit.
932 state.FinishCommit(); 980 state.FinishCommit();
933 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 981 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
934 state.UpdateState(state.NextAction());
935 982
983 // We will abort the draw when the output surface is lost if we are
984 // waiting for the first draw to unblock the main thread.
936 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 985 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW,
937 state.CommitState()); 986 state.CommitState());
938 987 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
939 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT,
940 state.NextAction());
941 state.UpdateState(state.NextAction());
942 988
943 // Expect to be told to begin context recreation, independent of 989 // Expect to be told to begin context recreation, independent of
944 // BeginFrame state. 990 // BeginFrame state.
945 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); 991 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_IDLE,
992 state.begin_frame_state());
946 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 993 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
947 state.NextAction()); 994 state.NextAction());
948 state.DidLeaveBeginFrame(); 995
996 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
997 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_BEGIN_FRAME_STARTING,
998 state.begin_frame_state());
999 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1000 state.NextAction());
1001
1002 state.OnBeginFrameDeadlinePending();
1003 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME,
1004 state.begin_frame_state());
1005 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1006 state.NextAction());
1007
1008 state.OnBeginFrameDeadline();
1009 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_DEADLINE,
1010 state.begin_frame_state());
949 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1011 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
950 state.NextAction()); 1012 state.NextAction());
951 } 1013 }
952 1014
953 TEST(SchedulerStateMachineTest, 1015 TEST(SchedulerStateMachineTest,
954 TestContextLostWhileCommitInProgressAndAnotherCommitRequested) { 1016 TestContextLostWhileCommitInProgressAndAnotherCommitRequested) {
955 SchedulerSettings default_scheduler_settings; 1017 SchedulerSettings default_scheduler_settings;
956 StateMachine state(default_scheduler_settings); 1018 StateMachine state(default_scheduler_settings);
957 state.SetCanStart(); 1019 state.SetCanStart();
958 state.UpdateState(state.NextAction()); 1020 state.UpdateState(state.NextAction());
959 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1021 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
960 state.SetVisible(true); 1022 state.SetVisible(true);
961 state.SetCanDraw(true); 1023 state.SetCanDraw(true);
962 1024
963 // Get a commit in flight. 1025 // Get a commit in flight.
964 state.SetNeedsCommit(); 1026 state.SetNeedsCommit();
965 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, 1027 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
966 state.NextAction());
967 state.UpdateState(state.NextAction());
968 1028
969 // Set damage and expect a draw. 1029 // Set damage and expect a draw.
970 state.SetNeedsRedraw(true); 1030 state.SetNeedsRedraw(true);
971 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); 1031 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
972 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 1032 EXPECT_ACTION_UPDATE_STATE(
973 state.NextAction()); 1033 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
974 state.UpdateState(state.NextAction()); 1034 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
975 state.DidLeaveBeginFrame(); 1035 state.OnBeginFrameDeadline();
1036 EXPECT_ACTION_UPDATE_STATE(
1037 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1038 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
976 1039
977 // Cause a lost context while the begin frame is in flight 1040 // Cause a lost context while the begin frame is in flight
978 // for the main thread. 1041 // for the main thread.
979 state.DidLoseOutputSurface(); 1042 state.DidLoseOutputSurface();
980 1043
981 // Ask for another draw and also set needs commit. Expect nothing happens. 1044 // Ask for another draw and also set needs commit. Expect nothing happens.
982 state.SetNeedsRedraw(true); 1045 state.SetNeedsRedraw(true);
983 state.SetNeedsCommit(); 1046 state.SetNeedsCommit();
984 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1047 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
985 1048
986 // Finish the frame, and commit. 1049 // Finish the frame, and commit.
987 state.FinishCommit(); 1050 state.FinishCommit();
988 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 1051 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
989 state.UpdateState(state.NextAction());
990
991 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1052 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW,
992 state.CommitState()); 1053 state.CommitState());
993 1054
994 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT, 1055 // Because the output surface is missing, we expect the draw to abort.
995 state.NextAction()); 1056 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
996 state.UpdateState(state.NextAction());
997 1057
998 // Expect to be told to begin context recreation, independent of 1058 // Expect to be told to begin context recreation, independent of
999 // BeginFrame state 1059 // BeginFrame state
1000 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting()); 1060 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_IDLE,
1061 state.begin_frame_state());
1001 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1062 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1002 state.NextAction()); 1063 state.NextAction());
1003 state.DidLeaveBeginFrame(); 1064
1065 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
1066 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_BEGIN_FRAME_STARTING,
1067 state.begin_frame_state());
1004 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1068 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1005 state.NextAction()); 1069 state.NextAction());
1070
1071 state.OnBeginFrameDeadlinePending();
1072 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_BEGIN_FRAME,
1073 state.begin_frame_state());
1074 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1075 state.NextAction());
1076
1077 state.OnBeginFrameDeadline();
1078 EXPECT_EQ(SchedulerStateMachine::BEGIN_FRAME_STATE_INSIDE_DEADLINE,
1079 state.begin_frame_state());
1080 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1081 state.NextAction());
1082
1083 // After we get a new output surface, the commit flow should start.
1084 EXPECT_ACTION_UPDATE_STATE(
1085 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1086 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1087 state.OnBeginFrameIdle();
1088 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
1089 EXPECT_ACTION_UPDATE_STATE(
1090 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
1091 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1092 state.FinishCommit();
1093 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1094 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1095 state.OnBeginFrameDeadline();
1096 EXPECT_ACTION_UPDATE_STATE(
1097 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1098 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1006 } 1099 }
1007 1100
1008 TEST(SchedulerStateMachineTest, TestFinishAllRenderingWhileContextLost) { 1101 TEST(SchedulerStateMachineTest, TestFinishAllRenderingWhileContextLost) {
1009 SchedulerSettings default_scheduler_settings; 1102 SchedulerSettings default_scheduler_settings;
1010 StateMachine state(default_scheduler_settings); 1103 StateMachine state(default_scheduler_settings);
1011 state.SetCanStart(); 1104 state.SetCanStart();
1012 state.UpdateState(state.NextAction()); 1105 state.UpdateState(state.NextAction());
1013 state.DidCreateAndInitializeOutputSurface(); 1106 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1014 state.SetVisible(true); 1107 state.SetVisible(true);
1015 state.SetCanDraw(true); 1108 state.SetCanDraw(true);
1016 1109
1017 // Cause a lost context lost. 1110 // Cause a lost context lost.
1018 state.DidLoseOutputSurface(); 1111 state.DidLoseOutputSurface();
1019 1112
1020 // Ask a forced redraw and verify it ocurrs, even with a lost context, 1113 // Ask a forced redraw for readback and verify it ocurrs.
1021 // independent of the BeginFrame stae. 1114 state.SetCommitState(
1115 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
1022 state.SetNeedsForcedRedrawForReadback(); 1116 state.SetNeedsForcedRedrawForReadback();
1117 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
1023 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1118 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1119 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1024 1120
1025 // Forced redraws for readbacks need to be followed by a new commit 1121 // Forced redraws for readbacks need to be followed by a new commit
1026 // to replace the readback commit. 1122 // to replace the readback commit.
1027 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 1123 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
1028 state.CommitState()); 1124 state.CommitState());
1029 state.FinishCommit(); 1125 state.FinishCommit();
1030 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1126 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1031 1127
1032 // We don't yet have an output surface, so we the draw and swap should abort. 1128 // We don't yet have an output surface, so we the draw and swap should abort.
1033 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1129 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1034 1130
1035 // Expect to be told to begin context recreation, independent of 1131 // Expect to be told to begin context recreation, independent of
1036 // BeginFrame state. 1132 // BeginFrame state
1037 EXPECT_ACTION_UPDATE_STATE( 1133 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
1038 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 1134 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1135 state.NextAction());
1039 1136
1040 // Ask a readback and verify it ocurrs. 1137 state.OnBeginFrameDeadline();
1138 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1139 state.NextAction());
1140
1141 // Ask a readback and verify it occurs.
1142 state.SetCommitState(
1143 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
1041 state.SetNeedsForcedRedrawForReadback(); 1144 state.SetNeedsForcedRedrawForReadback();
1042 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_READBACK, 1145 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1043 state.NextAction()); 1146 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1044 } 1147 }
1045 1148
1046 TEST(SchedulerStateMachineTest, DontDrawBeforeCommitAfterLostOutputSurface) { 1149 TEST(SchedulerStateMachineTest, DontDrawBeforeCommitAfterLostOutputSurface) {
1047 SchedulerSettings default_scheduler_settings; 1150 SchedulerSettings default_scheduler_settings;
1048 StateMachine state(default_scheduler_settings); 1151 StateMachine state(default_scheduler_settings);
1049 state.SetCanStart(); 1152 state.SetCanStart();
1050 state.UpdateState(state.NextAction()); 1153 state.UpdateState(state.NextAction());
1051 state.DidCreateAndInitializeOutputSurface(); 1154 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1052 state.SetVisible(true); 1155 state.SetVisible(true);
1053 state.SetCanDraw(true); 1156 state.SetCanDraw(true);
1054 1157
1055 state.SetNeedsRedraw(true); 1158 state.SetNeedsRedraw(true);
1056 1159
1057 // Cause a lost output surface, and restore it. 1160 // Cause a lost output surface, and restore it.
1058 state.DidLoseOutputSurface(); 1161 state.DidLoseOutputSurface();
1059 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1162 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1060 state.NextAction()); 1163 state.NextAction());
1061 state.UpdateState(state.NextAction()); 1164 state.UpdateState(state.NextAction());
1062 state.DidCreateAndInitializeOutputSurface(); 1165 state.DidCreateAndInitializeOutputSurface();
1063 1166
1064 EXPECT_FALSE(state.RedrawPending()); 1167 EXPECT_FALSE(state.RedrawPending());
1168 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
1065 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, 1169 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
1066 state.NextAction()); 1170 state.NextAction());
1067 } 1171 }
1068 1172
1069 TEST(SchedulerStateMachineTest, 1173 TEST(SchedulerStateMachineTest,
1070 TestSendBeginFrameToMainThreadWhenInvisibleAndForceCommit) { 1174 TestSendBeginFrameToMainThreadWhenInvisibleAndForceCommit) {
1071 SchedulerSettings default_scheduler_settings; 1175 SchedulerSettings default_scheduler_settings;
1072 StateMachine state(default_scheduler_settings); 1176 StateMachine state(default_scheduler_settings);
1073 state.SetCanStart(); 1177 state.SetCanStart();
1074 state.UpdateState(state.NextAction()); 1178 state.UpdateState(state.NextAction());
1075 state.DidCreateAndInitializeOutputSurface(); 1179 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1076 state.SetVisible(false); 1180 state.SetVisible(false);
1077 state.SetNeedsCommit(); 1181 state.SetNeedsCommit();
1078 state.SetNeedsForcedCommitForReadback(); 1182 state.SetNeedsForcedCommitForReadback();
1079 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, 1183 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
1080 state.NextAction()); 1184 state.NextAction());
1081 } 1185 }
1082 1186
1083 TEST(SchedulerStateMachineTest, 1187 TEST(SchedulerStateMachineTest,
1084 TestSendBeginFrameToMainThreadWhenCanStartFalseAndForceCommit) { 1188 TestSendBeginFrameToMainThreadWhenCanStartFalseAndForceCommit) {
1085 SchedulerSettings default_scheduler_settings; 1189 SchedulerSettings default_scheduler_settings;
1086 StateMachine state(default_scheduler_settings); 1190 StateMachine state(default_scheduler_settings);
1087 state.SetVisible(true); 1191 state.SetVisible(true);
1088 state.SetCanDraw(true); 1192 state.SetCanDraw(true);
1089 state.SetNeedsCommit(); 1193 state.SetNeedsCommit();
1090 state.SetNeedsForcedCommitForReadback(); 1194 state.SetNeedsForcedCommitForReadback();
1091 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, 1195 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
1092 state.NextAction()); 1196 state.NextAction());
1093 } 1197 }
1094 1198
1095 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) { 1199 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) {
1096 SchedulerSettings default_scheduler_settings; 1200 SchedulerSettings default_scheduler_settings;
1097 StateMachine state(default_scheduler_settings); 1201 StateMachine state(default_scheduler_settings);
1098 state.SetCanStart(); 1202 state.SetCanStart();
1099 state.UpdateState(state.NextAction()); 1203 state.UpdateState(state.NextAction());
1100 state.DidCreateAndInitializeOutputSurface(); 1204 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1101 state.SetVisible(false); 1205 state.SetVisible(false);
1102 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); 1206 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS);
1103 state.SetNeedsCommit(); 1207 state.SetNeedsCommit();
1104 1208
1105 state.FinishCommit(); 1209 state.FinishCommit();
1106 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 1210 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
1107 state.UpdateState(state.NextAction()); 1211 state.UpdateState(state.NextAction());
1108 1212
1109 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1213 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW,
1110 state.CommitState()); 1214 state.CommitState());
1111 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT, 1215 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1112 state.NextAction());
1113 state.UpdateState(state.NextAction());
1114
1115 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1116 } 1216 }
1117 1217
1118 TEST(SchedulerStateMachineTest, TestFinishCommitWhenForcedCommitInProgress) { 1218 TEST(SchedulerStateMachineTest, TestFinishCommitWhenForcedCommitInProgress) {
1119 SchedulerSettings default_scheduler_settings; 1219 SchedulerSettings default_scheduler_settings;
1120 StateMachine state(default_scheduler_settings); 1220 StateMachine state(default_scheduler_settings);
1121 state.SetCanStart(); 1221 state.SetCanStart();
1122 state.UpdateState(state.NextAction()); 1222 state.UpdateState(state.NextAction());
1123 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1223 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1124 state.SetVisible(false); 1224 state.SetVisible(false);
1125 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); 1225 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS);
(...skipping 16 matching lines...) Expand all
1142 // The normal commit can then proceed. 1242 // The normal commit can then proceed.
1143 state.FinishCommit(); 1243 state.FinishCommit();
1144 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1244 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1145 } 1245 }
1146 1246
1147 TEST(SchedulerStateMachineTest, TestInitialActionsWhenContextLost) { 1247 TEST(SchedulerStateMachineTest, TestInitialActionsWhenContextLost) {
1148 SchedulerSettings default_scheduler_settings; 1248 SchedulerSettings default_scheduler_settings;
1149 StateMachine state(default_scheduler_settings); 1249 StateMachine state(default_scheduler_settings);
1150 state.SetCanStart(); 1250 state.SetCanStart();
1151 state.UpdateState(state.NextAction()); 1251 state.UpdateState(state.NextAction());
1152 state.DidCreateAndInitializeOutputSurface(); 1252 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1153 state.SetVisible(true); 1253 state.SetVisible(true);
1154 state.SetCanDraw(true); 1254 state.SetCanDraw(true);
1155 state.SetNeedsCommit(); 1255 state.SetNeedsCommit();
1156 state.DidLoseOutputSurface(); 1256 state.DidLoseOutputSurface();
1157 1257
1158 // When we are visible, we normally want to begin output surface creation 1258 // When we are visible, we normally want to begin output surface creation
1159 // as soon as possible. 1259 // as soon as possible.
1160 EXPECT_ACTION_UPDATE_STATE( 1260 EXPECT_ACTION_UPDATE_STATE(
1161 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 1261 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1162 1262
(...skipping 15 matching lines...) Expand all
1178 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, 1278 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
1179 state.NextAction()) 1279 state.NextAction())
1180 << *state.AsValue(); 1280 << *state.AsValue();
1181 } 1281 }
1182 1282
1183 TEST(SchedulerStateMachineTest, TestImmediateFinishCommit) { 1283 TEST(SchedulerStateMachineTest, TestImmediateFinishCommit) {
1184 SchedulerSettings default_scheduler_settings; 1284 SchedulerSettings default_scheduler_settings;
1185 StateMachine state(default_scheduler_settings); 1285 StateMachine state(default_scheduler_settings);
1186 state.SetCanStart(); 1286 state.SetCanStart();
1187 state.UpdateState(state.NextAction()); 1287 state.UpdateState(state.NextAction());
1188 state.DidCreateAndInitializeOutputSurface(); 1288 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1189 state.SetVisible(true); 1289 state.SetVisible(true);
1190 state.SetCanDraw(true); 1290 state.SetCanDraw(true);
1191 1291
1192 // Schedule a readback, commit it, draw it. 1292 // Schedule a readback, commit it, draw it.
1193 state.SetNeedsCommit(); 1293 state.SetNeedsCommit();
1194 state.SetNeedsForcedCommitForReadback(); 1294 state.SetNeedsForcedCommitForReadback();
1195 EXPECT_ACTION_UPDATE_STATE( 1295 EXPECT_ACTION_UPDATE_STATE(
1196 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); 1296 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
1197 state.FinishCommit(); 1297 state.FinishCommit();
1198 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 1298
1199 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 1299 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
1200 state.CommitState()); 1300 state.CommitState());
1201 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1301 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1202 1302
1203 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1303 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW,
1204 state.CommitState()); 1304 state.CommitState());
1205 1305
1206 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1306 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1207 state.DidDrawIfPossibleCompleted(true); 1307 state.DidDrawIfPossibleCompleted(true);
1308
1208 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1309 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1209 1310
1210 // Should be waiting for the normal begin frame from the main thread. 1311 // Should be waiting for the normal begin frame from the main thread.
1211 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 1312 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
1212 state.CommitState()); 1313 state.CommitState());
1213 } 1314 }
1214 1315
1215 TEST(SchedulerStateMachineTest, TestImmediateFinishCommitDuringCommit) { 1316 TEST(SchedulerStateMachineTest, TestImmediateFinishCommitDuringCommit) {
1216 SchedulerSettings default_scheduler_settings; 1317 SchedulerSettings default_scheduler_settings;
1217 StateMachine state(default_scheduler_settings); 1318 StateMachine state(default_scheduler_settings);
1218 state.SetCanStart(); 1319 state.SetCanStart();
1219 state.UpdateState(state.NextAction()); 1320 state.UpdateState(state.NextAction());
1220 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1321 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1221 state.SetVisible(true); 1322 state.SetVisible(true);
1222 state.SetCanDraw(true); 1323 state.SetCanDraw(true);
1223 1324
1224 // Start a normal commit. 1325 // Start a normal commit.
1225 state.SetNeedsCommit(); 1326 state.SetNeedsCommit();
1327 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1328
1329 // Schedule a readback, commit it, draw it.
1330 state.SetNeedsForcedCommitForReadback();
1226 EXPECT_ACTION_UPDATE_STATE( 1331 EXPECT_ACTION_UPDATE_STATE(
1227 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); 1332 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
1228
1229 // Schedule a readback, commit it, draw it.
1230 state.SetNeedsCommit();
1231 state.SetNeedsForcedCommitForReadback();
1232 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1233 state.FinishCommit(); 1333 state.FinishCommit();
1234 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 1334 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
1235 state.CommitState()); 1335 state.CommitState());
1236 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1336 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1237 1337
1238 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1338 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW,
1239 state.CommitState()); 1339 state.CommitState());
1240 1340
1241 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1341 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1242 state.DidDrawIfPossibleCompleted(true); 1342 state.DidDrawIfPossibleCompleted(true);
1243 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1343 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1244 1344
1245 // Should be waiting for the normal begin frame from the main thread. 1345 // Should be waiting for the normal begin frame from the main thread.
1246 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 1346 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
1247 state.CommitState()) 1347 state.CommitState())
1248 << *state.AsValue(); 1348 << *state.AsValue();
1249 } 1349 }
1250 1350
1251 TEST(SchedulerStateMachineTest, 1351 TEST(SchedulerStateMachineTest,
1252 ImmediateBeginFrameAbortedByMainThreadWhileInvisible) { 1352 ImmediateBeginFrameAbortedByMainThreadWhileInvisible) {
1253 SchedulerSettings default_scheduler_settings; 1353 SchedulerSettings default_scheduler_settings;
1254 StateMachine state(default_scheduler_settings); 1354 StateMachine state(default_scheduler_settings);
1255 state.SetCanStart(); 1355 state.SetCanStart();
1256 state.UpdateState(state.NextAction()); 1356 state.UpdateState(state.NextAction());
1257 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1357 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1258 state.SetVisible(true); 1358 state.SetVisible(true);
1259 state.SetCanDraw(true); 1359 state.SetCanDraw(true);
1260 1360
1261 state.SetNeedsCommit(); 1361 state.SetNeedsCommit();
1262 EXPECT_ACTION_UPDATE_STATE( 1362 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1263 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
1264 1363
1265 state.SetNeedsCommit(); 1364 state.SetNeedsCommit();
1266 state.SetNeedsForcedCommitForReadback(); 1365 state.SetNeedsForcedCommitForReadback();
1267 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1366 EXPECT_ACTION_UPDATE_STATE(
1367 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
1268 state.FinishCommit(); 1368 state.FinishCommit();
1269 1369
1270 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 1370 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
1271 state.CommitState()); 1371 state.CommitState());
1272 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1372 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1273 1373
1274 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1374 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW,
1275 state.CommitState()); 1375 state.CommitState());
1276 1376
1277 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1377 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1353 SchedulerSettings default_scheduler_settings; 1453 SchedulerSettings default_scheduler_settings;
1354 StateMachine state(default_scheduler_settings); 1454 StateMachine state(default_scheduler_settings);
1355 state.SetCanStart(); 1455 state.SetCanStart();
1356 state.UpdateState(state.NextAction()); 1456 state.UpdateState(state.NextAction());
1357 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1457 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1358 state.SetCanDraw(true); 1458 state.SetCanDraw(true);
1359 state.SetVisible(true); 1459 state.SetVisible(true);
1360 EXPECT_FALSE(state.PendingDrawsShouldBeAborted()); 1460 EXPECT_FALSE(state.PendingDrawsShouldBeAborted());
1361 1461
1362 state.SetMainThreadNeedsLayerTextures(); 1462 state.SetMainThreadNeedsLayerTextures();
1363 EXPECT_EQ( 1463 EXPECT_ACTION_UPDATE_STATE(
1364 SchedulerStateMachine::ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD, 1464 SchedulerStateMachine::ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD);
1365 state.NextAction());
1366 state.UpdateState(state.NextAction());
1367 EXPECT_TRUE(state.PendingDrawsShouldBeAborted()); 1465 EXPECT_TRUE(state.PendingDrawsShouldBeAborted());
1466 EXPECT_TRUE(state.PendingActivationsShouldBeForced());
1467
1468 state.SetNeedsCommit();
1469 state.OnBeginFrame(BeginFrameArgs::CreateForTesting());
1470 EXPECT_ACTION_UPDATE_STATE(
1471 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
1472 EXPECT_TRUE(state.PendingDrawsShouldBeAborted());
1473 EXPECT_TRUE(state.PendingActivationsShouldBeForced());
1368 1474
1369 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1475 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1370 1476
1371 state.SetNeedsCommit();
1372 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
1373 state.NextAction());
1374
1375 state.UpdateState(state.NextAction());
1376 EXPECT_TRUE(state.PendingDrawsShouldBeAborted());
1377
1378 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1379
1380 state.FinishCommit(); 1477 state.FinishCommit();
1381 EXPECT_TRUE(state.PendingDrawsShouldBeAborted()); 1478 EXPECT_TRUE(state.PendingDrawsShouldBeAborted());
1382 1479
1383 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 1480 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
1384 1481
1385 state.UpdateState(state.NextAction()); 1482 state.UpdateState(state.NextAction());
1386 EXPECT_FALSE(state.PendingDrawsShouldBeAborted()); 1483 EXPECT_FALSE(state.PendingDrawsShouldBeAborted());
1387 } 1484 }
1388 1485
1389 TEST(SchedulerStateMachineTest, AcquireTexturesWithAbort) { 1486 TEST(SchedulerStateMachineTest, AcquireTexturesWithAbort) {
1390 SchedulerSettings default_scheduler_settings; 1487 SchedulerSettings default_scheduler_settings;
1391 SchedulerStateMachine state(default_scheduler_settings); 1488 StateMachine state(default_scheduler_settings);
1392 state.SetCanStart(); 1489 state.SetCanStart();
1393 state.UpdateState(state.NextAction()); 1490 state.UpdateState(state.NextAction());
1394 state.DidCreateAndInitializeOutputSurface(); 1491 state.DidCreateAndInitializeOutputSurface();
1395 state.SetCanDraw(true); 1492 state.SetCanDraw(true);
1396 state.SetVisible(true); 1493 state.SetVisible(true);
1397 1494
1398 state.SetMainThreadNeedsLayerTextures(); 1495 state.SetMainThreadNeedsLayerTextures();
1399 EXPECT_EQ( 1496 EXPECT_EQ(
1400 SchedulerStateMachine::ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD, 1497 SchedulerStateMachine::ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD,
1401 state.NextAction()); 1498 state.NextAction());
(...skipping 11 matching lines...) Expand all
1413 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1510 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1414 1511
1415 state.BeginFrameAbortedByMainThread(true); 1512 state.BeginFrameAbortedByMainThread(true);
1416 1513
1417 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1514 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1418 EXPECT_FALSE(state.PendingDrawsShouldBeAborted()); 1515 EXPECT_FALSE(state.PendingDrawsShouldBeAborted());
1419 } 1516 }
1420 1517
1421 } // namespace 1518 } // namespace
1422 } // namespace cc 1519 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698