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; |
| 25 | 26 |
| 26 class SchedulerClient { | 27 class SchedulerClient { |
| 27 public: | 28 public: |
| 28 virtual void SetNeedsBeginFrame(bool enable) = 0; | 29 virtual void SetNeedsBeginFrame(bool enable) = 0; |
| 29 virtual void WillBeginImplFrame(const BeginFrameArgs& args) = 0; | 30 virtual void WillBeginImplFrame(const BeginFrameArgs& args) = 0; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 40 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks time) = 0; | 41 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks time) = 0; |
| 41 virtual base::TimeDelta DrawDurationEstimate() = 0; | 42 virtual base::TimeDelta DrawDurationEstimate() = 0; |
| 42 virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() = 0; | 43 virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() = 0; |
| 43 virtual base::TimeDelta CommitToActivateDurationEstimate() = 0; | 44 virtual base::TimeDelta CommitToActivateDurationEstimate() = 0; |
| 44 virtual void DidBeginImplFrameDeadline() = 0; | 45 virtual void DidBeginImplFrameDeadline() = 0; |
| 45 | 46 |
| 46 protected: | 47 protected: |
| 47 virtual ~SchedulerClient() {} | 48 virtual ~SchedulerClient() {} |
| 48 }; | 49 }; |
| 49 | 50 |
| 50 class CC_EXPORT Scheduler { | 51 class CC_EXPORT Scheduler : public TimeSourceClient { |
| 51 public: | 52 public: |
| 52 static scoped_ptr<Scheduler> Create( | 53 static scoped_ptr<Scheduler> Create( |
| 53 SchedulerClient* client, | 54 SchedulerClient* client, |
| 54 const SchedulerSettings& scheduler_settings, | 55 const SchedulerSettings& scheduler_settings, |
| 55 int layer_tree_host_id, | 56 int layer_tree_host_id, |
| 56 const scoped_refptr<base::SequencedTaskRunner>& impl_task_runner) { | 57 const scoped_refptr<base::SingleThreadTaskRunner>& impl_task_runner) { |
| 57 return make_scoped_ptr(new Scheduler( | 58 return make_scoped_ptr(new Scheduler( |
| 58 client, scheduler_settings, layer_tree_host_id, impl_task_runner)); | 59 client, scheduler_settings, layer_tree_host_id, impl_task_runner)); |
| 59 } | 60 } |
| 60 | 61 |
| 61 virtual ~Scheduler(); | 62 virtual ~Scheduler(); |
| 62 | 63 |
| 64 // TimeSourceClient implementation | |
| 65 virtual void OnTimerTick() OVERRIDE; | |
| 66 | |
| 67 void CommitVSyncParameters(base::TimeTicks timebase, | |
| 68 base::TimeDelta interval); | |
| 69 void SetEstimatedParentDrawTime(base::TimeDelta draw_time); | |
|
Sami
2014/04/08 13:46:01
Since DrawDurationEstimate() is already in Schedul
brianderson
2014/04/09 02:52:05
SetEstimatedParentDrawTime is likely to be an asyn
| |
| 70 | |
| 63 void SetCanStart(); | 71 void SetCanStart(); |
| 64 | 72 |
| 65 void SetVisible(bool visible); | 73 void SetVisible(bool visible); |
| 66 void SetCanDraw(bool can_draw); | 74 void SetCanDraw(bool can_draw); |
| 67 void NotifyReadyToActivate(); | 75 void NotifyReadyToActivate(); |
| 68 | 76 |
| 69 void SetNeedsCommit(); | 77 void SetNeedsCommit(); |
| 70 | 78 |
| 71 // Like SetNeedsCommit(), but ensures a commit will definitely happen even if | 79 // Like SetNeedsCommit(), but ensures a commit will definitely happen even if |
| 72 // we are not visible. Will eventually result in a forced draw internally. | 80 // we are not visible. Will eventually result in a forced draw internally. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 | 117 |
| 110 bool WillDrawIfNeeded() const; | 118 bool WillDrawIfNeeded() const; |
| 111 | 119 |
| 112 base::TimeTicks AnticipatedDrawTime() const; | 120 base::TimeTicks AnticipatedDrawTime() const; |
| 113 | 121 |
| 114 void NotifyBeginMainFrameStarted(); | 122 void NotifyBeginMainFrameStarted(); |
| 115 | 123 |
| 116 base::TimeTicks LastBeginImplFrameTime(); | 124 base::TimeTicks LastBeginImplFrameTime(); |
| 117 | 125 |
| 118 void BeginFrame(const BeginFrameArgs& args); | 126 void BeginFrame(const BeginFrameArgs& args); |
| 127 void PostBeginRetroFrame(); | |
| 119 void BeginRetroFrame(); | 128 void BeginRetroFrame(); |
| 120 void BeginImplFrame(const BeginFrameArgs& args); | 129 void BeginImplFrame(const BeginFrameArgs& args); |
| 121 void OnBeginImplFrameDeadline(); | 130 void OnBeginImplFrameDeadline(); |
| 122 void PollForAnticipatedDrawTriggers(); | 131 void PollForAnticipatedDrawTriggers(); |
| 123 void PollToAdvanceCommitState(); | 132 void PollToAdvanceCommitState(); |
| 124 | 133 |
| 125 scoped_ptr<base::Value> StateAsValue() const; | 134 scoped_ptr<base::Value> StateAsValue() const; |
| 126 | 135 |
| 127 bool IsInsideAction(SchedulerStateMachine::Action action) { | 136 bool IsInsideAction(SchedulerStateMachine::Action action) { |
| 128 return inside_action_ == action; | 137 return inside_action_ == action; |
| 129 } | 138 } |
| 130 | 139 |
| 131 bool IsBeginMainFrameSent() const; | 140 bool IsBeginMainFrameSent() const; |
| 132 void SetContinuousPainting(bool continuous_painting) { | 141 void SetContinuousPainting(bool continuous_painting) { |
| 133 state_machine_.SetContinuousPainting(continuous_painting); | 142 state_machine_.SetContinuousPainting(continuous_painting); |
| 134 } | 143 } |
| 135 | 144 |
| 136 private: | 145 private: |
| 137 Scheduler(SchedulerClient* client, | 146 Scheduler( |
| 138 const SchedulerSettings& scheduler_settings, | 147 SchedulerClient* client, |
| 139 int layer_tree_host_id, | 148 const SchedulerSettings& scheduler_settings, |
| 140 const scoped_refptr<base::SequencedTaskRunner>& impl_task_runner); | 149 int layer_tree_host_id, |
| 150 const scoped_refptr<base::SingleThreadTaskRunner>& impl_task_runner); | |
| 141 | 151 |
| 142 base::TimeTicks AdjustedBeginImplFrameDeadline( | 152 base::TimeTicks AdjustedBeginImplFrameDeadline( |
| 143 const BeginFrameArgs& args, | 153 const BeginFrameArgs& args, |
| 144 base::TimeDelta draw_duration_estimate) const; | 154 base::TimeDelta draw_duration_estimate) const; |
| 145 void ScheduleBeginImplFrameDeadline(base::TimeTicks deadline); | 155 void ScheduleBeginImplFrameDeadline(base::TimeTicks deadline); |
| 146 void SetupNextBeginFrameIfNeeded(); | 156 void SetupNextBeginFrameIfNeeded(); |
| 147 void PostBeginRetroFrameIfNeeded(); | 157 void PostBeginRetroFrameIfNeeded(); |
| 158 void SetupNextBeginFrameWhenVSyncEnabled(bool needs_begin_frame); | |
| 159 void SetupNextBeginFrameWhenVSyncDisabled(bool needs_begin_frame); | |
| 160 void SetupPollingMechanisms(bool needs_begin_frame); | |
| 148 void ActivatePendingTree(); | 161 void ActivatePendingTree(); |
| 149 void DrawAndSwapIfPossible(); | 162 void DrawAndSwapIfPossible(); |
| 150 void DrawAndSwapForced(); | 163 void DrawAndSwapForced(); |
| 151 void DrawAndReadback(); | 164 void DrawAndReadback(); |
| 152 void ProcessScheduledActions(); | 165 void ProcessScheduledActions(); |
| 153 | 166 |
| 154 bool CanCommitAndActivateBeforeDeadline() const; | 167 bool CanCommitAndActivateBeforeDeadline() const; |
| 155 void AdvanceCommitStateIfPossible(); | 168 void AdvanceCommitStateIfPossible(); |
| 156 | 169 |
| 157 bool IsBeginMainFrameSentOrStarted() const; | 170 bool IsBeginMainFrameSentOrStarted() const; |
| 158 | 171 |
| 159 const SchedulerSettings settings_; | 172 const SchedulerSettings settings_; |
| 160 SchedulerClient* client_; | 173 SchedulerClient* client_; |
| 161 int layer_tree_host_id_; | 174 int layer_tree_host_id_; |
| 162 scoped_refptr<base::SequencedTaskRunner> impl_task_runner_; | 175 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner_; |
| 176 | |
| 177 base::TimeDelta vsync_interval_; | |
| 178 base::TimeDelta estimated_parent_draw_time_; | |
| 163 | 179 |
| 164 bool last_set_needs_begin_frame_; | 180 bool last_set_needs_begin_frame_; |
| 165 bool begin_retro_frame_posted_; | 181 bool begin_retro_frame_posted_; |
| 166 | |
| 167 std::deque<BeginFrameArgs> begin_retro_frame_args_; | 182 std::deque<BeginFrameArgs> begin_retro_frame_args_; |
| 168 BeginFrameArgs begin_impl_frame_args_; | 183 BeginFrameArgs begin_impl_frame_args_; |
| 169 | 184 |
| 185 scoped_refptr<TimeSource> time_source_for_synthetic_begin_frames_; | |
|
Sami
2014/04/08 13:46:01
Is there a way we could isolate the synthetic Begi
brianderson
2014/04/09 02:52:05
The goal was to get rid of it before, but I'm not
brianderson
2014/04/10 23:45:58
I ended up using an inner class like you originall
| |
| 186 void SetupSyntheticBeginFrames(); | |
| 187 BeginFrameArgs CreateSyntheticBeginFrameArgs(base::TimeTicks frame_time); | |
| 188 | |
| 170 base::Closure begin_retro_frame_closure_; | 189 base::Closure begin_retro_frame_closure_; |
| 171 base::Closure begin_impl_frame_deadline_closure_; | 190 base::Closure begin_impl_frame_deadline_closure_; |
| 172 base::Closure poll_for_draw_triggers_closure_; | 191 base::Closure poll_for_draw_triggers_closure_; |
| 173 base::Closure advance_commit_state_closure_; | 192 base::Closure advance_commit_state_closure_; |
| 174 base::CancelableClosure begin_impl_frame_deadline_task_; | 193 base::CancelableClosure begin_impl_frame_deadline_task_; |
| 175 base::CancelableClosure poll_for_draw_triggers_task_; | 194 base::CancelableClosure poll_for_draw_triggers_task_; |
| 176 base::CancelableClosure advance_commit_state_task_; | 195 base::CancelableClosure advance_commit_state_task_; |
| 177 | 196 |
| 178 SchedulerStateMachine state_machine_; | 197 SchedulerStateMachine state_machine_; |
| 179 bool inside_process_scheduled_actions_; | 198 bool inside_process_scheduled_actions_; |
| 180 SchedulerStateMachine::Action inside_action_; | 199 SchedulerStateMachine::Action inside_action_; |
| 181 | 200 |
| 182 base::WeakPtrFactory<Scheduler> weak_factory_; | 201 base::WeakPtrFactory<Scheduler> weak_factory_; |
| 183 | 202 |
| 184 DISALLOW_COPY_AND_ASSIGN(Scheduler); | 203 DISALLOW_COPY_AND_ASSIGN(Scheduler); |
| 185 }; | 204 }; |
| 186 | 205 |
| 187 } // namespace cc | 206 } // namespace cc |
| 188 | 207 |
| 189 #endif // CC_SCHEDULER_SCHEDULER_H_ | 208 #endif // CC_SCHEDULER_SCHEDULER_H_ |
| OLD | NEW |