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

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

Issue 2691453002: [cc] Track observer status in ExternalBeginFrameSource. (Closed)
Patch Set: Fix comments. 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') | no next file with comments »
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.
24 class CC_EXPORT BeginFrameObserver { 26 class CC_EXPORT BeginFrameObserver {
25 public: 27 public:
26 virtual ~BeginFrameObserver() {} 28 virtual ~BeginFrameObserver() {}
27 29
28 // The |args| given to OnBeginFrame is guaranteed to have 30 // The |args| given to OnBeginFrame is guaranteed to have
29 // |args|.IsValid()==true. If |args|.source_id did not change between 31 // |args|.IsValid()==true. If |args|.source_id did not change between
30 // invocations, |args|.sequence_number is guaranteed to be be strictly greater 32 // invocations, |args|.sequence_number is guaranteed to be be strictly greater
31 // than the previous call. Further, |args|.frame_time is guaranteed to be 33 // 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. 34 // greater than or equal to the previous call even if the source_id changes.
33 // 35 //
34 // Side effects: This function can (and most of the time *will*) change the 36 // Side effects: This function can (and most of the time *will*) change the
35 // return value of the LastUsedBeginFrameArgs method. See the documentation 37 // return value of the LastUsedBeginFrameArgs method. See the documentation
36 // on that method for more information. 38 // on that method for more information.
39 //
40 // The observer is required call BeginFrameSource::DidFinishFrame() as soon as
41 // it has completed handling the BeginFrame.
37 virtual void OnBeginFrame(const BeginFrameArgs& args) = 0; 42 virtual void OnBeginFrame(const BeginFrameArgs& args) = 0;
38 43
39 // Returns the last BeginFrameArgs used by the observer. This method's return 44 // Returns the last BeginFrameArgs used by the observer. This method's return
40 // value is affected by the OnBeginFrame method! 45 // value is affected by the OnBeginFrame method!
41 // 46 //
42 // - Before the first call of OnBeginFrame, this method should return a 47 // - Before the first call of OnBeginFrame, this method should return a
43 // BeginFrameArgs on which IsValid() returns false. 48 // BeginFrameArgs on which IsValid() returns false.
44 // 49 //
45 // - If the |args| passed to OnBeginFrame is (or *will be*) used, then 50 // - If the |args| passed to OnBeginFrame is (or *will be*) used, then
46 // LastUsedBeginFrameArgs return value should become the |args| given to 51 // LastUsedBeginFrameArgs return value should become the |args| given to
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 std::unique_ptr<DelayBasedTimeSource> time_source_; 228 std::unique_ptr<DelayBasedTimeSource> time_source_;
224 std::unordered_set<BeginFrameObserver*> observers_; 229 std::unordered_set<BeginFrameObserver*> observers_;
225 base::TimeTicks last_timebase_; 230 base::TimeTicks last_timebase_;
226 base::TimeDelta authoritative_interval_; 231 base::TimeDelta authoritative_interval_;
227 BeginFrameArgs current_begin_frame_args_; 232 BeginFrameArgs current_begin_frame_args_;
228 uint64_t next_sequence_number_; 233 uint64_t next_sequence_number_;
229 234
230 DISALLOW_COPY_AND_ASSIGN(DelayBasedBeginFrameSource); 235 DISALLOW_COPY_AND_ASSIGN(DelayBasedBeginFrameSource);
231 }; 236 };
232 237
238 // Helper class that tracks outstanding acknowledgments from
239 // BeginFrameObservers.
240 class CC_EXPORT BeginFrameObserverAckTracker {
241 public:
242 BeginFrameObserverAckTracker();
243 virtual ~BeginFrameObserverAckTracker();
244
245 // The BeginFrameSource uses these methods to notify us when a BeginFrame was
246 // started, an observer finished a frame, or an observer was added/removed.
247 void OnBeginFrame(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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698