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 <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
13 #include "cc/output/begin_frame_args.h" | 13 #include "cc/output/begin_frame_args.h" |
14 #include "cc/output/vsync_parameter_observer.h" | 14 #include "cc/output/vsync_parameter_observer.h" |
15 #include "cc/scheduler/delay_based_time_source.h" | 15 #include "cc/scheduler/delay_based_time_source.h" |
16 | 16 |
17 namespace cc { | 17 namespace cc { |
18 | 18 |
19 // (Pure) Interface for observing BeginFrame messages from BeginFrameSource | 19 // (Pure) Interface for observing BeginFrame messages from BeginFrameSource |
20 // objects. | 20 // objects. |
21 class CC_EXPORT BeginFrameObserver { | 21 class BeginFrameObserver { |
22 public: | 22 public: |
23 virtual ~BeginFrameObserver() {} | 23 virtual ~BeginFrameObserver() {} |
24 | 24 |
25 // The |args| given to OnBeginFrame is guaranteed to have | 25 // The |args| given to OnBeginFrame is guaranteed to have |
26 // |args|.IsValid()==true and have |args|.frame_time | 26 // |args|.IsValid()==true and have |args|.frame_time |
27 // field be strictly greater than the previous call. | 27 // field be strictly greater than the previous call. |
28 // | 28 // |
29 // Side effects: This function can (and most of the time *will*) change the | 29 // Side effects: This function can (and most of the time *will*) change the |
30 // return value of the LastUsedBeginFrameArgs method. See the documentation | 30 // return value of the LastUsedBeginFrameArgs method. See the documentation |
31 // on that method for more information. | 31 // on that method for more information. |
(...skipping 23 matching lines...) Expand all Loading... |
55 | 55 |
56 // Simple mix in which implements a BeginFrameObserver which checks the | 56 // Simple mix in 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 mix in should; |
61 // - Implement the OnBeginFrameMixInDelegate function. | 61 // - Implement the OnBeginFrameMixInDelegate function. |
62 // - Recommended (but not required) to call | 62 // - Recommended (but not required) to call |
63 // BeginFrameObserverMixIn::OnValueInto in their overridden OnValueInto | 63 // BeginFrameObserverMixIn::OnValueInto in their overridden OnValueInto |
64 // function. | 64 // function. |
65 class CC_EXPORT BeginFrameObserverMixIn : public BeginFrameObserver { | 65 class BeginFrameObserverMixIn : public BeginFrameObserver { |
66 public: | 66 public: |
67 BeginFrameObserverMixIn(); | 67 BeginFrameObserverMixIn(); |
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 // OnBeginFrameMixInDelegate 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; |
(...skipping 12 matching lines...) Expand all Loading... |
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 |
94 // of the vsync times. *However*, these values can be heavily modified or even | 94 // of the vsync times. *However*, these values can be heavily modified or even |
95 // plain made up (when no vsync signal is available or vsync throttling is | 95 // plain made up (when no vsync signal is available or vsync throttling is |
96 // turned off). See the BeginFrameObserver for information about the guarantees | 96 // turned off). See the BeginFrameObserver for information about the guarantees |
97 // all BeginFrameSources *must* provide. | 97 // all BeginFrameSources *must* provide. |
98 class CC_EXPORT BeginFrameSource { | 98 class BeginFrameSource { |
99 public: | 99 public: |
100 virtual ~BeginFrameSource() {} | 100 virtual ~BeginFrameSource() {} |
101 | 101 |
102 // SetNeedsBeginFrames is the on/off "switch" for the BeginFrameSource. When | 102 // SetNeedsBeginFrames is the on/off "switch" for the BeginFrameSource. When |
103 // set to false no more BeginFrame messages should be sent to observer. | 103 // set to false no more BeginFrame messages should be sent to observer. |
104 virtual bool NeedsBeginFrames() const = 0; | 104 virtual bool NeedsBeginFrames() const = 0; |
105 virtual void SetNeedsBeginFrames(bool needs_begin_frames) = 0; | 105 virtual void SetNeedsBeginFrames(bool needs_begin_frames) = 0; |
106 | 106 |
107 // DidFinishFrame provides back pressure to a frame source about frame | 107 // DidFinishFrame provides back pressure to a frame source about frame |
108 // processing (rather than toggling SetNeedsBeginFrames every frame). It is | 108 // processing (rather than toggling SetNeedsBeginFrames every frame). It is |
(...skipping 16 matching lines...) Expand all Loading... |
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 mix in 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 BeginFrameSourceMixIn::AsValueInto |
134 // in their own AsValueInto implementation. | 134 // in their own AsValueInto implementation. |
135 class CC_EXPORT BeginFrameSourceMixIn : public BeginFrameSource { | 135 class BeginFrameSourceMixIn : public BeginFrameSource { |
136 public: | 136 public: |
137 ~BeginFrameSourceMixIn() override {} | 137 ~BeginFrameSourceMixIn() 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 {} |
(...skipping 15 matching lines...) Expand all Loading... |
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 BackToBackBeginFrameSource : public BeginFrameSourceMixIn { |
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; |
(...skipping 11 matching lines...) Expand all Loading... |
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 SyntheticBeginFrameSource : public BeginFrameSourceMixIn, |
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 |
(...skipping 13 matching lines...) Expand all Loading... |
229 | 229 |
230 // BeginFrameSourceMixIn | 230 // BeginFrameSourceMixIn |
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 BeginFrameSourceMultiplexer : public BeginFrameSourceMixIn, |
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(); |
(...skipping 23 matching lines...) Expand all Loading... |
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_ |
OLD | NEW |