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

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: Fixing for review comments. Created 6 years, 2 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 {
Sami 2014/09/24 11:12:53 This seems more elaborate than it needs to be. How
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 BeginFrameObserver::BeginFrameArgsStatus ProcessBeginFrameArgs(
161 const BeginFrameArgs& args) OVERRIDE;
162 virtual BeginFrameObserver::BeginFrameArgsStatus OnMissedBeginFrame(
163 const BeginFrameArgs& args) OVERRIDE;
164
137 protected: 165 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, 166 Scheduler(SchedulerClient* client,
168 const SchedulerSettings& scheduler_settings, 167 const SchedulerSettings& scheduler_settings,
169 int layer_tree_host_id, 168 int layer_tree_host_id,
170 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); 169 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
170 SchedulerFrameSourcesConstructor* frame_sources_constructor);
171 171
172 // virtual for testing - Don't call these in the constructor or
173 // destructor!
172 virtual base::TimeTicks Now() const; 174 virtual base::TimeTicks Now() const;
173 175
176 scoped_ptr<BeginFrameSourceMultiplexer> frame_source_;
177 BeginFrameSource* primary_frame_source_;
178 BeginFrameSource* background_frame_source_;
179
180 // Storage when frame sources are internal
181 scoped_ptr<BeginFrameSource> primary_frame_source_internal_;
182 scoped_ptr<SyntheticBeginFrameSource> background_frame_source_internal_;
183
184 VSyncParameterObserver* vsync_observer_;
185
174 const SchedulerSettings settings_; 186 const SchedulerSettings settings_;
175 SchedulerClient* client_; 187 SchedulerClient* client_;
176 int layer_tree_host_id_; 188 int layer_tree_host_id_;
177 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 189 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
178 190
179 base::TimeDelta vsync_interval_;
180 base::TimeDelta estimated_parent_draw_time_; 191 base::TimeDelta estimated_parent_draw_time_;
181 192
182 bool last_set_needs_begin_frame_;
183 bool begin_unthrottled_frame_posted_;
184 bool begin_retro_frame_posted_; 193 bool begin_retro_frame_posted_;
185 std::deque<BeginFrameArgs> begin_retro_frame_args_; 194 std::deque<BeginFrameArgs> begin_retro_frame_args_;
186 BeginFrameArgs begin_impl_frame_args_; 195 BeginFrameArgs begin_impl_frame_args_;
187 196
188 scoped_ptr<SyntheticBeginFrameSource> synthetic_begin_frame_source_;
189
190 base::Closure begin_retro_frame_closure_; 197 base::Closure begin_retro_frame_closure_;
191 base::Closure begin_unthrottled_frame_closure_; 198 base::Closure begin_unthrottled_frame_closure_;
192 199
193 base::Closure begin_impl_frame_deadline_closure_; 200 base::Closure begin_impl_frame_deadline_closure_;
194 base::Closure poll_for_draw_triggers_closure_; 201 base::Closure poll_for_draw_triggers_closure_;
195 base::Closure advance_commit_state_closure_; 202 base::Closure advance_commit_state_closure_;
196 base::CancelableClosure begin_impl_frame_deadline_task_; 203 base::CancelableClosure begin_impl_frame_deadline_task_;
197 base::CancelableClosure poll_for_draw_triggers_task_; 204 base::CancelableClosure poll_for_draw_triggers_task_;
198 base::CancelableClosure advance_commit_state_task_; 205 base::CancelableClosure advance_commit_state_task_;
199 206
200 SchedulerStateMachine state_machine_; 207 SchedulerStateMachine state_machine_;
201 bool inside_process_scheduled_actions_; 208 bool inside_process_scheduled_actions_;
202 SchedulerStateMachine::Action inside_action_; 209 SchedulerStateMachine::Action inside_action_;
203 210
204 base::TimeDelta VSyncInterval() { return vsync_interval_; }
205
206 private: 211 private:
207 base::TimeTicks AdjustedBeginImplFrameDeadline( 212 base::TimeTicks AdjustedBeginImplFrameDeadline(
208 const BeginFrameArgs& args, 213 const BeginFrameArgs& args,
209 base::TimeDelta draw_duration_estimate) const; 214 base::TimeDelta draw_duration_estimate) const;
210 void ScheduleBeginImplFrameDeadline(base::TimeTicks deadline); 215 void ScheduleBeginImplFrameDeadline(base::TimeTicks deadline);
211 void SetupNextBeginFrameIfNeeded(); 216 void SetupNextBeginFrameIfNeeded();
212 void PostBeginRetroFrameIfNeeded(); 217 void PostBeginRetroFrameIfNeeded();
213 void SetupNextBeginFrameWhenVSyncThrottlingEnabled(bool needs_begin_frame);
214 void SetupNextBeginFrameWhenVSyncThrottlingDisabled(bool needs_begin_frame);
215 void SetupPollingMechanisms(bool needs_begin_frame); 218 void SetupPollingMechanisms(bool needs_begin_frame);
216 void DrawAndSwapIfPossible(); 219 void DrawAndSwapIfPossible();
217 void ProcessScheduledActions(); 220 void ProcessScheduledActions();
218 bool CanCommitAndActivateBeforeDeadline() const; 221 bool CanCommitAndActivateBeforeDeadline() const;
219 void AdvanceCommitStateIfPossible(); 222 void AdvanceCommitStateIfPossible();
220 bool IsBeginMainFrameSentOrStarted() const; 223 bool IsBeginMainFrameSentOrStarted() const;
221 void SetupSyntheticBeginFrames();
222 void BeginRetroFrame(); 224 void BeginRetroFrame();
223 void BeginUnthrottledFrame();
224 void BeginImplFrame(const BeginFrameArgs& args); 225 void BeginImplFrame(const BeginFrameArgs& args);
225 void OnBeginImplFrameDeadline(); 226 void OnBeginImplFrameDeadline();
226 void PollForAnticipatedDrawTriggers(); 227 void PollForAnticipatedDrawTriggers();
227 void PollToAdvanceCommitState(); 228 void PollToAdvanceCommitState();
228 229
229 base::TimeDelta EstimatedParentDrawTime() { 230 base::TimeDelta EstimatedParentDrawTime() {
230 return estimated_parent_draw_time_; 231 return estimated_parent_draw_time_;
231 } 232 }
232 233
233 bool IsInsideAction(SchedulerStateMachine::Action action) { 234 bool IsInsideAction(SchedulerStateMachine::Action action) {
234 return inside_action_ == action; 235 return inside_action_ == action;
235 } 236 }
236 237
237 base::WeakPtrFactory<Scheduler> weak_factory_; 238 base::WeakPtrFactory<Scheduler> weak_factory_;
238 239
240 friend class SchedulerFrameSourcesConstructor;
241 friend class TestSchedulerFrameSourcesConstructor;
242
239 DISALLOW_COPY_AND_ASSIGN(Scheduler); 243 DISALLOW_COPY_AND_ASSIGN(Scheduler);
240 }; 244 };
241 245
242 } // namespace cc 246 } // namespace cc
243 247
244 #endif // CC_SCHEDULER_SCHEDULER_H_ 248 #endif // CC_SCHEDULER_SCHEDULER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698