| 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 #include "base/auto_reset.h" | 8 #include "base/auto_reset.h" |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/debug/trace_event_argument.h" | 10 #include "base/debug/trace_event_argument.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 scheduler->Now(), | 66 scheduler->Now(), |
| 67 base::TimeDelta::FromSeconds(1)); | 67 base::TimeDelta::FromSeconds(1)); |
| 68 return scheduler->background_frame_source_internal_.get(); | 68 return scheduler->background_frame_source_internal_.get(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 Scheduler::Scheduler( | 71 Scheduler::Scheduler( |
| 72 SchedulerClient* client, | 72 SchedulerClient* client, |
| 73 const SchedulerSettings& scheduler_settings, | 73 const SchedulerSettings& scheduler_settings, |
| 74 int layer_tree_host_id, | 74 int layer_tree_host_id, |
| 75 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 75 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 76 SchedulerFrameSourcesConstructor* frame_sources_constructor) | 76 SchedulerFrameSourcesConstructor* frame_sources_constructor, |
| 77 base::PowerMonitor* power_monitor) |
| 77 : frame_source_(), | 78 : frame_source_(), |
| 78 primary_frame_source_(NULL), | 79 primary_frame_source_(NULL), |
| 79 background_frame_source_(NULL), | 80 background_frame_source_(NULL), |
| 80 primary_frame_source_internal_(), | 81 primary_frame_source_internal_(), |
| 81 background_frame_source_internal_(), | 82 background_frame_source_internal_(), |
| 82 vsync_observer_(NULL), | 83 vsync_observer_(NULL), |
| 83 settings_(scheduler_settings), | 84 settings_(scheduler_settings), |
| 84 client_(client), | 85 client_(client), |
| 85 layer_tree_host_id_(layer_tree_host_id), | 86 layer_tree_host_id_(layer_tree_host_id), |
| 86 task_runner_(task_runner), | 87 task_runner_(task_runner), |
| 88 power_monitor_(power_monitor), |
| 87 begin_retro_frame_posted_(false), | 89 begin_retro_frame_posted_(false), |
| 88 state_machine_(scheduler_settings), | 90 state_machine_(scheduler_settings), |
| 89 inside_process_scheduled_actions_(false), | 91 inside_process_scheduled_actions_(false), |
| 90 inside_action_(SchedulerStateMachine::ACTION_NONE), | 92 inside_action_(SchedulerStateMachine::ACTION_NONE), |
| 91 weak_factory_(this) { | 93 weak_factory_(this) { |
| 92 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), | 94 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), |
| 93 "Scheduler::Scheduler", | 95 "Scheduler::Scheduler", |
| 94 "settings", | 96 "settings", |
| 95 settings_.AsValue()); | 97 settings_.AsValue()); |
| 96 DCHECK(client_); | 98 DCHECK(client_); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 110 | 112 |
| 111 // Primary frame source | 113 // Primary frame source |
| 112 primary_frame_source_ = | 114 primary_frame_source_ = |
| 113 frame_sources_constructor->ConstructPrimaryFrameSource(this); | 115 frame_sources_constructor->ConstructPrimaryFrameSource(this); |
| 114 frame_source_->AddSource(primary_frame_source_); | 116 frame_source_->AddSource(primary_frame_source_); |
| 115 | 117 |
| 116 // Background ticking frame source | 118 // Background ticking frame source |
| 117 background_frame_source_ = | 119 background_frame_source_ = |
| 118 frame_sources_constructor->ConstructBackgroundFrameSource(this); | 120 frame_sources_constructor->ConstructBackgroundFrameSource(this); |
| 119 frame_source_->AddSource(background_frame_source_); | 121 frame_source_->AddSource(background_frame_source_); |
| 122 |
| 123 SetupPowerMonitoring(); |
| 120 } | 124 } |
| 121 | 125 |
| 122 Scheduler::~Scheduler() { | 126 Scheduler::~Scheduler() { |
| 127 TeardownPowerMonitoring(); |
| 123 } | 128 } |
| 124 | 129 |
| 125 base::TimeTicks Scheduler::Now() const { | 130 base::TimeTicks Scheduler::Now() const { |
| 126 base::TimeTicks now = gfx::FrameTime::Now(); | 131 base::TimeTicks now = gfx::FrameTime::Now(); |
| 127 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.now"), | 132 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.now"), |
| 128 "Scheduler::Now", | 133 "Scheduler::Now", |
| 129 "now", | 134 "now", |
| 130 now); | 135 now); |
| 131 return now; | 136 return now; |
| 132 } | 137 } |
| 133 | 138 |
| 139 void Scheduler::SetupPowerMonitoring() { |
| 140 if (settings_.prioritize_impl_latency_on_battery) { |
| 141 DCHECK(power_monitor_); |
| 142 power_monitor_->AddObserver(this); |
| 143 state_machine_.SetImplLatencyTakesPriorityOnBattery( |
| 144 power_monitor_->IsOnBatteryPower()); |
| 145 } |
| 146 } |
| 147 |
| 148 void Scheduler::TeardownPowerMonitoring() { |
| 149 if (settings_.prioritize_impl_latency_on_battery) { |
| 150 DCHECK(power_monitor_); |
| 151 power_monitor_->RemoveObserver(this); |
| 152 } |
| 153 } |
| 154 |
| 155 void Scheduler::OnPowerStateChange(bool on_battery_power) { |
| 156 DCHECK(settings_.prioritize_impl_latency_on_battery); |
| 157 state_machine_.SetImplLatencyTakesPriorityOnBattery(on_battery_power); |
| 158 } |
| 159 |
| 134 void Scheduler::CommitVSyncParameters(base::TimeTicks timebase, | 160 void Scheduler::CommitVSyncParameters(base::TimeTicks timebase, |
| 135 base::TimeDelta interval) { | 161 base::TimeDelta interval) { |
| 136 // TODO(brianderson): We should not be receiving 0 intervals. | 162 // TODO(brianderson): We should not be receiving 0 intervals. |
| 137 if (interval == base::TimeDelta()) | 163 if (interval == base::TimeDelta()) |
| 138 interval = BeginFrameArgs::DefaultInterval(); | 164 interval = BeginFrameArgs::DefaultInterval(); |
| 139 | 165 |
| 140 if (vsync_observer_) | 166 if (vsync_observer_) |
| 141 vsync_observer_->OnUpdateVSyncParameters(timebase, interval); | 167 vsync_observer_->OnUpdateVSyncParameters(timebase, interval); |
| 142 } | 168 } |
| 143 | 169 |
| (...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 } | 772 } |
| 747 | 773 |
| 748 bool Scheduler::IsBeginMainFrameSentOrStarted() const { | 774 bool Scheduler::IsBeginMainFrameSentOrStarted() const { |
| 749 return (state_machine_.commit_state() == | 775 return (state_machine_.commit_state() == |
| 750 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || | 776 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || |
| 751 state_machine_.commit_state() == | 777 state_machine_.commit_state() == |
| 752 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); | 778 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); |
| 753 } | 779 } |
| 754 | 780 |
| 755 } // namespace cc | 781 } // namespace cc |
| OLD | NEW |