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

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

Issue 19106007: cc: Allow the main thread to cancel commits (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments Created 7 years, 5 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 "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace cc { 10 namespace cc {
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 // Begin the frame while visible. 711 // Begin the frame while visible.
712 state.UpdateState( 712 state.UpdateState(
713 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD); 713 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
714 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 714 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
715 state.CommitState()); 715 state.CommitState());
716 EXPECT_FALSE(state.NeedsCommit()); 716 EXPECT_FALSE(state.NeedsCommit());
717 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 717 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
718 718
719 // Become invisible and abort the main thread's begin frame. 719 // Become invisible and abort the main thread's begin frame.
720 state.SetVisible(false); 720 state.SetVisible(false);
721 state.BeginFrameAbortedByMainThread(); 721 state.BeginFrameAbortedByMainThread(false);
722 722
723 // We should now be back in the idle state as if we didn't start a frame at 723 // We should now be back in the idle state as if we didn't start a frame at
724 // all. 724 // all.
725 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 725 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
726 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction()); 726 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
727 727
728 // Become visible again. 728 // Become visible again.
729 state.SetVisible(true); 729 state.SetVisible(true);
730 730
731 // Although we have aborted on this frame and haven't cancelled the commit
732 // (i.e. need another), don't send another begin frame yet.
733 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
734 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
735 EXPECT_TRUE(state.NeedsCommit());
736
737 // Start a new frame.
738 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting());
739 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
740 state.DidLeaveBeginFrame();
741
731 // We should be beginning a frame now. 742 // We should be beginning a frame now.
732 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 743 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
733 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, 744 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
734 state.NextAction()); 745 state.NextAction());
735 746
736 // Begin the frame. 747 // Begin the frame.
737 state.UpdateState(state.NextAction()); 748 state.UpdateState(state.NextAction());
738 749
739 // We should be starting the commit now. 750 // We should be starting the commit now.
740 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 751 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
741 state.CommitState()); 752 state.CommitState());
742 } 753 }
743 754
755 TEST(SchedulerStateMachineTest, AbortBeginFrameAndCancelCommit) {
756 SchedulerSettings default_scheduler_settings;
757 StateMachine state(default_scheduler_settings);
758 state.SetCanStart();
759 state.UpdateState(state.NextAction());
760 state.DidCreateAndInitializeOutputSurface();
761 state.SetVisible(true);
762 state.SetCanDraw(true);
763
764 // Get into a begin frame / commit state.
765 state.SetNeedsCommit();
766 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
767 state.NextAction());
768 state.UpdateState(
769 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
770 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
771 state.CommitState());
772 EXPECT_FALSE(state.NeedsCommit());
773 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
774
775 // Abort the commit, cancelling future commits.
776 state.BeginFrameAbortedByMainThread(true);
777
778 // Verify that another commit doesn't start on the same frame.
779 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
780 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
781 EXPECT_FALSE(state.NeedsCommit());
782
783 // Start a new frame.
784 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting());
785 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
786 state.DidLeaveBeginFrame();
787
788 // Verify another commit doesn't start on another frame either.
789 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
790 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
791 EXPECT_FALSE(state.NeedsCommit());
792
793 // Verify another commit can start if requested, though.
794 state.SetNeedsCommit();
795 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
796 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
797 state.NextAction());
798 }
799
744 TEST(SchedulerStateMachineTest, TestFirstContextCreation) { 800 TEST(SchedulerStateMachineTest, TestFirstContextCreation) {
745 SchedulerSettings default_scheduler_settings; 801 SchedulerSettings default_scheduler_settings;
746 StateMachine state(default_scheduler_settings); 802 StateMachine state(default_scheduler_settings);
747 state.SetCanStart(); 803 state.SetCanStart();
748 state.SetVisible(true); 804 state.SetVisible(true);
749 state.SetCanDraw(true); 805 state.SetCanDraw(true);
750 806
751 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 807 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
752 state.NextAction()); 808 state.NextAction());
753 state.UpdateState(state.NextAction()); 809 state.UpdateState(state.NextAction());
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 state.UpdateState(state.NextAction()); 1241 state.UpdateState(state.NextAction());
1186 state.DidDrawIfPossibleCompleted(true); 1242 state.DidDrawIfPossibleCompleted(true);
1187 state.DidLeaveBeginFrame(); 1243 state.DidLeaveBeginFrame();
1188 1244
1189 // Should be waiting for the main thread's begin frame. 1245 // Should be waiting for the main thread's begin frame.
1190 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 1246 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
1191 state.CommitState()) << state.ToString(); 1247 state.CommitState()) << state.ToString();
1192 1248
1193 // Become invisible and abort the main thread's begin frame. 1249 // Become invisible and abort the main thread's begin frame.
1194 state.SetVisible(false); 1250 state.SetVisible(false);
1195 state.BeginFrameAbortedByMainThread(); 1251 state.BeginFrameAbortedByMainThread(false);
1196 1252
1197 // Should be back in the idle state, but needing a commit. 1253 // Should be back in the idle state, but needing a commit.
1198 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1254 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
1199 EXPECT_TRUE(state.NeedsCommit()); 1255 EXPECT_TRUE(state.NeedsCommit());
1200 } 1256 }
1201 1257
1202 TEST(SchedulerStateMachineTest, ImmediateFinishCommitWhileCantDraw) { 1258 TEST(SchedulerStateMachineTest, ImmediateFinishCommitWhileCantDraw) {
1203 SchedulerSettings default_scheduler_settings; 1259 SchedulerSettings default_scheduler_settings;
1204 StateMachine state(default_scheduler_settings); 1260 StateMachine state(default_scheduler_settings);
1205 state.SetCanStart(); 1261 state.SetCanStart();
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 EXPECT_TRUE(state.DrawSuspendedUntilCommit()); 1346 EXPECT_TRUE(state.DrawSuspendedUntilCommit());
1291 1347
1292 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 1348 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
1293 1349
1294 state.UpdateState(state.NextAction()); 1350 state.UpdateState(state.NextAction());
1295 EXPECT_FALSE(state.DrawSuspendedUntilCommit()); 1351 EXPECT_FALSE(state.DrawSuspendedUntilCommit());
1296 } 1352 }
1297 1353
1298 } // namespace 1354 } // namespace
1299 } // namespace cc 1355 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698