| 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* GetBeginFrameSource() = 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 return 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)); |
| 63 } | 64 } |
| 64 | 65 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 bool BeginImplFrameDeadlinePending() const { | 117 bool BeginImplFrameDeadlinePending() const { |
| 117 return !begin_impl_frame_deadline_task_.IsCancelled(); | 118 return !begin_impl_frame_deadline_task_.IsCancelled(); |
| 118 } | 119 } |
| 119 | 120 |
| 120 bool WillDrawIfNeeded() const; | 121 bool WillDrawIfNeeded() const; |
| 121 | 122 |
| 122 base::TimeTicks AnticipatedDrawTime() const; | 123 base::TimeTicks AnticipatedDrawTime() const; |
| 123 | 124 |
| 124 void NotifyBeginMainFrameStarted(); | 125 void NotifyBeginMainFrameStarted(); |
| 125 | 126 |
| 126 base::TimeTicks LastBeginImplFrameTime(); | 127 virtual void AsValueInto(base::debug::TracedValue* value) const OVERRIDE; |
| 127 | |
| 128 void BeginFrame(const BeginFrameArgs& args); | |
| 129 | |
| 130 scoped_refptr<base::debug::ConvertableToTraceFormat> AsValue() const; | 128 scoped_refptr<base::debug::ConvertableToTraceFormat> AsValue() const; |
| 131 | 129 |
| 132 void SetContinuousPainting(bool continuous_painting) { | 130 void SetContinuousPainting(bool continuous_painting) { |
| 133 state_machine_.SetContinuousPainting(continuous_painting); | 131 state_machine_.SetContinuousPainting(continuous_painting); |
| 134 } | 132 } |
| 135 | 133 |
| 134 virtual void OnBeginFrame(const BeginFrameArgs& args) OVERRIDE; |
| 135 virtual const BeginFrameArgs& LastBeginFrameArgs() const OVERRIDE; |
| 136 base::TimeTicks LastBeginImplFrameTime(); |
| 137 |
| 138 ui::CompositorVSyncManager::Observer* vsync_observer_; |
| 139 scoped_ptr<BeginFrameSourceMultiplexer> frame_source_; |
| 140 BeginFrameSource* primary_frame_source_; |
| 141 scoped_ptr<BeginFrameSource> primary_frame_source_store_; |
| 142 scoped_ptr<SyntheticBeginFrameSource> background_frame_source_store_; |
| 143 |
| 136 protected: | 144 protected: |
| 137 class CC_EXPORT SyntheticBeginFrameSource : public TimeSourceClient { | |
| 138 public: | |
| 139 SyntheticBeginFrameSource(Scheduler* scheduler, | |
| 140 scoped_refptr<DelayBasedTimeSource> time_source); | |
| 141 virtual ~SyntheticBeginFrameSource(); | |
| 142 | |
| 143 // Updates the phase and frequency of the timer. | |
| 144 void CommitVSyncParameters(base::TimeTicks timebase, | |
| 145 base::TimeDelta interval); | |
| 146 | |
| 147 // Activates future BeginFrames and, if activating, pushes the most | |
| 148 // recently missed BeginFrame to the back of a retroactive queue. | |
| 149 void SetNeedsBeginFrame(bool needs_begin_frame, | |
| 150 std::deque<BeginFrameArgs>* begin_retro_frame_args); | |
| 151 | |
| 152 bool IsActive() const; | |
| 153 | |
| 154 // TimeSourceClient implementation of OnTimerTick triggers a BeginFrame. | |
| 155 virtual void OnTimerTick() OVERRIDE; | |
| 156 | |
| 157 void AsValueInto(base::debug::TracedValue* dict) const; | |
| 158 | |
| 159 private: | |
| 160 BeginFrameArgs CreateSyntheticBeginFrameArgs(base::TimeTicks frame_time); | |
| 161 | |
| 162 Scheduler* scheduler_; | |
| 163 scoped_refptr<DelayBasedTimeSource> time_source_; | |
| 164 }; | |
| 165 | |
| 166 Scheduler(SchedulerClient* client, | 145 Scheduler(SchedulerClient* client, |
| 167 const SchedulerSettings& scheduler_settings, | 146 const SchedulerSettings& scheduler_settings, |
| 168 int layer_tree_host_id, | 147 int layer_tree_host_id, |
| 169 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); | 148 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); |
| 170 | 149 |
| 150 // Overridable for testing. |
| 151 virtual void SetUpBackgroundFrameSource(); |
| 152 virtual void SetUpPrimaryFrameSource(); |
| 171 virtual base::TimeTicks Now() const; | 153 virtual base::TimeTicks Now() const; |
| 172 | 154 |
| 173 const SchedulerSettings settings_; | 155 const SchedulerSettings settings_; |
| 174 SchedulerClient* client_; | 156 SchedulerClient* client_; |
| 175 int layer_tree_host_id_; | 157 int layer_tree_host_id_; |
| 176 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 158 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 177 | 159 |
| 178 base::TimeDelta vsync_interval_; | |
| 179 base::TimeDelta estimated_parent_draw_time_; | 160 base::TimeDelta estimated_parent_draw_time_; |
| 180 | 161 |
| 181 bool last_set_needs_begin_frame_; | |
| 182 bool begin_unthrottled_frame_posted_; | |
| 183 bool begin_retro_frame_posted_; | 162 bool begin_retro_frame_posted_; |
| 184 std::deque<BeginFrameArgs> begin_retro_frame_args_; | 163 std::deque<BeginFrameArgs> begin_retro_frame_args_; |
| 164 BeginFrameArgs last_begin_frame_args_; |
| 185 BeginFrameArgs begin_impl_frame_args_; | 165 BeginFrameArgs begin_impl_frame_args_; |
| 186 | 166 |
| 187 scoped_ptr<SyntheticBeginFrameSource> synthetic_begin_frame_source_; | |
| 188 | |
| 189 base::Closure begin_retro_frame_closure_; | 167 base::Closure begin_retro_frame_closure_; |
| 190 base::Closure begin_unthrottled_frame_closure_; | 168 base::Closure begin_unthrottled_frame_closure_; |
| 191 | 169 |
| 192 base::Closure begin_impl_frame_deadline_closure_; | 170 base::Closure begin_impl_frame_deadline_closure_; |
| 193 base::Closure poll_for_draw_triggers_closure_; | 171 base::Closure poll_for_draw_triggers_closure_; |
| 194 base::Closure advance_commit_state_closure_; | 172 base::Closure advance_commit_state_closure_; |
| 195 base::CancelableClosure begin_impl_frame_deadline_task_; | 173 base::CancelableClosure begin_impl_frame_deadline_task_; |
| 196 base::CancelableClosure poll_for_draw_triggers_task_; | 174 base::CancelableClosure poll_for_draw_triggers_task_; |
| 197 base::CancelableClosure advance_commit_state_task_; | 175 base::CancelableClosure advance_commit_state_task_; |
| 198 | 176 |
| 199 SchedulerStateMachine state_machine_; | 177 SchedulerStateMachine state_machine_; |
| 200 bool inside_process_scheduled_actions_; | 178 bool inside_process_scheduled_actions_; |
| 201 SchedulerStateMachine::Action inside_action_; | 179 SchedulerStateMachine::Action inside_action_; |
| 202 | 180 |
| 203 base::TimeDelta VSyncInterval() { return vsync_interval_; } | |
| 204 | |
| 205 private: | 181 private: |
| 206 base::TimeTicks AdjustedBeginImplFrameDeadline( | 182 base::TimeTicks AdjustedBeginImplFrameDeadline( |
| 207 const BeginFrameArgs& args, | 183 const BeginFrameArgs& args, |
| 208 base::TimeDelta draw_duration_estimate) const; | 184 base::TimeDelta draw_duration_estimate) const; |
| 209 void ScheduleBeginImplFrameDeadline(base::TimeTicks deadline); | 185 void ScheduleBeginImplFrameDeadline(base::TimeTicks deadline); |
| 210 void SetupNextBeginFrameIfNeeded(); | 186 void SetupNextBeginFrameIfNeeded(); |
| 211 void PostBeginRetroFrameIfNeeded(); | 187 void PostBeginRetroFrameIfNeeded(); |
| 212 void SetupNextBeginFrameWhenVSyncThrottlingEnabled(bool needs_begin_frame); | |
| 213 void SetupNextBeginFrameWhenVSyncThrottlingDisabled(bool needs_begin_frame); | |
| 214 void SetupPollingMechanisms(bool needs_begin_frame); | 188 void SetupPollingMechanisms(bool needs_begin_frame); |
| 215 void DrawAndSwapIfPossible(); | 189 void DrawAndSwapIfPossible(); |
| 216 void ProcessScheduledActions(); | 190 void ProcessScheduledActions(); |
| 217 bool CanCommitAndActivateBeforeDeadline() const; | 191 bool CanCommitAndActivateBeforeDeadline() const; |
| 218 void AdvanceCommitStateIfPossible(); | 192 void AdvanceCommitStateIfPossible(); |
| 219 bool IsBeginMainFrameSentOrStarted() const; | 193 bool IsBeginMainFrameSentOrStarted() const; |
| 220 void SetupSyntheticBeginFrames(); | |
| 221 void BeginRetroFrame(); | 194 void BeginRetroFrame(); |
| 222 void BeginUnthrottledFrame(); | |
| 223 void BeginImplFrame(const BeginFrameArgs& args); | 195 void BeginImplFrame(const BeginFrameArgs& args); |
| 224 void OnBeginImplFrameDeadline(); | 196 void OnBeginImplFrameDeadline(); |
| 225 void PollForAnticipatedDrawTriggers(); | 197 void PollForAnticipatedDrawTriggers(); |
| 226 void PollToAdvanceCommitState(); | 198 void PollToAdvanceCommitState(); |
| 227 | 199 |
| 228 base::TimeDelta EstimatedParentDrawTime() { | 200 base::TimeDelta EstimatedParentDrawTime() { |
| 229 return estimated_parent_draw_time_; | 201 return estimated_parent_draw_time_; |
| 230 } | 202 } |
| 231 | 203 |
| 232 bool IsInsideAction(SchedulerStateMachine::Action action) { | 204 bool IsInsideAction(SchedulerStateMachine::Action action) { |
| 233 return inside_action_ == action; | 205 return inside_action_ == action; |
| 234 } | 206 } |
| 235 | 207 |
| 236 base::WeakPtrFactory<Scheduler> weak_factory_; | 208 base::WeakPtrFactory<Scheduler> weak_factory_; |
| 237 | 209 |
| 238 DISALLOW_COPY_AND_ASSIGN(Scheduler); | 210 DISALLOW_COPY_AND_ASSIGN(Scheduler); |
| 239 }; | 211 }; |
| 240 | 212 |
| 241 } // namespace cc | 213 } // namespace cc |
| 242 | 214 |
| 243 #endif // CC_SCHEDULER_SCHEDULER_H_ | 215 #endif // CC_SCHEDULER_SCHEDULER_H_ |
| OLD | NEW |