OLD | NEW |
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 #include "cc/scheduler/scheduler.h" | 4 #include "cc/scheduler/scheduler.h" |
5 | 5 |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 254 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
255 client.Reset(); | 255 client.Reset(); |
256 | 256 |
257 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 257 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
258 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 258 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
259 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 259 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
260 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 260 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
261 EXPECT_TRUE(client.needs_begin_impl_frame()); | 261 EXPECT_TRUE(client.needs_begin_impl_frame()); |
262 client.Reset(); | 262 client.Reset(); |
263 | 263 |
264 // If we don't swap on the deadline, we need to request another | 264 // If we don't swap on the deadline, we wait for the next BeginFrame. |
265 // BeginImplFrame. | |
266 client.task_runner().RunPendingTasks(); // Run posted deadline. | 265 client.task_runner().RunPendingTasks(); // Run posted deadline. |
267 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 266 EXPECT_EQ(0, client.num_actions_()); |
268 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 267 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
269 EXPECT_TRUE(client.needs_begin_impl_frame()); | 268 EXPECT_TRUE(client.needs_begin_impl_frame()); |
270 client.Reset(); | 269 client.Reset(); |
271 | 270 |
272 // NotifyReadyToCommit should trigger the commit. | 271 // NotifyReadyToCommit should trigger the commit. |
273 scheduler->NotifyBeginMainFrameStarted(); | 272 scheduler->NotifyBeginMainFrameStarted(); |
274 scheduler->NotifyReadyToCommit(); | 273 scheduler->NotifyReadyToCommit(); |
275 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 274 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
276 EXPECT_TRUE(client.needs_begin_impl_frame()); | 275 EXPECT_TRUE(client.needs_begin_impl_frame()); |
277 client.Reset(); | 276 client.Reset(); |
278 | 277 |
279 // BeginImplFrame should prepare the draw. | 278 // BeginImplFrame should prepare the draw. |
280 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 279 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
281 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 280 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
282 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 281 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
283 EXPECT_TRUE(client.needs_begin_impl_frame()); | 282 EXPECT_TRUE(client.needs_begin_impl_frame()); |
284 client.Reset(); | 283 client.Reset(); |
285 | 284 |
286 // BeginImplFrame deadline should draw. | 285 // BeginImplFrame deadline should draw. |
287 client.task_runner().RunPendingTasks(); // Run posted deadline. | 286 client.task_runner().RunPendingTasks(); // Run posted deadline. |
288 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 287 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); |
289 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); | |
290 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 288 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
291 EXPECT_TRUE(client.needs_begin_impl_frame()); | 289 EXPECT_TRUE(client.needs_begin_impl_frame()); |
292 client.Reset(); | 290 client.Reset(); |
293 | 291 |
294 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 292 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
295 // to avoid excessive toggles. | 293 // to avoid excessive toggles. |
296 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 294 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
297 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 295 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
298 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 296 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
299 client.Reset(); | 297 client.Reset(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 EXPECT_EQ(client.num_actions_(), 0); | 332 EXPECT_EQ(client.num_actions_(), 0); |
335 client.Reset(); | 333 client.Reset(); |
336 | 334 |
337 // Finish the first commit. | 335 // Finish the first commit. |
338 scheduler->NotifyBeginMainFrameStarted(); | 336 scheduler->NotifyBeginMainFrameStarted(); |
339 scheduler->NotifyReadyToCommit(); | 337 scheduler->NotifyReadyToCommit(); |
340 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 338 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
341 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 339 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
342 client.Reset(); | 340 client.Reset(); |
343 client.task_runner().RunPendingTasks(); // Run posted deadline. | 341 client.task_runner().RunPendingTasks(); // Run posted deadline. |
344 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 342 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); |
345 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); | |
346 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 343 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
347 | 344 |
348 // Because we just swapped, the Scheduler should also request the next | 345 // Because we just swapped, the Scheduler should also request the next |
349 // BeginImplFrame from the OutputSurface. | 346 // BeginImplFrame from the OutputSurface. |
350 EXPECT_TRUE(client.needs_begin_impl_frame()); | 347 EXPECT_TRUE(client.needs_begin_impl_frame()); |
351 client.Reset(); | 348 client.Reset(); |
352 // Since another commit is needed, the next BeginImplFrame should initiate | 349 // Since another commit is needed, the next BeginImplFrame should initiate |
353 // the second commit. | 350 // the second commit. |
354 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 351 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
355 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 352 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
356 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 353 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
357 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 354 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
358 client.Reset(); | 355 client.Reset(); |
359 | 356 |
360 // Finishing the commit before the deadline should post a new deadline task | 357 // Finishing the commit before the deadline should post a new deadline task |
361 // to trigger the deadline early. | 358 // to trigger the deadline early. |
362 scheduler->NotifyBeginMainFrameStarted(); | 359 scheduler->NotifyBeginMainFrameStarted(); |
363 scheduler->NotifyReadyToCommit(); | 360 scheduler->NotifyReadyToCommit(); |
364 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 361 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
365 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 362 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
366 client.Reset(); | 363 client.Reset(); |
367 client.task_runner().RunPendingTasks(); // Run posted deadline. | 364 client.task_runner().RunPendingTasks(); // Run posted deadline. |
368 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 365 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); |
369 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); | |
370 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 366 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
371 EXPECT_TRUE(client.needs_begin_impl_frame()); | 367 EXPECT_TRUE(client.needs_begin_impl_frame()); |
372 client.Reset(); | 368 client.Reset(); |
373 | 369 |
374 // On the next BeginImplFrame, verify we go back to a quiescent state and | 370 // On the next BeginImplFrame, verify we go back to a quiescent state and |
375 // no longer request BeginImplFrames. | 371 // no longer request BeginImplFrames. |
376 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 372 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
377 client.task_runner().RunPendingTasks(); // Run posted deadline. | 373 client.task_runner().RunPendingTasks(); // Run posted deadline. |
378 EXPECT_FALSE(client.needs_begin_impl_frame()); | 374 EXPECT_FALSE(client.needs_begin_impl_frame()); |
379 client.Reset(); | 375 client.Reset(); |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 774 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
779 | 775 |
780 // We need a BeginImplFrame where we don't swap to go idle. | 776 // We need a BeginImplFrame where we don't swap to go idle. |
781 client.Reset(); | 777 client.Reset(); |
782 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 778 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
783 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 779 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
784 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 780 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
785 client.Reset(); | 781 client.Reset(); |
786 client.task_runner().RunPendingTasks(); // Run posted deadline. | 782 client.task_runner().RunPendingTasks(); // Run posted deadline. |
787 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 783 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| 784 EXPECT_FALSE(client.needs_begin_impl_frame()); |
788 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 785 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
789 EXPECT_EQ(0, client.num_draws()); | 786 EXPECT_EQ(0, client.num_draws()); |
790 | 787 |
791 // Now trigger a ManageTiles outside of a draw. We will then need | 788 // Now trigger a ManageTiles outside of a draw. We will then need |
792 // a begin-frame for the ManageTiles, but we don't need a draw. | 789 // a begin-frame for the ManageTiles, but we don't need a draw. |
793 client.Reset(); | 790 client.Reset(); |
794 EXPECT_FALSE(client.needs_begin_impl_frame()); | 791 EXPECT_FALSE(client.needs_begin_impl_frame()); |
795 scheduler->SetNeedsManageTiles(); | 792 scheduler->SetNeedsManageTiles(); |
796 EXPECT_TRUE(client.needs_begin_impl_frame()); | 793 EXPECT_TRUE(client.needs_begin_impl_frame()); |
797 EXPECT_TRUE(scheduler->ManageTilesPending()); | 794 EXPECT_TRUE(scheduler->ManageTilesPending()); |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1142 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1139 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1143 EXPECT_TRUE(client.needs_begin_impl_frame()); | 1140 EXPECT_TRUE(client.needs_begin_impl_frame()); |
1144 client.Reset(); | 1141 client.Reset(); |
1145 | 1142 |
1146 // Queue BeginFrames while we are still handling the previous BeginFrame. | 1143 // Queue BeginFrames while we are still handling the previous BeginFrame. |
1147 args.frame_time += base::TimeDelta::FromSeconds(1); | 1144 args.frame_time += base::TimeDelta::FromSeconds(1); |
1148 scheduler->BeginFrame(args); | 1145 scheduler->BeginFrame(args); |
1149 args.frame_time += base::TimeDelta::FromSeconds(1); | 1146 args.frame_time += base::TimeDelta::FromSeconds(1); |
1150 scheduler->BeginFrame(args); | 1147 scheduler->BeginFrame(args); |
1151 | 1148 |
1152 // If we don't swap on the deadline, we need to request another | 1149 // If we don't swap on the deadline, we wait for the next BeginImplFrame. |
1153 // BeginImplFrame. | |
1154 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1150 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1155 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1151 EXPECT_EQ(0, client.num_actions_()); |
1156 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1152 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1157 EXPECT_TRUE(client.needs_begin_impl_frame()); | 1153 EXPECT_TRUE(client.needs_begin_impl_frame()); |
1158 client.Reset(); | 1154 client.Reset(); |
1159 | 1155 |
1160 // NotifyReadyToCommit should trigger the commit. | 1156 // NotifyReadyToCommit should trigger the commit. |
1161 scheduler->NotifyBeginMainFrameStarted(); | 1157 scheduler->NotifyBeginMainFrameStarted(); |
1162 scheduler->NotifyReadyToCommit(); | 1158 scheduler->NotifyReadyToCommit(); |
1163 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1159 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
1164 EXPECT_TRUE(client.needs_begin_impl_frame()); | 1160 EXPECT_TRUE(client.needs_begin_impl_frame()); |
1165 client.Reset(); | 1161 client.Reset(); |
1166 | 1162 |
1167 // BeginImplFrame should prepare the draw. | 1163 // BeginImplFrame should prepare the draw. |
1168 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 1164 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
1169 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 1165 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
1170 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1166 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1171 EXPECT_TRUE(client.needs_begin_impl_frame()); | 1167 EXPECT_TRUE(client.needs_begin_impl_frame()); |
1172 client.Reset(); | 1168 client.Reset(); |
1173 | 1169 |
1174 // BeginImplFrame deadline should draw. | 1170 // BeginImplFrame deadline should draw. |
1175 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1171 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1176 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 1172 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); |
1177 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); | |
1178 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1173 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1179 EXPECT_TRUE(client.needs_begin_impl_frame()); | 1174 EXPECT_TRUE(client.needs_begin_impl_frame()); |
1180 client.Reset(); | 1175 client.Reset(); |
1181 | 1176 |
1182 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 1177 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
1183 // to avoid excessive toggles. | 1178 // to avoid excessive toggles. |
1184 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 1179 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
1185 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 1180 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
1186 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1181 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1187 client.Reset(); | 1182 client.Reset(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1233 | 1228 |
1234 // NotifyReadyToCommit should trigger the pending commit and draw. | 1229 // NotifyReadyToCommit should trigger the pending commit and draw. |
1235 scheduler->NotifyBeginMainFrameStarted(); | 1230 scheduler->NotifyBeginMainFrameStarted(); |
1236 scheduler->NotifyReadyToCommit(); | 1231 scheduler->NotifyReadyToCommit(); |
1237 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1232 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
1238 EXPECT_TRUE(client.needs_begin_impl_frame()); | 1233 EXPECT_TRUE(client.needs_begin_impl_frame()); |
1239 client.Reset(); | 1234 client.Reset(); |
1240 | 1235 |
1241 // Swapping will put us into a swap throttled state. | 1236 // Swapping will put us into a swap throttled state. |
1242 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1237 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1243 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 1238 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); |
1244 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); | |
1245 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1239 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1246 EXPECT_TRUE(client.needs_begin_impl_frame()); | 1240 EXPECT_TRUE(client.needs_begin_impl_frame()); |
1247 client.Reset(); | 1241 client.Reset(); |
1248 | 1242 |
1249 // While swap throttled, BeginRetroFrames should trigger BeginImplFrames | 1243 // While swap throttled, BeginRetroFrames should trigger BeginImplFrames |
1250 // but not a BeginMainFrame or draw. | 1244 // but not a BeginMainFrame or draw. |
1251 scheduler->SetNeedsCommit(); | 1245 scheduler->SetNeedsCommit(); |
1252 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 1246 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
1253 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); | 1247 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); |
1254 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1248 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
(...skipping 11 matching lines...) Expand all Loading... |
1266 // Take us out of a swap throttled state. | 1260 // Take us out of a swap throttled state. |
1267 scheduler->DidSwapBuffersComplete(); | 1261 scheduler->DidSwapBuffersComplete(); |
1268 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1); | 1262 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1); |
1269 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1263 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1270 EXPECT_TRUE(client.needs_begin_impl_frame()); | 1264 EXPECT_TRUE(client.needs_begin_impl_frame()); |
1271 client.Reset(); | 1265 client.Reset(); |
1272 | 1266 |
1273 // BeginImplFrame deadline should draw. | 1267 // BeginImplFrame deadline should draw. |
1274 scheduler->SetNeedsRedraw(); | 1268 scheduler->SetNeedsRedraw(); |
1275 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1269 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1276 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 1270 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); |
1277 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); | |
1278 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1271 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1279 EXPECT_TRUE(client.needs_begin_impl_frame()); | 1272 EXPECT_TRUE(client.needs_begin_impl_frame()); |
1280 client.Reset(); | 1273 client.Reset(); |
1281 } | 1274 } |
1282 | 1275 |
1283 } // namespace | 1276 } // namespace |
1284 } // namespace cc | 1277 } // namespace cc |
OLD | NEW |