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 VSyncParameterObserver | |
| 24 : public ui::CompositorVSyncManager::Observer { | |
| 25 public: | |
| 26 VSyncParameterObserver(base::TimeTicks initial_vsync_timebase, | |
| 27 base::TimeDelta initial_vsync_interval); | |
| 28 virtual ~VSyncParameterObserver(); | |
| 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 /** | |
| 63 * | |
| 64 */ | |
| 65 class CC_EXPORT BeginFrameSource { | |
| 66 public: | |
| 67 virtual ~BeginFrameSource() {} | |
| 68 | |
| 69 // Should the frame source be sending begin frames? | |
| 70 virtual bool NeedsBeginFrames() = 0; | |
|
Sami
2014/09/15 13:17:00
nit: Should be const.
| |
| 71 virtual void SetNeedsBeginFrames(bool needs_begin_frames) = 0; | |
| 72 // This method provides backpressure to a frame source rather then toggling | |
| 73 // SetGenerateFrames. It is used by systems like the BackToBackFrameSource to | |
| 74 // make sure only one frame is pending at a time. | |
| 75 virtual void FinishedFrame(size_t remaining_frames) = 0; | |
|
Sami
2014/09/15 13:17:00
nit: Call this something like DidFinishFrame() to
| |
| 76 | |
| 77 void AddObserver(BeginFrameObserver* obs); | |
|
Sami
2014/09/15 13:17:00
Should we call these SetObserver/ClearObserver sin
| |
| 78 void RemoveObserver(BeginFrameObserver* obs); | |
| 79 | |
| 80 // Tracing support | |
| 81 virtual void AsValueInto(base::debug::TracedValue* dict) const = 0; | |
| 82 | |
| 83 protected: | |
| 84 void SendBeginFrame(const BeginFrameArgs& args); | |
| 85 BeginFrameObserver* observer_ = NULL; | |
| 86 | |
| 87 private: | |
| 88 bool inside_as_value_into_ = false; | |
| 89 }; | |
| 90 | |
| 91 /** | |
| 92 * A frame source which sends a BeginFrame as soon as remaining frames reaches | |
| 93 * zero. | |
| 94 */ | |
| 95 class CC_EXPORT BackToBackBeginFrameSource : public BeginFrameSource { | |
| 96 public: | |
| 97 static scoped_ptr<BackToBackBeginFrameSource> Create( | |
| 98 base::SingleThreadTaskRunner* task_runner); | |
| 99 virtual ~BackToBackBeginFrameSource(); | |
| 100 | |
| 101 virtual void SendBeginFrameArgs(); | |
| 102 | |
| 103 // BeginFrameSource | |
| 104 virtual bool NeedsBeginFrames() OVERRIDE; | |
| 105 virtual void SetNeedsBeginFrames(bool needs_begin_frames) OVERRIDE; | |
| 106 virtual void FinishedFrame(size_t remaining_frames) OVERRIDE; | |
| 107 | |
| 108 // Tracing | |
| 109 virtual void AsValueInto(base::debug::TracedValue* dict) const OVERRIDE; | |
| 110 | |
| 111 protected: | |
| 112 explicit BackToBackBeginFrameSource( | |
| 113 base::SingleThreadTaskRunner* task_runner); | |
| 114 virtual base::TimeTicks Now(); // Now overridable for testing | |
| 115 | |
| 116 base::WeakPtrFactory<BackToBackBeginFrameSource> weak_factory_; | |
| 117 base::SingleThreadTaskRunner* task_runner_; | |
| 118 | |
| 119 bool needs_begin_frames_; | |
| 120 bool send_begin_frame_posted_; | |
| 121 | |
| 122 void ScheduleSendBeginFrameArgs(); | |
| 123 }; | |
| 124 | |
| 125 /** | |
| 126 * A frame source which is locked an external vsync source and generates | |
| 127 * BeginFrameArgs for it. | |
| 128 */ | |
| 129 class CC_EXPORT SyntheticBeginFrameSource : public BeginFrameSource, | |
| 130 public VSyncParameterObserver, | |
| 131 public TimeSourceClient { | |
| 132 public: | |
| 133 static scoped_ptr<SyntheticBeginFrameSource> Create( | |
| 134 base::SingleThreadTaskRunner* task_runner, | |
| 135 base::TimeDelta initial_vsync_interval); | |
| 136 virtual ~SyntheticBeginFrameSource(); | |
| 137 | |
| 138 // TimeSourceClient | |
| 139 virtual void OnTimerTick() OVERRIDE; | |
| 140 | |
| 141 // BeginFrameSource | |
| 142 virtual bool NeedsBeginFrames() OVERRIDE; | |
| 143 virtual void SetNeedsBeginFrames(bool needs_begin_frames) OVERRIDE; | |
| 144 virtual void FinishedFrame(size_t remaining_frames) OVERRIDE{}; | |
| 145 | |
| 146 // Tracing | |
| 147 virtual void AsValueInto(base::debug::TracedValue* dict) const OVERRIDE; | |
| 148 | |
| 149 protected: | |
| 150 SyntheticBeginFrameSource(scoped_refptr<DelayBasedTimeSource> time_source, | |
| 151 base::TimeTicks initial_vsync_timebase, | |
| 152 base::TimeDelta initial_vsync_interval); | |
| 153 | |
| 154 virtual void OnTimeBaseAndIntervalChange( | |
| 155 const base::TimeTicks new_vsync_timebase, | |
| 156 const base::TimeDelta new_vsync_interval) OVERRIDE; | |
| 157 | |
| 158 void SendBeginFrameFromTick(base::TimeTicks frame_time); | |
| 159 | |
| 160 scoped_refptr<DelayBasedTimeSource> time_source_; | |
| 161 }; | |
| 162 | |
| 163 /** | |
| 164 * A virtual frame source which lets you switch between multiple other frame | |
| 165 * sources while making sure the BeginFrameArgs stays increasing (possibly | |
| 166 * enforcing minimum boundry between BeginFrameArgs messages). | |
| 167 */ | |
| 168 class CC_EXPORT BeginFrameSourceMultiplexer : public BeginFrameSource, | |
| 169 public BeginFrameObserver { | |
| 170 public: | |
| 171 static scoped_ptr<BeginFrameSourceMultiplexer> Create(); | |
| 172 virtual ~BeginFrameSourceMultiplexer(); | |
| 173 | |
| 174 void SetMinimumInterval(base::TimeDelta new_minimum_interval); | |
| 175 | |
| 176 void AddSource(BeginFrameSource* new_source); | |
| 177 void RemoveSource(BeginFrameSource* existing_source); | |
| 178 void SetActiveSource(BeginFrameSource* new_source); | |
| 179 const BeginFrameSource* ActiveSource(); | |
| 180 | |
| 181 // BeginFrameObserver | |
| 182 virtual void OnBeginFrame(const BeginFrameArgs& args) OVERRIDE; | |
| 183 virtual const BeginFrameArgs& LastBeginFrameArgs() const OVERRIDE; | |
| 184 | |
| 185 // BeginFrameSource | |
| 186 virtual bool NeedsBeginFrames() OVERRIDE; | |
| 187 virtual void SetNeedsBeginFrames(bool needs_begin_frames) OVERRIDE; | |
| 188 virtual void FinishedFrame(size_t remaining_frames) OVERRIDE; | |
| 189 | |
| 190 // Tracing | |
| 191 virtual void AsValueInto(base::debug::TracedValue* dict) const OVERRIDE; | |
| 192 | |
| 193 protected: | |
| 194 BeginFrameSourceMultiplexer(); | |
| 195 explicit BeginFrameSourceMultiplexer(base::TimeDelta minimum_interval); | |
| 196 bool HasSource(BeginFrameSource* source); | |
| 197 | |
| 198 base::TimeDelta minimum_interval_; | |
| 199 | |
| 200 BeginFrameSource* active_source_; | |
| 201 std::set<BeginFrameSource*> source_list_; | |
| 202 }; | |
| 203 | |
| 204 } // namespace cc | |
| 205 | |
| 206 #endif // CC_SCHEDULER_FRAME_SOURCE_H_ | |
| OLD | NEW |