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

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: rebase 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 19 matching lines...) Expand all
77 } 71 }
78 72
79 SynchronousReadbackState readback_state() const { return readback_state_; } 73 SynchronousReadbackState readback_state() const { return readback_state_; }
80 74
81 bool NeedsCommit() const { return needs_commit_; } 75 bool NeedsCommit() const { return needs_commit_; }
82 76
83 void SetNeedsRedraw(bool b) { needs_redraw_ = b; } 77 void SetNeedsRedraw(bool b) { needs_redraw_ = b; }
84 78
85 void SetNeedsForcedRedrawForTimeout(bool b) { 79 void SetNeedsForcedRedrawForTimeout(bool b) {
86 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_COMMIT; 80 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_COMMIT;
87 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; 81 active_tree_needs_first_draw_ = true;
88 } 82 }
89 bool NeedsForcedRedrawForTimeout() const { 83 bool NeedsForcedRedrawForTimeout() const {
90 return forced_redraw_state_ != FORCED_REDRAW_STATE_IDLE; 84 return forced_redraw_state_ != FORCED_REDRAW_STATE_IDLE;
91 } 85 }
92 86
93 void SetNeedsForcedRedrawForReadback() { 87 void SetNeedsForcedRedrawForReadback() {
94 readback_state_ = READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK; 88 readback_state_ = READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK;
95 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; 89 active_tree_needs_first_draw_ = true;
96 } 90 }
97 91
98 bool NeedsForcedRedrawForReadback() const { 92 bool NeedsForcedRedrawForReadback() const {
99 return readback_state_ != READBACK_STATE_IDLE; 93 return readback_state_ != READBACK_STATE_IDLE;
100 } 94 }
101 95
102 void SetActiveTreeNeedsFirstDraw(bool needs_first_draw) { 96 void SetActiveTreeNeedsFirstDraw(bool needs_first_draw) {
103 active_tree_needs_first_draw_ = needs_first_draw; 97 active_tree_needs_first_draw_ = needs_first_draw;
104 } 98 }
105 99
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 state.UpdateState(state.NextAction()); 171 state.UpdateState(state.NextAction());
178 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 172 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
179 state.SetVisible(true); 173 state.SetVisible(true);
180 state.UpdateState(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 174 state.UpdateState(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
181 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 175 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
182 state.CommitState()); 176 state.CommitState());
183 EXPECT_FALSE(state.NeedsCommit()); 177 EXPECT_FALSE(state.NeedsCommit());
184 } 178 }
185 } 179 }
186 180
181 // start_commit_before_activate_enabled = true
182 TEST(SchedulerStateMachineTest, StartCommitBeforeActivateEnabled) {
183 SchedulerSettings scheduler_settings;
184 scheduler_settings.impl_side_painting = true;
185 scheduler_settings.start_commit_before_activate_enabled = true;
186 StateMachine state(scheduler_settings);
187 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_IDLE);
188 state.SetCanStart();
189 state.UpdateState(state.NextAction());
190 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
191 state.SetNeedsRedraw(false);
192 state.SetVisible(true);
193 state.SetCanDraw(true);
194 state.SetNeedsCommit();
195
196 EXPECT_TRUE(state.BeginImplFrameNeeded());
197
198 // Commit to the pending tree.
199 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
200 EXPECT_ACTION_UPDATE_STATE(
201 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
202 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
203 state.FinishCommit();
204 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
205 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
206 state.OnBeginImplFrameDeadline();
207 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
208
209 // Verify that the next commit starts while there is still a pending tree.
210 state.SetNeedsCommit();
211 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
212 EXPECT_ACTION_UPDATE_STATE(
213 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
214 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
215
216 // Verify the pending commit doesn't overwrite the pending
217 // tree until the pending tree has been activated.
218 state.FinishCommit();
219 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
220
221 // Verify NotifyReadyToActivate unblocks activation, draw, and
222 // commit in that order.
223 state.NotifyReadyToActivate();
224 EXPECT_ACTION_UPDATE_STATE(
225 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE);
226 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
227
228 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly());
229 state.OnBeginImplFrameDeadline();
230 EXPECT_ACTION_UPDATE_STATE(
231 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
232 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
233 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
234 }
235
187 TEST(SchedulerStateMachineTest, 236 TEST(SchedulerStateMachineTest,
188 TestFailedDrawForAnimationCheckerboardSetsNeedsCommitAndDoesNotDrawAgain) { 237 TestFailedDrawForAnimationCheckerboardSetsNeedsCommitAndDoesNotDrawAgain) {
189 SchedulerSettings default_scheduler_settings; 238 SchedulerSettings default_scheduler_settings;
190 StateMachine state(default_scheduler_settings); 239 StateMachine state(default_scheduler_settings);
191 state.SetCanStart(); 240 state.SetCanStart();
192 state.UpdateState(state.NextAction()); 241 state.UpdateState(state.NextAction());
193 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 242 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
194 state.SetVisible(true); 243 state.SetVisible(true);
195 state.SetCanDraw(true); 244 state.SetCanDraw(true);
196 state.SetNeedsRedraw(true); 245 state.SetNeedsRedraw(true);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 373
325 // Finish the commit. Note, we should not yet be forcing a draw, but should 374 // Finish the commit. Note, we should not yet be forcing a draw, but should
326 // continue the commit as usual. 375 // continue the commit as usual.
327 state.FinishCommit(); 376 state.FinishCommit();
328 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 377 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
329 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 378 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
330 EXPECT_TRUE(state.RedrawPending()); 379 EXPECT_TRUE(state.RedrawPending());
331 380
332 // The redraw should be forced at the end of the next BeginImplFrame. 381 // The redraw should be forced at the end of the next BeginImplFrame.
333 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 382 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
383 EXPECT_ACTION_UPDATE_STATE(
384 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
334 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 385 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
335 state.OnBeginImplFrameDeadline(); 386 state.OnBeginImplFrameDeadline();
336 EXPECT_ACTION_UPDATE_STATE( 387 EXPECT_ACTION_UPDATE_STATE(
337 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED); 388 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED);
338 } 389 }
339 390
340 TEST(SchedulerStateMachineTest, TestFailedDrawsDoNotRestartForcedDraw) { 391 TEST(SchedulerStateMachineTest, TestFailedDrawsDoNotRestartForcedDraw) {
341 SchedulerSettings scheduler_settings; 392 SchedulerSettings scheduler_settings;
342 int draw_limit = 1; 393 int draw_limit = 1;
343 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced_ = 394 scheduler_settings.maximum_number_of_failed_draws_before_draw_is_forced_ =
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 state.NextAction()); 561 state.NextAction());
511 562
512 // Case 2: needs_commit=true 563 // Case 2: needs_commit=true
513 state.SetNeedsCommit(); 564 state.SetNeedsCommit();
514 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 565 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
515 state.NextAction()) 566 state.NextAction())
516 << *state.AsValue(); 567 << *state.AsValue();
517 } 568 }
518 } 569 }
519 570
520 // When in BeginImplFrame deadline we should always draw for SetNeedsRedraw or 571 // When in BeginImplFrame deadline we should always draw for SetNeedsRedraw
521 // SetNeedsForcedRedrawForReadback have been called... except if we're 572 // except if we're ready to commit, in which case we expect a commit first.
522 // ready to commit, in which case we expect a commit first. 573 // SetNeedsForcedRedrawForReadback should take precedence over all and
574 // issue a readback.
523 for (size_t i = 0; i < num_commit_states; ++i) { 575 for (size_t i = 0; i < num_commit_states; ++i) {
524 for (size_t j = 0; j < 2; ++j) { 576 for (size_t j = 0; j < 2; ++j) {
525 bool request_readback = j; 577 bool request_readback = j;
526 578
527 // Skip invalid states
528 if (request_readback &&
529 (SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW !=
530 all_commit_states[i]))
531 continue;
532
533 StateMachine state(default_scheduler_settings); 579 StateMachine state(default_scheduler_settings);
534 state.SetCanStart(); 580 state.SetCanStart();
535 state.UpdateState(state.NextAction()); 581 state.UpdateState(state.NextAction());
536 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 582 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
537 state.SetCanDraw(true); 583 state.SetCanDraw(true);
538 state.SetCommitState(all_commit_states[i]); 584 state.SetCommitState(all_commit_states[i]);
539 state.SetBeginImplFrameState( 585 state.SetBeginImplFrameState(
540 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE); 586 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE);
541 if (request_readback) { 587 if (request_readback) {
542 state.SetNeedsForcedRedrawForReadback(); 588 state.SetNeedsForcedRedrawForReadback();
543 } else { 589 } else {
544 state.SetNeedsRedraw(true); 590 state.SetNeedsRedraw(true);
545 state.SetVisible(true); 591 state.SetVisible(true);
546 } 592 }
547 593
548 SchedulerStateMachine::Action expected_action; 594 SchedulerStateMachine::Action expected_action;
549 if (all_commit_states[i] == 595 if (request_readback) {
550 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) { 596 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_READBACK;
597 } else if (all_commit_states[i] ==
598 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) {
551 expected_action = SchedulerStateMachine::ACTION_COMMIT; 599 expected_action = SchedulerStateMachine::ACTION_COMMIT;
552 } else if (request_readback) {
553 if (all_commit_states[i] ==
554 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW)
555 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_READBACK;
556 else
557 expected_action = SchedulerStateMachine::ACTION_NONE;
558 } else { 600 } else {
559 expected_action = 601 expected_action =
560 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE; 602 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE;
561 } 603 }
562 604
563 // Case 1: needs_commit=false. 605 // Case 1: needs_commit=false.
564 EXPECT_NE(state.BeginImplFrameNeeded(), request_readback) 606 EXPECT_NE(state.BeginImplFrameNeeded(), request_readback)
565 << *state.AsValue(); 607 << *state.AsValue();
566 EXPECT_EQ(expected_action, state.NextAction()) << *state.AsValue(); 608 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue();
567 609
568 // Case 2: needs_commit=true. 610 // Case 2: needs_commit=true.
569 state.SetNeedsCommit(); 611 state.SetNeedsCommit();
570 EXPECT_NE(state.BeginImplFrameNeeded(), request_readback) 612 EXPECT_NE(state.BeginImplFrameNeeded(), request_readback)
571 << *state.AsValue(); 613 << *state.AsValue();
572 EXPECT_EQ(expected_action, state.NextAction()) << *state.AsValue(); 614 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue();
573 } 615 }
574 } 616 }
575 } 617 }
576 618
577 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) { 619 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) {
578 SchedulerSettings default_scheduler_settings; 620 SchedulerSettings default_scheduler_settings;
579 621
580 size_t num_commit_states = 622 size_t num_commit_states =
581 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); 623 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState);
582 for (size_t i = 0; i < num_commit_states; ++i) { 624 for (size_t i = 0; i < num_commit_states; ++i) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 } 675 }
634 676
635 TEST(SchedulerStateMachineTest, 677 TEST(SchedulerStateMachineTest,
636 TestCanRedrawWithWaitingForFirstDrawMakesProgress) { 678 TestCanRedrawWithWaitingForFirstDrawMakesProgress) {
637 SchedulerSettings default_scheduler_settings; 679 SchedulerSettings default_scheduler_settings;
638 StateMachine state(default_scheduler_settings); 680 StateMachine state(default_scheduler_settings);
639 state.SetCanStart(); 681 state.SetCanStart();
640 state.UpdateState(state.NextAction()); 682 state.UpdateState(state.NextAction());
641 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 683 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
642 684
643 state.SetCommitState(
644 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
645 state.SetActiveTreeNeedsFirstDraw(true); 685 state.SetActiveTreeNeedsFirstDraw(true);
646 state.SetNeedsCommit(); 686 state.SetNeedsCommit();
647 state.SetNeedsRedraw(true); 687 state.SetNeedsRedraw(true);
648 state.SetVisible(true); 688 state.SetVisible(true);
649 state.SetCanDraw(false); 689 state.SetCanDraw(false);
650 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 690 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
651 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 691 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
652 EXPECT_ACTION_UPDATE_STATE( 692 EXPECT_ACTION_UPDATE_STATE(
653 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 693 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
654 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 694 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 state.OnBeginImplFrameIdle(); 745 state.OnBeginImplFrameIdle();
706 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, 746 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE,
707 state.begin_impl_frame_state()); 747 state.begin_impl_frame_state());
708 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 748 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
709 749
710 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 750 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
711 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING, 751 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING,
712 state.begin_impl_frame_state()); 752 state.begin_impl_frame_state());
713 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 753 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
714 754
715 // Commit and make sure we draw on next BeginImplFrame 755 // Finish the commit, then make sure we start the next commit immediately
756 // and draw on the next BeginImplFrame.
716 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 757 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
717 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
718 state.OnBeginImplFrameDeadline();
719 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW,
720 state.CommitState());
721 EXPECT_ACTION_UPDATE_STATE(
722 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
723 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
724
725 // Verify that another commit will start immediately after draw.
726 EXPECT_ACTION_UPDATE_STATE( 758 EXPECT_ACTION_UPDATE_STATE(
727 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 759 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
728 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 760 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
761
762 state.OnBeginImplFrameDeadline();
763
764 EXPECT_TRUE(state.active_tree_needs_first_draw());
765 EXPECT_ACTION_UPDATE_STATE(
766 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
767 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
768 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
729 } 769 }
730 770
731 TEST(SchedulerStateMachineTest, TestFullCycle) { 771 TEST(SchedulerStateMachineTest, TestFullCycle) {
732 SchedulerSettings default_scheduler_settings; 772 SchedulerSettings default_scheduler_settings;
733 StateMachine state(default_scheduler_settings); 773 StateMachine state(default_scheduler_settings);
734 state.SetCanStart(); 774 state.SetCanStart();
735 state.UpdateState(state.NextAction()); 775 state.UpdateState(state.NextAction());
736 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 776 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
737 state.SetVisible(true); 777 state.SetVisible(true);
738 state.SetCanDraw(true); 778 state.SetCanDraw(true);
(...skipping 10 matching lines...) Expand all
749 EXPECT_FALSE(state.NeedsCommit()); 789 EXPECT_FALSE(state.NeedsCommit());
750 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 790 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
751 791
752 // Tell the scheduler the frame finished. 792 // Tell the scheduler the frame finished.
753 state.FinishCommit(); 793 state.FinishCommit();
754 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 794 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
755 state.CommitState()); 795 state.CommitState());
756 796
757 // Commit. 797 // Commit.
758 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 798 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
759 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 799 EXPECT_TRUE(state.active_tree_needs_first_draw());
760 state.CommitState());
761 EXPECT_TRUE(state.needs_redraw()); 800 EXPECT_TRUE(state.needs_redraw());
762 801
763 // Expect to do nothing until BeginImplFrame deadline 802 // Expect to do nothing until BeginImplFrame deadline
764 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 803 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
765 804
766 // At BeginImplFrame deadline, draw. 805 // At BeginImplFrame deadline, draw.
767 state.OnBeginImplFrameDeadline(); 806 state.OnBeginImplFrameDeadline();
768 EXPECT_ACTION_UPDATE_STATE( 807 EXPECT_ACTION_UPDATE_STATE(
769 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 808 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
770 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 809 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
(...skipping 29 matching lines...) Expand all
800 state.SetNeedsCommit(); 839 state.SetNeedsCommit();
801 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 840 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
802 841
803 // Tell the scheduler the frame finished. 842 // Tell the scheduler the frame finished.
804 state.FinishCommit(); 843 state.FinishCommit();
805 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 844 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
806 state.CommitState()); 845 state.CommitState());
807 846
808 // First commit. 847 // First commit.
809 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 848 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
810 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 849 EXPECT_TRUE(state.active_tree_needs_first_draw());
811 state.CommitState());
812 EXPECT_TRUE(state.needs_redraw()); 850 EXPECT_TRUE(state.needs_redraw());
813 851
814 // Expect to do nothing until BeginImplFrame deadline. 852 // Expect to do nothing until BeginImplFrame deadline.
815 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 853 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
816 854
817 // At BeginImplFrame deadline, draw. 855 // At BeginImplFrame deadline, draw.
818 state.OnBeginImplFrameDeadline(); 856 state.OnBeginImplFrameDeadline();
819 EXPECT_ACTION_UPDATE_STATE( 857 EXPECT_ACTION_UPDATE_STATE(
820 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 858 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
821 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 859 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 // Ask for another draw. Expect nothing happens. 1126 // Ask for another draw. Expect nothing happens.
1089 state.SetNeedsRedraw(true); 1127 state.SetNeedsRedraw(true);
1090 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1128 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1091 1129
1092 // Finish the frame, and commit. 1130 // Finish the frame, and commit.
1093 state.FinishCommit(); 1131 state.FinishCommit();
1094 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1132 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1095 1133
1096 // We will abort the draw when the output surface is lost if we are 1134 // We will abort the draw when the output surface is lost if we are
1097 // waiting for the first draw to unblock the main thread. 1135 // waiting for the first draw to unblock the main thread.
1098 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1136 EXPECT_TRUE(state.active_tree_needs_first_draw());
1099 state.CommitState());
1100 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1137 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1101 1138
1102 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE 1139 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE
1103 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, 1140 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE,
1104 state.begin_impl_frame_state()); 1141 state.begin_impl_frame_state());
1105 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1142 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1106 state.NextAction()); 1143 state.NextAction());
1107 1144
1108 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1145 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
1109 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING, 1146 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 state.DidLoseOutputSurface(); 1187 state.DidLoseOutputSurface();
1151 1188
1152 // Ask for another draw and also set needs commit. Expect nothing happens. 1189 // Ask for another draw and also set needs commit. Expect nothing happens.
1153 state.SetNeedsRedraw(true); 1190 state.SetNeedsRedraw(true);
1154 state.SetNeedsCommit(); 1191 state.SetNeedsCommit();
1155 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1192 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1156 1193
1157 // Finish the frame, and commit. 1194 // Finish the frame, and commit.
1158 state.FinishCommit(); 1195 state.FinishCommit();
1159 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1196 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1160 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1197 EXPECT_TRUE(state.active_tree_needs_first_draw());
1161 state.CommitState());
1162 1198
1163 // Because the output surface is missing, we expect the draw to abort. 1199 // Because the output surface is missing, we expect the draw to abort.
1164 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1200 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1165 1201
1166 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE 1202 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE
1167 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE, 1203 EXPECT_EQ(SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE,
1168 state.begin_impl_frame_state()); 1204 state.begin_impl_frame_state());
1169 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1205 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1170 state.NextAction()); 1206 state.NextAction());
1171 1207
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1209 state.SetCanStart(); 1245 state.SetCanStart();
1210 state.UpdateState(state.NextAction()); 1246 state.UpdateState(state.NextAction());
1211 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1247 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1212 state.SetVisible(true); 1248 state.SetVisible(true);
1213 state.SetCanDraw(true); 1249 state.SetCanDraw(true);
1214 1250
1215 // Cause a lost context lost. 1251 // Cause a lost context lost.
1216 state.DidLoseOutputSurface(); 1252 state.DidLoseOutputSurface();
1217 1253
1218 // Ask a forced redraw for readback and verify it ocurrs. 1254 // Ask a forced redraw for readback and verify it ocurrs.
1219 state.SetCommitState(
1220 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
1221 state.SetNeedsForcedRedrawForReadback(); 1255 state.SetNeedsForcedRedrawForReadback();
1222 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting()); 1256 state.OnBeginImplFrame(BeginFrameArgs::CreateForTesting());
1223 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1257 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1224 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1258 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1225 1259
1226 // Forced redraws for readbacks need to be followed by a new commit 1260 // Forced redraws for readbacks need to be followed by a new commit
1227 // to replace the readback commit. 1261 // to replace the readback commit.
1228 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 1262 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
1229 state.CommitState()); 1263 state.CommitState());
1230 state.FinishCommit(); 1264 state.FinishCommit();
1231 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1265 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1232 1266
1233 // We don't yet have an output surface, so we the draw and swap should abort. 1267 // We don't yet have an output surface, so we the draw and swap should abort.
1234 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1268 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1235 1269
1236 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE 1270 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE
1237 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1271 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1238 1272
1239 state.OnBeginImplFrameDeadline(); 1273 state.OnBeginImplFrameDeadline();
1240 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1274 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1241 1275
1242 state.OnBeginImplFrameIdle(); 1276 state.OnBeginImplFrameIdle();
1243 EXPECT_ACTION_UPDATE_STATE( 1277 EXPECT_ACTION_UPDATE_STATE(
1244 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 1278 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1245 1279
1246 // Ask a readback and verify it occurs. 1280 // Ask a readback and verify it occurs.
1247 state.SetCommitState(
1248 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
1249 state.SetNeedsForcedRedrawForReadback(); 1281 state.SetNeedsForcedRedrawForReadback();
1250 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1282 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1251 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1283 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1252 } 1284 }
1253 1285
1254 TEST(SchedulerStateMachineTest, DontDrawBeforeCommitAfterLostOutputSurface) { 1286 TEST(SchedulerStateMachineTest, DontDrawBeforeCommitAfterLostOutputSurface) {
1255 SchedulerSettings default_scheduler_settings; 1287 SchedulerSettings default_scheduler_settings;
1256 StateMachine state(default_scheduler_settings); 1288 StateMachine state(default_scheduler_settings);
1257 state.SetCanStart(); 1289 state.SetCanStart();
1258 state.UpdateState(state.NextAction()); 1290 state.UpdateState(state.NextAction());
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 state.UpdateState(state.NextAction()); 1379 state.UpdateState(state.NextAction());
1348 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1380 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1349 state.SetVisible(false); 1381 state.SetVisible(false);
1350 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); 1382 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS);
1351 state.SetNeedsCommit(); 1383 state.SetNeedsCommit();
1352 1384
1353 state.FinishCommit(); 1385 state.FinishCommit();
1354 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 1386 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
1355 state.UpdateState(state.NextAction()); 1387 state.UpdateState(state.NextAction());
1356 1388
1357 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1389 EXPECT_TRUE(state.active_tree_needs_first_draw());
1358 state.CommitState());
1359 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1390 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1360 } 1391 }
1361 1392
1362 TEST(SchedulerStateMachineTest, TestFinishCommitWhenForcedCommitInProgress) { 1393 TEST(SchedulerStateMachineTest, TestFinishCommitWhenForcedCommitInProgress) {
1363 SchedulerSettings default_scheduler_settings; 1394 SchedulerSettings default_scheduler_settings;
1364 StateMachine state(default_scheduler_settings); 1395 StateMachine state(default_scheduler_settings);
1365 state.SetCanStart(); 1396 state.SetCanStart();
1366 state.UpdateState(state.NextAction()); 1397 state.UpdateState(state.NextAction());
1367 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1398 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1368 state.SetVisible(false); 1399 state.SetVisible(false);
1369 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS); 1400 state.SetCommitState(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS);
1370 state.SetNeedsForcedCommitForReadback(); 1401 state.SetNeedsForcedCommitForReadback();
1371 1402
1372 // The commit for readback interupts the normal commit. 1403 // The commit for readback interupts the normal commit.
1373 state.FinishCommit(); 1404 state.FinishCommit();
1374 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1405 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1375 1406
1376 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1407 EXPECT_TRUE(state.active_tree_needs_first_draw());
1377 state.CommitState());
1378 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1408 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1379 1409
1380 // When the readback interrupts the normal commit, we should not get 1410 // When the readback interrupts the normal commit, we should not get
1381 // another BeginMainFrame when the readback completes. 1411 // another BeginMainFrame when the readback completes.
1382 EXPECT_NE(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME, 1412 EXPECT_NE(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME,
1383 state.NextAction()); 1413 state.NextAction());
1384 1414
1385 // The normal commit can then proceed. 1415 // The normal commit can then proceed.
1386 state.FinishCommit(); 1416 state.FinishCommit();
1387 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1417 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 // Schedule a readback, commit it, draw it. 1465 // Schedule a readback, commit it, draw it.
1436 state.SetNeedsForcedCommitForReadback(); 1466 state.SetNeedsForcedCommitForReadback();
1437 EXPECT_ACTION_UPDATE_STATE( 1467 EXPECT_ACTION_UPDATE_STATE(
1438 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1468 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1439 state.FinishCommit(); 1469 state.FinishCommit();
1440 1470
1441 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 1471 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
1442 state.CommitState()); 1472 state.CommitState());
1443 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1473 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1444 1474
1445 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1475 EXPECT_TRUE(state.active_tree_needs_first_draw());
1446 state.CommitState());
1447 1476
1448 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1477 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1449 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 1478 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
1450 1479
1451 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1480 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1452 1481
1453 // Should be waiting for the normal BeginMainFrame. 1482 // Should be waiting for the normal BeginMainFrame.
1454 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 1483 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
1455 state.CommitState()); 1484 state.CommitState());
1456 } 1485 }
(...skipping 14 matching lines...) Expand all
1471 // Schedule a readback, commit it, draw it. 1500 // Schedule a readback, commit it, draw it.
1472 state.SetNeedsForcedCommitForReadback(); 1501 state.SetNeedsForcedCommitForReadback();
1473 EXPECT_ACTION_UPDATE_STATE( 1502 EXPECT_ACTION_UPDATE_STATE(
1474 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1503 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1475 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1504 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1476 state.FinishCommit(); 1505 state.FinishCommit();
1477 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 1506 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
1478 state.CommitState()); 1507 state.CommitState());
1479 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1508 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1480 1509
1481 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1510 EXPECT_TRUE(state.active_tree_needs_first_draw());
1482 state.CommitState());
1483 1511
1484 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1512 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1485 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 1513 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
1486 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1514 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1487 1515
1488 // Should be waiting for the normal BeginMainFrame. 1516 // Should be waiting for the normal BeginMainFrame.
1489 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 1517 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
1490 state.CommitState()) 1518 state.CommitState())
1491 << *state.AsValue(); 1519 << *state.AsValue();
1492 } 1520 }
(...skipping 12 matching lines...) Expand all
1505 1533
1506 state.SetNeedsForcedCommitForReadback(); 1534 state.SetNeedsForcedCommitForReadback();
1507 EXPECT_ACTION_UPDATE_STATE( 1535 EXPECT_ACTION_UPDATE_STATE(
1508 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1536 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1509 state.FinishCommit(); 1537 state.FinishCommit();
1510 1538
1511 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 1539 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
1512 state.CommitState()); 1540 state.CommitState());
1513 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1541 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1514 1542
1515 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1543 EXPECT_TRUE(state.active_tree_needs_first_draw());
1516 state.CommitState());
1517 1544
1518 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1545 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1519 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 1546 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
1520 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1547 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1521 1548
1522 // Should be waiting for BeginMainFrame. 1549 // Should be waiting for BeginMainFrame.
1523 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 1550 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
1524 state.CommitState()) 1551 state.CommitState())
1525 << *state.AsValue(); 1552 << *state.AsValue();
1526 1553
(...skipping 19 matching lines...) Expand all
1546 state.UpdateState(state.NextAction()); 1573 state.UpdateState(state.NextAction());
1547 1574
1548 state.SetNeedsForcedCommitForReadback(); 1575 state.SetNeedsForcedCommitForReadback();
1549 state.UpdateState(state.NextAction()); 1576 state.UpdateState(state.NextAction());
1550 state.FinishCommit(); 1577 state.FinishCommit();
1551 1578
1552 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, 1579 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
1553 state.CommitState()); 1580 state.CommitState());
1554 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1581 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1555 1582
1556 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW, 1583 EXPECT_TRUE(state.active_tree_needs_first_draw());
1557 state.CommitState());
1558 1584
1559 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK); 1585 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1560 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS); 1586 state.DidDrawIfPossibleCompleted(DrawSwapReadbackResult::DRAW_SUCCESS);
1561 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1587 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1562 } 1588 }
1563 1589
1564 TEST(SchedulerStateMachineTest, ReportIfNotDrawing) { 1590 TEST(SchedulerStateMachineTest, ReportIfNotDrawing) {
1565 SchedulerSettings default_scheduler_settings; 1591 SchedulerSettings default_scheduler_settings;
1566 StateMachine state(default_scheduler_settings); 1592 StateMachine state(default_scheduler_settings);
1567 state.SetCanStart(); 1593 state.SetCanStart();
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1708 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1734 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1709 1735
1710 // The deadline is not triggered early until we enter prefer smoothness mode. 1736 // The deadline is not triggered early until we enter prefer smoothness mode.
1711 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 1737 EXPECT_FALSE(state.ShouldTriggerBeginImplFrameDeadlineEarly());
1712 state.SetSmoothnessTakesPriority(true); 1738 state.SetSmoothnessTakesPriority(true);
1713 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly()); 1739 EXPECT_TRUE(state.ShouldTriggerBeginImplFrameDeadlineEarly());
1714 } 1740 }
1715 1741
1716 } // namespace 1742 } // namespace
1717 } // namespace cc 1743 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698