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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 EXTERNAL_BFS, | 229 EXTERNAL_BFS, |
230 UNTHROTTLED_BFS, | 230 UNTHROTTLED_BFS, |
231 THROTTLED_BFS, | 231 THROTTLED_BFS, |
232 }; | 232 }; |
233 | 233 |
234 class SchedulerTest : public testing::Test { | 234 class SchedulerTest : public testing::Test { |
235 public: | 235 public: |
236 SchedulerTest() | 236 SchedulerTest() |
237 : now_src_(new base::SimpleTestTickClock()), | 237 : now_src_(new base::SimpleTestTickClock()), |
238 task_runner_(new OrderedSimpleTaskRunner(now_src_.get(), true)), | 238 task_runner_(new OrderedSimpleTaskRunner(now_src_.get(), true)), |
239 fake_external_begin_frame_source_(nullptr) { | 239 fake_external_begin_frame_source_(nullptr), |
| 240 next_begin_frame_number_(1) { |
240 now_src_->Advance(base::TimeDelta::FromMicroseconds(10000)); | 241 now_src_->Advance(base::TimeDelta::FromMicroseconds(10000)); |
241 // A bunch of tests require NowTicks() | 242 // A bunch of tests require NowTicks() |
242 // to be > BeginFrameArgs::DefaultInterval() | 243 // to be > BeginFrameArgs::DefaultInterval() |
243 now_src_->Advance(base::TimeDelta::FromMilliseconds(100)); | 244 now_src_->Advance(base::TimeDelta::FromMilliseconds(100)); |
244 // Fail if we need to run 100 tasks in a row. | 245 // Fail if we need to run 100 tasks in a row. |
245 task_runner_->SetRunTaskLimit(100); | 246 task_runner_->SetRunTaskLimit(100); |
246 } | 247 } |
247 | 248 |
248 ~SchedulerTest() override {} | 249 ~SchedulerTest() override {} |
249 | 250 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 task_runner_->RunTasksWhile(client_->FrameHasNotAdvancedCallback()); | 399 task_runner_->RunTasksWhile(client_->FrameHasNotAdvancedCallback()); |
399 } | 400 } |
400 } | 401 } |
401 | 402 |
402 BeginFrameArgs SendNextBeginFrame() { | 403 BeginFrameArgs SendNextBeginFrame() { |
403 DCHECK_EQ(scheduler_->begin_frame_source(), | 404 DCHECK_EQ(scheduler_->begin_frame_source(), |
404 fake_external_begin_frame_source_.get()); | 405 fake_external_begin_frame_source_.get()); |
405 // Creep the time forward so that any BeginFrameArgs is not equal to the | 406 // Creep the time forward so that any BeginFrameArgs is not equal to the |
406 // last one otherwise we violate the BeginFrameSource contract. | 407 // last one otherwise we violate the BeginFrameSource contract. |
407 now_src_->Advance(BeginFrameArgs::DefaultInterval()); | 408 now_src_->Advance(BeginFrameArgs::DefaultInterval()); |
408 BeginFrameArgs args = | 409 BeginFrameArgs args = CreateBeginFrameArgsForTesting( |
409 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); | 410 BEGINFRAME_FROM_HERE, fake_external_begin_frame_source_->source_id(), |
| 411 next_begin_frame_number_++, now_src()); |
410 fake_external_begin_frame_source_->TestOnBeginFrame(args); | 412 fake_external_begin_frame_source_->TestOnBeginFrame(args); |
411 return args; | 413 return args; |
412 } | 414 } |
413 | 415 |
414 FakeExternalBeginFrameSource* fake_external_begin_frame_source() const { | 416 FakeExternalBeginFrameSource* fake_external_begin_frame_source() const { |
415 return fake_external_begin_frame_source_.get(); | 417 return fake_external_begin_frame_source_.get(); |
416 } | 418 } |
417 | 419 |
418 void AdvanceAndMissOneFrame(); | 420 void AdvanceAndMissOneFrame(); |
419 void CheckMainFrameSkippedAfterLateCommit(bool expect_send_begin_main_frame); | 421 void CheckMainFrameSkippedAfterLateCommit(bool expect_send_begin_main_frame); |
420 void ImplFrameSkippedAfterLateAck(bool receive_ack_before_deadline); | 422 void ImplFrameSkippedAfterLateAck(bool receive_ack_before_deadline); |
421 void ImplFrameNotSkippedAfterLateAck(); | 423 void ImplFrameNotSkippedAfterLateAck(); |
422 void BeginFramesNotFromClient(BeginFrameSourceType bfs_type); | 424 void BeginFramesNotFromClient(BeginFrameSourceType bfs_type); |
423 void BeginFramesNotFromClient_IsDrawThrottled(BeginFrameSourceType bfs_type); | 425 void BeginFramesNotFromClient_IsDrawThrottled(BeginFrameSourceType bfs_type); |
424 bool BeginMainFrameOnCriticalPath(TreePriority tree_priority, | 426 bool BeginMainFrameOnCriticalPath(TreePriority tree_priority, |
425 ScrollHandlerState scroll_handler_state, | 427 ScrollHandlerState scroll_handler_state, |
426 base::TimeDelta durations); | 428 base::TimeDelta durations); |
427 | 429 |
428 std::unique_ptr<base::SimpleTestTickClock> now_src_; | 430 std::unique_ptr<base::SimpleTestTickClock> now_src_; |
429 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; | 431 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; |
430 std::unique_ptr<FakeExternalBeginFrameSource> | 432 std::unique_ptr<FakeExternalBeginFrameSource> |
431 fake_external_begin_frame_source_; | 433 fake_external_begin_frame_source_; |
432 std::unique_ptr<SyntheticBeginFrameSource> synthetic_frame_source_; | 434 std::unique_ptr<SyntheticBeginFrameSource> synthetic_frame_source_; |
433 std::unique_ptr<SyntheticBeginFrameSource> unthrottled_frame_source_; | 435 std::unique_ptr<SyntheticBeginFrameSource> unthrottled_frame_source_; |
434 SchedulerSettings scheduler_settings_; | 436 SchedulerSettings scheduler_settings_; |
435 std::unique_ptr<FakeSchedulerClient> client_; | 437 std::unique_ptr<FakeSchedulerClient> client_; |
436 std::unique_ptr<TestScheduler> scheduler_; | 438 std::unique_ptr<TestScheduler> scheduler_; |
437 FakeCompositorTimingHistory* fake_compositor_timing_history_; | 439 FakeCompositorTimingHistory* fake_compositor_timing_history_; |
| 440 uint64_t next_begin_frame_number_; |
438 }; | 441 }; |
439 | 442 |
440 TEST_F(SchedulerTest, InitializeCompositorFrameSinkDoesNotBeginImplFrame) { | 443 TEST_F(SchedulerTest, InitializeCompositorFrameSinkDoesNotBeginImplFrame) { |
441 SetUpSchedulerWithNoCompositorFrameSink(EXTERNAL_BFS); | 444 SetUpSchedulerWithNoCompositorFrameSink(EXTERNAL_BFS); |
442 scheduler_->SetVisible(true); | 445 scheduler_->SetVisible(true); |
443 scheduler_->SetCanDraw(true); | 446 scheduler_->SetCanDraw(true); |
444 | 447 |
445 EXPECT_SINGLE_ACTION("ScheduledActionBeginCompositorFrameSinkCreation", | 448 EXPECT_SINGLE_ACTION("ScheduledActionBeginCompositorFrameSinkCreation", |
446 client_); | 449 client_); |
447 client_->Reset(); | 450 client_->Reset(); |
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1325 // if it can activate before the deadline. | 1328 // if it can activate before the deadline. |
1326 SetUpScheduler(EXTERNAL_BFS); | 1329 SetUpScheduler(EXTERNAL_BFS); |
1327 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); | 1330 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); |
1328 | 1331 |
1329 AdvanceAndMissOneFrame(); | 1332 AdvanceAndMissOneFrame(); |
1330 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1333 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
1331 scheduler_->SetNeedsBeginMainFrame(); | 1334 scheduler_->SetNeedsBeginMainFrame(); |
1332 | 1335 |
1333 // Advance frame and create a begin frame. | 1336 // Advance frame and create a begin frame. |
1334 now_src_->Advance(BeginFrameArgs::DefaultInterval()); | 1337 now_src_->Advance(BeginFrameArgs::DefaultInterval()); |
1335 BeginFrameArgs args = | 1338 BeginFrameArgs args = CreateBeginFrameArgsForTesting( |
1336 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); | 1339 BEGINFRAME_FROM_HERE, fake_external_begin_frame_source_->source_id(), |
| 1340 next_begin_frame_number_++, now_src()); |
1337 | 1341 |
1338 // Deliver this begin frame super late. | 1342 // Deliver this begin frame super late. |
1339 now_src_->Advance(BeginFrameArgs::DefaultInterval() * 100); | 1343 now_src_->Advance(BeginFrameArgs::DefaultInterval() * 100); |
1340 fake_external_begin_frame_source_->TestOnBeginFrame(args); | 1344 fake_external_begin_frame_source_->TestOnBeginFrame(args); |
1341 | 1345 |
1342 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1346 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
1343 EXPECT_EQ(true, scheduler_->MainThreadMissedLastDeadline()); | 1347 EXPECT_EQ(true, scheduler_->MainThreadMissedLastDeadline()); |
1344 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 1348 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); |
1345 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 3); | 1349 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 3); |
1346 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 2, 3); | 1350 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 2, 3); |
(...skipping 1924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3271 } | 3275 } |
3272 | 3276 |
3273 TEST_F(SchedulerTest, BeginMainFrameOnCriticalPath_AHS) { | 3277 TEST_F(SchedulerTest, BeginMainFrameOnCriticalPath_AHS) { |
3274 EXPECT_FALSE(BeginMainFrameOnCriticalPath( | 3278 EXPECT_FALSE(BeginMainFrameOnCriticalPath( |
3275 SMOOTHNESS_TAKES_PRIORITY, | 3279 SMOOTHNESS_TAKES_PRIORITY, |
3276 ScrollHandlerState::SCROLL_AFFECTS_SCROLL_HANDLER, kSlowDuration)); | 3280 ScrollHandlerState::SCROLL_AFFECTS_SCROLL_HANDLER, kSlowDuration)); |
3277 } | 3281 } |
3278 | 3282 |
3279 } // namespace | 3283 } // namespace |
3280 } // namespace cc | 3284 } // namespace cc |
OLD | NEW |