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

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 danakj's 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 // We should be beginning a frame now. 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.
732 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 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());
733 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD, 739 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
734 state.NextAction()); 740 state.NextAction());
735 741
736 // Begin the frame. 742 // Begin the frame.
737 state.UpdateState(state.NextAction()); 743 state.UpdateState(state.NextAction());
738 744
739 // We should be starting the commit now. 745 // We should be starting the commit now.
740 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 746 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
741 state.CommitState()); 747 state.CommitState());
742 } 748 }
743 749
750 TEST(SchedulerStateMachineTest, AbortBeginFrameAndCancelCommit) {
751 SchedulerSettings default_scheduler_settings;
752 StateMachine state(default_scheduler_settings);
753 state.SetCanStart();
754 state.UpdateState(state.NextAction());
755 state.DidCreateAndInitializeOutputSurface();
756 state.SetVisible(true);
757 state.SetCanDraw(true);
758
759 // Get into a begin frame / commit state.
760 state.SetNeedsCommit();
761 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
762 state.NextAction());
763 state.UpdateState(
764 SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD);
765 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
766 state.CommitState());
767 EXPECT_FALSE(state.NeedsCommit());
768 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
769
770 // Abort the commit, cancelling future commits.
771 state.BeginFrameAbortedByMainThread(true);
772
773 // Verify that another commit doesn't start on the same frame.
774 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
775 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
776 EXPECT_FALSE(state.NeedsCommit());
777
778 // Start a new frame.
779 state.DidEnterBeginFrame(BeginFrameArgs::CreateForTesting());
780 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
781 state.DidLeaveBeginFrame();
782
783 // Verify another commit doesn't start on another frame either.
784 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
785 EXPECT_EQ(SchedulerStateMachine::ACTION_NONE, state.NextAction());
786 EXPECT_FALSE(state.NeedsCommit());
787
788 // Verify another commit can start if requested, though.
789 state.SetNeedsCommit();
790 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
791 EXPECT_EQ(SchedulerStateMachine::ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD,
792 state.NextAction());
793 }
794
744 TEST(SchedulerStateMachineTest, TestFirstContextCreation) { 795 TEST(SchedulerStateMachineTest, TestFirstContextCreation) {
745 SchedulerSettings default_scheduler_settings; 796 SchedulerSettings default_scheduler_settings;
746 StateMachine state(default_scheduler_settings); 797 StateMachine state(default_scheduler_settings);
747 state.SetCanStart(); 798 state.SetCanStart();
748 state.SetVisible(true); 799 state.SetVisible(true);
749 state.SetCanDraw(true); 800 state.SetCanDraw(true);
750 801
751 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 802 EXPECT_EQ(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
752 state.NextAction()); 803 state.NextAction());
753 state.UpdateState(state.NextAction()); 804 state.UpdateState(state.NextAction());
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 state.UpdateState(state.NextAction()); 1236 state.UpdateState(state.NextAction());
1186 state.DidDrawIfPossibleCompleted(true); 1237 state.DidDrawIfPossibleCompleted(true);
1187 state.DidLeaveBeginFrame(); 1238 state.DidLeaveBeginFrame();
1188 1239
1189 // Should be waiting for the main thread's begin frame. 1240 // Should be waiting for the main thread's begin frame.
1190 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, 1241 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
1191 state.CommitState()) << state.ToString(); 1242 state.CommitState()) << state.ToString();
1192 1243
1193 // Become invisible and abort the main thread's begin frame. 1244 // Become invisible and abort the main thread's begin frame.
1194 state.SetVisible(false); 1245 state.SetVisible(false);
1195 state.BeginFrameAbortedByMainThread(); 1246 state.BeginFrameAbortedByMainThread(false);
1196 1247
1197 // Should be back in the idle state, but needing a commit. 1248 // Should be back in the idle state, but needing a commit.
1198 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState()); 1249 EXPECT_EQ(SchedulerStateMachine::COMMIT_STATE_IDLE, state.CommitState());
1199 EXPECT_TRUE(state.NeedsCommit()); 1250 EXPECT_TRUE(state.NeedsCommit());
1200 } 1251 }
1201 1252
1202 TEST(SchedulerStateMachineTest, ImmediateFinishCommitWhileCantDraw) { 1253 TEST(SchedulerStateMachineTest, ImmediateFinishCommitWhileCantDraw) {
1203 SchedulerSettings default_scheduler_settings; 1254 SchedulerSettings default_scheduler_settings;
1204 StateMachine state(default_scheduler_settings); 1255 StateMachine state(default_scheduler_settings);
1205 state.SetCanStart(); 1256 state.SetCanStart();
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 EXPECT_TRUE(state.DrawSuspendedUntilCommit()); 1341 EXPECT_TRUE(state.DrawSuspendedUntilCommit());
1291 1342
1292 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction()); 1343 EXPECT_EQ(SchedulerStateMachine::ACTION_COMMIT, state.NextAction());
1293 1344
1294 state.UpdateState(state.NextAction()); 1345 state.UpdateState(state.NextAction());
1295 EXPECT_FALSE(state.DrawSuspendedUntilCommit()); 1346 EXPECT_FALSE(state.DrawSuspendedUntilCommit());
1296 } 1347 }
1297 1348
1298 } // namespace 1349 } // namespace
1299 } // namespace cc 1350 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698