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

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

Issue 23907006: cc: Allow sending BeginMainFrame before draw or activation (Closed) Base URL: http://git.chromium.org/chromium/src.git@schedDeadline3
Patch Set: fix typo Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/scheduler/scheduler_state_machine.h" 5 #include "cc/scheduler/scheduler_state_machine.h"
6 6
7 #include "cc/scheduler/scheduler.h" 7 #include "cc/scheduler/scheduler.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 #define EXPECT_ACTION_UPDATE_STATE(action) \ 10 #define EXPECT_ACTION_UPDATE_STATE(action) \
11 EXPECT_EQ(action, state.NextAction()) << *state.AsValue(); \ 11 EXPECT_EQ(action, state.NextAction()) << *state.AsValue(); \
12 if (action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE || \ 12 if (action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE || \
13 action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED) { \ 13 action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED) { \
14 if (SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW == \
15 state.CommitState() && \
16 SchedulerStateMachine::OUTPUT_SURFACE_ACTIVE != \
17 state.output_surface_state()) \
18 return; \
19 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, \ 14 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, \
20 state.begin_impl_frame_state()) \ 15 state.begin_impl_frame_state()) \
21 << *state.AsValue(); \ 16 << *state.AsValue(); \
22 } \ 17 } \
23 state.UpdateState(action); \ 18 state.UpdateState(action); \
24 if (action == SchedulerStateMachine::ACTION_NONE) { \ 19 if (action == SchedulerStateMachine::ACTION_NONE) { \
25 if (state.begin_impl_frame_state() == \ 20 if (state.begin_impl_frame_state() == \
26 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING) \ 21 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING) \
27 state.OnBeginImplFrameDeadlinePending(); \ 22 state.OnBeginImplFrameDeadlinePending(); \
28 if (state.begin_impl_frame_state() == \ 23 if (state.begin_impl_frame_state() == \
29 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) \ 24 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) \
30 state.OnBeginImplFrameIdle(); \ 25 state.OnBeginImplFrameIdle(); \
31 } 26 }
32 27
33 namespace cc { 28 namespace cc {
34 29
35 namespace { 30 namespace {
36 31
37 const SchedulerStateMachine::BeginImplFrameState all_begin_impl_frame_states[] = 32 const SchedulerStateMachine::BeginImplFrameState all_begin_impl_frame_states[] =
38 {SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, 33 {SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE,
39 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING, 34 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING,
40 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME, 35 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME,
41 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, }; 36 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, };
42 37
43 const SchedulerStateMachine::CommitState all_commit_states[] = { 38 const SchedulerStateMachine::CommitState all_commit_states[] = {
44 SchedulerStateMachine::COMMIT_STATE_IDLE, 39 SchedulerStateMachine::COMMIT_STATE_IDLE,
45 SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 40 SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
46 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 41 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, };
47 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, };
48 42
49 // Exposes the protected state fields of the SchedulerStateMachine for testing 43 // Exposes the protected state fields of the SchedulerStateMachine for testing
50 class StateMachine : public SchedulerStateMachine { 44 class StateMachine : public SchedulerStateMachine {
51 public: 45 public:
52 explicit StateMachine(const SchedulerSettings& scheduler_settings) 46 explicit StateMachine(const SchedulerSettings& scheduler_settings)
53 : SchedulerStateMachine(scheduler_settings) {} 47 : SchedulerStateMachine(scheduler_settings) {}
54 48
55 void CreateAndInitializeOutputSurfaceWithActivatedCommit() { 49 void CreateAndInitializeOutputSurfaceWithActivatedCommit() {
56 DidCreateAndInitializeOutputSurface(); 50 DidCreateAndInitializeOutputSurface();
57 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; 51 output_surface_state_ = OUTPUT_SURFACE_ACTIVE;
(...skipping 17 matching lines...) Expand all
75 OutputSurfaceState output_surface_state() const { 69 OutputSurfaceState output_surface_state() const {
76 return output_surface_state_; 70 return output_surface_state_;
77 } 71 }
78 72
79 bool NeedsCommit() const { return needs_commit_; } 73 bool NeedsCommit() const { return needs_commit_; }
80 74
81 void SetNeedsRedraw(bool b) { needs_redraw_ = b; } 75 void SetNeedsRedraw(bool b) { needs_redraw_ = b; }
82 76
83 void SetNeedsForcedRedrawForTimeout(bool b) { 77 void SetNeedsForcedRedrawForTimeout(bool b) {
84 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_COMMIT; 78 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_COMMIT;
85 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; 79 active_tree_needs_first_draw_ = true;
86 } 80 }
87 bool NeedsForcedRedrawForTimeout() const { 81 bool NeedsForcedRedrawForTimeout() const {
88 return forced_redraw_state_ != FORCED_REDRAW_STATE_IDLE; 82 return forced_redraw_state_ != FORCED_REDRAW_STATE_IDLE;
89 } 83 }
90 84
91 void SetNeedsForcedRedrawForReadback() { 85 void SetNeedsForcedRedrawForReadback() {
92 readback_state_ = READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK; 86 readback_state_ = READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK;
93 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; 87 active_tree_needs_first_draw_ = true;
94 } 88 }
95 89
96 bool NeedsForcedRedrawForReadback() const { 90 bool NeedsForcedRedrawForReadback() const {
97 return readback_state_ != READBACK_STATE_IDLE; 91 return readback_state_ != READBACK_STATE_IDLE;
98 } 92 }
99 93
100 void SetActiveTreeNeedsFirstDraw(bool needs_first_draw) { 94 void SetActiveTreeNeedsFirstDraw(bool needs_first_draw) {
101 active_tree_needs_first_draw_ = needs_first_draw; 95 active_tree_needs_first_draw_ = needs_first_draw;
102 } 96 }
103 97
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 309 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
316 EXPECT_TRUE(state.BeginImplFrameNeeded()); 310 EXPECT_TRUE(state.BeginImplFrameNeeded());
317 EXPECT_TRUE(state.RedrawPending()); 311 EXPECT_TRUE(state.RedrawPending());
318 // But the commit is ongoing. 312 // But the commit is ongoing.
319 EXPECT_TRUE(state.CommitPending()); 313 EXPECT_TRUE(state.CommitPending());
320 314
321 // Finish the commit. Note, we should not yet be forcing a draw, but should 315 // Finish the commit. Note, we should not yet be forcing a draw, but should
322 // continue the commit as usual. 316 // continue the commit as usual.
323 state.FinishCommit(); 317 state.FinishCommit();
324 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 318 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
319 if (!deadline_scheduling_enabled) {
320 EXPECT_ACTION_UPDATE_STATE(
321 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
322 }
325 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 323 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
326 EXPECT_TRUE(state.RedrawPending()); 324 EXPECT_TRUE(state.RedrawPending());
327 325
328 // The redraw should be forced at the end of the next BeginImplFrame. 326 // The redraw should be forced at the end of the next BeginImplFrame.
329 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 327 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
328 if (deadline_scheduling_enabled) {
329 EXPECT_ACTION_UPDATE_STATE(
330 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
331 }
330 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 332 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
331 state.OnBeginImplFrameDeadline(); 333 state.OnBeginImplFrameDeadline();
332 EXPECT_ACTION_UPDATE_STATE( 334 EXPECT_ACTION_UPDATE_STATE(
333 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED); 335 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED);
334 } 336 }
335 337
336 TEST(SchedulerStateMachineTest, 338 TEST(SchedulerStateMachineTest,
337 TestFailedDrawsWillEventuallyForceADrawAfterTheNextCommit) { 339 TestFailedDrawsWillEventuallyForceADrawAfterTheNextCommit) {
338 bool deadline_scheduling_enabled = false; 340 bool deadline_scheduling_enabled = false;
339 TestFailedDrawsWillEventuallyForceADrawAfterTheNextCommit( 341 TestFailedDrawsWillEventuallyForceADrawAfterTheNextCommit(
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 state.NextAction()); 544 state.NextAction());
543 545
544 // Case 2: needs_commit=true 546 // Case 2: needs_commit=true
545 state.SetNeedsCommit(); 547 state.SetNeedsCommit();
546 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 548 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
547 state.NextAction()) 549 state.NextAction())
548 << *state.AsValue(); 550 << *state.AsValue();
549 } 551 }
550 } 552 }
551 553
552 // When in BeginImplFrame deadline we should always draw for SetNeedsRedraw or 554 // When in BeginImplFrame deadline we should always draw for SetNeedsRedraw
553 // SetNeedsForcedRedrawForReadback have been called... except if we're 555 // except if we're ready to commit, in which case we expect a commit first.
554 // ready to commit, in which case we expect a commit first. 556 // SetNeedsForcedRedrawForReadback should take precedence over all and
557 // issue a readback.
555 for (size_t i = 0; i < num_commit_states; ++i) { 558 for (size_t i = 0; i < num_commit_states; ++i) {
556 for (size_t j = 0; j < 2; ++j) { 559 for (size_t j = 0; j < 2; ++j) {
557 bool request_readback = j; 560 bool request_readback = j;
558 561
559 // Skip invalid states
560 if (request_readback &&
561 (SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW !=
562 all_commit_states[i]))
563 continue;
564
565 StateMachine state(default_scheduler_settings); 562 StateMachine state(default_scheduler_settings);
566 state.SetCanStart(); 563 state.SetCanStart();
567 state.UpdateState(state.NextAction()); 564 state.UpdateState(state.NextAction());
568 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 565 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
569 state.SetCanDraw(true); 566 state.SetCanDraw(true);
570 state.SetCommitState(all_commit_states[i]); 567 state.SetCommitState(all_commit_states[i]);
571 state.SetBeginImplFrameState( 568 state.SetBeginImplFrameState(
572 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); 569 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE);
573 if (request_readback) { 570 if (request_readback) {
574 state.SetNeedsForcedRedrawForReadback(); 571 state.SetNeedsForcedRedrawForReadback();
575 } else { 572 } else {
576 state.SetNeedsRedraw(true); 573 state.SetNeedsRedraw(true);
577 state.SetVisible(true); 574 state.SetVisible(true);
578 } 575 }
579 576
580 SchedulerStateMachine::Action expected_action; 577 SchedulerStateMachine::Action expected_action;
581 if (all_commit_states[i] == 578 if (request_readback) {
582 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) { 579 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_READBACK;
580 } else if (all_commit_states[i] ==
581 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) {
583 expected_action = SchedulerStateMachine::ACTION_COMMIT; 582 expected_action = SchedulerStateMachine::ACTION_COMMIT;
584 } else if (request_readback) {
585 if (all_commit_states[i] ==
586 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW)
587 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_READBACK;
588 else
589 expected_action = SchedulerStateMachine::ACTION_NONE;
590 } else { 583 } else {
591 expected_action = 584 expected_action =
592 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE; 585 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE;
593 } 586 }
594 587
595 // Case 1: needs_commit=false. 588 // Case 1: needs_commit=false.
596 EXPECT_NE(state.BeginImplFrameNeeded(), request_readback) 589 EXPECT_NE(state.BeginImplFrameNeeded(), request_readback)
597 << *state.AsValue(); 590 << *state.AsValue();
598 EXPECT_EQ(expected_action, state.NextAction()) << *state.AsValue(); 591 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue();
599 592
600 // Case 2: needs_commit=true. 593 // Case 2: needs_commit=true.
601 state.SetNeedsCommit(); 594 state.SetNeedsCommit();
602 EXPECT_NE(state.BeginImplFrameNeeded(), request_readback) 595 EXPECT_NE(state.BeginImplFrameNeeded(), request_readback)
603 << *state.AsValue(); 596 << *state.AsValue();
604 EXPECT_EQ(expected_action, state.NextAction()) << *state.AsValue(); 597 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue();
605 } 598 }
606 } 599 }
607 } 600 }
608 601
609 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) { 602 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) {
610 SchedulerSettings default_scheduler_settings; 603 SchedulerSettings default_scheduler_settings;
611 604
612 size_t num_commit_states = 605 size_t num_commit_states =
613 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); 606 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState);
614 for (size_t i = 0; i < num_commit_states; ++i) { 607 for (size_t i = 0; i < num_commit_states; ++i) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 } 658 }
666 659
667 TEST(SchedulerStateMachineTest, 660 TEST(SchedulerStateMachineTest,
668 TestCanRedrawWithWaitingForFirstDrawMakesProgress) { 661 TestCanRedrawWithWaitingForFirstDrawMakesProgress) {
669 SchedulerSettings default_scheduler_settings; 662 SchedulerSettings default_scheduler_settings;
670 StateMachine state(default_scheduler_settings); 663 StateMachine state(default_scheduler_settings);
671 state.SetCanStart(); 664 state.SetCanStart();
672 state.UpdateState(state.NextAction()); 665 state.UpdateState(state.NextAction());
673 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 666 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
674 667
675 state.SetCommitState(
676 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
677 state.SetActiveTreeNeedsFirstDraw(true); 668 state.SetActiveTreeNeedsFirstDraw(true);
678 state.SetNeedsCommit(); 669 state.SetNeedsCommit();
679 state.SetNeedsRedraw(true); 670 state.SetNeedsRedraw(true);
680 state.SetVisible(true); 671 state.SetVisible(true);
681 state.SetCanDraw(false); 672 state.SetCanDraw(false);
682 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 673 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
683 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 674 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
684 EXPECT_ACTION_UPDATE_STATE( 675 EXPECT_ACTION_UPDATE_STATE(
685 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 676 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
686 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 677 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 state.OnBeginImplFrameIdle(); 728 state.OnBeginImplFrameIdle();
738 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, 729 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE,
739 state.begin_impl_frame_state()); 730 state.begin_impl_frame_state());
740 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 731 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
741 732
742 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 733 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
743 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING, 734 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING,
744 state.begin_impl_frame_state()); 735 state.begin_impl_frame_state());
745 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 736 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
746 737
747 // Commit and make sure we draw on next BeginImplFrame 738 // Finish the commit, then make sure we start the next commit immediately
739 // and draw on the next BeginImplFrame.
748 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 740 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
749 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
750 state.OnBeginImplFrameDeadline();
751 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW,
752 state.CommitState());
753 EXPECT_ACTION_UPDATE_STATE(
754 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
755 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
756
757 // Verify that another commit will start immediately after draw.
758 EXPECT_ACTION_UPDATE_STATE( 741 EXPECT_ACTION_UPDATE_STATE(
759 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 742 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
760 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 743 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
744
745 state.OnBeginImplFrameDeadline();
746
747 EXPECT_TRUE(state.active_tree_needs_first_draw());
748 EXPECT_ACTION_UPDATE_STATE(
749 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
750 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
751 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
761 } 752 }
762 753
763 TEST(SchedulerStateMachineTest, TestFullCycle) { 754 TEST(SchedulerStateMachineTest, TestFullCycle) {
764 SchedulerSettings default_scheduler_settings; 755 SchedulerSettings default_scheduler_settings;
765 StateMachine state(default_scheduler_settings); 756 StateMachine state(default_scheduler_settings);
766 state.SetCanStart(); 757 state.SetCanStart();
767 state.UpdateState(state.NextAction()); 758 state.UpdateState(state.NextAction());
768 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 759 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
769 state.SetVisible(true); 760 state.SetVisible(true);
770 state.SetCanDraw(true); 761 state.SetCanDraw(true);
(...skipping 10 matching lines...) Expand all
781 EXPECT_FALSE(state.NeedsCommit()); 772 EXPECT_FALSE(state.NeedsCommit());
782 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 773 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
783 774
784 // Tell the scheduler the frame finished. 775 // Tell the scheduler the frame finished.
785 state.FinishCommit(); 776 state.FinishCommit();
786 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 777 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
787 state.CommitState()); 778 state.CommitState());
788 779
789 // Commit. 780 // Commit.
790 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 781 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
791 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 782 EXPECT_TRUE(state.active_tree_needs_first_draw());
792 state.CommitState());
793 EXPECT_TRUE(state.needs_redraw()); 783 EXPECT_TRUE(state.needs_redraw());
794 784
795 // Expect to do nothing until BeginImplFrame deadline 785 // Expect to do nothing until BeginImplFrame deadline
796 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 786 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
797 787
798 // At BeginImplFrame deadline, draw. 788 // At BeginImplFrame deadline, draw.
799 state.OnBeginImplFrameDeadline(); 789 state.OnBeginImplFrameDeadline();
800 EXPECT_ACTION_UPDATE_STATE( 790 EXPECT_ACTION_UPDATE_STATE(
801 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 791 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
802 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 792 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
(...skipping 29 matching lines...) Expand all
832 state.SetNeedsCommit(); 822 state.SetNeedsCommit();
833 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 823 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
834 824
835 // Tell the scheduler the frame finished. 825 // Tell the scheduler the frame finished.
836 state.FinishCommit(); 826 state.FinishCommit();
837 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 827 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
838 state.CommitState()); 828 state.CommitState());
839 829
840 // First commit. 830 // First commit.
841 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 831 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
842 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 832 EXPECT_TRUE(state.active_tree_needs_first_draw());
843 state.CommitState());
844 EXPECT_TRUE(state.needs_redraw()); 833 EXPECT_TRUE(state.needs_redraw());
845 834
846 // Expect to do nothing until BeginImplFrame deadline. 835 // Expect to do nothing until BeginImplFrame deadline.
847 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 836 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
848 837
849 // At BeginImplFrame deadline, draw. 838 // At BeginImplFrame deadline, draw.
850 state.OnBeginImplFrameDeadline(); 839 state.OnBeginImplFrameDeadline();
851 EXPECT_ACTION_UPDATE_STATE( 840 EXPECT_ACTION_UPDATE_STATE(
852 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 841 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
853 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 842 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 // Ask for another draw. Expect nothing happens. 1116 // Ask for another draw. Expect nothing happens.
1128 state.SetNeedsRedraw(true); 1117 state.SetNeedsRedraw(true);
1129 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1118 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1130 1119
1131 // Finish the frame, and commit. 1120 // Finish the frame, and commit.
1132 state.FinishCommit(); 1121 state.FinishCommit();
1133 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1122 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1134 1123
1135 // We will abort the draw when the output surface is lost if we are 1124 // We will abort the draw when the output surface is lost if we are
1136 // waiting for the first draw to unblock the main thread. 1125 // waiting for the first draw to unblock the main thread.
1137 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1126 EXPECT_TRUE(state.active_tree_needs_first_draw());
1138 state.CommitState());
1139 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1127 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1140 1128
1141 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE 1129 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE
1142 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, 1130 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE,
1143 state.begin_impl_frame_state()); 1131 state.begin_impl_frame_state());
1144 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1132 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1145 state.NextAction()); 1133 state.NextAction());
1146 1134
1147 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1135 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
1148 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING, 1136 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1206 state.DidLoseOutputSurface(); 1194 state.DidLoseOutputSurface();
1207 1195
1208 // Ask for another draw and also set needs commit. Expect nothing happens. 1196 // Ask for another draw and also set needs commit. Expect nothing happens.
1209 state.SetNeedsRedraw(true); 1197 state.SetNeedsRedraw(true);
1210 state.SetNeedsCommit(); 1198 state.SetNeedsCommit();
1211 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1199 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1212 1200
1213 // Finish the frame, and commit. 1201 // Finish the frame, and commit.
1214 state.FinishCommit(); 1202 state.FinishCommit();
1215 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1203 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1216 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1204 EXPECT_TRUE(state.active_tree_needs_first_draw());
1217 state.CommitState());
1218 1205
1219 // Because the output surface is missing, we expect the draw to abort. 1206 // Because the output surface is missing, we expect the draw to abort.
1220 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1207 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1221 1208
1222 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE 1209 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE
1223 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, 1210 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE,
1224 state.begin_impl_frame_state()); 1211 state.begin_impl_frame_state());
1225 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1212 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1226 state.NextAction()); 1213 state.NextAction());
1227 1214
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 state.SetCanStart(); 1266 state.SetCanStart();
1280 state.UpdateState(state.NextAction()); 1267 state.UpdateState(state.NextAction());
1281 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1268 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1282 state.SetVisible(true); 1269 state.SetVisible(true);
1283 state.SetCanDraw(true); 1270 state.SetCanDraw(true);
1284 1271
1285 // Cause a lost context lost. 1272 // Cause a lost context lost.
1286 state.DidLoseOutputSurface(); 1273 state.DidLoseOutputSurface();
1287 1274
1288 // Ask a forced redraw for readback and verify it ocurrs. 1275 // Ask a forced redraw for readback and verify it ocurrs.
1289 state.SetCommitState(
1290 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
1291 state.SetNeedsForcedRedrawForReadback(); 1276 state.SetNeedsForcedRedrawForReadback();
1292 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1277 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
1293 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1278 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1294 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1279 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1295 1280
1296 // Forced redraws for readbacks need to be followed by a new commit 1281 // Forced redraws for readbacks need to be followed by a new commit
1297 // to replace the readback commit. 1282 // to replace the readback commit.
1298 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 1283 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
1299 state.CommitState()); 1284 state.CommitState());
1300 state.FinishCommit(); 1285 state.FinishCommit();
1301 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1286 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1302 1287
1303 // We don't yet have an output surface, so we the draw and swap should abort. 1288 // We don't yet have an output surface, so we the draw and swap should abort.
1304 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1289 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1305 1290
1306 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE 1291 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE
1307 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1292 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1308 1293
1309 state.OnBeginImplFrameDeadline(); 1294 state.OnBeginImplFrameDeadline();
1310 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1295 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1311 1296
1312 state.OnBeginImplFrameIdle(); 1297 state.OnBeginImplFrameIdle();
1313 EXPECT_ACTION_UPDATE_STATE( 1298 EXPECT_ACTION_UPDATE_STATE(
1314 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 1299 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1315 1300
1316 // Ask a readback and verify it occurs. 1301 // Ask a readback and verify it occurs.
1317 state.SetCommitState(
1318 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
1319 state.SetNeedsForcedRedrawForReadback(); 1302 state.SetNeedsForcedRedrawForReadback();
1320 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1303 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1321 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1304 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1322 } 1305 }
1323 1306
1324 TEST(SchedulerStateMachineTest, DontDrawBeforeCommitAfterLostOutputSurface) { 1307 TEST(SchedulerStateMachineTest, DontDrawBeforeCommitAfterLostOutputSurface) {
1325 SchedulerSettings default_scheduler_settings; 1308 SchedulerSettings default_scheduler_settings;
1326 StateMachine state(default_scheduler_settings); 1309 StateMachine state(default_scheduler_settings);
1327 state.SetCanStart(); 1310 state.SetCanStart();
1328 state.UpdateState(state.NextAction()); 1311 state.UpdateState(state.NextAction());
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 state.UpdateState(state.NextAction()); 1361 state.UpdateState(state.NextAction());
1379 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1362 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1380 state.SetVisible(false); 1363 state.SetVisible(false);
1381 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); 1364 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS);
1382 state.SetNeedsCommit(); 1365 state.SetNeedsCommit();
1383 1366
1384 state.FinishCommit(); 1367 state.FinishCommit();
1385 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 1368 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
1386 state.UpdateState(state.NextAction()); 1369 state.UpdateState(state.NextAction());
1387 1370
1388 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1371 EXPECT_TRUE(state.active_tree_needs_first_draw());
1389 state.CommitState());
1390 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1372 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1391 } 1373 }
1392 1374
1393 TEST(SchedulerStateMachineTest, TestFinishCommitWhenForcedCommitInProgress) { 1375 TEST(SchedulerStateMachineTest, TestFinishCommitWhenForcedCommitInProgress) {
1394 SchedulerSettings default_scheduler_settings; 1376 SchedulerSettings default_scheduler_settings;
1395 StateMachine state(default_scheduler_settings); 1377 StateMachine state(default_scheduler_settings);
1396 state.SetCanStart(); 1378 state.SetCanStart();
1397 state.UpdateState(state.NextAction()); 1379 state.UpdateState(state.NextAction());
1398 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1380 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1399 state.SetVisible(false); 1381 state.SetVisible(false);
1400 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); 1382 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS);
1401 state.SetNeedsCommit(); 1383 state.SetNeedsCommit();
1402 state.SetNeedsForcedCommitForReadback(); 1384 state.SetNeedsForcedCommitForReadback();
1403 1385
1404 // The commit for readback interupts the normal commit. 1386 // The commit for readback interupts the normal commit.
1405 state.FinishCommit(); 1387 state.FinishCommit();
1406 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1388 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1407 1389
1408 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1390 EXPECT_TRUE(state.active_tree_needs_first_draw());
1409 state.CommitState());
1410 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1391 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1411 1392
1412 // When the readback interrupts the normal commit, we should not get 1393 // When the readback interrupts the normal commit, we should not get
1413 // another BeginMainFrame when the readback completes. 1394 // another BeginMainFrame when the readback completes.
1414 EXPECT_NE(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME, 1395 EXPECT_NE(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME,
1415 state.NextAction()); 1396 state.NextAction());
1416 1397
1417 // The normal commit can then proceed. 1398 // The normal commit can then proceed.
1418 state.FinishCommit(); 1399 state.FinishCommit();
1419 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1400 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1468 state.SetNeedsCommit(); 1449 state.SetNeedsCommit();
1469 state.SetNeedsForcedCommitForReadback(); 1450 state.SetNeedsForcedCommitForReadback();
1470 EXPECT_ACTION_UPDATE_STATE( 1451 EXPECT_ACTION_UPDATE_STATE(
1471 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1452 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1472 state.FinishCommit(); 1453 state.FinishCommit();
1473 1454
1474 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 1455 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
1475 state.CommitState()); 1456 state.CommitState());
1476 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1457 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1477 1458
1478 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1459 EXPECT_TRUE(state.active_tree_needs_first_draw());
1479 state.CommitState());
1480 1460
1481 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1461 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1482 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 1462 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
1483 1463
1484 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1464 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1485 1465
1486 // Should be waiting for the normal BeginMainFrame. 1466 // Should be waiting for the normal BeginMainFrame.
1487 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 1467 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
1488 state.CommitState()); 1468 state.CommitState());
1489 } 1469 }
(...skipping 21 matching lines...) Expand all
1511 if (deadline_scheduling_enabled) { 1491 if (deadline_scheduling_enabled) {
1512 EXPECT_ACTION_UPDATE_STATE( 1492 EXPECT_ACTION_UPDATE_STATE(
1513 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1493 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1514 } 1494 }
1515 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1495 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1516 state.FinishCommit(); 1496 state.FinishCommit();
1517 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 1497 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
1518 state.CommitState()); 1498 state.CommitState());
1519 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1499 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1520 1500
1521 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1501 EXPECT_TRUE(state.active_tree_needs_first_draw());
1522 state.CommitState());
1523 1502
1524 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1503 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1525 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 1504 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
1526 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1505 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1527 1506
1528 // Should be waiting for the normal BeginMainFrame. 1507 // Should be waiting for the normal BeginMainFrame.
1529 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 1508 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
1530 state.CommitState()) 1509 state.CommitState())
1531 << *state.AsValue(); 1510 << *state.AsValue();
1532 } 1511 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1565 if (deadline_scheduling_enabled) { 1544 if (deadline_scheduling_enabled) {
1566 EXPECT_ACTION_UPDATE_STATE( 1545 EXPECT_ACTION_UPDATE_STATE(
1567 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1546 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1568 } 1547 }
1569 state.FinishCommit(); 1548 state.FinishCommit();
1570 1549
1571 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 1550 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
1572 state.CommitState()); 1551 state.CommitState());
1573 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1552 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1574 1553
1575 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1554 EXPECT_TRUE(state.active_tree_needs_first_draw());
1576 state.CommitState());
1577 1555
1578 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1556 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1579 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 1557 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
1580 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1558 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1581 1559
1582 // Should be waiting for BeginMainFrame. 1560 // Should be waiting for BeginMainFrame.
1583 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 1561 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
1584 state.CommitState()) 1562 state.CommitState())
1585 << *state.AsValue(); 1563 << *state.AsValue();
1586 1564
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1621 1599
1622 state.SetNeedsCommit(); 1600 state.SetNeedsCommit();
1623 state.SetNeedsForcedCommitForReadback(); 1601 state.SetNeedsForcedCommitForReadback();
1624 state.UpdateState(state.NextAction()); 1602 state.UpdateState(state.NextAction());
1625 state.FinishCommit(); 1603 state.FinishCommit();
1626 1604
1627 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 1605 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
1628 state.CommitState()); 1606 state.CommitState());
1629 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1607 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1630 1608
1631 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1609 EXPECT_TRUE(state.active_tree_needs_first_draw());
1632 state.CommitState());
1633 1610
1634 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1611 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1635 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 1612 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
1636 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1613 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1637 } 1614 }
1638 1615
1639 TEST(SchedulerStateMachineTest, ReportIfNotDrawing) { 1616 TEST(SchedulerStateMachineTest, ReportIfNotDrawing) {
1640 SchedulerSettings default_scheduler_settings; 1617 SchedulerSettings default_scheduler_settings;
1641 StateMachine state(default_scheduler_settings); 1618 StateMachine state(default_scheduler_settings);
1642 state.SetCanStart(); 1619 state.SetCanStart();
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1786 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1763 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1787 1764
1788 // The deadline is not triggered early until we enter prefer smoothness mode. 1765 // The deadline is not triggered early until we enter prefer smoothness mode.
1789 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 1766 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineEarly());
1790 state.SetSmoothnessTakesPriority(true); 1767 state.SetSmoothnessTakesPriority(true);
1791 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 1768 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly());
1792 } 1769 }
1793 1770
1794 } // namespace 1771 } // namespace
1795 } // namespace cc 1772 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698