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

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

Issue 885443002: Roll Chrome into Mojo. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Rebase to ToT mojo Created 5 years, 10 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
« no previous file with comments | « cc/scheduler/scheduler_state_machine.cc ('k') | cc/scheduler/scheduler_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "cc/scheduler/scheduler.h" 8 #include "cc/scheduler/scheduler.h"
9 #include "cc/test/begin_frame_args_test.h" 9 #include "cc/test/begin_frame_args_test.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 state.UpdateState(action); \ 42 state.UpdateState(action); \
43 if (action == SchedulerStateMachine::ACTION_NONE) { \ 43 if (action == SchedulerStateMachine::ACTION_NONE) { \
44 if (state.begin_impl_frame_state() == \ 44 if (state.begin_impl_frame_state() == \
45 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING) \ 45 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING) \
46 state.OnBeginImplFrameDeadlinePending(); \ 46 state.OnBeginImplFrameDeadlinePending(); \
47 if (state.begin_impl_frame_state() == \ 47 if (state.begin_impl_frame_state() == \
48 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) \ 48 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) \
49 state.OnBeginImplFrameIdle(); \ 49 state.OnBeginImplFrameIdle(); \
50 } 50 }
51 51
52 #define SET_UP_STATE(state) \
53 state.SetCanStart(); \
54 state.UpdateState(state.NextAction()); \
55 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); \
56 state.SetVisible(true); \
57 state.SetCanDraw(true);
58
52 namespace cc { 59 namespace cc {
53 60
54 namespace { 61 namespace {
55 62
56 const SchedulerStateMachine::BeginImplFrameState all_begin_impl_frame_states[] = 63 const SchedulerStateMachine::BeginImplFrameState all_begin_impl_frame_states[] =
57 {SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, 64 {SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE,
58 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING, 65 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING,
59 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME, 66 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME,
60 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, }; 67 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, };
61 68
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 } 210 }
204 } 211 }
205 212
206 // Explicitly test main_frame_before_activation_enabled = true 213 // Explicitly test main_frame_before_activation_enabled = true
207 TEST(SchedulerStateMachineTest, MainFrameBeforeActivationEnabled) { 214 TEST(SchedulerStateMachineTest, MainFrameBeforeActivationEnabled) {
208 SchedulerSettings scheduler_settings; 215 SchedulerSettings scheduler_settings;
209 scheduler_settings.impl_side_painting = true; 216 scheduler_settings.impl_side_painting = true;
210 scheduler_settings.main_frame_before_activation_enabled = true; 217 scheduler_settings.main_frame_before_activation_enabled = true;
211 StateMachine state(scheduler_settings); 218 StateMachine state(scheduler_settings);
212 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE); 219 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE);
213 state.SetCanStart(); 220 SET_UP_STATE(state)
214 state.UpdateState(state.NextAction());
215 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
216 state.SetNeedsRedraw(false); 221 state.SetNeedsRedraw(false);
217 state.SetVisible(true);
218 state.SetCanDraw(true);
219 state.SetNeedsCommit(); 222 state.SetNeedsCommit();
220 223
221 EXPECT_TRUE(state.BeginFrameNeeded()); 224 EXPECT_TRUE(state.BeginFrameNeeded());
222 225
223 // Commit to the pending tree. 226 // Commit to the pending tree.
224 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 227 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
225 EXPECT_ACTION_UPDATE_STATE( 228 EXPECT_ACTION_UPDATE_STATE(
226 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 229 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
227 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 230 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
228 231
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 state.DidSwapBuffersComplete(); 266 state.DidSwapBuffersComplete();
264 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 267 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
265 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 268 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
266 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE); 269 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE);
267 } 270 }
268 271
269 TEST(SchedulerStateMachineTest, 272 TEST(SchedulerStateMachineTest,
270 TestFailedDrawForAnimationCheckerboardSetsNeedsCommitAndDoesNotDrawAgain) { 273 TestFailedDrawForAnimationCheckerboardSetsNeedsCommitAndDoesNotDrawAgain) {
271 SchedulerSettings default_scheduler_settings; 274 SchedulerSettings default_scheduler_settings;
272 StateMachine state(default_scheduler_settings); 275 StateMachine state(default_scheduler_settings);
273 state.SetCanStart(); 276 SET_UP_STATE(state)
274 state.UpdateState(state.NextAction());
275 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
276 state.SetVisible(true);
277 state.SetCanDraw(true);
278 state.SetNeedsRedraw(true); 277 state.SetNeedsRedraw(true);
279 EXPECT_TRUE(state.RedrawPending()); 278 EXPECT_TRUE(state.RedrawPending());
280 EXPECT_TRUE(state.BeginFrameNeeded()); 279 EXPECT_TRUE(state.BeginFrameNeeded());
281 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 280 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
282 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 281 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
283 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 282 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
284 state.OnBeginImplFrameDeadline(); 283 state.OnBeginImplFrameDeadline();
285 284
286 // We're drawing now. 285 // We're drawing now.
287 EXPECT_ACTION_UPDATE_STATE( 286 EXPECT_ACTION_UPDATE_STATE(
(...skipping 11 matching lines...) Expand all
299 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 298 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
300 EXPECT_ACTION_UPDATE_STATE( 299 EXPECT_ACTION_UPDATE_STATE(
301 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 300 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
302 EXPECT_TRUE(state.RedrawPending()); 301 EXPECT_TRUE(state.RedrawPending());
303 EXPECT_TRUE(state.CommitPending()); 302 EXPECT_TRUE(state.CommitPending());
304 } 303 }
305 304
306 TEST(SchedulerStateMachineTest, TestFailedDrawForMissingHighResNeedsCommit) { 305 TEST(SchedulerStateMachineTest, TestFailedDrawForMissingHighResNeedsCommit) {
307 SchedulerSettings default_scheduler_settings; 306 SchedulerSettings default_scheduler_settings;
308 StateMachine state(default_scheduler_settings); 307 StateMachine state(default_scheduler_settings);
309 state.SetCanStart(); 308 SET_UP_STATE(state)
310 state.UpdateState(state.NextAction());
311 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
312 state.SetVisible(true);
313 state.SetCanDraw(true);
314 state.SetNeedsRedraw(true); 309 state.SetNeedsRedraw(true);
315 EXPECT_TRUE(state.RedrawPending()); 310 EXPECT_TRUE(state.RedrawPending());
316 EXPECT_TRUE(state.BeginFrameNeeded()); 311 EXPECT_TRUE(state.BeginFrameNeeded());
317 312
318 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 313 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
319 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 314 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
320 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 315 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
321 state.OnBeginImplFrameDeadline(); 316 state.OnBeginImplFrameDeadline();
322 EXPECT_ACTION_UPDATE_STATE( 317 EXPECT_ACTION_UPDATE_STATE(
323 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 318 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
324 state.DidSwapBuffers(); 319 state.DidSwapBuffers();
325 state.DidSwapBuffersComplete(); 320 state.DidSwapBuffersComplete();
326 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 321 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
327 EXPECT_FALSE(state.RedrawPending()); 322 EXPECT_FALSE(state.RedrawPending());
328 EXPECT_FALSE(state.CommitPending()); 323 EXPECT_FALSE(state.CommitPending());
329 324
330 // Missing high res content requires a commit (but not a redraw) 325 // Missing high res content requires a commit (but not a redraw)
331 state.DidDrawIfPossibleCompleted(DRAW_ABORTED_MISSING_HIGH_RES_CONTENT); 326 state.DidDrawIfPossibleCompleted(DRAW_ABORTED_MISSING_HIGH_RES_CONTENT);
332 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 327 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
333 EXPECT_ACTION_UPDATE_STATE( 328 EXPECT_ACTION_UPDATE_STATE(
334 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 329 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
335 EXPECT_FALSE(state.RedrawPending()); 330 EXPECT_FALSE(state.RedrawPending());
336 EXPECT_TRUE(state.CommitPending()); 331 EXPECT_TRUE(state.CommitPending());
337 } 332 }
338 333
339 TEST(SchedulerStateMachineTest, 334 TEST(SchedulerStateMachineTest,
340 TestsetNeedsRedrawDuringFailedDrawDoesNotRemoveNeedsRedraw) { 335 TestsetNeedsRedrawDuringFailedDrawDoesNotRemoveNeedsRedraw) {
341 SchedulerSettings default_scheduler_settings; 336 SchedulerSettings default_scheduler_settings;
342 StateMachine state(default_scheduler_settings); 337 StateMachine state(default_scheduler_settings);
343 state.SetCanStart(); 338 SET_UP_STATE(state)
344 state.UpdateState(state.NextAction());
345 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
346
347 state.SetVisible(true);
348 state.SetCanDraw(true);
349 state.SetNeedsRedraw(true); 339 state.SetNeedsRedraw(true);
350 EXPECT_TRUE(state.RedrawPending()); 340 EXPECT_TRUE(state.RedrawPending());
351 EXPECT_TRUE(state.BeginFrameNeeded()); 341 EXPECT_TRUE(state.BeginFrameNeeded());
352 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 342 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
353 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 343 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
354 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 344 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
355 state.OnBeginImplFrameDeadline(); 345 state.OnBeginImplFrameDeadline();
356 346
357 // We're drawing now. 347 // We're drawing now.
358 EXPECT_ACTION_UPDATE_STATE( 348 EXPECT_ACTION_UPDATE_STATE(
(...skipping 16 matching lines...) Expand all
375 EXPECT_ACTION_UPDATE_STATE( 365 EXPECT_ACTION_UPDATE_STATE(
376 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 366 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
377 EXPECT_TRUE(state.RedrawPending()); 367 EXPECT_TRUE(state.RedrawPending());
378 } 368 }
379 369
380 TEST(SchedulerStateMachineTest, 370 TEST(SchedulerStateMachineTest,
381 TestFailedDrawsEventuallyForceDrawAfterNextCommit) { 371 TestFailedDrawsEventuallyForceDrawAfterNextCommit) {
382 SchedulerSettings scheduler_settings; 372 SchedulerSettings scheduler_settings;
383 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced_ = 1; 373 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced_ = 1;
384 StateMachine state(scheduler_settings); 374 StateMachine state(scheduler_settings);
385 state.SetCanStart(); 375 SET_UP_STATE(state)
386 state.UpdateState(state.NextAction());
387 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
388 state.SetVisible(true);
389 state.SetCanDraw(true);
390 376
391 // Start a commit. 377 // Start a commit.
392 state.SetNeedsCommit(); 378 state.SetNeedsCommit();
393 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 379 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
394 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 380 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
395 EXPECT_ACTION_UPDATE_STATE( 381 EXPECT_ACTION_UPDATE_STATE(
396 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 382 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
397 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 383 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
398 EXPECT_TRUE(state.CommitPending()); 384 EXPECT_TRUE(state.CommitPending());
399 385
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 state.DidSwapBuffersComplete(); 419 state.DidSwapBuffersComplete();
434 } 420 }
435 421
436 TEST(SchedulerStateMachineTest, TestFailedDrawsDoNotRestartForcedDraw) { 422 TEST(SchedulerStateMachineTest, TestFailedDrawsDoNotRestartForcedDraw) {
437 SchedulerSettings scheduler_settings; 423 SchedulerSettings scheduler_settings;
438 int draw_limit = 1; 424 int draw_limit = 1;
439 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced_ = 425 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced_ =
440 draw_limit; 426 draw_limit;
441 scheduler_settings.impl_side_painting = true; 427 scheduler_settings.impl_side_painting = true;
442 StateMachine state(scheduler_settings); 428 StateMachine state(scheduler_settings);
443 state.SetCanStart(); 429 SET_UP_STATE(state)
444 state.UpdateState(state.NextAction());
445 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
446 state.SetVisible(true);
447 state.SetCanDraw(true);
448 430
449 // Start a commit. 431 // Start a commit.
450 state.SetNeedsCommit(); 432 state.SetNeedsCommit();
451 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 433 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
452 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 434 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
453 EXPECT_ACTION_UPDATE_STATE( 435 EXPECT_ACTION_UPDATE_STATE(
454 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 436 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
455 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 437 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
456 EXPECT_TRUE(state.CommitPending()); 438 EXPECT_TRUE(state.CommitPending());
457 439
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 for (int i = 0; i < draw_limit + 1; ++i) 472 for (int i = 0; i < draw_limit + 1; ++i)
491 state.DidDrawIfPossibleCompleted(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 473 state.DidDrawIfPossibleCompleted(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
492 EXPECT_TRUE(state.RedrawPending()); 474 EXPECT_TRUE(state.RedrawPending());
493 EXPECT_TRUE(state.ForcedRedrawState() == 475 EXPECT_TRUE(state.ForcedRedrawState() ==
494 SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION); 476 SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION);
495 } 477 }
496 478
497 TEST(SchedulerStateMachineTest, TestFailedDrawIsRetriedInNextBeginImplFrame) { 479 TEST(SchedulerStateMachineTest, TestFailedDrawIsRetriedInNextBeginImplFrame) {
498 SchedulerSettings default_scheduler_settings; 480 SchedulerSettings default_scheduler_settings;
499 StateMachine state(default_scheduler_settings); 481 StateMachine state(default_scheduler_settings);
500 state.SetCanStart(); 482 SET_UP_STATE(state)
501 state.UpdateState(state.NextAction());
502 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
503 state.SetVisible(true);
504 state.SetCanDraw(true);
505 483
506 // Start a draw. 484 // Start a draw.
507 state.SetNeedsRedraw(true); 485 state.SetNeedsRedraw(true);
508 EXPECT_TRUE(state.BeginFrameNeeded()); 486 EXPECT_TRUE(state.BeginFrameNeeded());
509 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 487 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
510 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 488 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
511 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 489 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
512 state.OnBeginImplFrameDeadline(); 490 state.OnBeginImplFrameDeadline();
513 EXPECT_TRUE(state.RedrawPending()); 491 EXPECT_TRUE(state.RedrawPending());
514 EXPECT_ACTION_UPDATE_STATE( 492 EXPECT_ACTION_UPDATE_STATE(
(...skipping 18 matching lines...) Expand all
533 EXPECT_ACTION_UPDATE_STATE( 511 EXPECT_ACTION_UPDATE_STATE(
534 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 512 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
535 state.DidSwapBuffers(); 513 state.DidSwapBuffers();
536 state.DidSwapBuffersComplete(); 514 state.DidSwapBuffersComplete();
537 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 515 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
538 } 516 }
539 517
540 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) { 518 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) {
541 SchedulerSettings default_scheduler_settings; 519 SchedulerSettings default_scheduler_settings;
542 StateMachine state(default_scheduler_settings); 520 StateMachine state(default_scheduler_settings);
543 state.SetCanStart(); 521 SET_UP_STATE(state)
544 state.UpdateState(state.NextAction());
545 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
546 state.SetVisible(true);
547 state.SetCanDraw(true);
548 state.SetNeedsRedraw(true); 522 state.SetNeedsRedraw(true);
549 523
550 // Draw the first frame. 524 // Draw the first frame.
551 EXPECT_TRUE(state.BeginFrameNeeded()); 525 EXPECT_TRUE(state.BeginFrameNeeded());
552 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 526 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
553 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 527 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
554 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 528 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
555 529
556 state.OnBeginImplFrameDeadline(); 530 state.OnBeginImplFrameDeadline();
557 EXPECT_ACTION_UPDATE_STATE( 531 EXPECT_ACTION_UPDATE_STATE(
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 711 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
738 state.OnBeginImplFrameDeadline(); 712 state.OnBeginImplFrameDeadline();
739 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 713 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
740 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 714 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
741 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 715 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
742 } 716 }
743 717
744 TEST(SchedulerStateMachineTest, TestSetNeedsCommitIsNotLost) { 718 TEST(SchedulerStateMachineTest, TestSetNeedsCommitIsNotLost) {
745 SchedulerSettings scheduler_settings; 719 SchedulerSettings scheduler_settings;
746 StateMachine state(scheduler_settings); 720 StateMachine state(scheduler_settings);
747 state.SetCanStart(); 721 SET_UP_STATE(state)
748 state.UpdateState(state.NextAction());
749 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
750 state.SetNeedsCommit(); 722 state.SetNeedsCommit();
751 state.SetVisible(true);
752 state.SetCanDraw(true);
753 723
754 EXPECT_TRUE(state.BeginFrameNeeded()); 724 EXPECT_TRUE(state.BeginFrameNeeded());
755 725
756 // Begin the frame. 726 // Begin the frame.
757 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 727 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
758 EXPECT_ACTION_UPDATE_STATE( 728 EXPECT_ACTION_UPDATE_STATE(
759 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 729 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
760 EXPECT_COMMIT_STATE( 730 EXPECT_COMMIT_STATE(
761 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT); 731 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT);
762 732
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 778 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
809 state.DidSwapBuffers(); 779 state.DidSwapBuffers();
810 state.DidDrawIfPossibleCompleted(DRAW_SUCCESS); 780 state.DidDrawIfPossibleCompleted(DRAW_SUCCESS);
811 state.DidSwapBuffersComplete(); 781 state.DidSwapBuffersComplete();
812 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 782 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
813 } 783 }
814 784
815 TEST(SchedulerStateMachineTest, TestFullCycle) { 785 TEST(SchedulerStateMachineTest, TestFullCycle) {
816 SchedulerSettings default_scheduler_settings; 786 SchedulerSettings default_scheduler_settings;
817 StateMachine state(default_scheduler_settings); 787 StateMachine state(default_scheduler_settings);
818 state.SetCanStart(); 788 SET_UP_STATE(state)
819 state.UpdateState(state.NextAction());
820 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
821 state.SetVisible(true);
822 state.SetCanDraw(true);
823 789
824 // Start clean and set commit. 790 // Start clean and set commit.
825 state.SetNeedsCommit(); 791 state.SetNeedsCommit();
826 792
827 // Begin the frame. 793 // Begin the frame.
828 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 794 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
829 EXPECT_ACTION_UPDATE_STATE( 795 EXPECT_ACTION_UPDATE_STATE(
830 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 796 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
831 EXPECT_COMMIT_STATE( 797 EXPECT_COMMIT_STATE(
832 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT); 798 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT);
(...skipping 25 matching lines...) Expand all
858 // Should be synchronized, no draw needed, no action needed. 824 // Should be synchronized, no draw needed, no action needed.
859 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 825 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
860 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE); 826 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE);
861 EXPECT_FALSE(state.needs_redraw()); 827 EXPECT_FALSE(state.needs_redraw());
862 } 828 }
863 829
864 TEST(SchedulerStateMachineTest, TestFullCycleWithMainThreadLowLatencyMode) { 830 TEST(SchedulerStateMachineTest, TestFullCycleWithMainThreadLowLatencyMode) {
865 SchedulerSettings scheduler_settings; 831 SchedulerSettings scheduler_settings;
866 scheduler_settings.main_thread_should_always_be_low_latency = true; 832 scheduler_settings.main_thread_should_always_be_low_latency = true;
867 StateMachine state(scheduler_settings); 833 StateMachine state(scheduler_settings);
868 state.SetCanStart(); 834 SET_UP_STATE(state)
869 state.UpdateState(state.NextAction());
870 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
871 state.SetVisible(true);
872 state.SetCanDraw(true);
873 835
874 // Start clean and set commit. 836 // Start clean and set commit.
875 state.SetNeedsCommit(); 837 state.SetNeedsCommit();
876 838
877 // Begin the frame. 839 // Begin the frame.
878 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 840 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
879 EXPECT_ACTION_UPDATE_STATE( 841 EXPECT_ACTION_UPDATE_STATE(
880 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 842 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
881 EXPECT_COMMIT_STATE( 843 EXPECT_COMMIT_STATE(
882 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT); 844 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 EXPECT_ACTION_UPDATE_STATE( 885 EXPECT_ACTION_UPDATE_STATE(
924 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 886 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
925 } 887 }
926 888
927 TEST(SchedulerStateMachineTest, 889 TEST(SchedulerStateMachineTest,
928 TestFullCycleWithMainThreadLowLatencyMode_ImplSidePaint) { 890 TestFullCycleWithMainThreadLowLatencyMode_ImplSidePaint) {
929 SchedulerSettings scheduler_settings; 891 SchedulerSettings scheduler_settings;
930 scheduler_settings.main_thread_should_always_be_low_latency = true; 892 scheduler_settings.main_thread_should_always_be_low_latency = true;
931 scheduler_settings.impl_side_painting = true; 893 scheduler_settings.impl_side_painting = true;
932 StateMachine state(scheduler_settings); 894 StateMachine state(scheduler_settings);
933 state.SetCanStart(); 895 SET_UP_STATE(state)
934 state.UpdateState(state.NextAction());
935 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
936 state.SetVisible(true);
937 state.SetCanDraw(true);
938 896
939 // Start clean and set commit. 897 // Start clean and set commit.
940 state.SetNeedsCommit(); 898 state.SetNeedsCommit();
941 899
942 // Begin the frame. 900 // Begin the frame.
943 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 901 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
944 EXPECT_ACTION_UPDATE_STATE( 902 EXPECT_ACTION_UPDATE_STATE(
945 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 903 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
946 EXPECT_COMMIT_STATE( 904 EXPECT_COMMIT_STATE(
947 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT); 905 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 // Now will be able to start main frame. 965 // Now will be able to start main frame.
1008 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE); 966 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE);
1009 EXPECT_FALSE(state.needs_redraw()); 967 EXPECT_FALSE(state.needs_redraw());
1010 EXPECT_ACTION_UPDATE_STATE( 968 EXPECT_ACTION_UPDATE_STATE(
1011 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 969 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1012 } 970 }
1013 971
1014 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) { 972 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) {
1015 SchedulerSettings default_scheduler_settings; 973 SchedulerSettings default_scheduler_settings;
1016 StateMachine state(default_scheduler_settings); 974 StateMachine state(default_scheduler_settings);
1017 state.SetCanStart(); 975 SET_UP_STATE(state)
1018 state.UpdateState(state.NextAction());
1019 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1020 state.SetVisible(true);
1021 state.SetCanDraw(true);
1022 976
1023 // Start clean and set commit. 977 // Start clean and set commit.
1024 state.SetNeedsCommit(); 978 state.SetNeedsCommit();
1025 979
1026 // Begin the frame. 980 // Begin the frame.
1027 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 981 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1028 EXPECT_ACTION_UPDATE_STATE( 982 EXPECT_ACTION_UPDATE_STATE(
1029 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 983 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1030 EXPECT_COMMIT_STATE( 984 EXPECT_COMMIT_STATE(
1031 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT); 985 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1031 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1078 state.SetNeedsCommit(); 1032 state.SetNeedsCommit();
1079 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1033 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1080 } 1034 }
1081 1035
1082 // See ThreadProxy::BeginMainFrame "EarlyOut_NotVisible" / 1036 // See ThreadProxy::BeginMainFrame "EarlyOut_NotVisible" /
1083 // "EarlyOut_OutputSurfaceLost" cases. 1037 // "EarlyOut_OutputSurfaceLost" cases.
1084 TEST(SchedulerStateMachineTest, TestAbortBeginMainFrameBecauseInvisible) { 1038 TEST(SchedulerStateMachineTest, TestAbortBeginMainFrameBecauseInvisible) {
1085 SchedulerSettings default_scheduler_settings; 1039 SchedulerSettings default_scheduler_settings;
1086 StateMachine state(default_scheduler_settings); 1040 StateMachine state(default_scheduler_settings);
1087 state.SetCanStart(); 1041 SET_UP_STATE(state)
1088 state.UpdateState(state.NextAction());
1089 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1090 state.SetVisible(true);
1091 state.SetCanDraw(true);
1092 1042
1093 // Start clean and set commit. 1043 // Start clean and set commit.
1094 state.SetNeedsCommit(); 1044 state.SetNeedsCommit();
1095 1045
1096 // Begin the frame while visible. 1046 // Begin the frame while visible.
1097 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1047 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1098 EXPECT_ACTION_UPDATE_STATE( 1048 EXPECT_ACTION_UPDATE_STATE(
1099 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1049 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1100 EXPECT_COMMIT_STATE( 1050 EXPECT_COMMIT_STATE(
1101 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT); 1051 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 // Check that a needs commit initiates a BeginMainFrame. 1162 // Check that a needs commit initiates a BeginMainFrame.
1213 state.SetNeedsCommit(); 1163 state.SetNeedsCommit();
1214 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1164 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1215 EXPECT_ACTION_UPDATE_STATE( 1165 EXPECT_ACTION_UPDATE_STATE(
1216 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1166 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1217 } 1167 }
1218 1168
1219 TEST(SchedulerStateMachineTest, TestContextLostWhenCompletelyIdle) { 1169 TEST(SchedulerStateMachineTest, TestContextLostWhenCompletelyIdle) {
1220 SchedulerSettings default_scheduler_settings; 1170 SchedulerSettings default_scheduler_settings;
1221 StateMachine state(default_scheduler_settings); 1171 StateMachine state(default_scheduler_settings);
1222 state.SetCanStart(); 1172 SET_UP_STATE(state)
1223 state.UpdateState(state.NextAction());
1224 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1225
1226 state.SetVisible(true);
1227 state.SetCanDraw(true);
1228 1173
1229 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1174 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1230 state.NextAction()); 1175 state.NextAction());
1231 state.DidLoseOutputSurface(); 1176 state.DidLoseOutputSurface();
1232 1177
1233 EXPECT_ACTION(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 1178 EXPECT_ACTION(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1234 state.UpdateState(state.NextAction()); 1179 state.UpdateState(state.NextAction());
1235 1180
1236 // Once context recreation begins, nothing should happen. 1181 // Once context recreation begins, nothing should happen.
1237 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1182 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1238 1183
1239 // Recreate the context. 1184 // Recreate the context.
1240 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1185 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1241 1186
1242 // When the context is recreated, we should begin a commit. 1187 // When the context is recreated, we should begin a commit.
1243 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1188 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1244 EXPECT_ACTION_UPDATE_STATE( 1189 EXPECT_ACTION_UPDATE_STATE(
1245 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1190 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1246 } 1191 }
1247 1192
1248 TEST(SchedulerStateMachineTest, 1193 TEST(SchedulerStateMachineTest,
1249 TestContextLostWhenIdleAndCommitRequestedWhileRecreating) { 1194 TestContextLostWhenIdleAndCommitRequestedWhileRecreating) {
1250 SchedulerSettings default_scheduler_settings; 1195 SchedulerSettings default_scheduler_settings;
1251 // We use impl side painting because it's the more complicated version. 1196 // We use impl side painting because it's the more complicated version.
1252 default_scheduler_settings.impl_side_painting = true; 1197 default_scheduler_settings.impl_side_painting = true;
1253 StateMachine state(default_scheduler_settings); 1198 StateMachine state(default_scheduler_settings);
1254 state.SetCanStart(); 1199 SET_UP_STATE(state)
1255 state.UpdateState(state.NextAction());
1256 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1257 state.SetVisible(true);
1258 state.SetCanDraw(true);
1259 1200
1260 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1201 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1261 state.NextAction()); 1202 state.NextAction());
1262 state.DidLoseOutputSurface(); 1203 state.DidLoseOutputSurface();
1263 EXPECT_EQ(state.output_surface_state(), 1204 EXPECT_EQ(state.output_surface_state(),
1264 SchedulerStateMachine::OUTPUT_SURFACE_LOST); 1205 SchedulerStateMachine::OUTPUT_SURFACE_LOST);
1265 1206
1266 EXPECT_ACTION_UPDATE_STATE( 1207 EXPECT_ACTION_UPDATE_STATE(
1267 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 1208 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1268 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1209 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1312 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1372 state.SetCanDraw(false); 1313 state.SetCanDraw(false);
1373 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1314 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1374 state.SetCanDraw(true); 1315 state.SetCanDraw(true);
1375 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1316 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1376 } 1317 }
1377 1318
1378 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) { 1319 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) {
1379 SchedulerSettings scheduler_settings; 1320 SchedulerSettings scheduler_settings;
1380 StateMachine state(scheduler_settings); 1321 StateMachine state(scheduler_settings);
1381 state.SetCanStart(); 1322 SET_UP_STATE(state)
1382 state.UpdateState(state.NextAction());
1383 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1384 state.SetVisible(true);
1385 state.SetCanDraw(true);
1386 1323
1387 // Get a commit in flight. 1324 // Get a commit in flight.
1388 state.SetNeedsCommit(); 1325 state.SetNeedsCommit();
1389 1326
1390 // Set damage and expect a draw. 1327 // Set damage and expect a draw.
1391 state.SetNeedsRedraw(true); 1328 state.SetNeedsRedraw(true);
1392 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1329 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1393 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1330 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1394 EXPECT_ACTION_UPDATE_STATE( 1331 EXPECT_ACTION_UPDATE_STATE(
1395 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1332 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 state.OnBeginImplFrameDeadline(); 1372 state.OnBeginImplFrameDeadline();
1436 EXPECT_IMPL_FRAME_STATE( 1373 EXPECT_IMPL_FRAME_STATE(
1437 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); 1374 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE);
1438 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); 1375 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1439 } 1376 }
1440 1377
1441 TEST(SchedulerStateMachineTest, 1378 TEST(SchedulerStateMachineTest,
1442 TestContextLostWhileCommitInProgressAndAnotherCommitRequested) { 1379 TestContextLostWhileCommitInProgressAndAnotherCommitRequested) {
1443 SchedulerSettings scheduler_settings; 1380 SchedulerSettings scheduler_settings;
1444 StateMachine state(scheduler_settings); 1381 StateMachine state(scheduler_settings);
1445 state.SetCanStart(); 1382 SET_UP_STATE(state)
1446 state.UpdateState(state.NextAction());
1447 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1448 state.SetVisible(true);
1449 state.SetCanDraw(true);
1450 1383
1451 // Get a commit in flight. 1384 // Get a commit in flight.
1452 state.SetNeedsCommit(); 1385 state.SetNeedsCommit();
1453 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1386 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1454 1387
1455 // Set damage and expect a draw. 1388 // Set damage and expect a draw.
1456 state.SetNeedsRedraw(true); 1389 state.SetNeedsRedraw(true);
1457 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1390 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1458 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1391 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1459 EXPECT_ACTION_UPDATE_STATE( 1392 EXPECT_ACTION_UPDATE_STATE(
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1521 EXPECT_ACTION_UPDATE_STATE( 1454 EXPECT_ACTION_UPDATE_STATE(
1522 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1455 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1523 state.DidSwapBuffers(); 1456 state.DidSwapBuffers();
1524 state.DidSwapBuffersComplete(); 1457 state.DidSwapBuffersComplete();
1525 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1458 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1526 } 1459 }
1527 1460
1528 TEST(SchedulerStateMachineTest, DontDrawBeforeCommitAfterLostOutputSurface) { 1461 TEST(SchedulerStateMachineTest, DontDrawBeforeCommitAfterLostOutputSurface) {
1529 SchedulerSettings default_scheduler_settings; 1462 SchedulerSettings default_scheduler_settings;
1530 StateMachine state(default_scheduler_settings); 1463 StateMachine state(default_scheduler_settings);
1531 state.SetCanStart(); 1464 SET_UP_STATE(state)
1532 state.UpdateState(state.NextAction());
1533 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1534 state.SetVisible(true);
1535 state.SetCanDraw(true);
1536 1465
1537 state.SetNeedsRedraw(true); 1466 state.SetNeedsRedraw(true);
1538 1467
1539 // Cause a lost output surface, and restore it. 1468 // Cause a lost output surface, and restore it.
1540 state.DidLoseOutputSurface(); 1469 state.DidLoseOutputSurface();
1541 EXPECT_ACTION(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 1470 EXPECT_ACTION(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1542 state.UpdateState(state.NextAction()); 1471 state.UpdateState(state.NextAction());
1543 state.DidCreateAndInitializeOutputSurface(); 1472 state.DidCreateAndInitializeOutputSurface();
1544 1473
1545 EXPECT_FALSE(state.RedrawPending()); 1474 EXPECT_FALSE(state.RedrawPending());
1546 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1475 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1547 EXPECT_ACTION(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1476 EXPECT_ACTION(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1548 } 1477 }
1549 1478
1550 TEST(SchedulerStateMachineTest, 1479 TEST(SchedulerStateMachineTest,
1551 TestPendingActivationsShouldBeForcedAfterLostOutputSurface) { 1480 TestPendingActivationsShouldBeForcedAfterLostOutputSurface) {
1552 SchedulerSettings settings; 1481 SchedulerSettings settings;
1553 settings.impl_side_painting = true; 1482 settings.impl_side_painting = true;
1554 StateMachine state(settings); 1483 StateMachine state(settings);
1555 state.SetCanStart(); 1484 SET_UP_STATE(state)
1556 state.UpdateState(state.NextAction());
1557 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1558 state.SetVisible(true);
1559 state.SetCanDraw(true);
1560 1485
1561 state.SetCommitState( 1486 state.SetCommitState(
1562 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT); 1487 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT);
1563 1488
1564 // Cause a lost context. 1489 // Cause a lost context.
1565 state.DidLoseOutputSurface(); 1490 state.DidLoseOutputSurface();
1566 1491
1567 state.NotifyBeginMainFrameStarted(); 1492 state.NotifyBeginMainFrameStarted();
1568 state.NotifyReadyToCommit(); 1493 state.NotifyReadyToCommit();
1569 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1494 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1602 EXPECT_ACTION(SchedulerStateMachine::ACTION_COMMIT); 1527 EXPECT_ACTION(SchedulerStateMachine::ACTION_COMMIT);
1603 state.UpdateState(state.NextAction()); 1528 state.UpdateState(state.NextAction());
1604 1529
1605 EXPECT_TRUE(state.active_tree_needs_first_draw()); 1530 EXPECT_TRUE(state.active_tree_needs_first_draw());
1606 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1531 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1607 } 1532 }
1608 1533
1609 TEST(SchedulerStateMachineTest, TestInitialActionsWhenContextLost) { 1534 TEST(SchedulerStateMachineTest, TestInitialActionsWhenContextLost) {
1610 SchedulerSettings default_scheduler_settings; 1535 SchedulerSettings default_scheduler_settings;
1611 StateMachine state(default_scheduler_settings); 1536 StateMachine state(default_scheduler_settings);
1612 state.SetCanStart(); 1537 SET_UP_STATE(state)
1613 state.UpdateState(state.NextAction());
1614 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1615 state.SetVisible(true);
1616 state.SetCanDraw(true);
1617 state.SetNeedsCommit(); 1538 state.SetNeedsCommit();
1618 state.DidLoseOutputSurface(); 1539 state.DidLoseOutputSurface();
1619 1540
1620 // When we are visible, we normally want to begin output surface creation 1541 // When we are visible, we normally want to begin output surface creation
1621 // as soon as possible. 1542 // as soon as possible.
1622 EXPECT_ACTION_UPDATE_STATE( 1543 EXPECT_ACTION_UPDATE_STATE(
1623 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 1544 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1624 1545
1625 state.DidCreateAndInitializeOutputSurface(); 1546 state.DidCreateAndInitializeOutputSurface();
1626 EXPECT_EQ(state.output_surface_state(), 1547 EXPECT_EQ(state.output_surface_state(),
1627 SchedulerStateMachine::OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT); 1548 SchedulerStateMachine::OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT);
1628 1549
1629 // We should not send a BeginMainFrame when we are invisible, even if we've 1550 // We should not send a BeginMainFrame when we are invisible, even if we've
1630 // lost the output surface and are trying to get the first commit, since the 1551 // lost the output surface and are trying to get the first commit, since the
1631 // main thread will just abort anyway. 1552 // main thread will just abort anyway.
1632 state.SetVisible(false); 1553 state.SetVisible(false);
1633 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); 1554 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1634 } 1555 }
1635 1556
1636 TEST(SchedulerStateMachineTest, ReportIfNotDrawing) { 1557 TEST(SchedulerStateMachineTest, ReportIfNotDrawing) {
1637 SchedulerSettings default_scheduler_settings; 1558 SchedulerSettings default_scheduler_settings;
1638 StateMachine state(default_scheduler_settings); 1559 StateMachine state(default_scheduler_settings);
1639 state.SetCanStart(); 1560 SET_UP_STATE(state)
1640 state.UpdateState(state.NextAction());
1641 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1642
1643 state.SetCanDraw(true);
1644 state.SetVisible(true);
1645 EXPECT_FALSE(state.PendingDrawsShouldBeAborted()); 1561 EXPECT_FALSE(state.PendingDrawsShouldBeAborted());
1646 1562
1647 state.SetCanDraw(false); 1563 state.SetCanDraw(false);
1648 state.SetVisible(true); 1564 state.SetVisible(true);
1649 EXPECT_TRUE(state.PendingDrawsShouldBeAborted()); 1565 EXPECT_TRUE(state.PendingDrawsShouldBeAborted());
1650 1566
1651 state.SetCanDraw(true); 1567 state.SetCanDraw(true);
1652 state.SetVisible(false); 1568 state.SetVisible(false);
1653 EXPECT_TRUE(state.PendingDrawsShouldBeAborted()); 1569 EXPECT_TRUE(state.PendingDrawsShouldBeAborted());
1654 1570
1655 state.SetCanDraw(false); 1571 state.SetCanDraw(false);
1656 state.SetVisible(false); 1572 state.SetVisible(false);
1657 EXPECT_TRUE(state.PendingDrawsShouldBeAborted()); 1573 EXPECT_TRUE(state.PendingDrawsShouldBeAborted());
1658 1574
1659 state.SetCanDraw(true); 1575 state.SetCanDraw(true);
1660 state.SetVisible(true); 1576 state.SetVisible(true);
1661 EXPECT_FALSE(state.PendingDrawsShouldBeAborted()); 1577 EXPECT_FALSE(state.PendingDrawsShouldBeAborted());
1662 } 1578 }
1663 1579
1664 TEST(SchedulerStateMachineTest, 1580 TEST(SchedulerStateMachineTest,
1665 TestTriggerDeadlineImmediatelyAfterAbortedCommit) { 1581 TestTriggerDeadlineImmediatelyAfterAbortedCommit) {
1666 SchedulerSettings settings; 1582 SchedulerSettings settings;
1667 settings.impl_side_painting = true; 1583 settings.impl_side_painting = true;
1668 StateMachine state(settings); 1584 StateMachine state(settings);
1669 state.SetCanStart(); 1585 SET_UP_STATE(state)
1670 state.UpdateState(state.NextAction());
1671 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1672 state.SetVisible(true);
1673 state.SetCanDraw(true);
1674 1586
1675 // This test mirrors what happens during the first frame of a scroll gesture. 1587 // This test mirrors what happens during the first frame of a scroll gesture.
1676 // First we get the input event and a BeginFrame. 1588 // First we get the input event and a BeginFrame.
1677 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1589 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1678 1590
1679 // As a response the compositor requests a redraw and a commit to tell the 1591 // As a response the compositor requests a redraw and a commit to tell the
1680 // main thread about the new scroll offset. 1592 // main thread about the new scroll offset.
1681 state.SetNeedsRedraw(true); 1593 state.SetNeedsRedraw(true);
1682 state.SetNeedsCommit(); 1594 state.SetNeedsCommit();
1683 1595
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1717 state.OnBeginImplFrameDeadline(); 1629 state.OnBeginImplFrameDeadline();
1718 EXPECT_ACTION_UPDATE_STATE( 1630 EXPECT_ACTION_UPDATE_STATE(
1719 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1631 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1720 state.DidSwapBuffers(); 1632 state.DidSwapBuffers();
1721 } 1633 }
1722 1634
1723 TEST(SchedulerStateMachineTest, TestImplLatencyTakesPriority) { 1635 TEST(SchedulerStateMachineTest, TestImplLatencyTakesPriority) {
1724 SchedulerSettings settings; 1636 SchedulerSettings settings;
1725 settings.impl_side_painting = true; 1637 settings.impl_side_painting = true;
1726 StateMachine state(settings); 1638 StateMachine state(settings);
1727 state.SetCanStart(); 1639 SET_UP_STATE(state)
1728 state.UpdateState(state.NextAction());
1729 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1730 state.SetVisible(true);
1731 state.SetCanDraw(true);
1732 1640
1733 // This test ensures that impl-draws are prioritized over main thread updates 1641 // This test ensures that impl-draws are prioritized over main thread updates
1734 // in prefer impl latency mode. 1642 // in prefer impl latency mode.
1735 state.SetNeedsRedraw(true); 1643 state.SetNeedsRedraw(true);
1736 state.SetNeedsCommit(); 1644 state.SetNeedsCommit();
1737 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1645 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1738 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1646 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1739 EXPECT_ACTION_UPDATE_STATE( 1647 EXPECT_ACTION_UPDATE_STATE(
1740 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1648 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1741 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1649 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1775 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1683 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1776 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 1684 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
1777 state.OnBeginImplFrameDeadline(); 1685 state.OnBeginImplFrameDeadline();
1778 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1686 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1779 } 1687 }
1780 1688
1781 TEST(SchedulerStateMachineTest, 1689 TEST(SchedulerStateMachineTest,
1782 TestTriggerDeadlineImmediatelyOnLostOutputSurface) { 1690 TestTriggerDeadlineImmediatelyOnLostOutputSurface) {
1783 SchedulerSettings default_scheduler_settings; 1691 SchedulerSettings default_scheduler_settings;
1784 StateMachine state(default_scheduler_settings); 1692 StateMachine state(default_scheduler_settings);
1785 state.SetCanStart(); 1693 SET_UP_STATE(state)
1786 state.UpdateState(state.NextAction());
1787 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1788 state.SetVisible(true);
1789 state.SetCanDraw(true);
1790 1694
1791 state.SetNeedsCommit(); 1695 state.SetNeedsCommit();
1792 1696
1793 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1697 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1794 EXPECT_ACTION_UPDATE_STATE( 1698 EXPECT_ACTION_UPDATE_STATE(
1795 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1699 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1796 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1700 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1797 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 1701 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
1798 1702
1799 state.DidLoseOutputSurface(); 1703 state.DidLoseOutputSurface();
1800 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1704 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1801 // The deadline should be triggered immediately when output surface is lost. 1705 // The deadline should be triggered immediately when output surface is lost.
1802 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 1706 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
1803 } 1707 }
1804 1708
1805 TEST(SchedulerStateMachineTest, TestSetNeedsAnimate) { 1709 TEST(SchedulerStateMachineTest, TestSetNeedsAnimate) {
1806 SchedulerSettings settings; 1710 SchedulerSettings settings;
1807 settings.impl_side_painting = true; 1711 settings.impl_side_painting = true;
1808 StateMachine state(settings); 1712 StateMachine state(settings);
1809 state.SetCanStart(); 1713 SET_UP_STATE(state)
1810 state.UpdateState(state.NextAction());
1811 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1812 state.SetVisible(true);
1813 state.SetCanDraw(true);
1814 1714
1815 // Test requesting an animation that, when run, causes us to draw. 1715 // Test requesting an animation that, when run, causes us to draw.
1816 state.SetNeedsAnimate(); 1716 state.SetNeedsAnimate();
1817 EXPECT_TRUE(state.BeginFrameNeeded()); 1717 EXPECT_TRUE(state.BeginFrameNeeded());
1818 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1718 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1819 1719
1820 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1720 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1821 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1721 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1822 1722
1823 state.OnBeginImplFrameDeadlinePending(); 1723 state.OnBeginImplFrameDeadlinePending();
1824 state.OnBeginImplFrameDeadline(); 1724 state.OnBeginImplFrameDeadline();
1825 EXPECT_ACTION_UPDATE_STATE( 1725 EXPECT_ACTION_UPDATE_STATE(
1826 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1726 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1827 } 1727 }
1828 1728
1829 TEST(SchedulerStateMachineTest, TestAnimateBeforeCommit) { 1729 TEST(SchedulerStateMachineTest, TestAnimateBeforeCommit) {
1830 SchedulerSettings settings; 1730 SchedulerSettings settings;
1831 settings.impl_side_painting = true; 1731 settings.impl_side_painting = true;
1832 StateMachine state(settings); 1732 StateMachine state(settings);
1833 state.SetCanStart(); 1733 SET_UP_STATE(state)
1834 state.UpdateState(state.NextAction());
1835 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1836 state.SetVisible(true);
1837 state.SetCanDraw(true);
1838 1734
1839 // Check that animations are updated before we start a commit. 1735 // Check that animations are updated before we start a commit.
1840 state.SetNeedsAnimate(); 1736 state.SetNeedsAnimate();
1841 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1737 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1842 state.SetNeedsCommit(); 1738 state.SetNeedsCommit();
1843 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1739 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1844 EXPECT_TRUE(state.BeginFrameNeeded()); 1740 EXPECT_TRUE(state.BeginFrameNeeded());
1845 1741
1846 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1742 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1847 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1743 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1848 EXPECT_ACTION_UPDATE_STATE( 1744 EXPECT_ACTION_UPDATE_STATE(
1849 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1745 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1850 1746
1851 state.OnBeginImplFrameDeadlinePending(); 1747 state.OnBeginImplFrameDeadlinePending();
1852 state.OnBeginImplFrameDeadline(); 1748 state.OnBeginImplFrameDeadline();
1853 EXPECT_ACTION_UPDATE_STATE( 1749 EXPECT_ACTION_UPDATE_STATE(
1854 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1750 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1855 } 1751 }
1856 1752
1857 TEST(SchedulerStateMachineTest, TestAnimateAfterCommitBeforeDraw) { 1753 TEST(SchedulerStateMachineTest, TestAnimateAfterCommitBeforeDraw) {
1858 SchedulerSettings settings; 1754 SchedulerSettings settings;
1859 settings.impl_side_painting = true; 1755 settings.impl_side_painting = true;
1860 StateMachine state(settings); 1756 StateMachine state(settings);
1861 state.SetCanStart(); 1757 SET_UP_STATE(state)
1862 state.UpdateState(state.NextAction());
1863 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1864 state.SetVisible(true);
1865 state.SetCanDraw(true);
1866 1758
1867 // Check that animations are updated before we start a commit. 1759 // Check that animations are updated before we start a commit.
1868 state.SetNeedsAnimate(); 1760 state.SetNeedsAnimate();
1869 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1761 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1870 state.SetNeedsCommit(); 1762 state.SetNeedsCommit();
1871 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1763 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1872 EXPECT_TRUE(state.BeginFrameNeeded()); 1764 EXPECT_TRUE(state.BeginFrameNeeded());
1873 1765
1874 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1766 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1875 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1767 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1876 EXPECT_ACTION_UPDATE_STATE( 1768 EXPECT_ACTION_UPDATE_STATE(
1877 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1769 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1878 1770
1879 state.NotifyBeginMainFrameStarted(); 1771 state.NotifyBeginMainFrameStarted();
1880 state.NotifyReadyToCommit(); 1772 state.NotifyReadyToCommit();
1881 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1773 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1882 1774
1883 state.OnBeginImplFrameDeadlinePending(); 1775 state.OnBeginImplFrameDeadlinePending();
1884 state.OnBeginImplFrameDeadline(); 1776 state.OnBeginImplFrameDeadline();
1885 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1777 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1886 EXPECT_ACTION_UPDATE_STATE( 1778 EXPECT_ACTION_UPDATE_STATE(
1887 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1779 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1888 } 1780 }
1889 1781
1890 TEST(SchedulerStateMachineTest, TestSetNeedsAnimateAfterAnimate) { 1782 TEST(SchedulerStateMachineTest, TestSetNeedsAnimateAfterAnimate) {
1891 SchedulerSettings settings; 1783 SchedulerSettings settings;
1892 settings.impl_side_painting = true; 1784 settings.impl_side_painting = true;
1893 StateMachine state(settings); 1785 StateMachine state(settings);
1894 state.SetCanStart(); 1786 SET_UP_STATE(state)
1895 state.UpdateState(state.NextAction());
1896 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1897 state.SetVisible(true);
1898 state.SetCanDraw(true);
1899 1787
1900 // Test requesting an animation after we have already animated during this 1788 // Test requesting an animation after we have already animated during this
1901 // frame. 1789 // frame.
1902 state.SetNeedsRedraw(true); 1790 state.SetNeedsRedraw(true);
1903 EXPECT_TRUE(state.BeginFrameNeeded()); 1791 EXPECT_TRUE(state.BeginFrameNeeded());
1904 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1792 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1905 1793
1906 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1794 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1907 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1795 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1908 1796
1909 state.SetNeedsAnimate(); 1797 state.SetNeedsAnimate();
1910 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1798 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1911 1799
1912 state.OnBeginImplFrameDeadline(); 1800 state.OnBeginImplFrameDeadline();
1913 EXPECT_ACTION_UPDATE_STATE( 1801 EXPECT_ACTION_UPDATE_STATE(
1914 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1802 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1915 } 1803 }
1916 1804
1917 TEST(SchedulerStateMachineTest, TestForwardBeginFramesToChildren) { 1805 TEST(SchedulerStateMachineTest, TestForwardBeginFramesToChildren) {
1918 SchedulerSettings settings; 1806 SchedulerSettings settings;
1919 settings.forward_begin_frames_to_children = true; 1807 settings.forward_begin_frames_to_children = true;
1920 StateMachine state(settings); 1808 StateMachine state(settings);
1921 state.SetCanStart(); 1809 SET_UP_STATE(state)
1922 state.UpdateState(state.NextAction());
1923 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1924 state.SetVisible(true);
1925 state.SetCanDraw(true);
1926 1810
1927 EXPECT_FALSE(state.BeginFrameNeeded()); 1811 EXPECT_FALSE(state.BeginFrameNeeded());
1928 state.SetChildrenNeedBeginFrames(true); 1812 state.SetChildrenNeedBeginFrames(true);
1929 EXPECT_TRUE(state.BeginFrameNeeded()); 1813 EXPECT_TRUE(state.BeginFrameNeeded());
1930 } 1814 }
1931 1815
1932 } // namespace 1816 } // namespace
1933 } // namespace cc 1817 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler_state_machine.cc ('k') | cc/scheduler/scheduler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698