Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: cc/scheduler/scheduler.cc

Issue 811523002: Added ability to dynamically toggle frame throttling in the scheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 "BackgroundFrameSource", 64 "BackgroundFrameSource",
65 "SyntheticBeginFrameSource"); 65 "SyntheticBeginFrameSource");
66 DCHECK(!(scheduler->background_frame_source_internal_)); 66 DCHECK(!(scheduler->background_frame_source_internal_));
67 scheduler->background_frame_source_internal_ = 67 scheduler->background_frame_source_internal_ =
68 SyntheticBeginFrameSource::Create( 68 SyntheticBeginFrameSource::Create(
69 scheduler->task_runner_.get(), scheduler->Now(), 69 scheduler->task_runner_.get(), scheduler->Now(),
70 scheduler->settings_.background_frame_interval); 70 scheduler->settings_.background_frame_interval);
71 return scheduler->background_frame_source_internal_.get(); 71 return scheduler->background_frame_source_internal_.get();
72 } 72 }
73 73
74 BeginFrameSource*
75 SchedulerFrameSourcesConstructor::ConstructUnthrottledFrameSource(
76 Scheduler* scheduler) {
77 TRACE_EVENT1("cc", "Scheduler::Scheduler()", "PrimaryFrameSource",
78 "BackToBackBeginFrameSource");
79 DCHECK(!scheduler->unthrottled_frame_source_internal_);
80 scheduler->unthrottled_frame_source_internal_ =
81 BackToBackBeginFrameSource::Create(scheduler->task_runner_.get());
82 return scheduler->unthrottled_frame_source_internal_.get();
83 }
84
74 Scheduler::Scheduler( 85 Scheduler::Scheduler(
75 SchedulerClient* client, 86 SchedulerClient* client,
76 const SchedulerSettings& scheduler_settings, 87 const SchedulerSettings& scheduler_settings,
77 int layer_tree_host_id, 88 int layer_tree_host_id,
78 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 89 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
79 base::PowerMonitor* power_monitor, 90 base::PowerMonitor* power_monitor,
80 scoped_ptr<BeginFrameSource> external_begin_frame_source, 91 scoped_ptr<BeginFrameSource> external_begin_frame_source,
81 SchedulerFrameSourcesConstructor* frame_sources_constructor) 92 SchedulerFrameSourcesConstructor* frame_sources_constructor)
82 : frame_source_(), 93 : frame_source_(),
83 primary_frame_source_(NULL), 94 primary_frame_source_(NULL),
84 background_frame_source_(NULL), 95 background_frame_source_(NULL),
85 primary_frame_source_internal_(external_begin_frame_source.Pass()), 96 primary_frame_source_internal_(external_begin_frame_source.Pass()),
86 background_frame_source_internal_(), 97 background_frame_source_internal_(),
87 vsync_observer_(NULL), 98 vsync_observer_(NULL),
99 throttle_frame_production_(scheduler_settings.throttle_frame_production),
88 settings_(scheduler_settings), 100 settings_(scheduler_settings),
89 client_(client), 101 client_(client),
90 layer_tree_host_id_(layer_tree_host_id), 102 layer_tree_host_id_(layer_tree_host_id),
91 task_runner_(task_runner), 103 task_runner_(task_runner),
92 power_monitor_(power_monitor), 104 power_monitor_(power_monitor),
93 begin_retro_frame_posted_(false), 105 begin_retro_frame_posted_(false),
94 state_machine_(scheduler_settings), 106 state_machine_(scheduler_settings),
95 inside_process_scheduled_actions_(false), 107 inside_process_scheduled_actions_(false),
96 inside_action_(SchedulerStateMachine::ACTION_NONE), 108 inside_action_(SchedulerStateMachine::ACTION_NONE),
97 weak_factory_(this) { 109 weak_factory_(this) {
(...skipping 20 matching lines...) Expand all
118 primary_frame_source_ = 130 primary_frame_source_ =
119 frame_sources_constructor->ConstructPrimaryFrameSource(this); 131 frame_sources_constructor->ConstructPrimaryFrameSource(this);
120 frame_source_->AddSource(primary_frame_source_); 132 frame_source_->AddSource(primary_frame_source_);
121 primary_frame_source_->SetClientReady(); 133 primary_frame_source_->SetClientReady();
122 134
123 // Background ticking frame source 135 // Background ticking frame source
124 background_frame_source_ = 136 background_frame_source_ =
125 frame_sources_constructor->ConstructBackgroundFrameSource(this); 137 frame_sources_constructor->ConstructBackgroundFrameSource(this);
126 frame_source_->AddSource(background_frame_source_); 138 frame_source_->AddSource(background_frame_source_);
127 139
140 // Unthrottled frame source
141 unthrottled_frame_source_ =
142 frame_sources_constructor->ConstructUnthrottledFrameSource(this);
143 frame_source_->AddSource(unthrottled_frame_source_);
144
128 SetupPowerMonitoring(); 145 SetupPowerMonitoring();
129 } 146 }
130 147
131 Scheduler::~Scheduler() { 148 Scheduler::~Scheduler() {
132 TeardownPowerMonitoring(); 149 TeardownPowerMonitoring();
133 if (frame_source_->NeedsBeginFrames()) 150 if (frame_source_->NeedsBeginFrames())
134 frame_source_->SetNeedsBeginFrames(false); 151 frame_source_->SetNeedsBeginFrames(false);
135 } 152 }
136 153
137 base::TimeTicks Scheduler::Now() const { 154 base::TimeTicks Scheduler::Now() const {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 void Scheduler::SetEstimatedParentDrawTime(base::TimeDelta draw_time) { 194 void Scheduler::SetEstimatedParentDrawTime(base::TimeDelta draw_time) {
178 DCHECK_GE(draw_time.ToInternalValue(), 0); 195 DCHECK_GE(draw_time.ToInternalValue(), 0);
179 estimated_parent_draw_time_ = draw_time; 196 estimated_parent_draw_time_ = draw_time;
180 } 197 }
181 198
182 void Scheduler::SetCanStart() { 199 void Scheduler::SetCanStart() {
183 state_machine_.SetCanStart(); 200 state_machine_.SetCanStart();
184 ProcessScheduledActions(); 201 ProcessScheduledActions();
185 } 202 }
186 203
187 void Scheduler::SetVisible(bool visible) { 204 void Scheduler::UpdateActiveFrameSource() {
188 state_machine_.SetVisible(visible); 205 if (state_machine_.visible()) {
189 if (visible) { 206 if (throttle_frame_production_) {
190 frame_source_->SetActiveSource(primary_frame_source_); 207 frame_source_->SetActiveSource(primary_frame_source_);
208 } else {
209 frame_source_->SetActiveSource(unthrottled_frame_source_);
210 }
191 } else { 211 } else {
192 frame_source_->SetActiveSource(background_frame_source_); 212 frame_source_->SetActiveSource(background_frame_source_);
193 } 213 }
194 ProcessScheduledActions(); 214 ProcessScheduledActions();
195 } 215 }
196 216
217 void Scheduler::SetVisible(bool visible) {
218 state_machine_.SetVisible(visible);
219 UpdateActiveFrameSource();
220 }
221
197 void Scheduler::SetCanDraw(bool can_draw) { 222 void Scheduler::SetCanDraw(bool can_draw) {
198 state_machine_.SetCanDraw(can_draw); 223 state_machine_.SetCanDraw(can_draw);
199 ProcessScheduledActions(); 224 ProcessScheduledActions();
200 } 225 }
201 226
202 void Scheduler::NotifyReadyToActivate() { 227 void Scheduler::NotifyReadyToActivate() {
203 state_machine_.NotifyReadyToActivate(); 228 state_machine_.NotifyReadyToActivate();
204 ProcessScheduledActions(); 229 ProcessScheduledActions();
205 } 230 }
206 231
207 void Scheduler::NotifyReadyToDraw() { 232 void Scheduler::NotifyReadyToDraw() {
208 // Empty for now, until we take action based on the notification as part of 233 // Empty for now, until we take action based on the notification as part of
209 // crbugs 352894, 383157, 421923. 234 // crbugs 352894, 383157, 421923.
210 } 235 }
211 236
237 void Scheduler::SetThrottleFrameProduction(bool throttle) {
238 throttle_frame_production_ = settings_.throttle_frame_production && throttle;
enne (OOO) 2014/12/15 23:21:07 It's a little odd to my eyes to have both a schedu
brianderson 2014/12/16 22:36:42 Can we make the command line flag only set the ini
239 UpdateActiveFrameSource();
240 }
241
212 void Scheduler::SetNeedsCommit() { 242 void Scheduler::SetNeedsCommit() {
213 state_machine_.SetNeedsCommit(); 243 state_machine_.SetNeedsCommit();
214 ProcessScheduledActions(); 244 ProcessScheduledActions();
215 } 245 }
216 246
217 void Scheduler::SetNeedsRedraw() { 247 void Scheduler::SetNeedsRedraw() {
218 state_machine_.SetNeedsRedraw(); 248 state_machine_.SetNeedsRedraw();
219 ProcessScheduledActions(); 249 ProcessScheduledActions();
220 } 250 }
221 251
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 } 830 }
801 831
802 bool Scheduler::IsBeginMainFrameSentOrStarted() const { 832 bool Scheduler::IsBeginMainFrameSentOrStarted() const {
803 return (state_machine_.commit_state() == 833 return (state_machine_.commit_state() ==
804 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || 834 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT ||
805 state_machine_.commit_state() == 835 state_machine_.commit_state() ==
806 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); 836 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED);
807 } 837 }
808 838
809 } // namespace cc 839 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698