1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/test/scheduler_test_common.h"
9 #include "base/logging.h"
13 void FakeTimeSourceClient::OnTimerTick() {
17 base::TimeTicks
FakeDelayBasedTimeSource::Now() const { return now_
; }
19 TestDelayBasedTimeSource::TestDelayBasedTimeSource(
20 scoped_refptr
<TestNowSource
> now_src
,
21 base::TimeDelta interval
,
22 OrderedSimpleTaskRunner
* task_runner
)
23 : DelayBasedTimeSource(interval
, task_runner
), now_src_(now_src
) {
26 base::TimeTicks
TestDelayBasedTimeSource::Now() const {
27 return now_src_
->Now();
30 std::string
TestDelayBasedTimeSource::TypeString() const {
31 return "TestDelayBasedTimeSource";
34 TestDelayBasedTimeSource::~TestDelayBasedTimeSource() {
37 void FakeBeginFrameSource::DidFinishFrame(size_t remaining_frames
) {
38 remaining_frames_
= remaining_frames
;
40 void FakeBeginFrameSource::AsValueInto(base::debug::TracedValue
* dict
) const {
41 dict
->SetString("type", "FakeBeginFrameSource");
42 BeginFrameSourceMixIn::AsValueInto(dict
);
45 TestBackToBackBeginFrameSource::TestBackToBackBeginFrameSource(
46 scoped_refptr
<TestNowSource
> now_src
,
47 base::SingleThreadTaskRunner
* task_runner
)
48 : BackToBackBeginFrameSource(task_runner
), now_src_(now_src
) {
51 TestBackToBackBeginFrameSource::~TestBackToBackBeginFrameSource() {
54 base::TimeTicks
TestBackToBackBeginFrameSource::Now() {
55 return now_src_
->Now();
58 TestSyntheticBeginFrameSource::TestSyntheticBeginFrameSource(
59 scoped_refptr
<DelayBasedTimeSource
> time_source
)
60 : SyntheticBeginFrameSource(time_source
) {
63 TestSyntheticBeginFrameSource::~TestSyntheticBeginFrameSource() {
66 TestSchedulerFrameSourcesConstructor::TestSchedulerFrameSourcesConstructor(
67 OrderedSimpleTaskRunner
* test_task_runner
,
68 TestNowSource
* now_src
)
69 : test_task_runner_(test_task_runner
), now_src_(now_src
) {
71 TestSchedulerFrameSourcesConstructor::~TestSchedulerFrameSourcesConstructor() {
75 TestSchedulerFrameSourcesConstructor::ConstructPrimaryFrameSource(
76 Scheduler
* scheduler
) {
77 if (!scheduler
->settings_
.throttle_frame_production
) {
80 "TestSchedulerFrameSourcesConstructor::ConstructPrimaryFrameSource",
82 "TestBackToBackBeginFrameSource");
83 DCHECK(!scheduler
->primary_frame_source_internal_
);
84 scheduler
->primary_frame_source_internal_
=
85 TestBackToBackBeginFrameSource::Create(now_src_
, test_task_runner_
);
86 return scheduler
->primary_frame_source_internal_
.get();
87 } else if (scheduler
->settings_
.use_external_begin_frame_source
) {
88 return SchedulerFrameSourcesConstructor::ConstructPrimaryFrameSource(
93 "TestSchedulerFrameSourcesConstructor::ConstructPrimaryFrameSource",
95 "TestSyntheticBeginFrameSource");
96 scoped_ptr
<TestSyntheticBeginFrameSource
> synthetic_source
=
97 TestSyntheticBeginFrameSource::Create(
98 now_src_
, test_task_runner_
, BeginFrameArgs::DefaultInterval());
100 DCHECK(!scheduler
->vsync_observer_
);
101 scheduler
->vsync_observer_
= synthetic_source
.get();
103 DCHECK(!scheduler
->primary_frame_source_internal_
);
104 scheduler
->primary_frame_source_internal_
= synthetic_source
.Pass();
105 return scheduler
->primary_frame_source_internal_
.get();
110 TestSchedulerFrameSourcesConstructor::ConstructBackgroundFrameSource(
111 Scheduler
* scheduler
) {
114 "TestSchedulerFrameSourcesConstructor::ConstructBackgroundFrameSource",
116 "TestSyntheticBeginFrameSource");
117 DCHECK(!(scheduler
->background_frame_source_internal_
));
118 scheduler
->background_frame_source_internal_
=
119 TestSyntheticBeginFrameSource::Create(
120 now_src_
, test_task_runner_
, base::TimeDelta::FromSeconds(1));
121 return scheduler
->background_frame_source_internal_
.get();
124 TestScheduler::TestScheduler(
125 scoped_refptr
<TestNowSource
> now_src
,
126 SchedulerClient
* client
,
127 const SchedulerSettings
& scheduler_settings
,
128 int layer_tree_host_id
,
129 const scoped_refptr
<OrderedSimpleTaskRunner
>& test_task_runner
,
130 base::PowerMonitor
* power_monitor
,
131 TestSchedulerFrameSourcesConstructor
* frame_sources_constructor
,
132 scoped_ptr
<BeginFrameSource
> external_begin_frame_source
)
138 external_begin_frame_source
.Pass(),
139 frame_sources_constructor
),
143 base::TimeTicks
TestScheduler::Now() const {
144 return now_src_
->Now();
147 TestScheduler::~TestScheduler() {