Chromium Code Reviews| 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 // is pending at a time. | 115 // is pending at a time. |
| 116 virtual void DidFinishFrame(BeginFrameObserver* obs, | 116 virtual void DidFinishFrame(BeginFrameObserver* obs, |
| 117 size_t remaining_frames) = 0; | 117 size_t remaining_frames) = 0; |
| 118 | 118 |
| 119 // Add/Remove an observer from the source. When no observers are added the BFS | 119 // Add/Remove an observer from the source. When no observers are added the BFS |
| 120 // should shut down its timers, disable vsync, etc. | 120 // should shut down its timers, disable vsync, etc. |
| 121 virtual void AddObserver(BeginFrameObserver* obs) = 0; | 121 virtual void AddObserver(BeginFrameObserver* obs) = 0; |
| 122 virtual void RemoveObserver(BeginFrameObserver* obs) = 0; | 122 virtual void RemoveObserver(BeginFrameObserver* obs) = 0; |
| 123 }; | 123 }; |
| 124 | 124 |
| 125 // Simple base class which implements a BeginFrameSource. | 125 // A frame source which ticks itself independently. |
| 126 // Implementation classes should: | 126 class CC_EXPORT SyntheticBeginFrameSource : public BeginFrameSource { |
| 127 // - Implement the pure virtual (Set)NeedsBeginFrames methods from | |
| 128 // BeginFrameSource. | |
| 129 // - Use the CallOnBeginFrame method to call to the observer(s). | |
| 130 class CC_EXPORT BeginFrameSourceBase : public BeginFrameSource { | |
| 131 public: | 127 public: |
| 132 ~BeginFrameSourceBase() override; | 128 ~SyntheticBeginFrameSource() override; |
| 133 | 129 |
| 134 // BeginFrameSource | 130 virtual void OnUpdateVSyncParameters(base::TimeTicks timebase, |
| 135 void DidFinishFrame(BeginFrameObserver* obs, | 131 base::TimeDelta interval) = 0; |
| 136 size_t remaining_frames) override {} | 132 // This overrides any past or future interval from updating vsync parameters. |
| 137 void AddObserver(BeginFrameObserver* obs) override; | 133 virtual void SetAuthoritativeVSyncInterval(base::TimeDelta interval) = 0; |
| 138 void RemoveObserver(BeginFrameObserver* obs) override; | |
| 139 | |
| 140 protected: | |
| 141 BeginFrameSourceBase(); | |
| 142 | |
| 143 // These methods should be used by subclasses to make the call to the | |
| 144 // observers. | |
| 145 void CallOnBeginFrame(const BeginFrameArgs& args); | |
| 146 void SetBeginFrameSourcePaused(bool paused); | |
| 147 | |
| 148 // This notifies that the subclass that it must turn on or off its mechnanism | |
| 149 // for producing BeginFrames. | |
| 150 virtual void OnNeedsBeginFramesChanged(bool needs_begin_frames) {} | |
|
enne (OOO)
2016/06/15 19:46:56
Just moving this logic up into each class is nice
| |
| 151 | |
| 152 bool needs_begin_frames() const { return !observers_.empty(); } | |
| 153 | |
| 154 std::set<BeginFrameObserver*> observers_; | |
| 155 bool paused_; | |
| 156 | |
| 157 private: | |
| 158 DISALLOW_COPY_AND_ASSIGN(BeginFrameSourceBase); | |
| 159 }; | 134 }; |
| 160 | 135 |
| 161 // A frame source which calls BeginFrame (at the next possible time) as soon as | 136 // A frame source which calls BeginFrame (at the next possible time) as soon as |
| 162 // remaining frames reaches zero. | 137 // remaining frames reaches zero. |
| 163 class CC_EXPORT BackToBackBeginFrameSource : public BeginFrameSourceBase { | 138 class CC_EXPORT BackToBackBeginFrameSource : public SyntheticBeginFrameSource, |
| 139 public DelayBasedTimeSourceClient { | |
| 164 public: | 140 public: |
| 165 explicit BackToBackBeginFrameSource( | 141 explicit BackToBackBeginFrameSource( |
| 166 base::SingleThreadTaskRunner* task_runner); | 142 std::unique_ptr<DelayBasedTimeSource> time_source); |
| 167 ~BackToBackBeginFrameSource() override; | 143 ~BackToBackBeginFrameSource() override; |
| 168 | 144 |
| 169 // BeginFrameSource | 145 // BeginFrameSource implementation. |
| 170 void AddObserver(BeginFrameObserver* obs) override; | 146 void AddObserver(BeginFrameObserver* obs) override; |
| 171 void RemoveObserver(BeginFrameObserver* obs) override; | 147 void RemoveObserver(BeginFrameObserver* obs) override; |
| 172 void DidFinishFrame(BeginFrameObserver* obs, | 148 void DidFinishFrame(BeginFrameObserver* obs, |
| 173 size_t remaining_frames) override; | 149 size_t remaining_frames) override; |
| 174 | 150 |
| 175 protected: | 151 // SyntheticBeginFrameSource implementation. |
| 176 virtual base::TimeTicks Now(); // Now overridable for testing | 152 void OnUpdateVSyncParameters(base::TimeTicks timebase, |
| 153 base::TimeDelta interval) override {} | |
| 154 void SetAuthoritativeVSyncInterval(base::TimeDelta interval) override {} | |
| 177 | 155 |
| 178 base::SingleThreadTaskRunner* task_runner_; | 156 // DelayBasedTimeSourceClient implementation. |
| 179 base::CancelableClosure begin_frame_task_; | 157 void OnTimerTick() override; |
| 180 std::set<BeginFrameObserver*> pending_begin_frame_observers_; | |
| 181 | |
| 182 void PostPendingBeginFramesTask(); | |
| 183 void SendPendingBeginFrames(); | |
| 184 | 158 |
| 185 private: | 159 private: |
| 160 std::unique_ptr<DelayBasedTimeSource> time_source_; | |
| 161 std::set<BeginFrameObserver*> observers_; | |
| 162 std::set<BeginFrameObserver*> pending_begin_frame_observers_; | |
| 186 base::WeakPtrFactory<BackToBackBeginFrameSource> weak_factory_; | 163 base::WeakPtrFactory<BackToBackBeginFrameSource> weak_factory_; |
| 187 | 164 |
| 188 DISALLOW_COPY_AND_ASSIGN(BackToBackBeginFrameSource); | 165 DISALLOW_COPY_AND_ASSIGN(BackToBackBeginFrameSource); |
| 189 }; | 166 }; |
| 190 | 167 |
| 191 // A frame source which is locked to an external parameters provides from a | 168 // A frame source which is locked to an external parameters provides from a |
| 192 // vsync source and generates BeginFrameArgs for it. | 169 // vsync source and generates BeginFrameArgs for it. |
| 193 class CC_EXPORT SyntheticBeginFrameSource : public BeginFrameSourceBase, | 170 class CC_EXPORT DelayBasedBeginFrameSource : public SyntheticBeginFrameSource, |
| 194 public DelayBasedTimeSourceClient { | 171 public DelayBasedTimeSourceClient { |
| 195 public: | 172 public: |
| 196 explicit SyntheticBeginFrameSource(base::SingleThreadTaskRunner* task_runner, | 173 explicit DelayBasedBeginFrameSource( |
| 197 base::TimeDelta initial_vsync_interval); | |
| 198 explicit SyntheticBeginFrameSource( | |
| 199 std::unique_ptr<DelayBasedTimeSource> time_source); | 174 std::unique_ptr<DelayBasedTimeSource> time_source); |
| 200 ~SyntheticBeginFrameSource() override; | 175 ~DelayBasedBeginFrameSource() override; |
| 201 | 176 |
| 177 // BeginFrameSource implementation. | |
| 178 void AddObserver(BeginFrameObserver* obs) override; | |
| 179 void RemoveObserver(BeginFrameObserver* obs) override; | |
| 180 void DidFinishFrame(BeginFrameObserver* obs, | |
| 181 size_t remaining_frames) override {} | |
| 182 | |
| 183 // SyntheticBeginFrameSource implementation. | |
| 202 void OnUpdateVSyncParameters(base::TimeTicks timebase, | 184 void OnUpdateVSyncParameters(base::TimeTicks timebase, |
| 203 base::TimeDelta interval); | 185 base::TimeDelta interval) override; |
| 204 // This overrides any past or future interval from updating vsync parameters. | 186 void SetAuthoritativeVSyncInterval(base::TimeDelta interval) override; |
| 205 void SetAuthoritativeVSyncInterval(base::TimeDelta interval); | |
| 206 | 187 |
| 207 // BeginFrameSourceBase | 188 // DelayBasedTimeSourceClient implementation. |
| 208 void AddObserver(BeginFrameObserver* obs) override; | |
| 209 void OnNeedsBeginFramesChanged(bool needs_begin_frames) override; | |
| 210 | |
| 211 // DelayBasedTimeSourceClient | |
| 212 void OnTimerTick() override; | 189 void OnTimerTick() override; |
| 213 | 190 |
| 214 protected: | 191 private: |
| 215 BeginFrameArgs CreateBeginFrameArgs(base::TimeTicks frame_time, | 192 BeginFrameArgs CreateBeginFrameArgs(base::TimeTicks frame_time, |
| 216 BeginFrameArgs::BeginFrameArgsType type); | 193 BeginFrameArgs::BeginFrameArgsType type); |
| 217 | 194 |
| 218 std::unique_ptr<DelayBasedTimeSource> time_source_; | 195 std::unique_ptr<DelayBasedTimeSource> time_source_; |
| 196 std::set<BeginFrameObserver*> observers_; | |
| 219 base::TimeTicks last_timebase_; | 197 base::TimeTicks last_timebase_; |
| 220 base::TimeDelta authoritative_interval_; | 198 base::TimeDelta authoritative_interval_; |
| 221 | 199 |
| 222 private: | 200 DISALLOW_COPY_AND_ASSIGN(DelayBasedBeginFrameSource); |
| 223 DISALLOW_COPY_AND_ASSIGN(SyntheticBeginFrameSource); | |
| 224 }; | 201 }; |
| 225 | 202 |
| 226 } // namespace cc | 203 } // namespace cc |
| 227 | 204 |
| 228 #endif // CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_ | 205 #endif // CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_ |
| OLD | NEW |