Chromium Code Reviews| 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 namespace debug { | 24 namespace debug { |
| 24 class ConvertableToTraceFormat; | 25 class ConvertableToTraceFormat; |
| 25 } | 26 } |
| 26 class SingleThreadTaskRunner; | 27 class SingleThreadTaskRunner; |
| 27 } | 28 } |
| 28 | 29 |
| 29 namespace cc { | 30 namespace cc { |
| 30 | 31 |
| 31 class SchedulerClient { | 32 class SchedulerClient { |
| 32 public: | 33 public: |
| 33 virtual void SetNeedsBeginFrame(bool enable) = 0; | 34 virtual BeginFrameSource* GetExternalBeginFrameSource() = 0; |
| 34 virtual void WillBeginImplFrame(const BeginFrameArgs& args) = 0; | 35 virtual void WillBeginImplFrame(const BeginFrameArgs& args) = 0; |
| 35 virtual void ScheduledActionSendBeginMainFrame() = 0; | 36 virtual void ScheduledActionSendBeginMainFrame() = 0; |
| 36 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() = 0; | 37 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() = 0; |
| 37 virtual DrawResult ScheduledActionDrawAndSwapForced() = 0; | 38 virtual DrawResult ScheduledActionDrawAndSwapForced() = 0; |
| 38 virtual void ScheduledActionAnimate() = 0; | 39 virtual void ScheduledActionAnimate() = 0; |
| 39 virtual void ScheduledActionCommit() = 0; | 40 virtual void ScheduledActionCommit() = 0; |
| 40 virtual void ScheduledActionUpdateVisibleTiles() = 0; | 41 virtual void ScheduledActionUpdateVisibleTiles() = 0; |
| 41 virtual void ScheduledActionActivateSyncTree() = 0; | 42 virtual void ScheduledActionActivateSyncTree() = 0; |
| 42 virtual void ScheduledActionBeginOutputSurfaceCreation() = 0; | 43 virtual void ScheduledActionBeginOutputSurfaceCreation() = 0; |
| 43 virtual void ScheduledActionManageTiles() = 0; | 44 virtual void ScheduledActionManageTiles() = 0; |
| 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 BeginFrameObserver { |
| 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 scoped_ptr<Scheduler> scheduler = make_scoped_ptr(new Scheduler( |
| 62 client, scheduler_settings, layer_tree_host_id, task_runner)); | 63 client, scheduler_settings, layer_tree_host_id, task_runner)); |
| 64 scheduler->FinalizeSetup(); | |
| 65 return scheduler.Pass(); | |
| 63 } | 66 } |
| 64 | 67 |
| 65 virtual ~Scheduler(); | 68 virtual ~Scheduler(); |
| 66 | 69 |
| 67 const SchedulerSettings& settings() const { return settings_; } | 70 const SchedulerSettings& settings() const { return settings_; } |
| 68 | 71 |
| 69 void CommitVSyncParameters(base::TimeTicks timebase, | 72 void CommitVSyncParameters(base::TimeTicks timebase, |
| 70 base::TimeDelta interval); | 73 base::TimeDelta interval); |
| 71 void SetEstimatedParentDrawTime(base::TimeDelta draw_time); | 74 void SetEstimatedParentDrawTime(base::TimeDelta draw_time); |
| 72 | 75 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 bool BeginImplFrameDeadlinePending() const { | 119 bool BeginImplFrameDeadlinePending() const { |
| 117 return !begin_impl_frame_deadline_task_.IsCancelled(); | 120 return !begin_impl_frame_deadline_task_.IsCancelled(); |
| 118 } | 121 } |
| 119 | 122 |
| 120 bool WillDrawIfNeeded() const; | 123 bool WillDrawIfNeeded() const; |
| 121 | 124 |
| 122 base::TimeTicks AnticipatedDrawTime() const; | 125 base::TimeTicks AnticipatedDrawTime() const; |
| 123 | 126 |
| 124 void NotifyBeginMainFrameStarted(); | 127 void NotifyBeginMainFrameStarted(); |
| 125 | 128 |
| 126 base::TimeTicks LastBeginImplFrameTime(); | |
| 127 | |
| 128 void BeginFrame(const BeginFrameArgs& args); | |
| 129 | |
| 130 scoped_refptr<base::debug::ConvertableToTraceFormat> AsValue() const; | 129 scoped_refptr<base::debug::ConvertableToTraceFormat> AsValue() const; |
| 131 void AsValueInto(base::debug::TracedValue* state) const; | 130 virtual void AsValueInto(base::debug::TracedValue* value) const OVERRIDE; |
| 132 | 131 |
| 133 void SetContinuousPainting(bool continuous_painting) { | 132 void SetContinuousPainting(bool continuous_painting) { |
| 134 state_machine_.SetContinuousPainting(continuous_painting); | 133 state_machine_.SetContinuousPainting(continuous_painting); |
| 135 } | 134 } |
| 136 | 135 |
| 136 // BeginFrameObserver | |
| 137 virtual void OnBeginFrame(const BeginFrameArgs& args) OVERRIDE; | |
| 138 virtual const BeginFrameArgs& LastBeginFrameArgs() const OVERRIDE; | |
| 139 base::TimeTicks LastBeginImplFrameTime(); | |
| 140 | |
| 141 ui::CompositorVSyncManager::Observer* vsync_observer_ = NULL; | |
| 142 scoped_ptr<BeginFrameSourceMultiplexer> frame_source_; | |
| 143 BeginFrameSource* primary_frame_source_ = NULL; | |
| 144 BeginFrameSource* background_frame_source_ = NULL; | |
| 145 | |
| 146 // Storage for when using internal frame sources. | |
| 147 scoped_ptr<BeginFrameSource> primary_frame_source_internal_; | |
| 148 scoped_ptr<SyntheticBeginFrameSource> background_frame_source_internal_; | |
| 149 | |
| 137 protected: | 150 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, | 151 Scheduler(SchedulerClient* client, |
| 168 const SchedulerSettings& scheduler_settings, | 152 const SchedulerSettings& scheduler_settings, |
| 169 int layer_tree_host_id, | 153 int layer_tree_host_id, |
| 170 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); | 154 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); |
| 171 | 155 |
| 156 // Two phase setup needed because C++ don't call the right virtual functions. | |
| 157 void FinalizeSetup(); | |
| 158 | |
| 159 // Overridable for testing. | |
| 172 virtual base::TimeTicks Now() const; | 160 virtual base::TimeTicks Now() const; |
| 161 virtual BeginFrameSource* GetPrimaryBeginFrameSource(); | |
| 162 virtual BeginFrameSource* GetBackgroundBeginFrameSource(); | |
| 173 | 163 |
| 174 const SchedulerSettings settings_; | 164 const SchedulerSettings settings_; |
| 175 SchedulerClient* client_; | 165 SchedulerClient* client_; |
| 176 int layer_tree_host_id_; | 166 int layer_tree_host_id_; |
| 177 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 167 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 178 | 168 |
| 179 base::TimeDelta vsync_interval_; | |
| 180 base::TimeDelta estimated_parent_draw_time_; | 169 base::TimeDelta estimated_parent_draw_time_; |
| 181 | 170 |
| 182 bool last_set_needs_begin_frame_; | |
| 183 bool begin_unthrottled_frame_posted_; | |
| 184 bool begin_retro_frame_posted_; | 171 bool begin_retro_frame_posted_; |
| 185 std::deque<BeginFrameArgs> begin_retro_frame_args_; | 172 std::deque<BeginFrameArgs> begin_retro_frame_args_; |
| 173 BeginFrameArgs last_begin_frame_args_; | |
|
Sami
2014/09/18 13:55:08
Is this ever set?
mithro-old
2014/09/19 02:45:39
It should have been, but has been removed now.
| |
| 186 BeginFrameArgs begin_impl_frame_args_; | 174 BeginFrameArgs begin_impl_frame_args_; |
| 187 | 175 |
| 188 scoped_ptr<SyntheticBeginFrameSource> synthetic_begin_frame_source_; | |
| 189 | |
| 190 base::Closure begin_retro_frame_closure_; | 176 base::Closure begin_retro_frame_closure_; |
| 191 base::Closure begin_unthrottled_frame_closure_; | 177 base::Closure begin_unthrottled_frame_closure_; |
| 192 | 178 |
| 193 base::Closure begin_impl_frame_deadline_closure_; | 179 base::Closure begin_impl_frame_deadline_closure_; |
| 194 base::Closure poll_for_draw_triggers_closure_; | 180 base::Closure poll_for_draw_triggers_closure_; |
| 195 base::Closure advance_commit_state_closure_; | 181 base::Closure advance_commit_state_closure_; |
| 196 base::CancelableClosure begin_impl_frame_deadline_task_; | 182 base::CancelableClosure begin_impl_frame_deadline_task_; |
| 197 base::CancelableClosure poll_for_draw_triggers_task_; | 183 base::CancelableClosure poll_for_draw_triggers_task_; |
| 198 base::CancelableClosure advance_commit_state_task_; | 184 base::CancelableClosure advance_commit_state_task_; |
| 199 | 185 |
| 200 SchedulerStateMachine state_machine_; | 186 SchedulerStateMachine state_machine_; |
| 201 bool inside_process_scheduled_actions_; | 187 bool inside_process_scheduled_actions_; |
| 202 SchedulerStateMachine::Action inside_action_; | 188 SchedulerStateMachine::Action inside_action_; |
| 203 | 189 |
| 204 base::TimeDelta VSyncInterval() { return vsync_interval_; } | |
| 205 | |
| 206 private: | 190 private: |
| 207 base::TimeTicks AdjustedBeginImplFrameDeadline( | 191 base::TimeTicks AdjustedBeginImplFrameDeadline( |
| 208 const BeginFrameArgs& args, | 192 const BeginFrameArgs& args, |
| 209 base::TimeDelta draw_duration_estimate) const; | 193 base::TimeDelta draw_duration_estimate) const; |
| 210 void ScheduleBeginImplFrameDeadline(base::TimeTicks deadline); | 194 void ScheduleBeginImplFrameDeadline(base::TimeTicks deadline); |
| 211 void SetupNextBeginFrameIfNeeded(); | 195 void SetupNextBeginFrameIfNeeded(); |
| 212 void PostBeginRetroFrameIfNeeded(); | 196 void PostBeginRetroFrameIfNeeded(); |
| 213 void SetupNextBeginFrameWhenVSyncThrottlingEnabled(bool needs_begin_frame); | |
| 214 void SetupNextBeginFrameWhenVSyncThrottlingDisabled(bool needs_begin_frame); | |
| 215 void SetupPollingMechanisms(bool needs_begin_frame); | 197 void SetupPollingMechanisms(bool needs_begin_frame); |
| 216 void DrawAndSwapIfPossible(); | 198 void DrawAndSwapIfPossible(); |
| 217 void ProcessScheduledActions(); | 199 void ProcessScheduledActions(); |
| 218 bool CanCommitAndActivateBeforeDeadline() const; | 200 bool CanCommitAndActivateBeforeDeadline() const; |
| 219 void AdvanceCommitStateIfPossible(); | 201 void AdvanceCommitStateIfPossible(); |
| 220 bool IsBeginMainFrameSentOrStarted() const; | 202 bool IsBeginMainFrameSentOrStarted() const; |
| 221 void SetupSyntheticBeginFrames(); | |
| 222 void BeginRetroFrame(); | 203 void BeginRetroFrame(); |
| 223 void BeginUnthrottledFrame(); | |
| 224 void BeginImplFrame(const BeginFrameArgs& args); | 204 void BeginImplFrame(const BeginFrameArgs& args); |
| 225 void OnBeginImplFrameDeadline(); | 205 void OnBeginImplFrameDeadline(); |
| 226 void PollForAnticipatedDrawTriggers(); | 206 void PollForAnticipatedDrawTriggers(); |
| 227 void PollToAdvanceCommitState(); | 207 void PollToAdvanceCommitState(); |
| 228 | 208 |
| 229 base::TimeDelta EstimatedParentDrawTime() { | 209 base::TimeDelta EstimatedParentDrawTime() { |
| 230 return estimated_parent_draw_time_; | 210 return estimated_parent_draw_time_; |
| 231 } | 211 } |
| 232 | 212 |
| 233 bool IsInsideAction(SchedulerStateMachine::Action action) { | 213 bool IsInsideAction(SchedulerStateMachine::Action action) { |
| 234 return inside_action_ == action; | 214 return inside_action_ == action; |
| 235 } | 215 } |
| 236 | 216 |
| 237 base::WeakPtrFactory<Scheduler> weak_factory_; | 217 base::WeakPtrFactory<Scheduler> weak_factory_; |
| 238 | 218 |
| 239 DISALLOW_COPY_AND_ASSIGN(Scheduler); | 219 DISALLOW_COPY_AND_ASSIGN(Scheduler); |
| 240 }; | 220 }; |
| 241 | 221 |
| 242 } // namespace cc | 222 } // namespace cc |
| 243 | 223 |
| 244 #endif // CC_SCHEDULER_SCHEDULER_H_ | 224 #endif // CC_SCHEDULER_SCHEDULER_H_ |
| OLD | NEW |