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

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

Issue 292533002: Remove forced commit and readback from the scheduler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rm-cnr-scheduler: tests Created 6 years, 7 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 | Annotate | Revision Log
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 "cc/test/begin_frame_args_test.h" 8 #include "cc/test/begin_frame_args_test.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 } 67 }
68 68
69 BeginImplFrameState begin_impl_frame_state() const { 69 BeginImplFrameState begin_impl_frame_state() const {
70 return begin_impl_frame_state_; 70 return begin_impl_frame_state_;
71 } 71 }
72 72
73 OutputSurfaceState output_surface_state() const { 73 OutputSurfaceState output_surface_state() const {
74 return output_surface_state_; 74 return output_surface_state_;
75 } 75 }
76 76
77 void SetReadbackState(SynchronousReadbackState rs) { readback_state_ = rs; }
78 SynchronousReadbackState readback_state() const { return readback_state_; }
79
80 bool NeedsCommit() const { return needs_commit_; } 77 bool NeedsCommit() const { return needs_commit_; }
81 78
82 void SetNeedsRedraw(bool b) { needs_redraw_ = b; } 79 void SetNeedsRedraw(bool b) { needs_redraw_ = b; }
83 80
84 void SetNeedsForcedRedrawForTimeout(bool b) { 81 void SetNeedsForcedRedrawForTimeout(bool b) {
85 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_COMMIT; 82 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_COMMIT;
86 active_tree_needs_first_draw_ = true; 83 active_tree_needs_first_draw_ = true;
87 } 84 }
88 bool NeedsForcedRedrawForTimeout() const { 85 bool NeedsForcedRedrawForTimeout() const {
89 return forced_redraw_state_ != FORCED_REDRAW_STATE_IDLE; 86 return forced_redraw_state_ != FORCED_REDRAW_STATE_IDLE;
90 } 87 }
91 88
92 void SetNeedsForcedRedrawForReadback() {
93 readback_state_ = READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK;
94 active_tree_needs_first_draw_ = true;
95 }
96
97 bool NeedsForcedRedrawForReadback() const {
98 return readback_state_ != READBACK_STATE_IDLE;
99 }
100
101 void SetActiveTreeNeedsFirstDraw(bool needs_first_draw) { 89 void SetActiveTreeNeedsFirstDraw(bool needs_first_draw) {
102 active_tree_needs_first_draw_ = needs_first_draw; 90 active_tree_needs_first_draw_ = needs_first_draw;
103 } 91 }
104 92
105 bool CanDraw() const { return can_draw_; } 93 bool CanDraw() const { return can_draw_; }
106 bool Visible() const { return visible_; } 94 bool Visible() const { return visible_; }
107 95
108 bool PendingActivationsShouldBeForced() const { 96 bool PendingActivationsShouldBeForced() const {
109 return SchedulerStateMachine::PendingActivationsShouldBeForced(); 97 return SchedulerStateMachine::PendingActivationsShouldBeForced();
110 } 98 }
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 // Case 2: needs_commit=true 691 // Case 2: needs_commit=true
704 state.SetNeedsCommit(); 692 state.SetNeedsCommit();
705 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE, 693 EXPECT_NE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE,
706 state.NextAction()) 694 state.NextAction())
707 << *state.AsValue(); 695 << *state.AsValue();
708 } 696 }
709 } 697 }
710 698
711 // When in BeginImplFrame deadline we should always draw for SetNeedsRedraw 699 // When in BeginImplFrame deadline we should always draw for SetNeedsRedraw
712 // except if we're ready to commit, in which case we expect a commit first. 700 // except if we're ready to commit, in which case we expect a commit first.
713 // SetNeedsForcedRedrawForReadback should take precedence over all and
714 // issue a readback.
715 for (size_t i = 0; i < num_commit_states; ++i) { 701 for (size_t i = 0; i < num_commit_states; ++i) {
716 for (size_t j = 0; j < 2; ++j) { 702 StateMachine state(default_scheduler_settings);
717 bool request_readback = j; 703 state.SetCanStart();
704 state.UpdateState(state.NextAction());
705 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
706 state.SetCanDraw(true);
707 state.SetCommitState(all_commit_states[i]);
708 state.SetBeginImplFrameState(
709 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE);
718 710
719 StateMachine state(default_scheduler_settings); 711 state.SetNeedsRedraw(true);
720 state.SetCanStart(); 712 state.SetVisible(true);
713
714 SchedulerStateMachine::Action expected_action;
715 if (all_commit_states[i] ==
716 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) {
717 expected_action = SchedulerStateMachine::ACTION_COMMIT;
718 } else {
719 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE;
720 EXPECT_EQ(state.NextAction(), SchedulerStateMachine::ACTION_ANIMATE)
721 << *state.AsValue();
721 state.UpdateState(state.NextAction()); 722 state.UpdateState(state.NextAction());
722 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 723 }
723 state.SetCanDraw(true);
724 state.SetCommitState(all_commit_states[i]);
725 state.SetBeginImplFrameState(
726 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE);
727 724
728 if (request_readback) { 725 // Case 1: needs_commit=false.
729 state.SetNeedsForcedRedrawForReadback(); 726 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue();
730 } else {
731 state.SetNeedsRedraw(true);
732 state.SetVisible(true);
733 }
734 727
735 SchedulerStateMachine::Action expected_action; 728 // Case 2: needs_commit=true.
736 if (request_readback) { 729 state.SetNeedsCommit();
737 expected_action = SchedulerStateMachine::ACTION_DRAW_AND_READBACK; 730 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue();
738 } else if (all_commit_states[i] ==
739 SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT) {
740 expected_action = SchedulerStateMachine::ACTION_COMMIT;
741 } else {
742 expected_action =
743 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE;
744 EXPECT_EQ(state.NextAction(), SchedulerStateMachine::ACTION_ANIMATE)
745 << *state.AsValue();
746 state.UpdateState(state.NextAction());
747 }
748
749 // Case 1: needs_commit=false.
750 EXPECT_NE(state.BeginFrameNeeded(), request_readback) << *state.AsValue();
751 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue();
752
753 // Case 2: needs_commit=true.
754 state.SetNeedsCommit();
755 EXPECT_NE(state.BeginFrameNeeded(), request_readback) << *state.AsValue();
756 EXPECT_EQ(state.NextAction(), expected_action) << *state.AsValue();
757 }
758 } 731 }
759 } 732 }
760 733
761 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) { 734 TEST(SchedulerStateMachineTest, TestNoCommitStatesRedrawWhenInvisible) {
762 SchedulerSettings default_scheduler_settings; 735 SchedulerSettings default_scheduler_settings;
763 736
764 size_t num_commit_states = 737 size_t num_commit_states =
765 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState); 738 sizeof(all_commit_states) / sizeof(SchedulerStateMachine::CommitState);
766 for (size_t i = 0; i < num_commit_states; ++i) { 739 for (size_t i = 0; i < num_commit_states; ++i) {
767 // There shouldn't be any drawing regardless of BeginImplFrame. 740 // There shouldn't be any drawing regardless of BeginImplFrame.
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 1121 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1149 EXPECT_FALSE(state.NeedsCommit()); 1122 EXPECT_FALSE(state.NeedsCommit());
1150 1123
1151 // Verify another commit can start if requested, though. 1124 // Verify another commit can start if requested, though.
1152 state.SetNeedsCommit(); 1125 state.SetNeedsCommit();
1153 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1126 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
1154 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME, 1127 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME,
1155 state.NextAction()); 1128 state.NextAction());
1156 } 1129 }
1157 1130
1131 TEST(SchedulerStateMachineTest,
1132 AbortBeginMainFrameAndCancelCommitWhenInvisible) {
1133 SchedulerSettings default_scheduler_settings;
1134 StateMachine state(default_scheduler_settings);
1135 state.SetCanStart();
1136 state.UpdateState(state.NextAction());
1137 state.DidCreateAndInitializeOutputSurface();
1138 state.SetVisible(true);
1139 state.SetCanDraw(true);
1140
1141 // Get into a begin frame / commit state.
1142 state.SetNeedsCommit();
1143
1144 EXPECT_ACTION_UPDATE_STATE(
1145 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1146 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT,
1147 state.CommitState());
1148 EXPECT_FALSE(state.NeedsCommit());
1149 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1150
1151 // Become invisible and abort BeginMainFrame.
1152 state.SetVisible(false);
1153 state.BeginMainFrameAborted(true);
1154
1155 // Verify that another commit doesn't start on the same frame.
1156 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
1157 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1158 EXPECT_FALSE(state.NeedsCommit());
1159
1160 // Become visible and start a new frame.
1161 state.SetVisible(true);
1162 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
1163 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1164 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1165
1166 // Draw because this is the first frame since output surface init'd.
1167 state.OnBeginImplFrameDeadline();
1168 EXPECT_ACTION_UPDATE_STATE(
1169 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1170 state.DidSwapBuffers();
1171 state.DidSwapBuffersComplete();
1172
1173 // Verify another commit doesn't start on another frame either.
1174 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
1175 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1176 EXPECT_FALSE(state.NeedsCommit());
1177
1178 // Verify another commit can start if requested, though.
1179 state.SetNeedsCommit();
1180 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
1181 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME,
1182 state.NextAction());
1183 }
1184
1185 TEST(SchedulerStateMachineTest,
1186 AbortBeginMainFrameAndRequestCommitWhenInvisible) {
1187 SchedulerSettings default_scheduler_settings;
1188 StateMachine state(default_scheduler_settings);
1189 state.SetCanStart();
1190 state.UpdateState(state.NextAction());
1191 state.DidCreateAndInitializeOutputSurface();
1192 state.SetVisible(true);
1193 state.SetCanDraw(true);
1194
1195 // Get into a begin frame / commit state.
1196 state.SetNeedsCommit();
1197
1198 EXPECT_ACTION_UPDATE_STATE(
1199 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1200 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT,
1201 state.CommitState());
1202 EXPECT_FALSE(state.NeedsCommit());
1203 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1204
1205 // Become invisible and abort BeginMainFrame.
1206 state.SetVisible(false);
1207 state.BeginMainFrameAborted(true);
1208
1209 // Verify that another commit doesn't start on the same frame.
1210 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
1211 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1212 EXPECT_FALSE(state.NeedsCommit());
1213
1214 // Asking for a commit while not visible won't make it happen.
1215 state.SetNeedsCommit();
1216 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
1217 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1218 EXPECT_TRUE(state.NeedsCommit());
1219
1220 // Become visible but nothing happens until the next frame.
brianderson 2014/05/16 23:02:25 Can you call state.OnBeginImplFrame(CreateBeginFra
danakj 2014/05/20 16:05:25 Well, this causes us to be in an impl frame, which
1221 state.SetVisible(true);
1222 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
1223 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1224 EXPECT_TRUE(state.NeedsCommit());
1225
1226 // We should get that commit when we begin the next frame.
1227 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
1228 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1229 EXPECT_ACTION_UPDATE_STATE(
1230 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1231 }
1232
1158 TEST(SchedulerStateMachineTest, TestFirstContextCreation) { 1233 TEST(SchedulerStateMachineTest, TestFirstContextCreation) {
1159 SchedulerSettings default_scheduler_settings; 1234 SchedulerSettings default_scheduler_settings;
1160 StateMachine state(default_scheduler_settings); 1235 StateMachine state(default_scheduler_settings);
1161 state.SetCanStart(); 1236 state.SetCanStart();
1162 state.SetVisible(true); 1237 state.SetVisible(true);
1163 state.SetCanDraw(true); 1238 state.SetCanDraw(true);
1164 1239
1165 EXPECT_ACTION_UPDATE_STATE( 1240 EXPECT_ACTION_UPDATE_STATE(
1166 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 1241 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1167 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1242 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1498 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1424 state.OnBeginImplFrameDeadline(); 1499 state.OnBeginImplFrameDeadline();
1425 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1500 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1426 EXPECT_ACTION_UPDATE_STATE( 1501 EXPECT_ACTION_UPDATE_STATE(
1427 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1502 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1428 state.DidSwapBuffers(); 1503 state.DidSwapBuffers();
1429 state.DidSwapBuffersComplete(); 1504 state.DidSwapBuffersComplete();
1430 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1505 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1431 } 1506 }
1432 1507
1433 TEST(SchedulerStateMachineTest, TestFinishAllRenderingWhileContextLost) {
1434 SchedulerSettings default_scheduler_settings;
1435 StateMachine state(default_scheduler_settings);
1436 state.SetCanStart();
1437 state.UpdateState(state.NextAction());
1438 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1439 state.SetVisible(true);
1440 state.SetCanDraw(true);
1441
1442 // Cause a lost context lost.
1443 state.DidLoseOutputSurface();
1444
1445 // Ask a forced redraw for readback and verify it ocurrs.
1446 state.SetNeedsForcedRedrawForReadback();
1447 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
1448 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1449 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1450
1451 // Forced redraws for readbacks need to be followed by a new commit
1452 // to replace the readback commit.
1453 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT,
1454 state.CommitState());
1455 state.NotifyBeginMainFrameStarted();
1456 state.NotifyReadyToCommit();
1457 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1458
1459 // We don't yet have an output surface, so we the draw and swap should abort.
1460 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1461
1462 // Expect to begin context recreation only in BEGIN_IMPL_FRAME_STATE_IDLE
1463 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1464
1465 state.OnBeginImplFrameDeadline();
1466 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1467
1468 state.OnBeginImplFrameIdle();
1469 EXPECT_ACTION_UPDATE_STATE(
1470 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1471
1472 // Ask a readback and verify it occurs.
1473 state.SetNeedsForcedRedrawForReadback();
1474 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1475 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1476 }
1477
1478 TEST(SchedulerStateMachineTest, DontDrawBeforeCommitAfterLostOutputSurface) { 1508 TEST(SchedulerStateMachineTest, DontDrawBeforeCommitAfterLostOutputSurface) {
1479 SchedulerSettings default_scheduler_settings; 1509 SchedulerSettings default_scheduler_settings;
1480 StateMachine state(default_scheduler_settings); 1510 StateMachine state(default_scheduler_settings);
1481 state.SetCanStart(); 1511 state.SetCanStart();
1482 state.UpdateState(state.NextAction()); 1512 state.UpdateState(state.NextAction());
1483 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1513 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1484 state.SetVisible(true); 1514 state.SetVisible(true);
1485 state.SetCanDraw(true); 1515 state.SetCanDraw(true);
1486 1516
1487 state.SetNeedsRedraw(true); 1517 state.SetNeedsRedraw(true);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1521 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1551 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1522 1552
1523 EXPECT_TRUE(state.PendingActivationsShouldBeForced()); 1553 EXPECT_TRUE(state.PendingActivationsShouldBeForced());
1524 EXPECT_ACTION_UPDATE_STATE( 1554 EXPECT_ACTION_UPDATE_STATE(
1525 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE); 1555 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE);
1526 1556
1527 EXPECT_TRUE(state.PendingDrawsShouldBeAborted()); 1557 EXPECT_TRUE(state.PendingDrawsShouldBeAborted());
1528 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1558 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1529 } 1559 }
1530 1560
1531 TEST(SchedulerStateMachineTest, 1561 TEST(SchedulerStateMachineTest, TestNoBeginMainFrameWhenInvisible) {
1532 TestSendBeginMainFrameWhenInvisibleAndForceCommit) {
1533 SchedulerSettings default_scheduler_settings; 1562 SchedulerSettings default_scheduler_settings;
1534 StateMachine state(default_scheduler_settings); 1563 StateMachine state(default_scheduler_settings);
1535 state.SetCanStart(); 1564 state.SetCanStart();
1536 state.UpdateState(state.NextAction()); 1565 state.UpdateState(state.NextAction());
1537 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1566 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1538 state.SetVisible(false); 1567 state.SetVisible(false);
1539 state.SetNeedsForcedCommitForReadback(); 1568 state.SetNeedsCommit();
1540 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME, 1569 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
1541 state.NextAction());
1542 }
1543
1544 TEST(SchedulerStateMachineTest,
1545 TestSendBeginMainFrameWhenCanStartFalseAndForceCommit) {
1546 SchedulerSettings default_scheduler_settings;
1547 StateMachine state(default_scheduler_settings);
1548 state.SetVisible(true);
1549 state.SetCanDraw(true);
1550 state.SetNeedsForcedCommitForReadback();
1551 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME,
1552 state.NextAction());
1553 }
1554
1555 // If new commit is not requested explicitly after starting forced commit,
1556 // new commit should not scheduled after drawing the replacement commit.
1557 TEST(SchedulerStateMachineTest, DontMakeNewCommitAfterDrawingReplaceCommit) {
1558 SchedulerSettings default_scheduler_settings;
1559 StateMachine state(default_scheduler_settings);
1560 state.SetCanStart();
1561 state.UpdateState(state.NextAction());
1562 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1563 state.SetVisible(true);
1564 state.SetCanDraw(true);
1565
1566 // There is a scheduled commit.
1567 state.SetCommitState(
1568 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT);
1569
1570 // Request a forced commit.
1571 state.SetNeedsForcedCommitForReadback();
1572
1573 state.NotifyBeginMainFrameStarted();
1574 state.NotifyReadyToCommit();
1575 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1576 EXPECT_EQ(SchedulerStateMachine::ACTION_DRAW_AND_READBACK,
1577 state.NextAction());
1578 state.UpdateState(state.NextAction());
1579 EXPECT_EQ(
1580 SchedulerStateMachine::READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT,
1581 state.readback_state());
1582 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT,
1583 state.CommitState());
1584
1585 // Finish the replacement commit.
1586 state.NotifyBeginMainFrameStarted();
1587 state.NotifyReadyToCommit();
1588 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1589
1590 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
1591 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1592 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1593 state.OnBeginImplFrameDeadline();
1594 EXPECT_ACTION_UPDATE_STATE(
1595 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1596 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_IDLE, state.readback_state());
1597 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1598 } 1570 }
1599 1571
1600 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) { 1572 TEST(SchedulerStateMachineTest, TestFinishCommitWhenCommitInProgress) {
1601 SchedulerSettings default_scheduler_settings; 1573 SchedulerSettings default_scheduler_settings;
1602 StateMachine state(default_scheduler_settings); 1574 StateMachine state(default_scheduler_settings);
1603 state.SetCanStart(); 1575 state.SetCanStart();
1604 state.UpdateState(state.NextAction()); 1576 state.UpdateState(state.NextAction());
1605 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1577 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1606 state.SetVisible(false); 1578 state.SetVisible(false);
1607 state.SetCommitState( 1579 state.SetCommitState(
1608 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT); 1580 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT);
1609 state.SetNeedsCommit(); 1581 state.SetNeedsCommit();
1610 1582
1611 state.NotifyBeginMainFrameStarted(); 1583 state.NotifyBeginMainFrameStarted();
1612 state.NotifyReadyToCommit(); 1584 state.NotifyReadyToCommit();
1613 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 1585 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
1614 state.UpdateState(state.NextAction()); 1586 state.UpdateState(state.NextAction());
1615 1587
1616 EXPECT_TRUE(state.active_tree_needs_first_draw()); 1588 EXPECT_TRUE(state.active_tree_needs_first_draw());
1617 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1589 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1618 } 1590 }
1619 1591
1620 TEST(SchedulerStateMachineTest, TestFinishCommitWhenForcedCommitInProgress) {
1621 SchedulerSettings default_scheduler_settings;
1622 StateMachine state(default_scheduler_settings);
1623 state.SetCanStart();
1624 state.UpdateState(state.NextAction());
1625 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1626 state.SetVisible(false);
1627 state.SetCommitState(
1628 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT);
1629 state.SetNeedsForcedCommitForReadback();
1630
1631 // The commit for readback interupts the normal commit.
1632 state.NotifyBeginMainFrameStarted();
1633 state.NotifyReadyToCommit();
1634 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1635
1636 EXPECT_TRUE(state.active_tree_needs_first_draw());
1637 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1638
1639 // When the readback interrupts the normal commit, we should not get
1640 // another BeginMainFrame when the readback completes.
1641 EXPECT_NE(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME,
1642 state.NextAction());
1643
1644 // The normal commit can then proceed.
1645 state.NotifyBeginMainFrameStarted();
1646 state.NotifyReadyToCommit();
1647 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1648 }
1649
1650 void TestForceCommitWhenReplacementActivationInProgress(
1651 bool main_frame_before_draw_enabled) {
1652 SchedulerSettings settings;
1653 settings.impl_side_painting = true;
1654 settings.main_frame_before_draw_enabled = main_frame_before_draw_enabled;
1655 StateMachine state(settings);
1656 state.SetCanStart();
1657 state.UpdateState(state.NextAction());
1658 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1659 state.SetVisible(true);
1660 state.SetCanDraw(true);
1661
1662 // Impl-side painting of replacement commit is in-progress.
1663 if (settings.main_frame_before_draw_enabled) {
1664 state.SetCommitState(
1665 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_ACTIVATION);
1666 } else {
1667 state.SetCommitState(
1668 SchedulerStateMachine::COMMIT_STATE_WAITING_FOR_FIRST_DRAW);
1669 }
1670 state.SetReadbackState(
1671 SchedulerStateMachine::READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION);
1672 state.SetHasPendingTree(true);
1673
1674 // Forced commit is requested during the impl-side painting.
1675 state.SetNeedsForcedCommitForReadback();
1676 EXPECT_FALSE(state.NeedsCommit());
1677
1678 state.NotifyReadyToActivate();
1679 EXPECT_ACTION_UPDATE_STATE(
1680 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE);
1681 // New replacement commit is needed for incoming forced commit.
1682 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME,
1683 state.readback_state());
1684 EXPECT_TRUE(state.NeedsCommit());
1685 if (settings.main_frame_before_draw_enabled) {
1686 // New replacement commit is scheduled.
1687 EXPECT_ACTION_UPDATE_STATE(
1688 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1689 // Forced commit is started.
1690 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_WAITING_FOR_COMMIT,
1691 state.readback_state());
1692 }
1693 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1694
1695 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
1696 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1697 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1698 // Perform the draw & swap of replacement commit.
1699 state.OnBeginImplFrameDeadline();
1700 EXPECT_ACTION_UPDATE_STATE(
1701 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1702 state.DidSwapBuffers();
1703 state.DidSwapBuffersComplete();
1704 if (!settings.main_frame_before_draw_enabled) {
1705 // New replacement commit is scheduled.
1706 EXPECT_ACTION_UPDATE_STATE(
1707 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1708 // Forced commit is started.
1709 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_WAITING_FOR_COMMIT,
1710 state.readback_state());
1711 }
1712 EXPECT_ACTION_UPDATE_STATE(
1713 SchedulerStateMachine::ACTION_NONE);
1714
1715 // Finish the forced commit and draw it.
1716 state.NotifyBeginMainFrameStarted();
1717 state.NotifyReadyToCommit();
1718 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1719 state.NotifyReadyToActivate();
1720 EXPECT_ACTION_UPDATE_STATE(
1721 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE);
1722 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK)
1723 EXPECT_EQ(
1724 SchedulerStateMachine::READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT,
1725 state.readback_state());
1726 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT,
1727 state.CommitState());
1728 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1729
1730 // Finish the replacement commit and draw it.
1731 state.NotifyBeginMainFrameStarted();
1732 state.NotifyReadyToCommit();
1733 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1734 state.NotifyReadyToActivate();
1735 EXPECT_ACTION_UPDATE_STATE(
1736 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE);
1737 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
1738 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1739 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1740 state.OnBeginImplFrameDeadline();
1741 EXPECT_ACTION_UPDATE_STATE(
1742 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1743 state.DidSwapBuffers();
1744 state.DidSwapBuffersComplete();
1745 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_IDLE, state.readback_state());
1746 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1747 }
1748
1749 // Explicitly test when main_frame_before_draw_enabled = true.
1750 TEST(SchedulerStateMachineTest,
1751 ForceCommitWhenReplacementActivationInProgressAndMainFrameEnabled) {
1752 bool main_frame_before_draw_enabled = true;
1753 TestForceCommitWhenReplacementActivationInProgress(
1754 main_frame_before_draw_enabled);
1755 }
1756
1757 // Explicitly test when main_frame_before_draw_enabled = false.
1758 TEST(SchedulerStateMachineTest,
1759 ForceCommitWhenReplacementActivationInProgressAndMainFrameDisabled) {
1760 bool main_frame_before_draw_enabled = false;
1761 TestForceCommitWhenReplacementActivationInProgress(
1762 main_frame_before_draw_enabled);
1763 }
1764
1765 // Test with main_frame_before_activation_enable = true;
1766 TEST(SchedulerStateMachineTest,
1767 ForceCommitWhenReplacementActivationInProgressWithMFBA) {
1768 SchedulerSettings settings;
1769 settings.impl_side_painting = true;
1770 settings.main_frame_before_activation_enabled = true;
1771 StateMachine state(settings);
1772 state.SetCanStart();
1773 state.UpdateState(state.NextAction());
1774 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1775 state.SetVisible(true);
1776 state.SetCanDraw(true);
1777
1778 // When impl-side painting of replacement commit is in-progress, commit state
1779 // is idle because main_frame_before_activation is enabled.
1780 state.SetCommitState(
1781 SchedulerStateMachine::COMMIT_STATE_IDLE);
1782 state.SetReadbackState(
1783 SchedulerStateMachine::READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION);
1784 state.SetHasPendingTree(true);
1785
1786 // New commit is requested and scheduled when impl-side painting is in
1787 // progress.
1788 state.SetNeedsCommit();
1789 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
1790 EXPECT_ACTION_UPDATE_STATE(
1791 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1792 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1793
1794 // Forced commit is requested during the impl-side painting.
1795 state.SetNeedsForcedCommitForReadback();
1796 EXPECT_FALSE(state.NeedsCommit());
1797
1798 state.OnBeginImplFrameDeadline();
1799 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1800
1801 state.NotifyReadyToActivate();
1802 EXPECT_ACTION_UPDATE_STATE(
1803 SchedulerStateMachine::ACTION_ACTIVATE_PENDING_TREE);
1804 // Replacement commit for requested forced commit is already scheduled.
1805 EXPECT_EQ(SchedulerStateMachine::READBACK_STATE_WAITING_FOR_COMMIT,
1806 state.readback_state());
1807 EXPECT_FALSE(state.NeedsCommit());
1808 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1809
1810 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting());
1811 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1812 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1813 // Perform the draw & swap of replacement commit.
1814 state.OnBeginImplFrameDeadline();
1815 EXPECT_ACTION_UPDATE_STATE(
1816 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1817 state.DidSwapBuffers();
1818 state.DidSwapBuffersComplete();
1819 EXPECT_ACTION_UPDATE_STATE(
1820 SchedulerStateMachine::ACTION_NONE);
1821
1822 // forced commit is started.
1823 state.NotifyBeginMainFrameStarted();
1824 state.NotifyReadyToCommit();
1825 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1826 }
1827
1828 TEST(SchedulerStateMachineTest, TestInitialActionsWhenContextLost) { 1592 TEST(SchedulerStateMachineTest, TestInitialActionsWhenContextLost) {
1829 SchedulerSettings default_scheduler_settings; 1593 SchedulerSettings default_scheduler_settings;
1830 StateMachine state(default_scheduler_settings); 1594 StateMachine state(default_scheduler_settings);
1831 state.SetCanStart(); 1595 state.SetCanStart();
1832 state.UpdateState(state.NextAction()); 1596 state.UpdateState(state.NextAction());
1833 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1597 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1834 state.SetVisible(true); 1598 state.SetVisible(true);
1835 state.SetCanDraw(true); 1599 state.SetCanDraw(true);
1836 state.SetNeedsCommit(); 1600 state.SetNeedsCommit();
1837 state.DidLoseOutputSurface(); 1601 state.DidLoseOutputSurface();
1838 1602
1839 // When we are visible, we normally want to begin output surface creation 1603 // When we are visible, we normally want to begin output surface creation
1840 // as soon as possible. 1604 // as soon as possible.
1841 EXPECT_ACTION_UPDATE_STATE( 1605 EXPECT_ACTION_UPDATE_STATE(
1842 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 1606 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1843 1607
1844 state.DidCreateAndInitializeOutputSurface(); 1608 state.DidCreateAndInitializeOutputSurface();
1845 EXPECT_EQ(state.output_surface_state(), 1609 EXPECT_EQ(state.output_surface_state(),
1846 SchedulerStateMachine::OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT); 1610 SchedulerStateMachine::OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT);
1847 1611
1848 // We should not send a BeginMainFrame when we are invisible, even if we've 1612 // We should not send a BeginMainFrame when we are invisible, even if we've
1849 // lost the output surface and are trying to get the first commit, since the 1613 // lost the output surface and are trying to get the first commit, since the
1850 // main thread will just abort anyway. 1614 // main thread will just abort anyway.
1851 state.SetVisible(false); 1615 state.SetVisible(false);
1852 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()) 1616 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction())
1853 << *state.AsValue(); 1617 << *state.AsValue();
1854
1855 // If there is a forced commit, however, we could be blocking a readback
1856 // on the main thread, so we need to unblock it before we can get our
1857 // output surface, even if we are not visible.
1858 state.SetNeedsForcedCommitForReadback();
1859 EXPECT_EQ(
1860 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME, state.NextAction())
1861 << *state.AsValue();
1862 }
1863
1864 TEST(SchedulerStateMachineTest, TestImmediateFinishCommit) {
1865 SchedulerSettings default_scheduler_settings;
1866 StateMachine state(default_scheduler_settings);
1867 state.SetCanStart();
1868 state.UpdateState(state.NextAction());
1869 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1870 state.SetVisible(true);
1871 state.SetCanDraw(true);
1872
1873 // Schedule a readback, commit it, draw it.
1874 state.SetNeedsForcedCommitForReadback();
1875 EXPECT_ACTION_UPDATE_STATE(
1876 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1877
1878 state.NotifyBeginMainFrameStarted();
1879 state.NotifyReadyToCommit();
1880
1881 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
1882 state.CommitState());
1883 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1884
1885 EXPECT_TRUE(state.active_tree_needs_first_draw());
1886
1887 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1888 state.DidSwapBuffers();
1889 state.DidDrawIfPossibleCompleted(DRAW_SUCCESS);
1890 state.DidSwapBuffersComplete();
1891
1892 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1893
1894 // Should be waiting for the normal BeginMainFrame.
1895 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT,
1896 state.CommitState());
1897 }
1898
1899 TEST(SchedulerStateMachineTest, TestImmediateFinishCommitDuringCommit) {
1900 SchedulerSettings scheduler_settings;
1901 StateMachine state(scheduler_settings);
1902 state.SetCanStart();
1903 state.UpdateState(state.NextAction());
1904 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1905 state.SetVisible(true);
1906 state.SetCanDraw(true);
1907
1908 // Start a normal commit.
1909 state.SetNeedsCommit();
1910 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1911
1912 // Schedule a readback, commit it, draw it.
1913 state.SetNeedsForcedCommitForReadback();
1914 EXPECT_ACTION_UPDATE_STATE(
1915 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1916 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1917 state.NotifyBeginMainFrameStarted();
1918 state.NotifyReadyToCommit();
1919 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
1920 state.CommitState());
1921 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1922
1923 EXPECT_TRUE(state.active_tree_needs_first_draw());
1924
1925 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1926 state.DidSwapBuffers();
1927 state.DidDrawIfPossibleCompleted(DRAW_SUCCESS);
1928 state.DidSwapBuffersComplete();
1929 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1930
1931 // Should be waiting for the normal BeginMainFrame.
1932 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT,
1933 state.CommitState())
1934 << *state.AsValue();
1935 }
1936
1937 TEST(SchedulerStateMachineTest, ImmediateBeginMainFrameAbortedWhileInvisible) {
1938 SchedulerSettings scheduler_settings;
1939 StateMachine state(scheduler_settings);
1940 state.SetCanStart();
1941 state.UpdateState(state.NextAction());
1942 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1943 state.SetVisible(true);
1944 state.SetCanDraw(true);
1945
1946 state.SetNeedsCommit();
1947 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1948
1949 state.SetNeedsForcedCommitForReadback();
1950 EXPECT_ACTION_UPDATE_STATE(
1951 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1952 state.NotifyBeginMainFrameStarted();
1953 state.NotifyReadyToCommit();
1954
1955 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
1956 state.CommitState());
1957 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1958
1959 EXPECT_TRUE(state.active_tree_needs_first_draw());
1960
1961 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
1962 state.DidSwapBuffers();
1963 state.DidDrawIfPossibleCompleted(DRAW_SUCCESS);
1964 state.DidSwapBuffersComplete();
1965 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1966
1967 // Should be waiting for BeginMainFrame.
1968 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT,
1969 state.CommitState())
1970 << *state.AsValue();
1971
1972 // Become invisible and abort BeginMainFrame.
1973 state.SetVisible(false);
1974 state.BeginMainFrameAborted(false);
1975
1976 // Should be back in the idle state, but needing a commit.
1977 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
1978 EXPECT_TRUE(state.NeedsCommit());
1979 }
1980
1981 TEST(SchedulerStateMachineTest, ImmediateFinishCommitWhileCantDraw) {
1982 SchedulerSettings default_scheduler_settings;
1983 StateMachine state(default_scheduler_settings);
1984 state.SetCanStart();
1985 state.UpdateState(state.NextAction());
1986 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1987 state.SetVisible(true);
1988 state.SetCanDraw(false);
1989
1990 state.SetNeedsCommit();
1991 state.UpdateState(state.NextAction());
1992
1993 state.SetNeedsForcedCommitForReadback();
1994 state.UpdateState(state.NextAction());
1995 state.NotifyBeginMainFrameStarted();
1996 state.NotifyReadyToCommit();
1997
1998 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT,
1999 state.CommitState());
2000 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
2001
2002 EXPECT_TRUE(state.active_tree_needs_first_draw());
2003
2004 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_DRAW_AND_READBACK);
2005 state.DidSwapBuffers();
2006 state.DidDrawIfPossibleCompleted(DRAW_SUCCESS);
2007 state.DidSwapBuffersComplete();
2008 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2009 } 1618 }
2010 1619
2011 TEST(SchedulerStateMachineTest, ReportIfNotDrawing) { 1620 TEST(SchedulerStateMachineTest, ReportIfNotDrawing) {
2012 SchedulerSettings default_scheduler_settings; 1621 SchedulerSettings default_scheduler_settings;
2013 StateMachine state(default_scheduler_settings); 1622 StateMachine state(default_scheduler_settings);
2014 state.SetCanStart(); 1623 state.SetCanStart();
2015 state.UpdateState(state.NextAction()); 1624 state.UpdateState(state.NextAction());
2016 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1625 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
2017 1626
2018 state.SetCanDraw(true); 1627 state.SetCanDraw(true);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
2170 state.SetNeedsAnimate(); 1779 state.SetNeedsAnimate();
2171 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1780 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
2172 1781
2173 state.OnBeginImplFrameDeadline(); 1782 state.OnBeginImplFrameDeadline();
2174 EXPECT_ACTION_UPDATE_STATE( 1783 EXPECT_ACTION_UPDATE_STATE(
2175 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1784 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
2176 } 1785 }
2177 1786
2178 } // namespace 1787 } // namespace
2179 } // namespace cc 1788 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698