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

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

Issue 2409923002: cc: Rename SwapBuffers on CompositorFrameSink to SubmitCompositorFrame (Closed)
Patch Set: swap-to-submit: . Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/scheduler/scheduler_state_machine.h" 5 #include "cc/scheduler/scheduler_state_machine.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/trace_event/trace_event.h" 9 #include "base/trace_event/trace_event.h"
10 #include "cc/scheduler/scheduler.h" 10 #include "cc/scheduler/scheduler.h"
11 #include "cc/test/begin_frame_args_test.h" 11 #include "cc/test/begin_frame_args_test.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 // Macro to compare two enum values and get nice output. 14 // Macro to compare two enum values and get nice output.
15 // Without: 15 // Without:
16 // Value of: actual() Actual: 7 16 // Value of: actual() Actual: 7
17 // Expected: expected() Which is: 0 17 // Expected: expected() Which is: 0
18 // With: 18 // With:
19 // Value of: actual() Actual: "ACTION_DRAW_AND_SWAP" 19 // Value of: actual() Actual: "ACTION_DRAW"
20 // Expected: expected() Which is: "ACTION_NONE" 20 // Expected: expected() Which is: "ACTION_NONE"
21 #define EXPECT_ENUM_EQ(enum_tostring, expected, actual) \ 21 #define EXPECT_ENUM_EQ(enum_tostring, expected, actual) \
22 EXPECT_STREQ(SchedulerStateMachine::enum_tostring(expected), \ 22 EXPECT_STREQ(SchedulerStateMachine::enum_tostring(expected), \
23 SchedulerStateMachine::enum_tostring(actual)) 23 SchedulerStateMachine::enum_tostring(actual))
24 24
25 #define EXPECT_IMPL_FRAME_STATE(expected) \ 25 #define EXPECT_IMPL_FRAME_STATE(expected) \
26 EXPECT_ENUM_EQ(BeginImplFrameStateToString, expected, \ 26 EXPECT_ENUM_EQ(BeginImplFrameStateToString, expected, \
27 state.begin_impl_frame_state()) \ 27 state.begin_impl_frame_state()) \
28 << state.AsValue()->ToString() 28 << state.AsValue()->ToString()
29 29
30 #define EXPECT_MAIN_FRAME_STATE(expected) \ 30 #define EXPECT_MAIN_FRAME_STATE(expected) \
31 EXPECT_ENUM_EQ(BeginMainFrameStateToString, expected, \ 31 EXPECT_ENUM_EQ(BeginMainFrameStateToString, expected, \
32 state.BeginMainFrameState()) 32 state.BeginMainFrameState())
33 33
34 #define EXPECT_ACTION(expected) \ 34 #define EXPECT_ACTION(expected) \
35 EXPECT_ENUM_EQ(ActionToString, expected, state.NextAction()) \ 35 EXPECT_ENUM_EQ(ActionToString, expected, state.NextAction()) \
36 << state.AsValue()->ToString() 36 << state.AsValue()->ToString()
37 37
38 #define EXPECT_ACTION_UPDATE_STATE(action) \ 38 #define EXPECT_ACTION_UPDATE_STATE(action) \
39 EXPECT_ACTION(action); \ 39 EXPECT_ACTION(action); \
40 if (action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE || \ 40 if (action == SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE || \
41 action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED) { \ 41 action == SchedulerStateMachine::ACTION_DRAW_FORCED) { \
42 EXPECT_IMPL_FRAME_STATE( \ 42 EXPECT_IMPL_FRAME_STATE( \
43 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); \ 43 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); \
44 } \ 44 } \
45 PerformAction(&state, action); \ 45 PerformAction(&state, action); \
46 if (action == SchedulerStateMachine::ACTION_NONE) { \ 46 if (action == SchedulerStateMachine::ACTION_NONE) { \
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) \ 52 #define SET_UP_STATE(state) \
53 state.SetVisible(true); \ 53 state.SetVisible(true); \
54 EXPECT_ACTION_UPDATE_STATE( \ 54 EXPECT_ACTION_UPDATE_STATE( \
55 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); \ 55 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); \
56 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); \ 56 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); \
57 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); \ 57 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); \
58 state.SetCanDraw(true); 58 state.SetCanDraw(true);
59 59
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 case SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME: 170 case SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME:
171 sm->WillSendBeginMainFrame(); 171 sm->WillSendBeginMainFrame();
172 return; 172 return;
173 173
174 case SchedulerStateMachine::ACTION_COMMIT: { 174 case SchedulerStateMachine::ACTION_COMMIT: {
175 bool commit_has_no_updates = false; 175 bool commit_has_no_updates = false;
176 sm->WillCommit(commit_has_no_updates); 176 sm->WillCommit(commit_has_no_updates);
177 return; 177 return;
178 } 178 }
179 179
180 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED: 180 case SchedulerStateMachine::ACTION_DRAW_FORCED:
181 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE: { 181 case SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE: {
182 sm->WillDraw(); 182 sm->WillDraw();
183 sm->DidDraw(sm->draw_result_for_test()); 183 sm->DidDraw(sm->draw_result_for_test());
184 return; 184 return;
185 } 185 }
186 186
187 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT: { 187 case SchedulerStateMachine::ACTION_DRAW_ABORT: {
188 sm->AbortDrawAndSwap(); 188 sm->AbortDraw();
189 return; 189 return;
190 } 190 }
191 191
192 case SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION: 192 case SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION:
193 sm->WillBeginCompositorFrameSinkCreation(); 193 sm->WillBeginCompositorFrameSinkCreation();
194 return; 194 return;
195 195
196 case SchedulerStateMachine::ACTION_PREPARE_TILES: 196 case SchedulerStateMachine::ACTION_PREPARE_TILES:
197 sm->WillPrepareTiles(); 197 sm->WillPrepareTiles();
198 return; 198 return;
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 396
397 // Verify NotifyReadyToActivate unblocks activation, commit, and 397 // Verify NotifyReadyToActivate unblocks activation, commit, and
398 // draw in that order. 398 // draw in that order.
399 state.NotifyReadyToActivate(); 399 state.NotifyReadyToActivate();
400 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 400 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
401 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 401 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
402 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 402 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
403 403
404 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 404 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
405 state.OnBeginImplFrameDeadline(); 405 state.OnBeginImplFrameDeadline();
406 EXPECT_ACTION_UPDATE_STATE( 406 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
407 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 407 state.DidSubmitCompositorFrame();
408 state.DidSwapBuffers(); 408 state.DidReceiveCompositorFrameAck();
409 state.DidSwapBuffersComplete();
410 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 409 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
411 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 410 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
412 } 411 }
413 412
414 TEST(SchedulerStateMachineTest, 413 TEST(SchedulerStateMachineTest,
415 FailedDrawForAnimationCheckerboardSetsNeedsCommitAndRetriesDraw) { 414 FailedDrawForAnimationCheckerboardSetsNeedsCommitAndRetriesDraw) {
416 SchedulerSettings default_scheduler_settings; 415 SchedulerSettings default_scheduler_settings;
417 StateMachine state(default_scheduler_settings); 416 StateMachine state(default_scheduler_settings);
418 SET_UP_STATE(state) 417 SET_UP_STATE(state)
419 state.SetNeedsRedraw(true); 418 state.SetNeedsRedraw(true);
420 EXPECT_TRUE(state.RedrawPending()); 419 EXPECT_TRUE(state.RedrawPending());
421 EXPECT_TRUE(state.BeginFrameNeeded()); 420 EXPECT_TRUE(state.BeginFrameNeeded());
422 421
423 // Start a frame. 422 // Start a frame.
424 state.OnBeginImplFrame(); 423 state.OnBeginImplFrame();
425 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 424 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
426 EXPECT_FALSE(state.CommitPending()); 425 EXPECT_FALSE(state.CommitPending());
427 426
428 // Failing a draw triggers request for a new BeginMainFrame. 427 // Failing a draw triggers request for a new BeginMainFrame.
429 state.OnBeginImplFrameDeadline(); 428 state.OnBeginImplFrameDeadline();
430 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 429 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
431 EXPECT_ACTION_UPDATE_STATE( 430 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
432 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
433 EXPECT_ACTION_UPDATE_STATE( 431 EXPECT_ACTION_UPDATE_STATE(
434 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 432 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
435 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 433 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
436 state.OnBeginImplFrameIdle(); 434 state.OnBeginImplFrameIdle();
437 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 435 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
438 436
439 // It's okay to attempt more draws just in case additional raster 437 // It's okay to attempt more draws just in case additional raster
440 // finishes and the requested commit wasn't actually necessary. 438 // finishes and the requested commit wasn't actually necessary.
441 EXPECT_TRUE(state.CommitPending()); 439 EXPECT_TRUE(state.CommitPending());
442 EXPECT_TRUE(state.RedrawPending()); 440 EXPECT_TRUE(state.RedrawPending());
443 state.OnBeginImplFrame(); 441 state.OnBeginImplFrame();
444 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 442 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
445 state.OnBeginImplFrameDeadline(); 443 state.OnBeginImplFrameDeadline();
446 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 444 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
447 EXPECT_ACTION_UPDATE_STATE( 445 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
448 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
449 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 446 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
450 state.OnBeginImplFrameIdle(); 447 state.OnBeginImplFrameIdle();
451 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 448 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
452 } 449 }
453 450
454 TEST(SchedulerStateMachineTest, FailedDrawForMissingHighResNeedsCommit) { 451 TEST(SchedulerStateMachineTest, FailedDrawForMissingHighResNeedsCommit) {
455 SchedulerSettings default_scheduler_settings; 452 SchedulerSettings default_scheduler_settings;
456 StateMachine state(default_scheduler_settings); 453 StateMachine state(default_scheduler_settings);
457 SET_UP_STATE(state) 454 SET_UP_STATE(state)
458 state.SetNeedsRedraw(true); 455 state.SetNeedsRedraw(true);
459 EXPECT_TRUE(state.RedrawPending()); 456 EXPECT_TRUE(state.RedrawPending());
460 EXPECT_TRUE(state.BeginFrameNeeded()); 457 EXPECT_TRUE(state.BeginFrameNeeded());
461 458
462 // Start a frame. 459 // Start a frame.
463 state.OnBeginImplFrame(); 460 state.OnBeginImplFrame();
464 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 461 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
465 EXPECT_FALSE(state.CommitPending()); 462 EXPECT_FALSE(state.CommitPending());
466 463
467 // Failing a draw triggers because of high res tiles missing 464 // Failing a draw triggers because of high res tiles missing
468 // request for a new BeginMainFrame. 465 // request for a new BeginMainFrame.
469 state.OnBeginImplFrameDeadline(); 466 state.OnBeginImplFrameDeadline();
470 state.SetDrawResultForTest(DRAW_ABORTED_MISSING_HIGH_RES_CONTENT); 467 state.SetDrawResultForTest(DRAW_ABORTED_MISSING_HIGH_RES_CONTENT);
471 EXPECT_ACTION_UPDATE_STATE( 468 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
472 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
473 EXPECT_ACTION_UPDATE_STATE( 469 EXPECT_ACTION_UPDATE_STATE(
474 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 470 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
475 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 471 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
476 state.OnBeginImplFrameIdle(); 472 state.OnBeginImplFrameIdle();
477 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 473 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
478 474
479 // It doesn't request a draw until we get a new commit though. 475 // It doesn't request a draw until we get a new commit though.
480 EXPECT_TRUE(state.CommitPending()); 476 EXPECT_TRUE(state.CommitPending());
481 EXPECT_FALSE(state.RedrawPending()); 477 EXPECT_FALSE(state.RedrawPending());
482 state.OnBeginImplFrame(); 478 state.OnBeginImplFrame();
(...skipping 11 matching lines...) Expand all
494 state.NotifyReadyToActivate(); 490 state.NotifyReadyToActivate();
495 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 491 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
496 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 492 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
497 EXPECT_TRUE(state.RedrawPending()); 493 EXPECT_TRUE(state.RedrawPending());
498 494
499 // Verify we draw with the new frame. 495 // Verify we draw with the new frame.
500 state.OnBeginImplFrame(); 496 state.OnBeginImplFrame();
501 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 497 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
502 state.OnBeginImplFrameDeadline(); 498 state.OnBeginImplFrameDeadline();
503 state.SetDrawResultForTest(DRAW_SUCCESS); 499 state.SetDrawResultForTest(DRAW_SUCCESS);
504 EXPECT_ACTION_UPDATE_STATE( 500 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
505 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 501 state.DidSubmitCompositorFrame();
506 state.DidSwapBuffers();
507 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 502 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
508 state.OnBeginImplFrameIdle(); 503 state.OnBeginImplFrameIdle();
509 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 504 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
510 } 505 }
511 506
512 TEST(SchedulerStateMachineTest, 507 TEST(SchedulerStateMachineTest,
513 TestFailedDrawsEventuallyForceDrawAfterNextCommit) { 508 TestFailedDrawsEventuallyForceDrawAfterNextCommit) {
514 SchedulerSettings scheduler_settings; 509 SchedulerSettings scheduler_settings;
515 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced = 1; 510 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced = 1;
516 StateMachine state(scheduler_settings); 511 StateMachine state(scheduler_settings);
517 SET_UP_STATE(state) 512 SET_UP_STATE(state)
518 513
519 // Start a commit. 514 // Start a commit.
520 state.SetNeedsBeginMainFrame(); 515 state.SetNeedsBeginMainFrame();
521 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 516 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
522 state.OnBeginImplFrame(); 517 state.OnBeginImplFrame();
523 EXPECT_ACTION_UPDATE_STATE( 518 EXPECT_ACTION_UPDATE_STATE(
524 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 519 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
525 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 520 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
526 EXPECT_TRUE(state.CommitPending()); 521 EXPECT_TRUE(state.CommitPending());
527 522
528 // Then initiate a draw that fails. 523 // Then initiate a draw that fails.
529 state.SetNeedsRedraw(true); 524 state.SetNeedsRedraw(true);
530 state.OnBeginImplFrameDeadline(); 525 state.OnBeginImplFrameDeadline();
531 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 526 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
532 EXPECT_ACTION_UPDATE_STATE( 527 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
533 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
534 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 528 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
535 EXPECT_TRUE(state.BeginFrameNeeded()); 529 EXPECT_TRUE(state.BeginFrameNeeded());
536 EXPECT_TRUE(state.RedrawPending()); 530 EXPECT_TRUE(state.RedrawPending());
537 EXPECT_TRUE(state.CommitPending()); 531 EXPECT_TRUE(state.CommitPending());
538 532
539 // Finish the commit. Note, we should not yet be forcing a draw, but should 533 // Finish the commit. Note, we should not yet be forcing a draw, but should
540 // continue the commit as usual. 534 // continue the commit as usual.
541 state.NotifyBeginMainFrameStarted(); 535 state.NotifyBeginMainFrameStarted();
542 state.NotifyReadyToCommit(); 536 state.NotifyReadyToCommit();
543 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 537 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
544 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 538 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
545 EXPECT_TRUE(state.RedrawPending()); 539 EXPECT_TRUE(state.RedrawPending());
546 540
547 // Activate so we're ready for a new main frame. 541 // Activate so we're ready for a new main frame.
548 state.NotifyReadyToActivate(); 542 state.NotifyReadyToActivate();
549 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 543 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
550 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 544 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
551 EXPECT_TRUE(state.RedrawPending()); 545 EXPECT_TRUE(state.RedrawPending());
552 546
553 // The redraw should be forced at the end of the next BeginImplFrame. 547 // The redraw should be forced at the end of the next BeginImplFrame.
554 state.OnBeginImplFrame(); 548 state.OnBeginImplFrame();
555 EXPECT_ACTION_UPDATE_STATE( 549 EXPECT_ACTION_UPDATE_STATE(
556 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 550 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
557 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 551 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
558 state.OnBeginImplFrameDeadline(); 552 state.OnBeginImplFrameDeadline();
559 state.SetDrawResultForTest(DRAW_SUCCESS); 553 state.SetDrawResultForTest(DRAW_SUCCESS);
560 EXPECT_ACTION_UPDATE_STATE( 554 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_FORCED);
561 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED); 555 state.DidSubmitCompositorFrame();
562 state.DidSwapBuffers();
563 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 556 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
564 state.DidSwapBuffersComplete(); 557 state.DidReceiveCompositorFrameAck();
565 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 558 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
566 } 559 }
567 560
568 TEST(SchedulerStateMachineTest, TestFailedDrawsDoNotRestartForcedDraw) { 561 TEST(SchedulerStateMachineTest, TestFailedDrawsDoNotRestartForcedDraw) {
569 SchedulerSettings scheduler_settings; 562 SchedulerSettings scheduler_settings;
570 int draw_limit = 2; 563 int draw_limit = 2;
571 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced = 564 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced =
572 draw_limit; 565 draw_limit;
573 StateMachine state(scheduler_settings); 566 StateMachine state(scheduler_settings);
574 SET_UP_STATE(state) 567 SET_UP_STATE(state)
575 568
576 // Start a commit. 569 // Start a commit.
577 state.SetNeedsBeginMainFrame(); 570 state.SetNeedsBeginMainFrame();
578 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 571 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
579 state.OnBeginImplFrame(); 572 state.OnBeginImplFrame();
580 EXPECT_ACTION_UPDATE_STATE( 573 EXPECT_ACTION_UPDATE_STATE(
581 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 574 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
582 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 575 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
583 EXPECT_TRUE(state.CommitPending()); 576 EXPECT_TRUE(state.CommitPending());
584 577
585 // Then initiate a draw. 578 // Then initiate a draw.
586 state.SetNeedsRedraw(true); 579 state.SetNeedsRedraw(true);
587 state.OnBeginImplFrameDeadline(); 580 state.OnBeginImplFrameDeadline();
588 EXPECT_ACTION_UPDATE_STATE( 581 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
589 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
590 582
591 // Fail the draw enough times to force a redraw. 583 // Fail the draw enough times to force a redraw.
592 for (int i = 0; i < draw_limit; ++i) { 584 for (int i = 0; i < draw_limit; ++i) {
593 state.SetNeedsRedraw(true); 585 state.SetNeedsRedraw(true);
594 state.OnBeginImplFrame(); 586 state.OnBeginImplFrame();
595 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 587 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
596 state.OnBeginImplFrameDeadline(); 588 state.OnBeginImplFrameDeadline();
597 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 589 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
598 EXPECT_ACTION_UPDATE_STATE( 590 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
599 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
600 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 591 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
601 state.OnBeginImplFrameIdle(); 592 state.OnBeginImplFrameIdle();
602 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 593 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
603 } 594 }
604 595
605 EXPECT_TRUE(state.BeginFrameNeeded()); 596 EXPECT_TRUE(state.BeginFrameNeeded());
606 EXPECT_TRUE(state.RedrawPending()); 597 EXPECT_TRUE(state.RedrawPending());
607 // But the commit is ongoing. 598 // But the commit is ongoing.
608 EXPECT_TRUE(state.CommitPending()); 599 EXPECT_TRUE(state.CommitPending());
609 EXPECT_TRUE(state.ForcedRedrawState() == 600 EXPECT_TRUE(state.ForcedRedrawState() ==
610 SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_COMMIT); 601 SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_COMMIT);
611 602
612 // After failing additional draws, we should still be in a forced 603 // After failing additional draws, we should still be in a forced
613 // redraw, but not back in IDLE. 604 // redraw, but not back in IDLE.
614 for (int i = 0; i < draw_limit; ++i) { 605 for (int i = 0; i < draw_limit; ++i) {
615 state.SetNeedsRedraw(true); 606 state.SetNeedsRedraw(true);
616 state.OnBeginImplFrame(); 607 state.OnBeginImplFrame();
617 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 608 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
618 state.OnBeginImplFrameDeadline(); 609 state.OnBeginImplFrameDeadline();
619 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 610 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
620 EXPECT_ACTION_UPDATE_STATE( 611 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
621 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
622 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 612 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
623 state.OnBeginImplFrameIdle(); 613 state.OnBeginImplFrameIdle();
624 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 614 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
625 } 615 }
626 EXPECT_TRUE(state.RedrawPending()); 616 EXPECT_TRUE(state.RedrawPending());
627 EXPECT_TRUE(state.ForcedRedrawState() == 617 EXPECT_TRUE(state.ForcedRedrawState() ==
628 SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_COMMIT); 618 SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_COMMIT);
629 } 619 }
630 620
631 TEST(SchedulerStateMachineTest, TestFailedDrawIsRetriedInNextBeginImplFrame) { 621 TEST(SchedulerStateMachineTest, TestFailedDrawIsRetriedInNextBeginImplFrame) {
632 SchedulerSettings default_scheduler_settings; 622 SchedulerSettings default_scheduler_settings;
633 StateMachine state(default_scheduler_settings); 623 StateMachine state(default_scheduler_settings);
634 SET_UP_STATE(state) 624 SET_UP_STATE(state)
635 625
636 // Start a draw. 626 // Start a draw.
637 state.SetNeedsRedraw(true); 627 state.SetNeedsRedraw(true);
638 EXPECT_TRUE(state.BeginFrameNeeded()); 628 EXPECT_TRUE(state.BeginFrameNeeded());
639 state.OnBeginImplFrame(); 629 state.OnBeginImplFrame();
640 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 630 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
641 state.OnBeginImplFrameDeadline(); 631 state.OnBeginImplFrameDeadline();
642 EXPECT_TRUE(state.RedrawPending()); 632 EXPECT_TRUE(state.RedrawPending());
643 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 633 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
644 EXPECT_ACTION_UPDATE_STATE( 634 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
645 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
646 635
647 // Failing the draw for animation checkerboards makes us require a commit. 636 // Failing the draw for animation checkerboards makes us require a commit.
648 EXPECT_ACTION_UPDATE_STATE( 637 EXPECT_ACTION_UPDATE_STATE(
649 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 638 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
650 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 639 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
651 EXPECT_TRUE(state.RedrawPending()); 640 EXPECT_TRUE(state.RedrawPending());
652 641
653 // We should not be trying to draw again now, but we have a commit pending. 642 // We should not be trying to draw again now, but we have a commit pending.
654 EXPECT_TRUE(state.BeginFrameNeeded()); 643 EXPECT_TRUE(state.BeginFrameNeeded());
655 state.OnBeginImplFrame(); 644 state.OnBeginImplFrame();
656 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 645 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
657 646
658 // We should try to draw again at the end of the next BeginImplFrame on 647 // We should try to draw again at the end of the next BeginImplFrame on
659 // the impl thread. 648 // the impl thread.
660 state.OnBeginImplFrameDeadline(); 649 state.OnBeginImplFrameDeadline();
661 state.SetDrawResultForTest(DRAW_SUCCESS); 650 state.SetDrawResultForTest(DRAW_SUCCESS);
662 EXPECT_ACTION_UPDATE_STATE( 651 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
663 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 652 state.DidSubmitCompositorFrame();
664 state.DidSwapBuffers(); 653 state.DidReceiveCompositorFrameAck();
665 state.DidSwapBuffersComplete();
666 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 654 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
667 } 655 }
668 656
669 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) { 657 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) {
670 SchedulerSettings default_scheduler_settings; 658 SchedulerSettings default_scheduler_settings;
671 StateMachine state(default_scheduler_settings); 659 StateMachine state(default_scheduler_settings);
672 SET_UP_STATE(state) 660 SET_UP_STATE(state)
673 state.SetNeedsRedraw(true); 661 state.SetNeedsRedraw(true);
674 662
675 // Draw the first frame. 663 // Draw the first frame.
676 EXPECT_TRUE(state.BeginFrameNeeded()); 664 EXPECT_TRUE(state.BeginFrameNeeded());
677 state.OnBeginImplFrame(); 665 state.OnBeginImplFrame();
678 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 666 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
679 667
680 state.OnBeginImplFrameDeadline(); 668 state.OnBeginImplFrameDeadline();
681 EXPECT_ACTION_UPDATE_STATE( 669 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
682 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 670 state.DidSubmitCompositorFrame();
683 state.DidSwapBuffers(); 671 state.DidReceiveCompositorFrameAck();
684 state.DidSwapBuffersComplete();
685 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 672 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
686 673
687 // Before the next BeginImplFrame, set needs redraw again. 674 // Before the next BeginImplFrame, set needs redraw again.
688 // This should not redraw until the next BeginImplFrame. 675 // This should not redraw until the next BeginImplFrame.
689 state.SetNeedsRedraw(true); 676 state.SetNeedsRedraw(true);
690 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 677 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
691 678
692 // Move to another frame. This should now draw. 679 // Move to another frame. This should now draw.
693 EXPECT_TRUE(state.BeginFrameNeeded()); 680 EXPECT_TRUE(state.BeginFrameNeeded());
694 state.OnBeginImplFrame(); 681 state.OnBeginImplFrame();
695 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 682 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
696 state.OnBeginImplFrameDeadline(); 683 state.OnBeginImplFrameDeadline();
697 EXPECT_ACTION_UPDATE_STATE( 684 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
698 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 685 state.DidSubmitCompositorFrame();
699 state.DidSwapBuffers(); 686 state.DidReceiveCompositorFrameAck();
700 state.DidSwapBuffersComplete();
701 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 687 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
702 688
703 // We just swapped, so we should proactively request another BeginImplFrame. 689 // We just submitted, so we should proactively request another BeginImplFrame.
704 EXPECT_TRUE(state.BeginFrameNeeded()); 690 EXPECT_TRUE(state.BeginFrameNeeded());
705 } 691 }
706 692
707 TEST(SchedulerStateMachineTest, TestNextActionDrawsOnBeginImplFrame) { 693 TEST(SchedulerStateMachineTest, TestNextActionDrawsOnBeginImplFrame) {
708 SchedulerSettings default_scheduler_settings; 694 SchedulerSettings default_scheduler_settings;
709 695
710 // When not in BeginImplFrame deadline, or in BeginImplFrame deadline 696 // When not in BeginImplFrame deadline, or in BeginImplFrame deadline
711 // but not visible, don't draw. 697 // but not visible, don't draw.
712 size_t num_begin_main_frame_states = 698 size_t num_begin_main_frame_states =
713 sizeof(begin_main_frame_states) / 699 sizeof(begin_main_frame_states) /
(...skipping 10 matching lines...) Expand all
724 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 710 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
725 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 711 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
726 state.SetBeginMainFrameState(begin_main_frame_states[i]); 712 state.SetBeginMainFrameState(begin_main_frame_states[i]);
727 state.SetBeginImplFrameState(all_begin_impl_frame_states[j]); 713 state.SetBeginImplFrameState(all_begin_impl_frame_states[j]);
728 bool visible = 714 bool visible =
729 (all_begin_impl_frame_states[j] != 715 (all_begin_impl_frame_states[j] !=
730 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); 716 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE);
731 state.SetVisible(visible); 717 state.SetVisible(visible);
732 718
733 // Case 1: needs_begin_main_frame=false 719 // Case 1: needs_begin_main_frame=false
734 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 720 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE,
735 state.NextAction()); 721 state.NextAction());
736 722
737 // Case 2: needs_begin_main_frame=true 723 // Case 2: needs_begin_main_frame=true
738 state.SetNeedsBeginMainFrame(); 724 state.SetNeedsBeginMainFrame();
739 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 725 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE,
740 state.NextAction()) 726 state.NextAction())
741 << state.AsValue()->ToString(); 727 << state.AsValue()->ToString();
742 } 728 }
743 } 729 }
744 730
745 // When in BeginImplFrame deadline we should always draw for SetNeedsRedraw 731 // When in BeginImplFrame deadline we should always draw for SetNeedsRedraw
746 // except if we're ready to commit, in which case we expect a commit first. 732 // except if we're ready to commit, in which case we expect a commit first.
747 for (size_t i = 0; i < num_begin_main_frame_states; ++i) { 733 for (size_t i = 0; i < num_begin_main_frame_states; ++i) {
748 StateMachine state(default_scheduler_settings); 734 StateMachine state(default_scheduler_settings);
749 state.SetVisible(true); 735 state.SetVisible(true);
750 EXPECT_ACTION_UPDATE_STATE( 736 EXPECT_ACTION_UPDATE_STATE(
751 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 737 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
752 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 738 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
753 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 739 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
754 state.SetCanDraw(true); 740 state.SetCanDraw(true);
755 state.SetBeginMainFrameState(begin_main_frame_states[i]); 741 state.SetBeginMainFrameState(begin_main_frame_states[i]);
756 state.SetBeginImplFrameState( 742 state.SetBeginImplFrameState(
757 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); 743 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE);
758 744
759 state.SetNeedsRedraw(true); 745 state.SetNeedsRedraw(true);
760 746
761 SchedulerStateMachine::Action expected_action; 747 SchedulerStateMachine::Action expected_action;
762 if (begin_main_frame_states[i] == 748 if (begin_main_frame_states[i] ==
763 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT) { 749 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT) {
764 expected_action = SchedulerStateMachine::ACTION_COMMIT; 750 expected_action = SchedulerStateMachine::ACTION_COMMIT;
765 } else { 751 } else {
766 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE; 752 expected_action = SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE;
767 } 753 }
768 754
769 // Case 1: needs_begin_main_frame=false. 755 // Case 1: needs_begin_main_frame=false.
770 EXPECT_ACTION(expected_action); 756 EXPECT_ACTION(expected_action);
771 757
772 // Case 2: needs_begin_main_frame=true. 758 // Case 2: needs_begin_main_frame=true.
773 state.SetNeedsBeginMainFrame(); 759 state.SetNeedsBeginMainFrame();
774 EXPECT_ACTION(expected_action); 760 EXPECT_ACTION(expected_action);
775 } 761 }
776 } 762 }
(...skipping 15 matching lines...) Expand all
792 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 778 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
793 state.SetBeginMainFrameState(begin_main_frame_states[i]); 779 state.SetBeginMainFrameState(begin_main_frame_states[i]);
794 state.SetVisible(false); 780 state.SetVisible(false);
795 state.SetNeedsRedraw(true); 781 state.SetNeedsRedraw(true);
796 if (j == 1) { 782 if (j == 1) {
797 state.SetBeginImplFrameState( 783 state.SetBeginImplFrameState(
798 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); 784 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE);
799 } 785 }
800 786
801 // Case 1: needs_begin_main_frame=false. 787 // Case 1: needs_begin_main_frame=false.
802 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 788 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE,
803 state.NextAction()); 789 state.NextAction());
804 790
805 // Case 2: needs_begin_main_frame=true. 791 // Case 2: needs_begin_main_frame=true.
806 state.SetNeedsBeginMainFrame(); 792 state.SetNeedsBeginMainFrame();
807 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 793 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE,
808 state.NextAction()) 794 state.NextAction())
809 << state.AsValue()->ToString(); 795 << state.AsValue()->ToString();
810 } 796 }
811 } 797 }
812 } 798 }
813 799
814 TEST(SchedulerStateMachineTest, TestCanRedraw_StopsDraw) { 800 TEST(SchedulerStateMachineTest, TestCanRedraw_StopsDraw) {
815 SchedulerSettings default_scheduler_settings; 801 SchedulerSettings default_scheduler_settings;
816 802
817 size_t num_begin_main_frame_states = 803 size_t num_begin_main_frame_states =
818 sizeof(begin_main_frame_states) / 804 sizeof(begin_main_frame_states) /
819 sizeof(SchedulerStateMachine::BeginMainFrameState); 805 sizeof(SchedulerStateMachine::BeginMainFrameState);
820 for (size_t i = 0; i < num_begin_main_frame_states; ++i) { 806 for (size_t i = 0; i < num_begin_main_frame_states; ++i) {
821 // There shouldn't be any drawing regardless of BeginImplFrame. 807 // There shouldn't be any drawing regardless of BeginImplFrame.
822 for (size_t j = 0; j < 2; ++j) { 808 for (size_t j = 0; j < 2; ++j) {
823 StateMachine state(default_scheduler_settings); 809 StateMachine state(default_scheduler_settings);
824 state.SetVisible(true); 810 state.SetVisible(true);
825 EXPECT_ACTION_UPDATE_STATE( 811 EXPECT_ACTION_UPDATE_STATE(
826 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 812 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
827 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 813 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
828 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 814 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
829 state.SetBeginMainFrameState(begin_main_frame_states[i]); 815 state.SetBeginMainFrameState(begin_main_frame_states[i]);
830 state.SetVisible(false); 816 state.SetVisible(false);
831 state.SetNeedsRedraw(true); 817 state.SetNeedsRedraw(true);
832 if (j == 1) 818 if (j == 1)
833 state.OnBeginImplFrame(); 819 state.OnBeginImplFrame();
834 820
835 state.SetCanDraw(false); 821 state.SetCanDraw(false);
836 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 822 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE,
837 state.NextAction()); 823 state.NextAction());
838 } 824 }
839 } 825 }
840 } 826 }
841 827
842 TEST(SchedulerStateMachineTest, 828 TEST(SchedulerStateMachineTest,
843 TestCanRedrawWithWaitingForFirstDrawMakesProgress) { 829 TestCanRedrawWithWaitingForFirstDrawMakesProgress) {
844 SchedulerSettings default_scheduler_settings; 830 SchedulerSettings default_scheduler_settings;
845 StateMachine state(default_scheduler_settings); 831 StateMachine state(default_scheduler_settings);
846 state.SetVisible(true); 832 state.SetVisible(true);
847 EXPECT_ACTION_UPDATE_STATE( 833 EXPECT_ACTION_UPDATE_STATE(
848 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 834 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
849 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 835 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
850 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 836 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
851 837
852 state.SetActiveTreeNeedsFirstDraw(true); 838 state.SetActiveTreeNeedsFirstDraw(true);
853 state.SetNeedsBeginMainFrame(); 839 state.SetNeedsBeginMainFrame();
854 state.SetNeedsRedraw(true); 840 state.SetNeedsRedraw(true);
855 state.SetCanDraw(false); 841 state.SetCanDraw(false);
856 state.OnBeginImplFrame(); 842 state.OnBeginImplFrame();
857 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 843 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_ABORT);
858 EXPECT_ACTION_UPDATE_STATE( 844 EXPECT_ACTION_UPDATE_STATE(
859 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 845 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
860 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 846 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
861 state.NotifyBeginMainFrameStarted(); 847 state.NotifyBeginMainFrameStarted();
862 state.NotifyReadyToCommit(); 848 state.NotifyReadyToCommit();
863 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 849 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
864 state.NotifyReadyToActivate(); 850 state.NotifyReadyToActivate();
865 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 851 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
866 state.OnBeginImplFrameDeadline(); 852 state.OnBeginImplFrameDeadline();
867 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 853 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_ABORT);
868 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 854 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
869 } 855 }
870 856
871 TEST(SchedulerStateMachineTest, TestSetNeedsBeginMainFrameIsNotLost) { 857 TEST(SchedulerStateMachineTest, TestSetNeedsBeginMainFrameIsNotLost) {
872 SchedulerSettings scheduler_settings; 858 SchedulerSettings scheduler_settings;
873 StateMachine state(scheduler_settings); 859 StateMachine state(scheduler_settings);
874 SET_UP_STATE(state) 860 SET_UP_STATE(state)
875 state.SetNeedsBeginMainFrame(); 861 state.SetNeedsBeginMainFrame();
876 862
877 EXPECT_TRUE(state.BeginFrameNeeded()); 863 EXPECT_TRUE(state.BeginFrameNeeded());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 902 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
917 state.NotifyReadyToActivate(); 903 state.NotifyReadyToActivate();
918 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 904 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
919 EXPECT_ACTION_UPDATE_STATE( 905 EXPECT_ACTION_UPDATE_STATE(
920 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 906 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
921 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 907 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
922 908
923 state.OnBeginImplFrameDeadline(); 909 state.OnBeginImplFrameDeadline();
924 910
925 EXPECT_TRUE(state.active_tree_needs_first_draw()); 911 EXPECT_TRUE(state.active_tree_needs_first_draw());
926 EXPECT_ACTION_UPDATE_STATE( 912 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
927 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 913 state.DidSubmitCompositorFrame();
928 state.DidSwapBuffers(); 914 state.DidReceiveCompositorFrameAck();
929 state.DidSwapBuffersComplete();
930 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 915 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
931 } 916 }
932 917
933 TEST(SchedulerStateMachineTest, TestFullCycle) { 918 TEST(SchedulerStateMachineTest, TestFullCycle) {
934 SchedulerSettings default_scheduler_settings; 919 SchedulerSettings default_scheduler_settings;
935 StateMachine state(default_scheduler_settings); 920 StateMachine state(default_scheduler_settings);
936 SET_UP_STATE(state) 921 SET_UP_STATE(state)
937 922
938 // Start clean and set commit. 923 // Start clean and set commit.
939 state.SetNeedsBeginMainFrame(); 924 state.SetNeedsBeginMainFrame();
(...skipping 19 matching lines...) Expand all
959 state.NotifyReadyToActivate(); 944 state.NotifyReadyToActivate();
960 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 945 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
961 EXPECT_TRUE(state.active_tree_needs_first_draw()); 946 EXPECT_TRUE(state.active_tree_needs_first_draw());
962 EXPECT_TRUE(state.needs_redraw()); 947 EXPECT_TRUE(state.needs_redraw());
963 948
964 // Expect to do nothing until BeginImplFrame deadline 949 // Expect to do nothing until BeginImplFrame deadline
965 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 950 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
966 951
967 // At BeginImplFrame deadline, draw. 952 // At BeginImplFrame deadline, draw.
968 state.OnBeginImplFrameDeadline(); 953 state.OnBeginImplFrameDeadline();
969 EXPECT_ACTION_UPDATE_STATE( 954 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
970 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 955 state.DidSubmitCompositorFrame();
971 state.DidSwapBuffers(); 956 state.DidReceiveCompositorFrameAck();
972 state.DidSwapBuffersComplete();
973 957
974 // Should be synchronized, no draw needed, no action needed. 958 // Should be synchronized, no draw needed, no action needed.
975 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 959 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
976 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 960 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
977 EXPECT_FALSE(state.needs_redraw()); 961 EXPECT_FALSE(state.needs_redraw());
978 } 962 }
979 963
980 TEST(SchedulerStateMachineTest, CommitWithoutDrawWithPendingTree) { 964 TEST(SchedulerStateMachineTest, CommitWithoutDrawWithPendingTree) {
981 SchedulerSettings default_scheduler_settings; 965 SchedulerSettings default_scheduler_settings;
982 StateMachine state(default_scheduler_settings); 966 StateMachine state(default_scheduler_settings);
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 1111
1128 // Can't BeginMainFrame yet since last commit hasn't been drawn yet. 1112 // Can't BeginMainFrame yet since last commit hasn't been drawn yet.
1129 state.SetNeedsBeginMainFrame(); 1113 state.SetNeedsBeginMainFrame();
1130 state.OnBeginImplFrame(); 1114 state.OnBeginImplFrame();
1131 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1115 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1132 1116
1133 // Now call ready to draw which will allow the draw to happen and 1117 // Now call ready to draw which will allow the draw to happen and
1134 // BeginMainFrame to be sent. 1118 // BeginMainFrame to be sent.
1135 state.NotifyReadyToDraw(); 1119 state.NotifyReadyToDraw();
1136 state.OnBeginImplFrameDeadline(); 1120 state.OnBeginImplFrameDeadline();
1137 EXPECT_ACTION_UPDATE_STATE( 1121 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1138 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1122 // Submit throttled from this point.
1139 // Swap throttled from this point. 1123 state.DidSubmitCompositorFrame();
1140 state.DidSwapBuffers();
1141 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1124 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1142 1125
1143 // Can't BeginMainFrame yet since we're swap throttled. 1126 // Can't BeginMainFrame yet since we're submit-frame throttled.
1144 state.OnBeginImplFrame(); 1127 state.OnBeginImplFrame();
1145 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1128 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1146 1129
1147 // Swap ack unblocks BeginMainFrame. 1130 // CompositorFrameAck unblocks BeginMainFrame.
1148 state.DidSwapBuffersComplete(); 1131 state.DidReceiveCompositorFrameAck();
1149 EXPECT_ACTION_UPDATE_STATE( 1132 EXPECT_ACTION_UPDATE_STATE(
1150 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1133 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1151 state.NotifyBeginMainFrameStarted(); 1134 state.NotifyBeginMainFrameStarted();
1152 state.NotifyReadyToCommit(); 1135 state.NotifyReadyToCommit();
1153 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1136 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1154 state.NotifyReadyToActivate(); 1137 state.NotifyReadyToActivate();
1155 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1138 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1156 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1139 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1157 1140
1158 // Draw the newly activated tree. 1141 // Draw the newly activated tree.
1159 state.NotifyReadyToDraw(); 1142 state.NotifyReadyToDraw();
1160 state.OnBeginImplFrameDeadline(); 1143 state.OnBeginImplFrameDeadline();
1161 EXPECT_ACTION_UPDATE_STATE( 1144 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1162 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1163 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1145 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1164 } 1146 }
1165 1147
1166 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) { 1148 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) {
1167 SchedulerSettings default_scheduler_settings; 1149 SchedulerSettings default_scheduler_settings;
1168 StateMachine state(default_scheduler_settings); 1150 StateMachine state(default_scheduler_settings);
1169 SET_UP_STATE(state) 1151 SET_UP_STATE(state)
1170 1152
1171 // Start clean and set commit. 1153 // Start clean and set commit.
1172 state.SetNeedsBeginMainFrame(); 1154 state.SetNeedsBeginMainFrame();
(...skipping 21 matching lines...) Expand all
1194 state.NotifyReadyToActivate(); 1176 state.NotifyReadyToActivate();
1195 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1177 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1196 EXPECT_TRUE(state.active_tree_needs_first_draw()); 1178 EXPECT_TRUE(state.active_tree_needs_first_draw());
1197 EXPECT_TRUE(state.needs_redraw()); 1179 EXPECT_TRUE(state.needs_redraw());
1198 1180
1199 // Expect to do nothing until BeginImplFrame deadline. 1181 // Expect to do nothing until BeginImplFrame deadline.
1200 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1182 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1201 1183
1202 // At BeginImplFrame deadline, draw. 1184 // At BeginImplFrame deadline, draw.
1203 state.OnBeginImplFrameDeadline(); 1185 state.OnBeginImplFrameDeadline();
1204 EXPECT_ACTION_UPDATE_STATE( 1186 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1205 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1187 state.DidSubmitCompositorFrame();
1206 state.DidSwapBuffers(); 1188 state.DidReceiveCompositorFrameAck();
1207 state.DidSwapBuffersComplete();
1208 1189
1209 // Should be synchronized, no draw needed, no action needed. 1190 // Should be synchronized, no draw needed, no action needed.
1210 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1191 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1211 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 1192 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
1212 EXPECT_FALSE(state.needs_redraw()); 1193 EXPECT_FALSE(state.needs_redraw());
1213 1194
1214 // Next BeginImplFrame should initiate second commit. 1195 // Next BeginImplFrame should initiate second commit.
1215 state.OnBeginImplFrame(); 1196 state.OnBeginImplFrame();
1216 EXPECT_ACTION_UPDATE_STATE( 1197 EXPECT_ACTION_UPDATE_STATE(
1217 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1198 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1479 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1460 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1480 EXPECT_EQ(state.compositor_frame_sink_state(), 1461 EXPECT_EQ(state.compositor_frame_sink_state(),
1481 SchedulerStateMachine::COMPOSITOR_FRAME_SINK_ACTIVE); 1462 SchedulerStateMachine::COMPOSITOR_FRAME_SINK_ACTIVE);
1482 1463
1483 // Finishing the first commit after initializing an CompositorFrameSink should 1464 // Finishing the first commit after initializing an CompositorFrameSink should
1484 // automatically cause a redraw. 1465 // automatically cause a redraw.
1485 EXPECT_TRUE(state.RedrawPending()); 1466 EXPECT_TRUE(state.RedrawPending());
1486 state.OnBeginImplFrame(); 1467 state.OnBeginImplFrame();
1487 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1468 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1488 state.OnBeginImplFrameDeadline(); 1469 state.OnBeginImplFrameDeadline();
1489 EXPECT_ACTION_UPDATE_STATE( 1470 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1490 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1491 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1471 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1492 EXPECT_FALSE(state.RedrawPending()); 1472 EXPECT_FALSE(state.RedrawPending());
1493 1473
1494 // Next frame as no work to do. 1474 // Next frame as no work to do.
1495 state.OnBeginImplFrame(); 1475 state.OnBeginImplFrame();
1496 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1476 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1497 state.OnBeginImplFrameDeadline(); 1477 state.OnBeginImplFrameDeadline();
1498 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1478 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1499 1479
1500 // Once the context is recreated, whether we draw should be based on 1480 // Once the context is recreated, whether we draw should be based on
1501 // SetCanDraw if waiting on first draw after activate. 1481 // SetCanDraw if waiting on first draw after activate.
1502 state.SetNeedsRedraw(true); 1482 state.SetNeedsRedraw(true);
1503 state.OnBeginImplFrame(); 1483 state.OnBeginImplFrame();
1504 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1484 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1505 state.OnBeginImplFrameDeadline(); 1485 state.OnBeginImplFrameDeadline();
1506 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1486 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1507 state.SetCanDraw(false); 1487 state.SetCanDraw(false);
1508 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); 1488 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1509 state.SetCanDraw(true); 1489 state.SetCanDraw(true);
1510 EXPECT_ACTION_UPDATE_STATE( 1490 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1511 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1512 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1491 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1513 1492
1514 // Once the context is recreated, whether we draw should be based on 1493 // Once the context is recreated, whether we draw should be based on
1515 // SetCanDraw if waiting on first draw after activate. 1494 // SetCanDraw if waiting on first draw after activate.
1516 state.SetNeedsRedraw(true); 1495 state.SetNeedsRedraw(true);
1517 state.SetNeedsBeginMainFrame(); 1496 state.SetNeedsBeginMainFrame();
1518 state.OnBeginImplFrame(); 1497 state.OnBeginImplFrame();
1519 EXPECT_ACTION_UPDATE_STATE( 1498 EXPECT_ACTION_UPDATE_STATE(
1520 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1499 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1521 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1500 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1522 // Activate so we need the first draw 1501 // Activate so we need the first draw
1523 state.NotifyBeginMainFrameStarted(); 1502 state.NotifyBeginMainFrameStarted();
1524 state.NotifyReadyToCommit(); 1503 state.NotifyReadyToCommit();
1525 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1504 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1526 state.NotifyReadyToActivate(); 1505 state.NotifyReadyToActivate();
1527 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1506 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1528 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1507 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1529 EXPECT_TRUE(state.active_tree_needs_first_draw()); 1508 EXPECT_TRUE(state.active_tree_needs_first_draw());
1530 EXPECT_TRUE(state.needs_redraw()); 1509 EXPECT_TRUE(state.needs_redraw());
1531 1510
1532 state.OnBeginImplFrameDeadline(); 1511 state.OnBeginImplFrameDeadline();
1533 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1512 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1534 state.SetCanDraw(false); 1513 state.SetCanDraw(false);
1535 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1514 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_ABORT);
1536 state.SetCanDraw(true); 1515 state.SetCanDraw(true);
1537 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1516 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1538 } 1517 }
1539 1518
1540 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) { 1519 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) {
1541 SchedulerSettings scheduler_settings; 1520 SchedulerSettings scheduler_settings;
1542 StateMachine state(scheduler_settings); 1521 StateMachine state(scheduler_settings);
1543 SET_UP_STATE(state) 1522 SET_UP_STATE(state)
1544 1523
1545 // Get a commit in flight. 1524 // Get a commit in flight.
1546 state.SetNeedsBeginMainFrame(); 1525 state.SetNeedsBeginMainFrame();
1547 1526
1548 // Set damage and expect a draw. 1527 // Set damage and expect a draw.
1549 state.SetNeedsRedraw(true); 1528 state.SetNeedsRedraw(true);
1550 state.OnBeginImplFrame(); 1529 state.OnBeginImplFrame();
1551 EXPECT_ACTION_UPDATE_STATE( 1530 EXPECT_ACTION_UPDATE_STATE(
1552 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1531 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1553 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1532 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1554 state.OnBeginImplFrameDeadline(); 1533 state.OnBeginImplFrameDeadline();
1555 EXPECT_ACTION_UPDATE_STATE( 1534 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1556 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1535 state.DidSubmitCompositorFrame();
1557 state.DidSwapBuffers(); 1536 state.DidReceiveCompositorFrameAck();
1558 state.DidSwapBuffersComplete();
1559 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1537 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1560 1538
1561 // Cause a lost context while the BeginMainFrame is in flight. 1539 // Cause a lost context while the BeginMainFrame is in flight.
1562 state.DidLoseCompositorFrameSink(); 1540 state.DidLoseCompositorFrameSink();
1563 1541
1564 // Ask for another draw. Expect nothing happens. 1542 // Ask for another draw. Expect nothing happens.
1565 state.SetNeedsRedraw(true); 1543 state.SetNeedsRedraw(true);
1566 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); 1544 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1567 1545
1568 // Finish the frame, commit and activate. 1546 // Finish the frame, commit and activate.
1569 state.NotifyBeginMainFrameStarted(); 1547 state.NotifyBeginMainFrameStarted();
1570 state.NotifyReadyToCommit(); 1548 state.NotifyReadyToCommit();
1571 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1549 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1572 state.NotifyReadyToActivate(); 1550 state.NotifyReadyToActivate();
1573 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1551 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1574 1552
1575 // We will abort the draw when the CompositorFrameSink is lost if we are 1553 // We will abort the draw when the CompositorFrameSink is lost if we are
1576 // waiting for the first draw to unblock the main thread. 1554 // waiting for the first draw to unblock the main thread.
1577 EXPECT_TRUE(state.active_tree_needs_first_draw()); 1555 EXPECT_TRUE(state.active_tree_needs_first_draw());
1578 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1556 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_ABORT);
1579 1557
1580 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE 1558 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE
1581 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); 1559 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
1582 EXPECT_ACTION( 1560 EXPECT_ACTION(
1583 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 1561 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
1584 1562
1585 state.OnBeginImplFrame(); 1563 state.OnBeginImplFrame();
1586 EXPECT_IMPL_FRAME_STATE( 1564 EXPECT_IMPL_FRAME_STATE(
1587 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME); 1565 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME);
1588 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); 1566 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
(...skipping 14 matching lines...) Expand all
1603 state.SetNeedsBeginMainFrame(); 1581 state.SetNeedsBeginMainFrame();
1604 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1582 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1605 1583
1606 // Set damage and expect a draw. 1584 // Set damage and expect a draw.
1607 state.SetNeedsRedraw(true); 1585 state.SetNeedsRedraw(true);
1608 state.OnBeginImplFrame(); 1586 state.OnBeginImplFrame();
1609 EXPECT_ACTION_UPDATE_STATE( 1587 EXPECT_ACTION_UPDATE_STATE(
1610 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1588 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1611 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1589 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1612 state.OnBeginImplFrameDeadline(); 1590 state.OnBeginImplFrameDeadline();
1613 EXPECT_ACTION_UPDATE_STATE( 1591 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1614 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1592 state.DidSubmitCompositorFrame();
1615 state.DidSwapBuffers(); 1593 state.DidReceiveCompositorFrameAck();
1616 state.DidSwapBuffersComplete();
1617 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1594 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1618 1595
1619 // Cause a lost context while the BeginMainFrame is in flight. 1596 // Cause a lost context while the BeginMainFrame is in flight.
1620 state.DidLoseCompositorFrameSink(); 1597 state.DidLoseCompositorFrameSink();
1621 1598
1622 // Ask for another draw and also set needs commit. Expect nothing happens. 1599 // Ask for another draw and also set needs commit. Expect nothing happens.
1623 state.SetNeedsRedraw(true); 1600 state.SetNeedsRedraw(true);
1624 state.SetNeedsBeginMainFrame(); 1601 state.SetNeedsBeginMainFrame();
1625 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1602 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1626 1603
1627 // Finish the frame, and commit and activate. 1604 // Finish the frame, and commit and activate.
1628 state.NotifyBeginMainFrameStarted(); 1605 state.NotifyBeginMainFrameStarted();
1629 state.NotifyReadyToCommit(); 1606 state.NotifyReadyToCommit();
1630 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1607 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1631 state.NotifyReadyToActivate(); 1608 state.NotifyReadyToActivate();
1632 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1609 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1633 EXPECT_TRUE(state.active_tree_needs_first_draw()); 1610 EXPECT_TRUE(state.active_tree_needs_first_draw());
1634 1611
1635 // Because the CompositorFrameSink is missing, we expect the draw to abort. 1612 // Because the CompositorFrameSink is missing, we expect the draw to abort.
1636 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1613 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_ABORT);
1637 1614
1638 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE 1615 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE
1639 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); 1616 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
1640 EXPECT_ACTION( 1617 EXPECT_ACTION(
1641 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 1618 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
1642 1619
1643 state.OnBeginImplFrame(); 1620 state.OnBeginImplFrame();
1644 EXPECT_IMPL_FRAME_STATE( 1621 EXPECT_IMPL_FRAME_STATE(
1645 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME); 1622 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME);
1646 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); 1623 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
(...skipping 14 matching lines...) Expand all
1661 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1638 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1662 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1639 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1663 state.NotifyBeginMainFrameStarted(); 1640 state.NotifyBeginMainFrameStarted();
1664 state.NotifyReadyToCommit(); 1641 state.NotifyReadyToCommit();
1665 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1642 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1666 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1643 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1667 state.NotifyReadyToActivate(); 1644 state.NotifyReadyToActivate();
1668 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1645 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1669 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1646 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1670 state.OnBeginImplFrameDeadline(); 1647 state.OnBeginImplFrameDeadline();
1671 EXPECT_ACTION_UPDATE_STATE( 1648 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1672 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1649 state.DidSubmitCompositorFrame();
1673 state.DidSwapBuffers(); 1650 state.DidReceiveCompositorFrameAck();
1674 state.DidSwapBuffersComplete();
1675 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1651 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1676 } 1652 }
1677 1653
1678 TEST(SchedulerStateMachineTest, 1654 TEST(SchedulerStateMachineTest,
1679 DontDrawBeforeCommitAfterLostCompositorFrameSink) { 1655 DontDrawBeforeCommitAfterLostCompositorFrameSink) {
1680 SchedulerSettings default_scheduler_settings; 1656 SchedulerSettings default_scheduler_settings;
1681 StateMachine state(default_scheduler_settings); 1657 StateMachine state(default_scheduler_settings);
1682 SET_UP_STATE(state) 1658 SET_UP_STATE(state)
1683 1659
1684 state.SetNeedsRedraw(true); 1660 state.SetNeedsRedraw(true);
(...skipping 23 matching lines...) Expand all
1708 state.DidLoseCompositorFrameSink(); 1684 state.DidLoseCompositorFrameSink();
1709 1685
1710 state.NotifyBeginMainFrameStarted(); 1686 state.NotifyBeginMainFrameStarted();
1711 state.NotifyReadyToCommit(); 1687 state.NotifyReadyToCommit();
1712 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1688 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1713 1689
1714 EXPECT_TRUE(state.PendingActivationsShouldBeForced()); 1690 EXPECT_TRUE(state.PendingActivationsShouldBeForced());
1715 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1691 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1716 1692
1717 EXPECT_TRUE(state.PendingDrawsShouldBeAborted()); 1693 EXPECT_TRUE(state.PendingDrawsShouldBeAborted());
1718 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1694 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_ABORT);
1719 } 1695 }
1720 1696
1721 TEST(SchedulerStateMachineTest, TestNoBeginFrameNeededWhenInvisible) { 1697 TEST(SchedulerStateMachineTest, TestNoBeginFrameNeededWhenInvisible) {
1722 SchedulerSettings default_scheduler_settings; 1698 SchedulerSettings default_scheduler_settings;
1723 StateMachine state(default_scheduler_settings); 1699 StateMachine state(default_scheduler_settings);
1724 state.SetVisible(true); 1700 state.SetVisible(true);
1725 EXPECT_ACTION_UPDATE_STATE( 1701 EXPECT_ACTION_UPDATE_STATE(
1726 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 1702 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
1727 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1703 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1728 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 1704 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1772 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); 1748 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
1773 state.SetNeedsBeginMainFrame(); 1749 state.SetNeedsBeginMainFrame();
1774 1750
1775 // After the commit completes, activation and draw happen immediately 1751 // After the commit completes, activation and draw happen immediately
1776 // because we are not visible. 1752 // because we are not visible.
1777 state.NotifyBeginMainFrameStarted(); 1753 state.NotifyBeginMainFrameStarted();
1778 state.NotifyReadyToCommit(); 1754 state.NotifyReadyToCommit();
1779 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1755 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1780 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1756 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1781 EXPECT_TRUE(state.active_tree_needs_first_draw()); 1757 EXPECT_TRUE(state.active_tree_needs_first_draw());
1782 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1758 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_ABORT);
1783 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1759 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1784 } 1760 }
1785 1761
1786 TEST(SchedulerStateMachineTest, 1762 TEST(SchedulerStateMachineTest,
1787 TestFinishCommitWhenCommitInProgressAndBeginFrameSourcePaused) { 1763 TestFinishCommitWhenCommitInProgressAndBeginFrameSourcePaused) {
1788 SchedulerSettings default_scheduler_settings; 1764 SchedulerSettings default_scheduler_settings;
1789 StateMachine state(default_scheduler_settings); 1765 StateMachine state(default_scheduler_settings);
1790 state.SetVisible(true); 1766 state.SetVisible(true);
1791 EXPECT_ACTION_UPDATE_STATE( 1767 EXPECT_ACTION_UPDATE_STATE(
1792 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 1768 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
1793 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1769 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1794 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 1770 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
1795 state.SetBeginFrameSourcePaused(true); 1771 state.SetBeginFrameSourcePaused(true);
1796 state.SetBeginMainFrameState( 1772 state.SetBeginMainFrameState(
1797 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); 1773 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
1798 state.SetNeedsBeginMainFrame(); 1774 state.SetNeedsBeginMainFrame();
1799 1775
1800 // After the commit completes, activation and draw happen immediately 1776 // After the commit completes, activation and draw happen immediately
1801 // because we are not visible. 1777 // because we are not visible.
1802 state.NotifyBeginMainFrameStarted(); 1778 state.NotifyBeginMainFrameStarted();
1803 state.NotifyReadyToCommit(); 1779 state.NotifyReadyToCommit();
1804 EXPECT_TRUE(state.PendingActivationsShouldBeForced()); 1780 EXPECT_TRUE(state.PendingActivationsShouldBeForced());
1805 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1781 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1806 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1782 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1807 EXPECT_TRUE(state.active_tree_needs_first_draw()); 1783 EXPECT_TRUE(state.active_tree_needs_first_draw());
1808 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1784 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_ABORT);
1809 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1785 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1810 } 1786 }
1811 1787
1812 TEST(SchedulerStateMachineTest, TestInitialActionsWhenContextLost) { 1788 TEST(SchedulerStateMachineTest, TestInitialActionsWhenContextLost) {
1813 SchedulerSettings default_scheduler_settings; 1789 SchedulerSettings default_scheduler_settings;
1814 StateMachine state(default_scheduler_settings); 1790 StateMachine state(default_scheduler_settings);
1815 SET_UP_STATE(state) 1791 SET_UP_STATE(state)
1816 state.SetNeedsBeginMainFrame(); 1792 state.SetNeedsBeginMainFrame();
1817 state.DidLoseCompositorFrameSink(); 1793 state.DidLoseCompositorFrameSink();
1818 1794
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1951 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1927 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1952 state.NotifyReadyToActivate(); 1928 state.NotifyReadyToActivate();
1953 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1929 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1954 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1930 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1955 1931
1956 state.OnBeginImplFrame(); 1932 state.OnBeginImplFrame();
1957 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1933 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1958 1934
1959 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 1935 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
1960 state.OnBeginImplFrameDeadline(); 1936 state.OnBeginImplFrameDeadline();
1961 EXPECT_ACTION_UPDATE_STATE( 1937 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1962 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1938 state.DidSubmitCompositorFrame();
1963 state.DidSwapBuffers();
1964 } 1939 }
1965 1940
1966 TEST(SchedulerStateMachineTest, TestImplLatencyTakesPriority) { 1941 TEST(SchedulerStateMachineTest, TestImplLatencyTakesPriority) {
1967 SchedulerSettings default_scheduler_settings; 1942 SchedulerSettings default_scheduler_settings;
1968 StateMachine state(default_scheduler_settings); 1943 StateMachine state(default_scheduler_settings);
1969 SET_UP_STATE(state) 1944 SET_UP_STATE(state)
1970 1945
1971 // This test ensures that impl-draws are prioritized over main thread updates 1946 // This test ensures that impl-draws are prioritized over main thread updates
1972 // in prefer impl latency mode. 1947 // in prefer impl latency mode.
1973 state.SetNeedsRedraw(true); 1948 state.SetNeedsRedraw(true);
1974 state.SetNeedsBeginMainFrame(); 1949 state.SetNeedsBeginMainFrame();
1975 state.OnBeginImplFrame(); 1950 state.OnBeginImplFrame();
1976 EXPECT_ACTION_UPDATE_STATE( 1951 EXPECT_ACTION_UPDATE_STATE(
1977 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1952 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1978 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1953 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1979 1954
1980 // Verify the deadline is not triggered early until we enter 1955 // Verify the deadline is not triggered early until we enter
1981 // prefer impl latency mode. 1956 // prefer impl latency mode.
1982 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 1957 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
1983 state.SetTreePrioritiesAndScrollState( 1958 state.SetTreePrioritiesAndScrollState(
1984 SMOOTHNESS_TAKES_PRIORITY, 1959 SMOOTHNESS_TAKES_PRIORITY,
1985 ScrollHandlerState::SCROLL_DOES_NOT_AFFECT_SCROLL_HANDLER); 1960 ScrollHandlerState::SCROLL_DOES_NOT_AFFECT_SCROLL_HANDLER);
1986 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 1961 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
1987 1962
1988 // Trigger the deadline. 1963 // Trigger the deadline.
1989 state.OnBeginImplFrameDeadline(); 1964 state.OnBeginImplFrameDeadline();
1990 EXPECT_ACTION_UPDATE_STATE( 1965 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_IF_POSSIBLE);
1991 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1966 state.DidSubmitCompositorFrame();
1992 state.DidSwapBuffers();
1993 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1967 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1994 state.DidSwapBuffersComplete(); 1968 state.DidReceiveCompositorFrameAck();
1995 1969
1996 // Request a new commit and finish the previous one. 1970 // Request a new commit and finish the previous one.
1997 state.SetNeedsBeginMainFrame(); 1971 state.SetNeedsBeginMainFrame();
1998 FinishPreviousCommitAndDrawWithoutExitingDeadline(&state); 1972 FinishPreviousCommitAndDrawWithoutExitingDeadline(&state);
1999 EXPECT_ACTION_UPDATE_STATE( 1973 EXPECT_ACTION_UPDATE_STATE(
2000 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1974 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
2001 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1975 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2002 state.DidSwapBuffersComplete(); 1976 state.DidReceiveCompositorFrameAck();
2003 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1977 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2004 1978
2005 // Finish the previous commit and draw it. 1979 // Finish the previous commit and draw it.
2006 FinishPreviousCommitAndDrawWithoutExitingDeadline(&state); 1980 FinishPreviousCommitAndDrawWithoutExitingDeadline(&state);
2007 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1981 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2008 1982
2009 // Verify we do not send another BeginMainFrame if was are swap throttled 1983 // Verify we do not send another BeginMainFrame if was are submit-frame
2010 // and did not just swap. 1984 // throttled and did not just submit one.
2011 state.SetNeedsBeginMainFrame(); 1985 state.SetNeedsBeginMainFrame();
2012 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1986 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2013 state.OnBeginImplFrame(); 1987 state.OnBeginImplFrame();
2014 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1988 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2015 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 1989 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
2016 state.OnBeginImplFrameDeadline(); 1990 state.OnBeginImplFrameDeadline();
2017 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1991 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2018 } 1992 }
2019 1993
2020 TEST(SchedulerStateMachineTest, 1994 TEST(SchedulerStateMachineTest,
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
2171 state.OnBeginImplFrameDeadline(); 2145 state.OnBeginImplFrameDeadline();
2172 state.OnBeginImplFrameIdle(); 2146 state.OnBeginImplFrameIdle();
2173 2147
2174 // The scheduler should begin the CompositorFrameSink creation now. 2148 // The scheduler should begin the CompositorFrameSink creation now.
2175 EXPECT_ACTION_UPDATE_STATE( 2149 EXPECT_ACTION_UPDATE_STATE(
2176 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 2150 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
2177 } 2151 }
2178 2152
2179 } // namespace 2153 } // namespace
2180 } // namespace cc 2154 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698