Chromium Code Reviews| 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 <set> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/debug/trace_event.h" | |
| 12 #include "base/logging.h" | |
| 13 #include "cc/output/begin_frame_args.h" | |
| 14 #include "cc/scheduler/delay_based_time_source.h" | |
| 15 #include "ui/compositor/compositor_vsync_manager.h" | |
| 16 #include "ui/gfx/frame_time.h" | |
| 17 | |
| 18 namespace cc { | |
| 19 | |
| 20 /** | |
| 21 * | |
| 22 */ | |
| 23 class CC_EXPORT VSyncObserverImpl | |
|
brianderson
2014/09/13 01:38:12
Maybe call this VSyncParameterObserver so it's cle
| |
| 24 : public ui::CompositorVSyncManager::Observer { | |
| 25 public: | |
| 26 VSyncObserverImpl(base::TimeTicks initial_vsync_timebase, | |
| 27 base::TimeDelta initial_vsync_interval); | |
| 28 virtual ~VSyncObserverImpl(); | |
| 29 | |
| 30 virtual void OnUpdateVSyncParameters( | |
| 31 base::TimeTicks new_vsync_timebase, | |
| 32 base::TimeDelta new_vsync_interval) OVERRIDE; | |
| 33 | |
| 34 virtual base::TimeTicks VSyncTimebase() const; | |
| 35 virtual base::TimeDelta VSyncInterval() const; | |
| 36 | |
| 37 // Tracing support | |
| 38 virtual void AsValueInto(base::debug::TracedValue* dict) const; | |
| 39 | |
| 40 protected: | |
| 41 virtual void OnTimeBaseAndIntervalChange( | |
| 42 const base::TimeTicks new_vsync_timebase, | |
| 43 const base::TimeDelta new_vsync_interval) {} | |
| 44 | |
| 45 private: | |
| 46 base::TimeTicks vsync_timebase_; | |
| 47 base::TimeDelta vsync_interval_; | |
| 48 }; | |
| 49 | |
| 50 /** | |
| 51 * | |
| 52 */ | |
| 53 class CC_EXPORT BeginFrameObserver { | |
| 54 public: | |
| 55 virtual const BeginFrameArgs& LastBeginFrameArgs() const = 0; | |
| 56 virtual void OnBeginFrame(const BeginFrameArgs& args) = 0; | |
| 57 | |
| 58 // Tracing support | |
| 59 virtual void AsValueInto(base::debug::TracedValue* dict) const = 0; | |
| 60 }; | |
| 61 | |
| 62 /* Allows multiple observers to be connected to a single BeginFrameSource. | |
| 63 class MultiBeginFrameObserver : public BeginFrameObserver { | |
| 64 public: | |
| 65 void AddObserver(BeginFrameObserver* obs) OVERRIDE { | |
| 66 observer_list_.AddObserver(obs); | |
| 67 } | |
| 68 void RemoveObserver(BeginFrameObserver* obs) OVERRIDE { | |
| 69 observer_list_.RemoveObserver(obs); | |
| 70 } | |
| 71 | |
| 72 virtual void OnBeginFrame(const BeginFrameArgs& args) OVERRIDE { | |
| 73 FOR_EACH_OBSERVER(BeginFrameObserver, observer_list_, OnBeginFrame(args)); | |
| 74 } | |
| 75 private: | |
| 76 ObserverList<BeginFrameObserver> observer_list_; | |
| 77 }; | |
| 78 */ | |
| 79 | |
| 80 /** | |
| 81 * | |
| 82 */ | |
| 83 class CC_EXPORT BeginFrameSource { | |
|
brianderson
2014/09/13 01:38:12
Would it make sense to split this into a BeginFram
| |
| 84 public: | |
| 85 virtual ~BeginFrameSource() {} | |
| 86 | |
| 87 // Should the frame source be sending begin frames? | |
| 88 virtual bool NeedsBeginFrames() = 0; | |
| 89 virtual void SetNeedsBeginFrames(bool needs_begin_frames) = 0; | |
| 90 // This method provides backpressure to a frame source rather then toggling | |
| 91 // SetGenerateFrames. It is used by systems like the BackToBackFrameSource to | |
| 92 // make sure only one frame is pending at a time. | |
| 93 virtual void FinishedFrame(size_t remaining_frames) = 0; | |
| 94 | |
| 95 void AddObserver(BeginFrameObserver* obs); | |
| 96 void RemoveObserver(BeginFrameObserver* obs); | |
| 97 | |
| 98 // Tracing support | |
| 99 virtual void AsValueInto(base::debug::TracedValue* dict) const = 0; | |
| 100 | |
| 101 protected: | |
| 102 void SendBeginFrame(const BeginFrameArgs& args); | |
| 103 BeginFrameObserver* observer_ = NULL; | |
| 104 }; | |
| 105 | |
| 106 /** | |
| 107 * A frame source which throttles down another begin frame source. | |
| 108 */ | |
| 109 class CC_EXPORT ThrottledBeginFrameSource : public BeginFrameSource, | |
|
brianderson
2014/09/13 01:38:13
Let's keep this class out of this patch and add it
| |
| 110 public BeginFrameObserver { | |
| 111 public: | |
| 112 static scoped_ptr<ThrottledBeginFrameSource> Create(base::TimeDelta interval); | |
| 113 virtual ~ThrottledBeginFrameSource(); | |
| 114 | |
| 115 void SetMinimumInterval(base::TimeDelta new_minimum_interval); | |
| 116 virtual void AddSource(BeginFrameSource* new_source); | |
| 117 virtual void RemoveSource(BeginFrameSource* new_source); | |
| 118 | |
| 119 // BeginFrameObserver | |
| 120 virtual void OnBeginFrame(const BeginFrameArgs& args) OVERRIDE; | |
| 121 virtual const BeginFrameArgs& LastBeginFrameArgs() const OVERRIDE; | |
| 122 | |
| 123 // BeginFrameSource | |
| 124 virtual bool NeedsBeginFrames() OVERRIDE; | |
| 125 virtual void SetNeedsBeginFrames(bool needs_begin_frames) OVERRIDE; | |
| 126 virtual void FinishedFrame(size_t remaining_frames) OVERRIDE; | |
| 127 | |
| 128 // Tracing | |
| 129 virtual void AsValueInto(base::debug::TracedValue* dict) const OVERRIDE; | |
| 130 | |
| 131 protected: | |
| 132 explicit ThrottledBeginFrameSource(base::TimeDelta interval); | |
| 133 | |
| 134 base::TimeDelta minimum_interval_; | |
| 135 BeginFrameSource* source_; | |
| 136 }; | |
| 137 | |
| 138 /** | |
| 139 * A frame source which sends a BeginFrame as soon as remaining frames reaches | |
| 140 * zero. | |
| 141 */ | |
| 142 class CC_EXPORT BackToBackBeginFrameSource : public BeginFrameSource { | |
| 143 public: | |
| 144 static scoped_ptr<BackToBackBeginFrameSource> Create( | |
| 145 base::SingleThreadTaskRunner* task_runner); | |
| 146 virtual ~BackToBackBeginFrameSource(); | |
| 147 | |
| 148 virtual void SendBeginFrameArgs(); | |
| 149 | |
| 150 // BeginFrameSource | |
| 151 virtual bool NeedsBeginFrames() OVERRIDE; | |
| 152 virtual void SetNeedsBeginFrames(bool needs_begin_frames) OVERRIDE; | |
| 153 virtual void FinishedFrame(size_t remaining_frames) OVERRIDE; | |
| 154 | |
| 155 // Tracing | |
| 156 virtual void AsValueInto(base::debug::TracedValue* dict) const OVERRIDE; | |
| 157 | |
| 158 protected: | |
| 159 explicit BackToBackBeginFrameSource( | |
| 160 base::SingleThreadTaskRunner* task_runner); | |
| 161 virtual base::TimeTicks Now(); // Now overridable for testing | |
| 162 | |
| 163 base::WeakPtrFactory<BackToBackBeginFrameSource> weak_factory_; | |
| 164 base::SingleThreadTaskRunner* task_runner_; | |
| 165 | |
| 166 bool needs_begin_frames_; | |
| 167 bool send_begin_frame_posted_; | |
| 168 | |
| 169 void ScheduleSendBeginFrameArgs(); | |
| 170 }; | |
| 171 | |
| 172 /** | |
| 173 * A frame source which is locked an external vsync source and generates | |
| 174 * BeginFrameArgs for it. | |
| 175 */ | |
| 176 class CC_EXPORT SyntheticBeginFrameSource : public BeginFrameSource, | |
| 177 public VSyncObserverImpl, | |
| 178 public TimeSourceClient { | |
| 179 public: | |
| 180 static scoped_ptr<SyntheticBeginFrameSource> Create( | |
| 181 base::SingleThreadTaskRunner* task_runner, | |
| 182 base::TimeDelta initial_vsync_interval); | |
| 183 virtual ~SyntheticBeginFrameSource(); | |
| 184 | |
| 185 // TimeSourceClient | |
| 186 virtual void OnTimerTick() OVERRIDE; | |
| 187 | |
| 188 // BeginFrameSource | |
| 189 virtual bool NeedsBeginFrames() OVERRIDE; | |
| 190 virtual void SetNeedsBeginFrames(bool needs_begin_frames) OVERRIDE; | |
| 191 virtual void FinishedFrame(size_t remaining_frames) OVERRIDE{}; | |
| 192 | |
| 193 // Tracing | |
| 194 virtual void AsValueInto(base::debug::TracedValue* dict) const OVERRIDE; | |
| 195 | |
| 196 protected: | |
| 197 SyntheticBeginFrameSource(scoped_refptr<DelayBasedTimeSource> time_source, | |
| 198 base::TimeTicks initial_vsync_timebase, | |
| 199 base::TimeDelta initial_vsync_interval); | |
| 200 | |
| 201 virtual void OnTimeBaseAndIntervalChange( | |
| 202 const base::TimeTicks new_vsync_timebase, | |
| 203 const base::TimeDelta new_vsync_interval) OVERRIDE; | |
| 204 | |
| 205 void SendBeginFrameFromTick(base::TimeTicks frame_time); | |
| 206 | |
| 207 scoped_refptr<DelayBasedTimeSource> time_source_; | |
| 208 }; | |
| 209 | |
| 210 /** | |
| 211 * A virtual frame source which lets you switch between multiple other frame | |
| 212 * sources while making sure the BeginFrameArgs stays increasing (possibly | |
| 213 * enforcing minimum boundry between BeginFrameArgs messages). | |
| 214 */ | |
| 215 class CC_EXPORT BeginFrameSourceMultiplexer : public ThrottledBeginFrameSource { | |
| 216 public: | |
| 217 static scoped_ptr<BeginFrameSourceMultiplexer> Create(); | |
| 218 virtual ~BeginFrameSourceMultiplexer(); | |
| 219 | |
| 220 void SetActiveSource(BeginFrameSource* new_source); | |
| 221 const BeginFrameSource* ActiveSource(); | |
| 222 | |
| 223 // ThrottledBeginFrameSource | |
| 224 virtual void AddSource(BeginFrameSource* new_source) OVERRIDE; | |
| 225 virtual void RemoveSource(BeginFrameSource* existing_source) OVERRIDE; | |
| 226 | |
| 227 // Tracing | |
| 228 virtual void AsValueInto(base::debug::TracedValue* dict) const OVERRIDE; | |
| 229 | |
| 230 protected: | |
| 231 BeginFrameSourceMultiplexer(); | |
| 232 explicit BeginFrameSourceMultiplexer(base::TimeDelta minimum_interval); | |
| 233 | |
| 234 private: | |
| 235 bool HasSource(BeginFrameSource* source); | |
| 236 std::set<BeginFrameSource*> source_list_; | |
| 237 }; | |
| 238 | |
| 239 } // namespace cc | |
| 240 | |
| 241 #endif // CC_SCHEDULER_FRAME_SOURCE_H_ | |
| OLD | NEW |