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

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

Issue 798323003: cc: Only send a BeginMainFrame inside an BeginImplFrame. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing for rename. Created 6 years 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
« no previous file with comments | « cc/scheduler/scheduler_state_machine.cc ('k') | cc/scheduler/scheduler_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "cc/scheduler/scheduler.h" 8 #include "cc/scheduler/scheduler.h"
9 #include "cc/test/begin_frame_args_test.h" 9 #include "cc/test/begin_frame_args_test.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 SchedulerSettings default_scheduler_settings; 1143 SchedulerSettings default_scheduler_settings;
1144 StateMachine state(default_scheduler_settings); 1144 StateMachine state(default_scheduler_settings);
1145 state.SetCanStart(); 1145 state.SetCanStart();
1146 state.UpdateState(state.NextAction()); 1146 state.UpdateState(state.NextAction());
1147 state.DidCreateAndInitializeOutputSurface(); 1147 state.DidCreateAndInitializeOutputSurface();
1148 state.SetVisible(true); 1148 state.SetVisible(true);
1149 state.SetCanDraw(true); 1149 state.SetCanDraw(true);
1150 1150
1151 // Get into a begin frame / commit state. 1151 // Get into a begin frame / commit state.
1152 state.SetNeedsCommit(); 1152 state.SetNeedsCommit();
1153 1153 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1154 EXPECT_ACTION_UPDATE_STATE( 1154 EXPECT_ACTION_UPDATE_STATE(
1155 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1155 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1156 EXPECT_COMMIT_STATE( 1156 EXPECT_COMMIT_STATE(
1157 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT); 1157 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT);
1158 EXPECT_FALSE(state.NeedsCommit()); 1158 EXPECT_FALSE(state.NeedsCommit());
1159 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); 1159 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1160 1160
1161 // Abort the commit, true means that the BeginMainFrame was sent but there 1161 // Abort the commit, true means that the BeginMainFrame was sent but there
1162 // was no work to do on the main thread. 1162 // was no work to do on the main thread.
1163 state.BeginMainFrameAborted(CommitEarlyOutReason::FINISHED_NO_UPDATES); 1163 state.BeginMainFrameAborted(CommitEarlyOutReason::FINISHED_NO_UPDATES);
1164 1164
1165 // NeedsCommit should now be false because the commit was actually handled. 1165 // NeedsCommit should now be false because the commit was actually handled.
1166 EXPECT_FALSE(state.NeedsCommit()); 1166 EXPECT_FALSE(state.NeedsCommit());
1167 // Verify that another commit doesn't start on the same frame.
1168 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE);
1169 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1170 1167
1171 // Even though the commit was aborted, we still expect to draw the new frame. 1168 // Even though the commit was aborted, we still expect to draw the new frame.
1172 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1173 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1169 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1174 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1170 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1175 state.OnBeginImplFrameDeadline(); 1171 state.OnBeginImplFrameDeadline();
1176 EXPECT_ACTION_UPDATE_STATE( 1172 EXPECT_ACTION_UPDATE_STATE(
1177 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1173 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1178 state.DidSwapBuffers(); 1174 state.DidSwapBuffers();
1179 state.DidSwapBuffersComplete(); 1175 state.DidSwapBuffersComplete();
1176 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1180 1177
1181 // Verify another commit doesn't start on another frame either. 1178 // Verify another commit doesn't start on another frame either.
1179 EXPECT_FALSE(state.NeedsCommit());
1182 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE); 1180 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE);
1183 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE); 1181
1184 EXPECT_FALSE(state.NeedsCommit()); 1182 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1183 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1184 state.OnBeginImplFrameDeadline();
1185 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1185 1186
1186 // Verify another commit can start if requested, though. 1187 // Verify another commit can start if requested, though.
1187 state.SetNeedsCommit(); 1188 state.SetNeedsCommit();
1188 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE); 1189 EXPECT_COMMIT_STATE(SchedulerStateMachine::COMMIT_STATE_IDLE);
1190 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1189 EXPECT_ACTION(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1191 EXPECT_ACTION(SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1190 } 1192 }
1191 1193
1192 TEST(SchedulerStateMachineTest, TestFirstContextCreation) { 1194 TEST(SchedulerStateMachineTest, TestFirstContextCreation) {
1193 SchedulerSettings default_scheduler_settings; 1195 SchedulerSettings default_scheduler_settings;
1194 StateMachine state(default_scheduler_settings); 1196 StateMachine state(default_scheduler_settings);
1195 state.SetCanStart(); 1197 state.SetCanStart();
1196 state.SetVisible(true); 1198 state.SetVisible(true);
1197 state.SetCanDraw(true); 1199 state.SetCanDraw(true);
1198 1200
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1239 1241
1240 // When the context is recreated, we should begin a commit. 1242 // When the context is recreated, we should begin a commit.
1241 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1243 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1242 EXPECT_ACTION_UPDATE_STATE( 1244 EXPECT_ACTION_UPDATE_STATE(
1243 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1245 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1244 } 1246 }
1245 1247
1246 TEST(SchedulerStateMachineTest, 1248 TEST(SchedulerStateMachineTest,
1247 TestContextLostWhenIdleAndCommitRequestedWhileRecreating) { 1249 TestContextLostWhenIdleAndCommitRequestedWhileRecreating) {
1248 SchedulerSettings default_scheduler_settings; 1250 SchedulerSettings default_scheduler_settings;
1251 // We use impl side painting because it's the more complicated version.
1252 default_scheduler_settings.impl_side_painting = true;
1249 StateMachine state(default_scheduler_settings); 1253 StateMachine state(default_scheduler_settings);
1250 state.SetCanStart(); 1254 state.SetCanStart();
1251 state.UpdateState(state.NextAction()); 1255 state.UpdateState(state.NextAction());
1252 state.CreateAndInitializeOutputSurfaceWithActivatedCommit(); 1256 state.CreateAndInitializeOutputSurfaceWithActivatedCommit();
1253 state.SetVisible(true); 1257 state.SetVisible(true);
1254 state.SetCanDraw(true); 1258 state.SetCanDraw(true);
1255 1259
1256 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION, 1260 EXPECT_NE(SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION,
1257 state.NextAction()); 1261 state.NextAction());
1258 state.DidLoseOutputSurface(); 1262 state.DidLoseOutputSurface();
1263 EXPECT_EQ(state.output_surface_state(),
1264 SchedulerStateMachine::OUTPUT_SURFACE_LOST);
1259 1265
1260 EXPECT_ACTION_UPDATE_STATE( 1266 EXPECT_ACTION_UPDATE_STATE(
1261 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION); 1267 SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION);
1262 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1268 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1263 1269
1264 // Once context recreation begins, nothing should happen. 1270 // Once context recreation begins, nothing should happen.
1265 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1271 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1266 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1272 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1267 state.OnBeginImplFrameDeadline(); 1273 state.OnBeginImplFrameDeadline();
1268 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1274 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1269 1275
1270 // While context is recreating, commits shouldn't begin. 1276 // While context is recreating, commits shouldn't begin.
1271 state.SetNeedsCommit(); 1277 state.SetNeedsCommit();
1272 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1278 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1273 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1279 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1274 state.OnBeginImplFrameDeadline(); 1280 state.OnBeginImplFrameDeadline();
1275 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1281 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1276 1282
1277 // Recreate the context 1283 // Recreate the context
1278 state.DidCreateAndInitializeOutputSurface(); 1284 state.DidCreateAndInitializeOutputSurface();
1285 EXPECT_EQ(state.output_surface_state(),
1286 SchedulerStateMachine::OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT);
1279 EXPECT_FALSE(state.RedrawPending()); 1287 EXPECT_FALSE(state.RedrawPending());
1280 1288
1281 // When the context is recreated, we should begin a commit 1289 // When the context is recreated, we wait until the next BeginImplFrame
1290 // before starting.
1291 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1292
1293 // When the BeginFrame comes in we should begin a commit
1294 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1282 EXPECT_ACTION_UPDATE_STATE( 1295 EXPECT_ACTION_UPDATE_STATE(
1283 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME); 1296 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1284 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1297 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1285 EXPECT_COMMIT_STATE( 1298 EXPECT_COMMIT_STATE(
1286 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT); 1299 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT);
1287 1300
1301 // Until that commit finishes, we shouldn't be drawing or animate.
1302 state.OnBeginImplFrameDeadline();
1303 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1304
1305 // Finish the commit, which should make the surface active.
1288 state.NotifyBeginMainFrameStarted(); 1306 state.NotifyBeginMainFrameStarted();
1289 state.NotifyReadyToCommit(); 1307 state.NotifyReadyToCommit();
1290 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT); 1308 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1309 EXPECT_EQ(state.output_surface_state(),
1310 SchedulerStateMachine::OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION);
1311 state.NotifyReadyToActivate();
1312 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1291 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1313 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1314 EXPECT_EQ(state.output_surface_state(),
1315 SchedulerStateMachine::OUTPUT_SURFACE_ACTIVE);
1316
1292 // Finishing the first commit after initializing an output surface should 1317 // Finishing the first commit after initializing an output surface should
1293 // automatically cause a redraw. 1318 // automatically cause a redraw.
1294 EXPECT_TRUE(state.RedrawPending()); 1319 EXPECT_TRUE(state.RedrawPending());
1320 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1321 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1322 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1323 state.OnBeginImplFrameDeadline();
1324 EXPECT_ACTION_UPDATE_STATE(
1325 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1326 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1327 EXPECT_FALSE(state.RedrawPending());
1328
1329 // Next frame as no work to do.
1330 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1331 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1332 state.OnBeginImplFrameDeadline();
1333 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1295 1334
1296 // Once the context is recreated, whether we draw should be based on 1335 // Once the context is recreated, whether we draw should be based on
1297 // SetCanDraw. 1336 // SetCanDraw if waiting on first draw after activate.
1337 state.SetNeedsRedraw(true);
1298 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE)); 1338 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1299 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE); 1339 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1300 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE); 1340 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1301 state.OnBeginImplFrameDeadline(); 1341 state.OnBeginImplFrameDeadline();
1302 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1342 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1303 state.SetCanDraw(false); 1343 state.SetCanDraw(false);
1344 EXPECT_ACTION(SchedulerStateMachine::ACTION_NONE);
1345 state.SetCanDraw(true);
1346 EXPECT_ACTION_UPDATE_STATE(
1347 SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1348 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1349
1350 // Once the context is recreated, whether we draw should be based on
1351 // SetCanDraw if waiting on first draw after activate.
1352 state.SetNeedsRedraw(true);
1353 state.SetNeedsCommit();
1354 state.OnBeginImplFrame(CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE));
1355 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1356 EXPECT_ACTION_UPDATE_STATE(
1357 SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME);
1358 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1359 // Activate so we need the first draw
1360 state.NotifyBeginMainFrameStarted();
1361 state.NotifyReadyToCommit();
1362 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_COMMIT);
1363 state.NotifyReadyToActivate();
1364 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE);
1365 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_NONE);
1366 EXPECT_TRUE(state.active_tree_needs_first_draw());
1367 EXPECT_TRUE(state.needs_redraw());
1368
1369 state.OnBeginImplFrameDeadline();
1370 EXPECT_ACTION_UPDATE_STATE(SchedulerStateMachine::ACTION_ANIMATE);
1371 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1372 state.SetCanDraw(false);
1304 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT); 1373 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT);
1305 state.SetCanDraw(true); 1374 state.SetCanDraw(true);
1306 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE); 1375 EXPECT_ACTION(SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE);
1307 } 1376 }
1308 1377
1309 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) { 1378 TEST(SchedulerStateMachineTest, TestContextLostWhileCommitInProgress) {
1310 SchedulerSettings scheduler_settings; 1379 SchedulerSettings scheduler_settings;
1311 StateMachine state(scheduler_settings); 1380 StateMachine state(scheduler_settings);
1312 state.SetCanStart(); 1381 state.SetCanStart();
1313 state.UpdateState(state.NextAction()); 1382 state.UpdateState(state.NextAction());
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
1855 state.SetVisible(true); 1924 state.SetVisible(true);
1856 state.SetCanDraw(true); 1925 state.SetCanDraw(true);
1857 1926
1858 EXPECT_FALSE(state.BeginFrameNeeded()); 1927 EXPECT_FALSE(state.BeginFrameNeeded());
1859 state.SetChildrenNeedBeginFrames(true); 1928 state.SetChildrenNeedBeginFrames(true);
1860 EXPECT_TRUE(state.BeginFrameNeeded()); 1929 EXPECT_TRUE(state.BeginFrameNeeded());
1861 } 1930 }
1862 1931
1863 } // namespace 1932 } // namespace
1864 } // namespace cc 1933 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler_state_machine.cc ('k') | cc/scheduler/scheduler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698