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

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

Issue 812543002: Update from https://crrev.com/308331 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/scheduler/scheduler.cc ('k') | cc/surfaces/display.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/scheduler/scheduler_state_machine.h" 5 #include "cc/scheduler/scheduler_state_machine.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "cc/scheduler/scheduler.h" 8 #include "cc/scheduler/scheduler.h"
9 #include "cc/test/begin_frame_args_test.h" 9 #include "cc/test/begin_frame_args_test.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 #define EXPECT_ACTION_UPDATE_STATE(action) \ 12 // Macro to compare two enum values and get nice output.
13 EXPECT_STREQ(SchedulerStateMachine::ActionToString(action), \ 13 // Without:
14 SchedulerStateMachine::ActionToString(state.NextAction())) \ 14 // Value of: actual() Actual: 7
15 << state.AsValue()->ToString(); \ 15 // Expected: expected() Which is: 0
16 if (action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE || \ 16 // With:
17 action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED) { \ 17 // Value of: actual() Actual: "ACTION_ANIMATE"
18 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, \ 18 // Expected: expected() Which is: "ACTION_NONE"
19 state.begin_impl_frame_state()) \ 19 #define EXPECT_ENUM_EQ(enum_tostring, expected, actual) \
20 << state.AsValue()->ToString(); \ 20 EXPECT_STREQ(SchedulerStateMachine::enum_tostring(expected), \
21 } \ 21 SchedulerStateMachine::enum_tostring(actual))
22 state.UpdateState(action); \ 22
23 if (action == SchedulerStateMachine::ACTION_NONE) { \ 23 #define EXPECT_IMPL_FRAME_STATE(expected) \
24 if (state.begin_impl_frame_state() == \ 24 EXPECT_ENUM_EQ(BeginImplFrameStateToString, expected, \
25 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING) \ 25 state.begin_impl_frame_state()) \
26 state.OnBeginImplFrameDeadlinePending(); \ 26 << state.AsValue()->ToString()
27 if (state.begin_impl_frame_state() == \ 27
28 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) \ 28 #define EXPECT_COMMIT_STATE(expected) \
29 state.OnBeginImplFrameIdle(); \ 29 EXPECT_ENUM_EQ(CommitStateToString, expected, state.CommitState())
30
31 #define EXPECT_ACTION(expected) \
32 EXPECT_ENUM_EQ(ActionToString, expected, state.NextAction()) \
33 << state.AsValue()->ToString()
34
35 #define EXPECT_ACTION_UPDATE_STATE(action) \
36 EXPECT_ACTION(action); \
37 if (action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE || \
38 action == SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED) { \
39 EXPECT_IMPL_FRAME_STATE( \
40 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); \
41 } \
42 state.UpdateState(action); \
43 if (action == SchedulerStateMachine::ACTION_NONE) { \
44 if (state.begin_impl_frame_state() == \
45 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING) \
46 state.OnBeginImplFrameDeadlinePending(); \
47 if (state.begin_impl_frame_state() == \
48 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) \
49 state.OnBeginImplFrameIdle(); \
30 } 50 }
31 51
32 namespace cc { 52 namespace cc {
33 53
34 namespace { 54 namespace {
35 55
36 const SchedulerStateMachine::BeginImplFrameState all_begin_impl_frame_states[] = 56 const SchedulerStateMachine::BeginImplFrameState all_begin_impl_frame_states[] =
37 {SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, 57 {SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE,
38 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING, 58 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING,
39 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME, 59 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME,
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 } 190 }
171 191
172 // Begin the frame, make sure needs_commit and commit_state update correctly. 192 // Begin the frame, make sure needs_commit and commit_state update correctly.
173 { 193 {
174 StateMachine state(default_scheduler_settings); 194 StateMachine state(default_scheduler_settings);
175 state.SetCanStart(); 195 state.SetCanStart();
176 state.UpdateState(state.NextAction()); 196 state.UpdateState(state.NextAction());
177 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 197 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
178 state.SetVisible(true); 198 state.SetVisible(true);
179 state.UpdateState(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 199 state.UpdateState(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
180 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 200 EXPECT_COMMIT_STATE(
181 state.CommitState()); 201 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT);
182 EXPECT_FALSE(state.NeedsCommit()); 202 EXPECT_FALSE(state.NeedsCommit());
183 } 203 }
184 } 204 }
185 205
186 // Explicitly test main_frame_before_activation_enabled = true 206 // Explicitly test main_frame_before_activation_enabled = true
187 TEST(SchedulerStateMachineTest, MainFrameBeforeActivationEnabled) { 207 TEST(SchedulerStateMachineTest, MainFrameBeforeActivationEnabled) {
188 SchedulerSettings scheduler_settings; 208 SchedulerSettings scheduler_settings;
189 scheduler_settings.impl_side_painting = true; 209 scheduler_settings.impl_side_painting = true;
190 scheduler_settings.main_frame_before_activation_enabled = true; 210 scheduler_settings.main_frame_before_activation_enabled = true;
191 StateMachine state(scheduler_settings); 211 StateMachine state(scheduler_settings);
(...skipping 11 matching lines...) Expand all
203 // Commit to the pending tree. 223 // Commit to the pending tree.
204 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 224 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
205 EXPECT_ACTION_UPDATE_STATE( 225 EXPECT_ACTION_UPDATE_STATE(
206 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 226 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
207 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 227 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
208 228
209 state.NotifyBeginMainFrameStarted(); 229 state.NotifyBeginMainFrameStarted();
210 state.NotifyReadyToCommit(); 230 state.NotifyReadyToCommit();
211 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 231 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
212 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 232 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
213 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 233 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE);
214 234
215 state.OnBeginImplFrameDeadline(); 235 state.OnBeginImplFrameDeadline();
216 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 236 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
217 237
218 // Verify that the next commit starts while there is still a pending tree. 238 // Verify that the next commit starts while there is still a pending tree.
219 state.SetNeedsCommit(); 239 state.SetNeedsCommit();
220 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 240 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
221 EXPECT_ACTION_UPDATE_STATE( 241 EXPECT_ACTION_UPDATE_STATE(
222 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 242 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
223 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 243 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
(...skipping 12 matching lines...) Expand all
236 256
237 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately()); 257 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineImmediately());
238 state.OnBeginImplFrameDeadline(); 258 state.OnBeginImplFrameDeadline();
239 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 259 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
240 EXPECT_ACTION_UPDATE_STATE( 260 EXPECT_ACTION_UPDATE_STATE(
241 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 261 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
242 state.DidSwapBuffers(); 262 state.DidSwapBuffers();
243 state.DidSwapBuffersComplete(); 263 state.DidSwapBuffersComplete();
244 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 264 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
245 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 265 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
246 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 266 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE);
247 } 267 }
248 268
249 TEST(SchedulerStateMachineTest, 269 TEST(SchedulerStateMachineTest,
250 TestFailedDrawForAnimationCheckerboardSetsNeedsCommitAndDoesNotDrawAgain) { 270 TestFailedDrawForAnimationCheckerboardSetsNeedsCommitAndDoesNotDrawAgain) {
251 SchedulerSettings default_scheduler_settings; 271 SchedulerSettings default_scheduler_settings;
252 StateMachine state(default_scheduler_settings); 272 StateMachine state(default_scheduler_settings);
253 state.SetCanStart(); 273 state.SetCanStart();
254 state.UpdateState(state.NextAction()); 274 state.UpdateState(state.NextAction());
255 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 275 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
256 state.SetVisible(true); 276 state.SetVisible(true);
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 634
615 state.SetNeedsRedraw(true); 635 state.SetNeedsRedraw(true);
616 state.SetVisible(true); 636 state.SetVisible(true);
617 637
618 SchedulerStateMachine::Action expected_action; 638 SchedulerStateMachine::Action expected_action;
619 if (all_commit_states[i] == 639 if (all_commit_states[i] ==
620 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) { 640 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) {
621 expected_action = SchedulerStateMachine::ACTION_COMMIT; 641 expected_action = SchedulerStateMachine::ACTION_COMMIT;
622 } else { 642 } else {
623 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE; 643 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE;
624 EXPECT_EQ(state.NextAction(), SchedulerStateMachine::ACTION_ANIMATE) 644 EXPECT_ACTION(SchedulerStateMachine::ACTION_ANIMATE);
625 << state.AsValue()->ToString();
626 state.UpdateState(state.NextAction()); 645 state.UpdateState(state.NextAction());
627 } 646 }
628 647
629 // Case 1: needs_commit=false. 648 // Case 1: needs_commit=false.
630 EXPECT_EQ(state.NextAction(), expected_action) 649 EXPECT_ACTION(expected_action);
631 << state.AsValue()->ToString();
632 650
633 // Case 2: needs_commit=true. 651 // Case 2: needs_commit=true.
634 state.SetNeedsCommit(); 652 state.SetNeedsCommit();
635 EXPECT_EQ(state.NextAction(), expected_action) 653 EXPECT_ACTION(expected_action);
636 << state.AsValue()->ToString();
637 } 654 }
638 } 655 }
639 656
640 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) { 657 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) {
641 SchedulerSettings default_scheduler_settings; 658 SchedulerSettings default_scheduler_settings;
642 659
643 size_t num_commit_states = 660 size_t num_commit_states =
644 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); 661 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState);
645 for (size_t i = 0; i < num_commit_states; ++i) { 662 for (size_t i = 0; i < num_commit_states; ++i) {
646 // There shouldn't be any drawing regardless of BeginImplFrame. 663 // There shouldn't be any drawing regardless of BeginImplFrame.
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 state.SetNeedsCommit(); 750 state.SetNeedsCommit();
734 state.SetVisible(true); 751 state.SetVisible(true);
735 state.SetCanDraw(true); 752 state.SetCanDraw(true);
736 753
737 EXPECT_TRUE(state.BeginFrameNeeded()); 754 EXPECT_TRUE(state.BeginFrameNeeded());
738 755
739 // Begin the frame. 756 // Begin the frame.
740 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 757 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
741 EXPECT_ACTION_UPDATE_STATE( 758 EXPECT_ACTION_UPDATE_STATE(
742 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 759 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
743 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 760 EXPECT_COMMIT_STATE(
744 state.CommitState()); 761 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT);
745 762
746 // Now, while the frame is in progress, set another commit. 763 // Now, while the frame is in progress, set another commit.
747 state.SetNeedsCommit(); 764 state.SetNeedsCommit();
748 EXPECT_TRUE(state.NeedsCommit()); 765 EXPECT_TRUE(state.NeedsCommit());
749 766
750 // Let the frame finish. 767 // Let the frame finish.
751 state.NotifyBeginMainFrameStarted(); 768 state.NotifyBeginMainFrameStarted();
752 state.NotifyReadyToCommit(); 769 state.NotifyReadyToCommit();
753 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 770 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT);
754 state.CommitState());
755 771
756 // Expect to commit regardless of BeginImplFrame state. 772 // Expect to commit regardless of BeginImplFrame state.
757 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING, 773 EXPECT_IMPL_FRAME_STATE(
758 state.begin_impl_frame_state()); 774 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING);
759 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 775 EXPECT_ACTION(SchedulerStateMachine::ACTION_COMMIT);
760 776
761 state.OnBeginImplFrameDeadlinePending(); 777 state.OnBeginImplFrameDeadlinePending();
762 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME, 778 EXPECT_IMPL_FRAME_STATE(
763 state.begin_impl_frame_state()); 779 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME);
764 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 780 EXPECT_ACTION(SchedulerStateMachine::ACTION_COMMIT);
765 781
766 state.OnBeginImplFrameDeadline(); 782 state.OnBeginImplFrameDeadline();
767 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, 783 EXPECT_IMPL_FRAME_STATE(
768 state.begin_impl_frame_state()); 784 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE);
769 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 785 EXPECT_ACTION(SchedulerStateMachine::ACTION_COMMIT);
770 786
771 state.OnBeginImplFrameIdle(); 787 state.OnBeginImplFrameIdle();
772 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, 788 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
773 state.begin_impl_frame_state()); 789 EXPECT_ACTION(SchedulerStateMachine::ACTION_COMMIT);
774 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
775 790
776 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 791 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
777 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING, 792 EXPECT_IMPL_FRAME_STATE(
778 state.begin_impl_frame_state()); 793 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING);
779 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 794 EXPECT_ACTION(SchedulerStateMachine::ACTION_COMMIT);
780 795
781 // Finish the commit, then make sure we start the next commit immediately 796 // Finish the commit, then make sure we start the next commit immediately
782 // and draw on the next BeginImplFrame. 797 // and draw on the next BeginImplFrame.
783 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 798 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
784 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 799 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
785 EXPECT_ACTION_UPDATE_STATE( 800 EXPECT_ACTION_UPDATE_STATE(
786 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 801 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
787 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 802 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
788 803
789 state.OnBeginImplFrameDeadline(); 804 state.OnBeginImplFrameDeadline();
(...skipping 16 matching lines...) Expand all
806 state.SetVisible(true); 821 state.SetVisible(true);
807 state.SetCanDraw(true); 822 state.SetCanDraw(true);
808 823
809 // Start clean and set commit. 824 // Start clean and set commit.
810 state.SetNeedsCommit(); 825 state.SetNeedsCommit();
811 826
812 // Begin the frame. 827 // Begin the frame.
813 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 828 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
814 EXPECT_ACTION_UPDATE_STATE( 829 EXPECT_ACTION_UPDATE_STATE(
815 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 830 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
816 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 831 EXPECT_COMMIT_STATE(
817 state.CommitState()); 832 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT);
818 EXPECT_FALSE(state.NeedsCommit()); 833 EXPECT_FALSE(state.NeedsCommit());
819 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 834 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
820 835
821 // Tell the scheduler the frame finished. 836 // Tell the scheduler the frame finished.
822 state.NotifyBeginMainFrameStarted(); 837 state.NotifyBeginMainFrameStarted();
823 state.NotifyReadyToCommit(); 838 state.NotifyReadyToCommit();
824 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 839 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT);
825 state.CommitState());
826 840
827 // Commit. 841 // Commit.
828 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 842 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
829 EXPECT_TRUE(state.active_tree_needs_first_draw()); 843 EXPECT_TRUE(state.active_tree_needs_first_draw());
830 EXPECT_TRUE(state.needs_redraw()); 844 EXPECT_TRUE(state.needs_redraw());
831 845
832 // Expect to do nothing until BeginImplFrame deadline 846 // Expect to do nothing until BeginImplFrame deadline
833 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 847 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
834 848
835 // At BeginImplFrame deadline, draw. 849 // At BeginImplFrame deadline, draw.
836 state.OnBeginImplFrameDeadline(); 850 state.OnBeginImplFrameDeadline();
837 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 851 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
838 EXPECT_ACTION_UPDATE_STATE( 852 EXPECT_ACTION_UPDATE_STATE(
839 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 853 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
840 state.DidSwapBuffers(); 854 state.DidSwapBuffers();
841 state.DidDrawIfPossibleCompleted(DRAW_SUCCESS); 855 state.DidDrawIfPossibleCompleted(DRAW_SUCCESS);
842 state.DidSwapBuffersComplete(); 856 state.DidSwapBuffersComplete();
843 857
844 // Should be synchronized, no draw needed, no action needed. 858 // Should be synchronized, no draw needed, no action needed.
845 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 859 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
846 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 860 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE);
847 EXPECT_FALSE(state.needs_redraw()); 861 EXPECT_FALSE(state.needs_redraw());
848 } 862 }
849 863
850 TEST(SchedulerStateMachineTest, TestFullCycleWithMainThreadLowLatencyMode) { 864 TEST(SchedulerStateMachineTest, TestFullCycleWithMainThreadLowLatencyMode) {
851 SchedulerSettings scheduler_settings; 865 SchedulerSettings scheduler_settings;
852 scheduler_settings.main_thread_should_always_be_low_latency = true; 866 scheduler_settings.main_thread_should_always_be_low_latency = true;
853 StateMachine state(scheduler_settings); 867 StateMachine state(scheduler_settings);
854 state.SetCanStart(); 868 state.SetCanStart();
855 state.UpdateState(state.NextAction()); 869 state.UpdateState(state.NextAction());
856 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 870 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
857 state.SetVisible(true); 871 state.SetVisible(true);
858 state.SetCanDraw(true); 872 state.SetCanDraw(true);
859 873
860 // Start clean and set commit. 874 // Start clean and set commit.
861 state.SetNeedsCommit(); 875 state.SetNeedsCommit();
862 876
863 // Begin the frame. 877 // Begin the frame.
864 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 878 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
865 EXPECT_ACTION_UPDATE_STATE( 879 EXPECT_ACTION_UPDATE_STATE(
866 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 880 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
867 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 881 EXPECT_COMMIT_STATE(
868 state.CommitState()); 882 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT);
869 EXPECT_FALSE(state.NeedsCommit()); 883 EXPECT_FALSE(state.NeedsCommit());
870 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 884 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
871 885
872 // Tell the scheduler the frame finished. 886 // Tell the scheduler the frame finished.
873 state.NotifyBeginMainFrameStarted(); 887 state.NotifyBeginMainFrameStarted();
874 state.NotifyReadyToCommit(); 888 state.NotifyReadyToCommit();
875 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 889 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT);
876 state.CommitState());
877 890
878 // Commit. 891 // Commit.
879 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 892 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
880 EXPECT_TRUE(state.active_tree_needs_first_draw()); 893 EXPECT_TRUE(state.active_tree_needs_first_draw());
881 EXPECT_TRUE(state.needs_redraw()); 894 EXPECT_TRUE(state.needs_redraw());
882 895
883 // Now commit should wait for draw. 896 // Now commit should wait for draw.
884 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_DRAW, 897 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_DRAW);
885 state.CommitState());
886 898
887 // Swap throttled. Do not draw. 899 // Swap throttled. Do not draw.
888 state.DidSwapBuffers(); 900 state.DidSwapBuffers();
889 state.OnBeginImplFrameDeadline(); 901 state.OnBeginImplFrameDeadline();
890 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 902 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
891 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 903 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
892 state.DidSwapBuffersComplete(); 904 state.DidSwapBuffersComplete();
893 905
894 // Haven't draw since last commit, do not begin new main frame. 906 // Haven't draw since last commit, do not begin new main frame.
895 state.SetNeedsCommit(); 907 state.SetNeedsCommit();
896 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 908 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
897 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 909 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
898 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 910 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
899 911
900 // At BeginImplFrame deadline, draw. 912 // At BeginImplFrame deadline, draw.
901 state.OnBeginImplFrameDeadline(); 913 state.OnBeginImplFrameDeadline();
902 EXPECT_ACTION_UPDATE_STATE( 914 EXPECT_ACTION_UPDATE_STATE(
903 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 915 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
904 state.DidSwapBuffers(); 916 state.DidSwapBuffers();
905 state.DidDrawIfPossibleCompleted(DRAW_SUCCESS); 917 state.DidDrawIfPossibleCompleted(DRAW_SUCCESS);
906 state.DidSwapBuffersComplete(); 918 state.DidSwapBuffersComplete();
907 919
908 // Now will be able to start main frame. 920 // Now will be able to start main frame.
909 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 921 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE);
910 EXPECT_FALSE(state.needs_redraw()); 922 EXPECT_FALSE(state.needs_redraw());
911 EXPECT_ACTION_UPDATE_STATE( 923 EXPECT_ACTION_UPDATE_STATE(
912 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 924 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
913 } 925 }
914 926
915 TEST(SchedulerStateMachineTest, 927 TEST(SchedulerStateMachineTest,
916 TestFullCycleWithMainThreadLowLatencyMode_ImplSidePaint) { 928 TestFullCycleWithMainThreadLowLatencyMode_ImplSidePaint) {
917 SchedulerSettings scheduler_settings; 929 SchedulerSettings scheduler_settings;
918 scheduler_settings.main_thread_should_always_be_low_latency = true; 930 scheduler_settings.main_thread_should_always_be_low_latency = true;
919 scheduler_settings.impl_side_painting = true; 931 scheduler_settings.impl_side_painting = true;
920 StateMachine state(scheduler_settings); 932 StateMachine state(scheduler_settings);
921 state.SetCanStart(); 933 state.SetCanStart();
922 state.UpdateState(state.NextAction()); 934 state.UpdateState(state.NextAction());
923 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 935 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
924 state.SetVisible(true); 936 state.SetVisible(true);
925 state.SetCanDraw(true); 937 state.SetCanDraw(true);
926 938
927 // Start clean and set commit. 939 // Start clean and set commit.
928 state.SetNeedsCommit(); 940 state.SetNeedsCommit();
929 941
930 // Begin the frame. 942 // Begin the frame.
931 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 943 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
932 EXPECT_ACTION_UPDATE_STATE( 944 EXPECT_ACTION_UPDATE_STATE(
933 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 945 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
934 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 946 EXPECT_COMMIT_STATE(
935 state.CommitState()); 947 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT);
936 EXPECT_FALSE(state.NeedsCommit()); 948 EXPECT_FALSE(state.NeedsCommit());
937 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 949 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
938 950
939 // Tell the scheduler the frame finished. 951 // Tell the scheduler the frame finished.
940 state.NotifyBeginMainFrameStarted(); 952 state.NotifyBeginMainFrameStarted();
941 state.NotifyReadyToCommit(); 953 state.NotifyReadyToCommit();
942 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 954 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT);
943 state.CommitState());
944 955
945 // Commit. 956 // Commit.
946 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 957 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
947 958
948 // Now commit should wait for activation. 959 // Now commit should wait for activation.
949 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_ACTIVATION, 960 EXPECT_COMMIT_STATE(
950 state.CommitState()); 961 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_ACTIVATION);
951 962
952 // No activation yet, so this commit is not drawn yet. Force to draw this 963 // No activation yet, so this commit is not drawn yet. Force to draw this
953 // frame, and still block BeginMainFrame. 964 // frame, and still block BeginMainFrame.
954 state.SetNeedsRedraw(true); 965 state.SetNeedsRedraw(true);
955 state.SetNeedsCommit(); 966 state.SetNeedsCommit();
956 state.OnBeginImplFrameDeadline(); 967 state.OnBeginImplFrameDeadline();
957 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 968 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
958 EXPECT_ACTION_UPDATE_STATE( 969 EXPECT_ACTION_UPDATE_STATE(
959 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 970 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
960 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 971 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
961 972
962 // Cannot BeginMainFrame yet since last commit is not yet activated and drawn. 973 // Cannot BeginMainFrame yet since last commit is not yet activated and drawn.
963 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 974 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
964 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_ACTIVATION, 975 EXPECT_COMMIT_STATE(
965 state.CommitState()); 976 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_ACTIVATION);
966 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 977 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
967 978
968 // Now activate sync tree. 979 // Now activate sync tree.
969 state.NotifyReadyToActivate(); 980 state.NotifyReadyToActivate();
970 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE); 981 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
971 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 982 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
972 EXPECT_TRUE(state.active_tree_needs_first_draw()); 983 EXPECT_TRUE(state.active_tree_needs_first_draw());
973 EXPECT_TRUE(state.needs_redraw()); 984 EXPECT_TRUE(state.needs_redraw());
974 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_DRAW, 985 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_DRAW);
975 state.CommitState());
976 986
977 // Swap throttled. Do not draw. 987 // Swap throttled. Do not draw.
978 state.DidSwapBuffers(); 988 state.DidSwapBuffers();
979 state.OnBeginImplFrameDeadline(); 989 state.OnBeginImplFrameDeadline();
980 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 990 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
981 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 991 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
982 state.DidSwapBuffersComplete(); 992 state.DidSwapBuffersComplete();
983 993
984 // Haven't draw since last commit, do not begin new main frame. 994 // Haven't draw since last commit, do not begin new main frame.
985 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 995 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
986 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 996 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
987 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 997 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
988 998
989 // At BeginImplFrame deadline, draw. This draws unblocks BeginMainFrame. 999 // At BeginImplFrame deadline, draw. This draws unblocks BeginMainFrame.
990 state.OnBeginImplFrameDeadline(); 1000 state.OnBeginImplFrameDeadline();
991 EXPECT_ACTION_UPDATE_STATE( 1001 EXPECT_ACTION_UPDATE_STATE(
992 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1002 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
993 state.DidSwapBuffers(); 1003 state.DidSwapBuffers();
994 state.DidDrawIfPossibleCompleted(DRAW_SUCCESS); 1004 state.DidDrawIfPossibleCompleted(DRAW_SUCCESS);
995 state.DidSwapBuffersComplete(); 1005 state.DidSwapBuffersComplete();
996 1006
997 // Now will be able to start main frame. 1007 // Now will be able to start main frame.
998 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1008 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE);
999 EXPECT_FALSE(state.needs_redraw()); 1009 EXPECT_FALSE(state.needs_redraw());
1000 EXPECT_ACTION_UPDATE_STATE( 1010 EXPECT_ACTION_UPDATE_STATE(
1001 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1011 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1002 } 1012 }
1003 1013
1004 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) { 1014 TEST(SchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween) {
1005 SchedulerSettings default_scheduler_settings; 1015 SchedulerSettings default_scheduler_settings;
1006 StateMachine state(default_scheduler_settings); 1016 StateMachine state(default_scheduler_settings);
1007 state.SetCanStart(); 1017 state.SetCanStart();
1008 state.UpdateState(state.NextAction()); 1018 state.UpdateState(state.NextAction());
1009 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1019 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1010 state.SetVisible(true); 1020 state.SetVisible(true);
1011 state.SetCanDraw(true); 1021 state.SetCanDraw(true);
1012 1022
1013 // Start clean and set commit. 1023 // Start clean and set commit.
1014 state.SetNeedsCommit(); 1024 state.SetNeedsCommit();
1015 1025
1016 // Begin the frame. 1026 // Begin the frame.
1017 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1027 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1018 EXPECT_ACTION_UPDATE_STATE( 1028 EXPECT_ACTION_UPDATE_STATE(
1019 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1029 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1020 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 1030 EXPECT_COMMIT_STATE(
1021 state.CommitState()); 1031 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT);
1022 EXPECT_FALSE(state.NeedsCommit()); 1032 EXPECT_FALSE(state.NeedsCommit());
1023 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1033 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1024 1034
1025 // Request another commit while the commit is in flight. 1035 // Request another commit while the commit is in flight.
1026 state.SetNeedsCommit(); 1036 state.SetNeedsCommit();
1027 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1037 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1028 1038
1029 // Tell the scheduler the frame finished. 1039 // Tell the scheduler the frame finished.
1030 state.NotifyBeginMainFrameStarted(); 1040 state.NotifyBeginMainFrameStarted();
1031 state.NotifyReadyToCommit(); 1041 state.NotifyReadyToCommit();
1032 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 1042 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT);
1033 state.CommitState());
1034 1043
1035 // First commit. 1044 // First commit.
1036 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1045 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1037 EXPECT_TRUE(state.active_tree_needs_first_draw()); 1046 EXPECT_TRUE(state.active_tree_needs_first_draw());
1038 EXPECT_TRUE(state.needs_redraw()); 1047 EXPECT_TRUE(state.needs_redraw());
1039 1048
1040 // Expect to do nothing until BeginImplFrame deadline. 1049 // Expect to do nothing until BeginImplFrame deadline.
1041 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1050 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1042 1051
1043 // At BeginImplFrame deadline, draw. 1052 // At BeginImplFrame deadline, draw.
1044 state.OnBeginImplFrameDeadline(); 1053 state.OnBeginImplFrameDeadline();
1045 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1054 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1046 EXPECT_ACTION_UPDATE_STATE( 1055 EXPECT_ACTION_UPDATE_STATE(
1047 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1056 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1048 state.DidSwapBuffers(); 1057 state.DidSwapBuffers();
1049 state.DidDrawIfPossibleCompleted(DRAW_SUCCESS); 1058 state.DidDrawIfPossibleCompleted(DRAW_SUCCESS);
1050 state.DidSwapBuffersComplete(); 1059 state.DidSwapBuffersComplete();
1051 1060
1052 // Should be synchronized, no draw needed, no action needed. 1061 // Should be synchronized, no draw needed, no action needed.
1053 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1062 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1054 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1063 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE);
1055 EXPECT_FALSE(state.needs_redraw()); 1064 EXPECT_FALSE(state.needs_redraw());
1056 1065
1057 // Next BeginImplFrame should initiate second commit. 1066 // Next BeginImplFrame should initiate second commit.
1058 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1067 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1059 EXPECT_ACTION_UPDATE_STATE( 1068 EXPECT_ACTION_UPDATE_STATE(
1060 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1069 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1061 } 1070 }
1062 1071
1063 TEST(SchedulerStateMachineTest, TestRequestCommitInvisible) { 1072 TEST(SchedulerStateMachineTest, TestRequestCommitInvisible) {
1064 SchedulerSettings default_scheduler_settings; 1073 SchedulerSettings default_scheduler_settings;
(...skipping 14 matching lines...) Expand all
1079 state.SetVisible(true); 1088 state.SetVisible(true);
1080 state.SetCanDraw(true); 1089 state.SetCanDraw(true);
1081 1090
1082 // Start clean and set commit. 1091 // Start clean and set commit.
1083 state.SetNeedsCommit(); 1092 state.SetNeedsCommit();
1084 1093
1085 // Begin the frame while visible. 1094 // Begin the frame while visible.
1086 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1095 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1087 EXPECT_ACTION_UPDATE_STATE( 1096 EXPECT_ACTION_UPDATE_STATE(
1088 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1097 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1089 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 1098 EXPECT_COMMIT_STATE(
1090 state.CommitState()); 1099 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT);
1091 EXPECT_FALSE(state.NeedsCommit()); 1100 EXPECT_FALSE(state.NeedsCommit());
1092 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1101 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1093 1102
1094 // Become invisible and abort BeginMainFrame. 1103 // Become invisible and abort BeginMainFrame.
1095 state.SetVisible(false); 1104 state.SetVisible(false);
1096 state.BeginMainFrameAborted(false); 1105 state.BeginMainFrameAborted(false);
1097 1106
1098 // We should now be back in the idle state as if we never started the frame. 1107 // We should now be back in the idle state as if we never started the frame.
1099 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1108 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE);
1100 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1109 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1101 1110
1102 // We shouldn't do anything on the BeginImplFrame deadline. 1111 // We shouldn't do anything on the BeginImplFrame deadline.
1103 state.OnBeginImplFrameDeadline(); 1112 state.OnBeginImplFrameDeadline();
1104 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1113 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1105 1114
1106 // Become visible again. 1115 // Become visible again.
1107 state.SetVisible(true); 1116 state.SetVisible(true);
1108 1117
1109 // Although we have aborted on this frame and haven't cancelled the commit 1118 // Although we have aborted on this frame and haven't cancelled the commit
1110 // (i.e. need another), don't send another BeginMainFrame yet. 1119 // (i.e. need another), don't send another BeginMainFrame yet.
1111 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1120 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE);
1112 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1121 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1113 EXPECT_TRUE(state.NeedsCommit()); 1122 EXPECT_TRUE(state.NeedsCommit());
1114 1123
1115 // Start a new frame. 1124 // Start a new frame.
1116 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1125 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1117 EXPECT_ACTION_UPDATE_STATE( 1126 EXPECT_ACTION_UPDATE_STATE(
1118 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1127 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1119 1128
1120 // We should be starting the commit now. 1129 // We should be starting the commit now.
1121 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 1130 EXPECT_COMMIT_STATE(
1122 state.CommitState()); 1131 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT);
1123 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1132 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1124 } 1133 }
1125 1134
1126 TEST(SchedulerStateMachineTest, AbortBeginMainFrameAndCancelCommit) { 1135 TEST(SchedulerStateMachineTest, AbortBeginMainFrameAndCancelCommit) {
1127 SchedulerSettings default_scheduler_settings; 1136 SchedulerSettings default_scheduler_settings;
1128 StateMachine state(default_scheduler_settings); 1137 StateMachine state(default_scheduler_settings);
1129 state.SetCanStart(); 1138 state.SetCanStart();
1130 state.UpdateState(state.NextAction()); 1139 state.UpdateState(state.NextAction());
1131 state.DidCreateAndInitializeOutputSurface(); 1140 state.DidCreateAndInitializeOutputSurface();
1132 state.SetVisible(true); 1141 state.SetVisible(true);
1133 state.SetCanDraw(true); 1142 state.SetCanDraw(true);
1134 1143
1135 // Get into a begin frame / commit state. 1144 // Get into a begin frame / commit state.
1136 state.SetNeedsCommit(); 1145 state.SetNeedsCommit();
1137 1146
1138 EXPECT_ACTION_UPDATE_STATE( 1147 EXPECT_ACTION_UPDATE_STATE(
1139 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1148 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1140 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 1149 EXPECT_COMMIT_STATE(
1141 state.CommitState()); 1150 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT);
1142 EXPECT_FALSE(state.NeedsCommit()); 1151 EXPECT_FALSE(state.NeedsCommit());
1143 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1152 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1144 1153
1145 // Abort the commit, cancelling future commits. 1154 // Abort the commit, cancelling future commits.
1146 state.BeginMainFrameAborted(true); 1155 state.BeginMainFrameAborted(true);
1147 1156
1148 // Verify that another commit doesn't start on the same frame. 1157 // Verify that another commit doesn't start on the same frame.
1149 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1158 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE);
1150 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1159 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1151 EXPECT_FALSE(state.NeedsCommit()); 1160 EXPECT_FALSE(state.NeedsCommit());
1152 1161
1153 // Start a new frame; draw because this is the first frame since output 1162 // Start a new frame; draw because this is the first frame since output
1154 // surface init'd. 1163 // surface init'd.
1155 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1164 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1156 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1165 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1157 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1166 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1158 state.OnBeginImplFrameDeadline(); 1167 state.OnBeginImplFrameDeadline();
1159 EXPECT_ACTION_UPDATE_STATE( 1168 EXPECT_ACTION_UPDATE_STATE(
1160 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1169 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1161 state.DidSwapBuffers(); 1170 state.DidSwapBuffers();
1162 state.DidSwapBuffersComplete(); 1171 state.DidSwapBuffersComplete();
1163 1172
1164 // Verify another commit doesn't start on another frame either. 1173 // Verify another commit doesn't start on another frame either.
1165 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1174 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE);
1166 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1175 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1167 EXPECT_FALSE(state.NeedsCommit()); 1176 EXPECT_FALSE(state.NeedsCommit());
1168 1177
1169 // Verify another commit can start if requested, though. 1178 // Verify another commit can start if requested, though.
1170 state.SetNeedsCommit(); 1179 state.SetNeedsCommit();
1171 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1180 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE);
1172 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME, 1181 EXPECT_ACTION(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1173 state.NextAction());
1174 } 1182 }
1175 1183
1176 TEST(SchedulerStateMachineTest, 1184 TEST(SchedulerStateMachineTest,
1177 AbortBeginMainFrameAndCancelCommitWhenInvisible) { 1185 AbortBeginMainFrameAndCancelCommitWhenInvisible) {
1178 SchedulerSettings default_scheduler_settings; 1186 SchedulerSettings default_scheduler_settings;
1179 StateMachine state(default_scheduler_settings); 1187 StateMachine state(default_scheduler_settings);
1180 state.SetCanStart(); 1188 state.SetCanStart();
1181 state.UpdateState(state.NextAction()); 1189 state.UpdateState(state.NextAction());
1182 state.DidCreateAndInitializeOutputSurface(); 1190 state.DidCreateAndInitializeOutputSurface();
1183 state.SetVisible(true); 1191 state.SetVisible(true);
1184 state.SetCanDraw(true); 1192 state.SetCanDraw(true);
1185 1193
1186 // Get into a begin frame / commit state. 1194 // Get into a begin frame / commit state.
1187 state.SetNeedsCommit(); 1195 state.SetNeedsCommit();
1188 1196
1189 EXPECT_ACTION_UPDATE_STATE( 1197 EXPECT_ACTION_UPDATE_STATE(
1190 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1198 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1191 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 1199 EXPECT_COMMIT_STATE(
1192 state.CommitState()); 1200 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT);
1193 EXPECT_FALSE(state.NeedsCommit()); 1201 EXPECT_FALSE(state.NeedsCommit());
1194 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1202 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1195 1203
1196 // Become invisible and abort BeginMainFrame. 1204 // Become invisible and abort BeginMainFrame.
1197 state.SetVisible(false); 1205 state.SetVisible(false);
1198 state.BeginMainFrameAborted(true); 1206 state.BeginMainFrameAborted(true);
1199 1207
1200 // Verify that another commit doesn't start on the same frame. 1208 // Verify that another commit doesn't start on the same frame.
1201 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1209 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE);
1202 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1210 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1203 EXPECT_FALSE(state.NeedsCommit()); 1211 EXPECT_FALSE(state.NeedsCommit());
1204 1212
1205 // Become visible and start a new frame. 1213 // Become visible and start a new frame.
1206 state.SetVisible(true); 1214 state.SetVisible(true);
1207 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1215 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1208 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1216 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1209 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1217 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1210 1218
1211 // Draw because this is the first frame since output surface init'd. 1219 // Draw because this is the first frame since output surface init'd.
1212 state.OnBeginImplFrameDeadline(); 1220 state.OnBeginImplFrameDeadline();
1213 EXPECT_ACTION_UPDATE_STATE( 1221 EXPECT_ACTION_UPDATE_STATE(
1214 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1222 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1215 state.DidSwapBuffers(); 1223 state.DidSwapBuffers();
1216 state.DidSwapBuffersComplete(); 1224 state.DidSwapBuffersComplete();
1217 1225
1218 // Verify another commit doesn't start on another frame either. 1226 // Verify another commit doesn't start on another frame either.
1219 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1227 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE);
1220 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1228 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1221 EXPECT_FALSE(state.NeedsCommit()); 1229 EXPECT_FALSE(state.NeedsCommit());
1222 1230
1223 // Verify another commit can start if requested, though. 1231 // Verify another commit can start if requested, though.
1224 state.SetNeedsCommit(); 1232 state.SetNeedsCommit();
1225 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1233 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE);
1226 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME, 1234 EXPECT_ACTION(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1227 state.NextAction());
1228 } 1235 }
1229 1236
1230 TEST(SchedulerStateMachineTest, 1237 TEST(SchedulerStateMachineTest,
1231 AbortBeginMainFrameAndRequestCommitWhenInvisible) { 1238 AbortBeginMainFrameAndRequestCommitWhenInvisible) {
1232 SchedulerSettings default_scheduler_settings; 1239 SchedulerSettings default_scheduler_settings;
1233 StateMachine state(default_scheduler_settings); 1240 StateMachine state(default_scheduler_settings);
1234 state.SetCanStart(); 1241 state.SetCanStart();
1235 state.UpdateState(state.NextAction()); 1242 state.UpdateState(state.NextAction());
1236 state.DidCreateAndInitializeOutputSurface(); 1243 state.DidCreateAndInitializeOutputSurface();
1237 state.SetVisible(true); 1244 state.SetVisible(true);
1238 state.SetCanDraw(true); 1245 state.SetCanDraw(true);
1239 1246
1240 // Get into a begin frame / commit state. 1247 // Get into a begin frame / commit state.
1241 state.SetNeedsCommit(); 1248 state.SetNeedsCommit();
1242 1249
1243 EXPECT_ACTION_UPDATE_STATE( 1250 EXPECT_ACTION_UPDATE_STATE(
1244 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1251 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1245 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 1252 EXPECT_COMMIT_STATE(
1246 state.CommitState()); 1253 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT);
1247 EXPECT_FALSE(state.NeedsCommit()); 1254 EXPECT_FALSE(state.NeedsCommit());
1248 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1255 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1249 1256
1250 // Become invisible and abort BeginMainFrame. 1257 // Become invisible and abort BeginMainFrame.
1251 state.SetVisible(false); 1258 state.SetVisible(false);
1252 state.BeginMainFrameAborted(true); 1259 state.BeginMainFrameAborted(true);
1253 1260
1254 // Verify that another commit doesn't start on the same frame. 1261 // Verify that another commit doesn't start on the same frame.
1255 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1262 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE);
1256 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1263 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1257 EXPECT_FALSE(state.NeedsCommit()); 1264 EXPECT_FALSE(state.NeedsCommit());
1258 1265
1259 // Asking for a commit while not visible won't make it happen. 1266 // Asking for a commit while not visible won't make it happen.
1260 state.SetNeedsCommit(); 1267 state.SetNeedsCommit();
1261 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1268 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE);
1262 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1269 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1263 EXPECT_TRUE(state.NeedsCommit()); 1270 EXPECT_TRUE(state.NeedsCommit());
1264 1271
1265 // Become visible but nothing happens until the next frame. 1272 // Become visible but nothing happens until the next frame.
1266 state.SetVisible(true); 1273 state.SetVisible(true);
1267 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1274 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE);
1268 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1275 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1269 EXPECT_TRUE(state.NeedsCommit()); 1276 EXPECT_TRUE(state.NeedsCommit());
1270 1277
1271 // We should get that commit when we begin the next frame. 1278 // We should get that commit when we begin the next frame.
1272 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1279 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1273 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1280 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1274 EXPECT_ACTION_UPDATE_STATE( 1281 EXPECT_ACTION_UPDATE_STATE(
1275 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1282 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1276 } 1283 }
1277 1284
1278 TEST(SchedulerStateMachineTest, 1285 TEST(SchedulerStateMachineTest,
1279 AbortBeginMainFrameAndRequestCommitAndBeginImplFrameWhenInvisible) { 1286 AbortBeginMainFrameAndRequestCommitAndBeginImplFrameWhenInvisible) {
1280 SchedulerSettings default_scheduler_settings; 1287 SchedulerSettings default_scheduler_settings;
1281 StateMachine state(default_scheduler_settings); 1288 StateMachine state(default_scheduler_settings);
1282 state.SetCanStart(); 1289 state.SetCanStart();
1283 state.UpdateState(state.NextAction()); 1290 state.UpdateState(state.NextAction());
1284 state.DidCreateAndInitializeOutputSurface(); 1291 state.DidCreateAndInitializeOutputSurface();
1285 state.SetVisible(true); 1292 state.SetVisible(true);
1286 state.SetCanDraw(true); 1293 state.SetCanDraw(true);
1287 1294
1288 // Get into a begin frame / commit state. 1295 // Get into a begin frame / commit state.
1289 state.SetNeedsCommit(); 1296 state.SetNeedsCommit();
1290 1297
1291 EXPECT_ACTION_UPDATE_STATE( 1298 EXPECT_ACTION_UPDATE_STATE(
1292 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1299 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1293 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 1300 EXPECT_COMMIT_STATE(
1294 state.CommitState()); 1301 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT);
1295 EXPECT_FALSE(state.NeedsCommit()); 1302 EXPECT_FALSE(state.NeedsCommit());
1296 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1303 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1297 1304
1298 // Become invisible and abort BeginMainFrame. 1305 // Become invisible and abort BeginMainFrame.
1299 state.SetVisible(false); 1306 state.SetVisible(false);
1300 state.BeginMainFrameAborted(true); 1307 state.BeginMainFrameAborted(true);
1301 1308
1302 // Asking for a commit while not visible won't make it happen. 1309 // Asking for a commit while not visible won't make it happen.
1303 state.SetNeedsCommit(); 1310 state.SetNeedsCommit();
1304 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1311 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE);
1305 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1312 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1306 EXPECT_TRUE(state.NeedsCommit()); 1313 EXPECT_TRUE(state.NeedsCommit());
1307 1314
1308 // Begin a frame when not visible, the scheduler animates but does not commit. 1315 // Begin a frame when not visible, the scheduler animates but does not commit.
1309 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1316 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1310 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1317 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE);
1311 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1318 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1312 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1319 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1313 EXPECT_TRUE(state.NeedsCommit()); 1320 EXPECT_TRUE(state.NeedsCommit());
1314 1321
1315 // Become visible and the requested commit happens immediately. 1322 // Become visible and the requested commit happens immediately.
1316 state.SetVisible(true); 1323 state.SetVisible(true);
1317 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1324 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE);
1318 EXPECT_ACTION_UPDATE_STATE( 1325 EXPECT_ACTION_UPDATE_STATE(
1319 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1326 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1320 } 1327 }
1321 1328
1322 TEST(SchedulerStateMachineTest, TestFirstContextCreation) { 1329 TEST(SchedulerStateMachineTest, TestFirstContextCreation) {
1323 SchedulerSettings default_scheduler_settings; 1330 SchedulerSettings default_scheduler_settings;
1324 StateMachine state(default_scheduler_settings); 1331 StateMachine state(default_scheduler_settings);
1325 state.SetCanStart(); 1332 state.SetCanStart();
1326 state.SetVisible(true); 1333 state.SetVisible(true);
1327 state.SetCanDraw(true); 1334 state.SetCanDraw(true);
(...skipping 23 matching lines...) Expand all
1351 state.UpdateState(state.NextAction()); 1358 state.UpdateState(state.NextAction());
1352 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1359 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1353 1360
1354 state.SetVisible(true); 1361 state.SetVisible(true);
1355 state.SetCanDraw(true); 1362 state.SetCanDraw(true);
1356 1363
1357 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1364 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1358 state.NextAction()); 1365 state.NextAction());
1359 state.DidLoseOutputSurface(); 1366 state.DidLoseOutputSurface();
1360 1367
1361 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1368 EXPECT_ACTION(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1362 state.NextAction());
1363 state.UpdateState(state.NextAction()); 1369 state.UpdateState(state.NextAction());
1364 1370
1365 // Once context recreation begins, nothing should happen. 1371 // Once context recreation begins, nothing should happen.
1366 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1372 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1367 1373
1368 // Recreate the context. 1374 // Recreate the context.
1369 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1375 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1370 1376
1371 // When the context is recreated, we should begin a commit. 1377 // When the context is recreated, we should begin a commit.
1372 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1378 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1412 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1407 1413
1408 // Recreate the context 1414 // Recreate the context
1409 state.DidCreateAndInitializeOutputSurface(); 1415 state.DidCreateAndInitializeOutputSurface();
1410 EXPECT_FALSE(state.RedrawPending()); 1416 EXPECT_FALSE(state.RedrawPending());
1411 1417
1412 // When the context is recreated, we should begin a commit 1418 // When the context is recreated, we should begin a commit
1413 EXPECT_ACTION_UPDATE_STATE( 1419 EXPECT_ACTION_UPDATE_STATE(
1414 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1420 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1415 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1421 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1416 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT, 1422 EXPECT_COMMIT_STATE(
1417 state.CommitState()); 1423 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT);
1418 1424
1419 state.NotifyBeginMainFrameStarted(); 1425 state.NotifyBeginMainFrameStarted();
1420 state.NotifyReadyToCommit(); 1426 state.NotifyReadyToCommit();
1421 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1427 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1422 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1428 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1423 // Finishing the first commit after initializing an output surface should 1429 // Finishing the first commit after initializing an output surface should
1424 // automatically cause a redraw. 1430 // automatically cause a redraw.
1425 EXPECT_TRUE(state.RedrawPending()); 1431 EXPECT_TRUE(state.RedrawPending());
1426 1432
1427 // Once the context is recreated, whether we draw should be based on 1433 // Once the context is recreated, whether we draw should be based on
1428 // SetCanDraw. 1434 // SetCanDraw.
1429 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1435 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1430 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1436 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1431 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1437 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1432 state.OnBeginImplFrameDeadline(); 1438 state.OnBeginImplFrameDeadline();
1433 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 1439 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1434 state.NextAction());
1435 state.SetCanDraw(false); 1440 state.SetCanDraw(false);
1436 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT, 1441 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1437 state.NextAction());
1438 state.SetCanDraw(true); 1442 state.SetCanDraw(true);
1439 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 1443 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1440 state.NextAction());
1441 } 1444 }
1442 1445
1443 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) { 1446 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) {
1444 SchedulerSettings scheduler_settings; 1447 SchedulerSettings scheduler_settings;
1445 StateMachine state(scheduler_settings); 1448 StateMachine state(scheduler_settings);
1446 state.SetCanStart(); 1449 state.SetCanStart();
1447 state.UpdateState(state.NextAction()); 1450 state.UpdateState(state.NextAction());
1448 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1451 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1449 state.SetVisible(true); 1452 state.SetVisible(true);
1450 state.SetCanDraw(true); 1453 state.SetCanDraw(true);
(...skipping 13 matching lines...) Expand all
1464 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1467 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1465 state.DidSwapBuffers(); 1468 state.DidSwapBuffers();
1466 state.DidSwapBuffersComplete(); 1469 state.DidSwapBuffersComplete();
1467 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1470 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1468 1471
1469 // Cause a lost context while the BeginMainFrame is in flight. 1472 // Cause a lost context while the BeginMainFrame is in flight.
1470 state.DidLoseOutputSurface(); 1473 state.DidLoseOutputSurface();
1471 1474
1472 // Ask for another draw. Expect nothing happens. 1475 // Ask for another draw. Expect nothing happens.
1473 state.SetNeedsRedraw(true); 1476 state.SetNeedsRedraw(true);
1474 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1477 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1475 1478
1476 // Finish the frame, and commit. 1479 // Finish the frame, and commit.
1477 state.NotifyBeginMainFrameStarted(); 1480 state.NotifyBeginMainFrameStarted();
1478 state.NotifyReadyToCommit(); 1481 state.NotifyReadyToCommit();
1479 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1482 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1480 1483
1481 // We will abort the draw when the output surface is lost if we are 1484 // We will abort the draw when the output surface is lost if we are
1482 // waiting for the first draw to unblock the main thread. 1485 // waiting for the first draw to unblock the main thread.
1483 EXPECT_TRUE(state.active_tree_needs_first_draw()); 1486 EXPECT_TRUE(state.active_tree_needs_first_draw());
1484 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1487 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1485 1488
1486 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE 1489 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE
1487 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, 1490 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
1488 state.begin_impl_frame_state()); 1491 EXPECT_ACTION(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1489 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1490 state.NextAction());
1491 1492
1492 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1493 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1493 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING, 1494 EXPECT_IMPL_FRAME_STATE(
1494 state.begin_impl_frame_state()); 1495 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING);
1495 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1496 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1496 1497
1497 state.OnBeginImplFrameDeadlinePending(); 1498 state.OnBeginImplFrameDeadlinePending();
1498 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME, 1499 EXPECT_IMPL_FRAME_STATE(
1499 state.begin_impl_frame_state()); 1500 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME);
1500 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1501 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1501 1502
1502 state.OnBeginImplFrameDeadline(); 1503 state.OnBeginImplFrameDeadline();
1503 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, 1504 EXPECT_IMPL_FRAME_STATE(
1504 state.begin_impl_frame_state()); 1505 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE);
1505 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1506 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1506 } 1507 }
1507 1508
1508 TEST(SchedulerStateMachineTest, 1509 TEST(SchedulerStateMachineTest,
1509 TestContextLostWhileCommitInProgressAndAnotherCommitRequested) { 1510 TestContextLostWhileCommitInProgressAndAnotherCommitRequested) {
1510 SchedulerSettings scheduler_settings; 1511 SchedulerSettings scheduler_settings;
1511 StateMachine state(scheduler_settings); 1512 StateMachine state(scheduler_settings);
1512 state.SetCanStart(); 1513 state.SetCanStart();
1513 state.UpdateState(state.NextAction()); 1514 state.UpdateState(state.NextAction());
1514 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1515 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1515 state.SetVisible(true); 1516 state.SetVisible(true);
(...skipping 28 matching lines...) Expand all
1544 // Finish the frame, and commit. 1545 // Finish the frame, and commit.
1545 state.NotifyBeginMainFrameStarted(); 1546 state.NotifyBeginMainFrameStarted();
1546 state.NotifyReadyToCommit(); 1547 state.NotifyReadyToCommit();
1547 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1548 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1548 EXPECT_TRUE(state.active_tree_needs_first_draw()); 1549 EXPECT_TRUE(state.active_tree_needs_first_draw());
1549 1550
1550 // Because the output surface is missing, we expect the draw to abort. 1551 // Because the output surface is missing, we expect the draw to abort.
1551 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1552 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1552 1553
1553 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE 1554 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE
1554 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, 1555 EXPECT_IMPL_FRAME_STATE(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
1555 state.begin_impl_frame_state()); 1556 EXPECT_ACTION(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1556 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1557 state.NextAction());
1558 1557
1559 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1558 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1560 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING, 1559 EXPECT_IMPL_FRAME_STATE(
1561 state.begin_impl_frame_state()); 1560 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING);
1562 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1561 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1563 1562
1564 state.OnBeginImplFrameDeadlinePending(); 1563 state.OnBeginImplFrameDeadlinePending();
1565 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME, 1564 EXPECT_IMPL_FRAME_STATE(
1566 state.begin_impl_frame_state()); 1565 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME);
1567 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1566 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1568 1567
1569 state.OnBeginImplFrameDeadline(); 1568 state.OnBeginImplFrameDeadline();
1570 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE, 1569 EXPECT_IMPL_FRAME_STATE(
1571 state.begin_impl_frame_state()); 1570 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE);
1572 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1571 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1573 1572
1574 state.OnBeginImplFrameIdle(); 1573 state.OnBeginImplFrameIdle();
1575 EXPECT_ACTION_UPDATE_STATE( 1574 EXPECT_ACTION_UPDATE_STATE(
1576 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 1575 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1577 1576
1578 // After we get a new output surface, the commit flow should start. 1577 // After we get a new output surface, the commit flow should start.
1579 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1578 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1580 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1579 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1581 EXPECT_ACTION_UPDATE_STATE( 1580 EXPECT_ACTION_UPDATE_STATE(
1582 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1581 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
(...skipping 17 matching lines...) Expand all
1600 state.SetCanStart(); 1599 state.SetCanStart();
1601 state.UpdateState(state.NextAction()); 1600 state.UpdateState(state.NextAction());
1602 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1601 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1603 state.SetVisible(true); 1602 state.SetVisible(true);
1604 state.SetCanDraw(true); 1603 state.SetCanDraw(true);
1605 1604
1606 state.SetNeedsRedraw(true); 1605 state.SetNeedsRedraw(true);
1607 1606
1608 // Cause a lost output surface, and restore it. 1607 // Cause a lost output surface, and restore it.
1609 state.DidLoseOutputSurface(); 1608 state.DidLoseOutputSurface();
1610 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1609 EXPECT_ACTION(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1611 state.NextAction());
1612 state.UpdateState(state.NextAction()); 1610 state.UpdateState(state.NextAction());
1613 state.DidCreateAndInitializeOutputSurface(); 1611 state.DidCreateAndInitializeOutputSurface();
1614 1612
1615 EXPECT_FALSE(state.RedrawPending()); 1613 EXPECT_FALSE(state.RedrawPending());
1616 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1614 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1617 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME, 1615 EXPECT_ACTION(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1618 state.NextAction());
1619 } 1616 }
1620 1617
1621 TEST(SchedulerStateMachineTest, 1618 TEST(SchedulerStateMachineTest,
1622 TestPendingActivationsShouldBeForcedAfterLostOutputSurface) { 1619 TestPendingActivationsShouldBeForcedAfterLostOutputSurface) {
1623 SchedulerSettings settings; 1620 SchedulerSettings settings;
1624 settings.impl_side_painting = true; 1621 settings.impl_side_painting = true;
1625 StateMachine state(settings); 1622 StateMachine state(settings);
1626 state.SetCanStart(); 1623 state.SetCanStart();
1627 state.UpdateState(state.NextAction()); 1624 state.UpdateState(state.NextAction());
1628 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1625 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
(...skipping 18 matching lines...) Expand all
1647 } 1644 }
1648 1645
1649 TEST(SchedulerStateMachineTest, TestNoBeginMainFrameWhenInvisible) { 1646 TEST(SchedulerStateMachineTest, TestNoBeginMainFrameWhenInvisible) {
1650 SchedulerSettings default_scheduler_settings; 1647 SchedulerSettings default_scheduler_settings;
1651 StateMachine state(default_scheduler_settings); 1648 StateMachine state(default_scheduler_settings);
1652 state.SetCanStart(); 1649 state.SetCanStart();
1653 state.UpdateState(state.NextAction()); 1650 state.UpdateState(state.NextAction());
1654 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1651 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1655 state.SetVisible(false); 1652 state.SetVisible(false);
1656 state.SetNeedsCommit(); 1653 state.SetNeedsCommit();
1657 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1654 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1658 } 1655 }
1659 1656
1660 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) { 1657 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) {
1661 SchedulerSettings default_scheduler_settings; 1658 SchedulerSettings default_scheduler_settings;
1662 StateMachine state(default_scheduler_settings); 1659 StateMachine state(default_scheduler_settings);
1663 state.SetCanStart(); 1660 state.SetCanStart();
1664 state.UpdateState(state.NextAction()); 1661 state.UpdateState(state.NextAction());
1665 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1662 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1666 state.SetVisible(false); 1663 state.SetVisible(false);
1667 state.SetCommitState( 1664 state.SetCommitState(
1668 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT); 1665 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT);
1669 state.SetNeedsCommit(); 1666 state.SetNeedsCommit();
1670 1667
1671 state.NotifyBeginMainFrameStarted(); 1668 state.NotifyBeginMainFrameStarted();
1672 state.NotifyReadyToCommit(); 1669 state.NotifyReadyToCommit();
1673 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 1670 EXPECT_ACTION(SchedulerStateMachine::ACTION_COMMIT);
1674 state.UpdateState(state.NextAction()); 1671 state.UpdateState(state.NextAction());
1675 1672
1676 EXPECT_TRUE(state.active_tree_needs_first_draw()); 1673 EXPECT_TRUE(state.active_tree_needs_first_draw());
1677 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1674 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1678 } 1675 }
1679 1676
1680 TEST(SchedulerStateMachineTest, TestInitialActionsWhenContextLost) { 1677 TEST(SchedulerStateMachineTest, TestInitialActionsWhenContextLost) {
1681 SchedulerSettings default_scheduler_settings; 1678 SchedulerSettings default_scheduler_settings;
1682 StateMachine state(default_scheduler_settings); 1679 StateMachine state(default_scheduler_settings);
1683 state.SetCanStart(); 1680 state.SetCanStart();
(...skipping 10 matching lines...) Expand all
1694 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 1691 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1695 1692
1696 state.DidCreateAndInitializeOutputSurface(); 1693 state.DidCreateAndInitializeOutputSurface();
1697 EXPECT_EQ(state.output_surface_state(), 1694 EXPECT_EQ(state.output_surface_state(),
1698 SchedulerStateMachine::OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT); 1695 SchedulerStateMachine::OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT);
1699 1696
1700 // We should not send a BeginMainFrame when we are invisible, even if we've 1697 // We should not send a BeginMainFrame when we are invisible, even if we've
1701 // lost the output surface and are trying to get the first commit, since the 1698 // lost the output surface and are trying to get the first commit, since the
1702 // main thread will just abort anyway. 1699 // main thread will just abort anyway.
1703 state.SetVisible(false); 1700 state.SetVisible(false);
1704 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()) 1701 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1705 << state.AsValue()->ToString();
1706 } 1702 }
1707 1703
1708 TEST(SchedulerStateMachineTest, ReportIfNotDrawing) { 1704 TEST(SchedulerStateMachineTest, ReportIfNotDrawing) {
1709 SchedulerSettings default_scheduler_settings; 1705 SchedulerSettings default_scheduler_settings;
1710 StateMachine state(default_scheduler_settings); 1706 StateMachine state(default_scheduler_settings);
1711 state.SetCanStart(); 1707 state.SetCanStart();
1712 state.UpdateState(state.NextAction()); 1708 state.UpdateState(state.NextAction());
1713 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1709 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1714 1710
1715 state.SetCanDraw(true); 1711 state.SetCanDraw(true);
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
1996 state.SetVisible(true); 1992 state.SetVisible(true);
1997 state.SetCanDraw(true); 1993 state.SetCanDraw(true);
1998 1994
1999 EXPECT_FALSE(state.BeginFrameNeeded()); 1995 EXPECT_FALSE(state.BeginFrameNeeded());
2000 state.SetChildrenNeedBeginFrames(true); 1996 state.SetChildrenNeedBeginFrames(true);
2001 EXPECT_TRUE(state.BeginFrameNeeded()); 1997 EXPECT_TRUE(state.BeginFrameNeeded());
2002 } 1998 }
2003 1999
2004 } // namespace 2000 } // namespace
2005 } // namespace cc 2001 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler.cc ('k') | cc/surfaces/display.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698