OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_SCHEDULER_BEGIN_FRAME_SOURCE_H_ | 5 #ifndef CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_ |
6 #define CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_ | 6 #define CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 | 124 |
125 // Simple base class which implements a BeginFrameSource. | 125 // Simple base class which implements a BeginFrameSource. |
126 // Implementation classes should: | 126 // Implementation classes should: |
127 // - Implement the pure virtual (Set)NeedsBeginFrames methods from | 127 // - Implement the pure virtual (Set)NeedsBeginFrames methods from |
128 // BeginFrameSource. | 128 // BeginFrameSource. |
129 // - Use the CallOnBeginFrame method to call to the observer(s). | 129 // - Use the CallOnBeginFrame method to call to the observer(s). |
130 class CC_EXPORT BeginFrameSourceBase : public BeginFrameSource { | 130 class CC_EXPORT BeginFrameSourceBase : public BeginFrameSource { |
131 public: | 131 public: |
132 ~BeginFrameSourceBase() override; | 132 ~BeginFrameSourceBase() override; |
133 | 133 |
134 // BeginFrameSource | 134 // BeginFrameSource implementation. |
135 void DidFinishFrame(BeginFrameObserver* obs, | 135 void DidFinishFrame(BeginFrameObserver* obs, |
136 size_t remaining_frames) override {} | 136 size_t remaining_frames) override {} |
137 void AddObserver(BeginFrameObserver* obs) override; | 137 void AddObserver(BeginFrameObserver* obs) override; |
138 void RemoveObserver(BeginFrameObserver* obs) override; | 138 void RemoveObserver(BeginFrameObserver* obs) override; |
139 | 139 |
140 protected: | 140 protected: |
141 BeginFrameSourceBase(); | 141 BeginFrameSourceBase(); |
142 | 142 |
143 // These methods should be used by subclasses to make the call to the | 143 // These methods should be used by subclasses to make the call to the |
144 // observers. | 144 // observers. |
145 void CallOnBeginFrame(const BeginFrameArgs& args); | 145 void CallOnBeginFrame(const BeginFrameArgs& args); |
146 void SetBeginFrameSourcePaused(bool paused); | 146 void SetBeginFrameSourcePaused(bool paused); |
147 | 147 |
148 // This notifies that the subclass that it must turn on or off its mechnanism | 148 // This notifies the subclass that it must turn on or off its mechnanism |
149 // for producing BeginFrames. | 149 // for producing BeginFrames. |
150 virtual void OnNeedsBeginFramesChanged(bool needs_begin_frames) {} | 150 virtual void OnNeedsBeginFramesChanged(bool needs_begin_frames) {} |
151 | 151 |
152 bool needs_begin_frames() const { return !observers_.empty(); } | 152 bool needs_begin_frames() const { return !observers_.empty(); } |
153 | 153 |
154 std::set<BeginFrameObserver*> observers_; | 154 std::set<BeginFrameObserver*> observers_; |
155 bool paused_; | 155 bool paused_; |
156 | 156 |
157 private: | 157 private: |
158 DISALLOW_COPY_AND_ASSIGN(BeginFrameSourceBase); | 158 DISALLOW_COPY_AND_ASSIGN(BeginFrameSourceBase); |
159 }; | 159 }; |
160 | 160 |
161 // A frame source which calls BeginFrame (at the next possible time) as soon as | |
162 // remaining frames reaches zero. | |
163 class CC_EXPORT BackToBackBeginFrameSource : public BeginFrameSourceBase { | |
164 public: | |
165 explicit BackToBackBeginFrameSource( | |
166 base::SingleThreadTaskRunner* task_runner); | |
167 ~BackToBackBeginFrameSource() override; | |
168 | |
169 // BeginFrameSource | |
170 void AddObserver(BeginFrameObserver* obs) override; | |
171 void RemoveObserver(BeginFrameObserver* obs) override; | |
172 void DidFinishFrame(BeginFrameObserver* obs, | |
173 size_t remaining_frames) override; | |
174 | |
175 protected: | |
176 virtual base::TimeTicks Now(); // Now overridable for testing | |
177 | |
178 base::SingleThreadTaskRunner* task_runner_; | |
179 base::CancelableClosure begin_frame_task_; | |
180 std::set<BeginFrameObserver*> pending_begin_frame_observers_; | |
181 | |
182 void PostPendingBeginFramesTask(); | |
183 void SendPendingBeginFrames(); | |
184 | |
185 private: | |
186 base::WeakPtrFactory<BackToBackBeginFrameSource> weak_factory_; | |
187 | |
188 DISALLOW_COPY_AND_ASSIGN(BackToBackBeginFrameSource); | |
189 }; | |
190 | |
191 // A frame source which is locked to an external parameters provides from a | 161 // A frame source which is locked to an external parameters provides from a |
192 // vsync source and generates BeginFrameArgs for it. | 162 // vsync source and generates BeginFrameArgs for it. |
193 class CC_EXPORT SyntheticBeginFrameSource : public BeginFrameSourceBase, | 163 class CC_EXPORT SyntheticBeginFrameSource : public BeginFrameSourceBase, |
194 public DelayBasedTimeSourceClient { | 164 public DelayBasedTimeSourceClient { |
195 public: | 165 public: |
196 explicit SyntheticBeginFrameSource(base::SingleThreadTaskRunner* task_runner, | |
197 base::TimeDelta initial_vsync_interval); | |
198 explicit SyntheticBeginFrameSource( | 166 explicit SyntheticBeginFrameSource( |
199 std::unique_ptr<DelayBasedTimeSource> time_source); | 167 std::unique_ptr<DelayBasedTimeSource> time_source); |
200 ~SyntheticBeginFrameSource() override; | 168 ~SyntheticBeginFrameSource() override; |
201 | 169 |
202 void OnUpdateVSyncParameters(base::TimeTicks timebase, | 170 void OnUpdateVSyncParameters(base::TimeTicks timebase, |
203 base::TimeDelta interval); | 171 base::TimeDelta interval); |
204 // This overrides any past or future interval from updating vsync parameters. | 172 // This overrides any past or future interval from updating vsync parameters. |
205 void SetAuthoritativeVSyncInterval(base::TimeDelta interval); | 173 void SetAuthoritativeVSyncInterval(base::TimeDelta interval); |
206 | 174 |
207 // BeginFrameSourceBase | 175 // BeginFrameSourceBase overrides. |
208 void AddObserver(BeginFrameObserver* obs) override; | 176 void AddObserver(BeginFrameObserver* obs) override; |
| 177 void RemoveObserver(BeginFrameObserver* obs) override; |
209 void OnNeedsBeginFramesChanged(bool needs_begin_frames) override; | 178 void OnNeedsBeginFramesChanged(bool needs_begin_frames) override; |
| 179 void DidFinishFrame(BeginFrameObserver* obs, |
| 180 size_t remaining_frames) override; |
210 | 181 |
211 // DelayBasedTimeSourceClient | 182 // DelayBasedTimeSourceClient |
212 void OnTimerTick() override; | 183 void OnTimerTick() override; |
213 | 184 |
| 185 // When unthrottled, BeginFrames will be generates as fast as previous frames |
| 186 // finish for each observer. |
| 187 void SetUnthrottled(bool unthrottled); |
| 188 |
214 protected: | 189 protected: |
215 BeginFrameArgs CreateBeginFrameArgs(base::TimeTicks frame_time, | 190 BeginFrameArgs CreateBeginFrameArgs(base::TimeTicks frame_time, |
216 BeginFrameArgs::BeginFrameArgsType type); | 191 BeginFrameArgs::BeginFrameArgsType type); |
217 | 192 |
218 std::unique_ptr<DelayBasedTimeSource> time_source_; | 193 std::unique_ptr<DelayBasedTimeSource> time_source_; |
219 base::TimeTicks last_timebase_; | 194 base::TimeTicks last_timebase_; |
| 195 base::TimeDelta last_interval_; |
220 base::TimeDelta authoritative_interval_; | 196 base::TimeDelta authoritative_interval_; |
221 | 197 |
| 198 bool unthrottled_ = false; |
| 199 bool needs_unthrottled_tick_ = false; |
| 200 std::set<BeginFrameObserver*> frame_finished_observers_; |
| 201 |
222 private: | 202 private: |
223 DISALLOW_COPY_AND_ASSIGN(SyntheticBeginFrameSource); | 203 DISALLOW_COPY_AND_ASSIGN(SyntheticBeginFrameSource); |
224 }; | 204 }; |
225 | 205 |
| 206 // A frame source which calls BeginFrame (at the next possible time) as soon as |
| 207 // remaining frames reaches zero. |
| 208 class CC_EXPORT BackToBackBeginFrameSource : public SyntheticBeginFrameSource { |
| 209 public: |
| 210 explicit BackToBackBeginFrameSource( |
| 211 base::SingleThreadTaskRunner* task_runner); |
| 212 ~BackToBackBeginFrameSource() override; |
| 213 |
| 214 private: |
| 215 DISALLOW_COPY_AND_ASSIGN(BackToBackBeginFrameSource); |
| 216 }; |
| 217 |
226 } // namespace cc | 218 } // namespace cc |
227 | 219 |
228 #endif // CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_ | 220 #endif // CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_ |
OLD | NEW |