| 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/logging.h" | 10 #include "base/logging.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 scheduler->unthrottled_frame_source_internal_ = | 72 scheduler->unthrottled_frame_source_internal_ = |
| 73 BackToBackBeginFrameSource::Create(scheduler->task_runner_.get()); | 73 BackToBackBeginFrameSource::Create(scheduler->task_runner_.get()); |
| 74 return scheduler->unthrottled_frame_source_internal_.get(); | 74 return scheduler->unthrottled_frame_source_internal_.get(); |
| 75 } | 75 } |
| 76 | 76 |
| 77 Scheduler::Scheduler( | 77 Scheduler::Scheduler( |
| 78 SchedulerClient* client, | 78 SchedulerClient* client, |
| 79 const SchedulerSettings& scheduler_settings, | 79 const SchedulerSettings& scheduler_settings, |
| 80 int layer_tree_host_id, | 80 int layer_tree_host_id, |
| 81 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 81 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 82 base::PowerMonitor* power_monitor, | |
| 83 scoped_ptr<BeginFrameSource> external_begin_frame_source, | 82 scoped_ptr<BeginFrameSource> external_begin_frame_source, |
| 84 SchedulerFrameSourcesConstructor* frame_sources_constructor) | 83 SchedulerFrameSourcesConstructor* frame_sources_constructor) |
| 85 : frame_source_(), | 84 : frame_source_(), |
| 86 primary_frame_source_(NULL), | 85 primary_frame_source_(NULL), |
| 87 background_frame_source_(NULL), | 86 background_frame_source_(NULL), |
| 88 primary_frame_source_internal_(external_begin_frame_source.Pass()), | 87 primary_frame_source_internal_(external_begin_frame_source.Pass()), |
| 89 background_frame_source_internal_(), | 88 background_frame_source_internal_(), |
| 90 vsync_observer_(NULL), | 89 vsync_observer_(NULL), |
| 91 throttle_frame_production_(scheduler_settings.throttle_frame_production), | 90 throttle_frame_production_(scheduler_settings.throttle_frame_production), |
| 92 settings_(scheduler_settings), | 91 settings_(scheduler_settings), |
| 93 client_(client), | 92 client_(client), |
| 94 layer_tree_host_id_(layer_tree_host_id), | 93 layer_tree_host_id_(layer_tree_host_id), |
| 95 task_runner_(task_runner), | 94 task_runner_(task_runner), |
| 96 power_monitor_(power_monitor), | |
| 97 state_machine_(scheduler_settings), | 95 state_machine_(scheduler_settings), |
| 98 inside_process_scheduled_actions_(false), | 96 inside_process_scheduled_actions_(false), |
| 99 inside_action_(SchedulerStateMachine::ACTION_NONE), | 97 inside_action_(SchedulerStateMachine::ACTION_NONE), |
| 100 weak_factory_(this) { | 98 weak_factory_(this) { |
| 101 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), | 99 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), |
| 102 "Scheduler::Scheduler", | 100 "Scheduler::Scheduler", |
| 103 "settings", | 101 "settings", |
| 104 settings_.AsValue()); | 102 settings_.AsValue()); |
| 105 DCHECK(client_); | 103 DCHECK(client_); |
| 106 DCHECK(!state_machine_.BeginFrameNeeded()); | 104 DCHECK(!state_machine_.BeginFrameNeeded()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 125 | 123 |
| 126 // Background ticking frame source | 124 // Background ticking frame source |
| 127 background_frame_source_ = | 125 background_frame_source_ = |
| 128 frame_sources_constructor->ConstructBackgroundFrameSource(this); | 126 frame_sources_constructor->ConstructBackgroundFrameSource(this); |
| 129 frame_source_->AddSource(background_frame_source_); | 127 frame_source_->AddSource(background_frame_source_); |
| 130 | 128 |
| 131 // Unthrottled frame source | 129 // Unthrottled frame source |
| 132 unthrottled_frame_source_ = | 130 unthrottled_frame_source_ = |
| 133 frame_sources_constructor->ConstructUnthrottledFrameSource(this); | 131 frame_sources_constructor->ConstructUnthrottledFrameSource(this); |
| 134 frame_source_->AddSource(unthrottled_frame_source_); | 132 frame_source_->AddSource(unthrottled_frame_source_); |
| 135 | |
| 136 SetupPowerMonitoring(); | |
| 137 } | 133 } |
| 138 | 134 |
| 139 Scheduler::~Scheduler() { | 135 Scheduler::~Scheduler() { |
| 140 TeardownPowerMonitoring(); | |
| 141 if (frame_source_->NeedsBeginFrames()) | 136 if (frame_source_->NeedsBeginFrames()) |
| 142 frame_source_->SetNeedsBeginFrames(false); | 137 frame_source_->SetNeedsBeginFrames(false); |
| 143 } | 138 } |
| 144 | 139 |
| 145 base::TimeTicks Scheduler::Now() const { | 140 base::TimeTicks Scheduler::Now() const { |
| 146 base::TimeTicks now = gfx::FrameTime::Now(); | 141 base::TimeTicks now = gfx::FrameTime::Now(); |
| 147 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.now"), | 142 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.now"), |
| 148 "Scheduler::Now", | 143 "Scheduler::Now", |
| 149 "now", | 144 "now", |
| 150 now); | 145 now); |
| 151 return now; | 146 return now; |
| 152 } | 147 } |
| 153 | 148 |
| 154 void Scheduler::SetupPowerMonitoring() { | |
| 155 if (settings_.disable_hi_res_timer_tasks_on_battery) { | |
| 156 DCHECK(power_monitor_); | |
| 157 power_monitor_->AddObserver(this); | |
| 158 state_machine_.SetImplLatencyTakesPriorityOnBattery( | |
| 159 power_monitor_->IsOnBatteryPower()); | |
| 160 } | |
| 161 } | |
| 162 | |
| 163 void Scheduler::TeardownPowerMonitoring() { | |
| 164 if (settings_.disable_hi_res_timer_tasks_on_battery) { | |
| 165 DCHECK(power_monitor_); | |
| 166 power_monitor_->RemoveObserver(this); | |
| 167 } | |
| 168 } | |
| 169 | |
| 170 void Scheduler::OnPowerStateChange(bool on_battery_power) { | |
| 171 DCHECK(settings_.disable_hi_res_timer_tasks_on_battery); | |
| 172 state_machine_.SetImplLatencyTakesPriorityOnBattery(on_battery_power); | |
| 173 } | |
| 174 | |
| 175 void Scheduler::CommitVSyncParameters(base::TimeTicks timebase, | 149 void Scheduler::CommitVSyncParameters(base::TimeTicks timebase, |
| 176 base::TimeDelta interval) { | 150 base::TimeDelta interval) { |
| 177 // TODO(brianderson): We should not be receiving 0 intervals. | 151 // TODO(brianderson): We should not be receiving 0 intervals. |
| 178 if (interval == base::TimeDelta()) | 152 if (interval == base::TimeDelta()) |
| 179 interval = BeginFrameArgs::DefaultInterval(); | 153 interval = BeginFrameArgs::DefaultInterval(); |
| 180 | 154 |
| 181 if (vsync_observer_) | 155 if (vsync_observer_) |
| 182 vsync_observer_->OnUpdateVSyncParameters(timebase, interval); | 156 vsync_observer_->OnUpdateVSyncParameters(timebase, interval); |
| 183 } | 157 } |
| 184 | 158 |
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 896 } | 870 } |
| 897 | 871 |
| 898 bool Scheduler::IsBeginMainFrameSentOrStarted() const { | 872 bool Scheduler::IsBeginMainFrameSentOrStarted() const { |
| 899 return (state_machine_.commit_state() == | 873 return (state_machine_.commit_state() == |
| 900 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || | 874 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || |
| 901 state_machine_.commit_state() == | 875 state_machine_.commit_state() == |
| 902 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); | 876 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); |
| 903 } | 877 } |
| 904 | 878 |
| 905 } // namespace cc | 879 } // namespace cc |
| OLD | NEW |