OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CC_SCHEDULER_FRAME_SOURCE_H_ |
| 6 #define CC_SCHEDULER_FRAME_SOURCE_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/debug/trace_event.h" |
| 11 #include "base/logging.h" |
| 12 #include "cc/output/begin_frame_args.h" |
| 13 #include "cc/scheduler/delay_based_time_source.h" |
| 14 #include "ui/gfx/frame_time.h" |
| 15 |
| 16 namespace cc { |
| 17 |
| 18 class CC_EXPORT BeginFrameSink { |
| 19 public: |
| 20 virtual void BeginFrame(const BeginFrameArgs& args) = 0; |
| 21 }; |
| 22 |
| 23 class CC_EXPORT BeginFrameSource { |
| 24 public: |
| 25 virtual void SetBeginFrameSink(BeginFrameSink* sink) = 0; |
| 26 virtual BeginFrameSink* GetBeginFrameSink() const = 0; |
| 27 |
| 28 virtual void SetGenerateFrames(bool generate_frames) = 0; |
| 29 virtual bool IsGeneratingFrames() const = 0; |
| 30 // This method allows a more grandular frame sink to provide backpressure to |
| 31 // a frame source rather then toggling SetGenerateFrames. It is used by |
| 32 // systems like the BackToBackFrameSource to make sure only one frame is |
| 33 // pending at a time. |
| 34 virtual void PendingFrames(size_t count) = 0; |
| 35 |
| 36 virtual void SetTimeBaseAndInterval(base::TimeTicks timebase, |
| 37 base::TimeDelta interval) = 0; |
| 38 virtual base::TimeTicks TimeBase() const = 0; |
| 39 virtual base::TimeDelta Interval() const = 0; |
| 40 |
| 41 virtual scoped_ptr<base::Value> BeginFrameSourceAsValue() const = 0; |
| 42 |
| 43 virtual ~BeginFrameSource() {} |
| 44 }; |
| 45 |
| 46 class CC_EXPORT BaseBeginFrameSource : public BeginFrameSource { |
| 47 public: |
| 48 virtual void SetBeginFrameSink(BeginFrameSink* sink) OVERRIDE; |
| 49 virtual BeginFrameSink* GetBeginFrameSink() const OVERRIDE; |
| 50 |
| 51 virtual void SetGenerateFrames(bool generate_frames) OVERRIDE; |
| 52 virtual bool IsGeneratingFrames() const OVERRIDE; |
| 53 virtual void PendingFrames(size_t count) OVERRIDE; |
| 54 |
| 55 virtual void SetTimeBaseAndInterval(base::TimeTicks timebase, |
| 56 base::TimeDelta interval) OVERRIDE; |
| 57 virtual base::TimeTicks TimeBase() const OVERRIDE; |
| 58 virtual base::TimeDelta Interval() const OVERRIDE; |
| 59 |
| 60 virtual scoped_ptr<base::Value> BeginFrameSourceAsValue() const OVERRIDE; |
| 61 |
| 62 virtual ~BaseBeginFrameSource() {} |
| 63 |
| 64 protected: |
| 65 BeginFrameSink* frame_sink_; |
| 66 bool generate_frames_; |
| 67 base::TimeTicks timebase_; |
| 68 base::TimeDelta interval_; |
| 69 |
| 70 explicit BaseBeginFrameSource(BeginFrameSink* sink); |
| 71 |
| 72 virtual std::string TypeString() const = 0; |
| 73 virtual void ExtraAsValue(base::DictionaryValue* state) const {} |
| 74 virtual void OnGenerateChange(bool generate_frames) {} |
| 75 virtual void OnPendingFrames(size_t count) {} |
| 76 virtual void OnTimeBaseAndIntervalChange(const base::TimeTicks timebase, |
| 77 const base::TimeDelta interval) {} |
| 78 }; |
| 79 |
| 80 /** |
| 81 * A frame source which proxies to / from a frame source we don't take |
| 82 * ownership of. |
| 83 */ |
| 84 class CC_EXPORT ProxyBeginFrameSource : public BaseBeginFrameSource, |
| 85 public BeginFrameSink { |
| 86 public: |
| 87 // TODO(mithro): This should probably be a weakptr to the frame source |
| 88 // rather then a raw pointer. |
| 89 ProxyBeginFrameSource(BeginFrameSink* sink, BeginFrameSource* source); |
| 90 |
| 91 virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE; |
| 92 |
| 93 protected: |
| 94 BeginFrameSource* source_; |
| 95 |
| 96 // BaseBeginFrameSource |
| 97 virtual std::string TypeString() const OVERRIDE; |
| 98 virtual void ExtraAsValue(base::DictionaryValue* state) const OVERRIDE; |
| 99 virtual void OnGenerateChange(bool generate_frames) OVERRIDE; |
| 100 virtual void OnPendingFrames(size_t count) OVERRIDE; |
| 101 virtual void OnTimeBaseAndIntervalChange( |
| 102 const base::TimeTicks timebase, |
| 103 const base::TimeDelta interval) OVERRIDE; |
| 104 }; |
| 105 |
| 106 /** |
| 107 * A frame source which throttles down another begin frame source. |
| 108 */ |
| 109 class CC_EXPORT ThrottledBeginFrameSource : public ProxyBeginFrameSource { |
| 110 public: |
| 111 ThrottledBeginFrameSource(BeginFrameSink* sink, |
| 112 BeginFrameSource* source, |
| 113 base::TimeDelta interval); |
| 114 |
| 115 // BeginFrameSink |
| 116 virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE; |
| 117 |
| 118 private: |
| 119 BeginFrameArgs last_frame_args_; |
| 120 |
| 121 // BaseBeginFrameSource |
| 122 virtual std::string TypeString() const OVERRIDE; |
| 123 virtual void ExtraAsValue(base::DictionaryValue* state) const OVERRIDE; |
| 124 }; |
| 125 |
| 126 /** |
| 127 * A frame source which sends a BeginFrame as soon as pending frames reaches |
| 128 * zero. |
| 129 */ |
| 130 class CC_EXPORT BackToBackBeginFrameSource : public BaseBeginFrameSource { |
| 131 public: |
| 132 BackToBackBeginFrameSource(BeginFrameSink* sink, |
| 133 base::SingleThreadTaskRunner* task_runner); |
| 134 |
| 135 virtual void SendBeginFrameArgs(); |
| 136 |
| 137 protected: |
| 138 base::SingleThreadTaskRunner* task_runner_; |
| 139 bool send_begin_frame_posted_; |
| 140 |
| 141 void ScheduleSendBeginFrameArgs(); |
| 142 |
| 143 // BaseBeginFrameSource |
| 144 virtual std::string TypeString() const OVERRIDE; |
| 145 virtual void ExtraAsValue(base::DictionaryValue* state) const OVERRIDE; |
| 146 virtual void OnGenerateChange(bool generate_frames) OVERRIDE; |
| 147 virtual void OnPendingFrames(size_t count) OVERRIDE; |
| 148 }; |
| 149 |
| 150 /** |
| 151 * A frame source which is locked an external vsync source and generates |
| 152 * BeginFrameArgs for it. |
| 153 */ |
| 154 class CC_EXPORT SyntheticBeginFrameSource : public BaseBeginFrameSource, |
| 155 public TimeSourceClient { |
| 156 public: |
| 157 SyntheticBeginFrameSource(BeginFrameSink* sink, |
| 158 base::SingleThreadTaskRunner* task_runner, |
| 159 base::TimeDelta interval); |
| 160 virtual ~SyntheticBeginFrameSource(); |
| 161 |
| 162 virtual void OnTimerTick() OVERRIDE; |
| 163 |
| 164 protected: |
| 165 base::SingleThreadTaskRunner* task_runner_; |
| 166 scoped_refptr<DelayBasedTimeSource> time_source_; |
| 167 |
| 168 BeginFrameArgs CreateBeginFrameArgs(base::TimeTicks frame_time); |
| 169 |
| 170 // BaseBeginFrameSource |
| 171 virtual std::string TypeString() const OVERRIDE; |
| 172 virtual void ExtraAsValue(base::DictionaryValue* state) const OVERRIDE; |
| 173 virtual void OnGenerateChange(bool generate_frames) OVERRIDE; |
| 174 virtual void OnTimeBaseAndIntervalChange( |
| 175 const base::TimeTicks timebase, |
| 176 const base::TimeDelta interval) OVERRIDE; |
| 177 }; |
| 178 |
| 179 /** |
| 180 * A virtual frame source which lets you switch between two other frame sources |
| 181 * (making sure the BeginFrameArgs stays monotonic). |
| 182 */ |
| 183 class CC_EXPORT DualBeginFrameSource : public BaseBeginFrameSource, |
| 184 public BeginFrameSink { |
| 185 public: |
| 186 DualBeginFrameSource(BeginFrameSink* sink, |
| 187 scoped_ptr<BeginFrameSource> source_primary, |
| 188 scoped_ptr<BeginFrameSource> source_secondary); |
| 189 virtual ~DualBeginFrameSource(); |
| 190 |
| 191 // BeginFrameSink |
| 192 virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE; |
| 193 |
| 194 // --------------------------------------------------------------------- |
| 195 |
| 196 void SwitchSource(const BeginFrameSource* new_source); |
| 197 const BeginFrameSource* SourceForeground() const; |
| 198 const BeginFrameSource* SourceBackground() const; |
| 199 |
| 200 private: |
| 201 BeginFrameArgs last_frame_args_; |
| 202 BeginFrameSource* active_source_; |
| 203 scoped_ptr<BeginFrameSource> source_foreground_; |
| 204 scoped_ptr<BeginFrameSource> source_background_; |
| 205 |
| 206 // BaseBeginFrameSource |
| 207 virtual std::string TypeString() const OVERRIDE; |
| 208 virtual void ExtraAsValue(base::DictionaryValue* state) const OVERRIDE; |
| 209 virtual void OnGenerateChange(bool generate_frames) OVERRIDE; |
| 210 virtual void OnPendingFrames(size_t count) OVERRIDE; |
| 211 virtual void OnTimeBaseAndIntervalChange( |
| 212 const base::TimeTicks timebase, |
| 213 const base::TimeDelta interval) OVERRIDE; |
| 214 }; |
| 215 |
| 216 } // namespace cc |
| 217 |
| 218 #endif // CC_SCHEDULER_FRAME_SOURCE_H_ |
OLD | NEW |