Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(548)

Side by Side Diff: cc/scheduler/begin_frame_source.h

Issue 1136123009: Remove "mixin" from BeginFrameSource/Observer base classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated comments Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 // 46 //
47 // These requirements are designed to allow chaining and nesting of 47 // These requirements are designed to allow chaining and nesting of
48 // BeginFrameObservers which filter the incoming BeginFrame messages while 48 // BeginFrameObservers which filter the incoming BeginFrame messages while
49 // preventing "double dropping" and other bad side effects. 49 // preventing "double dropping" and other bad side effects.
50 virtual const BeginFrameArgs LastUsedBeginFrameArgs() const = 0; 50 virtual const BeginFrameArgs LastUsedBeginFrameArgs() const = 0;
51 51
52 // Tracing support 52 // Tracing support
53 virtual void AsValueInto(base::trace_event::TracedValue* dict) const = 0; 53 virtual void AsValueInto(base::trace_event::TracedValue* dict) const = 0;
54 }; 54 };
55 55
56 // Simple mix in which implements a BeginFrameObserver which checks the 56 // Simple base class which implements a BeginFrameObserver which checks the
57 // incoming values meet the BeginFrameObserver requirements and implements the 57 // incoming values meet the BeginFrameObserver requirements and implements the
58 // required LastUsedBeginFrameArgs behaviour. 58 // required LastUsedBeginFrameArgs behaviour.
59 // 59 //
60 // Users of this mix in should; 60 // Users of this class should;
61 // - Implement the OnBeginFrameMixInDelegate function. 61 // - Implement the OnBeginFrameDerivedImpl function.
62 // - Recommended (but not required) to call 62 // - Recommended (but not required) to call
63 // BeginFrameObserverMixIn::OnValueInto in their overridden OnValueInto 63 // BeginFrameObserverBase::OnValueInto in their overridden OnValueInto
64 // function. 64 // function.
65 class CC_EXPORT BeginFrameObserverMixIn : public BeginFrameObserver { 65 class CC_EXPORT BeginFrameObserverBase : public BeginFrameObserver {
66 public: 66 public:
67 BeginFrameObserverMixIn(); 67 BeginFrameObserverBase();
68 68
69 // BeginFrameObserver 69 // BeginFrameObserver
70 70
71 // Traces |args| and DCHECK |args| satisfies pre-conditions then calls 71 // Traces |args| and DCHECK |args| satisfies pre-conditions then calls
72 // OnBeginFrameMixInDelegate and updates the last_begin_frame_args_ value on 72 // OnBeginFrameDerivedImpl and updates the last_begin_frame_args_ value on
73 // true. 73 // true.
74 void OnBeginFrame(const BeginFrameArgs& args) override; 74 void OnBeginFrame(const BeginFrameArgs& args) override;
75 const BeginFrameArgs LastUsedBeginFrameArgs() const override; 75 const BeginFrameArgs LastUsedBeginFrameArgs() const override;
76 76
77 // Outputs last_begin_frame_args_ 77 // Outputs last_begin_frame_args_
78 void AsValueInto(base::trace_event::TracedValue* dict) const override; 78 void AsValueInto(base::trace_event::TracedValue* dict) const override;
79 79
80 protected: 80 protected:
81 // Subclasses should override this method! 81 // Subclasses should override this method!
82 // Return true if the given argument is (or will be) used. 82 // Return true if the given argument is (or will be) used.
83 virtual bool OnBeginFrameMixInDelegate(const BeginFrameArgs& args) = 0; 83 virtual bool OnBeginFrameDerivedImpl(const BeginFrameArgs& args) = 0;
84 84
85 BeginFrameArgs last_begin_frame_args_; 85 BeginFrameArgs last_begin_frame_args_;
86 int64_t dropped_begin_frame_args_; 86 int64_t dropped_begin_frame_args_;
87 }; 87 };
88 88
89 // Interface for a class which produces BeginFrame calls to a 89 // Interface for a class which produces BeginFrame calls to a
90 // BeginFrameObserver. 90 // BeginFrameObserver.
91 // 91 //
92 // BeginFrame calls *normally* occur just after a vsync interrupt when input 92 // BeginFrame calls *normally* occur just after a vsync interrupt when input
93 // processing has been finished and provide information about the time values 93 // processing has been finished and provide information about the time values
(...skipping 24 matching lines...) Expand all
118 virtual void RemoveObserver(BeginFrameObserver* obs) = 0; 118 virtual void RemoveObserver(BeginFrameObserver* obs) = 0;
119 119
120 // Tells the Source that client is ready to handle BeginFrames messages. 120 // Tells the Source that client is ready to handle BeginFrames messages.
121 virtual void SetClientReady() = 0; 121 virtual void SetClientReady() = 0;
122 122
123 // Tracing support - Recommend (but not required) to call this implementation 123 // Tracing support - Recommend (but not required) to call this implementation
124 // in any override. 124 // in any override.
125 virtual void AsValueInto(base::trace_event::TracedValue* dict) const = 0; 125 virtual void AsValueInto(base::trace_event::TracedValue* dict) const = 0;
126 }; 126 };
127 127
128 // Simple mix in which implements a BeginFrameSource. 128 // Simple base class which implements a BeginFrameSource.
129 // Implementation classes should: 129 // Implementation classes should:
130 // - Implement the pure virtual (Set)NeedsBeginFrames methods from 130 // - Implement the pure virtual (Set)NeedsBeginFrames methods from
131 // BeginFrameSource. 131 // BeginFrameSource.
132 // - Use the CallOnBeginFrame method to call to the observer(s). 132 // - Use the CallOnBeginFrame method to call to the observer(s).
133 // - Recommended (but not required) to call BeginFrameSourceMixIn::AsValueInto 133 // - Recommended (but not required) to call BeginFrameSourceBase::AsValueInto
134 // in their own AsValueInto implementation. 134 // in their own AsValueInto implementation.
135 class CC_EXPORT BeginFrameSourceMixIn : public BeginFrameSource { 135 class CC_EXPORT BeginFrameSourceBase : public BeginFrameSource {
136 public: 136 public:
137 ~BeginFrameSourceMixIn() override {} 137 ~BeginFrameSourceBase() override {}
138 138
139 // BeginFrameSource 139 // BeginFrameSource
140 bool NeedsBeginFrames() const final; 140 bool NeedsBeginFrames() const final;
141 void SetNeedsBeginFrames(bool needs_begin_frames) final; 141 void SetNeedsBeginFrames(bool needs_begin_frames) final;
142 void DidFinishFrame(size_t remaining_frames) override {} 142 void DidFinishFrame(size_t remaining_frames) override {}
143 void AddObserver(BeginFrameObserver* obs) final; 143 void AddObserver(BeginFrameObserver* obs) final;
144 void RemoveObserver(BeginFrameObserver* obs) final; 144 void RemoveObserver(BeginFrameObserver* obs) final;
145 void SetClientReady() override {} 145 void SetClientReady() override {}
146 146
147 // Tracing support - Recommend (but not required) to call this implementation 147 // Tracing support - Recommend (but not required) to call this implementation
148 // in any override. 148 // in any override.
149 void AsValueInto(base::trace_event::TracedValue* dict) const override; 149 void AsValueInto(base::trace_event::TracedValue* dict) const override;
150 150
151 protected: 151 protected:
152 BeginFrameSourceMixIn(); 152 BeginFrameSourceBase();
153 153
154 // These methods should be used by subclasses to make the call to the 154 // These methods should be used by subclasses to make the call to the
155 // observers. 155 // observers.
156 void CallOnBeginFrame(const BeginFrameArgs& args); 156 void CallOnBeginFrame(const BeginFrameArgs& args);
157 157
158 // This method should be overridden if you want to change some behaviour on 158 // This method should be overridden if you want to change some behaviour on
159 // needs_begin_frames change. 159 // needs_begin_frames change.
160 virtual void OnNeedsBeginFramesChange(bool needs_begin_frames) {} 160 virtual void OnNeedsBeginFramesChange(bool needs_begin_frames) {}
161 161
162 BeginFrameObserver* observer_; 162 BeginFrameObserver* observer_;
163 bool needs_begin_frames_; 163 bool needs_begin_frames_;
164 164
165 private: 165 private:
166 bool inside_as_value_into_; 166 bool inside_as_value_into_;
167 }; 167 };
168 168
169 // A frame source which calls BeginFrame (at the next possible time) as soon as 169 // A frame source which calls BeginFrame (at the next possible time) as soon as
170 // remaining frames reaches zero. 170 // remaining frames reaches zero.
171 class CC_EXPORT BackToBackBeginFrameSource : public BeginFrameSourceMixIn { 171 class CC_EXPORT BackToBackBeginFrameSource : public BeginFrameSourceBase {
172 public: 172 public:
173 static scoped_ptr<BackToBackBeginFrameSource> Create( 173 static scoped_ptr<BackToBackBeginFrameSource> Create(
174 base::SingleThreadTaskRunner* task_runner); 174 base::SingleThreadTaskRunner* task_runner);
175 ~BackToBackBeginFrameSource() override; 175 ~BackToBackBeginFrameSource() override;
176 176
177 // BeginFrameSource 177 // BeginFrameSource
178 void DidFinishFrame(size_t remaining_frames) override; 178 void DidFinishFrame(size_t remaining_frames) override;
179 179
180 // Tracing 180 // Tracing
181 void AsValueInto(base::trace_event::TracedValue* dict) const override; 181 void AsValueInto(base::trace_event::TracedValue* dict) const override;
182 182
183 protected: 183 protected:
184 explicit BackToBackBeginFrameSource( 184 explicit BackToBackBeginFrameSource(
185 base::SingleThreadTaskRunner* task_runner); 185 base::SingleThreadTaskRunner* task_runner);
186 virtual base::TimeTicks Now(); // Now overridable for testing 186 virtual base::TimeTicks Now(); // Now overridable for testing
187 187
188 base::SingleThreadTaskRunner* task_runner_; 188 base::SingleThreadTaskRunner* task_runner_;
189 189
190 bool send_begin_frame_posted_; 190 bool send_begin_frame_posted_;
191 191
192 // BeginFrameSourceMixIn 192 // BeginFrameSourceBase
193 void OnNeedsBeginFramesChange(bool needs_begin_frames) override; 193 void OnNeedsBeginFramesChange(bool needs_begin_frames) override;
194 194
195 void BeginFrame(); 195 void BeginFrame();
196 196
197 private: 197 private:
198 base::WeakPtrFactory<BackToBackBeginFrameSource> weak_factory_; 198 base::WeakPtrFactory<BackToBackBeginFrameSource> weak_factory_;
199 }; 199 };
200 200
201 // A frame source which is locked to an external parameters provides from a 201 // A frame source which is locked to an external parameters provides from a
202 // vsync source and generates BeginFrameArgs for it. 202 // vsync source and generates BeginFrameArgs for it.
203 class CC_EXPORT SyntheticBeginFrameSource : public BeginFrameSourceMixIn, 203 class CC_EXPORT SyntheticBeginFrameSource : public BeginFrameSourceBase,
204 public VSyncParameterObserver, 204 public VSyncParameterObserver,
205 public TimeSourceClient { 205 public TimeSourceClient {
206 public: 206 public:
207 static scoped_ptr<SyntheticBeginFrameSource> Create( 207 static scoped_ptr<SyntheticBeginFrameSource> Create(
208 base::SingleThreadTaskRunner* task_runner, 208 base::SingleThreadTaskRunner* task_runner,
209 base::TimeTicks initial_vsync_timebase, 209 base::TimeTicks initial_vsync_timebase,
210 base::TimeDelta initial_vsync_interval); 210 base::TimeDelta initial_vsync_interval);
211 ~SyntheticBeginFrameSource() override; 211 ~SyntheticBeginFrameSource() override;
212 212
213 // Tracing 213 // Tracing
214 void AsValueInto(base::trace_event::TracedValue* dict) const override; 214 void AsValueInto(base::trace_event::TracedValue* dict) const override;
215 215
216 // VSyncParameterObserver 216 // VSyncParameterObserver
217 void OnUpdateVSyncParameters(base::TimeTicks new_vsync_timebase, 217 void OnUpdateVSyncParameters(base::TimeTicks new_vsync_timebase,
218 base::TimeDelta new_vsync_interval) override; 218 base::TimeDelta new_vsync_interval) override;
219 219
220 // TimeSourceClient 220 // TimeSourceClient
221 void OnTimerTick() override; 221 void OnTimerTick() override;
222 222
223 protected: 223 protected:
224 explicit SyntheticBeginFrameSource( 224 explicit SyntheticBeginFrameSource(
225 scoped_refptr<DelayBasedTimeSource> time_source); 225 scoped_refptr<DelayBasedTimeSource> time_source);
226 226
227 BeginFrameArgs CreateBeginFrameArgs(base::TimeTicks frame_time, 227 BeginFrameArgs CreateBeginFrameArgs(base::TimeTicks frame_time,
228 BeginFrameArgs::BeginFrameArgsType type); 228 BeginFrameArgs::BeginFrameArgsType type);
229 229
230 // BeginFrameSourceMixIn 230 // BeginFrameSourceBase
231 void OnNeedsBeginFramesChange(bool needs_begin_frames) override; 231 void OnNeedsBeginFramesChange(bool needs_begin_frames) override;
232 232
233 scoped_refptr<DelayBasedTimeSource> time_source_; 233 scoped_refptr<DelayBasedTimeSource> time_source_;
234 }; 234 };
235 235
236 // A "virtual" frame source which lets you switch between multiple other frame 236 // A "virtual" frame source which lets you switch between multiple other frame
237 // sources while making sure the BeginFrameArgs stays increasing (possibly 237 // sources while making sure the BeginFrameArgs stays increasing (possibly
238 // enforcing minimum boundry between BeginFrameArgs messages). 238 // enforcing minimum boundry between BeginFrameArgs messages).
239 class CC_EXPORT BeginFrameSourceMultiplexer : public BeginFrameSourceMixIn, 239 class CC_EXPORT BeginFrameSourceMultiplexer : public BeginFrameSourceBase,
240 public BeginFrameObserver { 240 public BeginFrameObserver {
241 public: 241 public:
242 static scoped_ptr<BeginFrameSourceMultiplexer> Create(); 242 static scoped_ptr<BeginFrameSourceMultiplexer> Create();
243 ~BeginFrameSourceMultiplexer() override; 243 ~BeginFrameSourceMultiplexer() override;
244 244
245 void SetMinimumInterval(base::TimeDelta new_minimum_interval); 245 void SetMinimumInterval(base::TimeDelta new_minimum_interval);
246 246
247 void AddSource(BeginFrameSource* new_source); 247 void AddSource(BeginFrameSource* new_source);
248 void RemoveSource(BeginFrameSource* existing_source); 248 void RemoveSource(BeginFrameSource* existing_source);
249 void SetActiveSource(BeginFrameSource* new_source); 249 void SetActiveSource(BeginFrameSource* new_source);
250 const BeginFrameSource* ActiveSource(); 250 const BeginFrameSource* ActiveSource();
251 251
252 // BeginFrameObserver 252 // BeginFrameObserver
253 // The mux is an BeginFrameObserver as it needs to proxy the OnBeginFrame 253 // The mux is an BeginFrameObserver as it needs to proxy the OnBeginFrame
254 // calls to preserve the monotonicity of the BeginFrameArgs when switching 254 // calls to preserve the monotonicity of the BeginFrameArgs when switching
255 // sources. 255 // sources.
256 void OnBeginFrame(const BeginFrameArgs& args) override; 256 void OnBeginFrame(const BeginFrameArgs& args) override;
257 const BeginFrameArgs LastUsedBeginFrameArgs() const override; 257 const BeginFrameArgs LastUsedBeginFrameArgs() const override;
258 258
259 // BeginFrameSource 259 // BeginFrameSource
260 void DidFinishFrame(size_t remaining_frames) override; 260 void DidFinishFrame(size_t remaining_frames) override;
261 261
262 // BeginFrameSourceMixIn 262 // BeginFrameSourceBase
263 void OnNeedsBeginFramesChange(bool needs_begin_frames) override; 263 void OnNeedsBeginFramesChange(bool needs_begin_frames) override;
264 264
265 // Tracing 265 // Tracing
266 void AsValueInto(base::trace_event::TracedValue* dict) const override; 266 void AsValueInto(base::trace_event::TracedValue* dict) const override;
267 267
268 protected: 268 protected:
269 BeginFrameSourceMultiplexer(); 269 BeginFrameSourceMultiplexer();
270 explicit BeginFrameSourceMultiplexer(base::TimeDelta minimum_interval); 270 explicit BeginFrameSourceMultiplexer(base::TimeDelta minimum_interval);
271 271
272 bool HasSource(BeginFrameSource* source); 272 bool HasSource(BeginFrameSource* source);
273 bool IsIncreasing(const BeginFrameArgs& args); 273 bool IsIncreasing(const BeginFrameArgs& args);
274 274
275 base::TimeDelta minimum_interval_; 275 base::TimeDelta minimum_interval_;
276 276
277 BeginFrameSource* active_source_; 277 BeginFrameSource* active_source_;
278 std::set<BeginFrameSource*> source_list_; 278 std::set<BeginFrameSource*> source_list_;
279 }; 279 };
280 280
281 } // namespace cc 281 } // namespace cc
282 282
283 #endif // CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_ 283 #endif // CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_
OLDNEW
« no previous file with comments | « build/android/pylib/gtest/filter/cc_unittests_disabled ('k') | cc/scheduler/begin_frame_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698