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

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

Issue 267783004: Refactoring the way begin frame sources inside scheduler work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Small fix. Created 6 years, 3 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
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/output/vsync_parameter_observer.h"
18 #include "cc/scheduler/begin_frame_source.h"
17 #include "cc/scheduler/delay_based_time_source.h" 19 #include "cc/scheduler/delay_based_time_source.h"
18 #include "cc/scheduler/draw_result.h" 20 #include "cc/scheduler/draw_result.h"
19 #include "cc/scheduler/scheduler_settings.h" 21 #include "cc/scheduler/scheduler_settings.h"
20 #include "cc/scheduler/scheduler_state_machine.h" 22 #include "cc/scheduler/scheduler_state_machine.h"
21 23
22 namespace base { 24 namespace base {
23 namespace debug { 25 namespace debug {
24 class ConvertableToTraceFormat; 26 class ConvertableToTraceFormat;
25 } 27 }
26 class SingleThreadTaskRunner; 28 class SingleThreadTaskRunner;
27 } 29 }
28 30
29 namespace cc { 31 namespace cc {
30 32
31 class SchedulerClient { 33 class SchedulerClient {
32 public: 34 public:
33 virtual void SetNeedsBeginFrame(bool enable) = 0; 35 virtual BeginFrameSource* ExternalBeginFrameSource() = 0;
34 virtual void WillBeginImplFrame(const BeginFrameArgs& args) = 0; 36 virtual void WillBeginImplFrame(const BeginFrameArgs& args) = 0;
35 virtual void ScheduledActionSendBeginMainFrame() = 0; 37 virtual void ScheduledActionSendBeginMainFrame() = 0;
36 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() = 0; 38 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() = 0;
37 virtual DrawResult ScheduledActionDrawAndSwapForced() = 0; 39 virtual DrawResult ScheduledActionDrawAndSwapForced() = 0;
38 virtual void ScheduledActionAnimate() = 0; 40 virtual void ScheduledActionAnimate() = 0;
39 virtual void ScheduledActionCommit() = 0; 41 virtual void ScheduledActionCommit() = 0;
40 virtual void ScheduledActionUpdateVisibleTiles() = 0; 42 virtual void ScheduledActionUpdateVisibleTiles() = 0;
41 virtual void ScheduledActionActivateSyncTree() = 0; 43 virtual void ScheduledActionActivateSyncTree() = 0;
42 virtual void ScheduledActionBeginOutputSurfaceCreation() = 0; 44 virtual void ScheduledActionBeginOutputSurfaceCreation() = 0;
43 virtual void ScheduledActionManageTiles() = 0; 45 virtual void ScheduledActionManageTiles() = 0;
44 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks time) = 0; 46 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks time) = 0;
45 virtual base::TimeDelta DrawDurationEstimate() = 0; 47 virtual base::TimeDelta DrawDurationEstimate() = 0;
46 virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() = 0; 48 virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() = 0;
47 virtual base::TimeDelta CommitToActivateDurationEstimate() = 0; 49 virtual base::TimeDelta CommitToActivateDurationEstimate() = 0;
48 virtual void DidBeginImplFrameDeadline() = 0; 50 virtual void DidBeginImplFrameDeadline() = 0;
49 51
50 protected: 52 protected:
51 virtual ~SchedulerClient() {} 53 virtual ~SchedulerClient() {}
52 }; 54 };
53 55
54 class CC_EXPORT Scheduler { 56 class Scheduler;
57 // This class exists to allow tests to override the frame source construction.
58 // A virtual method can't be used as this needs to happen in the constructor
59 // (see C++ FAQ / Section 23 - http://goo.gl/fnrwom for why).
60 // This class exists solely long enough to construct the frame sources.
61 class CC_EXPORT SchedulerFrameSourcesConstructor {
62 public:
63 virtual ~SchedulerFrameSourcesConstructor() {}
64 virtual BeginFrameSource* ConstructPrimaryFrameSource(Scheduler* scheduler);
65 virtual BeginFrameSource* ConstructBackgroundFrameSource(
66 Scheduler* scheduler);
67
68 protected:
69 SchedulerFrameSourcesConstructor() {}
70
71 friend class Scheduler;
72 };
73
74 class CC_EXPORT Scheduler : public BeginFrameObserverMixIn {
55 public: 75 public:
56 static scoped_ptr<Scheduler> Create( 76 static scoped_ptr<Scheduler> Create(
57 SchedulerClient* client, 77 SchedulerClient* client,
58 const SchedulerSettings& scheduler_settings, 78 const SchedulerSettings& scheduler_settings,
59 int layer_tree_host_id, 79 int layer_tree_host_id,
60 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { 80 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) {
61 return make_scoped_ptr(new Scheduler( 81 SchedulerFrameSourcesConstructor frame_sources_constructor;
62 client, scheduler_settings, layer_tree_host_id, task_runner)); 82 return make_scoped_ptr(new Scheduler(client,
83 scheduler_settings,
84 layer_tree_host_id,
85 task_runner,
86 &frame_sources_constructor));
63 } 87 }
64 88
65 virtual ~Scheduler(); 89 virtual ~Scheduler();
66 90
67 const SchedulerSettings& settings() const { return settings_; } 91 const SchedulerSettings& settings() const { return settings_; }
68 92
69 void CommitVSyncParameters(base::TimeTicks timebase, 93 void CommitVSyncParameters(base::TimeTicks timebase,
70 base::TimeDelta interval); 94 base::TimeDelta interval);
71 void SetEstimatedParentDrawTime(base::TimeDelta draw_time); 95 void SetEstimatedParentDrawTime(base::TimeDelta draw_time);
72 96
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 bool BeginImplFrameDeadlinePending() const { 140 bool BeginImplFrameDeadlinePending() const {
117 return !begin_impl_frame_deadline_task_.IsCancelled(); 141 return !begin_impl_frame_deadline_task_.IsCancelled();
118 } 142 }
119 143
120 bool WillDrawIfNeeded() const; 144 bool WillDrawIfNeeded() const;
121 145
122 base::TimeTicks AnticipatedDrawTime() const; 146 base::TimeTicks AnticipatedDrawTime() const;
123 147
124 void NotifyBeginMainFrameStarted(); 148 void NotifyBeginMainFrameStarted();
125 149
126 base::TimeTicks LastBeginImplFrameTime();
127
128 void BeginFrame(const BeginFrameArgs& args);
129
130 scoped_refptr<base::debug::ConvertableToTraceFormat> AsValue() const; 150 scoped_refptr<base::debug::ConvertableToTraceFormat> AsValue() const;
131 void AsValueInto(base::debug::TracedValue* state) const; 151 virtual void AsValueInto(base::debug::TracedValue* value) const OVERRIDE;
132 152
133 void SetContinuousPainting(bool continuous_painting) { 153 void SetContinuousPainting(bool continuous_painting) {
134 state_machine_.SetContinuousPainting(continuous_painting); 154 state_machine_.SetContinuousPainting(continuous_painting);
135 } 155 }
136 156
157 base::TimeTicks LastBeginImplFrameTime();
158
159 // BeginFrameObserverMixin
160 virtual bool ProcessBeginFrameArgs(const BeginFrameArgs& args) OVERRIDE;
161 virtual bool ProcessMissedBeginFrameArgs(const BeginFrameArgs& args) OVERRIDE;
162
137 protected: 163 protected:
138 class CC_EXPORT SyntheticBeginFrameSource : public TimeSourceClient {
139 public:
140 SyntheticBeginFrameSource(Scheduler* scheduler,
141 scoped_refptr<DelayBasedTimeSource> time_source);
142 virtual ~SyntheticBeginFrameSource();
143
144 // Updates the phase and frequency of the timer.
145 void CommitVSyncParameters(base::TimeTicks timebase,
146 base::TimeDelta interval);
147
148 // Activates future BeginFrames and, if activating, pushes the most
149 // recently missed BeginFrame to the back of a retroactive queue.
150 void SetNeedsBeginFrame(bool needs_begin_frame,
151 std::deque<BeginFrameArgs>* begin_retro_frame_args);
152
153 bool IsActive() const;
154
155 // TimeSourceClient implementation of OnTimerTick triggers a BeginFrame.
156 virtual void OnTimerTick() OVERRIDE;
157
158 void AsValueInto(base::debug::TracedValue* dict) const;
159
160 private:
161 BeginFrameArgs CreateSyntheticBeginFrameArgs(base::TimeTicks frame_time);
162
163 Scheduler* scheduler_;
164 scoped_refptr<DelayBasedTimeSource> time_source_;
165 };
166
167 Scheduler(SchedulerClient* client, 164 Scheduler(SchedulerClient* client,
168 const SchedulerSettings& scheduler_settings, 165 const SchedulerSettings& scheduler_settings,
169 int layer_tree_host_id, 166 int layer_tree_host_id,
170 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); 167 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
168 SchedulerFrameSourcesConstructor* frame_sources_constructor);
171 169
170 // virtual for testing - Don't call these in the constructor or
171 // destructor!
172 virtual base::TimeTicks Now() const; 172 virtual base::TimeTicks Now() const;
173 173
174 scoped_ptr<BeginFrameSourceMultiplexer> frame_source_;
175 BeginFrameSource* primary_frame_source_;
176 BeginFrameSource* background_frame_source_;
177
178 // Storage when frame sources are internal
179 scoped_ptr<BeginFrameSource> primary_frame_source_internal_;
180 scoped_ptr<SyntheticBeginFrameSource> background_frame_source_internal_;
181
182 VSyncParameterObserver* vsync_observer_;
183
174 const SchedulerSettings settings_; 184 const SchedulerSettings settings_;
175 SchedulerClient* client_; 185 SchedulerClient* client_;
176 int layer_tree_host_id_; 186 int layer_tree_host_id_;
177 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 187 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
178 188
179 base::TimeDelta vsync_interval_;
180 base::TimeDelta estimated_parent_draw_time_; 189 base::TimeDelta estimated_parent_draw_time_;
181 190
182 bool last_set_needs_begin_frame_;
183 bool begin_unthrottled_frame_posted_;
184 bool begin_retro_frame_posted_; 191 bool begin_retro_frame_posted_;
185 std::deque<BeginFrameArgs> begin_retro_frame_args_; 192 std::deque<BeginFrameArgs> begin_retro_frame_args_;
186 BeginFrameArgs begin_impl_frame_args_; 193 BeginFrameArgs begin_impl_frame_args_;
187 194
188 scoped_ptr<SyntheticBeginFrameSource> synthetic_begin_frame_source_;
189
190 base::Closure begin_retro_frame_closure_; 195 base::Closure begin_retro_frame_closure_;
191 base::Closure begin_unthrottled_frame_closure_; 196 base::Closure begin_unthrottled_frame_closure_;
192 197
193 base::Closure begin_impl_frame_deadline_closure_; 198 base::Closure begin_impl_frame_deadline_closure_;
194 base::Closure poll_for_draw_triggers_closure_; 199 base::Closure poll_for_draw_triggers_closure_;
195 base::Closure advance_commit_state_closure_; 200 base::Closure advance_commit_state_closure_;
196 base::CancelableClosure begin_impl_frame_deadline_task_; 201 base::CancelableClosure begin_impl_frame_deadline_task_;
197 base::CancelableClosure poll_for_draw_triggers_task_; 202 base::CancelableClosure poll_for_draw_triggers_task_;
198 base::CancelableClosure advance_commit_state_task_; 203 base::CancelableClosure advance_commit_state_task_;
199 204
200 SchedulerStateMachine state_machine_; 205 SchedulerStateMachine state_machine_;
201 bool inside_process_scheduled_actions_; 206 bool inside_process_scheduled_actions_;
202 SchedulerStateMachine::Action inside_action_; 207 SchedulerStateMachine::Action inside_action_;
203 208
204 base::TimeDelta VSyncInterval() { return vsync_interval_; }
205
206 private: 209 private:
207 base::TimeTicks AdjustedBeginImplFrameDeadline( 210 base::TimeTicks AdjustedBeginImplFrameDeadline(
208 const BeginFrameArgs& args, 211 const BeginFrameArgs& args,
209 base::TimeDelta draw_duration_estimate) const; 212 base::TimeDelta draw_duration_estimate) const;
210 void ScheduleBeginImplFrameDeadline(base::TimeTicks deadline); 213 void ScheduleBeginImplFrameDeadline(base::TimeTicks deadline);
211 void SetupNextBeginFrameIfNeeded(); 214 void SetupNextBeginFrameIfNeeded();
212 void PostBeginRetroFrameIfNeeded(); 215 void PostBeginRetroFrameIfNeeded();
213 void SetupNextBeginFrameWhenVSyncThrottlingEnabled(bool needs_begin_frame);
214 void SetupNextBeginFrameWhenVSyncThrottlingDisabled(bool needs_begin_frame);
215 void SetupPollingMechanisms(bool needs_begin_frame); 216 void SetupPollingMechanisms(bool needs_begin_frame);
216 void DrawAndSwapIfPossible(); 217 void DrawAndSwapIfPossible();
217 void ProcessScheduledActions(); 218 void ProcessScheduledActions();
218 bool CanCommitAndActivateBeforeDeadline() const; 219 bool CanCommitAndActivateBeforeDeadline() const;
219 void AdvanceCommitStateIfPossible(); 220 void AdvanceCommitStateIfPossible();
220 bool IsBeginMainFrameSentOrStarted() const; 221 bool IsBeginMainFrameSentOrStarted() const;
221 void SetupSyntheticBeginFrames();
222 void BeginRetroFrame(); 222 void BeginRetroFrame();
223 void BeginUnthrottledFrame();
224 void BeginImplFrame(const BeginFrameArgs& args); 223 void BeginImplFrame(const BeginFrameArgs& args);
225 void OnBeginImplFrameDeadline(); 224 void OnBeginImplFrameDeadline();
226 void PollForAnticipatedDrawTriggers(); 225 void PollForAnticipatedDrawTriggers();
227 void PollToAdvanceCommitState(); 226 void PollToAdvanceCommitState();
228 227
229 base::TimeDelta EstimatedParentDrawTime() { 228 base::TimeDelta EstimatedParentDrawTime() {
230 return estimated_parent_draw_time_; 229 return estimated_parent_draw_time_;
231 } 230 }
232 231
233 bool IsInsideAction(SchedulerStateMachine::Action action) { 232 bool IsInsideAction(SchedulerStateMachine::Action action) {
234 return inside_action_ == action; 233 return inside_action_ == action;
235 } 234 }
236 235
237 base::WeakPtrFactory<Scheduler> weak_factory_; 236 base::WeakPtrFactory<Scheduler> weak_factory_;
238 237
238 friend class SchedulerFrameSourcesConstructor;
239 friend class TestSchedulerFrameSourcesConstructor;
240
239 DISALLOW_COPY_AND_ASSIGN(Scheduler); 241 DISALLOW_COPY_AND_ASSIGN(Scheduler);
240 }; 242 };
241 243
242 } // namespace cc 244 } // namespace cc
243 245
244 #endif // CC_SCHEDULER_SCHEDULER_H_ 246 #endif // CC_SCHEDULER_SCHEDULER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698