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

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

Issue 2691453002: [cc] Track observer status in ExternalBeginFrameSource. (Closed)
Patch Set: Use flat_set and SmallMap. 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
11 #include <set> 11 #include <set>
12 #include <string> 12 #include <string>
13 13
14 #include "base/containers/flat_set.h"
15 #include "base/containers/small_map.h"
14 #include "base/logging.h" 16 #include "base/logging.h"
15 #include "base/macros.h" 17 #include "base/macros.h"
16 #include "base/trace_event/trace_event.h" 18 #include "base/trace_event/trace_event.h"
17 #include "cc/output/begin_frame_args.h" 19 #include "cc/output/begin_frame_args.h"
18 #include "cc/scheduler/delay_based_time_source.h" 20 #include "cc/scheduler/delay_based_time_source.h"
19 21
20 namespace cc { 22 namespace cc {
21 23
22 // (Pure) Interface for observing BeginFrame messages from BeginFrameSource 24 // (Pure) Interface for observing BeginFrame messages from BeginFrameSource
23 // objects. 25 // objects.
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 std::unique_ptr<DelayBasedTimeSource> time_source_; 225 std::unique_ptr<DelayBasedTimeSource> time_source_;
224 std::unordered_set<BeginFrameObserver*> observers_; 226 std::unordered_set<BeginFrameObserver*> observers_;
225 base::TimeTicks last_timebase_; 227 base::TimeTicks last_timebase_;
226 base::TimeDelta authoritative_interval_; 228 base::TimeDelta authoritative_interval_;
227 BeginFrameArgs current_begin_frame_args_; 229 BeginFrameArgs current_begin_frame_args_;
228 uint64_t next_sequence_number_; 230 uint64_t next_sequence_number_;
229 231
230 DISALLOW_COPY_AND_ASSIGN(DelayBasedBeginFrameSource); 232 DISALLOW_COPY_AND_ASSIGN(DelayBasedBeginFrameSource);
231 }; 233 };
232 234
235 // Helper class that tracks outstanding acknowledgments from
236 // BeginFrameObservers.
237 class CC_EXPORT BeginFrameObserverAckTracker {
238 public:
239 BeginFrameObserverAckTracker();
240 virtual ~BeginFrameObserverAckTracker();
241
242 // The BeginFrameSource uses these methods to notify us when a BeginFrame was
243 // started and sent to a specific observer, an observer finished a frame, or
244 // an observer was added/removed.
245 void OnBeginFrame(const BeginFrameArgs& args);
246 void OnObserverBeginFrame(BeginFrameObserver* obs,
247 const BeginFrameArgs& args);
248 void OnObserverFinishedFrame(BeginFrameObserver* obs,
249 const BeginFrameAck& ack);
250 void OnObserverAdded(BeginFrameObserver* obs);
251 void OnObserverRemoved(BeginFrameObserver* obs);
252
253 // Returns |true| if all the source's observers completed the current frame.
254 bool AllObserversFinishedFrame() const;
255
256 // Returns |true| if any observer had damage during the current frame.
257 bool AnyObserversHadDamage() const;
258
259 // Return the sequence number of the latest frame that all active observers
260 // have confirmed.
261 uint64_t LatestConfirmedSequenceNumber() const;
262
263 private:
264 void SourceChanged(const BeginFrameArgs& args);
265
266 uint32_t current_source_id_;
267 uint64_t current_sequence_number_;
268 // Small sets, but order matters for intersection computation.
269 base::flat_set<BeginFrameObserver*> observers_;
270 base::flat_set<BeginFrameObserver*> finished_observers_;
271 bool observers_had_damage_;
272 base::SmallMap<std::map<BeginFrameObserver*, uint64_t>, 4>
273 latest_confirmed_sequence_numbers_;
274 };
275
233 class CC_EXPORT ExternalBeginFrameSourceClient { 276 class CC_EXPORT ExternalBeginFrameSourceClient {
234 public: 277 public:
235 // Only called when changed. Assumed false by default. 278 // Only called when changed. Assumed false by default.
236 virtual void OnNeedsBeginFrames(bool needs_begin_frames) = 0; 279 virtual void OnNeedsBeginFrames(bool needs_begin_frames) = 0;
280 // Called when all observers have completed a frame.
281 virtual void OnDidFinishFrame(const BeginFrameAck& ack) = 0;
237 }; 282 };
238 283
239 // A BeginFrameSource that is only ticked manually. Usually the endpoint 284 // A BeginFrameSource that is only ticked manually. Usually the endpoint
240 // of messages from some other thread/process that send OnBeginFrame and 285 // of messages from some other thread/process that send OnBeginFrame and
241 // receive SetNeedsBeginFrame messages. This turns such messages back into 286 // receive SetNeedsBeginFrame messages. This turns such messages back into
242 // an observable BeginFrameSource. 287 // an observable BeginFrameSource.
243 class CC_EXPORT ExternalBeginFrameSource : public BeginFrameSource { 288 class CC_EXPORT ExternalBeginFrameSource : public BeginFrameSource {
244 public: 289 public:
245 // Client lifetime must be preserved by owner past the lifetime of this class. 290 // Client lifetime must be preserved by owner past the lifetime of this class.
246 explicit ExternalBeginFrameSource(ExternalBeginFrameSourceClient* client); 291 explicit ExternalBeginFrameSource(ExternalBeginFrameSourceClient* client);
247 ~ExternalBeginFrameSource() override; 292 ~ExternalBeginFrameSource() override;
248 293
249 // BeginFrameSource implementation. 294 // BeginFrameSource implementation.
250 void AddObserver(BeginFrameObserver* obs) override; 295 void AddObserver(BeginFrameObserver* obs) override;
251 void RemoveObserver(BeginFrameObserver* obs) override; 296 void RemoveObserver(BeginFrameObserver* obs) override;
252 void DidFinishFrame(BeginFrameObserver* obs, 297 void DidFinishFrame(BeginFrameObserver* obs,
253 const BeginFrameAck& ack) override {} 298 const BeginFrameAck& ack) override;
254 bool IsThrottled() const override; 299 bool IsThrottled() const override;
255 300
256 void OnSetBeginFrameSourcePaused(bool paused); 301 void OnSetBeginFrameSourcePaused(bool paused);
257 void OnBeginFrame(const BeginFrameArgs& args); 302 void OnBeginFrame(const BeginFrameArgs& args);
258 303
259 protected: 304 protected:
305 void MaybeFinishFrame();
306 void FinishFrame();
307
260 BeginFrameArgs missed_begin_frame_args_; 308 BeginFrameArgs missed_begin_frame_args_;
261 std::unordered_set<BeginFrameObserver*> observers_; 309 std::unordered_set<BeginFrameObserver*> observers_;
262 ExternalBeginFrameSourceClient* client_; 310 ExternalBeginFrameSourceClient* client_;
263 bool paused_ = false; 311 bool paused_ = false;
312 bool frame_active_ = false;
313 BeginFrameObserverAckTracker ack_tracker_;
264 314
265 private: 315 private:
266 DISALLOW_COPY_AND_ASSIGN(ExternalBeginFrameSource); 316 DISALLOW_COPY_AND_ASSIGN(ExternalBeginFrameSource);
267 }; 317 };
268 318
269 } // namespace cc 319 } // namespace cc
270 320
271 #endif // CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_ 321 #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