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

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: rebase 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_SUBMIT_COMPOSITOR_FRAME"
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 == \
41 action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED) { \ 41 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE || \
42 EXPECT_IMPL_FRAME_STATE( \ 42 action == \
43 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); \ 43 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_FORCED) { \
44 } \ 44 EXPECT_IMPL_FRAME_STATE( \
45 PerformAction(&state, action); \ 45 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); \
46 if (action == SchedulerStateMachine::ACTION_NONE) { \ 46 } \
47 if (state.begin_impl_frame_state() == \ 47 PerformAction(&state, action); \
48 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) \ 48 if (action == SchedulerStateMachine::ACTION_NONE) { \
49 state.OnBeginImplFrameIdle(); \ 49 if (state.begin_impl_frame_state() == \
50 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) \
51 state.OnBeginImplFrameIdle(); \
50 } 52 }
51 53
52 #define SET_UP_STATE(state) \ 54 #define SET_UP_STATE(state) \
53 state.SetVisible(true); \ 55 state.SetVisible(true); \
54 EXPECT_ACTION_UPDATE_STATE( \ 56 EXPECT_ACTION_UPDATE_STATE( \
55 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); \ 57 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); \
56 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); \ 58 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); \
57 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); \ 59 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); \
58 state.SetCanDraw(true); 60 state.SetCanDraw(true);
59 61
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 case SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME: 172 case SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME:
171 sm->WillSendBeginMainFrame(); 173 sm->WillSendBeginMainFrame();
172 return; 174 return;
173 175
174 case SchedulerStateMachine::ACTION_COMMIT: { 176 case SchedulerStateMachine::ACTION_COMMIT: {
175 bool commit_has_no_updates = false; 177 bool commit_has_no_updates = false;
176 sm->WillCommit(commit_has_no_updates); 178 sm->WillCommit(commit_has_no_updates);
177 return; 179 return;
178 } 180 }
179 181
180 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED: 182 case SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_FORCED:
181 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE: { 183 case SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE: {
182 sm->WillDraw(); 184 sm->WillDraw();
183 sm->DidDraw(sm->draw_result_for_test()); 185 sm->DidDraw(sm->draw_result_for_test());
184 return; 186 return;
185 } 187 }
186 188
187 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT: { 189 case SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_ABORT: {
188 sm->AbortDrawAndSwap(); 190 sm->AbortSubmitCompositorFrame();
189 return; 191 return;
190 } 192 }
191 193
192 case SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION: 194 case SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION:
193 sm->WillBeginCompositorFrameSinkCreation(); 195 sm->WillBeginCompositorFrameSinkCreation();
194 return; 196 return;
195 197
196 case SchedulerStateMachine::ACTION_PREPARE_TILES: 198 case SchedulerStateMachine::ACTION_PREPARE_TILES:
197 sm->WillPrepareTiles(); 199 sm->WillPrepareTiles();
198 return; 200 return;
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 // Verify NotifyReadyToActivate unblocks activation, commit, and 399 // Verify NotifyReadyToActivate unblocks activation, commit, and
398 // draw in that order. 400 // draw in that order.
399 state.NotifyReadyToActivate(); 401 state.NotifyReadyToActivate();
400 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 402 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
401 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 403 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
402 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 404 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
403 405
404 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 406 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
405 state.OnBeginImplFrameDeadline(); 407 state.OnBeginImplFrameDeadline();
406 EXPECT_ACTION_UPDATE_STATE( 408 EXPECT_ACTION_UPDATE_STATE(
407 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 409 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE);
408 state.DidSwapBuffers(); 410 state.DidSubmitCompositorFrame();
409 state.DidSwapBuffersComplete(); 411 state.DidReceiveCompositorFrameAck();
410 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 412 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
411 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 413 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
412 } 414 }
413 415
414 TEST(SchedulerStateMachineTest, 416 TEST(SchedulerStateMachineTest,
415 FailedDrawForAnimationCheckerboardSetsNeedsCommitAndRetriesDraw) { 417 FailedDrawForAnimationCheckerboardSetsNeedsCommitAndRetriesDraw) {
416 SchedulerSettings default_scheduler_settings; 418 SchedulerSettings default_scheduler_settings;
417 StateMachine state(default_scheduler_settings); 419 StateMachine state(default_scheduler_settings);
418 SET_UP_STATE(state) 420 SET_UP_STATE(state)
419 state.SetNeedsRedraw(true); 421 state.SetNeedsRedraw(true);
420 EXPECT_TRUE(state.RedrawPending()); 422 EXPECT_TRUE(state.RedrawPending());
421 EXPECT_TRUE(state.BeginFrameNeeded()); 423 EXPECT_TRUE(state.BeginFrameNeeded());
422 424
423 // Start a frame. 425 // Start a frame.
424 state.OnBeginImplFrame(); 426 state.OnBeginImplFrame();
425 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 427 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
426 EXPECT_FALSE(state.CommitPending()); 428 EXPECT_FALSE(state.CommitPending());
427 429
428 // Failing a draw triggers request for a new BeginMainFrame. 430 // Failing a draw triggers request for a new BeginMainFrame.
429 state.OnBeginImplFrameDeadline(); 431 state.OnBeginImplFrameDeadline();
430 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 432 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
431 EXPECT_ACTION_UPDATE_STATE( 433 EXPECT_ACTION_UPDATE_STATE(
432 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 434 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE);
433 EXPECT_ACTION_UPDATE_STATE( 435 EXPECT_ACTION_UPDATE_STATE(
434 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 436 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
435 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 437 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
436 state.OnBeginImplFrameIdle(); 438 state.OnBeginImplFrameIdle();
437 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 439 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
438 440
439 // It's okay to attempt more draws just in case additional raster 441 // It's okay to attempt more draws just in case additional raster
440 // finishes and the requested commit wasn't actually necessary. 442 // finishes and the requested commit wasn't actually necessary.
441 EXPECT_TRUE(state.CommitPending()); 443 EXPECT_TRUE(state.CommitPending());
442 EXPECT_TRUE(state.RedrawPending()); 444 EXPECT_TRUE(state.RedrawPending());
443 state.OnBeginImplFrame(); 445 state.OnBeginImplFrame();
444 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 446 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
445 state.OnBeginImplFrameDeadline(); 447 state.OnBeginImplFrameDeadline();
446 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 448 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
447 EXPECT_ACTION_UPDATE_STATE( 449 EXPECT_ACTION_UPDATE_STATE(
448 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 450 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE);
449 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 451 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
450 state.OnBeginImplFrameIdle(); 452 state.OnBeginImplFrameIdle();
451 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 453 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
452 } 454 }
453 455
454 TEST(SchedulerStateMachineTest, FailedDrawForMissingHighResNeedsCommit) { 456 TEST(SchedulerStateMachineTest, FailedDrawForMissingHighResNeedsCommit) {
455 SchedulerSettings default_scheduler_settings; 457 SchedulerSettings default_scheduler_settings;
456 StateMachine state(default_scheduler_settings); 458 StateMachine state(default_scheduler_settings);
457 SET_UP_STATE(state) 459 SET_UP_STATE(state)
458 state.SetNeedsRedraw(true); 460 state.SetNeedsRedraw(true);
459 EXPECT_TRUE(state.RedrawPending()); 461 EXPECT_TRUE(state.RedrawPending());
460 EXPECT_TRUE(state.BeginFrameNeeded()); 462 EXPECT_TRUE(state.BeginFrameNeeded());
461 463
462 // Start a frame. 464 // Start a frame.
463 state.OnBeginImplFrame(); 465 state.OnBeginImplFrame();
464 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 466 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
465 EXPECT_FALSE(state.CommitPending()); 467 EXPECT_FALSE(state.CommitPending());
466 468
467 // Failing a draw triggers because of high res tiles missing 469 // Failing a draw triggers because of high res tiles missing
468 // request for a new BeginMainFrame. 470 // request for a new BeginMainFrame.
469 state.OnBeginImplFrameDeadline(); 471 state.OnBeginImplFrameDeadline();
470 state.SetDrawResultForTest(DRAW_ABORTED_MISSING_HIGH_RES_CONTENT); 472 state.SetDrawResultForTest(DRAW_ABORTED_MISSING_HIGH_RES_CONTENT);
471 EXPECT_ACTION_UPDATE_STATE( 473 EXPECT_ACTION_UPDATE_STATE(
472 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 474 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE);
473 EXPECT_ACTION_UPDATE_STATE( 475 EXPECT_ACTION_UPDATE_STATE(
474 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 476 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
475 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 477 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
476 state.OnBeginImplFrameIdle(); 478 state.OnBeginImplFrameIdle();
477 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 479 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
478 480
479 // It doesn't request a draw until we get a new commit though. 481 // It doesn't request a draw until we get a new commit though.
480 EXPECT_TRUE(state.CommitPending()); 482 EXPECT_TRUE(state.CommitPending());
481 EXPECT_FALSE(state.RedrawPending()); 483 EXPECT_FALSE(state.RedrawPending());
482 state.OnBeginImplFrame(); 484 state.OnBeginImplFrame();
(...skipping 12 matching lines...) Expand all
495 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 497 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
496 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 498 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
497 EXPECT_TRUE(state.RedrawPending()); 499 EXPECT_TRUE(state.RedrawPending());
498 500
499 // Verify we draw with the new frame. 501 // Verify we draw with the new frame.
500 state.OnBeginImplFrame(); 502 state.OnBeginImplFrame();
501 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 503 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
502 state.OnBeginImplFrameDeadline(); 504 state.OnBeginImplFrameDeadline();
503 state.SetDrawResultForTest(DRAW_SUCCESS); 505 state.SetDrawResultForTest(DRAW_SUCCESS);
504 EXPECT_ACTION_UPDATE_STATE( 506 EXPECT_ACTION_UPDATE_STATE(
505 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 507 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE);
506 state.DidSwapBuffers(); 508 state.DidSubmitCompositorFrame();
507 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 509 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
508 state.OnBeginImplFrameIdle(); 510 state.OnBeginImplFrameIdle();
509 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 511 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
510 } 512 }
511 513
512 TEST(SchedulerStateMachineTest, 514 TEST(SchedulerStateMachineTest,
513 TestFailedDrawsEventuallyForceDrawAfterNextCommit) { 515 TestFailedDrawsEventuallyForceDrawAfterNextCommit) {
514 SchedulerSettings scheduler_settings; 516 SchedulerSettings scheduler_settings;
515 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced = 1; 517 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced = 1;
516 StateMachine state(scheduler_settings); 518 StateMachine state(scheduler_settings);
517 SET_UP_STATE(state) 519 SET_UP_STATE(state)
518 520
519 // Start a commit. 521 // Start a commit.
520 state.SetNeedsBeginMainFrame(); 522 state.SetNeedsBeginMainFrame();
521 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 523 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
522 state.OnBeginImplFrame(); 524 state.OnBeginImplFrame();
523 EXPECT_ACTION_UPDATE_STATE( 525 EXPECT_ACTION_UPDATE_STATE(
524 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 526 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
525 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 527 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
526 EXPECT_TRUE(state.CommitPending()); 528 EXPECT_TRUE(state.CommitPending());
527 529
528 // Then initiate a draw that fails. 530 // Then initiate a draw that fails.
529 state.SetNeedsRedraw(true); 531 state.SetNeedsRedraw(true);
530 state.OnBeginImplFrameDeadline(); 532 state.OnBeginImplFrameDeadline();
531 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 533 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
532 EXPECT_ACTION_UPDATE_STATE( 534 EXPECT_ACTION_UPDATE_STATE(
533 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 535 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE);
534 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 536 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
535 EXPECT_TRUE(state.BeginFrameNeeded()); 537 EXPECT_TRUE(state.BeginFrameNeeded());
536 EXPECT_TRUE(state.RedrawPending()); 538 EXPECT_TRUE(state.RedrawPending());
537 EXPECT_TRUE(state.CommitPending()); 539 EXPECT_TRUE(state.CommitPending());
538 540
539 // Finish the commit. Note, we should not yet be forcing a draw, but should 541 // Finish the commit. Note, we should not yet be forcing a draw, but should
540 // continue the commit as usual. 542 // continue the commit as usual.
541 state.NotifyBeginMainFrameStarted(); 543 state.NotifyBeginMainFrameStarted();
542 state.NotifyReadyToCommit(); 544 state.NotifyReadyToCommit();
543 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 545 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
544 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 546 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
545 EXPECT_TRUE(state.RedrawPending()); 547 EXPECT_TRUE(state.RedrawPending());
546 548
547 // Activate so we're ready for a new main frame. 549 // Activate so we're ready for a new main frame.
548 state.NotifyReadyToActivate(); 550 state.NotifyReadyToActivate();
549 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 551 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
550 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 552 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
551 EXPECT_TRUE(state.RedrawPending()); 553 EXPECT_TRUE(state.RedrawPending());
552 554
553 // The redraw should be forced at the end of the next BeginImplFrame. 555 // The redraw should be forced at the end of the next BeginImplFrame.
554 state.OnBeginImplFrame(); 556 state.OnBeginImplFrame();
555 EXPECT_ACTION_UPDATE_STATE( 557 EXPECT_ACTION_UPDATE_STATE(
556 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 558 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
557 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 559 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
558 state.OnBeginImplFrameDeadline(); 560 state.OnBeginImplFrameDeadline();
559 state.SetDrawResultForTest(DRAW_SUCCESS); 561 state.SetDrawResultForTest(DRAW_SUCCESS);
560 EXPECT_ACTION_UPDATE_STATE( 562 EXPECT_ACTION_UPDATE_STATE(
561 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED); 563 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_FORCED);
562 state.DidSwapBuffers(); 564 state.DidSubmitCompositorFrame();
563 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 565 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
564 state.DidSwapBuffersComplete(); 566 state.DidReceiveCompositorFrameAck();
565 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 567 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
566 } 568 }
567 569
568 TEST(SchedulerStateMachineTest, TestFailedDrawsDoNotRestartForcedDraw) { 570 TEST(SchedulerStateMachineTest, TestFailedDrawsDoNotRestartForcedDraw) {
569 SchedulerSettings scheduler_settings; 571 SchedulerSettings scheduler_settings;
570 int draw_limit = 2; 572 int draw_limit = 2;
571 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced = 573 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced =
572 draw_limit; 574 draw_limit;
573 StateMachine state(scheduler_settings); 575 StateMachine state(scheduler_settings);
574 SET_UP_STATE(state) 576 SET_UP_STATE(state)
575 577
576 // Start a commit. 578 // Start a commit.
577 state.SetNeedsBeginMainFrame(); 579 state.SetNeedsBeginMainFrame();
578 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 580 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
579 state.OnBeginImplFrame(); 581 state.OnBeginImplFrame();
580 EXPECT_ACTION_UPDATE_STATE( 582 EXPECT_ACTION_UPDATE_STATE(
581 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 583 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
582 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 584 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
583 EXPECT_TRUE(state.CommitPending()); 585 EXPECT_TRUE(state.CommitPending());
584 586
585 // Then initiate a draw. 587 // Then initiate a draw.
586 state.SetNeedsRedraw(true); 588 state.SetNeedsRedraw(true);
587 state.OnBeginImplFrameDeadline(); 589 state.OnBeginImplFrameDeadline();
588 EXPECT_ACTION_UPDATE_STATE( 590 EXPECT_ACTION_UPDATE_STATE(
589 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 591 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE);
590 592
591 // Fail the draw enough times to force a redraw. 593 // Fail the draw enough times to force a redraw.
592 for (int i = 0; i < draw_limit; ++i) { 594 for (int i = 0; i < draw_limit; ++i) {
593 state.SetNeedsRedraw(true); 595 state.SetNeedsRedraw(true);
594 state.OnBeginImplFrame(); 596 state.OnBeginImplFrame();
595 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 597 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
596 state.OnBeginImplFrameDeadline(); 598 state.OnBeginImplFrameDeadline();
597 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 599 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
598 EXPECT_ACTION_UPDATE_STATE( 600 EXPECT_ACTION_UPDATE_STATE(
599 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 601 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE);
600 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 602 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
601 state.OnBeginImplFrameIdle(); 603 state.OnBeginImplFrameIdle();
602 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 604 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
603 } 605 }
604 606
605 EXPECT_TRUE(state.BeginFrameNeeded()); 607 EXPECT_TRUE(state.BeginFrameNeeded());
606 EXPECT_TRUE(state.RedrawPending()); 608 EXPECT_TRUE(state.RedrawPending());
607 // But the commit is ongoing. 609 // But the commit is ongoing.
608 EXPECT_TRUE(state.CommitPending()); 610 EXPECT_TRUE(state.CommitPending());
609 EXPECT_TRUE(state.ForcedRedrawState() == 611 EXPECT_TRUE(state.ForcedRedrawState() ==
610 SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_COMMIT); 612 SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_COMMIT);
611 613
612 // After failing additional draws, we should still be in a forced 614 // After failing additional draws, we should still be in a forced
613 // redraw, but not back in IDLE. 615 // redraw, but not back in IDLE.
614 for (int i = 0; i < draw_limit; ++i) { 616 for (int i = 0; i < draw_limit; ++i) {
615 state.SetNeedsRedraw(true); 617 state.SetNeedsRedraw(true);
616 state.OnBeginImplFrame(); 618 state.OnBeginImplFrame();
617 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 619 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
618 state.OnBeginImplFrameDeadline(); 620 state.OnBeginImplFrameDeadline();
619 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 621 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
620 EXPECT_ACTION_UPDATE_STATE( 622 EXPECT_ACTION_UPDATE_STATE(
621 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 623 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE);
622 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 624 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
623 state.OnBeginImplFrameIdle(); 625 state.OnBeginImplFrameIdle();
624 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 626 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
625 } 627 }
626 EXPECT_TRUE(state.RedrawPending()); 628 EXPECT_TRUE(state.RedrawPending());
627 EXPECT_TRUE(state.ForcedRedrawState() == 629 EXPECT_TRUE(state.ForcedRedrawState() ==
628 SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_COMMIT); 630 SchedulerStateMachine::FORCED_REDRAW_STATE_WAITING_FOR_COMMIT);
629 } 631 }
630 632
631 TEST(SchedulerStateMachineTest, TestFailedDrawIsRetriedInNextBeginImplFrame) { 633 TEST(SchedulerStateMachineTest, TestFailedDrawIsRetriedInNextBeginImplFrame) {
632 SchedulerSettings default_scheduler_settings; 634 SchedulerSettings default_scheduler_settings;
633 StateMachine state(default_scheduler_settings); 635 StateMachine state(default_scheduler_settings);
634 SET_UP_STATE(state) 636 SET_UP_STATE(state)
635 637
636 // Start a draw. 638 // Start a draw.
637 state.SetNeedsRedraw(true); 639 state.SetNeedsRedraw(true);
638 EXPECT_TRUE(state.BeginFrameNeeded()); 640 EXPECT_TRUE(state.BeginFrameNeeded());
639 state.OnBeginImplFrame(); 641 state.OnBeginImplFrame();
640 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 642 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
641 state.OnBeginImplFrameDeadline(); 643 state.OnBeginImplFrameDeadline();
642 EXPECT_TRUE(state.RedrawPending()); 644 EXPECT_TRUE(state.RedrawPending());
643 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS); 645 state.SetDrawResultForTest(DRAW_ABORTED_CHECKERBOARD_ANIMATIONS);
644 EXPECT_ACTION_UPDATE_STATE( 646 EXPECT_ACTION_UPDATE_STATE(
645 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 647 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE);
646 648
647 // Failing the draw for animation checkerboards makes us require a commit. 649 // Failing the draw for animation checkerboards makes us require a commit.
648 EXPECT_ACTION_UPDATE_STATE( 650 EXPECT_ACTION_UPDATE_STATE(
649 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 651 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
650 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 652 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
651 EXPECT_TRUE(state.RedrawPending()); 653 EXPECT_TRUE(state.RedrawPending());
652 654
653 // We should not be trying to draw again now, but we have a commit pending. 655 // We should not be trying to draw again now, but we have a commit pending.
654 EXPECT_TRUE(state.BeginFrameNeeded()); 656 EXPECT_TRUE(state.BeginFrameNeeded());
655 state.OnBeginImplFrame(); 657 state.OnBeginImplFrame();
656 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 658 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
657 659
658 // We should try to draw again at the end of the next BeginImplFrame on 660 // We should try to draw again at the end of the next BeginImplFrame on
659 // the impl thread. 661 // the impl thread.
660 state.OnBeginImplFrameDeadline(); 662 state.OnBeginImplFrameDeadline();
661 state.SetDrawResultForTest(DRAW_SUCCESS); 663 state.SetDrawResultForTest(DRAW_SUCCESS);
662 EXPECT_ACTION_UPDATE_STATE( 664 EXPECT_ACTION_UPDATE_STATE(
663 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 665 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE);
664 state.DidSwapBuffers(); 666 state.DidSubmitCompositorFrame();
665 state.DidSwapBuffersComplete(); 667 state.DidReceiveCompositorFrameAck();
666 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 668 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
667 } 669 }
668 670
669 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) { 671 TEST(SchedulerStateMachineTest, TestDoestDrawTwiceInSameFrame) {
670 SchedulerSettings default_scheduler_settings; 672 SchedulerSettings default_scheduler_settings;
671 StateMachine state(default_scheduler_settings); 673 StateMachine state(default_scheduler_settings);
672 SET_UP_STATE(state) 674 SET_UP_STATE(state)
673 state.SetNeedsRedraw(true); 675 state.SetNeedsRedraw(true);
674 676
675 // Draw the first frame. 677 // Draw the first frame.
676 EXPECT_TRUE(state.BeginFrameNeeded()); 678 EXPECT_TRUE(state.BeginFrameNeeded());
677 state.OnBeginImplFrame(); 679 state.OnBeginImplFrame();
678 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 680 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
679 681
680 state.OnBeginImplFrameDeadline(); 682 state.OnBeginImplFrameDeadline();
681 EXPECT_ACTION_UPDATE_STATE( 683 EXPECT_ACTION_UPDATE_STATE(
682 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 684 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE);
683 state.DidSwapBuffers(); 685 state.DidSubmitCompositorFrame();
684 state.DidSwapBuffersComplete(); 686 state.DidReceiveCompositorFrameAck();
685 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 687 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
686 688
687 // Before the next BeginImplFrame, set needs redraw again. 689 // Before the next BeginImplFrame, set needs redraw again.
688 // This should not redraw until the next BeginImplFrame. 690 // This should not redraw until the next BeginImplFrame.
689 state.SetNeedsRedraw(true); 691 state.SetNeedsRedraw(true);
690 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 692 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
691 693
692 // Move to another frame. This should now draw. 694 // Move to another frame. This should now draw.
693 EXPECT_TRUE(state.BeginFrameNeeded()); 695 EXPECT_TRUE(state.BeginFrameNeeded());
694 state.OnBeginImplFrame(); 696 state.OnBeginImplFrame();
695 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 697 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
696 state.OnBeginImplFrameDeadline(); 698 state.OnBeginImplFrameDeadline();
697 EXPECT_ACTION_UPDATE_STATE( 699 EXPECT_ACTION_UPDATE_STATE(
698 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 700 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE);
699 state.DidSwapBuffers(); 701 state.DidSubmitCompositorFrame();
700 state.DidSwapBuffersComplete(); 702 state.DidReceiveCompositorFrameAck();
701 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 703 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
702 704
703 // We just swapped, so we should proactively request another BeginImplFrame. 705 // We just submitted, so we should proactively request another BeginImplFrame.
704 EXPECT_TRUE(state.BeginFrameNeeded()); 706 EXPECT_TRUE(state.BeginFrameNeeded());
705 } 707 }
706 708
707 TEST(SchedulerStateMachineTest, TestNextActionDrawsOnBeginImplFrame) { 709 TEST(SchedulerStateMachineTest, TestNextActionDrawsOnBeginImplFrame) {
708 SchedulerSettings default_scheduler_settings; 710 SchedulerSettings default_scheduler_settings;
709 711
710 // When not in BeginImplFrame deadline, or in BeginImplFrame deadline 712 // When not in BeginImplFrame deadline, or in BeginImplFrame deadline
711 // but not visible, don't draw. 713 // but not visible, don't draw.
712 size_t num_begin_main_frame_states = 714 size_t num_begin_main_frame_states =
713 sizeof(begin_main_frame_states) / 715 sizeof(begin_main_frame_states) /
(...skipping 10 matching lines...) Expand all
724 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 726 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
725 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 727 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
726 state.SetBeginMainFrameState(begin_main_frame_states[i]); 728 state.SetBeginMainFrameState(begin_main_frame_states[i]);
727 state.SetBeginImplFrameState(all_begin_impl_frame_states[j]); 729 state.SetBeginImplFrameState(all_begin_impl_frame_states[j]);
728 bool visible = 730 bool visible =
729 (all_begin_impl_frame_states[j] != 731 (all_begin_impl_frame_states[j] !=
730 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); 732 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE);
731 state.SetVisible(visible); 733 state.SetVisible(visible);
732 734
733 // Case 1: needs_begin_main_frame=false 735 // Case 1: needs_begin_main_frame=false
734 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 736 EXPECT_NE(
735 state.NextAction()); 737 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE,
738 state.NextAction());
736 739
737 // Case 2: needs_begin_main_frame=true 740 // Case 2: needs_begin_main_frame=true
738 state.SetNeedsBeginMainFrame(); 741 state.SetNeedsBeginMainFrame();
739 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 742 EXPECT_NE(
740 state.NextAction()) 743 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE,
744 state.NextAction())
741 << state.AsValue()->ToString(); 745 << state.AsValue()->ToString();
742 } 746 }
743 } 747 }
744 748
745 // When in BeginImplFrame deadline we should always draw for SetNeedsRedraw 749 // 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. 750 // 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) { 751 for (size_t i = 0; i < num_begin_main_frame_states; ++i) {
748 StateMachine state(default_scheduler_settings); 752 StateMachine state(default_scheduler_settings);
749 state.SetVisible(true); 753 state.SetVisible(true);
750 EXPECT_ACTION_UPDATE_STATE( 754 EXPECT_ACTION_UPDATE_STATE(
751 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 755 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
752 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 756 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
753 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 757 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
754 state.SetCanDraw(true); 758 state.SetCanDraw(true);
755 state.SetBeginMainFrameState(begin_main_frame_states[i]); 759 state.SetBeginMainFrameState(begin_main_frame_states[i]);
756 state.SetBeginImplFrameState( 760 state.SetBeginImplFrameState(
757 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); 761 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE);
758 762
759 state.SetNeedsRedraw(true); 763 state.SetNeedsRedraw(true);
760 764
761 SchedulerStateMachine::Action expected_action; 765 SchedulerStateMachine::Action expected_action;
762 if (begin_main_frame_states[i] == 766 if (begin_main_frame_states[i] ==
763 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT) { 767 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT) {
764 expected_action = SchedulerStateMachine::ACTION_COMMIT; 768 expected_action = SchedulerStateMachine::ACTION_COMMIT;
765 } else { 769 } else {
766 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE; 770 expected_action =
771 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE;
767 } 772 }
768 773
769 // Case 1: needs_begin_main_frame=false. 774 // Case 1: needs_begin_main_frame=false.
770 EXPECT_ACTION(expected_action); 775 EXPECT_ACTION(expected_action);
771 776
772 // Case 2: needs_begin_main_frame=true. 777 // Case 2: needs_begin_main_frame=true.
773 state.SetNeedsBeginMainFrame(); 778 state.SetNeedsBeginMainFrame();
774 EXPECT_ACTION(expected_action); 779 EXPECT_ACTION(expected_action);
775 } 780 }
776 } 781 }
(...skipping 15 matching lines...) Expand all
792 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 797 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
793 state.SetBeginMainFrameState(begin_main_frame_states[i]); 798 state.SetBeginMainFrameState(begin_main_frame_states[i]);
794 state.SetVisible(false); 799 state.SetVisible(false);
795 state.SetNeedsRedraw(true); 800 state.SetNeedsRedraw(true);
796 if (j == 1) { 801 if (j == 1) {
797 state.SetBeginImplFrameState( 802 state.SetBeginImplFrameState(
798 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); 803 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE);
799 } 804 }
800 805
801 // Case 1: needs_begin_main_frame=false. 806 // Case 1: needs_begin_main_frame=false.
802 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 807 EXPECT_NE(
803 state.NextAction()); 808 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE,
809 state.NextAction());
804 810
805 // Case 2: needs_begin_main_frame=true. 811 // Case 2: needs_begin_main_frame=true.
806 state.SetNeedsBeginMainFrame(); 812 state.SetNeedsBeginMainFrame();
807 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 813 EXPECT_NE(
808 state.NextAction()) 814 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE,
815 state.NextAction())
809 << state.AsValue()->ToString(); 816 << state.AsValue()->ToString();
810 } 817 }
811 } 818 }
812 } 819 }
813 820
814 TEST(SchedulerStateMachineTest, TestCanRedraw_StopsDraw) { 821 TEST(SchedulerStateMachineTest, TestCanRedraw_StopsDraw) {
815 SchedulerSettings default_scheduler_settings; 822 SchedulerSettings default_scheduler_settings;
816 823
817 size_t num_begin_main_frame_states = 824 size_t num_begin_main_frame_states =
818 sizeof(begin_main_frame_states) / 825 sizeof(begin_main_frame_states) /
819 sizeof(SchedulerStateMachine::BeginMainFrameState); 826 sizeof(SchedulerStateMachine::BeginMainFrameState);
820 for (size_t i = 0; i < num_begin_main_frame_states; ++i) { 827 for (size_t i = 0; i < num_begin_main_frame_states; ++i) {
821 // There shouldn't be any drawing regardless of BeginImplFrame. 828 // There shouldn't be any drawing regardless of BeginImplFrame.
822 for (size_t j = 0; j < 2; ++j) { 829 for (size_t j = 0; j < 2; ++j) {
823 StateMachine state(default_scheduler_settings); 830 StateMachine state(default_scheduler_settings);
824 state.SetVisible(true); 831 state.SetVisible(true);
825 EXPECT_ACTION_UPDATE_STATE( 832 EXPECT_ACTION_UPDATE_STATE(
826 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 833 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
827 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 834 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
828 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 835 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
829 state.SetBeginMainFrameState(begin_main_frame_states[i]); 836 state.SetBeginMainFrameState(begin_main_frame_states[i]);
830 state.SetVisible(false); 837 state.SetVisible(false);
831 state.SetNeedsRedraw(true); 838 state.SetNeedsRedraw(true);
832 if (j == 1) 839 if (j == 1)
833 state.OnBeginImplFrame(); 840 state.OnBeginImplFrame();
834 841
835 state.SetCanDraw(false); 842 state.SetCanDraw(false);
836 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 843 EXPECT_NE(
837 state.NextAction()); 844 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE,
845 state.NextAction());
838 } 846 }
839 } 847 }
840 } 848 }
841 849
842 TEST(SchedulerStateMachineTest, 850 TEST(SchedulerStateMachineTest,
843 TestCanRedrawWithWaitingForFirstDrawMakesProgress) { 851 TestCanRedrawWithWaitingForFirstDrawMakesProgress) {
844 SchedulerSettings default_scheduler_settings; 852 SchedulerSettings default_scheduler_settings;
845 StateMachine state(default_scheduler_settings); 853 StateMachine state(default_scheduler_settings);
846 state.SetVisible(true); 854 state.SetVisible(true);
847 EXPECT_ACTION_UPDATE_STATE( 855 EXPECT_ACTION_UPDATE_STATE(
848 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 856 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
849 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 857 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
850 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 858 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
851 859
852 state.SetActiveTreeNeedsFirstDraw(true); 860 state.SetActiveTreeNeedsFirstDraw(true);
853 state.SetNeedsBeginMainFrame(); 861 state.SetNeedsBeginMainFrame();
854 state.SetNeedsRedraw(true); 862 state.SetNeedsRedraw(true);
855 state.SetCanDraw(false); 863 state.SetCanDraw(false);
856 state.OnBeginImplFrame(); 864 state.OnBeginImplFrame();
857 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 865 EXPECT_ACTION_UPDATE_STATE(
866 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_ABORT);
858 EXPECT_ACTION_UPDATE_STATE( 867 EXPECT_ACTION_UPDATE_STATE(
859 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 868 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
860 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 869 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
861 state.NotifyBeginMainFrameStarted(); 870 state.NotifyBeginMainFrameStarted();
862 state.NotifyReadyToCommit(); 871 state.NotifyReadyToCommit();
863 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 872 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
864 state.NotifyReadyToActivate(); 873 state.NotifyReadyToActivate();
865 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 874 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
866 state.OnBeginImplFrameDeadline(); 875 state.OnBeginImplFrameDeadline();
867 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 876 EXPECT_ACTION_UPDATE_STATE(
877 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_ABORT);
868 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 878 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
869 } 879 }
870 880
871 TEST(SchedulerStateMachineTest, TestSetNeedsBeginMainFrameIsNotLost) { 881 TEST(SchedulerStateMachineTest, TestSetNeedsBeginMainFrameIsNotLost) {
872 SchedulerSettings scheduler_settings; 882 SchedulerSettings scheduler_settings;
873 StateMachine state(scheduler_settings); 883 StateMachine state(scheduler_settings);
874 SET_UP_STATE(state) 884 SET_UP_STATE(state)
875 state.SetNeedsBeginMainFrame(); 885 state.SetNeedsBeginMainFrame();
876 886
877 EXPECT_TRUE(state.BeginFrameNeeded()); 887 EXPECT_TRUE(state.BeginFrameNeeded());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 state.NotifyReadyToActivate(); 927 state.NotifyReadyToActivate();
918 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 928 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
919 EXPECT_ACTION_UPDATE_STATE( 929 EXPECT_ACTION_UPDATE_STATE(
920 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 930 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
921 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 931 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
922 932
923 state.OnBeginImplFrameDeadline(); 933 state.OnBeginImplFrameDeadline();
924 934
925 EXPECT_TRUE(state.active_tree_needs_first_draw()); 935 EXPECT_TRUE(state.active_tree_needs_first_draw());
926 EXPECT_ACTION_UPDATE_STATE( 936 EXPECT_ACTION_UPDATE_STATE(
927 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 937 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE);
928 state.DidSwapBuffers(); 938 state.DidSubmitCompositorFrame();
929 state.DidSwapBuffersComplete(); 939 state.DidReceiveCompositorFrameAck();
930 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 940 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
931 } 941 }
932 942
933 TEST(SchedulerStateMachineTest, TestFullCycle) { 943 TEST(SchedulerStateMachineTest, TestFullCycle) {
934 SchedulerSettings default_scheduler_settings; 944 SchedulerSettings default_scheduler_settings;
935 StateMachine state(default_scheduler_settings); 945 StateMachine state(default_scheduler_settings);
936 SET_UP_STATE(state) 946 SET_UP_STATE(state)
937 947
938 // Start clean and set commit. 948 // Start clean and set commit.
939 state.SetNeedsBeginMainFrame(); 949 state.SetNeedsBeginMainFrame();
(...skipping 20 matching lines...) Expand all
960 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 970 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
961 EXPECT_TRUE(state.active_tree_needs_first_draw()); 971 EXPECT_TRUE(state.active_tree_needs_first_draw());
962 EXPECT_TRUE(state.needs_redraw()); 972 EXPECT_TRUE(state.needs_redraw());
963 973
964 // Expect to do nothing until BeginImplFrame deadline 974 // Expect to do nothing until BeginImplFrame deadline
965 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 975 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
966 976
967 // At BeginImplFrame deadline, draw. 977 // At BeginImplFrame deadline, draw.
968 state.OnBeginImplFrameDeadline(); 978 state.OnBeginImplFrameDeadline();
969 EXPECT_ACTION_UPDATE_STATE( 979 EXPECT_ACTION_UPDATE_STATE(
970 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 980 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE);
971 state.DidSwapBuffers(); 981 state.DidSubmitCompositorFrame();
972 state.DidSwapBuffersComplete(); 982 state.DidReceiveCompositorFrameAck();
973 983
974 // Should be synchronized, no draw needed, no action needed. 984 // Should be synchronized, no draw needed, no action needed.
975 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 985 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
976 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 986 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
977 EXPECT_FALSE(state.needs_redraw()); 987 EXPECT_FALSE(state.needs_redraw());
978 } 988 }
979 989
980 TEST(SchedulerStateMachineTest, CommitWithoutDrawWithPendingTree) { 990 TEST(SchedulerStateMachineTest, CommitWithoutDrawWithPendingTree) {
981 SchedulerSettings default_scheduler_settings; 991 SchedulerSettings default_scheduler_settings;
982 StateMachine state(default_scheduler_settings); 992 StateMachine state(default_scheduler_settings);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1128 // Can't BeginMainFrame yet since last commit hasn't been drawn yet. 1138 // Can't BeginMainFrame yet since last commit hasn't been drawn yet.
1129 state.SetNeedsBeginMainFrame(); 1139 state.SetNeedsBeginMainFrame();
1130 state.OnBeginImplFrame(); 1140 state.OnBeginImplFrame();
1131 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1141 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1132 1142
1133 // Now call ready to draw which will allow the draw to happen and 1143 // Now call ready to draw which will allow the draw to happen and
1134 // BeginMainFrame to be sent. 1144 // BeginMainFrame to be sent.
1135 state.NotifyReadyToDraw(); 1145 state.NotifyReadyToDraw();
1136 state.OnBeginImplFrameDeadline(); 1146 state.OnBeginImplFrameDeadline();
1137 EXPECT_ACTION_UPDATE_STATE( 1147 EXPECT_ACTION_UPDATE_STATE(
1138 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1148 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE);
1139 // Swap throttled from this point. 1149 // Submit throttled from this point.
1140 state.DidSwapBuffers(); 1150 state.DidSubmitCompositorFrame();
1141 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1151 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1142 1152
1143 // Can't BeginMainFrame yet since we're swap throttled. 1153 // Can't BeginMainFrame yet since we're submit-frame throttled.
1144 state.OnBeginImplFrame(); 1154 state.OnBeginImplFrame();
1145 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1155 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1146 1156
1147 // Swap ack unblocks BeginMainFrame. 1157 // CompositorFrameAck unblocks BeginMainFrame.
1148 state.DidSwapBuffersComplete(); 1158 state.DidReceiveCompositorFrameAck();
1149 EXPECT_ACTION_UPDATE_STATE( 1159 EXPECT_ACTION_UPDATE_STATE(
1150 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1160 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1151 state.NotifyBeginMainFrameStarted(); 1161 state.NotifyBeginMainFrameStarted();
1152 state.NotifyReadyToCommit(); 1162 state.NotifyReadyToCommit();
1153 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1163 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1154 state.NotifyReadyToActivate(); 1164 state.NotifyReadyToActivate();
1155 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1165 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1156 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1166 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1157 1167
1158 // Draw the newly activated tree. 1168 // Draw the newly activated tree.
1159 state.NotifyReadyToDraw(); 1169 state.NotifyReadyToDraw();
1160 state.OnBeginImplFrameDeadline(); 1170 state.OnBeginImplFrameDeadline();
1161 EXPECT_ACTION_UPDATE_STATE( 1171 EXPECT_ACTION_UPDATE_STATE(
1162 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1172 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE);
1163 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1173 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1164 } 1174 }
1165 1175
1166 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) { 1176 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) {
1167 SchedulerSettings default_scheduler_settings; 1177 SchedulerSettings default_scheduler_settings;
1168 StateMachine state(default_scheduler_settings); 1178 StateMachine state(default_scheduler_settings);
1169 SET_UP_STATE(state) 1179 SET_UP_STATE(state)
1170 1180
1171 // Start clean and set commit. 1181 // Start clean and set commit.
1172 state.SetNeedsBeginMainFrame(); 1182 state.SetNeedsBeginMainFrame();
(...skipping 22 matching lines...) Expand all
1195 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1205 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1196 EXPECT_TRUE(state.active_tree_needs_first_draw()); 1206 EXPECT_TRUE(state.active_tree_needs_first_draw());
1197 EXPECT_TRUE(state.needs_redraw()); 1207 EXPECT_TRUE(state.needs_redraw());
1198 1208
1199 // Expect to do nothing until BeginImplFrame deadline. 1209 // Expect to do nothing until BeginImplFrame deadline.
1200 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1210 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1201 1211
1202 // At BeginImplFrame deadline, draw. 1212 // At BeginImplFrame deadline, draw.
1203 state.OnBeginImplFrameDeadline(); 1213 state.OnBeginImplFrameDeadline();
1204 EXPECT_ACTION_UPDATE_STATE( 1214 EXPECT_ACTION_UPDATE_STATE(
1205 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1215 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE);
1206 state.DidSwapBuffers(); 1216 state.DidSubmitCompositorFrame();
1207 state.DidSwapBuffersComplete(); 1217 state.DidReceiveCompositorFrameAck();
1208 1218
1209 // Should be synchronized, no draw needed, no action needed. 1219 // Should be synchronized, no draw needed, no action needed.
1210 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1220 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1211 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE); 1221 EXPECT_MAIN_FRAME_STATE(SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_IDLE);
1212 EXPECT_FALSE(state.needs_redraw()); 1222 EXPECT_FALSE(state.needs_redraw());
1213 1223
1214 // Next BeginImplFrame should initiate second commit. 1224 // Next BeginImplFrame should initiate second commit.
1215 state.OnBeginImplFrame(); 1225 state.OnBeginImplFrame();
1216 EXPECT_ACTION_UPDATE_STATE( 1226 EXPECT_ACTION_UPDATE_STATE(
1217 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1227 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1480 EXPECT_EQ(state.compositor_frame_sink_state(), 1490 EXPECT_EQ(state.compositor_frame_sink_state(),
1481 SchedulerStateMachine::COMPOSITOR_FRAME_SINK_ACTIVE); 1491 SchedulerStateMachine::COMPOSITOR_FRAME_SINK_ACTIVE);
1482 1492
1483 // Finishing the first commit after initializing an CompositorFrameSink should 1493 // Finishing the first commit after initializing an CompositorFrameSink should
1484 // automatically cause a redraw. 1494 // automatically cause a redraw.
1485 EXPECT_TRUE(state.RedrawPending()); 1495 EXPECT_TRUE(state.RedrawPending());
1486 state.OnBeginImplFrame(); 1496 state.OnBeginImplFrame();
1487 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1497 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1488 state.OnBeginImplFrameDeadline(); 1498 state.OnBeginImplFrameDeadline();
1489 EXPECT_ACTION_UPDATE_STATE( 1499 EXPECT_ACTION_UPDATE_STATE(
1490 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1500 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE);
1491 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1501 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1492 EXPECT_FALSE(state.RedrawPending()); 1502 EXPECT_FALSE(state.RedrawPending());
1493 1503
1494 // Next frame as no work to do. 1504 // Next frame as no work to do.
1495 state.OnBeginImplFrame(); 1505 state.OnBeginImplFrame();
1496 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1506 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1497 state.OnBeginImplFrameDeadline(); 1507 state.OnBeginImplFrameDeadline();
1498 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1508 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1499 1509
1500 // Once the context is recreated, whether we draw should be based on 1510 // Once the context is recreated, whether we draw should be based on
1501 // SetCanDraw if waiting on first draw after activate. 1511 // SetCanDraw if waiting on first draw after activate.
1502 state.SetNeedsRedraw(true); 1512 state.SetNeedsRedraw(true);
1503 state.OnBeginImplFrame(); 1513 state.OnBeginImplFrame();
1504 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1514 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1505 state.OnBeginImplFrameDeadline(); 1515 state.OnBeginImplFrameDeadline();
1506 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1516 EXPECT_ACTION(
1517 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE);
1507 state.SetCanDraw(false); 1518 state.SetCanDraw(false);
1508 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); 1519 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1509 state.SetCanDraw(true); 1520 state.SetCanDraw(true);
1510 EXPECT_ACTION_UPDATE_STATE( 1521 EXPECT_ACTION_UPDATE_STATE(
1511 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1522 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE);
1512 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1523 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1513 1524
1514 // Once the context is recreated, whether we draw should be based on 1525 // Once the context is recreated, whether we draw should be based on
1515 // SetCanDraw if waiting on first draw after activate. 1526 // SetCanDraw if waiting on first draw after activate.
1516 state.SetNeedsRedraw(true); 1527 state.SetNeedsRedraw(true);
1517 state.SetNeedsBeginMainFrame(); 1528 state.SetNeedsBeginMainFrame();
1518 state.OnBeginImplFrame(); 1529 state.OnBeginImplFrame();
1519 EXPECT_ACTION_UPDATE_STATE( 1530 EXPECT_ACTION_UPDATE_STATE(
1520 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1531 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1521 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1532 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1522 // Activate so we need the first draw 1533 // Activate so we need the first draw
1523 state.NotifyBeginMainFrameStarted(); 1534 state.NotifyBeginMainFrameStarted();
1524 state.NotifyReadyToCommit(); 1535 state.NotifyReadyToCommit();
1525 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1536 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1526 state.NotifyReadyToActivate(); 1537 state.NotifyReadyToActivate();
1527 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1538 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1528 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1539 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1529 EXPECT_TRUE(state.active_tree_needs_first_draw()); 1540 EXPECT_TRUE(state.active_tree_needs_first_draw());
1530 EXPECT_TRUE(state.needs_redraw()); 1541 EXPECT_TRUE(state.needs_redraw());
1531 1542
1532 state.OnBeginImplFrameDeadline(); 1543 state.OnBeginImplFrameDeadline();
1533 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1544 EXPECT_ACTION(
1545 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE);
1534 state.SetCanDraw(false); 1546 state.SetCanDraw(false);
1535 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1547 EXPECT_ACTION(SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_ABORT);
1536 state.SetCanDraw(true); 1548 state.SetCanDraw(true);
1537 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1549 EXPECT_ACTION(
1550 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE);
1538 } 1551 }
1539 1552
1540 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) { 1553 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) {
1541 SchedulerSettings scheduler_settings; 1554 SchedulerSettings scheduler_settings;
1542 StateMachine state(scheduler_settings); 1555 StateMachine state(scheduler_settings);
1543 SET_UP_STATE(state) 1556 SET_UP_STATE(state)
1544 1557
1545 // Get a commit in flight. 1558 // Get a commit in flight.
1546 state.SetNeedsBeginMainFrame(); 1559 state.SetNeedsBeginMainFrame();
1547 1560
1548 // Set damage and expect a draw. 1561 // Set damage and expect a draw.
1549 state.SetNeedsRedraw(true); 1562 state.SetNeedsRedraw(true);
1550 state.OnBeginImplFrame(); 1563 state.OnBeginImplFrame();
1551 EXPECT_ACTION_UPDATE_STATE( 1564 EXPECT_ACTION_UPDATE_STATE(
1552 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1565 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1553 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1566 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1554 state.OnBeginImplFrameDeadline(); 1567 state.OnBeginImplFrameDeadline();
1555 EXPECT_ACTION_UPDATE_STATE( 1568 EXPECT_ACTION_UPDATE_STATE(
1556 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1569 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE);
1557 state.DidSwapBuffers(); 1570 state.DidSubmitCompositorFrame();
1558 state.DidSwapBuffersComplete(); 1571 state.DidReceiveCompositorFrameAck();
1559 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1572 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1560 1573
1561 // Cause a lost context while the BeginMainFrame is in flight. 1574 // Cause a lost context while the BeginMainFrame is in flight.
1562 state.DidLoseCompositorFrameSink(); 1575 state.DidLoseCompositorFrameSink();
1563 1576
1564 // Ask for another draw. Expect nothing happens. 1577 // Ask for another draw. Expect nothing happens.
1565 state.SetNeedsRedraw(true); 1578 state.SetNeedsRedraw(true);
1566 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); 1579 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1567 1580
1568 // Finish the frame, commit and activate. 1581 // Finish the frame, commit and activate.
1569 state.NotifyBeginMainFrameStarted(); 1582 state.NotifyBeginMainFrameStarted();
1570 state.NotifyReadyToCommit(); 1583 state.NotifyReadyToCommit();
1571 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1584 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1572 state.NotifyReadyToActivate(); 1585 state.NotifyReadyToActivate();
1573 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1586 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1574 1587
1575 // We will abort the draw when the CompositorFrameSink is lost if we are 1588 // We will abort the draw when the CompositorFrameSink is lost if we are
1576 // waiting for the first draw to unblock the main thread. 1589 // waiting for the first draw to unblock the main thread.
1577 EXPECT_TRUE(state.active_tree_needs_first_draw()); 1590 EXPECT_TRUE(state.active_tree_needs_first_draw());
1578 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1591 EXPECT_ACTION_UPDATE_STATE(
1592 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_ABORT);
1579 1593
1580 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE 1594 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE
1581 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); 1595 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
1582 EXPECT_ACTION( 1596 EXPECT_ACTION(
1583 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 1597 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
1584 1598
1585 state.OnBeginImplFrame(); 1599 state.OnBeginImplFrame();
1586 EXPECT_IMPL_FRAME_STATE( 1600 EXPECT_IMPL_FRAME_STATE(
1587 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME); 1601 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME);
1588 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); 1602 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
(...skipping 15 matching lines...) Expand all
1604 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1618 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1605 1619
1606 // Set damage and expect a draw. 1620 // Set damage and expect a draw.
1607 state.SetNeedsRedraw(true); 1621 state.SetNeedsRedraw(true);
1608 state.OnBeginImplFrame(); 1622 state.OnBeginImplFrame();
1609 EXPECT_ACTION_UPDATE_STATE( 1623 EXPECT_ACTION_UPDATE_STATE(
1610 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1624 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1611 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1625 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1612 state.OnBeginImplFrameDeadline(); 1626 state.OnBeginImplFrameDeadline();
1613 EXPECT_ACTION_UPDATE_STATE( 1627 EXPECT_ACTION_UPDATE_STATE(
1614 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1628 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE);
1615 state.DidSwapBuffers(); 1629 state.DidSubmitCompositorFrame();
1616 state.DidSwapBuffersComplete(); 1630 state.DidReceiveCompositorFrameAck();
1617 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1631 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1618 1632
1619 // Cause a lost context while the BeginMainFrame is in flight. 1633 // Cause a lost context while the BeginMainFrame is in flight.
1620 state.DidLoseCompositorFrameSink(); 1634 state.DidLoseCompositorFrameSink();
1621 1635
1622 // Ask for another draw and also set needs commit. Expect nothing happens. 1636 // Ask for another draw and also set needs commit. Expect nothing happens.
1623 state.SetNeedsRedraw(true); 1637 state.SetNeedsRedraw(true);
1624 state.SetNeedsBeginMainFrame(); 1638 state.SetNeedsBeginMainFrame();
1625 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1639 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1626 1640
1627 // Finish the frame, and commit and activate. 1641 // Finish the frame, and commit and activate.
1628 state.NotifyBeginMainFrameStarted(); 1642 state.NotifyBeginMainFrameStarted();
1629 state.NotifyReadyToCommit(); 1643 state.NotifyReadyToCommit();
1630 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1644 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1631 state.NotifyReadyToActivate(); 1645 state.NotifyReadyToActivate();
1632 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1646 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1633 EXPECT_TRUE(state.active_tree_needs_first_draw()); 1647 EXPECT_TRUE(state.active_tree_needs_first_draw());
1634 1648
1635 // Because the CompositorFrameSink is missing, we expect the draw to abort. 1649 // Because the CompositorFrameSink is missing, we expect the draw to abort.
1636 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1650 EXPECT_ACTION_UPDATE_STATE(
1651 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_ABORT);
1637 1652
1638 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE 1653 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE
1639 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); 1654 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
1640 EXPECT_ACTION( 1655 EXPECT_ACTION(
1641 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 1656 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
1642 1657
1643 state.OnBeginImplFrame(); 1658 state.OnBeginImplFrame();
1644 EXPECT_IMPL_FRAME_STATE( 1659 EXPECT_IMPL_FRAME_STATE(
1645 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME); 1660 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME);
1646 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); 1661 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
(...skipping 15 matching lines...) Expand all
1662 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1677 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1663 state.NotifyBeginMainFrameStarted(); 1678 state.NotifyBeginMainFrameStarted();
1664 state.NotifyReadyToCommit(); 1679 state.NotifyReadyToCommit();
1665 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1680 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1666 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1681 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1667 state.NotifyReadyToActivate(); 1682 state.NotifyReadyToActivate();
1668 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1683 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1669 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1684 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1670 state.OnBeginImplFrameDeadline(); 1685 state.OnBeginImplFrameDeadline();
1671 EXPECT_ACTION_UPDATE_STATE( 1686 EXPECT_ACTION_UPDATE_STATE(
1672 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1687 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE);
1673 state.DidSwapBuffers(); 1688 state.DidSubmitCompositorFrame();
1674 state.DidSwapBuffersComplete(); 1689 state.DidReceiveCompositorFrameAck();
1675 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1690 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1676 } 1691 }
1677 1692
1678 TEST(SchedulerStateMachineTest, 1693 TEST(SchedulerStateMachineTest,
1679 DontDrawBeforeCommitAfterLostCompositorFrameSink) { 1694 DontDrawBeforeCommitAfterLostCompositorFrameSink) {
1680 SchedulerSettings default_scheduler_settings; 1695 SchedulerSettings default_scheduler_settings;
1681 StateMachine state(default_scheduler_settings); 1696 StateMachine state(default_scheduler_settings);
1682 SET_UP_STATE(state) 1697 SET_UP_STATE(state)
1683 1698
1684 state.SetNeedsRedraw(true); 1699 state.SetNeedsRedraw(true);
(...skipping 23 matching lines...) Expand all
1708 state.DidLoseCompositorFrameSink(); 1723 state.DidLoseCompositorFrameSink();
1709 1724
1710 state.NotifyBeginMainFrameStarted(); 1725 state.NotifyBeginMainFrameStarted();
1711 state.NotifyReadyToCommit(); 1726 state.NotifyReadyToCommit();
1712 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1727 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1713 1728
1714 EXPECT_TRUE(state.PendingActivationsShouldBeForced()); 1729 EXPECT_TRUE(state.PendingActivationsShouldBeForced());
1715 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1730 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1716 1731
1717 EXPECT_TRUE(state.PendingDrawsShouldBeAborted()); 1732 EXPECT_TRUE(state.PendingDrawsShouldBeAborted());
1718 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1733 EXPECT_ACTION_UPDATE_STATE(
1734 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_ABORT);
1719 } 1735 }
1720 1736
1721 TEST(SchedulerStateMachineTest, TestNoBeginFrameNeededWhenInvisible) { 1737 TEST(SchedulerStateMachineTest, TestNoBeginFrameNeededWhenInvisible) {
1722 SchedulerSettings default_scheduler_settings; 1738 SchedulerSettings default_scheduler_settings;
1723 StateMachine state(default_scheduler_settings); 1739 StateMachine state(default_scheduler_settings);
1724 state.SetVisible(true); 1740 state.SetVisible(true);
1725 EXPECT_ACTION_UPDATE_STATE( 1741 EXPECT_ACTION_UPDATE_STATE(
1726 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 1742 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
1727 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1743 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1728 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 1744 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1772 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); 1788 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
1773 state.SetNeedsBeginMainFrame(); 1789 state.SetNeedsBeginMainFrame();
1774 1790
1775 // After the commit completes, activation and draw happen immediately 1791 // After the commit completes, activation and draw happen immediately
1776 // because we are not visible. 1792 // because we are not visible.
1777 state.NotifyBeginMainFrameStarted(); 1793 state.NotifyBeginMainFrameStarted();
1778 state.NotifyReadyToCommit(); 1794 state.NotifyReadyToCommit();
1779 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1795 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1780 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1796 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1781 EXPECT_TRUE(state.active_tree_needs_first_draw()); 1797 EXPECT_TRUE(state.active_tree_needs_first_draw());
1782 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1798 EXPECT_ACTION_UPDATE_STATE(
1799 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_ABORT);
1783 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1800 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1784 } 1801 }
1785 1802
1786 TEST(SchedulerStateMachineTest, 1803 TEST(SchedulerStateMachineTest,
1787 TestFinishCommitWhenCommitInProgressAndBeginFrameSourcePaused) { 1804 TestFinishCommitWhenCommitInProgressAndBeginFrameSourcePaused) {
1788 SchedulerSettings default_scheduler_settings; 1805 SchedulerSettings default_scheduler_settings;
1789 StateMachine state(default_scheduler_settings); 1806 StateMachine state(default_scheduler_settings);
1790 state.SetVisible(true); 1807 state.SetVisible(true);
1791 EXPECT_ACTION_UPDATE_STATE( 1808 EXPECT_ACTION_UPDATE_STATE(
1792 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 1809 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
1793 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1810 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1794 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit(); 1811 state.CreateAndInitializeCompositorFrameSinkWithActivatedCommit();
1795 state.SetBeginFrameSourcePaused(true); 1812 state.SetBeginFrameSourcePaused(true);
1796 state.SetBeginMainFrameState( 1813 state.SetBeginMainFrameState(
1797 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT); 1814 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT);
1798 state.SetNeedsBeginMainFrame(); 1815 state.SetNeedsBeginMainFrame();
1799 1816
1800 // After the commit completes, activation and draw happen immediately 1817 // After the commit completes, activation and draw happen immediately
1801 // because we are not visible. 1818 // because we are not visible.
1802 state.NotifyBeginMainFrameStarted(); 1819 state.NotifyBeginMainFrameStarted();
1803 state.NotifyReadyToCommit(); 1820 state.NotifyReadyToCommit();
1804 EXPECT_TRUE(state.PendingActivationsShouldBeForced()); 1821 EXPECT_TRUE(state.PendingActivationsShouldBeForced());
1805 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1822 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1806 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1823 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1807 EXPECT_TRUE(state.active_tree_needs_first_draw()); 1824 EXPECT_TRUE(state.active_tree_needs_first_draw());
1808 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1825 EXPECT_ACTION_UPDATE_STATE(
1826 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_ABORT);
1809 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1827 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1810 } 1828 }
1811 1829
1812 TEST(SchedulerStateMachineTest, TestInitialActionsWhenContextLost) { 1830 TEST(SchedulerStateMachineTest, TestInitialActionsWhenContextLost) {
1813 SchedulerSettings default_scheduler_settings; 1831 SchedulerSettings default_scheduler_settings;
1814 StateMachine state(default_scheduler_settings); 1832 StateMachine state(default_scheduler_settings);
1815 SET_UP_STATE(state) 1833 SET_UP_STATE(state)
1816 state.SetNeedsBeginMainFrame(); 1834 state.SetNeedsBeginMainFrame();
1817 state.DidLoseCompositorFrameSink(); 1835 state.DidLoseCompositorFrameSink();
1818 1836
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1952 state.NotifyReadyToActivate(); 1970 state.NotifyReadyToActivate();
1953 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 1971 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1954 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1972 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1955 1973
1956 state.OnBeginImplFrame(); 1974 state.OnBeginImplFrame();
1957 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1975 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1958 1976
1959 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 1977 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
1960 state.OnBeginImplFrameDeadline(); 1978 state.OnBeginImplFrameDeadline();
1961 EXPECT_ACTION_UPDATE_STATE( 1979 EXPECT_ACTION_UPDATE_STATE(
1962 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1980 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE);
1963 state.DidSwapBuffers(); 1981 state.DidSubmitCompositorFrame();
1964 } 1982 }
1965 1983
1966 TEST(SchedulerStateMachineTest, TestImplLatencyTakesPriority) { 1984 TEST(SchedulerStateMachineTest, TestImplLatencyTakesPriority) {
1967 SchedulerSettings default_scheduler_settings; 1985 SchedulerSettings default_scheduler_settings;
1968 StateMachine state(default_scheduler_settings); 1986 StateMachine state(default_scheduler_settings);
1969 SET_UP_STATE(state) 1987 SET_UP_STATE(state)
1970 1988
1971 // This test ensures that impl-draws are prioritized over main thread updates 1989 // This test ensures that impl-draws are prioritized over main thread updates
1972 // in prefer impl latency mode. 1990 // in prefer impl latency mode.
1973 state.SetNeedsRedraw(true); 1991 state.SetNeedsRedraw(true);
1974 state.SetNeedsBeginMainFrame(); 1992 state.SetNeedsBeginMainFrame();
1975 state.OnBeginImplFrame(); 1993 state.OnBeginImplFrame();
1976 EXPECT_ACTION_UPDATE_STATE( 1994 EXPECT_ACTION_UPDATE_STATE(
1977 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1995 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1978 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1996 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1979 1997
1980 // Verify the deadline is not triggered early until we enter 1998 // Verify the deadline is not triggered early until we enter
1981 // prefer impl latency mode. 1999 // prefer impl latency mode.
1982 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 2000 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
1983 state.SetTreePrioritiesAndScrollState( 2001 state.SetTreePrioritiesAndScrollState(
1984 SMOOTHNESS_TAKES_PRIORITY, 2002 SMOOTHNESS_TAKES_PRIORITY,
1985 ScrollHandlerState::SCROLL_DOES_NOT_AFFECT_SCROLL_HANDLER); 2003 ScrollHandlerState::SCROLL_DOES_NOT_AFFECT_SCROLL_HANDLER);
1986 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 2004 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
1987 2005
1988 // Trigger the deadline. 2006 // Trigger the deadline.
1989 state.OnBeginImplFrameDeadline(); 2007 state.OnBeginImplFrameDeadline();
1990 EXPECT_ACTION_UPDATE_STATE( 2008 EXPECT_ACTION_UPDATE_STATE(
1991 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 2009 SchedulerStateMachine::ACTION_SUBMIT_COMPOSITOR_FRAME_IF_POSSIBLE);
1992 state.DidSwapBuffers(); 2010 state.DidSubmitCompositorFrame();
1993 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2011 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1994 state.DidSwapBuffersComplete(); 2012 state.DidReceiveCompositorFrameAck();
1995 2013
1996 // Request a new commit and finish the previous one. 2014 // Request a new commit and finish the previous one.
1997 state.SetNeedsBeginMainFrame(); 2015 state.SetNeedsBeginMainFrame();
1998 FinishPreviousCommitAndDrawWithoutExitingDeadline(&state); 2016 FinishPreviousCommitAndDrawWithoutExitingDeadline(&state);
1999 EXPECT_ACTION_UPDATE_STATE( 2017 EXPECT_ACTION_UPDATE_STATE(
2000 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 2018 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
2001 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2019 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2002 state.DidSwapBuffersComplete(); 2020 state.DidReceiveCompositorFrameAck();
2003 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2021 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2004 2022
2005 // Finish the previous commit and draw it. 2023 // Finish the previous commit and draw it.
2006 FinishPreviousCommitAndDrawWithoutExitingDeadline(&state); 2024 FinishPreviousCommitAndDrawWithoutExitingDeadline(&state);
2007 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2025 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2008 2026
2009 // Verify we do not send another BeginMainFrame if was are swap throttled 2027 // Verify we do not send another BeginMainFrame if was are submit-frame
2010 // and did not just swap. 2028 // throttled and did not just submit one.
2011 state.SetNeedsBeginMainFrame(); 2029 state.SetNeedsBeginMainFrame();
2012 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2030 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2013 state.OnBeginImplFrame(); 2031 state.OnBeginImplFrame();
2014 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2032 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2015 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 2033 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
2016 state.OnBeginImplFrameDeadline(); 2034 state.OnBeginImplFrameDeadline();
2017 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 2035 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2018 } 2036 }
2019 2037
2020 TEST(SchedulerStateMachineTest, 2038 TEST(SchedulerStateMachineTest,
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
2171 state.OnBeginImplFrameDeadline(); 2189 state.OnBeginImplFrameDeadline();
2172 state.OnBeginImplFrameIdle(); 2190 state.OnBeginImplFrameIdle();
2173 2191
2174 // The scheduler should begin the CompositorFrameSink creation now. 2192 // The scheduler should begin the CompositorFrameSink creation now.
2175 EXPECT_ACTION_UPDATE_STATE( 2193 EXPECT_ACTION_UPDATE_STATE(
2176 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION); 2194 SchedulerStateMachine::ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION);
2177 } 2195 }
2178 2196
2179 } // namespace 2197 } // namespace
2180 } // namespace cc 2198 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698