| 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* ExternalBeginFrameSource() = 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 Scheduler; |
| 56 // This class exists to allow tests to override the frame source construction. |
| 57 // A virtual method can't be used as this needs to happen in the constructor |
| 58 // (see C++ FAQ / Section 23 - http://goo.gl/fnrwom for why). |
| 59 // This class exists solely long enough to construct the frame sources. |
| 60 class CC_EXPORT SchedulerFrameSourcesConstructor { |
| 61 public: |
| 62 virtual ~SchedulerFrameSourcesConstructor() {} |
| 63 virtual BeginFrameSource* ConstructPrimaryFrameSource(Scheduler* scheduler); |
| 64 virtual BeginFrameSource* ConstructBackgroundFrameSource( |
| 65 Scheduler* scheduler); |
| 66 |
| 67 protected: |
| 68 SchedulerFrameSourcesConstructor() {} |
| 69 |
| 70 friend class Scheduler; |
| 71 }; |
| 72 |
| 73 class CC_EXPORT Scheduler : public BeginFrameObserverImpl { |
| 55 public: | 74 public: |
| 56 static scoped_ptr<Scheduler> Create( | 75 static scoped_ptr<Scheduler> Create( |
| 57 SchedulerClient* client, | 76 SchedulerClient* client, |
| 58 const SchedulerSettings& scheduler_settings, | 77 const SchedulerSettings& scheduler_settings, |
| 59 int layer_tree_host_id, | 78 int layer_tree_host_id, |
| 60 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { | 79 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { |
| 61 return make_scoped_ptr(new Scheduler( | 80 SchedulerFrameSourcesConstructor frame_sources_constructor; |
| 62 client, scheduler_settings, layer_tree_host_id, task_runner)); | 81 return make_scoped_ptr(new Scheduler(client, |
| 82 scheduler_settings, |
| 83 layer_tree_host_id, |
| 84 task_runner, |
| 85 &frame_sources_constructor)); |
| 63 } | 86 } |
| 64 | 87 |
| 65 virtual ~Scheduler(); | 88 virtual ~Scheduler(); |
| 66 | 89 |
| 67 const SchedulerSettings& settings() const { return settings_; } | 90 const SchedulerSettings& settings() const { return settings_; } |
| 68 | 91 |
| 69 void CommitVSyncParameters(base::TimeTicks timebase, | 92 void CommitVSyncParameters(base::TimeTicks timebase, |
| 70 base::TimeDelta interval); | 93 base::TimeDelta interval); |
| 71 void SetEstimatedParentDrawTime(base::TimeDelta draw_time); | 94 void SetEstimatedParentDrawTime(base::TimeDelta draw_time); |
| 72 | 95 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 bool BeginImplFrameDeadlinePending() const { | 139 bool BeginImplFrameDeadlinePending() const { |
| 117 return !begin_impl_frame_deadline_task_.IsCancelled(); | 140 return !begin_impl_frame_deadline_task_.IsCancelled(); |
| 118 } | 141 } |
| 119 | 142 |
| 120 bool WillDrawIfNeeded() const; | 143 bool WillDrawIfNeeded() const; |
| 121 | 144 |
| 122 base::TimeTicks AnticipatedDrawTime() const; | 145 base::TimeTicks AnticipatedDrawTime() const; |
| 123 | 146 |
| 124 void NotifyBeginMainFrameStarted(); | 147 void NotifyBeginMainFrameStarted(); |
| 125 | 148 |
| 126 base::TimeTicks LastBeginImplFrameTime(); | |
| 127 | |
| 128 void BeginFrame(const BeginFrameArgs& args); | |
| 129 | |
| 130 scoped_refptr<base::debug::ConvertableToTraceFormat> AsValue() const; | 149 scoped_refptr<base::debug::ConvertableToTraceFormat> AsValue() const; |
| 131 void AsValueInto(base::debug::TracedValue* state) const; | 150 virtual void AsValueInto(base::debug::TracedValue* value) const OVERRIDE; |
| 132 | 151 |
| 133 void SetContinuousPainting(bool continuous_painting) { | 152 void SetContinuousPainting(bool continuous_painting) { |
| 134 state_machine_.SetContinuousPainting(continuous_painting); | 153 state_machine_.SetContinuousPainting(continuous_painting); |
| 135 } | 154 } |
| 136 | 155 |
| 156 base::TimeTicks LastBeginImplFrameTime(); |
| 157 |
| 158 // BeginFrameObserver |
| 159 virtual bool OnBeginFrameImpl(const BeginFrameArgs& args) OVERRIDE; |
| 160 virtual void OnMissedBeginFrame(const BeginFrameArgs& args) OVERRIDE; |
| 161 |
| 137 protected: | 162 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, | 163 Scheduler(SchedulerClient* client, |
| 168 const SchedulerSettings& scheduler_settings, | 164 const SchedulerSettings& scheduler_settings, |
| 169 int layer_tree_host_id, | 165 int layer_tree_host_id, |
| 170 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); | 166 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 167 SchedulerFrameSourcesConstructor* frame_sources_constructor); |
| 171 | 168 |
| 169 // virtual for testing - Don't call these in the constructor or |
| 170 // destructor! |
| 172 virtual base::TimeTicks Now() const; | 171 virtual base::TimeTicks Now() const; |
| 173 | 172 |
| 173 scoped_ptr<BeginFrameSourceMultiplexer> frame_source_; |
| 174 BeginFrameSource* primary_frame_source_; |
| 175 BeginFrameSource* background_frame_source_; |
| 176 |
| 177 // Storage when frame sources are internal |
| 178 scoped_ptr<BeginFrameSource> primary_frame_source_internal_; |
| 179 scoped_ptr<SyntheticBeginFrameSource> background_frame_source_internal_; |
| 180 |
| 181 ui::CompositorVSyncManager::Observer* vsync_observer_; |
| 182 |
| 174 const SchedulerSettings settings_; | 183 const SchedulerSettings settings_; |
| 175 SchedulerClient* client_; | 184 SchedulerClient* client_; |
| 176 int layer_tree_host_id_; | 185 int layer_tree_host_id_; |
| 177 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 186 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 178 | 187 |
| 179 base::TimeDelta vsync_interval_; | |
| 180 base::TimeDelta estimated_parent_draw_time_; | 188 base::TimeDelta estimated_parent_draw_time_; |
| 181 | 189 |
| 182 bool last_set_needs_begin_frame_; | |
| 183 bool begin_unthrottled_frame_posted_; | |
| 184 bool begin_retro_frame_posted_; | 190 bool begin_retro_frame_posted_; |
| 185 std::deque<BeginFrameArgs> begin_retro_frame_args_; | 191 std::deque<BeginFrameArgs> begin_retro_frame_args_; |
| 186 BeginFrameArgs begin_impl_frame_args_; | 192 BeginFrameArgs begin_impl_frame_args_; |
| 187 | 193 |
| 188 scoped_ptr<SyntheticBeginFrameSource> synthetic_begin_frame_source_; | |
| 189 | |
| 190 base::Closure begin_retro_frame_closure_; | 194 base::Closure begin_retro_frame_closure_; |
| 191 base::Closure begin_unthrottled_frame_closure_; | 195 base::Closure begin_unthrottled_frame_closure_; |
| 192 | 196 |
| 193 base::Closure begin_impl_frame_deadline_closure_; | 197 base::Closure begin_impl_frame_deadline_closure_; |
| 194 base::Closure poll_for_draw_triggers_closure_; | 198 base::Closure poll_for_draw_triggers_closure_; |
| 195 base::Closure advance_commit_state_closure_; | 199 base::Closure advance_commit_state_closure_; |
| 196 base::CancelableClosure begin_impl_frame_deadline_task_; | 200 base::CancelableClosure begin_impl_frame_deadline_task_; |
| 197 base::CancelableClosure poll_for_draw_triggers_task_; | 201 base::CancelableClosure poll_for_draw_triggers_task_; |
| 198 base::CancelableClosure advance_commit_state_task_; | 202 base::CancelableClosure advance_commit_state_task_; |
| 199 | 203 |
| 200 SchedulerStateMachine state_machine_; | 204 SchedulerStateMachine state_machine_; |
| 201 bool inside_process_scheduled_actions_; | 205 bool inside_process_scheduled_actions_; |
| 202 SchedulerStateMachine::Action inside_action_; | 206 SchedulerStateMachine::Action inside_action_; |
| 203 | 207 |
| 204 base::TimeDelta VSyncInterval() { return vsync_interval_; } | |
| 205 | |
| 206 private: | 208 private: |
| 207 base::TimeTicks AdjustedBeginImplFrameDeadline( | 209 base::TimeTicks AdjustedBeginImplFrameDeadline( |
| 208 const BeginFrameArgs& args, | 210 const BeginFrameArgs& args, |
| 209 base::TimeDelta draw_duration_estimate) const; | 211 base::TimeDelta draw_duration_estimate) const; |
| 210 void ScheduleBeginImplFrameDeadline(base::TimeTicks deadline); | 212 void ScheduleBeginImplFrameDeadline(base::TimeTicks deadline); |
| 211 void SetupNextBeginFrameIfNeeded(); | 213 void SetupNextBeginFrameIfNeeded(); |
| 212 void PostBeginRetroFrameIfNeeded(); | 214 void PostBeginRetroFrameIfNeeded(); |
| 213 void SetupNextBeginFrameWhenVSyncThrottlingEnabled(bool needs_begin_frame); | |
| 214 void SetupNextBeginFrameWhenVSyncThrottlingDisabled(bool needs_begin_frame); | |
| 215 void SetupPollingMechanisms(bool needs_begin_frame); | 215 void SetupPollingMechanisms(bool needs_begin_frame); |
| 216 void DrawAndSwapIfPossible(); | 216 void DrawAndSwapIfPossible(); |
| 217 void ProcessScheduledActions(); | 217 void ProcessScheduledActions(); |
| 218 bool CanCommitAndActivateBeforeDeadline() const; | 218 bool CanCommitAndActivateBeforeDeadline() const; |
| 219 void AdvanceCommitStateIfPossible(); | 219 void AdvanceCommitStateIfPossible(); |
| 220 bool IsBeginMainFrameSentOrStarted() const; | 220 bool IsBeginMainFrameSentOrStarted() const; |
| 221 void SetupSyntheticBeginFrames(); | |
| 222 void BeginRetroFrame(); | 221 void BeginRetroFrame(); |
| 223 void BeginUnthrottledFrame(); | |
| 224 void BeginImplFrame(const BeginFrameArgs& args); | 222 void BeginImplFrame(const BeginFrameArgs& args); |
| 225 void OnBeginImplFrameDeadline(); | 223 void OnBeginImplFrameDeadline(); |
| 226 void PollForAnticipatedDrawTriggers(); | 224 void PollForAnticipatedDrawTriggers(); |
| 227 void PollToAdvanceCommitState(); | 225 void PollToAdvanceCommitState(); |
| 228 | 226 |
| 229 base::TimeDelta EstimatedParentDrawTime() { | 227 base::TimeDelta EstimatedParentDrawTime() { |
| 230 return estimated_parent_draw_time_; | 228 return estimated_parent_draw_time_; |
| 231 } | 229 } |
| 232 | 230 |
| 233 bool IsInsideAction(SchedulerStateMachine::Action action) { | 231 bool IsInsideAction(SchedulerStateMachine::Action action) { |
| 234 return inside_action_ == action; | 232 return inside_action_ == action; |
| 235 } | 233 } |
| 236 | 234 |
| 237 base::WeakPtrFactory<Scheduler> weak_factory_; | 235 base::WeakPtrFactory<Scheduler> weak_factory_; |
| 238 | 236 |
| 237 friend class SchedulerFrameSourcesConstructor; |
| 238 friend class TestSchedulerFrameSourcesConstructor; |
| 239 |
| 239 DISALLOW_COPY_AND_ASSIGN(Scheduler); | 240 DISALLOW_COPY_AND_ASSIGN(Scheduler); |
| 240 }; | 241 }; |
| 241 | 242 |
| 242 } // namespace cc | 243 } // namespace cc |
| 243 | 244 |
| 244 #endif // CC_SCHEDULER_SCHEDULER_H_ | 245 #endif // CC_SCHEDULER_SCHEDULER_H_ |
| OLD | NEW |