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 |
11 #include <set> | 11 #include <set> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
17 #include "cc/output/begin_frame_args.h" | 17 #include "cc/output/begin_frame_args.h" |
18 #include "cc/scheduler/delay_based_time_source.h" | 18 #include "cc/scheduler/delay_based_time_source.h" |
19 | 19 |
20 namespace cc { | 20 namespace cc { |
21 | 21 |
22 // (Pure) Interface for observing BeginFrame messages from BeginFrameSource | 22 // (Pure) Interface for observing BeginFrame messages from BeginFrameSource |
23 // objects. | 23 // objects. |
24 class CC_EXPORT BeginFrameObserver { | 24 class CC_EXPORT BeginFrameObserver { |
25 public: | 25 public: |
26 virtual ~BeginFrameObserver() {} | 26 virtual ~BeginFrameObserver() {} |
27 | 27 |
28 // The |args| given to OnBeginFrame is guaranteed to have | 28 // The |args| given to OnBeginFrame is guaranteed to have |
29 // |args|.IsValid()==true and have |args|.frame_time | 29 // |args|.IsValid()==true. If |args|.source_id did not change between |
30 // field be strictly greater than the previous call. | 30 // invocations, |args|.sequence_number is guaranteed to be be strictly greater |
| 31 // than the previous call. Further, |args|.frame_time is guaranteed to be |
| 32 // greater than or equal to the previous call even if the source_id changes. |
31 // | 33 // |
32 // Side effects: This function can (and most of the time *will*) change the | 34 // Side effects: This function can (and most of the time *will*) change the |
33 // return value of the LastUsedBeginFrameArgs method. See the documentation | 35 // return value of the LastUsedBeginFrameArgs method. See the documentation |
34 // on that method for more information. | 36 // on that method for more information. |
35 virtual void OnBeginFrame(const BeginFrameArgs& args) = 0; | 37 virtual void OnBeginFrame(const BeginFrameArgs& args) = 0; |
36 | 38 |
37 // Returns the last BeginFrameArgs used by the observer. This method's return | 39 // Returns the last BeginFrameArgs used by the observer. This method's return |
38 // value is affected by the OnBeginFrame method! | 40 // value is affected by the OnBeginFrame method! |
39 // | 41 // |
40 // - Before the first call of OnBeginFrame, this method should return a | 42 // - Before the first call of OnBeginFrame, this method should return a |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 // BeginFrameObserver. | 94 // BeginFrameObserver. |
93 // | 95 // |
94 // BeginFrame calls *normally* occur just after a vsync interrupt when input | 96 // BeginFrame calls *normally* occur just after a vsync interrupt when input |
95 // processing has been finished and provide information about the time values | 97 // processing has been finished and provide information about the time values |
96 // of the vsync times. *However*, these values can be heavily modified or even | 98 // of the vsync times. *However*, these values can be heavily modified or even |
97 // plain made up (when no vsync signal is available or vsync throttling is | 99 // plain made up (when no vsync signal is available or vsync throttling is |
98 // turned off). See the BeginFrameObserver for information about the guarantees | 100 // turned off). See the BeginFrameObserver for information about the guarantees |
99 // all BeginFrameSources *must* provide. | 101 // all BeginFrameSources *must* provide. |
100 class CC_EXPORT BeginFrameSource { | 102 class CC_EXPORT BeginFrameSource { |
101 public: | 103 public: |
| 104 BeginFrameSource(); |
102 virtual ~BeginFrameSource() {} | 105 virtual ~BeginFrameSource() {} |
103 | 106 |
104 // DidFinishFrame provides back pressure to a frame source about frame | 107 // DidFinishFrame provides back pressure to a frame source about frame |
105 // processing (rather than toggling SetNeedsBeginFrames every frame). It is | 108 // processing (rather than toggling SetNeedsBeginFrames every frame). It is |
106 // used by systems like the BackToBackFrameSource to make sure only one frame | 109 // used by systems like the BackToBackFrameSource to make sure only one frame |
107 // is pending at a time. | 110 // is pending at a time. |
108 virtual void DidFinishFrame(BeginFrameObserver* obs, | 111 virtual void DidFinishFrame(BeginFrameObserver* obs, |
109 size_t remaining_frames) = 0; | 112 size_t remaining_frames) = 0; |
110 | 113 |
111 // Add/Remove an observer from the source. When no observers are added the BFS | 114 // Add/Remove an observer from the source. When no observers are added the BFS |
112 // should shut down its timers, disable vsync, etc. | 115 // should shut down its timers, disable vsync, etc. |
113 virtual void AddObserver(BeginFrameObserver* obs) = 0; | 116 virtual void AddObserver(BeginFrameObserver* obs) = 0; |
114 virtual void RemoveObserver(BeginFrameObserver* obs) = 0; | 117 virtual void RemoveObserver(BeginFrameObserver* obs) = 0; |
115 | 118 |
116 // Returns false if the begin frame source will just continue to produce | 119 // Returns false if the begin frame source will just continue to produce |
117 // begin frames without waiting. | 120 // begin frames without waiting. |
118 virtual bool IsThrottled() const = 0; | 121 virtual bool IsThrottled() const = 0; |
| 122 |
| 123 // Returns an identifier for this BeginFrameSource. Guaranteed unique within a |
| 124 // process, but not across processes. This is used to create BeginFrames that |
| 125 // originate at this source. Note that BeginFrameSources may pass on |
| 126 // BeginFrames created by other sources, with different IDs. |
| 127 uint32_t source_id() const; |
| 128 |
| 129 private: |
| 130 uint32_t source_id_; |
119 }; | 131 }; |
120 | 132 |
121 // A BeginFrameSource that does nothing. | 133 // A BeginFrameSource that does nothing. |
122 class CC_EXPORT StubBeginFrameSource : public BeginFrameSource { | 134 class CC_EXPORT StubBeginFrameSource : public BeginFrameSource { |
123 public: | 135 public: |
124 void DidFinishFrame(BeginFrameObserver* obs, | 136 void DidFinishFrame(BeginFrameObserver* obs, |
125 size_t remaining_frames) override {} | 137 size_t remaining_frames) override {} |
126 void AddObserver(BeginFrameObserver* obs) override {} | 138 void AddObserver(BeginFrameObserver* obs) override {} |
127 void RemoveObserver(BeginFrameObserver* obs) override {} | 139 void RemoveObserver(BeginFrameObserver* obs) override {} |
128 bool IsThrottled() const override; | 140 bool IsThrottled() const override; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 base::TimeDelta interval) override {} | 172 base::TimeDelta interval) override {} |
161 void SetAuthoritativeVSyncInterval(base::TimeDelta interval) override {} | 173 void SetAuthoritativeVSyncInterval(base::TimeDelta interval) override {} |
162 | 174 |
163 // DelayBasedTimeSourceClient implementation. | 175 // DelayBasedTimeSourceClient implementation. |
164 void OnTimerTick() override; | 176 void OnTimerTick() override; |
165 | 177 |
166 private: | 178 private: |
167 std::unique_ptr<DelayBasedTimeSource> time_source_; | 179 std::unique_ptr<DelayBasedTimeSource> time_source_; |
168 std::unordered_set<BeginFrameObserver*> observers_; | 180 std::unordered_set<BeginFrameObserver*> observers_; |
169 std::unordered_set<BeginFrameObserver*> pending_begin_frame_observers_; | 181 std::unordered_set<BeginFrameObserver*> pending_begin_frame_observers_; |
| 182 uint64_t next_sequence_number_; |
170 base::WeakPtrFactory<BackToBackBeginFrameSource> weak_factory_; | 183 base::WeakPtrFactory<BackToBackBeginFrameSource> weak_factory_; |
171 | 184 |
172 DISALLOW_COPY_AND_ASSIGN(BackToBackBeginFrameSource); | 185 DISALLOW_COPY_AND_ASSIGN(BackToBackBeginFrameSource); |
173 }; | 186 }; |
174 | 187 |
175 // A frame source which is locked to an external parameters provides from a | 188 // A frame source which is locked to an external parameters provides from a |
176 // vsync source and generates BeginFrameArgs for it. | 189 // vsync source and generates BeginFrameArgs for it. |
177 class CC_EXPORT DelayBasedBeginFrameSource : public SyntheticBeginFrameSource, | 190 class CC_EXPORT DelayBasedBeginFrameSource : public SyntheticBeginFrameSource, |
178 public DelayBasedTimeSourceClient { | 191 public DelayBasedTimeSourceClient { |
179 public: | 192 public: |
(...skipping 10 matching lines...) Expand all Loading... |
190 | 203 |
191 // SyntheticBeginFrameSource implementation. | 204 // SyntheticBeginFrameSource implementation. |
192 void OnUpdateVSyncParameters(base::TimeTicks timebase, | 205 void OnUpdateVSyncParameters(base::TimeTicks timebase, |
193 base::TimeDelta interval) override; | 206 base::TimeDelta interval) override; |
194 void SetAuthoritativeVSyncInterval(base::TimeDelta interval) override; | 207 void SetAuthoritativeVSyncInterval(base::TimeDelta interval) override; |
195 | 208 |
196 // DelayBasedTimeSourceClient implementation. | 209 // DelayBasedTimeSourceClient implementation. |
197 void OnTimerTick() override; | 210 void OnTimerTick() override; |
198 | 211 |
199 private: | 212 private: |
200 BeginFrameArgs CreateBeginFrameArgs(base::TimeTicks frame_time, | 213 BeginFrameArgs CreateBeginFrameArgs(uint64_t sequence_number, |
| 214 base::TimeTicks frame_time, |
201 BeginFrameArgs::BeginFrameArgsType type); | 215 BeginFrameArgs::BeginFrameArgsType type); |
202 | 216 |
203 std::unique_ptr<DelayBasedTimeSource> time_source_; | 217 std::unique_ptr<DelayBasedTimeSource> time_source_; |
204 std::unordered_set<BeginFrameObserver*> observers_; | 218 std::unordered_set<BeginFrameObserver*> observers_; |
205 base::TimeTicks last_timebase_; | 219 base::TimeTicks last_timebase_; |
206 base::TimeDelta authoritative_interval_; | 220 base::TimeDelta authoritative_interval_; |
| 221 BeginFrameArgs current_begin_frame_args_; |
207 | 222 |
208 DISALLOW_COPY_AND_ASSIGN(DelayBasedBeginFrameSource); | 223 DISALLOW_COPY_AND_ASSIGN(DelayBasedBeginFrameSource); |
209 }; | 224 }; |
210 | 225 |
211 class CC_EXPORT ExternalBeginFrameSourceClient { | 226 class CC_EXPORT ExternalBeginFrameSourceClient { |
212 public: | 227 public: |
213 // Only called when changed. Assumed false by default. | 228 // Only called when changed. Assumed false by default. |
214 virtual void OnNeedsBeginFrames(bool needs_begin_frames) = 0; | 229 virtual void OnNeedsBeginFrames(bool needs_begin_frames) = 0; |
215 }; | 230 }; |
216 | 231 |
(...skipping 23 matching lines...) Expand all Loading... |
240 ExternalBeginFrameSourceClient* client_; | 255 ExternalBeginFrameSourceClient* client_; |
241 bool paused_ = false; | 256 bool paused_ = false; |
242 | 257 |
243 private: | 258 private: |
244 DISALLOW_COPY_AND_ASSIGN(ExternalBeginFrameSource); | 259 DISALLOW_COPY_AND_ASSIGN(ExternalBeginFrameSource); |
245 }; | 260 }; |
246 | 261 |
247 } // namespace cc | 262 } // namespace cc |
248 | 263 |
249 #endif // CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_ | 264 #endif // CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_ |
OLD | NEW |