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 <string> | |
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 FrameSink { | |
brianderson
2014/05/07 17:20:16
Please rename this BeginFrameSink so we have consi
mithro-old
2014/05/07 23:42:28
Done.
| |
19 public: | |
20 virtual void BeginFrame(const BeginFrameArgs& args) = 0; | |
21 }; | |
22 | |
23 class CC_EXPORT FrameSource { | |
brianderson
2014/05/07 17:20:16
Please rename this BeginFrameSource.
mithro-old
2014/05/07 23:42:28
Done.
| |
24 public: | |
25 virtual void SetNeedsBeginFrame(bool needs_begin_frame) = 0; | |
26 virtual void SetSink(FrameSink* sink) = 0; | |
27 virtual void SetTimeBaseAndInterval(base::TimeTicks timebase, | |
28 base::TimeDelta interval) = 0; | |
29 | |
30 virtual scoped_ptr<base::Value> FrameSourceAsValue() const = 0; | |
31 virtual inline std::string FrameSourceType() const = 0; | |
brianderson
2014/05/07 17:20:16
Is this for testing purposes? Can it be removed in
mithro-old
2014/05/07 22:02:32
Having which frame source is in use as part of the
| |
32 virtual ~FrameSource() {} | |
33 }; | |
34 | |
35 class CC_EXPORT BaseFrameSource : public FrameSource { | |
brianderson
2014/05/07 17:20:16
I need to think about this a bit. But can you prov
mithro-old
2014/05/07 23:42:28
The code BaseFrameSource saves is a relatively sma
| |
36 public: | |
37 virtual void SetNeedsBeginFrame(bool needs_begin_frame) = 0; | |
38 virtual void SetSink(FrameSink* sink) OVERRIDE; | |
39 virtual void SetTimeBaseAndInterval(base::TimeTicks timebase, | |
40 base::TimeDelta interval) OVERRIDE; | |
41 virtual scoped_ptr<base::Value> FrameSourceAsValue() const OVERRIDE; | |
42 | |
43 virtual inline std::string FrameSourceType() const = 0; | |
44 | |
45 virtual ~BaseFrameSource() {} | |
46 | |
47 protected: | |
48 base::TimeDelta interval_; | |
49 | |
50 scoped_ptr<base::DictionaryValue> BaseFrameSourceAsValue() const; | |
51 virtual void SendBeginFrame(const BeginFrameArgs& args); | |
52 | |
53 explicit BaseFrameSource(FrameSink* sink); | |
54 | |
55 private: | |
56 FrameSink* frame_sink_; | |
57 }; | |
58 | |
59 /** | |
60 * A frame source which proxies to / from a frame source we don't take | |
61 * ownership of. | |
62 */ | |
63 class CC_EXPORT ProxyFrameSource : public BaseFrameSource, public FrameSink { | |
brianderson
2014/05/07 17:20:16
This is getting a bit confusing for me to follow.
mithro-old
2014/05/07 22:02:32
The sole reason that ProxyFrameSource exists at th
brianderson
2014/05/08 00:55:58
I feel like there must be a solution to this probl
mithro-old
2014/05/09 02:45:58
This seems like mostly a style question?
I guess
| |
64 public: | |
65 // FIXME(mithro): This should probably be a weakptr to the frame source | |
66 // rather then a raw pointer. | |
67 ProxyFrameSource(FrameSink* sink, FrameSource* source); | |
68 | |
69 // FrameSource | |
70 virtual void SetNeedsBeginFrame(bool needs_begin_frame) OVERRIDE; | |
71 virtual scoped_ptr<base::Value> FrameSourceAsValue() const OVERRIDE; | |
72 virtual std::string FrameSourceType() const OVERRIDE; | |
73 virtual void SetTimeBaseAndInterval(base::TimeTicks timebase, | |
74 base::TimeDelta interval) OVERRIDE; | |
75 | |
76 // FrameSink | |
77 virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE; | |
78 | |
79 private: | |
80 FrameSource* source_; | |
81 }; | |
82 | |
83 /** | |
84 * A frame source which throttles down another begin frame source. | |
85 */ | |
86 class CC_EXPORT ThrottledFrameSource : public BaseFrameSource, | |
brianderson
2014/05/07 17:20:16
I was thinking about this more and think a wrapper
mithro-old
2014/05/07 23:42:28
I'm going to leave the ThrottledFrameSource here f
| |
87 public FrameSink { | |
88 public: | |
89 ThrottledFrameSource(FrameSink* sink, | |
90 scoped_ptr<FrameSource> source, | |
91 base::TimeDelta interval); | |
92 virtual ~ThrottledFrameSource(); | |
93 | |
94 // FrameSource | |
95 virtual void SetNeedsBeginFrame(bool needs_begin_frame) OVERRIDE; | |
96 virtual scoped_ptr<base::Value> FrameSourceAsValue() const OVERRIDE; | |
97 virtual std::string FrameSourceType() const OVERRIDE; | |
98 virtual void SetTimeBaseAndInterval(base::TimeTicks timebase, | |
99 base::TimeDelta interval) OVERRIDE; | |
100 | |
101 // FrameSink | |
102 virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE; | |
103 | |
104 private: | |
105 BeginFrameArgs last_frame_args_; | |
106 scoped_ptr<FrameSource> source_; | |
107 }; | |
108 | |
109 /** | |
110 * Frame source which needs a task runner object. | |
111 */ | |
112 class CC_EXPORT TaskRunnerFrameSource : public BaseFrameSource { | |
brianderson
2014/05/07 17:20:16
Does this extra level of inheritance buy us much?
mithro-old
2014/05/07 23:42:28
Not really - I thought there would be more shared
brianderson
2014/05/08 00:55:58
Please remove it unless you find there is a signif
mithro-old
2014/05/09 02:45:58
Done.
| |
113 public: | |
114 TaskRunnerFrameSource(FrameSink* sink, | |
115 base::SingleThreadTaskRunner* task_runner); | |
116 | |
117 protected: | |
118 base::SingleThreadTaskRunner* task_runner_; | |
119 }; | |
120 | |
121 /** | |
122 * A frame source which sends a BeginFrame as soon as SetNeedsBeginFrame is | |
123 * requested. | |
124 */ | |
125 class CC_EXPORT BackToBackFrameSource : public TaskRunnerFrameSource { | |
126 public: | |
127 BackToBackFrameSource(FrameSink* sink, | |
128 base::SingleThreadTaskRunner* task_runner); | |
129 | |
130 // FrameSource | |
131 virtual void SetNeedsBeginFrame(bool needs_begin_frame) OVERRIDE; | |
132 virtual std::string FrameSourceType() const OVERRIDE; | |
133 | |
134 // --------------------------------------------------------------------- | |
135 void PostBeginFrame(); | |
136 }; | |
137 | |
138 /** | |
139 * A frame source which is locked an external vsync source and generates | |
140 * BeginFrameArgs for it. | |
141 */ | |
142 class CC_EXPORT SyntheticFrameSource : public TaskRunnerFrameSource, | |
143 public TimeSourceClient { | |
144 public: | |
145 SyntheticFrameSource(FrameSink* sink, | |
146 base::SingleThreadTaskRunner* task_runner, | |
147 base::TimeDelta interval); | |
148 virtual ~SyntheticFrameSource(); | |
149 | |
150 // FrameSource | |
151 virtual void SetNeedsBeginFrame(bool needs_begin_frame) OVERRIDE; | |
152 virtual void SetTimeBaseAndInterval(base::TimeTicks timebase, | |
153 base::TimeDelta interval) OVERRIDE; | |
154 virtual scoped_ptr<base::Value> FrameSourceAsValue() const OVERRIDE; | |
155 virtual std::string FrameSourceType() const OVERRIDE; | |
156 | |
157 // --------------------------------------------------------------------- | |
158 | |
159 virtual void OnTimerTick() OVERRIDE; | |
160 | |
161 private: | |
162 scoped_refptr<TimeSource> time_source_; | |
163 | |
164 BeginFrameArgs CreateSyntheticBeginFrameArgs(base::TimeTicks frame_time); | |
165 }; | |
166 | |
167 /** | |
168 * A virtual frame source which lets you switch between two other frame sources | |
169 * (making sure the BeginFrameArgs stays monotonic). | |
170 */ | |
171 class CC_EXPORT DualFrameSource : public BaseFrameSource, public FrameSink { | |
brianderson
2014/05/07 17:20:16
Tim and I talked offline comparing this solution f
mithro-old
2014/05/07 23:42:28
We are currently
| |
172 public: | |
173 DualFrameSource(FrameSink* sink, | |
174 scoped_ptr<FrameSource> source_primary, | |
175 scoped_ptr<FrameSource> source_secondary); | |
176 virtual ~DualFrameSource(); | |
177 | |
178 // FrameSource | |
brianderson
2014/05/07 17:20:16
I think DualFrameSource needs to override SetTimeb
mithro-old
2014/05/07 22:02:32
Yes it does.
At the moment I think we want to for
brianderson
2014/05/08 00:55:58
To the primary source only sounds good.
mithro-old
2014/05/09 02:45:58
Done.
How do we set / change the interval for the
| |
179 virtual void SetNeedsBeginFrame(bool needs_begin_frame) OVERRIDE; | |
180 virtual scoped_ptr<base::Value> FrameSourceAsValue() const OVERRIDE; | |
181 virtual std::string FrameSourceType() const OVERRIDE; | |
182 | |
183 // FrameSink | |
184 virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE; | |
185 | |
186 // --------------------------------------------------------------------- | |
187 | |
188 void SwitchSource(const FrameSource* new_source); | |
189 const FrameSource* SourcePrimary() const; | |
190 const FrameSource* SourceSecondary() const; | |
brianderson
2014/05/07 17:20:16
Should we rename these to Foreground and Backgroun
mithro-old
2014/05/07 23:42:28
Done.
| |
191 | |
192 private: | |
193 bool needs_begin_frame_; | |
194 BeginFrameArgs last_frame_args_; | |
195 FrameSource* active_source_; | |
196 scoped_ptr<FrameSource> source_primary_; | |
197 scoped_ptr<FrameSource> source_secondary_; | |
198 }; | |
199 | |
200 } // namespace cc | |
201 | |
202 #endif // CC_SCHEDULER_FRAME_SOURCE_H_ | |
OLD | NEW |