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" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after 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_; |
| 78 bool remaining_frames_; |
| 79 |
| 80 BeginFrameObserver* GetObserver() { return observer_; } |
| 81 |
| 82 void TestSendBeginFrame(const BeginFrameArgs& args) { SendBeginFrame(args); } |
| 83 |
| 84 // BeginFrameSource |
| 85 virtual bool NeedsBeginFrames() OVERRIDE; |
| 86 virtual void SetNeedsBeginFrames(bool needs_begin_frames) OVERRIDE; |
| 87 virtual void FinishedFrame(size_t remaining_frames) OVERRIDE; |
| 88 |
| 89 virtual void AsValueInto(base::debug::TracedValue* dict) const OVERRIDE; |
| 90 |
| 91 virtual ~FakeBeginFrameSource() {} |
| 92 }; |
| 93 |
| 94 class TestSyntheticBeginFrameSource : public SyntheticBeginFrameSource { |
| 95 public: |
| 96 static scoped_ptr<TestSyntheticBeginFrameSource> Create( |
| 97 scoped_refptr<TestNowSource> now_src, |
| 98 OrderedSimpleTaskRunner* task_runner, |
| 99 base::TimeDelta initial_interval) { |
| 100 base::TimeTicks initial_timebase = now_src->Now(); |
| 101 return make_scoped_ptr(new TestSyntheticBeginFrameSource( |
| 102 TestDelayBasedTimeSource::Create( |
| 103 now_src, initial_interval, task_runner), |
| 104 initial_timebase, |
| 105 initial_interval)); |
| 106 } |
| 107 |
| 108 protected: |
| 109 TestSyntheticBeginFrameSource(scoped_refptr<DelayBasedTimeSource> time_source, |
| 110 base::TimeTicks initial_timebase, |
| 111 base::TimeDelta initial_interval) |
| 112 : SyntheticBeginFrameSource(time_source, |
| 113 initial_timebase, |
| 114 initial_interval) {} |
| 115 }; |
| 116 |
76 class TestScheduler : public Scheduler { | 117 class TestScheduler : public Scheduler { |
77 public: | 118 public: |
78 static scoped_ptr<TestScheduler> Create( | 119 static scoped_ptr<TestScheduler> Create( |
79 scoped_refptr<TestNowSource> now_src, | 120 scoped_refptr<TestNowSource> now_src, |
80 SchedulerClient* client, | 121 SchedulerClient* client, |
81 const SchedulerSettings& scheduler_settings, | 122 const SchedulerSettings& scheduler_settings, |
82 int layer_tree_host_id) { | 123 int layer_tree_host_id) { |
83 // A bunch of tests require Now() to be > BeginFrameArgs::DefaultInterval() | 124 // A bunch of tests require Now() to be > BeginFrameArgs::DefaultInterval() |
84 now_src->AdvanceNow(base::TimeDelta::FromMilliseconds(100)); | 125 now_src->AdvanceNow(base::TimeDelta::FromMilliseconds(100)); |
85 | 126 |
86 scoped_refptr<OrderedSimpleTaskRunner> test_task_runner = | 127 scoped_refptr<OrderedSimpleTaskRunner> test_task_runner = |
87 new OrderedSimpleTaskRunner(now_src, true); | 128 new OrderedSimpleTaskRunner(now_src, true); |
88 return make_scoped_ptr(new TestScheduler(now_src, | 129 return make_scoped_ptr(new TestScheduler(now_src, |
89 client, | 130 client, |
90 scheduler_settings, | 131 scheduler_settings, |
91 layer_tree_host_id, | 132 layer_tree_host_id, |
92 test_task_runner)); | 133 test_task_runner)); |
93 } | 134 } |
94 | 135 |
95 // Extra test helper functionality | 136 // Extra test helper functionality |
96 bool IsBeginRetroFrameArgsEmpty() const { | 137 bool IsBeginRetroFrameArgsEmpty() const { |
97 return begin_retro_frame_args_.empty(); | 138 return begin_retro_frame_args_.empty(); |
98 } | 139 } |
99 | 140 |
100 bool IsSyntheticBeginFrameSourceActive() const { | 141 BeginFrameSource& frame_source() { return *frame_source_; } |
101 return synthetic_begin_frame_source_->IsActive(); | |
102 } | |
103 | |
104 OrderedSimpleTaskRunner& task_runner() { return *test_task_runner_; } | 142 OrderedSimpleTaskRunner& task_runner() { return *test_task_runner_; } |
105 | 143 |
106 virtual ~TestScheduler(); | 144 virtual ~TestScheduler(); |
107 | 145 |
108 protected: | 146 protected: |
109 // Overridden from Scheduler. | 147 // Overridden from Scheduler. |
| 148 virtual void SetUpBackgroundFrameSource() OVERRIDE; |
| 149 virtual void SetUpPrimaryFrameSource() OVERRIDE; |
110 virtual base::TimeTicks Now() const OVERRIDE; | 150 virtual base::TimeTicks Now() const OVERRIDE; |
111 | 151 |
112 private: | 152 private: |
113 TestScheduler(scoped_refptr<TestNowSource> now_src, | 153 TestScheduler(scoped_refptr<TestNowSource> now_src, |
114 SchedulerClient* client, | 154 SchedulerClient* client, |
115 const SchedulerSettings& scheduler_settings, | 155 const SchedulerSettings& scheduler_settings, |
116 int layer_tree_host_id, | 156 int layer_tree_host_id, |
117 const scoped_refptr<OrderedSimpleTaskRunner>& test_task_runner); | 157 const scoped_refptr<OrderedSimpleTaskRunner>& test_task_runner); |
118 | 158 |
119 scoped_refptr<TestNowSource> now_src_; | 159 scoped_refptr<TestNowSource> now_src_; |
120 OrderedSimpleTaskRunner* test_task_runner_; | 160 OrderedSimpleTaskRunner* test_task_runner_; |
121 }; | 161 }; |
122 | 162 |
123 } // namespace cc | 163 } // namespace cc |
124 | 164 |
125 #endif // CC_TEST_SCHEDULER_TEST_COMMON_H_ | 165 #endif // CC_TEST_SCHEDULER_TEST_COMMON_H_ |
OLD | NEW |