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

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

Issue 2819723002: cc: Add more info to the BeginMainFrame dump. (Closed)
Patch Set: more tracing Created 3 years, 8 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
« no previous file with comments | « no previous file | cc/scheduler/begin_frame_source.cc » ('j') | cc/scheduler/begin_frame_source.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 // required LastUsedBeginFrameArgs behaviour. 67 // required LastUsedBeginFrameArgs behaviour.
68 // 68 //
69 // Users of this class should; 69 // Users of this class should;
70 // - Implement the OnBeginFrameDerivedImpl function. 70 // - Implement the OnBeginFrameDerivedImpl function.
71 // - Recommended (but not required) to call 71 // - Recommended (but not required) to call
72 // BeginFrameObserverBase::OnValueInto in their overridden OnValueInto 72 // BeginFrameObserverBase::OnValueInto in their overridden OnValueInto
73 // function. 73 // function.
74 class CC_EXPORT BeginFrameObserverBase : public BeginFrameObserver { 74 class CC_EXPORT BeginFrameObserverBase : public BeginFrameObserver {
75 public: 75 public:
76 BeginFrameObserverBase(); 76 BeginFrameObserverBase();
77 ~BeginFrameObserverBase() override;
77 78
78 // BeginFrameObserver 79 // BeginFrameObserver
79 80
80 // Traces |args| and DCHECK |args| satisfies pre-conditions then calls 81 // Traces |args| and DCHECK |args| satisfies pre-conditions then calls
81 // OnBeginFrameDerivedImpl and updates the last_begin_frame_args_ value on 82 // OnBeginFrameDerivedImpl and updates the last_begin_frame_args_ value on
82 // true. 83 // true.
83 void OnBeginFrame(const BeginFrameArgs& args) override; 84 void OnBeginFrame(const BeginFrameArgs& args) override;
84 const BeginFrameArgs& LastUsedBeginFrameArgs() const override; 85 const BeginFrameArgs& LastUsedBeginFrameArgs() const override;
85 86
86 protected: 87 protected:
87 // Subclasses should override this method!
88 // Return true if the given argument is (or will be) used. 88 // Return true if the given argument is (or will be) used.
89 virtual bool OnBeginFrameDerivedImpl(const BeginFrameArgs& args) = 0; 89 virtual bool OnBeginFrameDerivedImpl(const BeginFrameArgs& args) = 0;
90 90
91 void AsValueInto(base::trace_event::TracedValue* state) const;
92
91 BeginFrameArgs last_begin_frame_args_; 93 BeginFrameArgs last_begin_frame_args_;
92 int64_t dropped_begin_frame_args_; 94 int64_t dropped_begin_frame_args_ = 0;
93 95
94 private: 96 private:
95 DISALLOW_COPY_AND_ASSIGN(BeginFrameObserverBase); 97 DISALLOW_COPY_AND_ASSIGN(BeginFrameObserverBase);
96 }; 98 };
97 99
98 // Interface for a class which produces BeginFrame calls to a 100 // Interface for a class which produces BeginFrame calls to a
99 // BeginFrameObserver. 101 // BeginFrameObserver.
100 // 102 //
101 // BeginFrame calls *normally* occur just after a vsync interrupt when input 103 // BeginFrame calls *normally* occur just after a vsync interrupt when input
102 // processing has been finished and provide information about the time values 104 // processing has been finished and provide information about the time values
103 // of the vsync times. *However*, these values can be heavily modified or even 105 // of the vsync times. *However*, these values can be heavily modified or even
104 // plain made up (when no vsync signal is available or vsync throttling is 106 // plain made up (when no vsync signal is available or vsync throttling is
105 // turned off). See the BeginFrameObserver for information about the guarantees 107 // turned off). See the BeginFrameObserver for information about the guarantees
106 // all BeginFrameSources *must* provide. 108 // all BeginFrameSources *must* provide.
107 class CC_EXPORT BeginFrameSource { 109 class CC_EXPORT BeginFrameSource {
108 public: 110 public:
109 BeginFrameSource(); 111 BeginFrameSource();
110 virtual ~BeginFrameSource() {} 112 virtual ~BeginFrameSource();
113
114 // Returns an identifier for this BeginFrameSource. Guaranteed unique within a
115 // process, but not across processes. This is used to create BeginFrames that
116 // originate at this source. Note that BeginFrameSources may pass on
117 // BeginFrames created by other sources, with different IDs.
118 uint32_t source_id() const { return source_id_; }
111 119
112 // BeginFrameObservers use DidFinishFrame to acknowledge that they have 120 // BeginFrameObservers use DidFinishFrame to acknowledge that they have
113 // completed handling a BeginFrame. 121 // completed handling a BeginFrame.
114 // 122 //
115 // The DisplayScheduler uses these acknowledgments to trigger an early 123 // The DisplayScheduler uses these acknowledgments to trigger an early
116 // deadline once all BeginFrameObservers have completed a frame. 124 // deadline once all BeginFrameObservers have completed a frame.
117 // 125 //
118 // They also provide back pressure to a frame source about frame processing 126 // They also provide back pressure to a frame source about frame processing
119 // (rather than toggling SetNeedsBeginFrames every frame). For example, the 127 // (rather than toggling SetNeedsBeginFrames every frame). For example, the
120 // BackToBackFrameSource uses them to make sure only one frame is pending at a 128 // BackToBackFrameSource uses them to make sure only one frame is pending at a
(...skipping 10 matching lines...) Expand all
131 139
132 // Add/Remove an observer from the source. When no observers are added the BFS 140 // Add/Remove an observer from the source. When no observers are added the BFS
133 // should shut down its timers, disable vsync, etc. 141 // should shut down its timers, disable vsync, etc.
134 virtual void AddObserver(BeginFrameObserver* obs) = 0; 142 virtual void AddObserver(BeginFrameObserver* obs) = 0;
135 virtual void RemoveObserver(BeginFrameObserver* obs) = 0; 143 virtual void RemoveObserver(BeginFrameObserver* obs) = 0;
136 144
137 // Returns false if the begin frame source will just continue to produce 145 // Returns false if the begin frame source will just continue to produce
138 // begin frames without waiting. 146 // begin frames without waiting.
139 virtual bool IsThrottled() const = 0; 147 virtual bool IsThrottled() const = 0;
140 148
141 // Returns an identifier for this BeginFrameSource. Guaranteed unique within a 149 virtual void AsValueInto(base::trace_event::TracedValue* state) const;
142 // process, but not across processes. This is used to create BeginFrames that
143 // originate at this source. Note that BeginFrameSources may pass on
144 // BeginFrames created by other sources, with different IDs.
145 uint32_t source_id() const;
146 150
147 private: 151 private:
148 uint32_t source_id_; 152 uint32_t source_id_;
153
154 DISALLOW_COPY_AND_ASSIGN(BeginFrameSource);
149 }; 155 };
150 156
151 // A BeginFrameSource that does nothing. 157 // A BeginFrameSource that does nothing.
152 class CC_EXPORT StubBeginFrameSource : public BeginFrameSource { 158 class CC_EXPORT StubBeginFrameSource : public BeginFrameSource {
153 public: 159 public:
154 void DidFinishFrame(BeginFrameObserver* obs, 160 void DidFinishFrame(BeginFrameObserver* obs,
155 const BeginFrameAck& ack) override {} 161 const BeginFrameAck& ack) override {}
156 void AddObserver(BeginFrameObserver* obs) override {} 162 void AddObserver(BeginFrameObserver* obs) override {}
157 void RemoveObserver(BeginFrameObserver* obs) override {} 163 void RemoveObserver(BeginFrameObserver* obs) override {}
158 bool IsThrottled() const override; 164 bool IsThrottled() const override;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 uint64_t next_sequence_number_; 245 uint64_t next_sequence_number_;
240 246
241 DISALLOW_COPY_AND_ASSIGN(DelayBasedBeginFrameSource); 247 DISALLOW_COPY_AND_ASSIGN(DelayBasedBeginFrameSource);
242 }; 248 };
243 249
244 // Helper class that tracks outstanding acknowledgments from 250 // Helper class that tracks outstanding acknowledgments from
245 // BeginFrameObservers. 251 // BeginFrameObservers.
246 class CC_EXPORT BeginFrameObserverAckTracker { 252 class CC_EXPORT BeginFrameObserverAckTracker {
247 public: 253 public:
248 BeginFrameObserverAckTracker(); 254 BeginFrameObserverAckTracker();
249 virtual ~BeginFrameObserverAckTracker(); 255 ~BeginFrameObserverAckTracker();
250 256
251 // The BeginFrameSource uses these methods to notify us when a BeginFrame was 257 // The BeginFrameSource uses these methods to notify us when a BeginFrame was
252 // started, an observer finished a frame, or an observer was added/removed. 258 // started, an observer finished a frame, or an observer was added/removed.
253 void OnBeginFrame(const BeginFrameArgs& args); 259 void OnBeginFrame(const BeginFrameArgs& args);
254 void OnObserverFinishedFrame(BeginFrameObserver* obs, 260 void OnObserverFinishedFrame(BeginFrameObserver* obs,
255 const BeginFrameAck& ack); 261 const BeginFrameAck& ack);
256 void OnObserverAdded(BeginFrameObserver* obs); 262 void OnObserverAdded(BeginFrameObserver* obs);
257 void OnObserverRemoved(BeginFrameObserver* obs); 263 void OnObserverRemoved(BeginFrameObserver* obs);
258 264
259 // Returns |true| if all the source's observers completed the current frame. 265 // Returns |true| if all the source's observers completed the current frame.
260 bool AllObserversFinishedFrame() const; 266 bool AllObserversFinishedFrame() const;
261 267
262 // Returns |true| if any observer had damage during the current frame. 268 // Returns |true| if any observer had damage during the current frame.
263 bool AnyObserversHadDamage() const; 269 bool AnyObserversHadDamage() const;
264 270
265 // Return the sequence number of the latest frame that all active observers 271 // Return the sequence number of the latest frame that all active observers
266 // have confirmed. 272 // have confirmed.
267 uint64_t LatestConfirmedSequenceNumber() const; 273 uint64_t LatestConfirmedSequenceNumber() const;
268 274
275 void AsValueInto(base::trace_event::TracedValue* state) const;
276
269 private: 277 private:
270 void SourceChanged(const BeginFrameArgs& args); 278 void SourceChanged(const BeginFrameArgs& args);
271 279
272 uint32_t current_source_id_; 280 uint32_t current_source_id_ = 0;
273 uint64_t current_sequence_number_; 281 uint64_t current_sequence_number_ = BeginFrameArgs::kStartingFrameNumber;
274 // Small sets, but order matters for intersection computation. 282 // Small sets, but order matters for intersection computation.
275 base::flat_set<BeginFrameObserver*> observers_; 283 base::flat_set<BeginFrameObserver*> observers_;
276 base::flat_set<BeginFrameObserver*> finished_observers_; 284 base::flat_set<BeginFrameObserver*> finished_observers_;
277 bool observers_had_damage_; 285 bool observers_had_damage_ = false;
278 base::SmallMap<std::map<BeginFrameObserver*, uint64_t>, 4> 286 base::SmallMap<std::map<BeginFrameObserver*, uint64_t>, 4>
279 latest_confirmed_sequence_numbers_; 287 latest_confirmed_sequence_numbers_;
288
289 DISALLOW_COPY_AND_ASSIGN(BeginFrameObserverAckTracker);
280 }; 290 };
281 291
282 class CC_EXPORT ExternalBeginFrameSourceClient { 292 class CC_EXPORT ExternalBeginFrameSourceClient {
283 public: 293 public:
284 // Only called when changed. Assumed false by default. 294 // Only called when changed. Assumed false by default.
285 virtual void OnNeedsBeginFrames(bool needs_begin_frames) = 0; 295 virtual void OnNeedsBeginFrames(bool needs_begin_frames) = 0;
286 // Called when all observers have completed a frame. 296 // Called when all observers have completed a frame.
287 virtual void OnDidFinishFrame(const BeginFrameAck& ack) = 0; 297 virtual void OnDidFinishFrame(const BeginFrameAck& ack) = 0;
288 }; 298 };
289 299
290 // A BeginFrameSource that is only ticked manually. Usually the endpoint 300 // A BeginFrameSource that is only ticked manually. Usually the endpoint
291 // of messages from some other thread/process that send OnBeginFrame and 301 // of messages from some other thread/process that send OnBeginFrame and
292 // receive SetNeedsBeginFrame messages. This turns such messages back into 302 // receive SetNeedsBeginFrame messages. This turns such messages back into
293 // an observable BeginFrameSource. 303 // an observable BeginFrameSource.
294 class CC_EXPORT ExternalBeginFrameSource : public BeginFrameSource { 304 class CC_EXPORT ExternalBeginFrameSource : public BeginFrameSource {
295 public: 305 public:
296 // Client lifetime must be preserved by owner past the lifetime of this class. 306 // Client lifetime must be preserved by owner past the lifetime of this class.
297 explicit ExternalBeginFrameSource(ExternalBeginFrameSourceClient* client); 307 explicit ExternalBeginFrameSource(ExternalBeginFrameSourceClient* client);
298 ~ExternalBeginFrameSource() override; 308 ~ExternalBeginFrameSource() override;
299 309
300 // BeginFrameSource implementation. 310 // BeginFrameSource implementation.
301 void AddObserver(BeginFrameObserver* obs) override; 311 void AddObserver(BeginFrameObserver* obs) override;
302 void RemoveObserver(BeginFrameObserver* obs) override; 312 void RemoveObserver(BeginFrameObserver* obs) override;
303 void DidFinishFrame(BeginFrameObserver* obs, 313 void DidFinishFrame(BeginFrameObserver* obs,
304 const BeginFrameAck& ack) override; 314 const BeginFrameAck& ack) override;
305 bool IsThrottled() const override; 315 bool IsThrottled() const override;
316 void AsValueInto(base::trace_event::TracedValue* state) const override;
306 317
307 void OnSetBeginFrameSourcePaused(bool paused); 318 void OnSetBeginFrameSourcePaused(bool paused);
308 void OnBeginFrame(const BeginFrameArgs& args); 319 void OnBeginFrame(const BeginFrameArgs& args);
309 320
310 protected: 321 protected:
311 void MaybeFinishFrame(); 322 void MaybeFinishFrame();
312 void FinishFrame(); 323 void FinishFrame();
313 324
314 BeginFrameArgs missed_begin_frame_args_; 325 BeginFrameArgs last_begin_frame_args_;
315 std::unordered_set<BeginFrameObserver*> observers_; 326 std::unordered_set<BeginFrameObserver*> observers_;
316 ExternalBeginFrameSourceClient* client_; 327 ExternalBeginFrameSourceClient* client_;
317 bool paused_ = false; 328 bool paused_ = false;
318 bool frame_active_ = false; 329 bool frame_active_ = false;
319 BeginFrameObserverAckTracker ack_tracker_; 330 BeginFrameObserverAckTracker ack_tracker_;
320 331
321 private: 332 private:
322 DISALLOW_COPY_AND_ASSIGN(ExternalBeginFrameSource); 333 DISALLOW_COPY_AND_ASSIGN(ExternalBeginFrameSource);
323 }; 334 };
324 335
325 } // namespace cc 336 } // namespace cc
326 337
327 #endif // CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_ 338 #endif // CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_
OLDNEW
« no previous file with comments | « no previous file | cc/scheduler/begin_frame_source.cc » ('j') | cc/scheduler/begin_frame_source.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698