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/begin_frame_manager.h" | |
17 #include "cc/scheduler/delay_based_time_source.h" | 18 #include "cc/scheduler/delay_based_time_source.h" |
18 #include "cc/scheduler/draw_result.h" | 19 #include "cc/scheduler/draw_result.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 namespace debug { | 24 namespace debug { |
24 class ConvertableToTraceFormat; | 25 class ConvertableToTraceFormat; |
25 } | 26 } |
26 class SingleThreadTaskRunner; | 27 class SingleThreadTaskRunner; |
(...skipping 17 matching lines...) Expand all Loading... | |
44 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks time) = 0; | 45 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks time) = 0; |
45 virtual base::TimeDelta DrawDurationEstimate() = 0; | 46 virtual base::TimeDelta DrawDurationEstimate() = 0; |
46 virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() = 0; | 47 virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() = 0; |
47 virtual base::TimeDelta CommitToActivateDurationEstimate() = 0; | 48 virtual base::TimeDelta CommitToActivateDurationEstimate() = 0; |
48 virtual void DidBeginImplFrameDeadline() = 0; | 49 virtual void DidBeginImplFrameDeadline() = 0; |
49 | 50 |
50 protected: | 51 protected: |
51 virtual ~SchedulerClient() {} | 52 virtual ~SchedulerClient() {} |
52 }; | 53 }; |
53 | 54 |
54 class CC_EXPORT Scheduler { | 55 class CC_EXPORT Scheduler : public BeginFrameManager::Delegate { |
55 public: | 56 public: |
56 static scoped_ptr<Scheduler> Create( | 57 static scoped_ptr<Scheduler> Create( |
57 SchedulerClient* client, | 58 SchedulerClient* client, |
58 const SchedulerSettings& scheduler_settings, | 59 const SchedulerSettings& scheduler_settings, |
59 int layer_tree_host_id, | 60 int layer_tree_host_id, |
60 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { | 61 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
61 return make_scoped_ptr(new Scheduler( | 62 BeginFrameManager* begin_frame_manager) { |
62 client, scheduler_settings, layer_tree_host_id, task_runner)); | 63 return make_scoped_ptr(new Scheduler(client, |
64 scheduler_settings, | |
65 layer_tree_host_id, | |
66 task_runner, | |
67 begin_frame_manager)); | |
63 } | 68 } |
64 | 69 |
65 virtual ~Scheduler(); | 70 virtual ~Scheduler(); |
66 | 71 |
67 const SchedulerSettings& settings() const { return settings_; } | 72 const SchedulerSettings& settings() const { return settings_; } |
68 | 73 |
69 void CommitVSyncParameters(base::TimeTicks timebase, | 74 void CommitVSyncParameters(base::TimeTicks timebase, |
70 base::TimeDelta interval); | 75 base::TimeDelta interval); |
71 void SetEstimatedParentDrawTime(base::TimeDelta draw_time); | 76 void SetEstimatedParentDrawTime(base::TimeDelta draw_time); |
72 | 77 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 | 141 |
137 bool IsInsideAction(SchedulerStateMachine::Action action) { | 142 bool IsInsideAction(SchedulerStateMachine::Action action) { |
138 return inside_action_ == action; | 143 return inside_action_ == action; |
139 } | 144 } |
140 | 145 |
141 bool IsBeginMainFrameSent() const; | 146 bool IsBeginMainFrameSent() const; |
142 void SetContinuousPainting(bool continuous_painting) { | 147 void SetContinuousPainting(bool continuous_painting) { |
143 state_machine_.SetContinuousPainting(continuous_painting); | 148 state_machine_.SetContinuousPainting(continuous_painting); |
144 } | 149 } |
145 | 150 |
151 // BeginFrameManager::Delegate implementation. | |
152 // SetChildrenNeedBeginFrames() is only used when this Scheduler is acting | |
153 // the publisher. | |
brianderson
2014/08/27 01:34:08
the -> as the
simonhong
2014/08/27 07:56:12
Done.
| |
154 virtual void SetChildrenNeedBeginFrames(bool need_begin_frame) OVERRIDE; | |
155 virtual void SetAuthoritativeVSyncInterval( | |
156 base::TimeDelta interval) OVERRIDE; | |
157 | |
146 protected: | 158 protected: |
147 class CC_EXPORT SyntheticBeginFrameSource : public TimeSourceClient { | 159 class CC_EXPORT SyntheticBeginFrameSource : public TimeSourceClient { |
148 public: | 160 public: |
149 SyntheticBeginFrameSource(Scheduler* scheduler, | 161 SyntheticBeginFrameSource(Scheduler* scheduler, |
150 base::SingleThreadTaskRunner* task_runner); | 162 base::SingleThreadTaskRunner* task_runner); |
151 virtual ~SyntheticBeginFrameSource(); | 163 virtual ~SyntheticBeginFrameSource(); |
152 | 164 |
153 // Updates the phase and frequency of the timer. | 165 // Updates the phase and frequency of the timer. |
154 void CommitVSyncParameters(base::TimeTicks timebase, | 166 void CommitVSyncParameters(base::TimeTicks timebase, |
155 base::TimeDelta interval); | 167 base::TimeDelta interval); |
(...skipping 13 matching lines...) Expand all Loading... | |
169 private: | 181 private: |
170 BeginFrameArgs CreateSyntheticBeginFrameArgs(base::TimeTicks frame_time); | 182 BeginFrameArgs CreateSyntheticBeginFrameArgs(base::TimeTicks frame_time); |
171 | 183 |
172 Scheduler* scheduler_; | 184 Scheduler* scheduler_; |
173 scoped_refptr<DelayBasedTimeSource> time_source_; | 185 scoped_refptr<DelayBasedTimeSource> time_source_; |
174 }; | 186 }; |
175 | 187 |
176 Scheduler(SchedulerClient* client, | 188 Scheduler(SchedulerClient* client, |
177 const SchedulerSettings& scheduler_settings, | 189 const SchedulerSettings& scheduler_settings, |
178 int layer_tree_host_id, | 190 int layer_tree_host_id, |
179 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); | 191 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
192 BeginFrameManager* begin_frame_manager); | |
180 | 193 |
181 const SchedulerSettings settings_; | 194 const SchedulerSettings settings_; |
182 SchedulerClient* client_; | 195 SchedulerClient* client_; |
183 int layer_tree_host_id_; | 196 int layer_tree_host_id_; |
184 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 197 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
185 | 198 |
186 base::TimeDelta vsync_interval_; | 199 base::TimeDelta vsync_interval_; |
200 base::TimeDelta authoritative_vsync_interval_; | |
201 base::TimeTicks last_timebase_; | |
202 | |
187 base::TimeDelta estimated_parent_draw_time_; | 203 base::TimeDelta estimated_parent_draw_time_; |
188 | 204 |
189 bool last_set_needs_begin_frame_; | 205 bool last_set_needs_begin_frame_; |
190 bool begin_unthrottled_frame_posted_; | 206 bool begin_unthrottled_frame_posted_; |
191 bool begin_retro_frame_posted_; | 207 bool begin_retro_frame_posted_; |
192 std::deque<BeginFrameArgs> begin_retro_frame_args_; | 208 std::deque<BeginFrameArgs> begin_retro_frame_args_; |
193 BeginFrameArgs begin_impl_frame_args_; | 209 BeginFrameArgs begin_impl_frame_args_; |
194 | 210 |
195 scoped_ptr<SyntheticBeginFrameSource> synthetic_begin_frame_source_; | 211 scoped_ptr<SyntheticBeginFrameSource> synthetic_begin_frame_source_; |
196 | 212 |
197 base::Closure begin_retro_frame_closure_; | 213 base::Closure begin_retro_frame_closure_; |
198 base::Closure begin_unthrottled_frame_closure_; | 214 base::Closure begin_unthrottled_frame_closure_; |
199 | 215 |
200 base::Closure begin_impl_frame_deadline_closure_; | 216 base::Closure begin_impl_frame_deadline_closure_; |
201 base::Closure poll_for_draw_triggers_closure_; | 217 base::Closure poll_for_draw_triggers_closure_; |
202 base::Closure advance_commit_state_closure_; | 218 base::Closure advance_commit_state_closure_; |
203 base::CancelableClosure begin_impl_frame_deadline_task_; | 219 base::CancelableClosure begin_impl_frame_deadline_task_; |
204 base::CancelableClosure poll_for_draw_triggers_task_; | 220 base::CancelableClosure poll_for_draw_triggers_task_; |
205 base::CancelableClosure advance_commit_state_task_; | 221 base::CancelableClosure advance_commit_state_task_; |
206 | 222 |
207 SchedulerStateMachine state_machine_; | 223 SchedulerStateMachine state_machine_; |
208 bool inside_process_scheduled_actions_; | 224 bool inside_process_scheduled_actions_; |
209 SchedulerStateMachine::Action inside_action_; | 225 SchedulerStateMachine::Action inside_action_; |
210 | 226 |
227 // Not owned. | |
228 BeginFrameManager* begin_frame_manager_; | |
229 | |
211 private: | 230 private: |
212 base::TimeTicks AdjustedBeginImplFrameDeadline( | 231 base::TimeTicks AdjustedBeginImplFrameDeadline( |
213 const BeginFrameArgs& args, | 232 const BeginFrameArgs& args, |
214 base::TimeDelta draw_duration_estimate) const; | 233 base::TimeDelta draw_duration_estimate) const; |
215 void ScheduleBeginImplFrameDeadline(base::TimeTicks deadline); | 234 void ScheduleBeginImplFrameDeadline(base::TimeTicks deadline); |
216 void SetupNextBeginFrameIfNeeded(); | 235 void SetupNextBeginFrameIfNeeded(); |
217 void PostBeginRetroFrameIfNeeded(); | 236 void PostBeginRetroFrameIfNeeded(); |
218 void SetupNextBeginFrameWhenVSyncThrottlingEnabled(bool needs_begin_frame); | 237 void SetupNextBeginFrameWhenVSyncThrottlingEnabled(bool needs_begin_frame); |
219 void SetupNextBeginFrameWhenVSyncThrottlingDisabled(bool needs_begin_frame); | 238 void SetupNextBeginFrameWhenVSyncThrottlingDisabled(bool needs_begin_frame); |
220 void SetupPollingMechanisms(bool needs_begin_frame); | 239 void SetupPollingMechanisms(bool needs_begin_frame); |
221 void DrawAndSwapIfPossible(); | 240 void DrawAndSwapIfPossible(); |
222 void ProcessScheduledActions(); | 241 void ProcessScheduledActions(); |
223 bool CanCommitAndActivateBeforeDeadline() const; | 242 bool CanCommitAndActivateBeforeDeadline() const; |
224 void AdvanceCommitStateIfPossible(); | 243 void AdvanceCommitStateIfPossible(); |
225 bool IsBeginMainFrameSentOrStarted() const; | 244 bool IsBeginMainFrameSentOrStarted() const; |
226 void SetupSyntheticBeginFrames(); | 245 void SetupSyntheticBeginFrames(); |
227 | 246 |
228 base::WeakPtrFactory<Scheduler> weak_factory_; | 247 base::WeakPtrFactory<Scheduler> weak_factory_; |
229 | 248 |
230 DISALLOW_COPY_AND_ASSIGN(Scheduler); | 249 DISALLOW_COPY_AND_ASSIGN(Scheduler); |
231 }; | 250 }; |
232 | 251 |
233 } // namespace cc | 252 } // namespace cc |
234 | 253 |
235 #endif // CC_SCHEDULER_SCHEDULER_H_ | 254 #endif // CC_SCHEDULER_SCHEDULER_H_ |
OLD | NEW |