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