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" | |
|
brianderson
2014/09/18 00:27:25
Don't think frame_time.h needs to be included in t
mithro-old
2014/09/18 13:33:37
Done.
| |
| 17 | |
| 18 namespace cc { | |
| 19 | |
| 20 /** | |
| 21 * | |
| 22 */ | |
| 23 class CC_EXPORT VSyncParameterObserver | |
|
brianderson
2014/09/18 00:27:25
Would it be less code to just use ui::CompositorVS
mithro-old
2014/09/18 13:33:37
Yeah, I think we can probably ditch this class now
| |
| 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() const = 0; | |
| 71 virtual void SetNeedsBeginFrames(bool needs_begin_frames) = 0; | |
| 72 // This method provides backpressure to a frame source rather then toggling | |
|
brianderson
2014/09/18 00:27:25
then -> than
mithro-old
2014/09/18 13:33:37
Done.
| |
| 73 // SetGenerateFrames. It is used by systems like the BackToBackFrameSource to | |
|
brianderson
2014/09/18 00:27:25
Don't think you need to reference SetGenerateFrame
mithro-old
2014/09/18 13:33:37
Done.
| |
| 74 // make sure only one frame is pending at a time. | |
| 75 virtual void DidFinishFrame(size_t remaining_frames) = 0; | |
| 76 | |
| 77 void AddObserver(BeginFrameObserver* obs); | |
| 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() const OVERRIDE; | |
| 105 virtual void SetNeedsBeginFrames(bool needs_begin_frames) OVERRIDE; | |
| 106 virtual void DidFinishFrame(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_ = false; | |
| 120 bool send_begin_frame_posted_ = false; | |
| 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::TimeTicks initial_vsync_timebase, | |
| 136 base::TimeDelta initial_vsync_interval); | |
| 137 virtual ~SyntheticBeginFrameSource(); | |
| 138 | |
| 139 // TimeSourceClient | |
| 140 virtual void OnTimerTick() OVERRIDE; | |
| 141 | |
| 142 // BeginFrameSource | |
| 143 virtual bool NeedsBeginFrames() const OVERRIDE; | |
| 144 virtual void SetNeedsBeginFrames(bool needs_begin_frames) OVERRIDE; | |
| 145 virtual void DidFinishFrame(size_t remaining_frames) OVERRIDE{}; | |
| 146 | |
| 147 // Tracing | |
| 148 virtual void AsValueInto(base::debug::TracedValue* dict) const OVERRIDE; | |
| 149 | |
| 150 protected: | |
| 151 SyntheticBeginFrameSource(scoped_refptr<DelayBasedTimeSource> time_source, | |
| 152 base::TimeTicks initial_vsync_timebase, | |
| 153 base::TimeDelta initial_vsync_interval); | |
| 154 | |
| 155 virtual void OnTimeBaseAndIntervalChange( | |
|
brianderson
2014/09/18 00:27:25
// VSyncParameterObserver
mithro-old
2014/09/18 13:33:37
Done.
| |
| 156 const base::TimeTicks new_vsync_timebase, | |
| 157 const base::TimeDelta new_vsync_interval) OVERRIDE; | |
| 158 | |
| 159 void SendBeginFrameFromTick(base::TimeTicks frame_time); | |
| 160 | |
| 161 scoped_refptr<DelayBasedTimeSource> time_source_; | |
| 162 }; | |
| 163 | |
| 164 /** | |
| 165 * A virtual frame source which lets you switch between multiple other frame | |
| 166 * sources while making sure the BeginFrameArgs stays increasing (possibly | |
| 167 * enforcing minimum boundry between BeginFrameArgs messages). | |
| 168 */ | |
| 169 class CC_EXPORT BeginFrameSourceMultiplexer : public BeginFrameSource, | |
| 170 public BeginFrameObserver { | |
| 171 public: | |
| 172 static scoped_ptr<BeginFrameSourceMultiplexer> Create(); | |
| 173 virtual ~BeginFrameSourceMultiplexer(); | |
| 174 | |
| 175 void SetMinimumInterval(base::TimeDelta new_minimum_interval); | |
| 176 | |
| 177 void AddSource(BeginFrameSource* new_source); | |
| 178 void RemoveSource(BeginFrameSource* existing_source); | |
| 179 void SetActiveSource(BeginFrameSource* new_source); | |
| 180 const BeginFrameSource* ActiveSource(); | |
| 181 | |
| 182 // BeginFrameObserver | |
|
brianderson
2014/09/18 00:27:25
It isn't immediately obvious why this needs to be
mithro-old
2014/09/18 13:33:37
Added comment.
| |
| 183 virtual void OnBeginFrame(const BeginFrameArgs& args) OVERRIDE; | |
| 184 virtual const BeginFrameArgs& LastBeginFrameArgs() const OVERRIDE; | |
| 185 | |
| 186 // BeginFrameSource | |
| 187 virtual bool NeedsBeginFrames() const OVERRIDE; | |
| 188 virtual void SetNeedsBeginFrames(bool needs_begin_frames) OVERRIDE; | |
| 189 virtual void DidFinishFrame(size_t remaining_frames) OVERRIDE; | |
| 190 | |
| 191 // Tracing | |
| 192 virtual void AsValueInto(base::debug::TracedValue* dict) const OVERRIDE; | |
| 193 | |
| 194 protected: | |
| 195 BeginFrameSourceMultiplexer(); | |
| 196 explicit BeginFrameSourceMultiplexer(base::TimeDelta minimum_interval); | |
| 197 bool HasSource(BeginFrameSource* source); | |
| 198 | |
| 199 base::TimeDelta minimum_interval_; | |
| 200 | |
| 201 BeginFrameSource* active_source_; | |
| 202 std::set<BeginFrameSource*> source_list_; | |
|
brianderson
2014/09/18 00:27:25
Since this class doesn't take ownership anymore, i
mithro-old
2014/09/18 13:33:37
I think having AddSource/RemoveSource/HasSource is
brianderson
2014/09/18 21:54:18
I don't feel strongly. Don't worry about NDEBUG.
mithro-old
2014/09/19 02:45:39
Actually, should these be some type of weak_ptr? I
| |
| 203 }; | |
| 204 | |
| 205 } // namespace cc | |
| 206 | |
| 207 #endif // CC_SCHEDULER_FRAME_SOURCE_H_ | |
| OLD | NEW |