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 #include "cc/scheduler/scheduler.h" | 5 #include "cc/scheduler/scheduler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| 11 #include "base/debug/trace_event_argument.h" | 11 #include "base/debug/trace_event_argument.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "cc/debug/devtools_instrumentation.h" | 14 #include "cc/debug/devtools_instrumentation.h" |
| 15 #include "cc/debug/traced_value.h" | 15 #include "cc/debug/traced_value.h" |
| 16 #include "cc/scheduler/delay_based_time_source.h" | 16 #include "cc/scheduler/delay_based_time_source.h" |
| 17 #include "ui/gfx/frame_time.h" | 17 #include "ui/gfx/frame_time.h" |
| 18 | 18 |
| 19 namespace cc { | 19 namespace cc { |
| 20 | 20 |
| 21 BeginFrameSource* SchedulerFrameSourcesConstructor::ConstructPrimaryFrameSource( | 21 BeginFrameSource* SchedulerFrameSourcesConstructor::ConstructPrimaryFrameSource( |
| 22 Scheduler* scheduler) { | 22 Scheduler* scheduler) { |
| 23 if (!scheduler->settings_.throttle_frame_production) { | 23 if (scheduler->settings_.use_external_begin_frame_source) { |
| 24 TRACE_EVENT1("cc", | 24 TRACE_EVENT1("cc", |
| 25 "Scheduler::Scheduler()", | 25 "Scheduler::Scheduler()", |
| 26 "PrimaryFrameSource", | 26 "PrimaryFrameSource", |
| 27 "BackToBackBeginFrameSource"); | |
| 28 DCHECK(!scheduler->primary_frame_source_internal_); | |
| 29 scheduler->primary_frame_source_internal_ = | |
| 30 BackToBackBeginFrameSource::Create(scheduler->task_runner_.get()); | |
| 31 return scheduler->primary_frame_source_internal_.get(); | |
| 32 } else if (scheduler->settings_.use_external_begin_frame_source) { | |
| 33 TRACE_EVENT1("cc", | |
| 34 "Scheduler::Scheduler()", | |
| 35 "PrimaryFrameSource", | |
| 36 "ExternalBeginFrameSource"); | 27 "ExternalBeginFrameSource"); |
| 37 DCHECK(scheduler->primary_frame_source_internal_) | 28 DCHECK(scheduler->primary_frame_source_internal_) |
| 38 << "Need external BeginFrameSource"; | 29 << "Need external BeginFrameSource"; |
| 39 return scheduler->primary_frame_source_internal_.get(); | 30 return scheduler->primary_frame_source_internal_.get(); |
| 40 } else { | 31 } else { |
| 41 TRACE_EVENT1("cc", | 32 TRACE_EVENT1("cc", |
| 42 "Scheduler::Scheduler()", | 33 "Scheduler::Scheduler()", |
| 43 "PrimaryFrameSource", | 34 "PrimaryFrameSource", |
| 44 "SyntheticBeginFrameSource"); | 35 "SyntheticBeginFrameSource"); |
| 45 scoped_ptr<SyntheticBeginFrameSource> synthetic_source = | 36 scoped_ptr<SyntheticBeginFrameSource> synthetic_source = |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 64 "BackgroundFrameSource", | 55 "BackgroundFrameSource", |
| 65 "SyntheticBeginFrameSource"); | 56 "SyntheticBeginFrameSource"); |
| 66 DCHECK(!(scheduler->background_frame_source_internal_)); | 57 DCHECK(!(scheduler->background_frame_source_internal_)); |
| 67 scheduler->background_frame_source_internal_ = | 58 scheduler->background_frame_source_internal_ = |
| 68 SyntheticBeginFrameSource::Create( | 59 SyntheticBeginFrameSource::Create( |
| 69 scheduler->task_runner_.get(), scheduler->Now(), | 60 scheduler->task_runner_.get(), scheduler->Now(), |
| 70 scheduler->settings_.background_frame_interval); | 61 scheduler->settings_.background_frame_interval); |
| 71 return scheduler->background_frame_source_internal_.get(); | 62 return scheduler->background_frame_source_internal_.get(); |
| 72 } | 63 } |
| 73 | 64 |
| 65 BeginFrameSource* | |
| 66 SchedulerFrameSourcesConstructor::ConstructUnthrottledFrameSource( | |
| 67 Scheduler* scheduler) { | |
| 68 TRACE_EVENT1("cc", "Scheduler::Scheduler()", "PrimaryFrameSource", | |
| 69 "BackToBackBeginFrameSource"); | |
| 70 DCHECK(!scheduler->unthrottled_frame_source_internal_); | |
| 71 scheduler->unthrottled_frame_source_internal_ = | |
| 72 BackToBackBeginFrameSource::Create(scheduler->task_runner_.get()); | |
| 73 return scheduler->unthrottled_frame_source_internal_.get(); | |
| 74 } | |
| 75 | |
| 74 Scheduler::Scheduler( | 76 Scheduler::Scheduler( |
| 75 SchedulerClient* client, | 77 SchedulerClient* client, |
| 76 const SchedulerSettings& scheduler_settings, | 78 const SchedulerSettings& scheduler_settings, |
| 77 int layer_tree_host_id, | 79 int layer_tree_host_id, |
| 78 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 80 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 79 base::PowerMonitor* power_monitor, | 81 base::PowerMonitor* power_monitor, |
| 80 scoped_ptr<BeginFrameSource> external_begin_frame_source, | 82 scoped_ptr<BeginFrameSource> external_begin_frame_source, |
| 81 SchedulerFrameSourcesConstructor* frame_sources_constructor) | 83 SchedulerFrameSourcesConstructor* frame_sources_constructor) |
| 82 : frame_source_(), | 84 : frame_source_(), |
| 83 primary_frame_source_(NULL), | 85 primary_frame_source_(NULL), |
| 84 background_frame_source_(NULL), | 86 background_frame_source_(NULL), |
| 85 primary_frame_source_internal_(external_begin_frame_source.Pass()), | 87 primary_frame_source_internal_(external_begin_frame_source.Pass()), |
| 86 background_frame_source_internal_(), | 88 background_frame_source_internal_(), |
| 87 vsync_observer_(NULL), | 89 vsync_observer_(NULL), |
| 90 throttle_frame_production_(scheduler_settings.throttle_frame_production), | |
|
brianderson
2014/12/16 23:38:02
The meaning of throttle_frame_production is slight
| |
| 88 settings_(scheduler_settings), | 91 settings_(scheduler_settings), |
| 89 client_(client), | 92 client_(client), |
| 90 layer_tree_host_id_(layer_tree_host_id), | 93 layer_tree_host_id_(layer_tree_host_id), |
| 91 task_runner_(task_runner), | 94 task_runner_(task_runner), |
| 92 power_monitor_(power_monitor), | 95 power_monitor_(power_monitor), |
| 93 begin_retro_frame_posted_(false), | 96 begin_retro_frame_posted_(false), |
| 94 state_machine_(scheduler_settings), | 97 state_machine_(scheduler_settings), |
| 95 inside_process_scheduled_actions_(false), | 98 inside_process_scheduled_actions_(false), |
| 96 inside_action_(SchedulerStateMachine::ACTION_NONE), | 99 inside_action_(SchedulerStateMachine::ACTION_NONE), |
| 97 weak_factory_(this) { | 100 weak_factory_(this) { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 118 primary_frame_source_ = | 121 primary_frame_source_ = |
| 119 frame_sources_constructor->ConstructPrimaryFrameSource(this); | 122 frame_sources_constructor->ConstructPrimaryFrameSource(this); |
| 120 frame_source_->AddSource(primary_frame_source_); | 123 frame_source_->AddSource(primary_frame_source_); |
| 121 primary_frame_source_->SetClientReady(); | 124 primary_frame_source_->SetClientReady(); |
| 122 | 125 |
| 123 // Background ticking frame source | 126 // Background ticking frame source |
| 124 background_frame_source_ = | 127 background_frame_source_ = |
| 125 frame_sources_constructor->ConstructBackgroundFrameSource(this); | 128 frame_sources_constructor->ConstructBackgroundFrameSource(this); |
| 126 frame_source_->AddSource(background_frame_source_); | 129 frame_source_->AddSource(background_frame_source_); |
| 127 | 130 |
| 131 // Unthrottled frame source | |
| 132 unthrottled_frame_source_ = | |
| 133 frame_sources_constructor->ConstructUnthrottledFrameSource(this); | |
| 134 frame_source_->AddSource(unthrottled_frame_source_); | |
| 135 | |
| 128 SetupPowerMonitoring(); | 136 SetupPowerMonitoring(); |
| 129 } | 137 } |
| 130 | 138 |
| 131 Scheduler::~Scheduler() { | 139 Scheduler::~Scheduler() { |
| 132 TeardownPowerMonitoring(); | 140 TeardownPowerMonitoring(); |
| 133 if (frame_source_->NeedsBeginFrames()) | 141 if (frame_source_->NeedsBeginFrames()) |
| 134 frame_source_->SetNeedsBeginFrames(false); | 142 frame_source_->SetNeedsBeginFrames(false); |
| 135 } | 143 } |
| 136 | 144 |
| 137 base::TimeTicks Scheduler::Now() const { | 145 base::TimeTicks Scheduler::Now() const { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 void Scheduler::SetEstimatedParentDrawTime(base::TimeDelta draw_time) { | 185 void Scheduler::SetEstimatedParentDrawTime(base::TimeDelta draw_time) { |
| 178 DCHECK_GE(draw_time.ToInternalValue(), 0); | 186 DCHECK_GE(draw_time.ToInternalValue(), 0); |
| 179 estimated_parent_draw_time_ = draw_time; | 187 estimated_parent_draw_time_ = draw_time; |
| 180 } | 188 } |
| 181 | 189 |
| 182 void Scheduler::SetCanStart() { | 190 void Scheduler::SetCanStart() { |
| 183 state_machine_.SetCanStart(); | 191 state_machine_.SetCanStart(); |
| 184 ProcessScheduledActions(); | 192 ProcessScheduledActions(); |
| 185 } | 193 } |
| 186 | 194 |
| 187 void Scheduler::SetVisible(bool visible) { | 195 void Scheduler::UpdateActiveFrameSource() { |
| 188 state_machine_.SetVisible(visible); | 196 if (state_machine_.visible()) { |
| 189 if (visible) { | 197 if (throttle_frame_production_) { |
| 190 frame_source_->SetActiveSource(primary_frame_source_); | 198 frame_source_->SetActiveSource(primary_frame_source_); |
| 199 } else { | |
| 200 frame_source_->SetActiveSource(unthrottled_frame_source_); | |
| 201 } | |
| 191 } else { | 202 } else { |
| 192 frame_source_->SetActiveSource(background_frame_source_); | 203 frame_source_->SetActiveSource(background_frame_source_); |
| 193 } | 204 } |
| 194 ProcessScheduledActions(); | 205 ProcessScheduledActions(); |
| 195 } | 206 } |
| 196 | 207 |
| 208 void Scheduler::SetVisible(bool visible) { | |
| 209 state_machine_.SetVisible(visible); | |
| 210 UpdateActiveFrameSource(); | |
| 211 } | |
| 212 | |
| 197 void Scheduler::SetCanDraw(bool can_draw) { | 213 void Scheduler::SetCanDraw(bool can_draw) { |
| 198 state_machine_.SetCanDraw(can_draw); | 214 state_machine_.SetCanDraw(can_draw); |
| 199 ProcessScheduledActions(); | 215 ProcessScheduledActions(); |
| 200 } | 216 } |
| 201 | 217 |
| 202 void Scheduler::NotifyReadyToActivate() { | 218 void Scheduler::NotifyReadyToActivate() { |
| 203 state_machine_.NotifyReadyToActivate(); | 219 state_machine_.NotifyReadyToActivate(); |
| 204 ProcessScheduledActions(); | 220 ProcessScheduledActions(); |
| 205 } | 221 } |
| 206 | 222 |
| 207 void Scheduler::NotifyReadyToDraw() { | 223 void Scheduler::NotifyReadyToDraw() { |
| 208 // Empty for now, until we take action based on the notification as part of | 224 // Empty for now, until we take action based on the notification as part of |
| 209 // crbugs 352894, 383157, 421923. | 225 // crbugs 352894, 383157, 421923. |
| 210 } | 226 } |
| 211 | 227 |
| 228 void Scheduler::SetThrottleFrameProduction(bool throttle) { | |
| 229 throttle_frame_production_ = throttle; | |
| 230 UpdateActiveFrameSource(); | |
| 231 } | |
| 232 | |
| 212 void Scheduler::SetNeedsCommit() { | 233 void Scheduler::SetNeedsCommit() { |
| 213 state_machine_.SetNeedsCommit(); | 234 state_machine_.SetNeedsCommit(); |
| 214 ProcessScheduledActions(); | 235 ProcessScheduledActions(); |
| 215 } | 236 } |
| 216 | 237 |
| 217 void Scheduler::SetNeedsRedraw() { | 238 void Scheduler::SetNeedsRedraw() { |
| 218 state_machine_.SetNeedsRedraw(); | 239 state_machine_.SetNeedsRedraw(); |
| 219 ProcessScheduledActions(); | 240 ProcessScheduledActions(); |
| 220 } | 241 } |
| 221 | 242 |
| (...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 800 } | 821 } |
| 801 | 822 |
| 802 bool Scheduler::IsBeginMainFrameSentOrStarted() const { | 823 bool Scheduler::IsBeginMainFrameSentOrStarted() const { |
| 803 return (state_machine_.commit_state() == | 824 return (state_machine_.commit_state() == |
| 804 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || | 825 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || |
| 805 state_machine_.commit_state() == | 826 state_machine_.commit_state() == |
| 806 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); | 827 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); |
| 807 } | 828 } |
| 808 | 829 |
| 809 } // namespace cc | 830 } // namespace cc |
| OLD | NEW |