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

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

Issue 275543004: Refactoring the debug creation of BeginFrameArgs objects to be in unittest code only. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removing stuff copied from output_test_common.h into output_test_common.cc Created 6 years, 7 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 | Annotate | Revision Log
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 "cc/test/output_test_common.h"
8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
9 10
10 #define EXPECT_ACTION_UPDATE_STATE(action) \ 11 #define EXPECT_ACTION_UPDATE_STATE(action) \
11 EXPECT_EQ(action, state.NextAction()) << *state.AsValue(); \ 12 EXPECT_EQ(action, state.NextAction()) << *state.AsValue(); \
12 if (action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE || \ 13 if (action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE || \
13 action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED) { \ 14 action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED) { \
14 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, \ 15 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, \
15 state.begin_impl_frame_state()) \ 16 state.begin_impl_frame_state()) \
16 << *state.AsValue(); \ 17 << *state.AsValue(); \
17 } \ 18 } \
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION) 125 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION)
125 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 126 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
126 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); 127 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE);
127 state.SetNeedsRedraw(false); 128 state.SetNeedsRedraw(false);
128 state.SetVisible(true); 129 state.SetVisible(true);
129 130
130 EXPECT_FALSE(state.BeginFrameNeeded()); 131 EXPECT_FALSE(state.BeginFrameNeeded());
131 132
132 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 133 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
133 EXPECT_FALSE(state.BeginFrameNeeded()); 134 EXPECT_FALSE(state.BeginFrameNeeded());
134 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 135 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
135 136
136 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 137 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
137 state.OnBeginImplFrameDeadline(); 138 state.OnBeginImplFrameDeadline();
138 } 139 }
139 140
140 // If commit requested but can_start is still false, do nothing. 141 // If commit requested but can_start is still false, do nothing.
141 { 142 {
142 StateMachine state(default_scheduler_settings); 143 StateMachine state(default_scheduler_settings);
143 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); 144 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE);
144 state.SetNeedsRedraw(false); 145 state.SetNeedsRedraw(false);
145 state.SetVisible(true); 146 state.SetVisible(true);
146 state.SetNeedsCommit(); 147 state.SetNeedsCommit();
147 148
148 EXPECT_FALSE(state.BeginFrameNeeded()); 149 EXPECT_FALSE(state.BeginFrameNeeded());
149 150
150 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 151 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
151 EXPECT_FALSE(state.BeginFrameNeeded()); 152 EXPECT_FALSE(state.BeginFrameNeeded());
152 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 153 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
153 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 154 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
154 state.OnBeginImplFrameDeadline(); 155 state.OnBeginImplFrameDeadline();
155 } 156 }
156 157
157 // If commit requested, begin a main frame. 158 // If commit requested, begin a main frame.
158 { 159 {
159 StateMachine state(default_scheduler_settings); 160 StateMachine state(default_scheduler_settings);
160 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); 161 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE);
161 state.SetCanStart(); 162 state.SetCanStart();
162 state.UpdateState(state.NextAction()); 163 state.UpdateState(state.NextAction());
163 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 164 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
164 state.SetNeedsRedraw(false); 165 state.SetNeedsRedraw(false);
165 state.SetVisible(true); 166 state.SetVisible(true);
166 state.SetNeedsCommit(); 167 state.SetNeedsCommit();
167 168
168 EXPECT_TRUE(state.BeginFrameNeeded()); 169 EXPECT_TRUE(state.BeginFrameNeeded());
169 170
170 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 171 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
171 EXPECT_ACTION_UPDATE_STATE( 172 EXPECT_ACTION_UPDATE_STATE(
172 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 173 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
173 } 174 }
174 175
175 // Begin the frame, make sure needs_commit and commit_state update correctly. 176 // Begin the frame, make sure needs_commit and commit_state update correctly.
176 { 177 {
177 StateMachine state(default_scheduler_settings); 178 StateMachine state(default_scheduler_settings);
178 state.SetCanStart(); 179 state.SetCanStart();
179 state.UpdateState(state.NextAction()); 180 state.UpdateState(state.NextAction());
180 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 181 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
(...skipping 16 matching lines...) Expand all
197 state.UpdateState(state.NextAction()); 198 state.UpdateState(state.NextAction());
198 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 199 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
199 state.SetNeedsRedraw(false); 200 state.SetNeedsRedraw(false);
200 state.SetVisible(true); 201 state.SetVisible(true);
201 state.SetCanDraw(true); 202 state.SetCanDraw(true);
202 state.SetNeedsCommit(); 203 state.SetNeedsCommit();
203 204
204 EXPECT_TRUE(state.BeginFrameNeeded()); 205 EXPECT_TRUE(state.BeginFrameNeeded());
205 206
206 // Commit to the pending tree. 207 // Commit to the pending tree.
207 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 208 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
208 EXPECT_ACTION_UPDATE_STATE( 209 EXPECT_ACTION_UPDATE_STATE(
209 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 210 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
210 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 211 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
211 state.NotifyBeginMainFrameStarted(); 212 state.NotifyBeginMainFrameStarted();
212 state.NotifyReadyToCommit(); 213 state.NotifyReadyToCommit();
213 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 214 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
214 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 215 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
215 EXPECT_EQ(state.CommitState(), 216 EXPECT_EQ(state.CommitState(),
216 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW); 217 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
217 218
218 state.OnBeginImplFrameDeadline(); 219 state.OnBeginImplFrameDeadline();
219 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 220 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
220 EXPECT_EQ(state.CommitState(), 221 EXPECT_EQ(state.CommitState(),
221 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW); 222 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
222 223
223 // Verify that the next commit doesn't start until the previous 224 // Verify that the next commit doesn't start until the previous
224 // commit has been drawn. 225 // commit has been drawn.
225 state.SetNeedsCommit(); 226 state.SetNeedsCommit();
226 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 227 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
227 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 228 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
228 229
229 // Verify NotifyReadyToActivate unblocks activation, draw, and 230 // Verify NotifyReadyToActivate unblocks activation, draw, and
230 // commit in that order. 231 // commit in that order.
231 state.NotifyReadyToActivate(); 232 state.NotifyReadyToActivate();
232 EXPECT_ACTION_UPDATE_STATE( 233 EXPECT_ACTION_UPDATE_STATE(
233 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE); 234 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE);
234 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 235 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
235 EXPECT_EQ(state.CommitState(), 236 EXPECT_EQ(state.CommitState(),
236 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW); 237 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
(...skipping 29 matching lines...) Expand all
266 state.UpdateState(state.NextAction()); 267 state.UpdateState(state.NextAction());
267 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 268 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
268 state.SetNeedsRedraw(false); 269 state.SetNeedsRedraw(false);
269 state.SetVisible(true); 270 state.SetVisible(true);
270 state.SetCanDraw(true); 271 state.SetCanDraw(true);
271 state.SetNeedsCommit(); 272 state.SetNeedsCommit();
272 273
273 EXPECT_TRUE(state.BeginFrameNeeded()); 274 EXPECT_TRUE(state.BeginFrameNeeded());
274 275
275 // Commit to the pending tree. 276 // Commit to the pending tree.
276 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 277 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
277 EXPECT_ACTION_UPDATE_STATE( 278 EXPECT_ACTION_UPDATE_STATE(
278 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 279 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
279 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 280 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
280 281
281 state.NotifyBeginMainFrameStarted(); 282 state.NotifyBeginMainFrameStarted();
282 state.NotifyReadyToCommit(); 283 state.NotifyReadyToCommit();
283 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 284 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
284 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 285 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
285 EXPECT_EQ(state.CommitState(), SchedulerStateMachine::COMMIT_STATE_IDLE); 286 EXPECT_EQ(state.CommitState(), SchedulerStateMachine::COMMIT_STATE_IDLE);
286 287
287 state.OnBeginImplFrameDeadline(); 288 state.OnBeginImplFrameDeadline();
288 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 289 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
289 290
290 // Verify that the next commit starts while there is still a pending tree. 291 // Verify that the next commit starts while there is still a pending tree.
291 state.SetNeedsCommit(); 292 state.SetNeedsCommit();
292 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 293 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
293 EXPECT_ACTION_UPDATE_STATE( 294 EXPECT_ACTION_UPDATE_STATE(
294 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 295 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
295 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 296 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
296 297
297 // Verify the pending commit doesn't overwrite the pending 298 // Verify the pending commit doesn't overwrite the pending
298 // tree until the pending tree has been activated. 299 // tree until the pending tree has been activated.
299 state.NotifyBeginMainFrameStarted(); 300 state.NotifyBeginMainFrameStarted();
300 state.NotifyReadyToCommit(); 301 state.NotifyReadyToCommit();
301 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 302 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
302 303
(...skipping 19 matching lines...) Expand all
322 SchedulerSettings default_scheduler_settings; 323 SchedulerSettings default_scheduler_settings;
323 StateMachine state(default_scheduler_settings); 324 StateMachine state(default_scheduler_settings);
324 state.SetCanStart(); 325 state.SetCanStart();
325 state.UpdateState(state.NextAction()); 326 state.UpdateState(state.NextAction());
326 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 327 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
327 state.SetVisible(true); 328 state.SetVisible(true);
328 state.SetCanDraw(true); 329 state.SetCanDraw(true);
329 state.SetNeedsRedraw(true); 330 state.SetNeedsRedraw(true);
330 EXPECT_TRUE(state.RedrawPending()); 331 EXPECT_TRUE(state.RedrawPending());
331 EXPECT_TRUE(state.BeginFrameNeeded()); 332 EXPECT_TRUE(state.BeginFrameNeeded());
332 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 333 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
333 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 334 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
334 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 335 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
335 state.OnBeginImplFrameDeadline(); 336 state.OnBeginImplFrameDeadline();
336 337
337 // We're drawing now. 338 // We're drawing now.
338 EXPECT_ACTION_UPDATE_STATE( 339 EXPECT_ACTION_UPDATE_STATE(
339 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 340 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
340 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 341 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
341 342
342 EXPECT_FALSE(state.RedrawPending()); 343 EXPECT_FALSE(state.RedrawPending());
343 EXPECT_FALSE(state.CommitPending()); 344 EXPECT_FALSE(state.CommitPending());
344 345
345 // Failing the draw makes us require a commit. 346 // Failing the draw makes us require a commit.
346 state.DidDrawIfPossibleCompleted( 347 state.DidDrawIfPossibleCompleted(
347 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 348 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
348 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 349 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
349 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 350 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
350 EXPECT_ACTION_UPDATE_STATE( 351 EXPECT_ACTION_UPDATE_STATE(
351 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 352 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
352 EXPECT_TRUE(state.RedrawPending()); 353 EXPECT_TRUE(state.RedrawPending());
353 EXPECT_TRUE(state.CommitPending()); 354 EXPECT_TRUE(state.CommitPending());
354 } 355 }
355 356
356 TEST(SchedulerStateMachineTest, TestFailedDrawForMissingHighResNeedsCommit) { 357 TEST(SchedulerStateMachineTest, TestFailedDrawForMissingHighResNeedsCommit) {
357 SchedulerSettings default_scheduler_settings; 358 SchedulerSettings default_scheduler_settings;
358 StateMachine state(default_scheduler_settings); 359 StateMachine state(default_scheduler_settings);
359 state.SetCanStart(); 360 state.SetCanStart();
360 state.UpdateState(state.NextAction()); 361 state.UpdateState(state.NextAction());
361 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 362 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
362 state.SetVisible(true); 363 state.SetVisible(true);
363 state.SetCanDraw(true); 364 state.SetCanDraw(true);
364 state.SetNeedsRedraw(true); 365 state.SetNeedsRedraw(true);
365 EXPECT_TRUE(state.RedrawPending()); 366 EXPECT_TRUE(state.RedrawPending());
366 EXPECT_TRUE(state.BeginFrameNeeded()); 367 EXPECT_TRUE(state.BeginFrameNeeded());
367 368
368 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 369 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
369 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 370 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
370 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 371 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
371 state.OnBeginImplFrameDeadline(); 372 state.OnBeginImplFrameDeadline();
372 EXPECT_ACTION_UPDATE_STATE( 373 EXPECT_ACTION_UPDATE_STATE(
373 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 374 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
374 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 375 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
375 EXPECT_FALSE(state.RedrawPending()); 376 EXPECT_FALSE(state.RedrawPending());
376 EXPECT_FALSE(state.CommitPending()); 377 EXPECT_FALSE(state.CommitPending());
377 378
378 // Missing high res content requires a commit (but not a redraw) 379 // Missing high res content requires a commit (but not a redraw)
379 state.DidDrawIfPossibleCompleted( 380 state.DidDrawIfPossibleCompleted(
380 DrawSwapReadbackResult::DRAW_ABORTED_MISSING_HIGH_RES_CONTENT); 381 DrawSwapReadbackResult::DRAW_ABORTED_MISSING_HIGH_RES_CONTENT);
381 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 382 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
382 EXPECT_ACTION_UPDATE_STATE( 383 EXPECT_ACTION_UPDATE_STATE(
383 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 384 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
384 EXPECT_FALSE(state.RedrawPending()); 385 EXPECT_FALSE(state.RedrawPending());
385 EXPECT_TRUE(state.CommitPending()); 386 EXPECT_TRUE(state.CommitPending());
386 } 387 }
387 388
388 TEST(SchedulerStateMachineTest, 389 TEST(SchedulerStateMachineTest,
389 TestsetNeedsRedrawDuringFailedDrawDoesNotRemoveNeedsRedraw) { 390 TestsetNeedsRedrawDuringFailedDrawDoesNotRemoveNeedsRedraw) {
390 SchedulerSettings default_scheduler_settings; 391 SchedulerSettings default_scheduler_settings;
391 StateMachine state(default_scheduler_settings); 392 StateMachine state(default_scheduler_settings);
392 state.SetCanStart(); 393 state.SetCanStart();
393 state.UpdateState(state.NextAction()); 394 state.UpdateState(state.NextAction());
394 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 395 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
395 396
396 state.SetVisible(true); 397 state.SetVisible(true);
397 state.SetCanDraw(true); 398 state.SetCanDraw(true);
398 state.SetNeedsRedraw(true); 399 state.SetNeedsRedraw(true);
399 EXPECT_TRUE(state.RedrawPending()); 400 EXPECT_TRUE(state.RedrawPending());
400 EXPECT_TRUE(state.BeginFrameNeeded()); 401 EXPECT_TRUE(state.BeginFrameNeeded());
401 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 402 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
402 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 403 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
403 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 404 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
404 state.OnBeginImplFrameDeadline(); 405 state.OnBeginImplFrameDeadline();
405 406
406 // We're drawing now. 407 // We're drawing now.
407 EXPECT_ACTION_UPDATE_STATE( 408 EXPECT_ACTION_UPDATE_STATE(
408 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 409 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
409 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 410 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
410 EXPECT_FALSE(state.RedrawPending()); 411 EXPECT_FALSE(state.RedrawPending());
411 EXPECT_FALSE(state.CommitPending()); 412 EXPECT_FALSE(state.CommitPending());
412 413
413 // While still in the same BeginMainFrame callback on the main thread, 414 // While still in the same BeginMainFrame callback on the main thread,
414 // set needs redraw again. This should not redraw. 415 // set needs redraw again. This should not redraw.
415 state.SetNeedsRedraw(true); 416 state.SetNeedsRedraw(true);
416 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 417 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
417 418
418 // Failing the draw for animation checkerboards makes us require a commit. 419 // Failing the draw for animation checkerboards makes us require a commit.
419 state.DidDrawIfPossibleCompleted( 420 state.DidDrawIfPossibleCompleted(
420 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 421 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
421 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 422 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
422 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 423 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
423 EXPECT_ACTION_UPDATE_STATE( 424 EXPECT_ACTION_UPDATE_STATE(
424 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 425 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
425 EXPECT_TRUE(state.RedrawPending()); 426 EXPECT_TRUE(state.RedrawPending());
426 } 427 }
427 428
428 void TestFailedDrawsEventuallyForceDrawAfterNextCommit( 429 void TestFailedDrawsEventuallyForceDrawAfterNextCommit(
429 bool main_frame_before_draw_enabled) { 430 bool main_frame_before_draw_enabled) {
430 SchedulerSettings scheduler_settings; 431 SchedulerSettings scheduler_settings;
431 scheduler_settings.main_frame_before_draw_enabled = 432 scheduler_settings.main_frame_before_draw_enabled =
432 main_frame_before_draw_enabled; 433 main_frame_before_draw_enabled;
433 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced_ = 1; 434 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced_ = 1;
434 StateMachine state(scheduler_settings); 435 StateMachine state(scheduler_settings);
435 state.SetCanStart(); 436 state.SetCanStart();
436 state.UpdateState(state.NextAction()); 437 state.UpdateState(state.NextAction());
437 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 438 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
438 state.SetVisible(true); 439 state.SetVisible(true);
439 state.SetCanDraw(true); 440 state.SetCanDraw(true);
440 441
441 // Start a commit. 442 // Start a commit.
442 state.SetNeedsCommit(); 443 state.SetNeedsCommit();
443 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 444 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
444 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 445 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
445 EXPECT_ACTION_UPDATE_STATE( 446 EXPECT_ACTION_UPDATE_STATE(
446 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 447 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
447 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 448 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
448 EXPECT_TRUE(state.CommitPending()); 449 EXPECT_TRUE(state.CommitPending());
449 450
450 // Then initiate a draw. 451 // Then initiate a draw.
451 state.SetNeedsRedraw(true); 452 state.SetNeedsRedraw(true);
452 state.OnBeginImplFrameDeadline(); 453 state.OnBeginImplFrameDeadline();
453 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 454 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
454 EXPECT_ACTION_UPDATE_STATE( 455 EXPECT_ACTION_UPDATE_STATE(
(...skipping 10 matching lines...) Expand all
465 466
466 // Finish the commit. Note, we should not yet be forcing a draw, but should 467 // Finish the commit. Note, we should not yet be forcing a draw, but should
467 // continue the commit as usual. 468 // continue the commit as usual.
468 state.NotifyBeginMainFrameStarted(); 469 state.NotifyBeginMainFrameStarted();
469 state.NotifyReadyToCommit(); 470 state.NotifyReadyToCommit();
470 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 471 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
471 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 472 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
472 EXPECT_TRUE(state.RedrawPending()); 473 EXPECT_TRUE(state.RedrawPending());
473 474
474 // The redraw should be forced at the end of the next BeginImplFrame. 475 // The redraw should be forced at the end of the next BeginImplFrame.
475 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 476 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
476 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 477 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
477 if (main_frame_before_draw_enabled) { 478 if (main_frame_before_draw_enabled) {
478 EXPECT_ACTION_UPDATE_STATE( 479 EXPECT_ACTION_UPDATE_STATE(
479 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 480 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
480 } 481 }
481 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 482 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
482 state.OnBeginImplFrameDeadline(); 483 state.OnBeginImplFrameDeadline();
483 EXPECT_ACTION_UPDATE_STATE( 484 EXPECT_ACTION_UPDATE_STATE(
484 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED); 485 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED);
485 } 486 }
(...skipping 21 matching lines...) Expand all
507 StateMachine state(scheduler_settings); 508 StateMachine state(scheduler_settings);
508 state.SetCanStart(); 509 state.SetCanStart();
509 state.UpdateState(state.NextAction()); 510 state.UpdateState(state.NextAction());
510 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 511 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
511 state.SetVisible(true); 512 state.SetVisible(true);
512 state.SetCanDraw(true); 513 state.SetCanDraw(true);
513 514
514 // Start a commit. 515 // Start a commit.
515 state.SetNeedsCommit(); 516 state.SetNeedsCommit();
516 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 517 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
517 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 518 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
518 EXPECT_ACTION_UPDATE_STATE( 519 EXPECT_ACTION_UPDATE_STATE(
519 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 520 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
520 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 521 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
521 EXPECT_TRUE(state.CommitPending()); 522 EXPECT_TRUE(state.CommitPending());
522 523
523 // Then initiate a draw. 524 // Then initiate a draw.
524 state.SetNeedsRedraw(true); 525 state.SetNeedsRedraw(true);
525 state.OnBeginImplFrameDeadline(); 526 state.OnBeginImplFrameDeadline();
526 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 527 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
527 EXPECT_ACTION_UPDATE_STATE( 528 EXPECT_ACTION_UPDATE_STATE(
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 StateMachine state(default_scheduler_settings); 569 StateMachine state(default_scheduler_settings);
569 state.SetCanStart(); 570 state.SetCanStart();
570 state.UpdateState(state.NextAction()); 571 state.UpdateState(state.NextAction());
571 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 572 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
572 state.SetVisible(true); 573 state.SetVisible(true);
573 state.SetCanDraw(true); 574 state.SetCanDraw(true);
574 575
575 // Start a draw. 576 // Start a draw.
576 state.SetNeedsRedraw(true); 577 state.SetNeedsRedraw(true);
577 EXPECT_TRUE(state.BeginFrameNeeded()); 578 EXPECT_TRUE(state.BeginFrameNeeded());
578 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 579 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
579 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 580 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
580 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 581 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
581 state.OnBeginImplFrameDeadline(); 582 state.OnBeginImplFrameDeadline();
582 EXPECT_TRUE(state.RedrawPending()); 583 EXPECT_TRUE(state.RedrawPending());
583 EXPECT_ACTION_UPDATE_STATE( 584 EXPECT_ACTION_UPDATE_STATE(
584 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 585 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
585 586
586 // Failing the draw for animation checkerboards makes us require a commit. 587 // Failing the draw for animation checkerboards makes us require a commit.
587 state.DidDrawIfPossibleCompleted( 588 state.DidDrawIfPossibleCompleted(
588 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 589 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
589 EXPECT_ACTION_UPDATE_STATE( 590 EXPECT_ACTION_UPDATE_STATE(
590 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 591 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
591 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 592 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
592 EXPECT_TRUE(state.RedrawPending()); 593 EXPECT_TRUE(state.RedrawPending());
593 594
594 // We should not be trying to draw again now, but we have a commit pending. 595 // We should not be trying to draw again now, but we have a commit pending.
595 EXPECT_TRUE(state.BeginFrameNeeded()); 596 EXPECT_TRUE(state.BeginFrameNeeded());
596 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 597 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
597 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 598 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
598 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 599 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
599 600
600 // We should try to draw again at the end of the next BeginImplFrame on 601 // We should try to draw again at the end of the next BeginImplFrame on
601 // the impl thread. 602 // the impl thread.
602 state.OnBeginImplFrameDeadline(); 603 state.OnBeginImplFrameDeadline();
603 EXPECT_ACTION_UPDATE_STATE( 604 EXPECT_ACTION_UPDATE_STATE(
604 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 605 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
605 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 606 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
606 } 607 }
607 608
608 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) { 609 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) {
609 SchedulerSettings default_scheduler_settings; 610 SchedulerSettings default_scheduler_settings;
610 StateMachine state(default_scheduler_settings); 611 StateMachine state(default_scheduler_settings);
611 state.SetCanStart(); 612 state.SetCanStart();
612 state.UpdateState(state.NextAction()); 613 state.UpdateState(state.NextAction());
613 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 614 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
614 state.SetVisible(true); 615 state.SetVisible(true);
615 state.SetCanDraw(true); 616 state.SetCanDraw(true);
616 state.SetNeedsRedraw(true); 617 state.SetNeedsRedraw(true);
617 618
618 // Draw the first frame. 619 // Draw the first frame.
619 EXPECT_TRUE(state.BeginFrameNeeded()); 620 EXPECT_TRUE(state.BeginFrameNeeded());
620 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 621 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
621 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 622 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
622 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 623 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
623 624
624 state.OnBeginImplFrameDeadline(); 625 state.OnBeginImplFrameDeadline();
625 EXPECT_ACTION_UPDATE_STATE( 626 EXPECT_ACTION_UPDATE_STATE(
626 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 627 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
627 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 628 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
628 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 629 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
629 630
630 // Before the next BeginImplFrame, set needs redraw again. 631 // Before the next BeginImplFrame, set needs redraw again.
631 // This should not redraw until the next BeginImplFrame. 632 // This should not redraw until the next BeginImplFrame.
632 state.SetNeedsRedraw(true); 633 state.SetNeedsRedraw(true);
633 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 634 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
634 635
635 // Move to another frame. This should now draw. 636 // Move to another frame. This should now draw.
636 EXPECT_TRUE(state.BeginFrameNeeded()); 637 EXPECT_TRUE(state.BeginFrameNeeded());
637 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 638 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
638 639
639 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 640 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
640 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 641 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
641 642
642 state.OnBeginImplFrameDeadline(); 643 state.OnBeginImplFrameDeadline();
643 EXPECT_ACTION_UPDATE_STATE( 644 EXPECT_ACTION_UPDATE_STATE(
644 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 645 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
645 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 646 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
646 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 647 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
647 648
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 // There shouldn't be any drawing regardless of BeginImplFrame. 777 // There shouldn't be any drawing regardless of BeginImplFrame.
777 for (size_t j = 0; j < 2; ++j) { 778 for (size_t j = 0; j < 2; ++j) {
778 StateMachine state(default_scheduler_settings); 779 StateMachine state(default_scheduler_settings);
779 state.SetCanStart(); 780 state.SetCanStart();
780 state.UpdateState(state.NextAction()); 781 state.UpdateState(state.NextAction());
781 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 782 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
782 state.SetCommitState(all_commit_states[i]); 783 state.SetCommitState(all_commit_states[i]);
783 state.SetVisible(false); 784 state.SetVisible(false);
784 state.SetNeedsRedraw(true); 785 state.SetNeedsRedraw(true);
785 if (j == 1) 786 if (j == 1)
786 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 787 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
787 788
788 state.SetCanDraw(false); 789 state.SetCanDraw(false);
789 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 790 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
790 state.NextAction()); 791 state.NextAction());
791 } 792 }
792 } 793 }
793 } 794 }
794 795
795 TEST(SchedulerStateMachineTest, 796 TEST(SchedulerStateMachineTest,
796 TestCanRedrawWithWaitingForFirstDrawMakesProgress) { 797 TestCanRedrawWithWaitingForFirstDrawMakesProgress) {
797 SchedulerSettings default_scheduler_settings; 798 SchedulerSettings default_scheduler_settings;
798 StateMachine state(default_scheduler_settings); 799 StateMachine state(default_scheduler_settings);
799 state.SetCanStart(); 800 state.SetCanStart();
800 state.UpdateState(state.NextAction()); 801 state.UpdateState(state.NextAction());
801 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 802 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
802 803
803 state.SetActiveTreeNeedsFirstDraw(true); 804 state.SetActiveTreeNeedsFirstDraw(true);
804 state.SetNeedsCommit(); 805 state.SetNeedsCommit();
805 state.SetNeedsRedraw(true); 806 state.SetNeedsRedraw(true);
806 state.SetVisible(true); 807 state.SetVisible(true);
807 state.SetCanDraw(false); 808 state.SetCanDraw(false);
808 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 809 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
809 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 810 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
810 EXPECT_ACTION_UPDATE_STATE( 811 EXPECT_ACTION_UPDATE_STATE(
811 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 812 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
812 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 813 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
813 state.NotifyBeginMainFrameStarted(); 814 state.NotifyBeginMainFrameStarted();
814 state.NotifyReadyToCommit(); 815 state.NotifyReadyToCommit();
815 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 816 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
816 state.OnBeginImplFrameDeadline(); 817 state.OnBeginImplFrameDeadline();
817 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 818 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
818 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 819 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
819 } 820 }
820 821
821 void TestSetNeedsCommitIsNotLost(bool main_frame_before_draw_enabled) { 822 void TestSetNeedsCommitIsNotLost(bool main_frame_before_draw_enabled) {
822 SchedulerSettings scheduler_settings; 823 SchedulerSettings scheduler_settings;
823 scheduler_settings.main_frame_before_draw_enabled = 824 scheduler_settings.main_frame_before_draw_enabled =
824 main_frame_before_draw_enabled; 825 main_frame_before_draw_enabled;
825 StateMachine state(scheduler_settings); 826 StateMachine state(scheduler_settings);
826 state.SetCanStart(); 827 state.SetCanStart();
827 state.UpdateState(state.NextAction()); 828 state.UpdateState(state.NextAction());
828 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 829 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
829 state.SetNeedsCommit(); 830 state.SetNeedsCommit();
830 state.SetVisible(true); 831 state.SetVisible(true);
831 state.SetCanDraw(true); 832 state.SetCanDraw(true);
832 833
833 EXPECT_TRUE(state.BeginFrameNeeded()); 834 EXPECT_TRUE(state.BeginFrameNeeded());
834 835
835 // Begin the frame. 836 // Begin the frame.
836 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 837 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
837 EXPECT_ACTION_UPDATE_STATE( 838 EXPECT_ACTION_UPDATE_STATE(
838 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 839 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
839 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 840 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT,
840 state.CommitState()); 841 state.CommitState());
841 842
842 // Now, while the frame is in progress, set another commit. 843 // Now, while the frame is in progress, set another commit.
843 state.SetNeedsCommit(); 844 state.SetNeedsCommit();
844 EXPECT_TRUE(state.NeedsCommit()); 845 EXPECT_TRUE(state.NeedsCommit());
845 846
846 // Let the frame finish. 847 // Let the frame finish.
(...skipping 15 matching lines...) Expand all
862 state.OnBeginImplFrameDeadline(); 863 state.OnBeginImplFrameDeadline();
863 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, 864 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE,
864 state.begin_impl_frame_state()); 865 state.begin_impl_frame_state());
865 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 866 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
866 867
867 state.OnBeginImplFrameIdle(); 868 state.OnBeginImplFrameIdle();
868 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, 869 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE,
869 state.begin_impl_frame_state()); 870 state.begin_impl_frame_state());
870 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 871 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
871 872
872 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 873 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
873 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING, 874 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING,
874 state.begin_impl_frame_state()); 875 state.begin_impl_frame_state());
875 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 876 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
876 877
877 // Finish the commit, then make sure we start the next commit immediately 878 // Finish the commit, then make sure we start the next commit immediately
878 // and draw on the next BeginImplFrame. 879 // and draw on the next BeginImplFrame.
879 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 880 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
880 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 881 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
881 if (main_frame_before_draw_enabled) { 882 if (main_frame_before_draw_enabled) {
882 EXPECT_ACTION_UPDATE_STATE( 883 EXPECT_ACTION_UPDATE_STATE(
(...skipping 30 matching lines...) Expand all
913 state.SetCanStart(); 914 state.SetCanStart();
914 state.UpdateState(state.NextAction()); 915 state.UpdateState(state.NextAction());
915 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 916 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
916 state.SetVisible(true); 917 state.SetVisible(true);
917 state.SetCanDraw(true); 918 state.SetCanDraw(true);
918 919
919 // Start clean and set commit. 920 // Start clean and set commit.
920 state.SetNeedsCommit(); 921 state.SetNeedsCommit();
921 922
922 // Begin the frame. 923 // Begin the frame.
923 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 924 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
924 EXPECT_ACTION_UPDATE_STATE( 925 EXPECT_ACTION_UPDATE_STATE(
925 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 926 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
926 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 927 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT,
927 state.CommitState()); 928 state.CommitState());
928 EXPECT_FALSE(state.NeedsCommit()); 929 EXPECT_FALSE(state.NeedsCommit());
929 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 930 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
930 931
931 // Tell the scheduler the frame finished. 932 // Tell the scheduler the frame finished.
932 state.NotifyBeginMainFrameStarted(); 933 state.NotifyBeginMainFrameStarted();
933 state.NotifyReadyToCommit(); 934 state.NotifyReadyToCommit();
(...skipping 27 matching lines...) Expand all
961 state.SetCanStart(); 962 state.SetCanStart();
962 state.UpdateState(state.NextAction()); 963 state.UpdateState(state.NextAction());
963 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 964 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
964 state.SetVisible(true); 965 state.SetVisible(true);
965 state.SetCanDraw(true); 966 state.SetCanDraw(true);
966 967
967 // Start clean and set commit. 968 // Start clean and set commit.
968 state.SetNeedsCommit(); 969 state.SetNeedsCommit();
969 970
970 // Begin the frame. 971 // Begin the frame.
971 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 972 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
972 EXPECT_ACTION_UPDATE_STATE( 973 EXPECT_ACTION_UPDATE_STATE(
973 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 974 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
974 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 975 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT,
975 state.CommitState()); 976 state.CommitState());
976 EXPECT_FALSE(state.NeedsCommit()); 977 EXPECT_FALSE(state.NeedsCommit());
977 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 978 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
978 979
979 // Request another commit while the commit is in flight. 980 // Request another commit while the commit is in flight.
980 state.SetNeedsCommit(); 981 state.SetNeedsCommit();
981 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 982 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
(...skipping 18 matching lines...) Expand all
1000 EXPECT_ACTION_UPDATE_STATE( 1001 EXPECT_ACTION_UPDATE_STATE(
1001 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1002 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1002 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 1003 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
1003 1004
1004 // Should be synchronized, no draw needed, no action needed. 1005 // Should be synchronized, no draw needed, no action needed.
1005 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1006 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1006 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1007 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
1007 EXPECT_FALSE(state.needs_redraw()); 1008 EXPECT_FALSE(state.needs_redraw());
1008 1009
1009 // Next BeginImplFrame should initiate second commit. 1010 // Next BeginImplFrame should initiate second commit.
1010 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1011 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
1011 EXPECT_ACTION_UPDATE_STATE( 1012 EXPECT_ACTION_UPDATE_STATE(
1012 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1013 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1013 } 1014 }
1014 1015
1015 TEST(SchedulerStateMachineTest, TestRequestCommitInvisible) { 1016 TEST(SchedulerStateMachineTest, TestRequestCommitInvisible) {
1016 SchedulerSettings default_scheduler_settings; 1017 SchedulerSettings default_scheduler_settings;
1017 StateMachine state(default_scheduler_settings); 1018 StateMachine state(default_scheduler_settings);
1018 state.SetCanStart(); 1019 state.SetCanStart();
1019 state.UpdateState(state.NextAction()); 1020 state.UpdateState(state.NextAction());
1020 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1021 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1021 state.SetNeedsCommit(); 1022 state.SetNeedsCommit();
1022 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1023 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1023 } 1024 }
1024 1025
1025 TEST(SchedulerStateMachineTest, TestGoesInvisibleBeforeFinishCommit) { 1026 TEST(SchedulerStateMachineTest, TestGoesInvisibleBeforeFinishCommit) {
1026 SchedulerSettings default_scheduler_settings; 1027 SchedulerSettings default_scheduler_settings;
1027 StateMachine state(default_scheduler_settings); 1028 StateMachine state(default_scheduler_settings);
1028 state.SetCanStart(); 1029 state.SetCanStart();
1029 state.UpdateState(state.NextAction()); 1030 state.UpdateState(state.NextAction());
1030 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1031 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1031 state.SetVisible(true); 1032 state.SetVisible(true);
1032 state.SetCanDraw(true); 1033 state.SetCanDraw(true);
1033 1034
1034 // Start clean and set commit. 1035 // Start clean and set commit.
1035 state.SetNeedsCommit(); 1036 state.SetNeedsCommit();
1036 1037
1037 // Begin the frame while visible. 1038 // Begin the frame while visible.
1038 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1039 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
1039 EXPECT_ACTION_UPDATE_STATE( 1040 EXPECT_ACTION_UPDATE_STATE(
1040 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1041 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1041 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 1042 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT,
1042 state.CommitState()); 1043 state.CommitState());
1043 EXPECT_FALSE(state.NeedsCommit()); 1044 EXPECT_FALSE(state.NeedsCommit());
1044 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1045 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1045 1046
1046 // Become invisible and abort BeginMainFrame. 1047 // Become invisible and abort BeginMainFrame.
1047 state.SetVisible(false); 1048 state.SetVisible(false);
1048 state.BeginMainFrameAborted(false); 1049 state.BeginMainFrameAborted(false);
1049 1050
1050 // We should now be back in the idle state as if we never started the frame. 1051 // We should now be back in the idle state as if we never started the frame.
1051 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1052 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
1052 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1053 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1053 1054
1054 // We shouldn't do anything on the BeginImplFrame deadline. 1055 // We shouldn't do anything on the BeginImplFrame deadline.
1055 state.OnBeginImplFrameDeadline(); 1056 state.OnBeginImplFrameDeadline();
1056 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1057 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1057 1058
1058 // Become visible again. 1059 // Become visible again.
1059 state.SetVisible(true); 1060 state.SetVisible(true);
1060 1061
1061 // Although we have aborted on this frame and haven't cancelled the commit 1062 // Although we have aborted on this frame and haven't cancelled the commit
1062 // (i.e. need another), don't send another BeginMainFrame yet. 1063 // (i.e. need another), don't send another BeginMainFrame yet.
1063 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1064 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
1064 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1065 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1065 EXPECT_TRUE(state.NeedsCommit()); 1066 EXPECT_TRUE(state.NeedsCommit());
1066 1067
1067 // Start a new frame. 1068 // Start a new frame.
1068 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1069 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
1069 EXPECT_ACTION_UPDATE_STATE( 1070 EXPECT_ACTION_UPDATE_STATE(
1070 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1071 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1071 1072
1072 // We should be starting the commit now. 1073 // We should be starting the commit now.
1073 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 1074 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT,
1074 state.CommitState()); 1075 state.CommitState());
1075 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1076 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1076 } 1077 }
1077 1078
1078 TEST(SchedulerStateMachineTest, AbortBeginMainFrameAndCancelCommit) { 1079 TEST(SchedulerStateMachineTest, AbortBeginMainFrameAndCancelCommit) {
(...skipping 18 matching lines...) Expand all
1097 // Abort the commit, cancelling future commits. 1098 // Abort the commit, cancelling future commits.
1098 state.BeginMainFrameAborted(true); 1099 state.BeginMainFrameAborted(true);
1099 1100
1100 // Verify that another commit doesn't start on the same frame. 1101 // Verify that another commit doesn't start on the same frame.
1101 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1102 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
1102 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1103 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1103 EXPECT_FALSE(state.NeedsCommit()); 1104 EXPECT_FALSE(state.NeedsCommit());
1104 1105
1105 // Start a new frame; draw because this is the first frame since output 1106 // Start a new frame; draw because this is the first frame since output
1106 // surface init'd. 1107 // surface init'd.
1107 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1108 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
1108 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1109 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1109 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1110 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1110 state.OnBeginImplFrameDeadline(); 1111 state.OnBeginImplFrameDeadline();
1111 EXPECT_ACTION_UPDATE_STATE( 1112 EXPECT_ACTION_UPDATE_STATE(
1112 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1113 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1113 1114
1114 // Verify another commit doesn't start on another frame either. 1115 // Verify another commit doesn't start on another frame either.
1115 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1116 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
1116 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1117 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1117 EXPECT_FALSE(state.NeedsCommit()); 1118 EXPECT_FALSE(state.NeedsCommit());
(...skipping 11 matching lines...) Expand all
1129 state.SetCanStart(); 1130 state.SetCanStart();
1130 state.SetVisible(true); 1131 state.SetVisible(true);
1131 state.SetCanDraw(true); 1132 state.SetCanDraw(true);
1132 1133
1133 EXPECT_ACTION_UPDATE_STATE( 1134 EXPECT_ACTION_UPDATE_STATE(
1134 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 1135 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1135 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1136 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1136 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1137 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1137 1138
1138 // Check that the first init does not SetNeedsCommit. 1139 // Check that the first init does not SetNeedsCommit.
1139 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1140 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
1140 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1141 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1141 state.OnBeginImplFrameDeadline(); 1142 state.OnBeginImplFrameDeadline();
1142 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1143 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1143 1144
1144 // Check that a needs commit initiates a BeginMainFrame. 1145 // Check that a needs commit initiates a BeginMainFrame.
1145 state.SetNeedsCommit(); 1146 state.SetNeedsCommit();
1146 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1147 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
1147 EXPECT_ACTION_UPDATE_STATE( 1148 EXPECT_ACTION_UPDATE_STATE(
1148 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1149 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1149 } 1150 }
1150 1151
1151 TEST(SchedulerStateMachineTest, TestContextLostWhenCompletelyIdle) { 1152 TEST(SchedulerStateMachineTest, TestContextLostWhenCompletelyIdle) {
1152 SchedulerSettings default_scheduler_settings; 1153 SchedulerSettings default_scheduler_settings;
1153 StateMachine state(default_scheduler_settings); 1154 StateMachine state(default_scheduler_settings);
1154 state.SetCanStart(); 1155 state.SetCanStart();
1155 state.UpdateState(state.NextAction()); 1156 state.UpdateState(state.NextAction());
1156 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1157 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1157 1158
1158 state.SetVisible(true); 1159 state.SetVisible(true);
1159 state.SetCanDraw(true); 1160 state.SetCanDraw(true);
1160 1161
1161 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1162 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1162 state.NextAction()); 1163 state.NextAction());
1163 state.DidLoseOutputSurface(); 1164 state.DidLoseOutputSurface();
1164 1165
1165 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1166 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1166 state.NextAction()); 1167 state.NextAction());
1167 state.UpdateState(state.NextAction()); 1168 state.UpdateState(state.NextAction());
1168 1169
1169 // Once context recreation begins, nothing should happen. 1170 // Once context recreation begins, nothing should happen.
1170 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1171 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1171 1172
1172 // Recreate the context. 1173 // Recreate the context.
1173 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1174 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1174 1175
1175 // When the context is recreated, we should begin a commit. 1176 // When the context is recreated, we should begin a commit.
1176 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1177 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
1177 EXPECT_ACTION_UPDATE_STATE( 1178 EXPECT_ACTION_UPDATE_STATE(
1178 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1179 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1179 } 1180 }
1180 1181
1181 TEST(SchedulerStateMachineTest, 1182 TEST(SchedulerStateMachineTest,
1182 TestContextLostWhenIdleAndCommitRequestedWhileRecreating) { 1183 TestContextLostWhenIdleAndCommitRequestedWhileRecreating) {
1183 SchedulerSettings default_scheduler_settings; 1184 SchedulerSettings default_scheduler_settings;
1184 StateMachine state(default_scheduler_settings); 1185 StateMachine state(default_scheduler_settings);
1185 state.SetCanStart(); 1186 state.SetCanStart();
1186 state.UpdateState(state.NextAction()); 1187 state.UpdateState(state.NextAction());
1187 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1188 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1188 state.SetVisible(true); 1189 state.SetVisible(true);
1189 state.SetCanDraw(true); 1190 state.SetCanDraw(true);
1190 1191
1191 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1192 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1192 state.NextAction()); 1193 state.NextAction());
1193 state.DidLoseOutputSurface(); 1194 state.DidLoseOutputSurface();
1194 1195
1195 EXPECT_ACTION_UPDATE_STATE( 1196 EXPECT_ACTION_UPDATE_STATE(
1196 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 1197 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1197 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1198 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1198 1199
1199 // Once context recreation begins, nothing should happen. 1200 // Once context recreation begins, nothing should happen.
1200 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1201 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
1201 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1202 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1202 state.OnBeginImplFrameDeadline(); 1203 state.OnBeginImplFrameDeadline();
1203 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1204 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1204 1205
1205 // While context is recreating, commits shouldn't begin. 1206 // While context is recreating, commits shouldn't begin.
1206 state.SetNeedsCommit(); 1207 state.SetNeedsCommit();
1207 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1208 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
1208 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1209 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1209 state.OnBeginImplFrameDeadline(); 1210 state.OnBeginImplFrameDeadline();
1210 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1211 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1211 1212
1212 // Recreate the context 1213 // Recreate the context
1213 state.DidCreateAndInitializeOutputSurface(); 1214 state.DidCreateAndInitializeOutputSurface();
1214 EXPECT_FALSE(state.RedrawPending()); 1215 EXPECT_FALSE(state.RedrawPending());
1215 1216
1216 // When the context is recreated, we should begin a commit 1217 // When the context is recreated, we should begin a commit
1217 EXPECT_ACTION_UPDATE_STATE( 1218 EXPECT_ACTION_UPDATE_STATE(
1218 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1219 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1219 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1220 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1220 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 1221 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT,
1221 state.CommitState()); 1222 state.CommitState());
1222 1223
1223 state.NotifyBeginMainFrameStarted(); 1224 state.NotifyBeginMainFrameStarted();
1224 state.NotifyReadyToCommit(); 1225 state.NotifyReadyToCommit();
1225 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1226 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1226 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1227 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1227 // Finishing the first commit after initializing an output surface should 1228 // Finishing the first commit after initializing an output surface should
1228 // automatically cause a redraw. 1229 // automatically cause a redraw.
1229 EXPECT_TRUE(state.RedrawPending()); 1230 EXPECT_TRUE(state.RedrawPending());
1230 1231
1231 // Once the context is recreated, whether we draw should be based on 1232 // Once the context is recreated, whether we draw should be based on
1232 // SetCanDraw. 1233 // SetCanDraw.
1233 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1234 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
1234 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1235 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1235 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1236 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1236 state.OnBeginImplFrameDeadline(); 1237 state.OnBeginImplFrameDeadline();
1237 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 1238 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
1238 state.NextAction()); 1239 state.NextAction());
1239 state.SetCanDraw(false); 1240 state.SetCanDraw(false);
1240 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT, 1241 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT,
1241 state.NextAction()); 1242 state.NextAction());
1242 state.SetCanDraw(true); 1243 state.SetCanDraw(true);
1243 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 1244 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
1244 state.NextAction()); 1245 state.NextAction());
1245 } 1246 }
1246 1247
1247 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) { 1248 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) {
1248 SchedulerSettings scheduler_settings; 1249 SchedulerSettings scheduler_settings;
1249 StateMachine state(scheduler_settings); 1250 StateMachine state(scheduler_settings);
1250 state.SetCanStart(); 1251 state.SetCanStart();
1251 state.UpdateState(state.NextAction()); 1252 state.UpdateState(state.NextAction());
1252 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1253 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1253 state.SetVisible(true); 1254 state.SetVisible(true);
1254 state.SetCanDraw(true); 1255 state.SetCanDraw(true);
1255 1256
1256 // Get a commit in flight. 1257 // Get a commit in flight.
1257 state.SetNeedsCommit(); 1258 state.SetNeedsCommit();
1258 1259
1259 // Set damage and expect a draw. 1260 // Set damage and expect a draw.
1260 state.SetNeedsRedraw(true); 1261 state.SetNeedsRedraw(true);
1261 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1262 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
1262 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1263 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1263 EXPECT_ACTION_UPDATE_STATE( 1264 EXPECT_ACTION_UPDATE_STATE(
1264 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1265 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1265 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1266 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1266 state.OnBeginImplFrameDeadline(); 1267 state.OnBeginImplFrameDeadline();
1267 EXPECT_ACTION_UPDATE_STATE( 1268 EXPECT_ACTION_UPDATE_STATE(
1268 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1269 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1269 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1270 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1270 1271
1271 // Cause a lost context while the BeginMainFrame is in flight. 1272 // Cause a lost context while the BeginMainFrame is in flight.
(...skipping 12 matching lines...) Expand all
1284 // waiting for the first draw to unblock the main thread. 1285 // waiting for the first draw to unblock the main thread.
1285 EXPECT_TRUE(state.active_tree_needs_first_draw()); 1286 EXPECT_TRUE(state.active_tree_needs_first_draw());
1286 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1287 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1287 1288
1288 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE 1289 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE
1289 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, 1290 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE,
1290 state.begin_impl_frame_state()); 1291 state.begin_impl_frame_state());
1291 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1292 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1292 state.NextAction()); 1293 state.NextAction());
1293 1294
1294 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1295 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
1295 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING, 1296 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING,
1296 state.begin_impl_frame_state()); 1297 state.begin_impl_frame_state());
1297 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1298 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1298 1299
1299 state.OnBeginImplFrameDeadlinePending(); 1300 state.OnBeginImplFrameDeadlinePending();
1300 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME, 1301 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME,
1301 state.begin_impl_frame_state()); 1302 state.begin_impl_frame_state());
1302 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1303 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1303 1304
1304 state.OnBeginImplFrameDeadline(); 1305 state.OnBeginImplFrameDeadline();
(...skipping 11 matching lines...) Expand all
1316 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1317 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1317 state.SetVisible(true); 1318 state.SetVisible(true);
1318 state.SetCanDraw(true); 1319 state.SetCanDraw(true);
1319 1320
1320 // Get a commit in flight. 1321 // Get a commit in flight.
1321 state.SetNeedsCommit(); 1322 state.SetNeedsCommit();
1322 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1323 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1323 1324
1324 // Set damage and expect a draw. 1325 // Set damage and expect a draw.
1325 state.SetNeedsRedraw(true); 1326 state.SetNeedsRedraw(true);
1326 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1327 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
1327 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1328 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1328 EXPECT_ACTION_UPDATE_STATE( 1329 EXPECT_ACTION_UPDATE_STATE(
1329 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1330 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1330 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1331 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1331 state.OnBeginImplFrameDeadline(); 1332 state.OnBeginImplFrameDeadline();
1332 EXPECT_ACTION_UPDATE_STATE( 1333 EXPECT_ACTION_UPDATE_STATE(
1333 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1334 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1334 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1335 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1335 1336
1336 // Cause a lost context while the BeginMainFrame is in flight. 1337 // Cause a lost context while the BeginMainFrame is in flight.
(...skipping 12 matching lines...) Expand all
1349 1350
1350 // Because the output surface is missing, we expect the draw to abort. 1351 // Because the output surface is missing, we expect the draw to abort.
1351 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1352 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1352 1353
1353 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE 1354 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE
1354 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, 1355 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE,
1355 state.begin_impl_frame_state()); 1356 state.begin_impl_frame_state());
1356 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1357 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1357 state.NextAction()); 1358 state.NextAction());
1358 1359
1359 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1360 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
1360 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING, 1361 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING,
1361 state.begin_impl_frame_state()); 1362 state.begin_impl_frame_state());
1362 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1363 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1363 1364
1364 state.OnBeginImplFrameDeadlinePending(); 1365 state.OnBeginImplFrameDeadlinePending();
1365 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME, 1366 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME,
1366 state.begin_impl_frame_state()); 1367 state.begin_impl_frame_state());
1367 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1368 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1368 1369
1369 state.OnBeginImplFrameDeadline(); 1370 state.OnBeginImplFrameDeadline();
1370 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, 1371 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE,
1371 state.begin_impl_frame_state()); 1372 state.begin_impl_frame_state());
1372 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1373 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1373 1374
1374 state.OnBeginImplFrameIdle(); 1375 state.OnBeginImplFrameIdle();
1375 EXPECT_ACTION_UPDATE_STATE( 1376 EXPECT_ACTION_UPDATE_STATE(
1376 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 1377 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1377 1378
1378 // After we get a new output surface, the commit flow should start. 1379 // After we get a new output surface, the commit flow should start.
1379 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1380 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1380 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1381 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
1381 EXPECT_ACTION_UPDATE_STATE( 1382 EXPECT_ACTION_UPDATE_STATE(
1382 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1383 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1383 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1384 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1384 state.NotifyBeginMainFrameStarted(); 1385 state.NotifyBeginMainFrameStarted();
1385 state.NotifyReadyToCommit(); 1386 state.NotifyReadyToCommit();
1386 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1387 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1387 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1388 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1388 state.OnBeginImplFrameDeadline(); 1389 state.OnBeginImplFrameDeadline();
1389 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1390 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1390 EXPECT_ACTION_UPDATE_STATE( 1391 EXPECT_ACTION_UPDATE_STATE(
1391 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1392 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1392 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1393 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1393 } 1394 }
1394 1395
1395 TEST(SchedulerStateMachineTest, TestFinishAllRenderingWhileContextLost) { 1396 TEST(SchedulerStateMachineTest, TestFinishAllRenderingWhileContextLost) {
1396 SchedulerSettings default_scheduler_settings; 1397 SchedulerSettings default_scheduler_settings;
1397 StateMachine state(default_scheduler_settings); 1398 StateMachine state(default_scheduler_settings);
1398 state.SetCanStart(); 1399 state.SetCanStart();
1399 state.UpdateState(state.NextAction()); 1400 state.UpdateState(state.NextAction());
1400 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1401 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1401 state.SetVisible(true); 1402 state.SetVisible(true);
1402 state.SetCanDraw(true); 1403 state.SetCanDraw(true);
1403 1404
1404 // Cause a lost context lost. 1405 // Cause a lost context lost.
1405 state.DidLoseOutputSurface(); 1406 state.DidLoseOutputSurface();
1406 1407
1407 // Ask a forced redraw for readback and verify it ocurrs. 1408 // Ask a forced redraw for readback and verify it ocurrs.
1408 state.SetNeedsForcedRedrawForReadback(); 1409 state.SetNeedsForcedRedrawForReadback();
1409 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1410 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
1410 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1411 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1411 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1412 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1412 1413
1413 // Forced redraws for readbacks need to be followed by a new commit 1414 // Forced redraws for readbacks need to be followed by a new commit
1414 // to replace the readback commit. 1415 // to replace the readback commit.
1415 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 1416 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT,
1416 state.CommitState()); 1417 state.CommitState());
1417 state.NotifyBeginMainFrameStarted(); 1418 state.NotifyBeginMainFrameStarted();
1418 state.NotifyReadyToCommit(); 1419 state.NotifyReadyToCommit();
1419 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1420 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
(...skipping 29 matching lines...) Expand all
1449 state.SetNeedsRedraw(true); 1450 state.SetNeedsRedraw(true);
1450 1451
1451 // Cause a lost output surface, and restore it. 1452 // Cause a lost output surface, and restore it.
1452 state.DidLoseOutputSurface(); 1453 state.DidLoseOutputSurface();
1453 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1454 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1454 state.NextAction()); 1455 state.NextAction());
1455 state.UpdateState(state.NextAction()); 1456 state.UpdateState(state.NextAction());
1456 state.DidCreateAndInitializeOutputSurface(); 1457 state.DidCreateAndInitializeOutputSurface();
1457 1458
1458 EXPECT_FALSE(state.RedrawPending()); 1459 EXPECT_FALSE(state.RedrawPending());
1459 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1460 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
1460 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME, 1461 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME,
1461 state.NextAction()); 1462 state.NextAction());
1462 } 1463 }
1463 1464
1464 TEST(SchedulerStateMachineTest, 1465 TEST(SchedulerStateMachineTest,
1465 TestPendingActivationsShouldBeForcedAfterLostOutputSurface) { 1466 TestPendingActivationsShouldBeForcedAfterLostOutputSurface) {
1466 SchedulerSettings settings; 1467 SchedulerSettings settings;
1467 settings.impl_side_painting = true; 1468 settings.impl_side_painting = true;
1468 StateMachine state(settings); 1469 StateMachine state(settings);
1469 state.SetCanStart(); 1470 state.SetCanStart();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1542 SchedulerStateMachine::READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT, 1543 SchedulerStateMachine::READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT,
1543 state.readback_state()); 1544 state.readback_state());
1544 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 1545 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT,
1545 state.CommitState()); 1546 state.CommitState());
1546 1547
1547 // Finish the replacement commit. 1548 // Finish the replacement commit.
1548 state.NotifyBeginMainFrameStarted(); 1549 state.NotifyBeginMainFrameStarted();
1549 state.NotifyReadyToCommit(); 1550 state.NotifyReadyToCommit();
1550 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1551 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1551 1552
1552 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1553 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
1553 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1554 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1554 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1555 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1555 state.OnBeginImplFrameDeadline(); 1556 state.OnBeginImplFrameDeadline();
1556 EXPECT_ACTION_UPDATE_STATE( 1557 EXPECT_ACTION_UPDATE_STATE(
1557 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1558 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1558 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_IDLE, state.readback_state()); 1559 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_IDLE, state.readback_state());
1559 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1560 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1560 } 1561 }
1561 1562
1562 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) { 1563 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1647 if (settings.main_frame_before_draw_enabled) { 1648 if (settings.main_frame_before_draw_enabled) {
1648 // New replacement commit is scheduled. 1649 // New replacement commit is scheduled.
1649 EXPECT_ACTION_UPDATE_STATE( 1650 EXPECT_ACTION_UPDATE_STATE(
1650 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1651 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1651 // Forced commit is started. 1652 // Forced commit is started.
1652 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_WAITING_FOR_COMMIT, 1653 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_WAITING_FOR_COMMIT,
1653 state.readback_state()); 1654 state.readback_state());
1654 } 1655 }
1655 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1656 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1656 1657
1657 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1658 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
1658 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1659 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1659 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1660 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1660 // Perform the draw & swap of replacement commit. 1661 // Perform the draw & swap of replacement commit.
1661 state.OnBeginImplFrameDeadline(); 1662 state.OnBeginImplFrameDeadline();
1662 EXPECT_ACTION_UPDATE_STATE( 1663 EXPECT_ACTION_UPDATE_STATE(
1663 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1664 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1664 if (!settings.main_frame_before_draw_enabled) { 1665 if (!settings.main_frame_before_draw_enabled) {
1665 // New replacement commit is scheduled. 1666 // New replacement commit is scheduled.
1666 EXPECT_ACTION_UPDATE_STATE( 1667 EXPECT_ACTION_UPDATE_STATE(
1667 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1668 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
(...skipping 19 matching lines...) Expand all
1687 state.CommitState()); 1688 state.CommitState());
1688 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1689 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1689 1690
1690 // Finish the replacement commit and draw it. 1691 // Finish the replacement commit and draw it.
1691 state.NotifyBeginMainFrameStarted(); 1692 state.NotifyBeginMainFrameStarted();
1692 state.NotifyReadyToCommit(); 1693 state.NotifyReadyToCommit();
1693 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1694 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1694 state.NotifyReadyToActivate(); 1695 state.NotifyReadyToActivate();
1695 EXPECT_ACTION_UPDATE_STATE( 1696 EXPECT_ACTION_UPDATE_STATE(
1696 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE); 1697 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE);
1697 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1698 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
1698 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1699 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1699 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1700 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1700 state.OnBeginImplFrameDeadline(); 1701 state.OnBeginImplFrameDeadline();
1701 EXPECT_ACTION_UPDATE_STATE( 1702 EXPECT_ACTION_UPDATE_STATE(
1702 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1703 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1703 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_IDLE, state.readback_state()); 1704 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_IDLE, state.readback_state());
1704 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1705 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1705 } 1706 }
1706 1707
1707 // Explicitly test when main_frame_before_draw_enabled = true. 1708 // Explicitly test when main_frame_before_draw_enabled = true.
(...skipping 29 matching lines...) Expand all
1737 // is idle because main_frame_before_activation is enabled. 1738 // is idle because main_frame_before_activation is enabled.
1738 state.SetCommitState( 1739 state.SetCommitState(
1739 SchedulerStateMachine::COMMIT_STATE_IDLE); 1740 SchedulerStateMachine::COMMIT_STATE_IDLE);
1740 state.SetReadbackState( 1741 state.SetReadbackState(
1741 SchedulerStateMachine::READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION); 1742 SchedulerStateMachine::READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION);
1742 state.SetHasPendingTree(true); 1743 state.SetHasPendingTree(true);
1743 1744
1744 // New commit is requested and scheduled when impl-side painting is in 1745 // New commit is requested and scheduled when impl-side painting is in
1745 // progress. 1746 // progress.
1746 state.SetNeedsCommit(); 1747 state.SetNeedsCommit();
1747 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1748 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
1748 EXPECT_ACTION_UPDATE_STATE( 1749 EXPECT_ACTION_UPDATE_STATE(
1749 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1750 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1750 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1751 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1751 1752
1752 // Forced commit is requested during the impl-side painting. 1753 // Forced commit is requested during the impl-side painting.
1753 state.SetNeedsForcedCommitForReadback(); 1754 state.SetNeedsForcedCommitForReadback();
1754 EXPECT_FALSE(state.NeedsCommit()); 1755 EXPECT_FALSE(state.NeedsCommit());
1755 1756
1756 state.OnBeginImplFrameDeadline(); 1757 state.OnBeginImplFrameDeadline();
1757 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1758 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1758 1759
1759 state.NotifyReadyToActivate(); 1760 state.NotifyReadyToActivate();
1760 EXPECT_ACTION_UPDATE_STATE( 1761 EXPECT_ACTION_UPDATE_STATE(
1761 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE); 1762 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE);
1762 // Replacement commit for requested forced commit is already scheduled. 1763 // Replacement commit for requested forced commit is already scheduled.
1763 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_WAITING_FOR_COMMIT, 1764 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_WAITING_FOR_COMMIT,
1764 state.readback_state()); 1765 state.readback_state());
1765 EXPECT_FALSE(state.NeedsCommit()); 1766 EXPECT_FALSE(state.NeedsCommit());
1766 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1767 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1767 1768
1768 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1769 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
1769 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1770 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1770 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1771 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1771 // Perform the draw & swap of replacement commit. 1772 // Perform the draw & swap of replacement commit.
1772 state.OnBeginImplFrameDeadline(); 1773 state.OnBeginImplFrameDeadline();
1773 EXPECT_ACTION_UPDATE_STATE( 1774 EXPECT_ACTION_UPDATE_STATE(
1774 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1775 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1775 EXPECT_ACTION_UPDATE_STATE( 1776 EXPECT_ACTION_UPDATE_STATE(
1776 SchedulerStateMachine::ACTION_NONE); 1777 SchedulerStateMachine::ACTION_NONE);
1777 1778
1778 // forced commit is started. 1779 // forced commit is started.
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1989 settings.impl_side_painting = true; 1990 settings.impl_side_painting = true;
1990 StateMachine state(settings); 1991 StateMachine state(settings);
1991 state.SetCanStart(); 1992 state.SetCanStart();
1992 state.UpdateState(state.NextAction()); 1993 state.UpdateState(state.NextAction());
1993 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1994 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1994 state.SetVisible(true); 1995 state.SetVisible(true);
1995 state.SetCanDraw(true); 1996 state.SetCanDraw(true);
1996 1997
1997 // This test mirrors what happens during the first frame of a scroll gesture. 1998 // This test mirrors what happens during the first frame of a scroll gesture.
1998 // First we get the input event and a BeginFrame. 1999 // First we get the input event and a BeginFrame.
1999 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 2000 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
2000 2001
2001 // As a response the compositor requests a redraw and a commit to tell the 2002 // As a response the compositor requests a redraw and a commit to tell the
2002 // main thread about the new scroll offset. 2003 // main thread about the new scroll offset.
2003 state.SetNeedsRedraw(true); 2004 state.SetNeedsRedraw(true);
2004 state.SetNeedsCommit(); 2005 state.SetNeedsCommit();
2005 2006
2006 // We should start the commit normally. 2007 // We should start the commit normally.
2007 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 2008 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
2008 EXPECT_ACTION_UPDATE_STATE( 2009 EXPECT_ACTION_UPDATE_STATE(
2009 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 2010 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
(...skipping 13 matching lines...) Expand all
2023 settings.impl_side_painting = true; 2024 settings.impl_side_painting = true;
2024 StateMachine state(settings); 2025 StateMachine state(settings);
2025 state.SetCanStart(); 2026 state.SetCanStart();
2026 state.UpdateState(state.NextAction()); 2027 state.UpdateState(state.NextAction());
2027 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 2028 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
2028 state.SetVisible(true); 2029 state.SetVisible(true);
2029 state.SetCanDraw(true); 2030 state.SetCanDraw(true);
2030 2031
2031 // This test ensures that impl-draws are prioritized over main thread updates 2032 // This test ensures that impl-draws are prioritized over main thread updates
2032 // in prefer smoothness mode. 2033 // in prefer smoothness mode.
2033 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 2034 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
2034 state.SetNeedsRedraw(true); 2035 state.SetNeedsRedraw(true);
2035 state.SetNeedsCommit(); 2036 state.SetNeedsCommit();
2036 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 2037 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
2037 EXPECT_ACTION_UPDATE_STATE( 2038 EXPECT_ACTION_UPDATE_STATE(
2038 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 2039 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
2039 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2040 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2040 2041
2041 // The deadline is not triggered early until we enter prefer smoothness mode. 2042 // The deadline is not triggered early until we enter prefer smoothness mode.
2042 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 2043 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineEarly());
2043 state.SetSmoothnessTakesPriority(true); 2044 state.SetSmoothnessTakesPriority(true);
2044 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 2045 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly());
2045 } 2046 }
2046 2047
2047 TEST(SchedulerStateMachineTest, TestSetNeedsAnimate) { 2048 TEST(SchedulerStateMachineTest, TestSetNeedsAnimate) {
2048 SchedulerSettings settings; 2049 SchedulerSettings settings;
2049 settings.impl_side_painting = true; 2050 settings.impl_side_painting = true;
2050 StateMachine state(settings); 2051 StateMachine state(settings);
2051 state.SetCanStart(); 2052 state.SetCanStart();
2052 state.UpdateState(state.NextAction()); 2053 state.UpdateState(state.NextAction());
2053 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 2054 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
2054 state.SetVisible(true); 2055 state.SetVisible(true);
2055 state.SetCanDraw(true); 2056 state.SetCanDraw(true);
2056 2057
2057 // Test requesting an animation that, when run, causes us to draw. 2058 // Test requesting an animation that, when run, causes us to draw.
2058 state.SetNeedsAnimate(); 2059 state.SetNeedsAnimate();
2059 EXPECT_TRUE(state.BeginFrameNeeded()); 2060 EXPECT_TRUE(state.BeginFrameNeeded());
2060 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2061 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2061 2062
2062 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 2063 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
2063 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 2064 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
2064 2065
2065 state.OnBeginImplFrameDeadlinePending(); 2066 state.OnBeginImplFrameDeadlinePending();
2066 state.OnBeginImplFrameDeadline(); 2067 state.OnBeginImplFrameDeadline();
2067 EXPECT_ACTION_UPDATE_STATE( 2068 EXPECT_ACTION_UPDATE_STATE(
2068 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 2069 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
2069 } 2070 }
2070 2071
2071 TEST(SchedulerStateMachineTest, TestAnimateBeforeCommit) { 2072 TEST(SchedulerStateMachineTest, TestAnimateBeforeCommit) {
2072 SchedulerSettings settings; 2073 SchedulerSettings settings;
2073 settings.impl_side_painting = true; 2074 settings.impl_side_painting = true;
2074 StateMachine state(settings); 2075 StateMachine state(settings);
2075 state.SetCanStart(); 2076 state.SetCanStart();
2076 state.UpdateState(state.NextAction()); 2077 state.UpdateState(state.NextAction());
2077 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 2078 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
2078 state.SetVisible(true); 2079 state.SetVisible(true);
2079 state.SetCanDraw(true); 2080 state.SetCanDraw(true);
2080 2081
2081 // Check that animations are updated before we start a commit. 2082 // Check that animations are updated before we start a commit.
2082 state.SetNeedsAnimate(); 2083 state.SetNeedsAnimate();
2083 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2084 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2084 state.SetNeedsCommit(); 2085 state.SetNeedsCommit();
2085 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2086 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2086 EXPECT_TRUE(state.BeginFrameNeeded()); 2087 EXPECT_TRUE(state.BeginFrameNeeded());
2087 2088
2088 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 2089 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
2089 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 2090 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
2090 EXPECT_ACTION_UPDATE_STATE( 2091 EXPECT_ACTION_UPDATE_STATE(
2091 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 2092 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
2092 2093
2093 state.OnBeginImplFrameDeadlinePending(); 2094 state.OnBeginImplFrameDeadlinePending();
2094 state.OnBeginImplFrameDeadline(); 2095 state.OnBeginImplFrameDeadline();
2095 EXPECT_ACTION_UPDATE_STATE( 2096 EXPECT_ACTION_UPDATE_STATE(
2096 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 2097 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
2097 } 2098 }
2098 2099
2099 TEST(SchedulerStateMachineTest, TestSetNeedsAnimateAfterAnimate) { 2100 TEST(SchedulerStateMachineTest, TestSetNeedsAnimateAfterAnimate) {
2100 SchedulerSettings settings; 2101 SchedulerSettings settings;
2101 settings.impl_side_painting = true; 2102 settings.impl_side_painting = true;
2102 StateMachine state(settings); 2103 StateMachine state(settings);
2103 state.SetCanStart(); 2104 state.SetCanStart();
2104 state.UpdateState(state.NextAction()); 2105 state.UpdateState(state.NextAction());
2105 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 2106 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
2106 state.SetVisible(true); 2107 state.SetVisible(true);
2107 state.SetCanDraw(true); 2108 state.SetCanDraw(true);
2108 2109
2109 // Test requesting an animation after we have already animated during this 2110 // Test requesting an animation after we have already animated during this
2110 // frame. 2111 // frame.
2111 state.SetNeedsRedraw(true); 2112 state.SetNeedsRedraw(true);
2112 EXPECT_TRUE(state.BeginFrameNeeded()); 2113 EXPECT_TRUE(state.BeginFrameNeeded());
2113 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2114 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2114 2115
2115 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 2116 state.OnBeginImplFrame(BeginFrameArgsCreateForTesting());
2116 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 2117 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
2117 2118
2118 state.SetNeedsAnimate(); 2119 state.SetNeedsAnimate();
2119 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2120 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2120 2121
2121 state.OnBeginImplFrameDeadline(); 2122 state.OnBeginImplFrameDeadline();
2122 EXPECT_ACTION_UPDATE_STATE( 2123 EXPECT_ACTION_UPDATE_STATE(
2123 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 2124 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
2124 } 2125 }
2125 2126
2126 } // namespace 2127 } // namespace
2127 } // namespace cc 2128 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698