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

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

Issue 267783004: Refactoring the way begin frame sources inside scheduler work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebasing onto master. Created 6 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 | Annotate | Revision Log
OLDNEW
(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>
brianderson 2014/06/17 06:24:43 Is this only needed for the TypeString? Can we jus
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;
brianderson 2014/06/17 06:24:43 Is GetBeginFrameSink needed for anything? Can we g
27
28 virtual void SetGenerateFrames(bool generate_frames) = 0;
brianderson 2014/06/17 06:24:42 Good idea using the 's' to signify a level request
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;
brianderson 2014/06/17 06:24:42 I think the unthrottled BeginFrame source is reall
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;
brianderson 2014/06/17 06:24:42 Not all BeginFrameSources necessarily need a TimeB
40
41 virtual scoped_ptr<base::Value> BeginFrameSourceAsValue() const = 0;
42
43 virtual ~BeginFrameSource() {}
44 };
45
46 class CC_EXPORT BaseBeginFrameSource : public BeginFrameSource {
brianderson 2014/06/17 06:24:42 This BaseBeginFrameSource makes understanding the
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_;
simonhong 2014/06/12 13:47:39 Variable declaration should be followed by Method
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 */
simonhong 2014/06/12 13:47:39 How about using // instead of /* */? Style guide s
84 class CC_EXPORT ProxyBeginFrameSource : public BaseBeginFrameSource,
brianderson 2014/06/17 06:24:43 I understand the desire to have the DualBeginFrame
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 virtual ~BackToBackBeginFrameSource();
135
136 virtual void SendBeginFrameArgs();
137
138 protected:
139 base::WeakPtrFactory<BackToBackBeginFrameSource> weak_factory_;
140 base::SingleThreadTaskRunner* task_runner_;
141 bool send_begin_frame_posted_;
142
143 void ScheduleSendBeginFrameArgs();
144
145 // BaseBeginFrameSource
146 virtual std::string TypeString() const OVERRIDE;
147 virtual void ExtraAsValue(base::DictionaryValue* state) const OVERRIDE;
148 virtual void OnGenerateChange(bool generate_frames) OVERRIDE;
149 virtual void OnPendingFrames(size_t count) OVERRIDE;
150 };
151
152 /**
153 * A frame source which is locked an external vsync source and generates
154 * BeginFrameArgs for it.
155 */
156 class CC_EXPORT SyntheticBeginFrameSource : public BaseBeginFrameSource,
157 public TimeSourceClient {
158 public:
159 SyntheticBeginFrameSource(BeginFrameSink* sink,
160 base::SingleThreadTaskRunner* task_runner,
161 base::TimeDelta interval);
162 virtual ~SyntheticBeginFrameSource();
163
164 virtual void OnTimerTick() OVERRIDE;
165
166 protected:
167 base::SingleThreadTaskRunner* task_runner_;
168 scoped_refptr<DelayBasedTimeSource> time_source_;
169
170 BeginFrameArgs CreateBeginFrameArgs(base::TimeTicks frame_time);
171
172 // BaseBeginFrameSource
173 virtual std::string TypeString() const OVERRIDE;
174 virtual void ExtraAsValue(base::DictionaryValue* state) const OVERRIDE;
175 virtual void OnGenerateChange(bool generate_frames) OVERRIDE;
176 virtual void OnTimeBaseAndIntervalChange(
177 const base::TimeTicks timebase,
178 const base::TimeDelta interval) OVERRIDE;
179 };
180
181 /**
182 * A virtual frame source which lets you switch between two other frame sources
183 * (making sure the BeginFrameArgs stays monotonic).
184 */
185 class CC_EXPORT DualBeginFrameSource : public BaseBeginFrameSource,
brianderson 2014/06/17 06:24:43 Do we need this class anymore since the background
186 public BeginFrameSink {
187 public:
188 DualBeginFrameSource(BeginFrameSink* sink,
189 scoped_ptr<BeginFrameSource> source_primary,
190 scoped_ptr<BeginFrameSource> source_secondary);
simonhong 2014/06/12 13:47:39 How about foreground_source and background_source?
191 virtual ~DualBeginFrameSource();
192
193 // BeginFrameSink
194 virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE;
195
196 // ---------------------------------------------------------------------
197
198 void SwitchSource(const BeginFrameSource* new_source);
199 const BeginFrameSource* SourceForeground() const;
200 const BeginFrameSource* SourceBackground() const;
simonhong 2014/06/12 13:47:39 How about ForegroundSource() and BackgroundSource(
201
202 private:
203 BeginFrameArgs last_frame_args_;
204 BeginFrameSource* active_source_;
205 scoped_ptr<BeginFrameSource> source_foreground_;
206 scoped_ptr<BeginFrameSource> source_background_;
simonhong 2014/06/12 13:47:39 How about foreground_source_ and background_source
207
208 // BaseBeginFrameSource
209 virtual std::string TypeString() const OVERRIDE;
210 virtual void ExtraAsValue(base::DictionaryValue* state) const OVERRIDE;
211 virtual void OnGenerateChange(bool generate_frames) OVERRIDE;
212 virtual void OnPendingFrames(size_t count) OVERRIDE;
213 virtual void OnTimeBaseAndIntervalChange(
214 const base::TimeTicks timebase,
215 const base::TimeDelta interval) OVERRIDE;
216 };
217
218 } // namespace cc
219
220 #endif // CC_SCHEDULER_FRAME_SOURCE_H_
OLDNEW
« no previous file with comments | « cc/cc_tests.gyp ('k') | cc/scheduler/frame_source.cc » ('j') | cc/scheduler/frame_source.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698