Chromium Code Reviews| 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()); | |
|
brianderson
2016/12/15 22:10:33
Increment after.
Eric Seckler
2016/12/16 17:25:58
Done.
| |
| 410 fake_external_begin_frame_source_->TestOnBeginFrame(args); | 414 fake_external_begin_frame_source_->TestOnBeginFrame(args); |
| 411 return args; | 415 return args; |
| 412 } | 416 } |
| 413 | 417 |
| 414 FakeExternalBeginFrameSource* fake_external_begin_frame_source() const { | 418 FakeExternalBeginFrameSource* fake_external_begin_frame_source() const { |
| 415 return fake_external_begin_frame_source_.get(); | 419 return fake_external_begin_frame_source_.get(); |
| 416 } | 420 } |
| 417 | 421 |
| 418 void AdvanceAndMissOneFrame(); | 422 void AdvanceAndMissOneFrame(); |
| 419 void CheckMainFrameSkippedAfterLateCommit(bool expect_send_begin_main_frame); | 423 void CheckMainFrameSkippedAfterLateCommit(bool expect_send_begin_main_frame); |
| 420 void ImplFrameSkippedAfterLateAck(bool receive_ack_before_deadline); | 424 void ImplFrameSkippedAfterLateAck(bool receive_ack_before_deadline); |
| 421 void ImplFrameNotSkippedAfterLateAck(); | 425 void ImplFrameNotSkippedAfterLateAck(); |
| 422 void BeginFramesNotFromClient(BeginFrameSourceType bfs_type); | 426 void BeginFramesNotFromClient(BeginFrameSourceType bfs_type); |
| 423 void BeginFramesNotFromClient_IsDrawThrottled(BeginFrameSourceType bfs_type); | 427 void BeginFramesNotFromClient_IsDrawThrottled(BeginFrameSourceType bfs_type); |
| 424 bool BeginMainFrameOnCriticalPath(TreePriority tree_priority, | 428 bool BeginMainFrameOnCriticalPath(TreePriority tree_priority, |
| 425 ScrollHandlerState scroll_handler_state, | 429 ScrollHandlerState scroll_handler_state, |
| 426 base::TimeDelta durations); | 430 base::TimeDelta durations); |
| 427 | 431 |
| 428 std::unique_ptr<base::SimpleTestTickClock> now_src_; | 432 std::unique_ptr<base::SimpleTestTickClock> now_src_; |
| 429 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; | 433 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; |
| 430 std::unique_ptr<FakeExternalBeginFrameSource> | 434 std::unique_ptr<FakeExternalBeginFrameSource> |
| 431 fake_external_begin_frame_source_; | 435 fake_external_begin_frame_source_; |
| 432 std::unique_ptr<SyntheticBeginFrameSource> synthetic_frame_source_; | 436 std::unique_ptr<SyntheticBeginFrameSource> synthetic_frame_source_; |
| 433 std::unique_ptr<SyntheticBeginFrameSource> unthrottled_frame_source_; | 437 std::unique_ptr<SyntheticBeginFrameSource> unthrottled_frame_source_; |
| 434 SchedulerSettings scheduler_settings_; | 438 SchedulerSettings scheduler_settings_; |
| 435 std::unique_ptr<FakeSchedulerClient> client_; | 439 std::unique_ptr<FakeSchedulerClient> client_; |
| 436 std::unique_ptr<TestScheduler> scheduler_; | 440 std::unique_ptr<TestScheduler> scheduler_; |
| 437 FakeCompositorTimingHistory* fake_compositor_timing_history_; | 441 FakeCompositorTimingHistory* fake_compositor_timing_history_; |
| 442 uint64_t next_begin_frame_number_; | |
| 438 }; | 443 }; |
| 439 | 444 |
| 440 TEST_F(SchedulerTest, InitializeCompositorFrameSinkDoesNotBeginImplFrame) { | 445 TEST_F(SchedulerTest, InitializeCompositorFrameSinkDoesNotBeginImplFrame) { |
| 441 SetUpSchedulerWithNoCompositorFrameSink(EXTERNAL_BFS); | 446 SetUpSchedulerWithNoCompositorFrameSink(EXTERNAL_BFS); |
| 442 scheduler_->SetVisible(true); | 447 scheduler_->SetVisible(true); |
| 443 scheduler_->SetCanDraw(true); | 448 scheduler_->SetCanDraw(true); |
| 444 | 449 |
| 445 EXPECT_SINGLE_ACTION("ScheduledActionBeginCompositorFrameSinkCreation", | 450 EXPECT_SINGLE_ACTION("ScheduledActionBeginCompositorFrameSinkCreation", |
| 446 client_); | 451 client_); |
| 447 client_->Reset(); | 452 client_->Reset(); |
| (...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1325 // if it can activate before the deadline. | 1330 // if it can activate before the deadline. |
| 1326 SetUpScheduler(EXTERNAL_BFS); | 1331 SetUpScheduler(EXTERNAL_BFS); |
| 1327 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); | 1332 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); |
| 1328 | 1333 |
| 1329 AdvanceAndMissOneFrame(); | 1334 AdvanceAndMissOneFrame(); |
| 1330 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1335 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1331 scheduler_->SetNeedsBeginMainFrame(); | 1336 scheduler_->SetNeedsBeginMainFrame(); |
| 1332 | 1337 |
| 1333 // Advance frame and create a begin frame. | 1338 // Advance frame and create a begin frame. |
| 1334 now_src_->Advance(BeginFrameArgs::DefaultInterval()); | 1339 now_src_->Advance(BeginFrameArgs::DefaultInterval()); |
| 1335 BeginFrameArgs args = | 1340 BeginFrameArgs args = CreateBeginFrameArgsForTesting( |
| 1336 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); | 1341 BEGINFRAME_FROM_HERE, fake_external_begin_frame_source_->source_id(), |
| 1342 next_begin_frame_number_++, now_src()); | |
|
brianderson
2016/12/15 22:10:33
Increment after.
Eric Seckler
2016/12/16 17:25:58
Done.
| |
| 1337 | 1343 |
| 1338 // Deliver this begin frame super late. | 1344 // Deliver this begin frame super late. |
| 1339 now_src_->Advance(BeginFrameArgs::DefaultInterval() * 100); | 1345 now_src_->Advance(BeginFrameArgs::DefaultInterval() * 100); |
| 1340 fake_external_begin_frame_source_->TestOnBeginFrame(args); | 1346 fake_external_begin_frame_source_->TestOnBeginFrame(args); |
| 1341 | 1347 |
| 1342 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); | 1348 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1343 EXPECT_EQ(true, scheduler_->MainThreadMissedLastDeadline()); | 1349 EXPECT_EQ(true, scheduler_->MainThreadMissedLastDeadline()); |
| 1344 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 1350 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); |
| 1345 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 3); | 1351 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 3); |
| 1346 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 2, 3); | 1352 EXPECT_ACTION("ScheduledActionDrawIfPossible", client_, 2, 3); |
| (...skipping 1924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3271 } | 3277 } |
| 3272 | 3278 |
| 3273 TEST_F(SchedulerTest, BeginMainFrameOnCriticalPath_AHS) { | 3279 TEST_F(SchedulerTest, BeginMainFrameOnCriticalPath_AHS) { |
| 3274 EXPECT_FALSE(BeginMainFrameOnCriticalPath( | 3280 EXPECT_FALSE(BeginMainFrameOnCriticalPath( |
| 3275 SMOOTHNESS_TAKES_PRIORITY, | 3281 SMOOTHNESS_TAKES_PRIORITY, |
| 3276 ScrollHandlerState::SCROLL_AFFECTS_SCROLL_HANDLER, kSlowDuration)); | 3282 ScrollHandlerState::SCROLL_AFFECTS_SCROLL_HANDLER, kSlowDuration)); |
| 3277 } | 3283 } |
| 3278 | 3284 |
| 3279 } // namespace | 3285 } // namespace |
| 3280 } // namespace cc | 3286 } // namespace cc |
| OLD | NEW |