| 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() : tick_called_(false) {} | 22 FakeTimeSourceClient() : tick_called_(false) {} |
| 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 void OnTimerTick() override; |
| 28 | 28 |
| 29 protected: | 29 protected: |
| 30 bool tick_called_; | 30 bool tick_called_; |
| 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 |
| 41 void SetNow(base::TimeTicks time) { now_ = time; } | 41 void SetNow(base::TimeTicks time) { now_ = time; } |
| 42 virtual base::TimeTicks Now() const override; | 42 base::TimeTicks Now() const override; |
| 43 | 43 |
| 44 protected: | 44 protected: |
| 45 FakeDelayBasedTimeSource(base::TimeDelta interval, | 45 FakeDelayBasedTimeSource(base::TimeDelta interval, |
| 46 base::SingleThreadTaskRunner* task_runner) | 46 base::SingleThreadTaskRunner* task_runner) |
| 47 : DelayBasedTimeSource(interval, task_runner) {} | 47 : DelayBasedTimeSource(interval, task_runner) {} |
| 48 virtual ~FakeDelayBasedTimeSource() {} | 48 ~FakeDelayBasedTimeSource() override {} |
| 49 | 49 |
| 50 base::TimeTicks now_; | 50 base::TimeTicks now_; |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 class TestDelayBasedTimeSource : public DelayBasedTimeSource { | 53 class TestDelayBasedTimeSource : public DelayBasedTimeSource { |
| 54 public: | 54 public: |
| 55 static scoped_refptr<TestDelayBasedTimeSource> Create( | 55 static scoped_refptr<TestDelayBasedTimeSource> Create( |
| 56 scoped_refptr<TestNowSource> now_src, | 56 scoped_refptr<TestNowSource> now_src, |
| 57 base::TimeDelta interval, | 57 base::TimeDelta interval, |
| 58 OrderedSimpleTaskRunner* task_runner) { | 58 OrderedSimpleTaskRunner* task_runner) { |
| 59 return make_scoped_refptr( | 59 return make_scoped_refptr( |
| 60 new TestDelayBasedTimeSource(now_src, interval, task_runner)); | 60 new TestDelayBasedTimeSource(now_src, interval, task_runner)); |
| 61 } | 61 } |
| 62 | 62 |
| 63 protected: | 63 protected: |
| 64 TestDelayBasedTimeSource(scoped_refptr<TestNowSource> now_src, | 64 TestDelayBasedTimeSource(scoped_refptr<TestNowSource> now_src, |
| 65 base::TimeDelta interval, | 65 base::TimeDelta interval, |
| 66 OrderedSimpleTaskRunner* task_runner); | 66 OrderedSimpleTaskRunner* task_runner); |
| 67 | 67 |
| 68 // Overridden from DelayBasedTimeSource | 68 // Overridden from DelayBasedTimeSource |
| 69 virtual ~TestDelayBasedTimeSource(); | 69 ~TestDelayBasedTimeSource() override; |
| 70 virtual base::TimeTicks Now() const override; | 70 base::TimeTicks Now() const override; |
| 71 virtual std::string TypeString() const override; | 71 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 BeginFrameSourceMixIn { | 76 struct FakeBeginFrameSource : public BeginFrameSourceMixIn { |
| 77 bool remaining_frames_ = false; | 77 bool remaining_frames_ = false; |
| 78 | 78 |
| 79 BeginFrameObserver* GetObserver() { return observer_; } | 79 BeginFrameObserver* GetObserver() { return observer_; } |
| 80 | 80 |
| 81 BeginFrameArgs TestLastUsedBeginFrameArgs() { | 81 BeginFrameArgs TestLastUsedBeginFrameArgs() { |
| 82 if (observer_) { | 82 if (observer_) { |
| 83 return observer_->LastUsedBeginFrameArgs(); | 83 return observer_->LastUsedBeginFrameArgs(); |
| 84 } | 84 } |
| 85 return BeginFrameArgs(); | 85 return BeginFrameArgs(); |
| 86 } | 86 } |
| 87 void TestOnBeginFrame(const BeginFrameArgs& args) { | 87 void TestOnBeginFrame(const BeginFrameArgs& args) { |
| 88 return CallOnBeginFrame(args); | 88 return CallOnBeginFrame(args); |
| 89 } | 89 } |
| 90 | 90 |
| 91 // BeginFrameSource | 91 // BeginFrameSource |
| 92 virtual void DidFinishFrame(size_t remaining_frames) override; | 92 void DidFinishFrame(size_t remaining_frames) override; |
| 93 virtual void AsValueInto(base::debug::TracedValue* dict) const override; | 93 void AsValueInto(base::debug::TracedValue* dict) const override; |
| 94 | 94 |
| 95 virtual ~FakeBeginFrameSource() {} | 95 ~FakeBeginFrameSource() override {} |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 class TestBackToBackBeginFrameSource : public BackToBackBeginFrameSource { | 98 class TestBackToBackBeginFrameSource : public BackToBackBeginFrameSource { |
| 99 public: | 99 public: |
| 100 virtual ~TestBackToBackBeginFrameSource(); | 100 ~TestBackToBackBeginFrameSource() override; |
| 101 | 101 |
| 102 static scoped_ptr<TestBackToBackBeginFrameSource> Create( | 102 static scoped_ptr<TestBackToBackBeginFrameSource> Create( |
| 103 scoped_refptr<TestNowSource> now_src, | 103 scoped_refptr<TestNowSource> now_src, |
| 104 base::SingleThreadTaskRunner* task_runner) { | 104 base::SingleThreadTaskRunner* task_runner) { |
| 105 return make_scoped_ptr( | 105 return make_scoped_ptr( |
| 106 new TestBackToBackBeginFrameSource(now_src, task_runner)); | 106 new TestBackToBackBeginFrameSource(now_src, task_runner)); |
| 107 } | 107 } |
| 108 | 108 |
| 109 protected: | 109 protected: |
| 110 TestBackToBackBeginFrameSource(scoped_refptr<TestNowSource> now_src, | 110 TestBackToBackBeginFrameSource(scoped_refptr<TestNowSource> now_src, |
| 111 base::SingleThreadTaskRunner* task_runner); | 111 base::SingleThreadTaskRunner* task_runner); |
| 112 | 112 |
| 113 virtual base::TimeTicks Now() override; | 113 base::TimeTicks Now() override; |
| 114 | 114 |
| 115 scoped_refptr<TestNowSource> now_src_; | 115 scoped_refptr<TestNowSource> now_src_; |
| 116 }; | 116 }; |
| 117 | 117 |
| 118 class TestSyntheticBeginFrameSource : public SyntheticBeginFrameSource { | 118 class TestSyntheticBeginFrameSource : public SyntheticBeginFrameSource { |
| 119 public: | 119 public: |
| 120 virtual ~TestSyntheticBeginFrameSource(); | 120 ~TestSyntheticBeginFrameSource() override; |
| 121 | 121 |
| 122 static scoped_ptr<TestSyntheticBeginFrameSource> Create( | 122 static scoped_ptr<TestSyntheticBeginFrameSource> Create( |
| 123 scoped_refptr<TestNowSource> now_src, | 123 scoped_refptr<TestNowSource> now_src, |
| 124 OrderedSimpleTaskRunner* task_runner, | 124 OrderedSimpleTaskRunner* task_runner, |
| 125 base::TimeDelta initial_interval) { | 125 base::TimeDelta initial_interval) { |
| 126 return make_scoped_ptr( | 126 return make_scoped_ptr( |
| 127 new TestSyntheticBeginFrameSource(TestDelayBasedTimeSource::Create( | 127 new TestSyntheticBeginFrameSource(TestDelayBasedTimeSource::Create( |
| 128 now_src, initial_interval, task_runner))); | 128 now_src, initial_interval, task_runner))); |
| 129 } | 129 } |
| 130 | 130 |
| 131 protected: | 131 protected: |
| 132 TestSyntheticBeginFrameSource( | 132 TestSyntheticBeginFrameSource( |
| 133 scoped_refptr<DelayBasedTimeSource> time_source); | 133 scoped_refptr<DelayBasedTimeSource> time_source); |
| 134 }; | 134 }; |
| 135 | 135 |
| 136 class TestScheduler; | 136 class TestScheduler; |
| 137 class TestSchedulerFrameSourcesConstructor | 137 class TestSchedulerFrameSourcesConstructor |
| 138 : public SchedulerFrameSourcesConstructor { | 138 : public SchedulerFrameSourcesConstructor { |
| 139 public: | 139 public: |
| 140 virtual ~TestSchedulerFrameSourcesConstructor(); | 140 ~TestSchedulerFrameSourcesConstructor() override; |
| 141 | 141 |
| 142 protected: | 142 protected: |
| 143 virtual BeginFrameSource* ConstructPrimaryFrameSource( | 143 BeginFrameSource* ConstructPrimaryFrameSource(Scheduler* scheduler) override; |
| 144 Scheduler* scheduler) override; | 144 BeginFrameSource* ConstructBackgroundFrameSource( |
| 145 virtual BeginFrameSource* ConstructBackgroundFrameSource( | |
| 146 Scheduler* scheduler) override; | 145 Scheduler* scheduler) override; |
| 147 | 146 |
| 148 OrderedSimpleTaskRunner* test_task_runner_; | 147 OrderedSimpleTaskRunner* test_task_runner_; |
| 149 TestNowSource* now_src_; | 148 TestNowSource* now_src_; |
| 150 | 149 |
| 151 protected: | 150 protected: |
| 152 explicit TestSchedulerFrameSourcesConstructor( | 151 explicit TestSchedulerFrameSourcesConstructor( |
| 153 OrderedSimpleTaskRunner* test_task_runner, | 152 OrderedSimpleTaskRunner* test_task_runner, |
| 154 TestNowSource* now_src); | 153 TestNowSource* now_src); |
| 155 friend class TestScheduler; | 154 friend class TestScheduler; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 175 &frame_sources_constructor)); | 174 &frame_sources_constructor)); |
| 176 } | 175 } |
| 177 | 176 |
| 178 // Extra test helper functionality | 177 // Extra test helper functionality |
| 179 bool IsBeginRetroFrameArgsEmpty() const { | 178 bool IsBeginRetroFrameArgsEmpty() const { |
| 180 return begin_retro_frame_args_.empty(); | 179 return begin_retro_frame_args_.empty(); |
| 181 } | 180 } |
| 182 | 181 |
| 183 BeginFrameSource& frame_source() { return *frame_source_; } | 182 BeginFrameSource& frame_source() { return *frame_source_; } |
| 184 | 183 |
| 185 virtual ~TestScheduler(); | 184 ~TestScheduler() override; |
| 186 | 185 |
| 187 protected: | 186 protected: |
| 188 // Overridden from Scheduler. | 187 // Overridden from Scheduler. |
| 189 virtual base::TimeTicks Now() const override; | 188 base::TimeTicks Now() const override; |
| 190 | 189 |
| 191 private: | 190 private: |
| 192 TestScheduler( | 191 TestScheduler( |
| 193 scoped_refptr<TestNowSource> now_src, | 192 scoped_refptr<TestNowSource> now_src, |
| 194 SchedulerClient* client, | 193 SchedulerClient* client, |
| 195 const SchedulerSettings& scheduler_settings, | 194 const SchedulerSettings& scheduler_settings, |
| 196 int layer_tree_host_id, | 195 int layer_tree_host_id, |
| 197 const scoped_refptr<OrderedSimpleTaskRunner>& test_task_runner, | 196 const scoped_refptr<OrderedSimpleTaskRunner>& test_task_runner, |
| 198 base::PowerMonitor* power_monitor, | 197 base::PowerMonitor* power_monitor, |
| 199 TestSchedulerFrameSourcesConstructor* frame_sources_constructor); | 198 TestSchedulerFrameSourcesConstructor* frame_sources_constructor); |
| 200 | 199 |
| 201 scoped_refptr<TestNowSource> now_src_; | 200 scoped_refptr<TestNowSource> now_src_; |
| 202 }; | 201 }; |
| 203 | 202 |
| 204 } // namespace cc | 203 } // namespace cc |
| 205 | 204 |
| 206 #endif // CC_TEST_SCHEDULER_TEST_COMMON_H_ | 205 #endif // CC_TEST_SCHEDULER_TEST_COMMON_H_ |
| OLD | NEW |