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/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 void CommitVSyncParameters(base::TimeTicks timebase, | |
| 65 base::TimeDelta interval); | |
| 66 void SetEstimatedParentDrawTime(base::TimeDelta draw_time); | |
| 67 | |
| 62 void SetCanStart(); | 68 void SetCanStart(); |
| 63 | 69 |
| 64 void SetVisible(bool visible); | 70 void SetVisible(bool visible); |
| 65 void SetCanDraw(bool can_draw); | 71 void SetCanDraw(bool can_draw); |
| 66 void NotifyReadyToActivate(); | 72 void NotifyReadyToActivate(); |
| 67 | 73 |
| 68 void SetNeedsCommit(); | 74 void SetNeedsCommit(); |
| 69 | 75 |
| 70 // Like SetNeedsCommit(), but ensures a commit will definitely happen even if | 76 // Like SetNeedsCommit(), but ensures a commit will definitely happen even if |
| 71 // we are not visible. Will eventually result in a forced draw internally. | 77 // 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(); | 110 return !begin_impl_frame_deadline_task_.IsCancelled(); |
| 105 } | 111 } |
| 106 | 112 |
| 107 bool WillDrawIfNeeded() const; | 113 bool WillDrawIfNeeded() const; |
| 108 | 114 |
| 109 base::TimeTicks AnticipatedDrawTime() const; | 115 base::TimeTicks AnticipatedDrawTime() const; |
| 110 | 116 |
| 111 void NotifyBeginMainFrameStarted(); | 117 void NotifyBeginMainFrameStarted(); |
| 112 | 118 |
| 113 base::TimeTicks LastBeginImplFrameTime(); | 119 base::TimeTicks LastBeginImplFrameTime(); |
| 120 base::TimeDelta VSyncInterval() { return vsync_interval_; } | |
| 121 base::TimeDelta EstimatedParentDrawTime() { | |
| 122 return estimated_parent_draw_time_; | |
| 123 } | |
| 114 | 124 |
| 115 void BeginFrame(const BeginFrameArgs& args); | 125 void BeginFrame(const BeginFrameArgs& args); |
| 126 void PostBeginRetroFrame(); | |
| 116 void BeginRetroFrame(); | 127 void BeginRetroFrame(); |
| 128 void BeginUnthrottledFrame(); | |
| 129 | |
| 117 void BeginImplFrame(const BeginFrameArgs& args); | 130 void BeginImplFrame(const BeginFrameArgs& args); |
| 118 void OnBeginImplFrameDeadline(); | 131 void OnBeginImplFrameDeadline(); |
| 119 void PollForAnticipatedDrawTriggers(); | 132 void PollForAnticipatedDrawTriggers(); |
| 120 void PollToAdvanceCommitState(); | 133 void PollToAdvanceCommitState(); |
| 121 | 134 |
| 122 scoped_ptr<base::Value> StateAsValue() const; | 135 scoped_ptr<base::Value> StateAsValue() const; |
| 123 | 136 |
| 124 bool IsInsideAction(SchedulerStateMachine::Action action) { | 137 bool IsInsideAction(SchedulerStateMachine::Action action) { |
| 125 return inside_action_ == action; | 138 return inside_action_ == action; |
| 126 } | 139 } |
| 127 | 140 |
| 128 bool IsBeginMainFrameSent() const; | 141 bool IsBeginMainFrameSent() const; |
| 129 void SetContinuousPainting(bool continuous_painting) { | 142 void SetContinuousPainting(bool continuous_painting) { |
| 130 state_machine_.SetContinuousPainting(continuous_painting); | 143 state_machine_.SetContinuousPainting(continuous_painting); |
| 131 } | 144 } |
| 132 | 145 |
| 133 private: | 146 private: |
| 134 Scheduler(SchedulerClient* client, | 147 Scheduler( |
| 135 const SchedulerSettings& scheduler_settings, | 148 SchedulerClient* client, |
| 136 int layer_tree_host_id, | 149 const SchedulerSettings& scheduler_settings, |
| 137 const scoped_refptr<base::SequencedTaskRunner>& impl_task_runner); | 150 int layer_tree_host_id, |
| 151 const scoped_refptr<base::SingleThreadTaskRunner>& impl_task_runner); | |
| 138 | 152 |
| 139 base::TimeTicks AdjustedBeginImplFrameDeadline( | 153 base::TimeTicks AdjustedBeginImplFrameDeadline( |
| 140 const BeginFrameArgs& args, | 154 const BeginFrameArgs& args, |
| 141 base::TimeDelta draw_duration_estimate) const; | 155 base::TimeDelta draw_duration_estimate) const; |
| 142 void ScheduleBeginImplFrameDeadline(base::TimeTicks deadline); | 156 void ScheduleBeginImplFrameDeadline(base::TimeTicks deadline); |
| 143 void SetupNextBeginFrameIfNeeded(); | 157 void SetupNextBeginFrameIfNeeded(); |
| 144 void PostBeginRetroFrameIfNeeded(); | 158 void PostBeginRetroFrameIfNeeded(); |
| 159 void SetupNextBeginFrameWhenVSyncThrottlingEnabled(bool needs_begin_frame); | |
| 160 void SetupNextBeginFrameWhenVSyncThrottlingDisabled(bool needs_begin_frame); | |
| 161 void SetupPollingMechanisms(bool needs_begin_frame); | |
| 145 void ActivatePendingTree(); | 162 void ActivatePendingTree(); |
| 146 void DrawAndSwapIfPossible(); | 163 void DrawAndSwapIfPossible(); |
| 147 void DrawAndSwapForced(); | 164 void DrawAndSwapForced(); |
| 148 void DrawAndReadback(); | 165 void DrawAndReadback(); |
| 149 void ProcessScheduledActions(); | 166 void ProcessScheduledActions(); |
| 150 | 167 |
| 151 bool CanCommitAndActivateBeforeDeadline() const; | 168 bool CanCommitAndActivateBeforeDeadline() const; |
| 152 void AdvanceCommitStateIfPossible(); | 169 void AdvanceCommitStateIfPossible(); |
| 153 | 170 |
| 154 bool IsBeginMainFrameSentOrStarted() const; | 171 bool IsBeginMainFrameSentOrStarted() const; |
| 155 | 172 |
| 156 const SchedulerSettings settings_; | 173 const SchedulerSettings settings_; |
| 157 SchedulerClient* client_; | 174 SchedulerClient* client_; |
| 158 int layer_tree_host_id_; | 175 int layer_tree_host_id_; |
| 159 scoped_refptr<base::SequencedTaskRunner> impl_task_runner_; | 176 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner_; |
| 177 | |
| 178 base::TimeDelta vsync_interval_; | |
| 179 base::TimeDelta estimated_parent_draw_time_; | |
| 160 | 180 |
| 161 bool last_set_needs_begin_frame_; | 181 bool last_set_needs_begin_frame_; |
| 182 bool begin_unthrottled_frame_posted_; | |
| 162 bool begin_retro_frame_posted_; | 183 bool begin_retro_frame_posted_; |
| 163 | |
| 164 std::deque<BeginFrameArgs> begin_retro_frame_args_; | 184 std::deque<BeginFrameArgs> begin_retro_frame_args_; |
| 165 BeginFrameArgs begin_impl_frame_args_; | 185 BeginFrameArgs begin_impl_frame_args_; |
| 166 | 186 |
| 187 void SetupSyntheticBeginFrames(); | |
|
Sami
2014/04/16 17:48:23
nit: Move this before the variable declarations.
| |
| 188 scoped_ptr<SyntheticBeginFrameSource> synthetic_begin_frame_source_; | |
| 189 | |
| 167 base::Closure begin_retro_frame_closure_; | 190 base::Closure begin_retro_frame_closure_; |
| 191 base::Closure begin_unthrottled_frame_closure_; | |
| 192 | |
| 168 base::Closure begin_impl_frame_deadline_closure_; | 193 base::Closure begin_impl_frame_deadline_closure_; |
| 169 base::Closure poll_for_draw_triggers_closure_; | 194 base::Closure poll_for_draw_triggers_closure_; |
| 170 base::Closure advance_commit_state_closure_; | 195 base::Closure advance_commit_state_closure_; |
| 171 base::CancelableClosure begin_impl_frame_deadline_task_; | 196 base::CancelableClosure begin_impl_frame_deadline_task_; |
| 172 base::CancelableClosure poll_for_draw_triggers_task_; | 197 base::CancelableClosure poll_for_draw_triggers_task_; |
| 173 base::CancelableClosure advance_commit_state_task_; | 198 base::CancelableClosure advance_commit_state_task_; |
| 174 | 199 |
| 175 SchedulerStateMachine state_machine_; | 200 SchedulerStateMachine state_machine_; |
| 176 bool inside_process_scheduled_actions_; | 201 bool inside_process_scheduled_actions_; |
| 177 SchedulerStateMachine::Action inside_action_; | 202 SchedulerStateMachine::Action inside_action_; |
| 178 | 203 |
| 179 base::WeakPtrFactory<Scheduler> weak_factory_; | 204 base::WeakPtrFactory<Scheduler> weak_factory_; |
| 180 | 205 |
| 181 DISALLOW_COPY_AND_ASSIGN(Scheduler); | 206 DISALLOW_COPY_AND_ASSIGN(Scheduler); |
| 182 }; | 207 }; |
| 183 | 208 |
| 184 } // namespace cc | 209 } // namespace cc |
| 185 | 210 |
| 186 #endif // CC_SCHEDULER_SCHEDULER_H_ | 211 #endif // CC_SCHEDULER_SCHEDULER_H_ |
| OLD | NEW |