| 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/draw_swap_readback_result.h" | 17 #include "cc/scheduler/draw_swap_readback_result.h" |
| 18 #include "cc/scheduler/scheduler_settings.h" | 18 #include "cc/scheduler/scheduler_settings.h" |
| 19 #include "cc/scheduler/scheduler_state_machine.h" | 19 #include "cc/scheduler/scheduler_state_machine.h" |
| 20 #include "cc/scheduler/time_source.h" |
| 20 #include "cc/trees/layer_tree_host.h" | 21 #include "cc/trees/layer_tree_host.h" |
| 21 | 22 |
| 22 namespace cc { | 23 namespace cc { |
| 23 | 24 |
| 24 class Thread; | 25 class Thread; |
| 26 class SyntheticBeginFrameSource; |
| 25 | 27 |
| 26 class SchedulerClient { | 28 class SchedulerClient { |
| 27 public: | 29 public: |
| 28 virtual void SetNeedsBeginFrame(bool enable) = 0; | 30 virtual void SetNeedsBeginFrame(bool enable) = 0; |
| 29 virtual void WillBeginImplFrame(const BeginFrameArgs& args) = 0; | 31 virtual void WillBeginImplFrame(const BeginFrameArgs& args) = 0; |
| 30 virtual void ScheduledActionSendBeginMainFrame() = 0; | 32 virtual void ScheduledActionSendBeginMainFrame() = 0; |
| 31 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() = 0; | 33 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() = 0; |
| 32 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapForced() = 0; | 34 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapForced() = 0; |
| 33 virtual DrawSwapReadbackResult ScheduledActionDrawAndReadback() = 0; | 35 virtual DrawSwapReadbackResult ScheduledActionDrawAndReadback() = 0; |
| 34 virtual void ScheduledActionCommit() = 0; | 36 virtual void ScheduledActionCommit() = 0; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 45 protected: | 47 protected: |
| 46 virtual ~SchedulerClient() {} | 48 virtual ~SchedulerClient() {} |
| 47 }; | 49 }; |
| 48 | 50 |
| 49 class CC_EXPORT Scheduler { | 51 class CC_EXPORT Scheduler { |
| 50 public: | 52 public: |
| 51 static scoped_ptr<Scheduler> Create( | 53 static scoped_ptr<Scheduler> Create( |
| 52 SchedulerClient* client, | 54 SchedulerClient* client, |
| 53 const SchedulerSettings& scheduler_settings, | 55 const SchedulerSettings& scheduler_settings, |
| 54 int layer_tree_host_id, | 56 int layer_tree_host_id, |
| 55 const scoped_refptr<base::SequencedTaskRunner>& impl_task_runner) { | 57 const scoped_refptr<base::SingleThreadTaskRunner>& impl_task_runner) { |
| 56 return make_scoped_ptr(new Scheduler( | 58 return make_scoped_ptr(new Scheduler( |
| 57 client, scheduler_settings, layer_tree_host_id, impl_task_runner)); | 59 client, scheduler_settings, layer_tree_host_id, impl_task_runner)); |
| 58 } | 60 } |
| 59 | 61 |
| 60 virtual ~Scheduler(); | 62 virtual ~Scheduler(); |
| 61 | 63 |
| 64 const SchedulerSettings& settings() const { return settings_; } |
| 65 |
| 66 void CommitVSyncParameters(base::TimeTicks timebase, |
| 67 base::TimeDelta interval); |
| 68 void SetEstimatedParentDrawTime(base::TimeDelta draw_time); |
| 69 |
| 62 void SetCanStart(); | 70 void SetCanStart(); |
| 63 | 71 |
| 64 void SetVisible(bool visible); | 72 void SetVisible(bool visible); |
| 65 void SetCanDraw(bool can_draw); | 73 void SetCanDraw(bool can_draw); |
| 66 void NotifyReadyToActivate(); | 74 void NotifyReadyToActivate(); |
| 67 | 75 |
| 68 void SetNeedsCommit(); | 76 void SetNeedsCommit(); |
| 69 | 77 |
| 70 // Like SetNeedsCommit(), but ensures a commit will definitely happen even if | 78 // Like SetNeedsCommit(), but ensures a commit will definitely happen even if |
| 71 // we are not visible. Will eventually result in a forced draw internally. | 79 // we are not visible. Will eventually result in a forced draw internally. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 return !begin_impl_frame_deadline_task_.IsCancelled(); | 112 return !begin_impl_frame_deadline_task_.IsCancelled(); |
| 105 } | 113 } |
| 106 | 114 |
| 107 bool WillDrawIfNeeded() const; | 115 bool WillDrawIfNeeded() const; |
| 108 | 116 |
| 109 base::TimeTicks AnticipatedDrawTime() const; | 117 base::TimeTicks AnticipatedDrawTime() const; |
| 110 | 118 |
| 111 void NotifyBeginMainFrameStarted(); | 119 void NotifyBeginMainFrameStarted(); |
| 112 | 120 |
| 113 base::TimeTicks LastBeginImplFrameTime(); | 121 base::TimeTicks LastBeginImplFrameTime(); |
| 122 base::TimeDelta VSyncInterval() { return vsync_interval_; } |
| 123 base::TimeDelta EstimatedParentDrawTime() { |
| 124 return estimated_parent_draw_time_; |
| 125 } |
| 114 | 126 |
| 115 void BeginFrame(const BeginFrameArgs& args); | 127 void BeginFrame(const BeginFrameArgs& args); |
| 128 void PostBeginRetroFrame(); |
| 116 void BeginRetroFrame(); | 129 void BeginRetroFrame(); |
| 130 void BeginUnthrottledFrame(); |
| 131 |
| 117 void BeginImplFrame(const BeginFrameArgs& args); | 132 void BeginImplFrame(const BeginFrameArgs& args); |
| 118 void OnBeginImplFrameDeadline(); | 133 void OnBeginImplFrameDeadline(); |
| 119 void PollForAnticipatedDrawTriggers(); | 134 void PollForAnticipatedDrawTriggers(); |
| 120 void PollToAdvanceCommitState(); | 135 void PollToAdvanceCommitState(); |
| 121 | 136 |
| 122 scoped_ptr<base::Value> StateAsValue() const; | 137 scoped_ptr<base::Value> StateAsValue() const; |
| 123 | 138 |
| 124 bool IsInsideAction(SchedulerStateMachine::Action action) { | 139 bool IsInsideAction(SchedulerStateMachine::Action action) { |
| 125 return inside_action_ == action; | 140 return inside_action_ == action; |
| 126 } | 141 } |
| 127 | 142 |
| 128 bool IsBeginMainFrameSent() const; | 143 bool IsBeginMainFrameSent() const; |
| 129 void SetContinuousPainting(bool continuous_painting) { | 144 void SetContinuousPainting(bool continuous_painting) { |
| 130 state_machine_.SetContinuousPainting(continuous_painting); | 145 state_machine_.SetContinuousPainting(continuous_painting); |
| 131 } | 146 } |
| 132 | 147 |
| 133 private: | 148 private: |
| 134 Scheduler(SchedulerClient* client, | 149 Scheduler( |
| 135 const SchedulerSettings& scheduler_settings, | 150 SchedulerClient* client, |
| 136 int layer_tree_host_id, | 151 const SchedulerSettings& scheduler_settings, |
| 137 const scoped_refptr<base::SequencedTaskRunner>& impl_task_runner); | 152 int layer_tree_host_id, |
| 153 const scoped_refptr<base::SingleThreadTaskRunner>& impl_task_runner); |
| 138 | 154 |
| 139 base::TimeTicks AdjustedBeginImplFrameDeadline( | 155 base::TimeTicks AdjustedBeginImplFrameDeadline( |
| 140 const BeginFrameArgs& args, | 156 const BeginFrameArgs& args, |
| 141 base::TimeDelta draw_duration_estimate) const; | 157 base::TimeDelta draw_duration_estimate) const; |
| 142 void ScheduleBeginImplFrameDeadline(base::TimeTicks deadline); | 158 void ScheduleBeginImplFrameDeadline(base::TimeTicks deadline); |
| 143 void SetupNextBeginFrameIfNeeded(); | 159 void SetupNextBeginFrameIfNeeded(); |
| 144 void PostBeginRetroFrameIfNeeded(); | 160 void PostBeginRetroFrameIfNeeded(); |
| 161 void SetupNextBeginFrameWhenVSyncThrottlingEnabled(bool needs_begin_frame); |
| 162 void SetupNextBeginFrameWhenVSyncThrottlingDisabled(bool needs_begin_frame); |
| 163 void SetupPollingMechanisms(bool needs_begin_frame); |
| 145 void ActivatePendingTree(); | 164 void ActivatePendingTree(); |
| 146 void DrawAndSwapIfPossible(); | 165 void DrawAndSwapIfPossible(); |
| 147 void DrawAndSwapForced(); | 166 void DrawAndSwapForced(); |
| 148 void DrawAndReadback(); | 167 void DrawAndReadback(); |
| 149 void ProcessScheduledActions(); | 168 void ProcessScheduledActions(); |
| 150 | 169 |
| 151 bool CanCommitAndActivateBeforeDeadline() const; | 170 bool CanCommitAndActivateBeforeDeadline() const; |
| 152 void AdvanceCommitStateIfPossible(); | 171 void AdvanceCommitStateIfPossible(); |
| 153 | 172 |
| 154 bool IsBeginMainFrameSentOrStarted() const; | 173 bool IsBeginMainFrameSentOrStarted() const; |
| 155 | 174 |
| 156 const SchedulerSettings settings_; | 175 const SchedulerSettings settings_; |
| 157 SchedulerClient* client_; | 176 SchedulerClient* client_; |
| 158 int layer_tree_host_id_; | 177 int layer_tree_host_id_; |
| 159 scoped_refptr<base::SequencedTaskRunner> impl_task_runner_; | 178 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner_; |
| 179 |
| 180 base::TimeDelta vsync_interval_; |
| 181 base::TimeDelta estimated_parent_draw_time_; |
| 160 | 182 |
| 161 bool last_set_needs_begin_frame_; | 183 bool last_set_needs_begin_frame_; |
| 184 bool begin_unthrottled_frame_posted_; |
| 162 bool begin_retro_frame_posted_; | 185 bool begin_retro_frame_posted_; |
| 163 | |
| 164 std::deque<BeginFrameArgs> begin_retro_frame_args_; | 186 std::deque<BeginFrameArgs> begin_retro_frame_args_; |
| 165 BeginFrameArgs begin_impl_frame_args_; | 187 BeginFrameArgs begin_impl_frame_args_; |
| 166 | 188 |
| 189 void SetupSyntheticBeginFrames(); |
| 190 scoped_ptr<SyntheticBeginFrameSource> synthetic_begin_frame_source_; |
| 191 |
| 167 base::Closure begin_retro_frame_closure_; | 192 base::Closure begin_retro_frame_closure_; |
| 193 base::Closure begin_unthrottled_frame_closure_; |
| 194 |
| 168 base::Closure begin_impl_frame_deadline_closure_; | 195 base::Closure begin_impl_frame_deadline_closure_; |
| 169 base::Closure poll_for_draw_triggers_closure_; | 196 base::Closure poll_for_draw_triggers_closure_; |
| 170 base::Closure advance_commit_state_closure_; | 197 base::Closure advance_commit_state_closure_; |
| 171 base::CancelableClosure begin_impl_frame_deadline_task_; | 198 base::CancelableClosure begin_impl_frame_deadline_task_; |
| 172 base::CancelableClosure poll_for_draw_triggers_task_; | 199 base::CancelableClosure poll_for_draw_triggers_task_; |
| 173 base::CancelableClosure advance_commit_state_task_; | 200 base::CancelableClosure advance_commit_state_task_; |
| 174 | 201 |
| 175 SchedulerStateMachine state_machine_; | 202 SchedulerStateMachine state_machine_; |
| 176 bool inside_process_scheduled_actions_; | 203 bool inside_process_scheduled_actions_; |
| 177 SchedulerStateMachine::Action inside_action_; | 204 SchedulerStateMachine::Action inside_action_; |
| 178 | 205 |
| 179 base::WeakPtrFactory<Scheduler> weak_factory_; | 206 base::WeakPtrFactory<Scheduler> weak_factory_; |
| 180 | 207 |
| 181 DISALLOW_COPY_AND_ASSIGN(Scheduler); | 208 DISALLOW_COPY_AND_ASSIGN(Scheduler); |
| 182 }; | 209 }; |
| 183 | 210 |
| 184 } // namespace cc | 211 } // namespace cc |
| 185 | 212 |
| 186 #endif // CC_SCHEDULER_SCHEDULER_H_ | 213 #endif // CC_SCHEDULER_SCHEDULER_H_ |
| OLD | NEW |