summaryrefslogtreecommitdiffstats
path: root/cc/scheduler/begin_frame_source.h
diff options
context:
space:
mode:
authorsunnyps <sunnyps@chromium.org>2016-02-02 12:53:54 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-02 20:54:44 +0000
commit6ab38e4f06caa13bbcdfaa652109d114576c1cbe (patch)
treef4598dab99df0df2f41b317c85e15129e91d236b /cc/scheduler/begin_frame_source.h
parentf6ce6c613ba8ea75fe56125dc67bac6f22454738 (diff)
downloadchromium_src-6ab38e4f06caa13bbcdfaa652109d114576c1cbe.zip
chromium_src-6ab38e4f06caa13bbcdfaa652109d114576c1cbe.tar.gz
chromium_src-6ab38e4f06caa13bbcdfaa652109d114576c1cbe.tar.bz2
cc: Add support for multiple observers to BeginFrameSource.
Multiple observers can be added to BeginFrameSource. The SetNeedsBeginFrames method was removed because it doesn't make sense with multiple observers. BeginFrameSources are expected to produce BeginFrames as long as there are registered observers. There are helper methods in BeginFrameSourceBase to make this easy. Changes had to be made to DelayBasedTimeSource as its MISSED BeginFrame logic was moved to SyntheticBFS for dealing with multiple observers. BUG=580352 CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel Review URL: https://codereview.chromium.org/1611633004 Cr-Commit-Position: refs/heads/master@{#373031}
Diffstat (limited to 'cc/scheduler/begin_frame_source.h')
-rw-r--r--cc/scheduler/begin_frame_source.h64
1 files changed, 30 insertions, 34 deletions
diff --git a/cc/scheduler/begin_frame_source.h b/cc/scheduler/begin_frame_source.h
index a77d546..0850884 100644
--- a/cc/scheduler/begin_frame_source.h
+++ b/cc/scheduler/begin_frame_source.h
@@ -58,7 +58,7 @@ class CC_EXPORT BeginFrameObserver {
// These requirements are designed to allow chaining and nesting of
// BeginFrameObservers which filter the incoming BeginFrame messages while
// preventing "double dropping" and other bad side effects.
- virtual const BeginFrameArgs LastUsedBeginFrameArgs() const = 0;
+ virtual const BeginFrameArgs& LastUsedBeginFrameArgs() const = 0;
virtual void OnBeginFrameSourcePausedChanged(bool paused) = 0;
@@ -85,7 +85,7 @@ class CC_EXPORT BeginFrameObserverBase : public BeginFrameObserver {
// OnBeginFrameDerivedImpl and updates the last_begin_frame_args_ value on
// true.
void OnBeginFrame(const BeginFrameArgs& args) override;
- const BeginFrameArgs LastUsedBeginFrameArgs() const override;
+ const BeginFrameArgs& LastUsedBeginFrameArgs() const override;
// Outputs last_begin_frame_args_
void AsValueInto(base::trace_event::TracedValue* dict) const override;
@@ -115,21 +115,14 @@ class CC_EXPORT BeginFrameSource {
public:
virtual ~BeginFrameSource() {}
- // SetNeedsBeginFrames is the on/off "switch" for the BeginFrameSource. When
- // set to false no more BeginFrame messages should be sent to observer.
- virtual bool NeedsBeginFrames() const = 0;
- virtual void SetNeedsBeginFrames(bool needs_begin_frames) = 0;
-
// DidFinishFrame provides back pressure to a frame source about frame
// processing (rather than toggling SetNeedsBeginFrames every frame). It is
// used by systems like the BackToBackFrameSource to make sure only one frame
// is pending at a time.
virtual void DidFinishFrame(size_t remaining_frames) = 0;
- // Add/Remove an observer from the source.
- // *At the moment* only a single observer can be added to the source, however
- // in the future this may be extended to allow multiple observers.
- // If making this change, please use base::ObserverList to do so.
+ // Add/Remove an observer from the source. When no observers are added the BFS
+ // should shut down its timers, disable vsync, etc.
virtual void AddObserver(BeginFrameObserver* obs) = 0;
virtual void RemoveObserver(BeginFrameObserver* obs) = 0;
@@ -150,14 +143,12 @@ class CC_EXPORT BeginFrameSource {
// in their own AsValueInto implementation.
class CC_EXPORT BeginFrameSourceBase : public BeginFrameSource {
public:
- ~BeginFrameSourceBase() override {}
+ ~BeginFrameSourceBase() override;
// BeginFrameSource
- bool NeedsBeginFrames() const final;
- void SetNeedsBeginFrames(bool needs_begin_frames) final;
void DidFinishFrame(size_t remaining_frames) override {}
- void AddObserver(BeginFrameObserver* obs) final;
- void RemoveObserver(BeginFrameObserver* obs) final;
+ void AddObserver(BeginFrameObserver* obs) override;
+ void RemoveObserver(BeginFrameObserver* obs) override;
void SetClientReady() override {}
// Tracing support - Recommend (but not required) to call this implementation
@@ -172,12 +163,13 @@ class CC_EXPORT BeginFrameSourceBase : public BeginFrameSource {
void CallOnBeginFrame(const BeginFrameArgs& args);
void SetBeginFrameSourcePaused(bool paused);
- // This method should be overridden if you want to change some behaviour on
- // needs_begin_frames change.
- virtual void OnNeedsBeginFramesChange(bool needs_begin_frames) {}
+ // This notifies that the subclass that it must turn on or off its mechnanism
+ // for producing BeginFrames.
+ virtual void OnNeedsBeginFramesChanged(bool needs_begin_frames) {}
+
+ bool needs_begin_frames() const { return !observers_.empty(); }
- BeginFrameObserver* observer_;
- bool needs_begin_frames_;
+ std::set<BeginFrameObserver*> observers_;
bool paused_;
private:
@@ -197,6 +189,10 @@ class CC_EXPORT BackToBackBeginFrameSource : public BeginFrameSourceBase {
// BeginFrameSource
void DidFinishFrame(size_t remaining_frames) override;
+ // BeginFrameSourceBase
+ void AddObserver(BeginFrameObserver* obs) override;
+ void OnNeedsBeginFramesChanged(bool needs_begin_frames) override;
+
// Tracing
void AsValueInto(base::trace_event::TracedValue* dict) const override;
@@ -206,12 +202,9 @@ class CC_EXPORT BackToBackBeginFrameSource : public BeginFrameSourceBase {
virtual base::TimeTicks Now(); // Now overridable for testing
base::SingleThreadTaskRunner* task_runner_;
+ base::CancelableClosure begin_frame_task_;
- bool send_begin_frame_posted_;
-
- // BeginFrameSourceBase
- void OnNeedsBeginFramesChange(bool needs_begin_frames) override;
-
+ void PostBeginFrame();
void BeginFrame();
private:
@@ -233,6 +226,10 @@ class CC_EXPORT SyntheticBeginFrameSource : public BeginFrameSourceBase,
void OnUpdateVSyncParameters(base::TimeTicks new_vsync_timebase,
base::TimeDelta new_vsync_interval);
+ // BeginFrameSourceBase
+ void AddObserver(BeginFrameObserver* obs) override;
+ void OnNeedsBeginFramesChanged(bool needs_begin_frames) override;
+
// Tracing
void AsValueInto(base::trace_event::TracedValue* dict) const override;
@@ -246,9 +243,6 @@ class CC_EXPORT SyntheticBeginFrameSource : public BeginFrameSourceBase,
BeginFrameArgs CreateBeginFrameArgs(base::TimeTicks frame_time,
BeginFrameArgs::BeginFrameArgsType type);
- // BeginFrameSourceBase
- void OnNeedsBeginFramesChange(bool needs_begin_frames) override;
-
scoped_ptr<DelayBasedTimeSource> time_source_;
private:
@@ -276,14 +270,13 @@ class CC_EXPORT BeginFrameSourceMultiplexer : public BeginFrameSourceBase,
// calls to preserve the monotonicity of the BeginFrameArgs when switching
// sources.
void OnBeginFrame(const BeginFrameArgs& args) override;
- const BeginFrameArgs LastUsedBeginFrameArgs() const override;
+ const BeginFrameArgs& LastUsedBeginFrameArgs() const override;
void OnBeginFrameSourcePausedChanged(bool paused) override;
- // BeginFrameSource
- void DidFinishFrame(size_t remaining_frames) override;
-
// BeginFrameSourceBase
- void OnNeedsBeginFramesChange(bool needs_begin_frames) override;
+ void DidFinishFrame(size_t remaining_frames) override;
+ void AddObserver(BeginFrameObserver* obs) override;
+ void OnNeedsBeginFramesChanged(bool needs_begin_frames) override;
// Tracing
void AsValueInto(base::trace_event::TracedValue* dict) const override;
@@ -300,6 +293,9 @@ class CC_EXPORT BeginFrameSourceMultiplexer : public BeginFrameSourceBase,
BeginFrameSource* active_source_;
std::set<BeginFrameSource*> source_list_;
+ BeginFrameArgs last_begin_frame_args_;
+ bool inside_add_observer_;
+
private:
DISALLOW_COPY_AND_ASSIGN(BeginFrameSourceMultiplexer);
};