Index: cc/scheduler/frame_source.h |
diff --git a/cc/scheduler/frame_source.h b/cc/scheduler/frame_source.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..047dea1feaa1a600dd147aff69d8dd0b0801c550 |
--- /dev/null |
+++ b/cc/scheduler/frame_source.h |
@@ -0,0 +1,218 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CC_SCHEDULER_FRAME_SOURCE_H_ |
+#define CC_SCHEDULER_FRAME_SOURCE_H_ |
+ |
+#include <string> |
+ |
+#include "base/debug/trace_event.h" |
+#include "base/logging.h" |
+#include "cc/output/begin_frame_args.h" |
+#include "cc/scheduler/delay_based_time_source.h" |
+#include "ui/gfx/frame_time.h" |
+ |
+namespace cc { |
+ |
+class CC_EXPORT BeginFrameSink { |
+ public: |
+ virtual void BeginFrame(const BeginFrameArgs& args) = 0; |
+}; |
+ |
+class CC_EXPORT BeginFrameSource { |
+ public: |
+ virtual void SetBeginFrameSink(BeginFrameSink* sink) = 0; |
+ virtual BeginFrameSink* GetBeginFrameSink() const = 0; |
+ |
+ virtual void SetGenerateFrames(bool generate_frames) = 0; |
+ virtual bool IsGeneratingFrames() const = 0; |
+ // This method allows a more grandular frame sink to provide backpressure to |
+ // a frame source rather then toggling SetGenerateFrames. It is used by |
+ // systems like the BackToBackFrameSource to make sure only one frame is |
+ // pending at a time. |
+ virtual void PendingFrames(size_t count) = 0; |
+ |
+ virtual void SetTimeBaseAndInterval(base::TimeTicks timebase, |
+ base::TimeDelta interval) = 0; |
+ virtual base::TimeTicks TimeBase() const = 0; |
+ virtual base::TimeDelta Interval() const = 0; |
+ |
+ virtual scoped_ptr<base::Value> BeginFrameSourceAsValue() const = 0; |
+ |
+ virtual ~BeginFrameSource() {} |
+}; |
+ |
+class CC_EXPORT BaseBeginFrameSource : public BeginFrameSource { |
+ public: |
+ virtual void SetBeginFrameSink(BeginFrameSink* sink) OVERRIDE; |
+ virtual BeginFrameSink* GetBeginFrameSink() const OVERRIDE; |
+ |
+ virtual void SetGenerateFrames(bool generate_frames) OVERRIDE; |
+ virtual bool IsGeneratingFrames() const OVERRIDE; |
+ virtual void PendingFrames(size_t count) OVERRIDE; |
+ |
+ virtual void SetTimeBaseAndInterval(base::TimeTicks timebase, |
+ base::TimeDelta interval) OVERRIDE; |
+ virtual base::TimeTicks TimeBase() const OVERRIDE; |
+ virtual base::TimeDelta Interval() const OVERRIDE; |
+ |
+ virtual scoped_ptr<base::Value> BeginFrameSourceAsValue() const OVERRIDE; |
+ |
+ virtual ~BaseBeginFrameSource() {} |
+ |
+ protected: |
+ BeginFrameSink* frame_sink_; |
+ bool generate_frames_; |
+ base::TimeTicks timebase_; |
+ base::TimeDelta interval_; |
+ |
+ explicit BaseBeginFrameSource(BeginFrameSink* sink); |
+ |
+ virtual std::string TypeString() const = 0; |
+ virtual void ExtraAsValue(base::DictionaryValue* state) const {} |
+ virtual void OnGenerateChange(bool generate_frames) {} |
+ virtual void OnPendingFrames(size_t count) {} |
+ virtual void OnTimeBaseAndIntervalChange(const base::TimeTicks timebase, |
+ const base::TimeDelta interval) {} |
+}; |
+ |
+/** |
+ * A frame source which proxies to / from a frame source we don't take |
+ * ownership of. |
+ */ |
+class CC_EXPORT ProxyBeginFrameSource : public BaseBeginFrameSource, |
+ public BeginFrameSink { |
+ public: |
+ // TODO(mithro): This should probably be a weakptr to the frame source |
+ // rather then a raw pointer. |
+ ProxyBeginFrameSource(BeginFrameSink* sink, BeginFrameSource* source); |
+ |
+ virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE; |
+ |
+ protected: |
+ BeginFrameSource* source_; |
+ |
+ // BaseBeginFrameSource |
+ virtual std::string TypeString() const OVERRIDE; |
+ virtual void ExtraAsValue(base::DictionaryValue* state) const OVERRIDE; |
+ virtual void OnGenerateChange(bool generate_frames) OVERRIDE; |
+ virtual void OnPendingFrames(size_t count) OVERRIDE; |
+ virtual void OnTimeBaseAndIntervalChange( |
+ const base::TimeTicks timebase, |
+ const base::TimeDelta interval) OVERRIDE; |
+}; |
+ |
+/** |
+ * A frame source which throttles down another begin frame source. |
+ */ |
+class CC_EXPORT ThrottledBeginFrameSource : public ProxyBeginFrameSource { |
+ public: |
+ ThrottledBeginFrameSource(BeginFrameSink* sink, |
+ BeginFrameSource* source, |
+ base::TimeDelta interval); |
+ |
+ // BeginFrameSink |
+ virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE; |
+ |
+ private: |
+ BeginFrameArgs last_frame_args_; |
+ |
+ // BaseBeginFrameSource |
+ virtual std::string TypeString() const OVERRIDE; |
+ virtual void ExtraAsValue(base::DictionaryValue* state) const OVERRIDE; |
+}; |
+ |
+/** |
+ * A frame source which sends a BeginFrame as soon as pending frames reaches |
+ * zero. |
+ */ |
+class CC_EXPORT BackToBackBeginFrameSource : public BaseBeginFrameSource { |
+ public: |
+ BackToBackBeginFrameSource(BeginFrameSink* sink, |
+ base::SingleThreadTaskRunner* task_runner); |
+ |
+ virtual void SendBeginFrameArgs(); |
+ |
+ protected: |
+ base::SingleThreadTaskRunner* task_runner_; |
+ bool send_begin_frame_posted_; |
+ |
+ void ScheduleSendBeginFrameArgs(); |
+ |
+ // BaseBeginFrameSource |
+ virtual std::string TypeString() const OVERRIDE; |
+ virtual void ExtraAsValue(base::DictionaryValue* state) const OVERRIDE; |
+ virtual void OnGenerateChange(bool generate_frames) OVERRIDE; |
+ virtual void OnPendingFrames(size_t count) OVERRIDE; |
+}; |
+ |
+/** |
+ * A frame source which is locked an external vsync source and generates |
+ * BeginFrameArgs for it. |
+ */ |
+class CC_EXPORT SyntheticBeginFrameSource : public BaseBeginFrameSource, |
+ public TimeSourceClient { |
+ public: |
+ SyntheticBeginFrameSource(BeginFrameSink* sink, |
+ base::SingleThreadTaskRunner* task_runner, |
+ base::TimeDelta interval); |
+ virtual ~SyntheticBeginFrameSource(); |
+ |
+ virtual void OnTimerTick() OVERRIDE; |
+ |
+ protected: |
+ base::SingleThreadTaskRunner* task_runner_; |
+ scoped_refptr<DelayBasedTimeSource> time_source_; |
+ |
+ BeginFrameArgs CreateBeginFrameArgs(base::TimeTicks frame_time); |
+ |
+ // BaseBeginFrameSource |
+ virtual std::string TypeString() const OVERRIDE; |
+ virtual void ExtraAsValue(base::DictionaryValue* state) const OVERRIDE; |
+ virtual void OnGenerateChange(bool generate_frames) OVERRIDE; |
+ virtual void OnTimeBaseAndIntervalChange( |
+ const base::TimeTicks timebase, |
+ const base::TimeDelta interval) OVERRIDE; |
+}; |
+ |
+/** |
+ * A virtual frame source which lets you switch between two other frame sources |
+ * (making sure the BeginFrameArgs stays monotonic). |
+ */ |
+class CC_EXPORT DualBeginFrameSource : public BaseBeginFrameSource, |
+ public BeginFrameSink { |
+ public: |
+ DualBeginFrameSource(BeginFrameSink* sink, |
+ scoped_ptr<BeginFrameSource> source_primary, |
+ scoped_ptr<BeginFrameSource> source_secondary); |
+ virtual ~DualBeginFrameSource(); |
+ |
+ // BeginFrameSink |
+ virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE; |
+ |
+ // --------------------------------------------------------------------- |
+ |
+ void SwitchSource(const BeginFrameSource* new_source); |
+ const BeginFrameSource* SourceForeground() const; |
+ const BeginFrameSource* SourceBackground() const; |
+ |
+ private: |
+ BeginFrameArgs last_frame_args_; |
+ BeginFrameSource* active_source_; |
+ scoped_ptr<BeginFrameSource> source_foreground_; |
+ scoped_ptr<BeginFrameSource> source_background_; |
+ |
+ // BaseBeginFrameSource |
+ virtual std::string TypeString() const OVERRIDE; |
+ virtual void ExtraAsValue(base::DictionaryValue* state) const OVERRIDE; |
+ virtual void OnGenerateChange(bool generate_frames) OVERRIDE; |
+ virtual void OnPendingFrames(size_t count) OVERRIDE; |
+ virtual void OnTimeBaseAndIntervalChange( |
+ const base::TimeTicks timebase, |
+ const base::TimeDelta interval) OVERRIDE; |
+}; |
+ |
+} // namespace cc |
+ |
+#endif // CC_SCHEDULER_FRAME_SOURCE_H_ |