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 #ifndef CC_TEST_SCHEDULER_TEST_COMMON_H_ | 5 #ifndef CC_TEST_SCHEDULER_TEST_COMMON_H_ |
6 #define CC_TEST_SCHEDULER_TEST_COMMON_H_ | 6 #define CC_TEST_SCHEDULER_TEST_COMMON_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "cc/scheduler/delay_based_time_source.h" | 13 #include "cc/scheduler/delay_based_time_source.h" |
14 #include "cc/scheduler/scheduler.h" | 14 #include "cc/scheduler/scheduler.h" |
15 #include "cc/test/ordered_simple_task_runner.h" | 15 #include "cc/test/ordered_simple_task_runner.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 | 17 |
18 namespace cc { | 18 namespace cc { |
19 | 19 |
20 class FakeTimeSourceClient : public TimeSourceClient { | 20 class FakeTimeSourceClient : public TimeSourceClient { |
21 public: | 21 public: |
22 FakeTimeSourceClient() { Reset(); } | 22 FakeTimeSourceClient() { Reset(); } |
23 void Reset() { tick_called_ = false; } | 23 void Reset() { tick_called_ = false; } |
24 bool TickCalled() const { return tick_called_; } | 24 bool TickCalled() const { return tick_called_; } |
25 | 25 |
26 // TimeSourceClient implementation. | 26 // TimeSourceClient implementation. |
27 virtual void OnTimerTick() OVERRIDE; | 27 virtual void OnTimerTick() OVERRIDE; |
28 | 28 |
29 protected: | 29 protected: |
30 bool tick_called_; | 30 bool tick_called_ = false; |
Sami
2014/09/18 13:55:09
I think this is a C++11-ism which we don't allow y
mithro-old
2014/09/19 02:45:39
As Chrome style doesn't seem to used this, I've re
Sami
2014/09/19 13:44:22
Interesting, I didn't know that.
mithro-old
2014/09/23 12:43:54
It has the nice feature that if you forget to init
| |
31 }; | 31 }; |
32 | 32 |
33 class FakeDelayBasedTimeSource : public DelayBasedTimeSource { | 33 class FakeDelayBasedTimeSource : public DelayBasedTimeSource { |
34 public: | 34 public: |
35 static scoped_refptr<FakeDelayBasedTimeSource> Create( | 35 static scoped_refptr<FakeDelayBasedTimeSource> Create( |
36 base::TimeDelta interval, base::SingleThreadTaskRunner* task_runner) { | 36 base::TimeDelta interval, base::SingleThreadTaskRunner* task_runner) { |
37 return make_scoped_refptr(new FakeDelayBasedTimeSource(interval, | 37 return make_scoped_refptr(new FakeDelayBasedTimeSource(interval, |
38 task_runner)); | 38 task_runner)); |
39 } | 39 } |
40 | 40 |
(...skipping 25 matching lines...) Expand all Loading... | |
66 OrderedSimpleTaskRunner* task_runner); | 66 OrderedSimpleTaskRunner* task_runner); |
67 | 67 |
68 // Overridden from DelayBasedTimeSource | 68 // Overridden from DelayBasedTimeSource |
69 virtual ~TestDelayBasedTimeSource(); | 69 virtual ~TestDelayBasedTimeSource(); |
70 virtual base::TimeTicks Now() const OVERRIDE; | 70 virtual base::TimeTicks Now() const OVERRIDE; |
71 virtual std::string TypeString() const OVERRIDE; | 71 virtual std::string TypeString() const OVERRIDE; |
72 | 72 |
73 scoped_refptr<TestNowSource> now_src_; | 73 scoped_refptr<TestNowSource> now_src_; |
74 }; | 74 }; |
75 | 75 |
76 struct FakeBeginFrameSource : public BeginFrameSource { | |
77 bool needs_begin_frames_ = false; | |
Sami
2014/09/18 13:55:09
Ditto.
mithro-old
2014/09/19 02:45:39
Done.
| |
78 bool remaining_frames_ = false; | |
79 | |
80 BeginFrameObserver* GetObserver() { return observer_; } | |
81 | |
82 void TestSendBeginFrame(const BeginFrameArgs& args) { | |
brianderson
2014/09/18 21:54:19
TestOnBeginFrame.
mithro-old
2014/09/19 02:45:39
Done.
| |
83 CallOnBeginFrame(args); | |
84 } | |
85 | |
86 // BeginFrameSource | |
87 virtual bool NeedsBeginFrames() const OVERRIDE; | |
88 virtual void SetNeedsBeginFrames(bool needs_begin_frames) OVERRIDE; | |
89 virtual void DidFinishFrame(size_t remaining_frames) OVERRIDE; | |
90 | |
91 virtual void AsValueInto(base::debug::TracedValue* dict) const OVERRIDE; | |
92 | |
93 virtual ~FakeBeginFrameSource() {} | |
94 }; | |
95 | |
96 class TestBackToBackBeginFrameSource : public BackToBackBeginFrameSource { | |
97 public: | |
98 virtual ~TestBackToBackBeginFrameSource(); | |
99 | |
100 static scoped_ptr<TestBackToBackBeginFrameSource> Create( | |
101 scoped_refptr<TestNowSource> now_src, | |
102 base::SingleThreadTaskRunner* task_runner) { | |
103 return make_scoped_ptr( | |
104 new TestBackToBackBeginFrameSource(now_src, task_runner)); | |
105 } | |
106 | |
107 protected: | |
108 TestBackToBackBeginFrameSource(scoped_refptr<TestNowSource> now_src, | |
109 base::SingleThreadTaskRunner* task_runner); | |
110 | |
111 virtual base::TimeTicks Now() OVERRIDE; | |
112 | |
113 scoped_refptr<TestNowSource> now_src_; | |
114 }; | |
115 | |
116 class TestSyntheticBeginFrameSource : public SyntheticBeginFrameSource { | |
117 public: | |
118 virtual ~TestSyntheticBeginFrameSource(); | |
119 | |
120 static scoped_ptr<TestSyntheticBeginFrameSource> Create( | |
121 scoped_refptr<TestNowSource> now_src, | |
122 OrderedSimpleTaskRunner* task_runner, | |
123 base::TimeDelta initial_interval) { | |
124 base::TimeTicks initial_timebase = now_src->Now(); | |
125 return make_scoped_ptr(new TestSyntheticBeginFrameSource( | |
126 TestDelayBasedTimeSource::Create( | |
127 now_src, initial_interval, task_runner), | |
128 initial_timebase, | |
129 initial_interval)); | |
130 } | |
131 | |
132 protected: | |
133 TestSyntheticBeginFrameSource(scoped_refptr<DelayBasedTimeSource> time_source, | |
134 base::TimeTicks initial_timebase, | |
135 base::TimeDelta initial_interval); | |
136 }; | |
137 | |
76 class TestScheduler : public Scheduler { | 138 class TestScheduler : public Scheduler { |
77 public: | 139 public: |
78 static scoped_ptr<TestScheduler> Create( | 140 static scoped_ptr<TestScheduler> Create( |
79 scoped_refptr<TestNowSource> now_src, | 141 scoped_refptr<TestNowSource> now_src, |
80 SchedulerClient* client, | 142 SchedulerClient* client, |
81 const SchedulerSettings& scheduler_settings, | 143 const SchedulerSettings& scheduler_settings, |
82 int layer_tree_host_id) { | 144 int layer_tree_host_id) { |
83 // A bunch of tests require Now() to be > BeginFrameArgs::DefaultInterval() | 145 // A bunch of tests require Now() to be > BeginFrameArgs::DefaultInterval() |
84 now_src->AdvanceNow(base::TimeDelta::FromMilliseconds(100)); | 146 now_src->AdvanceNow(base::TimeDelta::FromMilliseconds(100)); |
85 | 147 |
86 scoped_refptr<OrderedSimpleTaskRunner> test_task_runner = | 148 scoped_refptr<OrderedSimpleTaskRunner> test_task_runner = |
87 new OrderedSimpleTaskRunner(now_src, true); | 149 new OrderedSimpleTaskRunner(now_src, true); |
88 return make_scoped_ptr(new TestScheduler(now_src, | 150 scoped_ptr<TestScheduler> scheduler = |
89 client, | 151 make_scoped_ptr(new TestScheduler(now_src, |
90 scheduler_settings, | 152 client, |
91 layer_tree_host_id, | 153 scheduler_settings, |
92 test_task_runner)); | 154 layer_tree_host_id, |
155 test_task_runner)); | |
156 scheduler->FinalizeSetup(); | |
157 return scheduler.Pass(); | |
93 } | 158 } |
94 | 159 |
95 // Extra test helper functionality | 160 // Extra test helper functionality |
96 bool IsBeginRetroFrameArgsEmpty() const { | 161 bool IsBeginRetroFrameArgsEmpty() const { |
97 return begin_retro_frame_args_.empty(); | 162 return begin_retro_frame_args_.empty(); |
98 } | 163 } |
99 | 164 |
100 bool IsSyntheticBeginFrameSourceActive() const { | 165 BeginFrameSource& frame_source() { return *frame_source_; } |
101 return synthetic_begin_frame_source_->IsActive(); | |
102 } | |
103 | |
104 OrderedSimpleTaskRunner& task_runner() { return *test_task_runner_; } | 166 OrderedSimpleTaskRunner& task_runner() { return *test_task_runner_; } |
105 | 167 |
106 virtual ~TestScheduler(); | 168 virtual ~TestScheduler(); |
107 | 169 |
108 protected: | 170 protected: |
109 // Overridden from Scheduler. | 171 // Overridden from Scheduler. |
110 virtual base::TimeTicks Now() const OVERRIDE; | 172 virtual base::TimeTicks Now() const OVERRIDE; |
173 virtual BeginFrameSource* GetPrimaryBeginFrameSource() OVERRIDE; | |
174 virtual BeginFrameSource* GetBackgroundBeginFrameSource() OVERRIDE; | |
111 | 175 |
112 private: | 176 private: |
113 TestScheduler(scoped_refptr<TestNowSource> now_src, | 177 TestScheduler(scoped_refptr<TestNowSource> now_src, |
114 SchedulerClient* client, | 178 SchedulerClient* client, |
115 const SchedulerSettings& scheduler_settings, | 179 const SchedulerSettings& scheduler_settings, |
116 int layer_tree_host_id, | 180 int layer_tree_host_id, |
117 const scoped_refptr<OrderedSimpleTaskRunner>& test_task_runner); | 181 const scoped_refptr<OrderedSimpleTaskRunner>& test_task_runner); |
118 | 182 |
119 scoped_refptr<TestNowSource> now_src_; | 183 scoped_refptr<TestNowSource> now_src_; |
120 OrderedSimpleTaskRunner* test_task_runner_; | 184 OrderedSimpleTaskRunner* test_task_runner_; |
121 }; | 185 }; |
122 | 186 |
123 } // namespace cc | 187 } // namespace cc |
124 | 188 |
125 #endif // CC_TEST_SCHEDULER_TEST_COMMON_H_ | 189 #endif // CC_TEST_SCHEDULER_TEST_COMMON_H_ |
OLD | NEW |