Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: cc/scheduler/begin_frame_source.h

Issue 2061273002: cc: Make BackToBackBeginFrameSource a SyntheticBeginFrameSource. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: syntheticbeginframesource: delete-DEBUG_FRAMES Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | cc/scheduler/begin_frame_source.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_ 5 #ifndef CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_
6 #define CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_ 6 #define CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <set> 11 #include <set>
12 #include <string> 12 #include <string>
13 13
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/trace_event/trace_event.h" 16 #include "base/trace_event/trace_event.h"
17 #include "cc/output/begin_frame_args.h" 17 #include "cc/output/begin_frame_args.h"
18 #include "cc/scheduler/delay_based_time_source.h" 18 #include "cc/scheduler/delay_based_time_source.h"
19 19
20 #ifdef NDEBUG
21 #define DEBUG_FRAMES(...)
22 #else
23 #define DEBUG_FRAMES(name, arg1_name, arg1_val, arg2_name, arg2_val) \
24 TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), name, \
25 arg1_name, arg1_val, arg2_name, arg2_val);
26 #endif
27
28 namespace cc { 20 namespace cc {
29 21
30 // (Pure) Interface for observing BeginFrame messages from BeginFrameSource 22 // (Pure) Interface for observing BeginFrame messages from BeginFrameSource
31 // objects. 23 // objects.
32 class CC_EXPORT BeginFrameObserver { 24 class CC_EXPORT BeginFrameObserver {
33 public: 25 public:
34 virtual ~BeginFrameObserver() {} 26 virtual ~BeginFrameObserver() {}
35 27
36 // The |args| given to OnBeginFrame is guaranteed to have 28 // The |args| given to OnBeginFrame is guaranteed to have
37 // |args|.IsValid()==true and have |args|.frame_time 29 // |args|.IsValid()==true and have |args|.frame_time
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 // is pending at a time. 107 // is pending at a time.
116 virtual void DidFinishFrame(BeginFrameObserver* obs, 108 virtual void DidFinishFrame(BeginFrameObserver* obs,
117 size_t remaining_frames) = 0; 109 size_t remaining_frames) = 0;
118 110
119 // Add/Remove an observer from the source. When no observers are added the BFS 111 // Add/Remove an observer from the source. When no observers are added the BFS
120 // should shut down its timers, disable vsync, etc. 112 // should shut down its timers, disable vsync, etc.
121 virtual void AddObserver(BeginFrameObserver* obs) = 0; 113 virtual void AddObserver(BeginFrameObserver* obs) = 0;
122 virtual void RemoveObserver(BeginFrameObserver* obs) = 0; 114 virtual void RemoveObserver(BeginFrameObserver* obs) = 0;
123 }; 115 };
124 116
125 // Simple base class which implements a BeginFrameSource. 117 // A frame source which ticks itself independently.
126 // Implementation classes should: 118 class CC_EXPORT SyntheticBeginFrameSource : public BeginFrameSource {
127 // - Implement the pure virtual (Set)NeedsBeginFrames methods from
128 // BeginFrameSource.
129 // - Use the CallOnBeginFrame method to call to the observer(s).
130 class CC_EXPORT BeginFrameSourceBase : public BeginFrameSource {
131 public: 119 public:
132 ~BeginFrameSourceBase() override; 120 ~SyntheticBeginFrameSource() override;
133 121
134 // BeginFrameSource 122 virtual void OnUpdateVSyncParameters(base::TimeTicks timebase,
135 void DidFinishFrame(BeginFrameObserver* obs, 123 base::TimeDelta interval) = 0;
136 size_t remaining_frames) override {} 124 // This overrides any past or future interval from updating vsync parameters.
137 void AddObserver(BeginFrameObserver* obs) override; 125 virtual void SetAuthoritativeVSyncInterval(base::TimeDelta interval) = 0;
138 void RemoveObserver(BeginFrameObserver* obs) override;
139
140 protected:
141 BeginFrameSourceBase();
142
143 // These methods should be used by subclasses to make the call to the
144 // observers.
145 void CallOnBeginFrame(const BeginFrameArgs& args);
146 void SetBeginFrameSourcePaused(bool paused);
147
148 // This notifies that the subclass that it must turn on or off its mechnanism
149 // for producing BeginFrames.
150 virtual void OnNeedsBeginFramesChanged(bool needs_begin_frames) {}
151
152 bool needs_begin_frames() const { return !observers_.empty(); }
153
154 std::set<BeginFrameObserver*> observers_;
155 bool paused_;
156
157 private:
158 DISALLOW_COPY_AND_ASSIGN(BeginFrameSourceBase);
159 }; 126 };
160 127
161 // A frame source which calls BeginFrame (at the next possible time) as soon as 128 // A frame source which calls BeginFrame (at the next possible time) as soon as
162 // remaining frames reaches zero. 129 // remaining frames reaches zero.
163 class CC_EXPORT BackToBackBeginFrameSource : public BeginFrameSourceBase { 130 class CC_EXPORT BackToBackBeginFrameSource : public SyntheticBeginFrameSource,
131 public DelayBasedTimeSourceClient {
164 public: 132 public:
165 explicit BackToBackBeginFrameSource( 133 explicit BackToBackBeginFrameSource(
166 base::SingleThreadTaskRunner* task_runner); 134 std::unique_ptr<DelayBasedTimeSource> time_source);
167 ~BackToBackBeginFrameSource() override; 135 ~BackToBackBeginFrameSource() override;
168 136
169 // BeginFrameSource 137 // BeginFrameSource implementation.
170 void AddObserver(BeginFrameObserver* obs) override; 138 void AddObserver(BeginFrameObserver* obs) override;
171 void RemoveObserver(BeginFrameObserver* obs) override; 139 void RemoveObserver(BeginFrameObserver* obs) override;
172 void DidFinishFrame(BeginFrameObserver* obs, 140 void DidFinishFrame(BeginFrameObserver* obs,
173 size_t remaining_frames) override; 141 size_t remaining_frames) override;
174 142
175 protected: 143 // SyntheticBeginFrameSource implementation.
176 virtual base::TimeTicks Now(); // Now overridable for testing 144 void OnUpdateVSyncParameters(base::TimeTicks timebase,
145 base::TimeDelta interval) override {}
146 void SetAuthoritativeVSyncInterval(base::TimeDelta interval) override {}
177 147
178 base::SingleThreadTaskRunner* task_runner_; 148 // DelayBasedTimeSourceClient implementation.
179 base::CancelableClosure begin_frame_task_; 149 void OnTimerTick() override;
180 std::set<BeginFrameObserver*> pending_begin_frame_observers_;
181
182 void PostPendingBeginFramesTask();
183 void SendPendingBeginFrames();
184 150
185 private: 151 private:
152 std::unique_ptr<DelayBasedTimeSource> time_source_;
153 std::unordered_set<BeginFrameObserver*> observers_;
154 std::unordered_set<BeginFrameObserver*> pending_begin_frame_observers_;
186 base::WeakPtrFactory<BackToBackBeginFrameSource> weak_factory_; 155 base::WeakPtrFactory<BackToBackBeginFrameSource> weak_factory_;
187 156
188 DISALLOW_COPY_AND_ASSIGN(BackToBackBeginFrameSource); 157 DISALLOW_COPY_AND_ASSIGN(BackToBackBeginFrameSource);
189 }; 158 };
190 159
191 // A frame source which is locked to an external parameters provides from a 160 // A frame source which is locked to an external parameters provides from a
192 // vsync source and generates BeginFrameArgs for it. 161 // vsync source and generates BeginFrameArgs for it.
193 class CC_EXPORT SyntheticBeginFrameSource : public BeginFrameSourceBase, 162 class CC_EXPORT DelayBasedBeginFrameSource : public SyntheticBeginFrameSource,
194 public DelayBasedTimeSourceClient { 163 public DelayBasedTimeSourceClient {
195 public: 164 public:
196 explicit SyntheticBeginFrameSource(base::SingleThreadTaskRunner* task_runner, 165 explicit DelayBasedBeginFrameSource(
197 base::TimeDelta initial_vsync_interval);
198 explicit SyntheticBeginFrameSource(
199 std::unique_ptr<DelayBasedTimeSource> time_source); 166 std::unique_ptr<DelayBasedTimeSource> time_source);
200 ~SyntheticBeginFrameSource() override; 167 ~DelayBasedBeginFrameSource() override;
201 168
169 // BeginFrameSource implementation.
170 void AddObserver(BeginFrameObserver* obs) override;
171 void RemoveObserver(BeginFrameObserver* obs) override;
172 void DidFinishFrame(BeginFrameObserver* obs,
173 size_t remaining_frames) override {}
174
175 // SyntheticBeginFrameSource implementation.
202 void OnUpdateVSyncParameters(base::TimeTicks timebase, 176 void OnUpdateVSyncParameters(base::TimeTicks timebase,
203 base::TimeDelta interval); 177 base::TimeDelta interval) override;
204 // This overrides any past or future interval from updating vsync parameters. 178 void SetAuthoritativeVSyncInterval(base::TimeDelta interval) override;
205 void SetAuthoritativeVSyncInterval(base::TimeDelta interval);
206 179
207 // BeginFrameSourceBase 180 // DelayBasedTimeSourceClient implementation.
208 void AddObserver(BeginFrameObserver* obs) override;
209 void OnNeedsBeginFramesChanged(bool needs_begin_frames) override;
210
211 // DelayBasedTimeSourceClient
212 void OnTimerTick() override; 181 void OnTimerTick() override;
213 182
214 protected: 183 private:
215 BeginFrameArgs CreateBeginFrameArgs(base::TimeTicks frame_time, 184 BeginFrameArgs CreateBeginFrameArgs(base::TimeTicks frame_time,
216 BeginFrameArgs::BeginFrameArgsType type); 185 BeginFrameArgs::BeginFrameArgsType type);
217 186
218 std::unique_ptr<DelayBasedTimeSource> time_source_; 187 std::unique_ptr<DelayBasedTimeSource> time_source_;
188 std::unordered_set<BeginFrameObserver*> observers_;
219 base::TimeTicks last_timebase_; 189 base::TimeTicks last_timebase_;
220 base::TimeDelta authoritative_interval_; 190 base::TimeDelta authoritative_interval_;
221 191
222 private: 192 DISALLOW_COPY_AND_ASSIGN(DelayBasedBeginFrameSource);
223 DISALLOW_COPY_AND_ASSIGN(SyntheticBeginFrameSource);
224 }; 193 };
225 194
226 } // namespace cc 195 } // namespace cc
227 196
228 #endif // CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_ 197 #endif // CC_SCHEDULER_BEGIN_FRAME_SOURCE_H_
OLDNEW
« no previous file with comments | « no previous file | cc/scheduler/begin_frame_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698