| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 public: | 110 public: |
| 111 BeginFrameSource(); | 111 BeginFrameSource(); |
| 112 virtual ~BeginFrameSource(); | 112 virtual ~BeginFrameSource(); |
| 113 | 113 |
| 114 // Returns an identifier for this BeginFrameSource. Guaranteed unique within a | 114 // Returns an identifier for this BeginFrameSource. Guaranteed unique within a |
| 115 // process, but not across processes. This is used to create BeginFrames that | 115 // process, but not across processes. This is used to create BeginFrames that |
| 116 // originate at this source. Note that BeginFrameSources may pass on | 116 // originate at this source. Note that BeginFrameSources may pass on |
| 117 // BeginFrames created by other sources, with different IDs. | 117 // BeginFrames created by other sources, with different IDs. |
| 118 uint32_t source_id() const { return source_id_; } | 118 uint32_t source_id() const { return source_id_; } |
| 119 | 119 |
| 120 // BeginFrameObservers use DidFinishFrame to acknowledge that they have | 120 // BeginFrameObservers use DidFinishFrame to provide back pressure to a frame |
| 121 // completed handling a BeginFrame. | 121 // source about frame processing (rather than toggling SetNeedsBeginFrames |
| 122 // | 122 // every frame). For example, the BackToBackFrameSource uses them to make sure |
| 123 // The DisplayScheduler uses these acknowledgments to trigger an early | 123 // only one frame is pending at a time. |
| 124 // deadline once all BeginFrameObservers have completed a frame. | 124 virtual void DidFinishFrame(BeginFrameObserver* obs) = 0; |
| 125 // | |
| 126 // They also provide back pressure to a frame source about frame processing | |
| 127 // (rather than toggling SetNeedsBeginFrames every frame). For example, the | |
| 128 // BackToBackFrameSource uses them to make sure only one frame is pending at a | |
| 129 // time. | |
| 130 // | |
| 131 // Note that the BeginFrameSource should not assume that the |ack| references | |
| 132 // a valid BeginFrame sent by the source. The |ack| may reference a BeginFrame | |
| 133 // sent by a different BeginFrameSource, and a malicious client may reference | |
| 134 // any invalid frame. The source is responsible for checking for | |
| 135 // validity/relevance of the BeginFrame itself. | |
| 136 // TODO(eseckler): Use BeginFrameAcks in DisplayScheduler as described above. | |
| 137 virtual void DidFinishFrame(BeginFrameObserver* obs, | |
| 138 const BeginFrameAck& ack) = 0; | |
| 139 | 125 |
| 140 // Add/Remove an observer from the source. When no observers are added the BFS | 126 // Add/Remove an observer from the source. When no observers are added the BFS |
| 141 // should shut down its timers, disable vsync, etc. | 127 // should shut down its timers, disable vsync, etc. |
| 142 virtual void AddObserver(BeginFrameObserver* obs) = 0; | 128 virtual void AddObserver(BeginFrameObserver* obs) = 0; |
| 143 virtual void RemoveObserver(BeginFrameObserver* obs) = 0; | 129 virtual void RemoveObserver(BeginFrameObserver* obs) = 0; |
| 144 | 130 |
| 145 // Returns false if the begin frame source will just continue to produce | 131 // Returns false if the begin frame source will just continue to produce |
| 146 // begin frames without waiting. | 132 // begin frames without waiting. |
| 147 virtual bool IsThrottled() const = 0; | 133 virtual bool IsThrottled() const = 0; |
| 148 | 134 |
| 149 virtual void AsValueInto(base::trace_event::TracedValue* state) const; | 135 virtual void AsValueInto(base::trace_event::TracedValue* state) const; |
| 150 | 136 |
| 151 private: | 137 private: |
| 152 uint32_t source_id_; | 138 uint32_t source_id_; |
| 153 | 139 |
| 154 DISALLOW_COPY_AND_ASSIGN(BeginFrameSource); | 140 DISALLOW_COPY_AND_ASSIGN(BeginFrameSource); |
| 155 }; | 141 }; |
| 156 | 142 |
| 157 // A BeginFrameSource that does nothing. | 143 // A BeginFrameSource that does nothing. |
| 158 class CC_EXPORT StubBeginFrameSource : public BeginFrameSource { | 144 class CC_EXPORT StubBeginFrameSource : public BeginFrameSource { |
| 159 public: | 145 public: |
| 160 void DidFinishFrame(BeginFrameObserver* obs, | 146 void DidFinishFrame(BeginFrameObserver* obs) override {} |
| 161 const BeginFrameAck& ack) override {} | |
| 162 void AddObserver(BeginFrameObserver* obs) override {} | 147 void AddObserver(BeginFrameObserver* obs) override {} |
| 163 void RemoveObserver(BeginFrameObserver* obs) override {} | 148 void RemoveObserver(BeginFrameObserver* obs) override {} |
| 164 bool IsThrottled() const override; | 149 bool IsThrottled() const override; |
| 165 }; | 150 }; |
| 166 | 151 |
| 167 // A frame source which ticks itself independently. | 152 // A frame source which ticks itself independently. |
| 168 class CC_EXPORT SyntheticBeginFrameSource : public BeginFrameSource { | 153 class CC_EXPORT SyntheticBeginFrameSource : public BeginFrameSource { |
| 169 public: | 154 public: |
| 170 ~SyntheticBeginFrameSource() override; | 155 ~SyntheticBeginFrameSource() override; |
| 171 | 156 |
| 172 virtual void OnUpdateVSyncParameters(base::TimeTicks timebase, | 157 virtual void OnUpdateVSyncParameters(base::TimeTicks timebase, |
| 173 base::TimeDelta interval) = 0; | 158 base::TimeDelta interval) = 0; |
| 174 // This overrides any past or future interval from updating vsync parameters. | 159 // This overrides any past or future interval from updating vsync parameters. |
| 175 virtual void SetAuthoritativeVSyncInterval(base::TimeDelta interval) = 0; | 160 virtual void SetAuthoritativeVSyncInterval(base::TimeDelta interval) = 0; |
| 176 }; | 161 }; |
| 177 | 162 |
| 178 // A frame source which calls BeginFrame (at the next possible time) as soon as | 163 // A frame source which calls BeginFrame (at the next possible time) as soon as |
| 179 // an observer acknowledges the prior BeginFrame. | 164 // an observer acknowledges the prior BeginFrame. |
| 180 class CC_EXPORT BackToBackBeginFrameSource : public SyntheticBeginFrameSource, | 165 class CC_EXPORT BackToBackBeginFrameSource : public SyntheticBeginFrameSource, |
| 181 public DelayBasedTimeSourceClient { | 166 public DelayBasedTimeSourceClient { |
| 182 public: | 167 public: |
| 183 explicit BackToBackBeginFrameSource( | 168 explicit BackToBackBeginFrameSource( |
| 184 std::unique_ptr<DelayBasedTimeSource> time_source); | 169 std::unique_ptr<DelayBasedTimeSource> time_source); |
| 185 ~BackToBackBeginFrameSource() override; | 170 ~BackToBackBeginFrameSource() override; |
| 186 | 171 |
| 187 // BeginFrameSource implementation. | 172 // BeginFrameSource implementation. |
| 188 void AddObserver(BeginFrameObserver* obs) override; | 173 void AddObserver(BeginFrameObserver* obs) override; |
| 189 void RemoveObserver(BeginFrameObserver* obs) override; | 174 void RemoveObserver(BeginFrameObserver* obs) override; |
| 190 void DidFinishFrame(BeginFrameObserver* obs, | 175 void DidFinishFrame(BeginFrameObserver* obs) override; |
| 191 const BeginFrameAck& ack) override; | |
| 192 bool IsThrottled() const override; | 176 bool IsThrottled() const override; |
| 193 | 177 |
| 194 // SyntheticBeginFrameSource implementation. | 178 // SyntheticBeginFrameSource implementation. |
| 195 void OnUpdateVSyncParameters(base::TimeTicks timebase, | 179 void OnUpdateVSyncParameters(base::TimeTicks timebase, |
| 196 base::TimeDelta interval) override {} | 180 base::TimeDelta interval) override {} |
| 197 void SetAuthoritativeVSyncInterval(base::TimeDelta interval) override {} | 181 void SetAuthoritativeVSyncInterval(base::TimeDelta interval) override {} |
| 198 | 182 |
| 199 // DelayBasedTimeSourceClient implementation. | 183 // DelayBasedTimeSourceClient implementation. |
| 200 void OnTimerTick() override; | 184 void OnTimerTick() override; |
| 201 | 185 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 214 class CC_EXPORT DelayBasedBeginFrameSource : public SyntheticBeginFrameSource, | 198 class CC_EXPORT DelayBasedBeginFrameSource : public SyntheticBeginFrameSource, |
| 215 public DelayBasedTimeSourceClient { | 199 public DelayBasedTimeSourceClient { |
| 216 public: | 200 public: |
| 217 explicit DelayBasedBeginFrameSource( | 201 explicit DelayBasedBeginFrameSource( |
| 218 std::unique_ptr<DelayBasedTimeSource> time_source); | 202 std::unique_ptr<DelayBasedTimeSource> time_source); |
| 219 ~DelayBasedBeginFrameSource() override; | 203 ~DelayBasedBeginFrameSource() override; |
| 220 | 204 |
| 221 // BeginFrameSource implementation. | 205 // BeginFrameSource implementation. |
| 222 void AddObserver(BeginFrameObserver* obs) override; | 206 void AddObserver(BeginFrameObserver* obs) override; |
| 223 void RemoveObserver(BeginFrameObserver* obs) override; | 207 void RemoveObserver(BeginFrameObserver* obs) override; |
| 224 void DidFinishFrame(BeginFrameObserver* obs, | 208 void DidFinishFrame(BeginFrameObserver* obs) override {} |
| 225 const BeginFrameAck& ack) override {} | |
| 226 bool IsThrottled() const override; | 209 bool IsThrottled() const override; |
| 227 | 210 |
| 228 // SyntheticBeginFrameSource implementation. | 211 // SyntheticBeginFrameSource implementation. |
| 229 void OnUpdateVSyncParameters(base::TimeTicks timebase, | 212 void OnUpdateVSyncParameters(base::TimeTicks timebase, |
| 230 base::TimeDelta interval) override; | 213 base::TimeDelta interval) override; |
| 231 void SetAuthoritativeVSyncInterval(base::TimeDelta interval) override; | 214 void SetAuthoritativeVSyncInterval(base::TimeDelta interval) override; |
| 232 | 215 |
| 233 // DelayBasedTimeSourceClient implementation. | 216 // DelayBasedTimeSourceClient implementation. |
| 234 void OnTimerTick() override; | 217 void OnTimerTick() override; |
| 235 | 218 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 259 // an observable BeginFrameSource. | 242 // an observable BeginFrameSource. |
| 260 class CC_EXPORT ExternalBeginFrameSource : public BeginFrameSource { | 243 class CC_EXPORT ExternalBeginFrameSource : public BeginFrameSource { |
| 261 public: | 244 public: |
| 262 // Client lifetime must be preserved by owner past the lifetime of this class. | 245 // Client lifetime must be preserved by owner past the lifetime of this class. |
| 263 explicit ExternalBeginFrameSource(ExternalBeginFrameSourceClient* client); | 246 explicit ExternalBeginFrameSource(ExternalBeginFrameSourceClient* client); |
| 264 ~ExternalBeginFrameSource() override; | 247 ~ExternalBeginFrameSource() override; |
| 265 | 248 |
| 266 // BeginFrameSource implementation. | 249 // BeginFrameSource implementation. |
| 267 void AddObserver(BeginFrameObserver* obs) override; | 250 void AddObserver(BeginFrameObserver* obs) override; |
| 268 void RemoveObserver(BeginFrameObserver* obs) override; | 251 void RemoveObserver(BeginFrameObserver* obs) override; |
| 269 void DidFinishFrame(BeginFrameObserver* obs, | 252 void DidFinishFrame(BeginFrameObserver* obs) override {} |
| 270 const BeginFrameAck& ack) override; | |
| 271 bool IsThrottled() const override; | 253 bool IsThrottled() const override; |
| 272 void AsValueInto(base::trace_event::TracedValue* state) const override; | 254 void AsValueInto(base::trace_event::TracedValue* state) const override; |
| 273 | 255 |
| 274 void OnSetBeginFrameSourcePaused(bool paused); | 256 void OnSetBeginFrameSourcePaused(bool paused); |
| 275 void OnBeginFrame(const BeginFrameArgs& args); | 257 void OnBeginFrame(const BeginFrameArgs& args); |
| 276 | 258 |
| 277 protected: | 259 protected: |
| 278 BeginFrameArgs last_begin_frame_args_; | 260 BeginFrameArgs last_begin_frame_args_; |
| 279 std::unordered_set<BeginFrameObserver*> observers_; | 261 std::unordered_set<BeginFrameObserver*> observers_; |
| 280 ExternalBeginFrameSourceClient* client_; | 262 ExternalBeginFrameSourceClient* client_; |
| 281 bool paused_ = false; | 263 bool paused_ = false; |
| 282 | 264 |
| 283 private: | 265 private: |
| 284 DISALLOW_COPY_AND_ASSIGN(ExternalBeginFrameSource); | 266 DISALLOW_COPY_AND_ASSIGN(ExternalBeginFrameSource); |
| 285 }; | 267 }; |
| 286 | 268 |
| 287 } // namespace cc | 269 } // namespace cc |
| 288 | 270 |
| 289 #endif // CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_ | 271 #endif // CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_ |
| OLD | NEW |