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

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: sami's suggestions Created 6 years, 9 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 state.UpdateState(state.NextAction()); 169 state.UpdateState(state.NextAction());
176 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 170 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
177 state.SetVisible(true); 171 state.SetVisible(true);
178 state.UpdateState(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 172 state.UpdateState(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
179 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 173 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
180 state.CommitState()); 174 state.CommitState());
181 EXPECT_FALSE(state.NeedsCommit()); 175 EXPECT_FALSE(state.NeedsCommit());
182 } 176 }
183 } 177 }
184 178
179 // start_commit_before_activate_enabled = true
180 TEST(SchedulerStateMachineTest, StartCommitBeforeActivateEnabled) {
181 SchedulerSettings scheduler_settings;
182 scheduler_settings.impl_side_painting = true;
183 scheduler_settings.start_commit_before_activate_enabled = true;
184 StateMachine state(scheduler_settings);
185 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE);
186 state.SetCanStart();
187 state.UpdateState(state.NextAction());
188 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
189 state.SetNeedsRedraw(false);
190 state.SetVisible(true);
191 state.SetCanDraw(true);
192 state.SetNeedsCommit();
193
194 EXPECT_TRUE(state.BeginImplFrameNeeded());
195
196 // Commit to the pending tree.
197 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
198 EXPECT_ACTION_UPDATE_STATE(
199 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
200 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
201 state.FinishCommit();
202 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
203 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
204 state.OnBeginImplFrameDeadline();
205 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
206
207 // Verify that the next commit starts while there is still a pending tree.
208 state.SetNeedsCommit();
209 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
210 EXPECT_ACTION_UPDATE_STATE(
211 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
212 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
213
214 // Verify the pending commit doesn't overwrite the pending
215 // tree until the pending tree has been activated.
216 state.FinishCommit();
217 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
218
219 // Verify NotifyReadyToActivate unblocks activation, draw, and
220 // commit in that order.
221 state.NotifyReadyToActivate();
222 EXPECT_ACTION_UPDATE_STATE(
223 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE);
224 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
225
226 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly());
227 state.OnBeginImplFrameDeadline();
228 EXPECT_ACTION_UPDATE_STATE(
229 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
230 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
231 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
232 }
233
185 TEST(SchedulerStateMachineTest, 234 TEST(SchedulerStateMachineTest,
186 TestFailedDrawForAnimationCheckerboardSetsNeedsCommitAndDoesNotDrawAgain) { 235 TestFailedDrawForAnimationCheckerboardSetsNeedsCommitAndDoesNotDrawAgain) {
187 SchedulerSettings default_scheduler_settings; 236 SchedulerSettings default_scheduler_settings;
188 StateMachine state(default_scheduler_settings); 237 StateMachine state(default_scheduler_settings);
189 state.SetCanStart(); 238 state.SetCanStart();
190 state.UpdateState(state.NextAction()); 239 state.UpdateState(state.NextAction());
191 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 240 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
192 state.SetVisible(true); 241 state.SetVisible(true);
193 state.SetCanDraw(true); 242 state.SetCanDraw(true);
194 state.SetNeedsRedraw(true); 243 state.SetNeedsRedraw(true);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 371
323 // Finish the commit. Note, we should not yet be forcing a draw, but should 372 // Finish the commit. Note, we should not yet be forcing a draw, but should
324 // continue the commit as usual. 373 // continue the commit as usual.
325 state.FinishCommit(); 374 state.FinishCommit();
326 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 375 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
327 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 376 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
328 EXPECT_TRUE(state.RedrawPending()); 377 EXPECT_TRUE(state.RedrawPending());
329 378
330 // The redraw should be forced at the end of the next BeginImplFrame. 379 // The redraw should be forced at the end of the next BeginImplFrame.
331 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 380 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
381 EXPECT_ACTION_UPDATE_STATE(
382 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
332 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 383 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
333 state.OnBeginImplFrameDeadline(); 384 state.OnBeginImplFrameDeadline();
334 EXPECT_ACTION_UPDATE_STATE( 385 EXPECT_ACTION_UPDATE_STATE(
335 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED); 386 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED);
336 } 387 }
337 388
338 TEST(SchedulerStateMachineTest, TestFailedDrawsDoNotRestartForcedDraw) { 389 TEST(SchedulerStateMachineTest, TestFailedDrawsDoNotRestartForcedDraw) {
339 SchedulerSettings scheduler_settings; 390 SchedulerSettings scheduler_settings;
340 int draw_limit = 1; 391 int draw_limit = 1;
341 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced_ = 392 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced_ =
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 state.NextAction()); 559 state.NextAction());
509 560
510 // Case 2: needs_commit=true 561 // Case 2: needs_commit=true
511 state.SetNeedsCommit(); 562 state.SetNeedsCommit();
512 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 563 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
513 state.NextAction()) 564 state.NextAction())
514 << *state.AsValue(); 565 << *state.AsValue();
515 } 566 }
516 } 567 }
517 568
518 // When in BeginImplFrame deadline we should always draw for SetNeedsRedraw or 569 // When in BeginImplFrame deadline we should always draw for SetNeedsRedraw
519 // SetNeedsForcedRedrawForReadback have been called... except if we're 570 // except if we're ready to commit, in which case we expect a commit first.
520 // ready to commit, in which case we expect a commit first. 571 // SetNeedsForcedRedrawForReadback should take precedence over all and
572 // issue a readback.
521 for (size_t i = 0; i < num_commit_states; ++i) { 573 for (size_t i = 0; i < num_commit_states; ++i) {
522 for (size_t j = 0; j < 2; ++j) { 574 for (size_t j = 0; j < 2; ++j) {
523 bool request_readback = j; 575 bool request_readback = j;
524 576
525 // Skip invalid states
526 if (request_readback &&
527 (SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW !=
528 all_commit_states[i]))
529 continue;
530
531 StateMachine state(default_scheduler_settings); 577 StateMachine state(default_scheduler_settings);
532 state.SetCanStart(); 578 state.SetCanStart();
533 state.UpdateState(state.NextAction()); 579 state.UpdateState(state.NextAction());
534 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 580 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
535 state.SetCanDraw(true); 581 state.SetCanDraw(true);
536 state.SetCommitState(all_commit_states[i]); 582 state.SetCommitState(all_commit_states[i]);
537 state.SetBeginImplFrameState( 583 state.SetBeginImplFrameState(
538 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); 584 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE);
539 if (request_readback) { 585 if (request_readback) {
540 state.SetNeedsForcedRedrawForReadback(); 586 state.SetNeedsForcedRedrawForReadback();
541 } else { 587 } else {
542 state.SetNeedsRedraw(true); 588 state.SetNeedsRedraw(true);
543 state.SetVisible(true); 589 state.SetVisible(true);
544 } 590 }
545 591
546 SchedulerStateMachine::Action expected_action; 592 SchedulerStateMachine::Action expected_action;
547 if (all_commit_states[i] == 593 if (request_readback) {
548 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) { 594 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_READBACK;
595 } else if (all_commit_states[i] ==
596 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) {
549 expected_action = SchedulerStateMachine::ACTION_COMMIT; 597 expected_action = SchedulerStateMachine::ACTION_COMMIT;
550 } else if (request_readback) {
551 if (all_commit_states[i] ==
552 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW)
553 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_READBACK;
554 else
555 expected_action = SchedulerStateMachine::ACTION_NONE;
556 } else { 598 } else {
557 expected_action = 599 expected_action =
558 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE; 600 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE;
559 } 601 }
560 602
561 // Case 1: needs_commit=false. 603 // Case 1: needs_commit=false.
562 EXPECT_NE(state.BeginImplFrameNeeded(), request_readback) 604 EXPECT_NE(state.BeginImplFrameNeeded(), request_readback)
563 << *state.AsValue(); 605 << *state.AsValue();
564 EXPECT_EQ(expected_action, state.NextAction()) << *state.AsValue(); 606 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue();
565 607
566 // Case 2: needs_commit=true. 608 // Case 2: needs_commit=true.
567 state.SetNeedsCommit(); 609 state.SetNeedsCommit();
568 EXPECT_NE(state.BeginImplFrameNeeded(), request_readback) 610 EXPECT_NE(state.BeginImplFrameNeeded(), request_readback)
569 << *state.AsValue(); 611 << *state.AsValue();
570 EXPECT_EQ(expected_action, state.NextAction()) << *state.AsValue(); 612 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue();
571 } 613 }
572 } 614 }
573 } 615 }
574 616
575 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) { 617 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) {
576 SchedulerSettings default_scheduler_settings; 618 SchedulerSettings default_scheduler_settings;
577 619
578 size_t num_commit_states = 620 size_t num_commit_states =
579 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); 621 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState);
580 for (size_t i = 0; i < num_commit_states; ++i) { 622 for (size_t i = 0; i < num_commit_states; ++i) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 } 673 }
632 674
633 TEST(SchedulerStateMachineTest, 675 TEST(SchedulerStateMachineTest,
634 TestCanRedrawWithWaitingForFirstDrawMakesProgress) { 676 TestCanRedrawWithWaitingForFirstDrawMakesProgress) {
635 SchedulerSettings default_scheduler_settings; 677 SchedulerSettings default_scheduler_settings;
636 StateMachine state(default_scheduler_settings); 678 StateMachine state(default_scheduler_settings);
637 state.SetCanStart(); 679 state.SetCanStart();
638 state.UpdateState(state.NextAction()); 680 state.UpdateState(state.NextAction());
639 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 681 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
640 682
641 state.SetCommitState(
642 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
643 state.SetActiveTreeNeedsFirstDraw(true); 683 state.SetActiveTreeNeedsFirstDraw(true);
644 state.SetNeedsCommit(); 684 state.SetNeedsCommit();
645 state.SetNeedsRedraw(true); 685 state.SetNeedsRedraw(true);
646 state.SetVisible(true); 686 state.SetVisible(true);
647 state.SetCanDraw(false); 687 state.SetCanDraw(false);
648 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 688 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
649 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 689 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
650 EXPECT_ACTION_UPDATE_STATE( 690 EXPECT_ACTION_UPDATE_STATE(
651 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 691 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
652 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 692 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 state.OnBeginImplFrameIdle(); 743 state.OnBeginImplFrameIdle();
704 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, 744 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE,
705 state.begin_impl_frame_state()); 745 state.begin_impl_frame_state());
706 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 746 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
707 747
708 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 748 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
709 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING, 749 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING,
710 state.begin_impl_frame_state()); 750 state.begin_impl_frame_state());
711 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 751 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
712 752
713 // Commit and make sure we draw on next BeginImplFrame 753 // Finish the commit, then make sure we start the next commit immediately
754 // and draw on the next BeginImplFrame.
714 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 755 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
715 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
716 state.OnBeginImplFrameDeadline();
717 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW,
718 state.CommitState());
719 EXPECT_ACTION_UPDATE_STATE(
720 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
721 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
722
723 // Verify that another commit will start immediately after draw.
724 EXPECT_ACTION_UPDATE_STATE( 756 EXPECT_ACTION_UPDATE_STATE(
725 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 757 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
726 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 758 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
759
760 state.OnBeginImplFrameDeadline();
761
762 EXPECT_TRUE(state.active_tree_needs_first_draw());
763 EXPECT_ACTION_UPDATE_STATE(
764 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
765 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
766 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
727 } 767 }
728 768
729 TEST(SchedulerStateMachineTest, TestFullCycle) { 769 TEST(SchedulerStateMachineTest, TestFullCycle) {
730 SchedulerSettings default_scheduler_settings; 770 SchedulerSettings default_scheduler_settings;
731 StateMachine state(default_scheduler_settings); 771 StateMachine state(default_scheduler_settings);
732 state.SetCanStart(); 772 state.SetCanStart();
733 state.UpdateState(state.NextAction()); 773 state.UpdateState(state.NextAction());
734 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 774 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
735 state.SetVisible(true); 775 state.SetVisible(true);
736 state.SetCanDraw(true); 776 state.SetCanDraw(true);
(...skipping 10 matching lines...) Expand all
747 EXPECT_FALSE(state.NeedsCommit()); 787 EXPECT_FALSE(state.NeedsCommit());
748 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 788 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
749 789
750 // Tell the scheduler the frame finished. 790 // Tell the scheduler the frame finished.
751 state.FinishCommit(); 791 state.FinishCommit();
752 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 792 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
753 state.CommitState()); 793 state.CommitState());
754 794
755 // Commit. 795 // Commit.
756 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 796 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
757 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 797 EXPECT_TRUE(state.active_tree_needs_first_draw());
758 state.CommitState());
759 EXPECT_TRUE(state.needs_redraw()); 798 EXPECT_TRUE(state.needs_redraw());
760 799
761 // Expect to do nothing until BeginImplFrame deadline 800 // Expect to do nothing until BeginImplFrame deadline
762 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 801 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
763 802
764 // At BeginImplFrame deadline, draw. 803 // At BeginImplFrame deadline, draw.
765 state.OnBeginImplFrameDeadline(); 804 state.OnBeginImplFrameDeadline();
766 EXPECT_ACTION_UPDATE_STATE( 805 EXPECT_ACTION_UPDATE_STATE(
767 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 806 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
768 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 807 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
(...skipping 29 matching lines...) Expand all
798 state.SetNeedsCommit(); 837 state.SetNeedsCommit();
799 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 838 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
800 839
801 // Tell the scheduler the frame finished. 840 // Tell the scheduler the frame finished.
802 state.FinishCommit(); 841 state.FinishCommit();
803 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 842 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
804 state.CommitState()); 843 state.CommitState());
805 844
806 // First commit. 845 // First commit.
807 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 846 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
808 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 847 EXPECT_TRUE(state.active_tree_needs_first_draw());
809 state.CommitState());
810 EXPECT_TRUE(state.needs_redraw()); 848 EXPECT_TRUE(state.needs_redraw());
811 849
812 // Expect to do nothing until BeginImplFrame deadline. 850 // Expect to do nothing until BeginImplFrame deadline.
813 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 851 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
814 852
815 // At BeginImplFrame deadline, draw. 853 // At BeginImplFrame deadline, draw.
816 state.OnBeginImplFrameDeadline(); 854 state.OnBeginImplFrameDeadline();
817 EXPECT_ACTION_UPDATE_STATE( 855 EXPECT_ACTION_UPDATE_STATE(
818 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 856 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
819 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 857 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 // Ask for another draw. Expect nothing happens. 1124 // Ask for another draw. Expect nothing happens.
1087 state.SetNeedsRedraw(true); 1125 state.SetNeedsRedraw(true);
1088 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1126 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1089 1127
1090 // Finish the frame, and commit. 1128 // Finish the frame, and commit.
1091 state.FinishCommit(); 1129 state.FinishCommit();
1092 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1130 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1093 1131
1094 // We will abort the draw when the output surface is lost if we are 1132 // We will abort the draw when the output surface is lost if we are
1095 // waiting for the first draw to unblock the main thread. 1133 // waiting for the first draw to unblock the main thread.
1096 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1134 EXPECT_TRUE(state.active_tree_needs_first_draw());
1097 state.CommitState());
1098 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1135 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1099 1136
1100 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE 1137 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE
1101 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, 1138 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE,
1102 state.begin_impl_frame_state()); 1139 state.begin_impl_frame_state());
1103 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1140 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1104 state.NextAction()); 1141 state.NextAction());
1105 1142
1106 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1143 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
1107 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING, 1144 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 state.DidLoseOutputSurface(); 1185 state.DidLoseOutputSurface();
1149 1186
1150 // Ask for another draw and also set needs commit. Expect nothing happens. 1187 // Ask for another draw and also set needs commit. Expect nothing happens.
1151 state.SetNeedsRedraw(true); 1188 state.SetNeedsRedraw(true);
1152 state.SetNeedsCommit(); 1189 state.SetNeedsCommit();
1153 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1190 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1154 1191
1155 // Finish the frame, and commit. 1192 // Finish the frame, and commit.
1156 state.FinishCommit(); 1193 state.FinishCommit();
1157 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1194 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1158 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1195 EXPECT_TRUE(state.active_tree_needs_first_draw());
1159 state.CommitState());
1160 1196
1161 // Because the output surface is missing, we expect the draw to abort. 1197 // Because the output surface is missing, we expect the draw to abort.
1162 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1198 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1163 1199
1164 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE 1200 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE
1165 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, 1201 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE,
1166 state.begin_impl_frame_state()); 1202 state.begin_impl_frame_state());
1167 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1203 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1168 state.NextAction()); 1204 state.NextAction());
1169 1205
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1207 state.SetCanStart(); 1243 state.SetCanStart();
1208 state.UpdateState(state.NextAction()); 1244 state.UpdateState(state.NextAction());
1209 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1245 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1210 state.SetVisible(true); 1246 state.SetVisible(true);
1211 state.SetCanDraw(true); 1247 state.SetCanDraw(true);
1212 1248
1213 // Cause a lost context lost. 1249 // Cause a lost context lost.
1214 state.DidLoseOutputSurface(); 1250 state.DidLoseOutputSurface();
1215 1251
1216 // Ask a forced redraw for readback and verify it ocurrs. 1252 // Ask a forced redraw for readback and verify it ocurrs.
1217 state.SetCommitState(
1218 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
1219 state.SetNeedsForcedRedrawForReadback(); 1253 state.SetNeedsForcedRedrawForReadback();
1220 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1254 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
1221 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1255 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1222 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1256 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1223 1257
1224 // Forced redraws for readbacks need to be followed by a new commit 1258 // Forced redraws for readbacks need to be followed by a new commit
1225 // to replace the readback commit. 1259 // to replace the readback commit.
1226 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 1260 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
1227 state.CommitState()); 1261 state.CommitState());
1228 state.FinishCommit(); 1262 state.FinishCommit();
1229 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1263 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1230 1264
1231 // We don't yet have an output surface, so we the draw and swap should abort. 1265 // We don't yet have an output surface, so we the draw and swap should abort.
1232 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1266 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1233 1267
1234 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE 1268 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE
1235 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1269 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1236 1270
1237 state.OnBeginImplFrameDeadline(); 1271 state.OnBeginImplFrameDeadline();
1238 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1272 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1239 1273
1240 state.OnBeginImplFrameIdle(); 1274 state.OnBeginImplFrameIdle();
1241 EXPECT_ACTION_UPDATE_STATE( 1275 EXPECT_ACTION_UPDATE_STATE(
1242 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 1276 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1243 1277
1244 // Ask a readback and verify it occurs. 1278 // Ask a readback and verify it occurs.
1245 state.SetCommitState(
1246 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
1247 state.SetNeedsForcedRedrawForReadback(); 1279 state.SetNeedsForcedRedrawForReadback();
1248 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1280 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1249 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1281 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1250 } 1282 }
1251 1283
1252 TEST(SchedulerStateMachineTest, DontDrawBeforeCommitAfterLostOutputSurface) { 1284 TEST(SchedulerStateMachineTest, DontDrawBeforeCommitAfterLostOutputSurface) {
1253 SchedulerSettings default_scheduler_settings; 1285 SchedulerSettings default_scheduler_settings;
1254 StateMachine state(default_scheduler_settings); 1286 StateMachine state(default_scheduler_settings);
1255 state.SetCanStart(); 1287 state.SetCanStart();
1256 state.UpdateState(state.NextAction()); 1288 state.UpdateState(state.NextAction());
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1306 state.UpdateState(state.NextAction()); 1338 state.UpdateState(state.NextAction());
1307 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1339 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1308 state.SetVisible(false); 1340 state.SetVisible(false);
1309 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); 1341 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS);
1310 state.SetNeedsCommit(); 1342 state.SetNeedsCommit();
1311 1343
1312 state.FinishCommit(); 1344 state.FinishCommit();
1313 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 1345 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
1314 state.UpdateState(state.NextAction()); 1346 state.UpdateState(state.NextAction());
1315 1347
1316 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1348 EXPECT_TRUE(state.active_tree_needs_first_draw());
1317 state.CommitState());
1318 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1349 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1319 } 1350 }
1320 1351
1321 TEST(SchedulerStateMachineTest, TestFinishCommitWhenForcedCommitInProgress) { 1352 TEST(SchedulerStateMachineTest, TestFinishCommitWhenForcedCommitInProgress) {
1322 SchedulerSettings default_scheduler_settings; 1353 SchedulerSettings default_scheduler_settings;
1323 StateMachine state(default_scheduler_settings); 1354 StateMachine state(default_scheduler_settings);
1324 state.SetCanStart(); 1355 state.SetCanStart();
1325 state.UpdateState(state.NextAction()); 1356 state.UpdateState(state.NextAction());
1326 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1357 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1327 state.SetVisible(false); 1358 state.SetVisible(false);
1328 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); 1359 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS);
1329 state.SetNeedsCommit(); 1360 state.SetNeedsCommit();
1330 state.SetNeedsForcedCommitForReadback(); 1361 state.SetNeedsForcedCommitForReadback();
1331 1362
1332 // The commit for readback interupts the normal commit. 1363 // The commit for readback interupts the normal commit.
1333 state.FinishCommit(); 1364 state.FinishCommit();
1334 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1365 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1335 1366
1336 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1367 EXPECT_TRUE(state.active_tree_needs_first_draw());
1337 state.CommitState());
1338 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1368 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1339 1369
1340 // When the readback interrupts the normal commit, we should not get 1370 // When the readback interrupts the normal commit, we should not get
1341 // another BeginMainFrame when the readback completes. 1371 // another BeginMainFrame when the readback completes.
1342 EXPECT_NE(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME, 1372 EXPECT_NE(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME,
1343 state.NextAction()); 1373 state.NextAction());
1344 1374
1345 // The normal commit can then proceed. 1375 // The normal commit can then proceed.
1346 state.FinishCommit(); 1376 state.FinishCommit();
1347 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1377 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1396 state.SetNeedsCommit(); 1426 state.SetNeedsCommit();
1397 state.SetNeedsForcedCommitForReadback(); 1427 state.SetNeedsForcedCommitForReadback();
1398 EXPECT_ACTION_UPDATE_STATE( 1428 EXPECT_ACTION_UPDATE_STATE(
1399 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1429 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1400 state.FinishCommit(); 1430 state.FinishCommit();
1401 1431
1402 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 1432 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
1403 state.CommitState()); 1433 state.CommitState());
1404 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1434 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1405 1435
1406 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1436 EXPECT_TRUE(state.active_tree_needs_first_draw());
1407 state.CommitState());
1408 1437
1409 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1438 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1410 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 1439 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
1411 1440
1412 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1441 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1413 1442
1414 // Should be waiting for the normal BeginMainFrame. 1443 // Should be waiting for the normal BeginMainFrame.
1415 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 1444 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
1416 state.CommitState()); 1445 state.CommitState());
1417 } 1446 }
(...skipping 14 matching lines...) Expand all
1432 // Schedule a readback, commit it, draw it. 1461 // Schedule a readback, commit it, draw it.
1433 state.SetNeedsForcedCommitForReadback(); 1462 state.SetNeedsForcedCommitForReadback();
1434 EXPECT_ACTION_UPDATE_STATE( 1463 EXPECT_ACTION_UPDATE_STATE(
1435 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1464 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1436 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1465 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1437 state.FinishCommit(); 1466 state.FinishCommit();
1438 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 1467 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
1439 state.CommitState()); 1468 state.CommitState());
1440 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1469 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1441 1470
1442 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1471 EXPECT_TRUE(state.active_tree_needs_first_draw());
1443 state.CommitState());
1444 1472
1445 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1473 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1446 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 1474 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
1447 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1475 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1448 1476
1449 // Should be waiting for the normal BeginMainFrame. 1477 // Should be waiting for the normal BeginMainFrame.
1450 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 1478 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
1451 state.CommitState()) 1479 state.CommitState())
1452 << *state.AsValue(); 1480 << *state.AsValue();
1453 } 1481 }
(...skipping 13 matching lines...) Expand all
1467 state.SetNeedsCommit(); 1495 state.SetNeedsCommit();
1468 state.SetNeedsForcedCommitForReadback(); 1496 state.SetNeedsForcedCommitForReadback();
1469 EXPECT_ACTION_UPDATE_STATE( 1497 EXPECT_ACTION_UPDATE_STATE(
1470 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1498 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1471 state.FinishCommit(); 1499 state.FinishCommit();
1472 1500
1473 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 1501 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
1474 state.CommitState()); 1502 state.CommitState());
1475 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1503 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1476 1504
1477 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1505 EXPECT_TRUE(state.active_tree_needs_first_draw());
1478 state.CommitState());
1479 1506
1480 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1507 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1481 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 1508 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
1482 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1509 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1483 1510
1484 // Should be waiting for BeginMainFrame. 1511 // Should be waiting for BeginMainFrame.
1485 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 1512 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
1486 state.CommitState()) 1513 state.CommitState())
1487 << *state.AsValue(); 1514 << *state.AsValue();
1488 1515
(...skipping 20 matching lines...) Expand all
1509 1536
1510 state.SetNeedsCommit(); 1537 state.SetNeedsCommit();
1511 state.SetNeedsForcedCommitForReadback(); 1538 state.SetNeedsForcedCommitForReadback();
1512 state.UpdateState(state.NextAction()); 1539 state.UpdateState(state.NextAction());
1513 state.FinishCommit(); 1540 state.FinishCommit();
1514 1541
1515 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 1542 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
1516 state.CommitState()); 1543 state.CommitState());
1517 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1544 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1518 1545
1519 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1546 EXPECT_TRUE(state.active_tree_needs_first_draw());
1520 state.CommitState());
1521 1547
1522 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1548 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1523 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 1549 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
1524 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1550 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1525 } 1551 }
1526 1552
1527 TEST(SchedulerStateMachineTest, ReportIfNotDrawing) { 1553 TEST(SchedulerStateMachineTest, ReportIfNotDrawing) {
1528 SchedulerSettings default_scheduler_settings; 1554 SchedulerSettings default_scheduler_settings;
1529 StateMachine state(default_scheduler_settings); 1555 StateMachine state(default_scheduler_settings);
1530 state.SetCanStart(); 1556 state.SetCanStart();
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1671 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1697 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1672 1698
1673 // The deadline is not triggered early until we enter prefer smoothness mode. 1699 // The deadline is not triggered early until we enter prefer smoothness mode.
1674 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 1700 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineEarly());
1675 state.SetSmoothnessTakesPriority(true); 1701 state.SetSmoothnessTakesPriority(true);
1676 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 1702 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly());
1677 } 1703 }
1678 1704
1679 } // namespace 1705 } // namespace
1680 } // namespace cc 1706 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698