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

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

Issue 2691453002: [cc] Track observer status in ExternalBeginFrameSource. (Closed)
Patch Set: Fix android compile errors. Created 3 years, 10 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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 std::unique_ptr<DelayBasedTimeSource> time_source_; 223 std::unique_ptr<DelayBasedTimeSource> time_source_;
224 std::unordered_set<BeginFrameObserver*> observers_; 224 std::unordered_set<BeginFrameObserver*> observers_;
225 base::TimeTicks last_timebase_; 225 base::TimeTicks last_timebase_;
226 base::TimeDelta authoritative_interval_; 226 base::TimeDelta authoritative_interval_;
227 BeginFrameArgs current_begin_frame_args_; 227 BeginFrameArgs current_begin_frame_args_;
228 uint64_t next_sequence_number_; 228 uint64_t next_sequence_number_;
229 229
230 DISALLOW_COPY_AND_ASSIGN(DelayBasedBeginFrameSource); 230 DISALLOW_COPY_AND_ASSIGN(DelayBasedBeginFrameSource);
231 }; 231 };
232 232
233 // Helper class that tracks outstanding acknowledgments from
234 // BeginFrameObservers.
235 class CC_EXPORT BeginFrameObserverAckTracker {
236 public:
237 BeginFrameObserverAckTracker();
238 virtual ~BeginFrameObserverAckTracker();
239
240 // The BeginFrameSource uses these methods to notify us when a BeginFrame was
241 // started and sent to a specific observer, an observer finished a frame, or
242 // an observer was added/removed.
243 void OnBeginFrame(const BeginFrameArgs& args);
244 void OnObserverBeginFrame(BeginFrameObserver* obs,
245 const BeginFrameArgs& args);
246 void OnObserverFinishedFrame(BeginFrameObserver* obs,
247 const BeginFrameAck& ack);
248 void OnObserverAdded(BeginFrameObserver* obs);
249 void OnObserverRemoved(BeginFrameObserver* obs);
250
251 // Returns |true| if all the source's observers completed the current frame.
252 bool AllObserversFinishedFrame() const;
253
254 // Returns |true| if any observer had damage during the current frame.
255 bool AnyObserversHadDamage() const;
256
257 // Return the sequence number of the latest frame that all active observers
258 // have confirmed.
259 uint64_t LatestConfirmedSequenceNumber() const;
260
261 private:
262 void SourceChanged(const BeginFrameArgs& args);
263
264 uint32_t current_source_id_;
265 uint64_t current_sequence_number_;
266 std::set<BeginFrameObserver*> observers_;
Sami 2017/02/10 14:14:28 nit: unordered_set for both of these? edit: Ah, I
brianderson 2017/02/15 20:21:36 Probably would be good to add a comment explaining
enne (OOO) 2017/02/15 23:12:25 Maybe flat_set instead? (And SmallMap instead of u
Eric Seckler 2017/02/17 19:10:01 All of these collections are likely very small. Do
267 std::set<BeginFrameObserver*> finished_observers_;
268 bool observers_had_damage_;
269 std::unordered_map<BeginFrameObserver*, uint64_t>
270 latest_confirmed_sequence_numbers_;
271 };
272
233 class CC_EXPORT ExternalBeginFrameSourceClient { 273 class CC_EXPORT ExternalBeginFrameSourceClient {
234 public: 274 public:
235 // Only called when changed. Assumed false by default. 275 // Only called when changed. Assumed false by default.
236 virtual void OnNeedsBeginFrames(bool needs_begin_frames) = 0; 276 virtual void OnNeedsBeginFrames(bool needs_begin_frames) = 0;
277 // Called when all observers have completed a frame.
278 virtual void OnDidFinishFrame(const BeginFrameAck& ack) = 0;
237 }; 279 };
238 280
239 // A BeginFrameSource that is only ticked manually. Usually the endpoint 281 // A BeginFrameSource that is only ticked manually. Usually the endpoint
240 // of messages from some other thread/process that send OnBeginFrame and 282 // of messages from some other thread/process that send OnBeginFrame and
241 // receive SetNeedsBeginFrame messages. This turns such messages back into 283 // receive SetNeedsBeginFrame messages. This turns such messages back into
242 // an observable BeginFrameSource. 284 // an observable BeginFrameSource.
243 class CC_EXPORT ExternalBeginFrameSource : public BeginFrameSource { 285 class CC_EXPORT ExternalBeginFrameSource : public BeginFrameSource {
244 public: 286 public:
245 // Client lifetime must be preserved by owner past the lifetime of this class. 287 // Client lifetime must be preserved by owner past the lifetime of this class.
246 explicit ExternalBeginFrameSource(ExternalBeginFrameSourceClient* client); 288 explicit ExternalBeginFrameSource(ExternalBeginFrameSourceClient* client);
247 ~ExternalBeginFrameSource() override; 289 ~ExternalBeginFrameSource() override;
248 290
249 // BeginFrameSource implementation. 291 // BeginFrameSource implementation.
250 void AddObserver(BeginFrameObserver* obs) override; 292 void AddObserver(BeginFrameObserver* obs) override;
251 void RemoveObserver(BeginFrameObserver* obs) override; 293 void RemoveObserver(BeginFrameObserver* obs) override;
252 void DidFinishFrame(BeginFrameObserver* obs, 294 void DidFinishFrame(BeginFrameObserver* obs,
253 const BeginFrameAck& ack) override {} 295 const BeginFrameAck& ack) override;
254 bool IsThrottled() const override; 296 bool IsThrottled() const override;
255 297
256 void OnSetBeginFrameSourcePaused(bool paused); 298 void OnSetBeginFrameSourcePaused(bool paused);
257 void OnBeginFrame(const BeginFrameArgs& args); 299 void OnBeginFrame(const BeginFrameArgs& args);
258 300
259 protected: 301 protected:
302 void MaybeFinishFrame();
303 void FinishFrame();
304
260 BeginFrameArgs missed_begin_frame_args_; 305 BeginFrameArgs missed_begin_frame_args_;
261 std::unordered_set<BeginFrameObserver*> observers_; 306 std::unordered_set<BeginFrameObserver*> observers_;
262 ExternalBeginFrameSourceClient* client_; 307 ExternalBeginFrameSourceClient* client_;
263 bool paused_ = false; 308 bool paused_ = false;
309 bool frame_active_ = false;
310 BeginFrameObserverAckTracker ack_tracker_;
brianderson 2017/02/15 20:21:36 Are there any instances of the ExternalBeginFrameS
264 311
265 private: 312 private:
266 DISALLOW_COPY_AND_ASSIGN(ExternalBeginFrameSource); 313 DISALLOW_COPY_AND_ASSIGN(ExternalBeginFrameSource);
267 }; 314 };
268 315
269 } // namespace cc 316 } // namespace cc
270 317
271 #endif // CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_ 318 #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