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

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: Addressed Brian's feedback Created 5 years, 11 months 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"
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
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",
brianderson 2015/01/05 23:50:46 PrimaryFrameSource -> UnthrottledFrameSource
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),
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 state_machine_(scheduler_settings), 96 state_machine_(scheduler_settings),
94 inside_process_scheduled_actions_(false), 97 inside_process_scheduled_actions_(false),
95 inside_action_(SchedulerStateMachine::ACTION_NONE), 98 inside_action_(SchedulerStateMachine::ACTION_NONE),
96 weak_factory_(this) { 99 weak_factory_(this) {
97 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), 100 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"),
(...skipping 19 matching lines...) Expand all
117 primary_frame_source_ = 120 primary_frame_source_ =
118 frame_sources_constructor->ConstructPrimaryFrameSource(this); 121 frame_sources_constructor->ConstructPrimaryFrameSource(this);
119 frame_source_->AddSource(primary_frame_source_); 122 frame_source_->AddSource(primary_frame_source_);
120 primary_frame_source_->SetClientReady(); 123 primary_frame_source_->SetClientReady();
121 124
122 // Background ticking frame source 125 // Background ticking frame source
123 background_frame_source_ = 126 background_frame_source_ =
124 frame_sources_constructor->ConstructBackgroundFrameSource(this); 127 frame_sources_constructor->ConstructBackgroundFrameSource(this);
125 frame_source_->AddSource(background_frame_source_); 128 frame_source_->AddSource(background_frame_source_);
126 129
130 // Unthrottled frame source
131 unthrottled_frame_source_ =
132 frame_sources_constructor->ConstructUnthrottledFrameSource(this);
133 frame_source_->AddSource(unthrottled_frame_source_);
134
127 SetupPowerMonitoring(); 135 SetupPowerMonitoring();
128 } 136 }
129 137
130 Scheduler::~Scheduler() { 138 Scheduler::~Scheduler() {
131 TeardownPowerMonitoring(); 139 TeardownPowerMonitoring();
132 if (frame_source_->NeedsBeginFrames()) 140 if (frame_source_->NeedsBeginFrames())
133 frame_source_->SetNeedsBeginFrames(false); 141 frame_source_->SetNeedsBeginFrames(false);
134 } 142 }
135 143
136 base::TimeTicks Scheduler::Now() const { 144 base::TimeTicks Scheduler::Now() const {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 void Scheduler::SetEstimatedParentDrawTime(base::TimeDelta draw_time) { 184 void Scheduler::SetEstimatedParentDrawTime(base::TimeDelta draw_time) {
177 DCHECK_GE(draw_time.ToInternalValue(), 0); 185 DCHECK_GE(draw_time.ToInternalValue(), 0);
178 estimated_parent_draw_time_ = draw_time; 186 estimated_parent_draw_time_ = draw_time;
179 } 187 }
180 188
181 void Scheduler::SetCanStart() { 189 void Scheduler::SetCanStart() {
182 state_machine_.SetCanStart(); 190 state_machine_.SetCanStart();
183 ProcessScheduledActions(); 191 ProcessScheduledActions();
184 } 192 }
185 193
186 void Scheduler::SetVisible(bool visible) { 194 void Scheduler::UpdateActiveFrameSource() {
187 state_machine_.SetVisible(visible); 195 if (state_machine_.visible()) {
188 if (visible) { 196 if (throttle_frame_production_) {
189 frame_source_->SetActiveSource(primary_frame_source_); 197 frame_source_->SetActiveSource(primary_frame_source_);
198 } else {
199 frame_source_->SetActiveSource(unthrottled_frame_source_);
200 }
190 } else { 201 } else {
191 frame_source_->SetActiveSource(background_frame_source_); 202 frame_source_->SetActiveSource(background_frame_source_);
192 } 203 }
193 ProcessScheduledActions(); 204 ProcessScheduledActions();
194 } 205 }
195 206
207 void Scheduler::SetVisible(bool visible) {
208 state_machine_.SetVisible(visible);
209 UpdateActiveFrameSource();
210 }
211
196 void Scheduler::SetCanDraw(bool can_draw) { 212 void Scheduler::SetCanDraw(bool can_draw) {
197 state_machine_.SetCanDraw(can_draw); 213 state_machine_.SetCanDraw(can_draw);
198 ProcessScheduledActions(); 214 ProcessScheduledActions();
199 } 215 }
200 216
201 void Scheduler::NotifyReadyToActivate() { 217 void Scheduler::NotifyReadyToActivate() {
202 state_machine_.NotifyReadyToActivate(); 218 state_machine_.NotifyReadyToActivate();
203 ProcessScheduledActions(); 219 ProcessScheduledActions();
204 } 220 }
205 221
206 void Scheduler::NotifyReadyToDraw() { 222 void Scheduler::NotifyReadyToDraw() {
207 // Empty for now, until we take action based on the notification as part of 223 // Empty for now, until we take action based on the notification as part of
208 // crbugs 352894, 383157, 421923. 224 // crbugs 352894, 383157, 421923.
209 } 225 }
210 226
227 void Scheduler::SetThrottleFrameProduction(bool throttle) {
228 throttle_frame_production_ = throttle;
229 UpdateActiveFrameSource();
230 }
231
211 void Scheduler::SetNeedsCommit() { 232 void Scheduler::SetNeedsCommit() {
212 state_machine_.SetNeedsCommit(); 233 state_machine_.SetNeedsCommit();
213 ProcessScheduledActions(); 234 ProcessScheduledActions();
214 } 235 }
215 236
216 void Scheduler::SetNeedsRedraw() { 237 void Scheduler::SetNeedsRedraw() {
217 state_machine_.SetNeedsRedraw(); 238 state_machine_.SetNeedsRedraw();
218 ProcessScheduledActions(); 239 ProcessScheduledActions();
219 } 240 }
220 241
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 } 824 }
804 825
805 bool Scheduler::IsBeginMainFrameSentOrStarted() const { 826 bool Scheduler::IsBeginMainFrameSentOrStarted() const {
806 return (state_machine_.commit_state() == 827 return (state_machine_.commit_state() ==
807 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || 828 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT ||
808 state_machine_.commit_state() == 829 state_machine_.commit_state() ==
809 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); 830 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED);
810 } 831 }
811 832
812 } // namespace cc 833 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698