| 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 | 4 |
| 5 #include "cc/scheduler/scheduler.h" | 5 #include "cc/scheduler/scheduler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 BeginFrameArgs args = | 408 BeginFrameArgs args = |
| 409 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); | 409 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); |
| 410 fake_external_begin_frame_source_->TestOnBeginFrame(args); | 410 fake_external_begin_frame_source_->TestOnBeginFrame(args); |
| 411 return args; | 411 return args; |
| 412 } | 412 } |
| 413 | 413 |
| 414 FakeExternalBeginFrameSource* fake_external_begin_frame_source() const { | 414 FakeExternalBeginFrameSource* fake_external_begin_frame_source() const { |
| 415 return fake_external_begin_frame_source_.get(); | 415 return fake_external_begin_frame_source_.get(); |
| 416 } | 416 } |
| 417 | 417 |
| 418 void AdvanceAndMissOneFrame(); |
| 418 void CheckMainFrameSkippedAfterLateCommit(bool expect_send_begin_main_frame); | 419 void CheckMainFrameSkippedAfterLateCommit(bool expect_send_begin_main_frame); |
| 419 void ImplFrameSkippedAfterLateAck(bool receive_ack_before_deadline); | 420 void ImplFrameSkippedAfterLateAck(bool receive_ack_before_deadline); |
| 420 void ImplFrameNotSkippedAfterLateAck(); | 421 void ImplFrameNotSkippedAfterLateAck(); |
| 421 void BeginFramesNotFromClient(BeginFrameSourceType bfs_type); | 422 void BeginFramesNotFromClient(BeginFrameSourceType bfs_type); |
| 422 void BeginFramesNotFromClient_IsDrawThrottled(BeginFrameSourceType bfs_type); | 423 void BeginFramesNotFromClient_IsDrawThrottled(BeginFrameSourceType bfs_type); |
| 423 bool BeginMainFrameOnCriticalPath(TreePriority tree_priority, | 424 bool BeginMainFrameOnCriticalPath(TreePriority tree_priority, |
| 424 ScrollHandlerState scroll_handler_state, | 425 ScrollHandlerState scroll_handler_state, |
| 425 base::TimeDelta durations); | 426 base::TimeDelta durations); |
| 426 | 427 |
| 427 std::unique_ptr<base::SimpleTestTickClock> now_src_; | 428 std::unique_ptr<base::SimpleTestTickClock> now_src_; |
| (...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1275 client_->Reset(); | 1276 client_->Reset(); |
| 1276 scheduler_->DidLoseCompositorFrameSink(); | 1277 scheduler_->DidLoseCompositorFrameSink(); |
| 1277 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); | 1278 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1278 task_runner().RunPendingTasks(); // Run posted deadline. | 1279 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1279 EXPECT_ACTION("ScheduledActionBeginCompositorFrameSinkCreation", client_, 0, | 1280 EXPECT_ACTION("ScheduledActionBeginCompositorFrameSinkCreation", client_, 0, |
| 1280 3); | 1281 3); |
| 1281 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); | 1282 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); |
| 1282 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 1283 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); |
| 1283 } | 1284 } |
| 1284 | 1285 |
| 1285 void SchedulerTest::CheckMainFrameSkippedAfterLateCommit( | 1286 void SchedulerTest::AdvanceAndMissOneFrame() { |
| 1286 bool expect_send_begin_main_frame) { | |
| 1287 // Impl thread hits deadline before commit finishes. | 1287 // Impl thread hits deadline before commit finishes. |
| 1288 scheduler_->SetNeedsBeginMainFrame(); | 1288 scheduler_->SetNeedsBeginMainFrame(); |
| 1289 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1289 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1290 EXPECT_SCOPED(AdvanceFrame()); | 1290 EXPECT_SCOPED(AdvanceFrame()); |
| 1291 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1291 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1292 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1292 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1293 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1293 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1294 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 1294 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1295 scheduler_->NotifyReadyToCommit(); | 1295 scheduler_->NotifyReadyToCommit(); |
| 1296 scheduler_->NotifyReadyToActivate(); | 1296 scheduler_->NotifyReadyToActivate(); |
| 1297 EXPECT_ACTION("AddObserver(this)", client_, 0, 5); | 1297 EXPECT_ACTION("AddObserver(this)", client_, 0, 5); |
| 1298 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 5); | 1298 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 5); |
| 1299 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 5); | 1299 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 5); |
| 1300 EXPECT_ACTION("ScheduledActionCommit", client_, 3, 5); | 1300 EXPECT_ACTION("ScheduledActionCommit", client_, 3, 5); |
| 1301 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 4, 5); | 1301 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 4, 5); |
| 1302 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1302 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1303 client_->Reset(); |
| 1304 } |
| 1303 | 1305 |
| 1304 client_->Reset(); | 1306 void SchedulerTest::CheckMainFrameSkippedAfterLateCommit( |
| 1307 bool expect_send_begin_main_frame) { |
| 1308 AdvanceAndMissOneFrame(); |
| 1309 |
| 1305 scheduler_->SetNeedsBeginMainFrame(); | 1310 scheduler_->SetNeedsBeginMainFrame(); |
| 1306 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1311 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1307 EXPECT_SCOPED(AdvanceFrame()); | 1312 EXPECT_SCOPED(AdvanceFrame()); |
| 1308 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1313 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1309 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1314 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1310 EXPECT_EQ(expect_send_begin_main_frame, | 1315 EXPECT_EQ(expect_send_begin_main_frame, |
| 1311 scheduler_->MainThreadMissedLastDeadline()); | 1316 scheduler_->MainThreadMissedLastDeadline()); |
| 1312 EXPECT_TRUE(client_->HasAction("WillBeginImplFrame")); | 1317 EXPECT_TRUE(client_->HasAction("WillBeginImplFrame")); |
| 1313 EXPECT_EQ(expect_send_begin_main_frame, | 1318 EXPECT_EQ(expect_send_begin_main_frame, |
| 1314 client_->HasAction("ScheduledActionSendBeginMainFrame")); | 1319 client_->HasAction("ScheduledActionSendBeginMainFrame")); |
| 1315 } | 1320 } |
| 1316 | 1321 |
| 1322 TEST_F(SchedulerTest, MainFrameNotSkippedAfterLateBeginFrame) { |
| 1323 // If a begin frame is delivered extremely late (because the browser has |
| 1324 // some contention), make sure that the main frame is not skipped even |
| 1325 // if it can activate before the deadline. |
| 1326 SetUpScheduler(EXTERNAL_BFS); |
| 1327 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); |
| 1328 |
| 1329 AdvanceAndMissOneFrame(); |
| 1330 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1331 scheduler_->SetNeedsBeginMainFrame(); |
| 1332 |
| 1333 // Advance frame and create a begin frame. |
| 1334 now_src_->Advance(BeginFrameArgs::DefaultInterval()); |
| 1335 BeginFrameArgs args = |
| 1336 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); |
| 1337 |
| 1338 // Deliver this begin frame super late. |
| 1339 now_src_->Advance(BeginFrameArgs::DefaultInterval() * 100); |
| 1340 fake_external_begin_frame_source_->TestOnBeginFrame(args); |
| 1341 |
| 1342 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1343 EXPECT_EQ(true, scheduler_->MainThreadMissedLastDeadline()); |
| 1344 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); |
| 1345 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 3); |
| 1346 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 2, 3); |
| 1347 } |
| 1348 |
| 1317 TEST_F(SchedulerTest, MainFrameSkippedAfterLateCommit) { | 1349 TEST_F(SchedulerTest, MainFrameSkippedAfterLateCommit) { |
| 1318 SetUpScheduler(EXTERNAL_BFS); | 1350 SetUpScheduler(EXTERNAL_BFS); |
| 1319 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); | 1351 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); |
| 1320 | 1352 |
| 1321 bool expect_send_begin_main_frame = false; | 1353 bool expect_send_begin_main_frame = false; |
| 1322 EXPECT_SCOPED( | 1354 EXPECT_SCOPED( |
| 1323 CheckMainFrameSkippedAfterLateCommit(expect_send_begin_main_frame)); | 1355 CheckMainFrameSkippedAfterLateCommit(expect_send_begin_main_frame)); |
| 1324 } | 1356 } |
| 1325 | 1357 |
| 1326 // Response times of BeginMainFrame's without the critical path flag set | 1358 // Response times of BeginMainFrame's without the critical path flag set |
| (...skipping 1912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3239 } | 3271 } |
| 3240 | 3272 |
| 3241 TEST_F(SchedulerTest, BeginMainFrameOnCriticalPath_AHS) { | 3273 TEST_F(SchedulerTest, BeginMainFrameOnCriticalPath_AHS) { |
| 3242 EXPECT_FALSE(BeginMainFrameOnCriticalPath( | 3274 EXPECT_FALSE(BeginMainFrameOnCriticalPath( |
| 3243 SMOOTHNESS_TAKES_PRIORITY, | 3275 SMOOTHNESS_TAKES_PRIORITY, |
| 3244 ScrollHandlerState::SCROLL_AFFECTS_SCROLL_HANDLER, kSlowDuration)); | 3276 ScrollHandlerState::SCROLL_AFFECTS_SCROLL_HANDLER, kSlowDuration)); |
| 3245 } | 3277 } |
| 3246 | 3278 |
| 3247 } // namespace | 3279 } // namespace |
| 3248 } // namespace cc | 3280 } // namespace cc |
| OLD | NEW |