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"
10 #include "cc/debug/rendering_stats_instrumentation.h"
14 void FakeTimeSourceClient::OnTimerTick() {
18 base::TimeTicks
FakeDelayBasedTimeSource::Now() const { return now_
; }
20 TestDelayBasedTimeSource::TestDelayBasedTimeSource(
21 base::SimpleTestTickClock
* now_src
,
22 base::TimeDelta interval
,
23 OrderedSimpleTaskRunner
* task_runner
)
24 : DelayBasedTimeSource(interval
, task_runner
), now_src_(now_src
) {
27 base::TimeTicks
TestDelayBasedTimeSource::Now() const {
28 return now_src_
->NowTicks();
31 std::string
TestDelayBasedTimeSource::TypeString() const {
32 return "TestDelayBasedTimeSource";
35 TestDelayBasedTimeSource::~TestDelayBasedTimeSource() {
38 void FakeBeginFrameSource::DidFinishFrame(size_t remaining_frames
) {
39 remaining_frames_
= remaining_frames
;
42 void FakeBeginFrameSource::AsValueInto(
43 base::trace_event::TracedValue
* dict
) const {
44 dict
->SetString("type", "FakeBeginFrameSource");
45 BeginFrameSourceBase::AsValueInto(dict
);
48 TestBackToBackBeginFrameSource::TestBackToBackBeginFrameSource(
49 base::SimpleTestTickClock
* now_src
,
50 base::SingleThreadTaskRunner
* task_runner
)
51 : BackToBackBeginFrameSource(task_runner
), now_src_(now_src
) {
54 TestBackToBackBeginFrameSource::~TestBackToBackBeginFrameSource() {
57 base::TimeTicks
TestBackToBackBeginFrameSource::Now() {
58 return now_src_
->NowTicks();
61 TestSyntheticBeginFrameSource::TestSyntheticBeginFrameSource(
62 scoped_ptr
<DelayBasedTimeSource
> time_source
)
63 : SyntheticBeginFrameSource(time_source
.Pass()) {
66 TestSyntheticBeginFrameSource::~TestSyntheticBeginFrameSource() {
69 scoped_ptr
<FakeCompositorTimingHistory
> FakeCompositorTimingHistory::Create() {
70 scoped_ptr
<RenderingStatsInstrumentation
> rendering_stats_instrumentation
=
71 RenderingStatsInstrumentation::Create();
72 return make_scoped_ptr(
73 new FakeCompositorTimingHistory(rendering_stats_instrumentation
.Pass()));
76 FakeCompositorTimingHistory::FakeCompositorTimingHistory(
77 scoped_ptr
<RenderingStatsInstrumentation
> rendering_stats_instrumentation
)
78 : CompositorTimingHistory(rendering_stats_instrumentation
.get()),
79 rendering_stats_instrumentation_owned_(
80 rendering_stats_instrumentation
.Pass()) {
83 FakeCompositorTimingHistory::~FakeCompositorTimingHistory() {
86 void FakeCompositorTimingHistory::SetDrawDurationEstimate(
87 base::TimeDelta duration
) {
88 draw_duration_
= duration
;
91 void FakeCompositorTimingHistory::SetBeginMainFrameToCommitDurationEstimate(
92 base::TimeDelta duration
) {
93 begin_main_frame_to_commit_duration_
= duration
;
96 void FakeCompositorTimingHistory::SetCommitToActivateDurationEstimate(
97 base::TimeDelta duration
) {
98 commit_to_activate_duration_
= duration
;
101 base::TimeDelta
FakeCompositorTimingHistory::DrawDurationEstimate() const {
102 return draw_duration_
;
106 FakeCompositorTimingHistory::BeginMainFrameToCommitDurationEstimate() const {
107 return begin_main_frame_to_commit_duration_
;
110 base::TimeDelta
FakeCompositorTimingHistory::CommitToActivateDurationEstimate()
112 return commit_to_activate_duration_
;
115 scoped_ptr
<TestScheduler
> TestScheduler::Create(
116 base::SimpleTestTickClock
* now_src
,
117 SchedulerClient
* client
,
118 const SchedulerSettings
& settings
,
119 int layer_tree_host_id
,
120 OrderedSimpleTaskRunner
* task_runner
,
121 BeginFrameSource
* external_frame_source
,
122 scoped_ptr
<CompositorTimingHistory
> compositor_timing_history
) {
123 scoped_ptr
<TestSyntheticBeginFrameSource
> synthetic_frame_source
;
124 if (!settings
.use_external_begin_frame_source
) {
125 synthetic_frame_source
= TestSyntheticBeginFrameSource::Create(
126 now_src
, task_runner
, BeginFrameArgs::DefaultInterval());
128 scoped_ptr
<TestBackToBackBeginFrameSource
> unthrottled_frame_source
=
129 TestBackToBackBeginFrameSource::Create(now_src
, task_runner
);
130 return make_scoped_ptr(new TestScheduler(
131 now_src
, client
, settings
, layer_tree_host_id
, task_runner
,
132 external_frame_source
, synthetic_frame_source
.Pass(),
133 unthrottled_frame_source
.Pass(), compositor_timing_history
.Pass()));
136 TestScheduler::TestScheduler(
137 base::SimpleTestTickClock
* now_src
,
138 SchedulerClient
* client
,
139 const SchedulerSettings
& scheduler_settings
,
140 int layer_tree_host_id
,
141 OrderedSimpleTaskRunner
* task_runner
,
142 BeginFrameSource
* external_frame_source
,
143 scoped_ptr
<TestSyntheticBeginFrameSource
> synthetic_frame_source
,
144 scoped_ptr
<TestBackToBackBeginFrameSource
> unthrottled_frame_source
,
145 scoped_ptr
<CompositorTimingHistory
> compositor_timing_history
)
150 external_frame_source
,
151 synthetic_frame_source
.Pass(),
152 unthrottled_frame_source
.Pass(),
153 compositor_timing_history
.Pass()),
157 base::TimeTicks
TestScheduler::Now() const {
158 return now_src_
->NowTicks();
161 TestScheduler::~TestScheduler() {