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/test/begin_frame_args_test.h" | 19 #include "cc/test/begin_frame_args_test.h" |
20 #include "cc/test/fake_external_begin_frame_source.h" | |
20 #include "cc/test/ordered_simple_task_runner.h" | 21 #include "cc/test/ordered_simple_task_runner.h" |
21 #include "cc/test/scheduler_test_common.h" | 22 #include "cc/test/scheduler_test_common.h" |
22 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
24 | 25 |
25 #define EXPECT_ACTION(action, client, action_index, expected_num_actions) \ | 26 #define EXPECT_ACTION(action, client, action_index, expected_num_actions) \ |
26 do { \ | 27 do { \ |
27 EXPECT_EQ(expected_num_actions, client->num_actions_()); \ | 28 EXPECT_EQ(expected_num_actions, client->num_actions_()); \ |
28 if (action_index >= 0) { \ | 29 if (action_index >= 0) { \ |
29 ASSERT_LT(action_index, client->num_actions_()) << scheduler_.get(); \ | 30 ASSERT_LT(action_index, client->num_actions_()) << scheduler_.get(); \ |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 bool automatic_swap_ack_; | 193 bool automatic_swap_ack_; |
193 int num_draws_; | 194 int num_draws_; |
194 BeginFrameArgs last_begin_main_frame_args_; | 195 BeginFrameArgs last_begin_main_frame_args_; |
195 base::TimeTicks posted_begin_impl_frame_deadline_; | 196 base::TimeTicks posted_begin_impl_frame_deadline_; |
196 std::vector<const char*> actions_; | 197 std::vector<const char*> actions_; |
197 std::vector<std::unique_ptr<base::trace_event::ConvertableToTraceFormat>> | 198 std::vector<std::unique_ptr<base::trace_event::ConvertableToTraceFormat>> |
198 states_; | 199 states_; |
199 TestScheduler* scheduler_; | 200 TestScheduler* scheduler_; |
200 }; | 201 }; |
201 | 202 |
202 class FakeExternalBeginFrameSource : public BeginFrameSourceBase { | 203 class BeginSourceToSchedulerClientProxy |
enne (OOO)
2016/06/15 19:46:56
class BeginSourceToSchedulerClientProxy : public F
danakj
2016/06/15 20:35:56
OK I made FakeSchedulerClient also be a FakeExtern
| |
204 : public FakeExternalBeginFrameSource::Client { | |
203 public: | 205 public: |
204 explicit FakeExternalBeginFrameSource(FakeSchedulerClient* client) | 206 explicit BeginSourceToSchedulerClientProxy(FakeSchedulerClient* client) |
205 : client_(client) {} | 207 : client_(client) {} |
206 ~FakeExternalBeginFrameSource() override {} | |
207 | 208 |
208 void AddObserver(BeginFrameObserver* obs) override { | 209 // FakeExternalBeginFrameSource::Client implementation. |
210 void OnAddObserver(BeginFrameObserver* obs) override { | |
209 client_->PushAction("AddObserver(this)"); | 211 client_->PushAction("AddObserver(this)"); |
210 BeginFrameSourceBase::AddObserver(obs); | 212 } |
213 void OnRemoveObserver(BeginFrameObserver* obs) override { | |
214 client_->PushAction("RemoveObserver(this)"); | |
211 } | 215 } |
212 | 216 |
213 void RemoveObserver(BeginFrameObserver* obs) override { | |
214 client_->PushAction("RemoveObserver(this)"); | |
215 BeginFrameSourceBase::RemoveObserver(obs); | |
216 } | |
217 | |
218 // TODO(sunnyps): Use using CallOnBeginFrame, SetBeginFrameSourcePaused. | |
219 void TestOnBeginFrame(const BeginFrameArgs& args) { | |
220 return CallOnBeginFrame(args); | |
221 } | |
222 | |
223 void SetPaused(bool paused) { SetBeginFrameSourcePaused(paused); } | |
224 | |
225 private: | 217 private: |
226 FakeSchedulerClient* client_; | 218 FakeSchedulerClient* const client_; |
227 }; | 219 }; |
228 | 220 |
229 class SchedulerTest : public testing::Test { | 221 class SchedulerTest : public testing::Test { |
230 public: | 222 public: |
231 SchedulerTest() | 223 SchedulerTest() |
232 : now_src_(new base::SimpleTestTickClock()), | 224 : now_src_(new base::SimpleTestTickClock()), |
233 task_runner_(new OrderedSimpleTaskRunner(now_src_.get(), true)), | 225 task_runner_(new OrderedSimpleTaskRunner(now_src_.get(), true)), |
234 fake_external_begin_frame_source_(nullptr) { | 226 fake_external_begin_frame_source_(nullptr) { |
235 now_src_->Advance(base::TimeDelta::FromMicroseconds(10000)); | 227 now_src_->Advance(base::TimeDelta::FromMicroseconds(10000)); |
236 // A bunch of tests require NowTicks() | 228 // A bunch of tests require NowTicks() |
237 // to be > BeginFrameArgs::DefaultInterval() | 229 // to be > BeginFrameArgs::DefaultInterval() |
238 now_src_->Advance(base::TimeDelta::FromMilliseconds(100)); | 230 now_src_->Advance(base::TimeDelta::FromMilliseconds(100)); |
239 // Fail if we need to run 100 tasks in a row. | 231 // Fail if we need to run 100 tasks in a row. |
240 task_runner_->SetRunTaskLimit(100); | 232 task_runner_->SetRunTaskLimit(100); |
241 } | 233 } |
242 | 234 |
243 ~SchedulerTest() override {} | 235 ~SchedulerTest() override {} |
244 | 236 |
245 protected: | 237 protected: |
246 TestScheduler* CreateScheduler() { | 238 TestScheduler* CreateScheduler() { |
247 BeginFrameSource* frame_source; | 239 BeginFrameSource* frame_source; |
248 unthrottled_frame_source_.reset( | 240 unthrottled_frame_source_.reset(new BackToBackBeginFrameSource( |
249 new TestBackToBackBeginFrameSource(now_src_.get(), task_runner_.get())); | 241 base::MakeUnique<TestDelayBasedTimeSource>(now_src_.get(), |
242 task_runner_.get()))); | |
250 fake_external_begin_frame_source_.reset( | 243 fake_external_begin_frame_source_.reset( |
251 new FakeExternalBeginFrameSource(client_.get())); | 244 new FakeExternalBeginFrameSource(0.f, false)); |
252 synthetic_frame_source_.reset(new TestSyntheticBeginFrameSource( | 245 fake_external_begin_frame_source_->SetClient(client_proxy_.get()); |
253 now_src_.get(), task_runner_.get(), BeginFrameArgs::DefaultInterval())); | 246 synthetic_frame_source_.reset(new DelayBasedBeginFrameSource( |
247 base::MakeUnique<TestDelayBasedTimeSource>(now_src_.get(), | |
248 task_runner_.get()))); | |
254 if (!scheduler_settings_.throttle_frame_production) { | 249 if (!scheduler_settings_.throttle_frame_production) { |
255 frame_source = unthrottled_frame_source_.get(); | 250 frame_source = unthrottled_frame_source_.get(); |
256 } else if (scheduler_settings_.use_external_begin_frame_source) { | 251 } else if (scheduler_settings_.use_external_begin_frame_source) { |
257 frame_source = fake_external_begin_frame_source_.get(); | 252 frame_source = fake_external_begin_frame_source_.get(); |
258 } else { | 253 } else { |
259 frame_source = synthetic_frame_source_.get(); | 254 frame_source = synthetic_frame_source_.get(); |
260 } | 255 } |
261 | 256 |
262 std::unique_ptr<FakeCompositorTimingHistory> | 257 std::unique_ptr<FakeCompositorTimingHistory> |
263 fake_compositor_timing_history = FakeCompositorTimingHistory::Create( | 258 fake_compositor_timing_history = FakeCompositorTimingHistory::Create( |
(...skipping 18 matching lines...) Expand all Loading... | |
282 EXPECT_SCOPED(InitializeOutputSurfaceAndFirstCommit()); | 277 EXPECT_SCOPED(InitializeOutputSurfaceAndFirstCommit()); |
283 } | 278 } |
284 | 279 |
285 void SetUpScheduler(bool initSurface) { | 280 void SetUpScheduler(bool initSurface) { |
286 SetUpScheduler(base::WrapUnique(new FakeSchedulerClient), initSurface); | 281 SetUpScheduler(base::WrapUnique(new FakeSchedulerClient), initSurface); |
287 } | 282 } |
288 | 283 |
289 void SetUpScheduler(std::unique_ptr<FakeSchedulerClient> client, | 284 void SetUpScheduler(std::unique_ptr<FakeSchedulerClient> client, |
290 bool initSurface) { | 285 bool initSurface) { |
291 client_ = std::move(client); | 286 client_ = std::move(client); |
287 client_proxy_.reset(new BeginSourceToSchedulerClientProxy(client_.get())); | |
292 if (initSurface) | 288 if (initSurface) |
293 CreateSchedulerAndInitSurface(); | 289 CreateSchedulerAndInitSurface(); |
294 else | 290 else |
295 CreateScheduler(); | 291 CreateScheduler(); |
296 } | 292 } |
297 | 293 |
298 OrderedSimpleTaskRunner& task_runner() { return *task_runner_; } | 294 OrderedSimpleTaskRunner& task_runner() { return *task_runner_; } |
299 base::SimpleTestTickClock* now_src() { return now_src_.get(); } | 295 base::SimpleTestTickClock* now_src() { return now_src_.get(); } |
300 | 296 |
301 // As this function contains EXPECT macros, to allow debugging it should be | 297 // As this function contains EXPECT macros, to allow debugging it should be |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
422 bool use_external_begin_frame_source, | 418 bool use_external_begin_frame_source, |
423 bool throttle_frame_production); | 419 bool throttle_frame_production); |
424 bool BeginMainFrameOnCriticalPath(TreePriority tree_priority, | 420 bool BeginMainFrameOnCriticalPath(TreePriority tree_priority, |
425 ScrollHandlerState scroll_handler_state, | 421 ScrollHandlerState scroll_handler_state, |
426 base::TimeDelta durations); | 422 base::TimeDelta durations); |
427 | 423 |
428 std::unique_ptr<base::SimpleTestTickClock> now_src_; | 424 std::unique_ptr<base::SimpleTestTickClock> now_src_; |
429 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; | 425 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; |
430 std::unique_ptr<FakeExternalBeginFrameSource> | 426 std::unique_ptr<FakeExternalBeginFrameSource> |
431 fake_external_begin_frame_source_; | 427 fake_external_begin_frame_source_; |
432 std::unique_ptr<TestSyntheticBeginFrameSource> synthetic_frame_source_; | 428 std::unique_ptr<SyntheticBeginFrameSource> synthetic_frame_source_; |
433 std::unique_ptr<TestBackToBackBeginFrameSource> unthrottled_frame_source_; | 429 std::unique_ptr<SyntheticBeginFrameSource> unthrottled_frame_source_; |
434 SchedulerSettings scheduler_settings_; | 430 SchedulerSettings scheduler_settings_; |
431 std::unique_ptr<BeginSourceToSchedulerClientProxy> client_proxy_; | |
435 std::unique_ptr<FakeSchedulerClient> client_; | 432 std::unique_ptr<FakeSchedulerClient> client_; |
436 std::unique_ptr<TestScheduler> scheduler_; | 433 std::unique_ptr<TestScheduler> scheduler_; |
437 FakeCompositorTimingHistory* fake_compositor_timing_history_; | 434 FakeCompositorTimingHistory* fake_compositor_timing_history_; |
438 }; | 435 }; |
439 | 436 |
440 TEST_F(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { | 437 TEST_F(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { |
441 scheduler_settings_.use_external_begin_frame_source = true; | 438 scheduler_settings_.use_external_begin_frame_source = true; |
442 SetUpScheduler(false); | 439 SetUpScheduler(false); |
443 scheduler_->SetVisible(true); | 440 scheduler_->SetVisible(true); |
444 scheduler_->SetCanDraw(true); | 441 scheduler_->SetCanDraw(true); |
(...skipping 2317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2762 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 2759 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); |
2763 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2760 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
2764 EXPECT_FALSE(scheduler_->begin_frames_expected()); | 2761 EXPECT_FALSE(scheduler_->begin_frames_expected()); |
2765 | 2762 |
2766 // No more BeginRetroFrame because BeginRetroFrame queue is cleared. | 2763 // No more BeginRetroFrame because BeginRetroFrame queue is cleared. |
2767 client_->Reset(); | 2764 client_->Reset(); |
2768 task_runner().RunPendingTasks(); | 2765 task_runner().RunPendingTasks(); |
2769 EXPECT_NO_ACTION(client_); | 2766 EXPECT_NO_ACTION(client_); |
2770 } | 2767 } |
2771 | 2768 |
2772 TEST_F(SchedulerTest, DidLoseOutputSurfaceWithSyntheticBeginFrameSource) { | 2769 TEST_F(SchedulerTest, DidLoseOutputSurfaceWithDelayBasedBeginFrameSource) { |
2773 SetUpScheduler(true); | 2770 SetUpScheduler(true); |
2774 | 2771 |
2775 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. | 2772 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. |
2776 EXPECT_FALSE(scheduler_->begin_frames_expected()); | 2773 EXPECT_FALSE(scheduler_->begin_frames_expected()); |
2777 scheduler_->SetNeedsBeginMainFrame(); | 2774 scheduler_->SetNeedsBeginMainFrame(); |
2778 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2775 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
2779 | 2776 |
2780 client_->Reset(); | 2777 client_->Reset(); |
2781 AdvanceFrame(); | 2778 AdvanceFrame(); |
2782 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2779 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
(...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3695 } | 3692 } |
3696 | 3693 |
3697 TEST_F(SchedulerTest, BeginMainFrameOnCriticalPath_AHS) { | 3694 TEST_F(SchedulerTest, BeginMainFrameOnCriticalPath_AHS) { |
3698 EXPECT_FALSE(BeginMainFrameOnCriticalPath( | 3695 EXPECT_FALSE(BeginMainFrameOnCriticalPath( |
3699 SMOOTHNESS_TAKES_PRIORITY, | 3696 SMOOTHNESS_TAKES_PRIORITY, |
3700 ScrollHandlerState::SCROLL_AFFECTS_SCROLL_HANDLER, kSlowDuration)); | 3697 ScrollHandlerState::SCROLL_AFFECTS_SCROLL_HANDLER, kSlowDuration)); |
3701 } | 3698 } |
3702 | 3699 |
3703 } // namespace | 3700 } // namespace |
3704 } // namespace cc | 3701 } // namespace cc |
OLD | NEW |