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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 // BeginFrameObservers which filter the incoming BeginFrame messages while | 59 // BeginFrameObservers which filter the incoming BeginFrame messages while |
60 // preventing "double dropping" and other bad side effects. | 60 // preventing "double dropping" and other bad side effects. |
61 virtual const BeginFrameArgs& LastUsedBeginFrameArgs() const = 0; | 61 virtual const BeginFrameArgs& LastUsedBeginFrameArgs() const = 0; |
62 | 62 |
63 virtual void OnBeginFrameSourcePausedChanged(bool paused) = 0; | 63 virtual void OnBeginFrameSourcePausedChanged(bool paused) = 0; |
64 | 64 |
65 // Tracing support | 65 // Tracing support |
66 virtual void AsValueInto(base::trace_event::TracedValue* dict) const = 0; | 66 virtual void AsValueInto(base::trace_event::TracedValue* dict) const = 0; |
67 }; | 67 }; |
68 | 68 |
69 // Simple base class which implements a BeginFrameObserver which checks the | |
70 // incoming values meet the BeginFrameObserver requirements and implements the | |
71 // required LastUsedBeginFrameArgs behaviour. | |
72 // | |
73 // Users of this class should; | |
74 // - Implement the OnBeginFrameDerivedImpl function. | |
75 // - Recommended (but not required) to call | |
76 // BeginFrameObserverBase::OnValueInto in their overridden OnValueInto | |
77 // function. | |
78 class CC_EXPORT BeginFrameObserverBase : public BeginFrameObserver { | |
enne (OOO)
2016/04/14 23:02:26
Hmm, this was useful because it implemented some f
| |
79 public: | |
80 BeginFrameObserverBase(); | |
81 | |
82 // BeginFrameObserver | |
83 | |
84 // Traces |args| and DCHECK |args| satisfies pre-conditions then calls | |
85 // OnBeginFrameDerivedImpl and updates the last_begin_frame_args_ value on | |
86 // true. | |
87 void OnBeginFrame(const BeginFrameArgs& args) override; | |
88 const BeginFrameArgs& LastUsedBeginFrameArgs() const override; | |
89 | |
90 // Outputs last_begin_frame_args_ | |
91 void AsValueInto(base::trace_event::TracedValue* dict) const override; | |
92 | |
93 protected: | |
94 // Subclasses should override this method! | |
95 // Return true if the given argument is (or will be) used. | |
96 virtual bool OnBeginFrameDerivedImpl(const BeginFrameArgs& args) = 0; | |
97 | |
98 BeginFrameArgs last_begin_frame_args_; | |
99 int64_t dropped_begin_frame_args_; | |
100 | |
101 private: | |
102 DISALLOW_COPY_AND_ASSIGN(BeginFrameObserverBase); | |
103 }; | |
104 | |
105 // Interface for a class which produces BeginFrame calls to a | 69 // Interface for a class which produces BeginFrame calls to a |
106 // BeginFrameObserver. | 70 // BeginFrameObserver. |
107 // | 71 // |
108 // BeginFrame calls *normally* occur just after a vsync interrupt when input | 72 // BeginFrame calls *normally* occur just after a vsync interrupt when input |
109 // processing has been finished and provide information about the time values | 73 // processing has been finished and provide information about the time values |
110 // of the vsync times. *However*, these values can be heavily modified or even | 74 // of the vsync times. *However*, these values can be heavily modified or even |
111 // plain made up (when no vsync signal is available or vsync throttling is | 75 // plain made up (when no vsync signal is available or vsync throttling is |
112 // turned off). See the BeginFrameObserver for information about the guarantees | 76 // turned off). See the BeginFrameObserver for information about the guarantees |
113 // all BeginFrameSources *must* provide. | 77 // all BeginFrameSources *must* provide. |
114 class CC_EXPORT BeginFrameSource { | 78 class CC_EXPORT BeginFrameSource { |
115 public: | 79 public: |
116 virtual ~BeginFrameSource() {} | 80 virtual ~BeginFrameSource() {} |
117 | 81 |
118 // DidFinishFrame provides back pressure to a frame source about frame | 82 // DidFinishFrame provides back pressure to a frame source about frame |
119 // processing (rather than toggling SetNeedsBeginFrames every frame). It is | 83 // processing (rather than toggling SetNeedsBeginFrames every frame). It is |
120 // used by systems like the BackToBackFrameSource to make sure only one frame | 84 // used by systems like the BackToBackFrameSource to make sure only one frame |
121 // is pending at a time. | 85 // is pending at a time. |
122 virtual void DidFinishFrame(size_t remaining_frames) = 0; | 86 virtual void DidFinishFrame(BeginFrameObserver* obs) = 0; |
123 | 87 |
124 // Add/Remove an observer from the source. When no observers are added the BFS | 88 // Add/Remove an observer from the source. When no observers are added the BFS |
125 // should shut down its timers, disable vsync, etc. | 89 // should shut down its timers, disable vsync, etc. |
126 virtual void AddObserver(BeginFrameObserver* obs) = 0; | 90 virtual void AddObserver(BeginFrameObserver* obs) = 0; |
127 virtual void RemoveObserver(BeginFrameObserver* obs) = 0; | 91 virtual void RemoveObserver(BeginFrameObserver* obs) = 0; |
128 | 92 |
129 // Tracing support - Recommend (but not required) to call this implementation | 93 // Tracing support - Recommend (but not required) to call this implementation |
130 // in any override. | 94 // in any override. |
131 virtual void AsValueInto(base::trace_event::TracedValue* dict) const = 0; | 95 virtual void AsValueInto(base::trace_event::TracedValue* dict) const = 0; |
132 }; | 96 }; |
133 | 97 |
134 // Simple base class which implements a BeginFrameSource. | 98 // Simple base class which implements a BeginFrameSource. |
135 // Implementation classes should: | 99 // Implementation classes should: |
136 // - Implement the pure virtual (Set)NeedsBeginFrames methods from | 100 // - Implement the pure virtual (Set)NeedsBeginFrames methods from |
137 // BeginFrameSource. | 101 // BeginFrameSource. |
138 // - Use the CallOnBeginFrame method to call to the observer(s). | 102 // - Use the CallOnBeginFrame method to call to the observer(s). |
139 // - Recommended (but not required) to call BeginFrameSourceBase::AsValueInto | 103 // - Recommended (but not required) to call BeginFrameSourceBase::AsValueInto |
140 // in their own AsValueInto implementation. | 104 // in their own AsValueInto implementation. |
141 class CC_EXPORT BeginFrameSourceBase : public BeginFrameSource { | 105 class CC_EXPORT BeginFrameSourceBase : public BeginFrameSource { |
142 public: | 106 public: |
143 ~BeginFrameSourceBase() override; | 107 ~BeginFrameSourceBase() override; |
144 | 108 |
145 // BeginFrameSource | 109 // BeginFrameSource |
146 void DidFinishFrame(size_t remaining_frames) override {} | 110 void DidFinishFrame(BeginFrameObserver* obs) override {} |
147 void AddObserver(BeginFrameObserver* obs) override; | 111 void AddObserver(BeginFrameObserver* obs) override; |
148 void RemoveObserver(BeginFrameObserver* obs) override; | 112 void RemoveObserver(BeginFrameObserver* obs) override; |
149 | 113 |
150 // Tracing support - Recommend (but not required) to call this implementation | 114 // Tracing support - Recommend (but not required) to call this implementation |
151 // in any override. | 115 // in any override. |
152 void AsValueInto(base::trace_event::TracedValue* dict) const override; | 116 void AsValueInto(base::trace_event::TracedValue* dict) const override; |
153 | 117 |
154 protected: | 118 protected: |
155 BeginFrameSourceBase(); | 119 BeginFrameSourceBase(); |
156 | 120 |
(...skipping 18 matching lines...) Expand all Loading... | |
175 }; | 139 }; |
176 | 140 |
177 // A frame source which calls BeginFrame (at the next possible time) as soon as | 141 // A frame source which calls BeginFrame (at the next possible time) as soon as |
178 // remaining frames reaches zero. | 142 // remaining frames reaches zero. |
179 class CC_EXPORT BackToBackBeginFrameSource : public BeginFrameSourceBase { | 143 class CC_EXPORT BackToBackBeginFrameSource : public BeginFrameSourceBase { |
180 public: | 144 public: |
181 explicit BackToBackBeginFrameSource( | 145 explicit BackToBackBeginFrameSource( |
182 base::SingleThreadTaskRunner* task_runner); | 146 base::SingleThreadTaskRunner* task_runner); |
183 ~BackToBackBeginFrameSource() override; | 147 ~BackToBackBeginFrameSource() override; |
184 | 148 |
185 // BeginFrameSource | |
186 void DidFinishFrame(size_t remaining_frames) override; | |
187 | |
188 // BeginFrameSourceBase | 149 // BeginFrameSourceBase |
150 void DidFinishFrame(BeginFrameObserver* obs) override; | |
189 void AddObserver(BeginFrameObserver* obs) override; | 151 void AddObserver(BeginFrameObserver* obs) override; |
190 void OnNeedsBeginFramesChanged(bool needs_begin_frames) override; | 152 void OnNeedsBeginFramesChanged(bool needs_begin_frames) override; |
191 | 153 |
192 // Tracing | 154 // Tracing |
193 void AsValueInto(base::trace_event::TracedValue* dict) const override; | 155 void AsValueInto(base::trace_event::TracedValue* dict) const override; |
194 | 156 |
195 protected: | 157 protected: |
196 virtual base::TimeTicks Now(); // Now overridable for testing | 158 virtual base::TimeTicks Now(); // Now overridable for testing |
197 | 159 |
198 base::SingleThreadTaskRunner* task_runner_; | 160 base::SingleThreadTaskRunner* task_runner_; |
(...skipping 16 matching lines...) Expand all Loading... | |
215 explicit SyntheticBeginFrameSource(base::SingleThreadTaskRunner* task_runner, | 177 explicit SyntheticBeginFrameSource(base::SingleThreadTaskRunner* task_runner, |
216 base::TimeDelta initial_vsync_interval); | 178 base::TimeDelta initial_vsync_interval); |
217 explicit SyntheticBeginFrameSource( | 179 explicit SyntheticBeginFrameSource( |
218 std::unique_ptr<DelayBasedTimeSource> time_source); | 180 std::unique_ptr<DelayBasedTimeSource> time_source); |
219 ~SyntheticBeginFrameSource() override; | 181 ~SyntheticBeginFrameSource() override; |
220 | 182 |
221 void OnUpdateVSyncParameters(base::TimeTicks new_vsync_timebase, | 183 void OnUpdateVSyncParameters(base::TimeTicks new_vsync_timebase, |
222 base::TimeDelta new_vsync_interval); | 184 base::TimeDelta new_vsync_interval); |
223 | 185 |
224 // BeginFrameSourceBase | 186 // BeginFrameSourceBase |
187 void DidFinishFrame(BeginFrameObserver* obs) override; | |
225 void AddObserver(BeginFrameObserver* obs) override; | 188 void AddObserver(BeginFrameObserver* obs) override; |
226 void OnNeedsBeginFramesChanged(bool needs_begin_frames) override; | 189 void OnNeedsBeginFramesChanged(bool needs_begin_frames) override; |
227 | 190 |
228 // Tracing | 191 // Tracing |
229 void AsValueInto(base::trace_event::TracedValue* dict) const override; | 192 void AsValueInto(base::trace_event::TracedValue* dict) const override; |
230 | 193 |
231 // DelayBasedTimeSourceClient | 194 // DelayBasedTimeSourceClient |
232 void OnTimerTick() override; | 195 void OnTimerTick() override; |
233 | 196 |
234 protected: | 197 protected: |
235 BeginFrameArgs CreateBeginFrameArgs(base::TimeTicks frame_time, | 198 BeginFrameArgs CreateBeginFrameArgs(base::TimeTicks frame_time, |
236 BeginFrameArgs::BeginFrameArgsType type); | 199 BeginFrameArgs::BeginFrameArgsType type); |
237 | 200 |
238 std::unique_ptr<DelayBasedTimeSource> time_source_; | 201 std::unique_ptr<DelayBasedTimeSource> time_source_; |
239 | 202 |
240 private: | 203 private: |
241 DISALLOW_COPY_AND_ASSIGN(SyntheticBeginFrameSource); | 204 DISALLOW_COPY_AND_ASSIGN(SyntheticBeginFrameSource); |
242 }; | 205 }; |
243 | 206 |
244 } // namespace cc | 207 } // namespace cc |
245 | 208 |
246 #endif // CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_ | 209 #endif // CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_ |
OLD | NEW |