OLD | NEW |
---|---|
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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_SCHEDULER_H_ | 5 #ifndef CC_SCHEDULER_SCHEDULER_H_ |
6 #define CC_SCHEDULER_SCHEDULER_H_ | 6 #define CC_SCHEDULER_SCHEDULER_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/cancelable_callback.h" | 12 #include "base/cancelable_callback.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "cc/base/cc_export.h" | 15 #include "cc/base/cc_export.h" |
16 #include "cc/output/begin_frame_args.h" | 16 #include "cc/output/begin_frame_args.h" |
17 #include "cc/scheduler/delay_based_time_source.h" | 17 #include "cc/scheduler/delay_based_time_source.h" |
18 #include "cc/scheduler/draw_result.h" | 18 #include "cc/scheduler/draw_result.h" |
19 #include "cc/scheduler/frame_source.h" | |
19 #include "cc/scheduler/scheduler_settings.h" | 20 #include "cc/scheduler/scheduler_settings.h" |
20 #include "cc/scheduler/scheduler_state_machine.h" | 21 #include "cc/scheduler/scheduler_state_machine.h" |
21 | 22 |
22 namespace base { | 23 namespace base { |
23 class SingleThreadTaskRunner; | 24 class SingleThreadTaskRunner; |
24 } | 25 } |
25 | 26 |
26 namespace cc { | 27 namespace cc { |
28 class Thread; | |
simonhong
2014/06/12 13:47:40
We don't need this.
| |
27 | 29 |
28 class SchedulerClient { | 30 class SchedulerClient { |
29 public: | 31 public: |
30 virtual void SetNeedsBeginFrame(bool enable) = 0; | |
31 virtual void WillBeginImplFrame(const BeginFrameArgs& args) = 0; | 32 virtual void WillBeginImplFrame(const BeginFrameArgs& args) = 0; |
32 virtual void ScheduledActionSendBeginMainFrame() = 0; | 33 virtual void ScheduledActionSendBeginMainFrame() = 0; |
33 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() = 0; | 34 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() = 0; |
34 virtual DrawResult ScheduledActionDrawAndSwapForced() = 0; | 35 virtual DrawResult ScheduledActionDrawAndSwapForced() = 0; |
35 virtual void ScheduledActionAnimate() = 0; | 36 virtual void ScheduledActionAnimate() = 0; |
36 virtual void ScheduledActionCommit() = 0; | 37 virtual void ScheduledActionCommit() = 0; |
37 virtual void ScheduledActionUpdateVisibleTiles() = 0; | 38 virtual void ScheduledActionUpdateVisibleTiles() = 0; |
38 virtual void ScheduledActionActivatePendingTree() = 0; | 39 virtual void ScheduledActionActivatePendingTree() = 0; |
39 virtual void ScheduledActionBeginOutputSurfaceCreation() = 0; | 40 virtual void ScheduledActionBeginOutputSurfaceCreation() = 0; |
40 virtual void ScheduledActionManageTiles() = 0; | 41 virtual void ScheduledActionManageTiles() = 0; |
41 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks time) = 0; | 42 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks time) = 0; |
42 virtual base::TimeDelta DrawDurationEstimate() = 0; | 43 virtual base::TimeDelta DrawDurationEstimate() = 0; |
43 virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() = 0; | 44 virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() = 0; |
44 virtual base::TimeDelta CommitToActivateDurationEstimate() = 0; | 45 virtual base::TimeDelta CommitToActivateDurationEstimate() = 0; |
45 virtual void DidBeginImplFrameDeadline() = 0; | 46 virtual void DidBeginImplFrameDeadline() = 0; |
46 | 47 |
47 protected: | 48 protected: |
48 virtual ~SchedulerClient() {} | 49 virtual ~SchedulerClient() {} |
49 }; | 50 }; |
50 | 51 |
51 class CC_EXPORT Scheduler { | 52 class CC_EXPORT Scheduler : public BeginFrameSink { |
52 public: | 53 public: |
53 static scoped_ptr<Scheduler> Create( | 54 static scoped_ptr<Scheduler> Create( |
54 SchedulerClient* client, | 55 SchedulerClient* client, |
55 const SchedulerSettings& scheduler_settings, | 56 const SchedulerSettings& scheduler_settings, |
56 int layer_tree_host_id, | 57 int layer_tree_host_id, |
58 BeginFrameSource* external_frame_source, | |
57 const scoped_refptr<base::SingleThreadTaskRunner>& impl_task_runner) { | 59 const scoped_refptr<base::SingleThreadTaskRunner>& impl_task_runner) { |
58 return make_scoped_ptr(new Scheduler( | 60 return make_scoped_ptr(new Scheduler(client, |
59 client, scheduler_settings, layer_tree_host_id, impl_task_runner)); | 61 scheduler_settings, |
62 layer_tree_host_id, | |
63 external_frame_source, | |
64 impl_task_runner)); | |
60 } | 65 } |
61 | 66 |
62 virtual ~Scheduler(); | 67 virtual ~Scheduler(); |
63 | 68 |
64 const SchedulerSettings& settings() const { return settings_; } | 69 const SchedulerSettings& settings() const { return settings_; } |
65 | 70 |
66 void CommitVSyncParameters(base::TimeTicks timebase, | 71 void CommitVSyncParameters(base::TimeTicks timebase, |
67 base::TimeDelta interval); | 72 base::TimeDelta interval); |
68 void SetEstimatedParentDrawTime(base::TimeDelta draw_time); | 73 void SetEstimatedParentDrawTime(base::TimeDelta draw_time); |
69 | 74 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 return !begin_impl_frame_deadline_task_.IsCancelled(); | 115 return !begin_impl_frame_deadline_task_.IsCancelled(); |
111 } | 116 } |
112 | 117 |
113 bool WillDrawIfNeeded() const; | 118 bool WillDrawIfNeeded() const; |
114 | 119 |
115 base::TimeTicks AnticipatedDrawTime() const; | 120 base::TimeTicks AnticipatedDrawTime() const; |
116 | 121 |
117 void NotifyBeginMainFrameStarted(); | 122 void NotifyBeginMainFrameStarted(); |
118 | 123 |
119 base::TimeTicks LastBeginImplFrameTime(); | 124 base::TimeTicks LastBeginImplFrameTime(); |
120 base::TimeDelta VSyncInterval() { return vsync_interval_; } | |
121 base::TimeDelta EstimatedParentDrawTime() { | 125 base::TimeDelta EstimatedParentDrawTime() { |
122 return estimated_parent_draw_time_; | 126 return estimated_parent_draw_time_; |
123 } | 127 } |
124 | 128 |
125 void BeginFrame(const BeginFrameArgs& args); | 129 virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE; |
simonhong
2014/06/12 13:47:40
Blank line is needed because this is overrided fro
| |
126 void PostBeginRetroFrame(); | 130 void PostBeginRetroFrame(); |
127 void BeginRetroFrame(); | 131 void BeginRetroFrame(); |
128 void BeginUnthrottledFrame(); | |
129 | 132 |
130 void BeginImplFrame(const BeginFrameArgs& args); | 133 void BeginImplFrame(const BeginFrameArgs& args); |
131 void OnBeginImplFrameDeadline(); | 134 void OnBeginImplFrameDeadline(); |
132 void PollForAnticipatedDrawTriggers(); | 135 void PollForAnticipatedDrawTriggers(); |
133 void PollToAdvanceCommitState(); | 136 void PollToAdvanceCommitState(); |
134 | 137 |
135 scoped_ptr<base::Value> AsValue() const; | 138 scoped_ptr<base::Value> AsValue() const; |
136 | 139 |
137 bool IsInsideAction(SchedulerStateMachine::Action action) { | 140 bool IsInsideAction(SchedulerStateMachine::Action action) { |
138 return inside_action_ == action; | 141 return inside_action_ == action; |
139 } | 142 } |
140 | 143 |
141 bool IsBeginMainFrameSent() const; | 144 bool IsBeginMainFrameSent() const; |
142 void SetContinuousPainting(bool continuous_painting) { | 145 void SetContinuousPainting(bool continuous_painting) { |
143 state_machine_.SetContinuousPainting(continuous_painting); | 146 state_machine_.SetContinuousPainting(continuous_painting); |
144 } | 147 } |
145 | 148 |
146 protected: | 149 protected: |
147 class CC_EXPORT SyntheticBeginFrameSource : public TimeSourceClient { | |
148 public: | |
149 SyntheticBeginFrameSource(Scheduler* scheduler, | |
150 base::SingleThreadTaskRunner* task_runner); | |
151 virtual ~SyntheticBeginFrameSource(); | |
152 | |
153 // Updates the phase and frequency of the timer. | |
154 void CommitVSyncParameters(base::TimeTicks timebase, | |
155 base::TimeDelta interval); | |
156 | |
157 // Activates future BeginFrames and, if activating, pushes the most | |
158 // recently missed BeginFrame to the back of a retroactive queue. | |
159 void SetNeedsBeginFrame(bool needs_begin_frame, | |
160 std::deque<BeginFrameArgs>* begin_retro_frame_args); | |
161 | |
162 bool IsActive() const; | |
163 | |
164 // TimeSourceClient implementation of OnTimerTick triggers a BeginFrame. | |
165 virtual void OnTimerTick() OVERRIDE; | |
166 | |
167 scoped_ptr<base::Value> AsValue() const; | |
168 | |
169 private: | |
170 BeginFrameArgs CreateSyntheticBeginFrameArgs(base::TimeTicks frame_time); | |
171 | |
172 Scheduler* scheduler_; | |
173 scoped_refptr<DelayBasedTimeSource> time_source_; | |
174 }; | |
175 | |
176 Scheduler( | 150 Scheduler( |
177 SchedulerClient* client, | 151 SchedulerClient* client, |
178 const SchedulerSettings& scheduler_settings, | 152 const SchedulerSettings& scheduler_settings, |
179 int layer_tree_host_id, | 153 int layer_tree_host_id, |
154 BeginFrameSource* external_frame_source, | |
180 const scoped_refptr<base::SingleThreadTaskRunner>& impl_task_runner); | 155 const scoped_refptr<base::SingleThreadTaskRunner>& impl_task_runner); |
181 | 156 |
182 const SchedulerSettings settings_; | 157 const SchedulerSettings settings_; |
183 SchedulerClient* client_; | 158 SchedulerClient* client_; |
184 int layer_tree_host_id_; | 159 int layer_tree_host_id_; |
185 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner_; | 160 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner_; |
186 | 161 |
187 base::TimeDelta vsync_interval_; | |
188 base::TimeDelta estimated_parent_draw_time_; | 162 base::TimeDelta estimated_parent_draw_time_; |
189 | 163 |
190 bool last_set_needs_begin_frame_; | |
191 bool begin_unthrottled_frame_posted_; | |
192 bool begin_retro_frame_posted_; | 164 bool begin_retro_frame_posted_; |
193 std::deque<BeginFrameArgs> begin_retro_frame_args_; | 165 std::deque<BeginFrameArgs> begin_retro_frame_args_; |
194 BeginFrameArgs begin_impl_frame_args_; | 166 BeginFrameArgs begin_impl_frame_args_; |
195 | 167 |
196 scoped_ptr<SyntheticBeginFrameSource> synthetic_begin_frame_source_; | 168 scoped_ptr<DualBeginFrameSource> frame_source_; |
197 | 169 |
198 base::Closure begin_retro_frame_closure_; | 170 base::Closure begin_retro_frame_closure_; |
199 base::Closure begin_unthrottled_frame_closure_; | 171 base::Closure begin_unthrottled_frame_closure_; |
200 | 172 |
201 base::Closure begin_impl_frame_deadline_closure_; | 173 base::Closure begin_impl_frame_deadline_closure_; |
202 base::Closure poll_for_draw_triggers_closure_; | 174 base::Closure poll_for_draw_triggers_closure_; |
203 base::Closure advance_commit_state_closure_; | 175 base::Closure advance_commit_state_closure_; |
204 base::CancelableClosure begin_impl_frame_deadline_task_; | 176 base::CancelableClosure begin_impl_frame_deadline_task_; |
205 base::CancelableClosure poll_for_draw_triggers_task_; | 177 base::CancelableClosure poll_for_draw_triggers_task_; |
206 base::CancelableClosure advance_commit_state_task_; | 178 base::CancelableClosure advance_commit_state_task_; |
(...skipping 10 matching lines...) Expand all Loading... | |
217 void SetupNextBeginFrameIfNeeded(); | 189 void SetupNextBeginFrameIfNeeded(); |
218 void PostBeginRetroFrameIfNeeded(); | 190 void PostBeginRetroFrameIfNeeded(); |
219 void SetupNextBeginFrameWhenVSyncThrottlingEnabled(bool needs_begin_frame); | 191 void SetupNextBeginFrameWhenVSyncThrottlingEnabled(bool needs_begin_frame); |
220 void SetupNextBeginFrameWhenVSyncThrottlingDisabled(bool needs_begin_frame); | 192 void SetupNextBeginFrameWhenVSyncThrottlingDisabled(bool needs_begin_frame); |
221 void SetupPollingMechanisms(bool needs_begin_frame); | 193 void SetupPollingMechanisms(bool needs_begin_frame); |
222 void DrawAndSwapIfPossible(); | 194 void DrawAndSwapIfPossible(); |
223 void ProcessScheduledActions(); | 195 void ProcessScheduledActions(); |
224 bool CanCommitAndActivateBeforeDeadline() const; | 196 bool CanCommitAndActivateBeforeDeadline() const; |
225 void AdvanceCommitStateIfPossible(); | 197 void AdvanceCommitStateIfPossible(); |
226 bool IsBeginMainFrameSentOrStarted() const; | 198 bool IsBeginMainFrameSentOrStarted() const; |
227 void SetupSyntheticBeginFrames(); | |
228 | 199 |
229 base::WeakPtrFactory<Scheduler> weak_factory_; | 200 base::WeakPtrFactory<Scheduler> weak_factory_; |
230 | 201 |
231 DISALLOW_COPY_AND_ASSIGN(Scheduler); | 202 DISALLOW_COPY_AND_ASSIGN(Scheduler); |
232 }; | 203 }; |
233 | 204 |
234 } // namespace cc | 205 } // namespace cc |
235 | 206 |
236 #endif // CC_SCHEDULER_SCHEDULER_H_ | 207 #endif // CC_SCHEDULER_SCHEDULER_H_ |
OLD | NEW |