| 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/output/vsync_parameter_observer.h" | |
| 18 #include "cc/scheduler/begin_frame_source.h" | 17 #include "cc/scheduler/begin_frame_source.h" |
| 19 #include "cc/scheduler/begin_frame_tracker.h" | 18 #include "cc/scheduler/begin_frame_tracker.h" |
| 20 #include "cc/scheduler/delay_based_time_source.h" | 19 #include "cc/scheduler/delay_based_time_source.h" |
| 21 #include "cc/scheduler/draw_result.h" | 20 #include "cc/scheduler/draw_result.h" |
| 22 #include "cc/scheduler/scheduler_settings.h" | 21 #include "cc/scheduler/scheduler_settings.h" |
| 23 #include "cc/scheduler/scheduler_state_machine.h" | 22 #include "cc/scheduler/scheduler_state_machine.h" |
| 24 | 23 |
| 25 namespace base { | 24 namespace base { |
| 26 namespace trace_event { | 25 namespace trace_event { |
| 27 class ConvertableToTraceFormat; | 26 class ConvertableToTraceFormat; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 47 virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() = 0; | 46 virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() = 0; |
| 48 virtual base::TimeDelta CommitToActivateDurationEstimate() = 0; | 47 virtual base::TimeDelta CommitToActivateDurationEstimate() = 0; |
| 49 virtual void DidFinishImplFrame() = 0; | 48 virtual void DidFinishImplFrame() = 0; |
| 50 virtual void SendBeginFramesToChildren(const BeginFrameArgs& args) = 0; | 49 virtual void SendBeginFramesToChildren(const BeginFrameArgs& args) = 0; |
| 51 virtual void SendBeginMainFrameNotExpectedSoon() = 0; | 50 virtual void SendBeginMainFrameNotExpectedSoon() = 0; |
| 52 | 51 |
| 53 protected: | 52 protected: |
| 54 virtual ~SchedulerClient() {} | 53 virtual ~SchedulerClient() {} |
| 55 }; | 54 }; |
| 56 | 55 |
| 57 class Scheduler; | |
| 58 // This class exists to allow tests to override the frame source construction. | |
| 59 // A virtual method can't be used as this needs to happen in the constructor | |
| 60 // (see C++ FAQ / Section 23 - http://goo.gl/fnrwom for why). | |
| 61 // This class exists solely long enough to construct the frame sources. | |
| 62 class CC_EXPORT SchedulerFrameSourcesConstructor { | |
| 63 public: | |
| 64 virtual ~SchedulerFrameSourcesConstructor() {} | |
| 65 virtual BeginFrameSource* ConstructPrimaryFrameSource(Scheduler* scheduler); | |
| 66 virtual BeginFrameSource* ConstructUnthrottledFrameSource( | |
| 67 Scheduler* scheduler); | |
| 68 | |
| 69 protected: | |
| 70 SchedulerFrameSourcesConstructor() {} | |
| 71 | |
| 72 friend class Scheduler; | |
| 73 }; | |
| 74 | |
| 75 class CC_EXPORT Scheduler : public BeginFrameObserverBase { | 56 class CC_EXPORT Scheduler : public BeginFrameObserverBase { |
| 76 public: | 57 public: |
| 77 static scoped_ptr<Scheduler> Create( | 58 static scoped_ptr<Scheduler> Create( |
| 78 SchedulerClient* client, | 59 SchedulerClient* client, |
| 79 const SchedulerSettings& scheduler_settings, | 60 const SchedulerSettings& scheduler_settings, |
| 80 int layer_tree_host_id, | 61 int layer_tree_host_id, |
| 81 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 62 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 82 scoped_ptr<BeginFrameSource> external_begin_frame_source) { | 63 BeginFrameSource* external_frame_source); |
| 83 SchedulerFrameSourcesConstructor frame_sources_constructor; | |
| 84 return make_scoped_ptr(new Scheduler(client, | |
| 85 scheduler_settings, | |
| 86 layer_tree_host_id, | |
| 87 task_runner, | |
| 88 external_begin_frame_source.Pass(), | |
| 89 &frame_sources_constructor)); | |
| 90 } | |
| 91 | 64 |
| 92 ~Scheduler() override; | 65 ~Scheduler() override; |
| 93 | 66 |
| 94 // BeginFrameObserverBase | 67 // BeginFrameObserverBase |
| 95 bool OnBeginFrameDerivedImpl(const BeginFrameArgs& args) override; | 68 bool OnBeginFrameDerivedImpl(const BeginFrameArgs& args) override; |
| 96 | 69 |
| 97 void OnDrawForOutputSurface(); | 70 void OnDrawForOutputSurface(); |
| 98 | 71 |
| 99 const SchedulerSettings& settings() const { return settings_; } | 72 const SchedulerSettings& settings() const { return settings_; } |
| 100 | 73 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 void SetChildrenNeedBeginFrames(bool children_need_begin_frames); | 144 void SetChildrenNeedBeginFrames(bool children_need_begin_frames); |
| 172 void SetVideoNeedsBeginFrames(bool video_needs_begin_frames); | 145 void SetVideoNeedsBeginFrames(bool video_needs_begin_frames); |
| 173 | 146 |
| 174 void SetAuthoritativeVSyncInterval(const base::TimeDelta& interval); | 147 void SetAuthoritativeVSyncInterval(const base::TimeDelta& interval); |
| 175 | 148 |
| 176 protected: | 149 protected: |
| 177 Scheduler(SchedulerClient* client, | 150 Scheduler(SchedulerClient* client, |
| 178 const SchedulerSettings& scheduler_settings, | 151 const SchedulerSettings& scheduler_settings, |
| 179 int layer_tree_host_id, | 152 int layer_tree_host_id, |
| 180 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 153 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 181 scoped_ptr<BeginFrameSource> external_begin_frame_source, | 154 BeginFrameSource* external_frame_source, |
| 182 SchedulerFrameSourcesConstructor* frame_sources_constructor); | 155 scoped_ptr<SyntheticBeginFrameSource> synthetic_frame_source, |
| 156 scoped_ptr<BackToBackBeginFrameSource> unthrottled_frame_source); |
| 183 | 157 |
| 184 // virtual for testing - Don't call these in the constructor or | 158 // virtual for testing - Don't call these in the constructor or |
| 185 // destructor! | 159 // destructor! |
| 186 virtual base::TimeTicks Now() const; | 160 virtual base::TimeTicks Now() const; |
| 187 | 161 |
| 188 scoped_ptr<BeginFrameSourceMultiplexer> frame_source_; | |
| 189 BeginFrameSource* primary_frame_source_; | |
| 190 BeginFrameSource* unthrottled_frame_source_; | |
| 191 | |
| 192 // Storage when frame sources are internal | |
| 193 scoped_ptr<BeginFrameSource> primary_frame_source_internal_; | |
| 194 scoped_ptr<BeginFrameSource> unthrottled_frame_source_internal_; | |
| 195 | |
| 196 VSyncParameterObserver* vsync_observer_; | |
| 197 base::TimeDelta authoritative_vsync_interval_; | |
| 198 base::TimeTicks last_vsync_timebase_; | |
| 199 | |
| 200 bool throttle_frame_production_; | |
| 201 | |
| 202 const SchedulerSettings settings_; | 162 const SchedulerSettings settings_; |
| 203 SchedulerClient* client_; | 163 SchedulerClient* client_; |
| 204 int layer_tree_host_id_; | 164 int layer_tree_host_id_; |
| 205 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 165 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 166 BeginFrameSource* external_frame_source_; |
| 167 scoped_ptr<SyntheticBeginFrameSource> synthetic_frame_source_; |
| 168 scoped_ptr<BackToBackBeginFrameSource> unthrottled_frame_source_; |
| 169 |
| 170 scoped_ptr<BeginFrameSourceMultiplexer> frame_source_; |
| 171 bool throttle_frame_production_; |
| 172 |
| 173 base::TimeDelta authoritative_vsync_interval_; |
| 174 base::TimeTicks last_vsync_timebase_; |
| 206 | 175 |
| 207 base::TimeDelta estimated_parent_draw_time_; | 176 base::TimeDelta estimated_parent_draw_time_; |
| 208 | 177 |
| 209 std::deque<BeginFrameArgs> begin_retro_frame_args_; | 178 std::deque<BeginFrameArgs> begin_retro_frame_args_; |
| 210 SchedulerStateMachine::BeginImplFrameDeadlineMode | 179 SchedulerStateMachine::BeginImplFrameDeadlineMode |
| 211 begin_impl_frame_deadline_mode_; | 180 begin_impl_frame_deadline_mode_; |
| 212 BeginFrameTracker begin_impl_frame_tracker_; | 181 BeginFrameTracker begin_impl_frame_tracker_; |
| 213 | 182 |
| 214 base::Closure begin_retro_frame_closure_; | 183 base::Closure begin_retro_frame_closure_; |
| 215 base::Closure begin_impl_frame_deadline_closure_; | 184 base::Closure begin_impl_frame_deadline_closure_; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 239 void PollToAdvanceCommitState(); | 208 void PollToAdvanceCommitState(); |
| 240 | 209 |
| 241 base::TimeDelta EstimatedParentDrawTime() { | 210 base::TimeDelta EstimatedParentDrawTime() { |
| 242 return estimated_parent_draw_time_; | 211 return estimated_parent_draw_time_; |
| 243 } | 212 } |
| 244 | 213 |
| 245 bool IsInsideAction(SchedulerStateMachine::Action action) { | 214 bool IsInsideAction(SchedulerStateMachine::Action action) { |
| 246 return inside_action_ == action; | 215 return inside_action_ == action; |
| 247 } | 216 } |
| 248 | 217 |
| 218 BeginFrameSource* primary_frame_source() { |
| 219 if (settings_.use_external_begin_frame_source) { |
| 220 DCHECK(external_frame_source_); |
| 221 return external_frame_source_; |
| 222 } |
| 223 return synthetic_frame_source_.get(); |
| 224 } |
| 225 |
| 249 base::WeakPtrFactory<Scheduler> weak_factory_; | 226 base::WeakPtrFactory<Scheduler> weak_factory_; |
| 250 | 227 |
| 251 friend class SchedulerFrameSourcesConstructor; | |
| 252 friend class TestSchedulerFrameSourcesConstructor; | |
| 253 | |
| 254 DISALLOW_COPY_AND_ASSIGN(Scheduler); | 228 DISALLOW_COPY_AND_ASSIGN(Scheduler); |
| 255 }; | 229 }; |
| 256 | 230 |
| 257 } // namespace cc | 231 } // namespace cc |
| 258 | 232 |
| 259 #endif // CC_SCHEDULER_SCHEDULER_H_ | 233 #endif // CC_SCHEDULER_SCHEDULER_H_ |
| OLD | NEW |