Add Pylint for docs server.
[chromium-blink-merge.git] / cc / test / scheduler_test_common.cc
blob94bcf5f909df85d36dc6b0cf062acc382e475bcc
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"
7 #include <string>
9 #include "base/logging.h"
11 namespace cc {
13 void FakeTimeSourceClient::OnTimerTick() {
14 tick_called_ = true;
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(
41 base::trace_event::TracedValue* dict) const {
42 dict->SetString("type", "FakeBeginFrameSource");
43 BeginFrameSourceMixIn::AsValueInto(dict);
46 TestBackToBackBeginFrameSource::TestBackToBackBeginFrameSource(
47 scoped_refptr<TestNowSource> now_src,
48 base::SingleThreadTaskRunner* task_runner)
49 : BackToBackBeginFrameSource(task_runner), now_src_(now_src) {
52 TestBackToBackBeginFrameSource::~TestBackToBackBeginFrameSource() {
55 base::TimeTicks TestBackToBackBeginFrameSource::Now() {
56 return now_src_->Now();
59 TestSyntheticBeginFrameSource::TestSyntheticBeginFrameSource(
60 scoped_refptr<DelayBasedTimeSource> time_source)
61 : SyntheticBeginFrameSource(time_source) {
64 TestSyntheticBeginFrameSource::~TestSyntheticBeginFrameSource() {
67 TestSchedulerFrameSourcesConstructor::TestSchedulerFrameSourcesConstructor(
68 OrderedSimpleTaskRunner* test_task_runner,
69 TestNowSource* now_src)
70 : test_task_runner_(test_task_runner), now_src_(now_src) {
72 TestSchedulerFrameSourcesConstructor::~TestSchedulerFrameSourcesConstructor() {
75 BeginFrameSource*
76 TestSchedulerFrameSourcesConstructor::ConstructPrimaryFrameSource(
77 Scheduler* scheduler) {
78 if (scheduler->settings_.use_external_begin_frame_source) {
79 return SchedulerFrameSourcesConstructor::ConstructPrimaryFrameSource(
80 scheduler);
81 } else {
82 TRACE_EVENT1(
83 "cc",
84 "TestSchedulerFrameSourcesConstructor::ConstructPrimaryFrameSource",
85 "source",
86 "TestSyntheticBeginFrameSource");
87 scoped_ptr<TestSyntheticBeginFrameSource> synthetic_source =
88 TestSyntheticBeginFrameSource::Create(
89 now_src_, test_task_runner_, BeginFrameArgs::DefaultInterval());
91 DCHECK(!scheduler->vsync_observer_);
92 scheduler->vsync_observer_ = synthetic_source.get();
94 DCHECK(!scheduler->primary_frame_source_internal_);
95 scheduler->primary_frame_source_internal_ = synthetic_source.Pass();
96 return scheduler->primary_frame_source_internal_.get();
100 BeginFrameSource*
101 TestSchedulerFrameSourcesConstructor::ConstructBackgroundFrameSource(
102 Scheduler* scheduler) {
103 TRACE_EVENT1(
104 "cc",
105 "TestSchedulerFrameSourcesConstructor::ConstructBackgroundFrameSource",
106 "source",
107 "TestSyntheticBeginFrameSource");
108 DCHECK(!(scheduler->background_frame_source_internal_));
109 scheduler->background_frame_source_internal_ =
110 TestSyntheticBeginFrameSource::Create(
111 now_src_, test_task_runner_, base::TimeDelta::FromSeconds(1));
112 return scheduler->background_frame_source_internal_.get();
115 BeginFrameSource*
116 TestSchedulerFrameSourcesConstructor::ConstructUnthrottledFrameSource(
117 Scheduler* scheduler) {
118 TRACE_EVENT1(
119 "cc",
120 "TestSchedulerFrameSourcesConstructor::ConstructUnthrottledFrameSource",
121 "source", "TestBackToBackBeginFrameSource");
122 DCHECK(!scheduler->unthrottled_frame_source_internal_);
123 scheduler->unthrottled_frame_source_internal_ =
124 TestBackToBackBeginFrameSource::Create(now_src_, test_task_runner_);
125 return scheduler->unthrottled_frame_source_internal_.get();
128 TestScheduler::TestScheduler(
129 scoped_refptr<TestNowSource> now_src,
130 SchedulerClient* client,
131 const SchedulerSettings& scheduler_settings,
132 int layer_tree_host_id,
133 const scoped_refptr<OrderedSimpleTaskRunner>& test_task_runner,
134 base::PowerMonitor* power_monitor,
135 TestSchedulerFrameSourcesConstructor* frame_sources_constructor,
136 scoped_ptr<BeginFrameSource> external_begin_frame_source)
137 : Scheduler(client,
138 scheduler_settings,
139 layer_tree_host_id,
140 test_task_runner,
141 power_monitor,
142 external_begin_frame_source.Pass(),
143 frame_sources_constructor),
144 now_src_(now_src) {
147 base::TimeTicks TestScheduler::Now() const {
148 return now_src_->Now();
151 TestScheduler::~TestScheduler() {
154 } // namespace cc