jamesr@chromium.org | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
jamesr@chromium.org | be4655a | 2013-03-18 08:36:31 | [diff] [blame] | 5 | #include "cc/scheduler/scheduler.h" |
jamesr@chromium.org | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6 | |
brianderson@chromium.org | 425e533 | 2013-09-21 04:10:03 | [diff] [blame] | 7 | #include <algorithm> |
simonhong | a7e3ac4 | 2014-11-11 20:50:22 | [diff] [blame] | 8 | |
jamesr@chromium.org | 6331a11 | 2012-10-18 11:35:13 | [diff] [blame] | 9 | #include "base/auto_reset.h" |
danakj@chromium.org | 1d99317 | 2012-10-18 18:15:04 | [diff] [blame] | 10 | #include "base/logging.h" |
robliao | dd25f5b | 2015-02-27 23:34:02 | [diff] [blame] | 11 | #include "base/profiler/scoped_tracker.h" |
simonhong@chromium.org | b6de344 | 2014-06-05 16:43:19 | [diff] [blame] | 12 | #include "base/single_thread_task_runner.h" |
primiano | c06e238 | 2015-01-28 04:21:49 | [diff] [blame] | 13 | #include "base/trace_event/trace_event.h" |
| 14 | #include "base/trace_event/trace_event_argument.h" |
caseq@chromium.org | dbe759a | 2013-12-02 19:23:02 | [diff] [blame] | 15 | #include "cc/debug/devtools_instrumentation.h" |
brianderson@chromium.org | 224b452 | 2013-08-21 09:58:30 | [diff] [blame] | 16 | #include "cc/debug/traced_value.h" |
brianderson@chromium.org | 3dc0c77 | 2014-04-26 10:06:05 | [diff] [blame] | 17 | #include "cc/scheduler/delay_based_time_source.h" |
jamesr@chromium.org | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 18 | |
enne@chromium.org | 9c88e56 | 2012-09-14 22:21:30 | [diff] [blame] | 19 | namespace cc { |
brianderson@chromium.org | 3dc0c77 | 2014-04-26 10:06:05 | [diff] [blame] | 20 | |
mithro | c34fc0b1 | 2014-09-30 09:10:41 | [diff] [blame] | 21 | BeginFrameSource* SchedulerFrameSourcesConstructor::ConstructPrimaryFrameSource( |
| 22 | Scheduler* scheduler) { |
bajones | 27411061 | 2015-01-06 20:53:59 | [diff] [blame] | 23 | if (scheduler->settings_.use_external_begin_frame_source) { |
mithro | c34fc0b1 | 2014-09-30 09:10:41 | [diff] [blame] | 24 | TRACE_EVENT1("cc", |
| 25 | "Scheduler::Scheduler()", |
| 26 | "PrimaryFrameSource", |
simonhong | a7e3ac4 | 2014-11-11 20:50:22 | [diff] [blame] | 27 | "ExternalBeginFrameSource"); |
| 28 | DCHECK(scheduler->primary_frame_source_internal_) |
| 29 | << "Need external BeginFrameSource"; |
| 30 | return scheduler->primary_frame_source_internal_.get(); |
mithro | c34fc0b1 | 2014-09-30 09:10:41 | [diff] [blame] | 31 | } else { |
| 32 | TRACE_EVENT1("cc", |
| 33 | "Scheduler::Scheduler()", |
| 34 | "PrimaryFrameSource", |
| 35 | "SyntheticBeginFrameSource"); |
| 36 | scoped_ptr<SyntheticBeginFrameSource> synthetic_source = |
| 37 | SyntheticBeginFrameSource::Create(scheduler->task_runner_.get(), |
| 38 | scheduler->Now(), |
| 39 | BeginFrameArgs::DefaultInterval()); |
brianderson@chromium.org | 3dc0c77 | 2014-04-26 10:06:05 | [diff] [blame] | 40 | |
mithro | c34fc0b1 | 2014-09-30 09:10:41 | [diff] [blame] | 41 | DCHECK(!scheduler->vsync_observer_); |
| 42 | scheduler->vsync_observer_ = synthetic_source.get(); |
brianderson@chromium.org | 3dc0c77 | 2014-04-26 10:06:05 | [diff] [blame] | 43 | |
mithro | c34fc0b1 | 2014-09-30 09:10:41 | [diff] [blame] | 44 | DCHECK(!scheduler->primary_frame_source_internal_); |
| 45 | scheduler->primary_frame_source_internal_ = synthetic_source.Pass(); |
| 46 | return scheduler->primary_frame_source_internal_.get(); |
brianderson@chromium.org | 3dc0c77 | 2014-04-26 10:06:05 | [diff] [blame] | 47 | } |
simonhong@chromium.org | b6de344 | 2014-06-05 16:43:19 | [diff] [blame] | 48 | } |
brianderson@chromium.org | 3dc0c77 | 2014-04-26 10:06:05 | [diff] [blame] | 49 | |
mithro | c34fc0b1 | 2014-09-30 09:10:41 | [diff] [blame] | 50 | BeginFrameSource* |
bajones | 27411061 | 2015-01-06 20:53:59 | [diff] [blame] | 51 | SchedulerFrameSourcesConstructor::ConstructUnthrottledFrameSource( |
| 52 | Scheduler* scheduler) { |
| 53 | TRACE_EVENT1("cc", "Scheduler::Scheduler()", "UnthrottledFrameSource", |
| 54 | "BackToBackBeginFrameSource"); |
| 55 | DCHECK(!scheduler->unthrottled_frame_source_internal_); |
| 56 | scheduler->unthrottled_frame_source_internal_ = |
| 57 | BackToBackBeginFrameSource::Create(scheduler->task_runner_.get()); |
| 58 | return scheduler->unthrottled_frame_source_internal_.get(); |
| 59 | } |
| 60 | |
boliu@chromium.org | 48abf81 | 2014-03-20 17:41:59 | [diff] [blame] | 61 | Scheduler::Scheduler( |
| 62 | SchedulerClient* client, |
| 63 | const SchedulerSettings& scheduler_settings, |
| 64 | int layer_tree_host_id, |
mithro | c34fc0b1 | 2014-09-30 09:10:41 | [diff] [blame] | 65 | const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
simonhong | a7e3ac4 | 2014-11-11 20:50:22 | [diff] [blame] | 66 | scoped_ptr<BeginFrameSource> external_begin_frame_source, |
mithro | c34fc0b1 | 2014-09-30 09:10:41 | [diff] [blame] | 67 | SchedulerFrameSourcesConstructor* frame_sources_constructor) |
| 68 | : frame_source_(), |
| 69 | primary_frame_source_(NULL), |
simonhong | a7e3ac4 | 2014-11-11 20:50:22 | [diff] [blame] | 70 | primary_frame_source_internal_(external_begin_frame_source.Pass()), |
mithro | c34fc0b1 | 2014-09-30 09:10:41 | [diff] [blame] | 71 | vsync_observer_(NULL), |
simonhong | 298590fe | 2015-03-25 06:51:13 | [diff] [blame] | 72 | authoritative_vsync_interval_(base::TimeDelta()), |
| 73 | last_vsync_timebase_(base::TimeTicks()), |
mithro | 4c7c7690 | 2015-04-09 07:05:01 | [diff] [blame] | 74 | throttle_frame_production_(false), |
mithro | c34fc0b1 | 2014-09-30 09:10:41 | [diff] [blame] | 75 | settings_(scheduler_settings), |
enne@chromium.org | a8335ac0 | 2013-03-16 09:15:12 | [diff] [blame] | 76 | client_(client), |
caseq@chromium.org | dbe759a | 2013-12-02 19:23:02 | [diff] [blame] | 77 | layer_tree_host_id_(layer_tree_host_id), |
enne@chromium.org | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 78 | task_runner_(task_runner), |
sunnyps | eab5ac9 | 2015-04-02 20:26:13 | [diff] [blame] | 79 | begin_impl_frame_deadline_mode_( |
| 80 | SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE), |
mithro | 0bdb49d | 2015-05-27 13:08:01 | [diff] [blame] | 81 | begin_impl_frame_tracker_(BEGINFRAMETRACKER_FROM_HERE), |
enne@chromium.org | a8335ac0 | 2013-03-16 09:15:12 | [diff] [blame] | 82 | state_machine_(scheduler_settings), |
epenner@chromium.org | c48536a5 | 2013-09-14 00:02:08 | [diff] [blame] | 83 | inside_process_scheduled_actions_(false), |
dmichael@chromium.org | 526bc6c | 2013-10-08 20:34:32 | [diff] [blame] | 84 | inside_action_(SchedulerStateMachine::ACTION_NONE), |
| 85 | weak_factory_(this) { |
mithro@mithis.com | ea00bf6a | 2014-05-11 00:53:20 | [diff] [blame] | 86 | TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), |
| 87 | "Scheduler::Scheduler", |
| 88 | "settings", |
yurys@chromium.org | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 89 | settings_.AsValue()); |
enne@chromium.org | a8335ac0 | 2013-03-16 09:15:12 | [diff] [blame] | 90 | DCHECK(client_); |
brianderson@chromium.org | 97e9ccd6 | 2014-04-12 01:07:15 | [diff] [blame] | 91 | DCHECK(!state_machine_.BeginFrameNeeded()); |
brianderson@chromium.org | beed86c | 2014-04-04 04:34:28 | [diff] [blame] | 92 | |
brianderson@chromium.org | 97e9ccd6 | 2014-04-12 01:07:15 | [diff] [blame] | 93 | begin_retro_frame_closure_ = |
| 94 | base::Bind(&Scheduler::BeginRetroFrame, weak_factory_.GetWeakPtr()); |
brianderson@chromium.org | beed86c | 2014-04-04 04:34:28 | [diff] [blame] | 95 | begin_impl_frame_deadline_closure_ = base::Bind( |
| 96 | &Scheduler::OnBeginImplFrameDeadline, weak_factory_.GetWeakPtr()); |
brianderson@chromium.org | beed86c | 2014-04-04 04:34:28 | [diff] [blame] | 97 | advance_commit_state_closure_ = base::Bind( |
| 98 | &Scheduler::PollToAdvanceCommitState, weak_factory_.GetWeakPtr()); |
brianderson@chromium.org | 3dc0c77 | 2014-04-26 10:06:05 | [diff] [blame] | 99 | |
mithro | c34fc0b1 | 2014-09-30 09:10:41 | [diff] [blame] | 100 | frame_source_ = BeginFrameSourceMultiplexer::Create(); |
| 101 | frame_source_->AddObserver(this); |
| 102 | |
| 103 | // Primary frame source |
| 104 | primary_frame_source_ = |
| 105 | frame_sources_constructor->ConstructPrimaryFrameSource(this); |
| 106 | frame_source_->AddSource(primary_frame_source_); |
simonhong | a7e3ac4 | 2014-11-11 20:50:22 | [diff] [blame] | 107 | primary_frame_source_->SetClientReady(); |
mithro | c34fc0b1 | 2014-09-30 09:10:41 | [diff] [blame] | 108 | |
bajones | 27411061 | 2015-01-06 20:53:59 | [diff] [blame] | 109 | // Unthrottled frame source |
| 110 | unthrottled_frame_source_ = |
| 111 | frame_sources_constructor->ConstructUnthrottledFrameSource(this); |
| 112 | frame_source_->AddSource(unthrottled_frame_source_); |
mithro | 4c7c7690 | 2015-04-09 07:05:01 | [diff] [blame] | 113 | |
| 114 | SetThrottleFrameProduction(scheduler_settings.throttle_frame_production); |
jamesr@chromium.org | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 115 | } |
| 116 | |
brianderson@chromium.org | 3dc0c77 | 2014-04-26 10:06:05 | [diff] [blame] | 117 | Scheduler::~Scheduler() { |
simonhong | a7e3ac4 | 2014-11-11 20:50:22 | [diff] [blame] | 118 | if (frame_source_->NeedsBeginFrames()) |
| 119 | frame_source_->SetNeedsBeginFrames(false); |
sunnyps | b2514f2f | 2015-04-14 22:51:57 | [diff] [blame] | 120 | frame_source_->SetActiveSource(nullptr); |
mithro | 0c0ac6a | 2014-09-10 01:03:36 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | base::TimeTicks Scheduler::Now() const { |
abhishek.ka | 7215854d | 2015-05-26 06:13:17 | [diff] [blame] | 124 | base::TimeTicks now = base::TimeTicks::Now(); |
mithro | c34fc0b1 | 2014-09-30 09:10:41 | [diff] [blame] | 125 | TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.now"), |
| 126 | "Scheduler::Now", |
| 127 | "now", |
| 128 | now); |
| 129 | return now; |
sunnyps | 34093979 | 2014-10-16 21:59:58 | [diff] [blame] | 130 | } |
| 131 | |
brianderson@chromium.org | 3dc0c77 | 2014-04-26 10:06:05 | [diff] [blame] | 132 | void Scheduler::CommitVSyncParameters(base::TimeTicks timebase, |
| 133 | base::TimeDelta interval) { |
simonhong | 298590fe | 2015-03-25 06:51:13 | [diff] [blame] | 134 | if (authoritative_vsync_interval_ != base::TimeDelta()) { |
| 135 | interval = authoritative_vsync_interval_; |
| 136 | } else if (interval == base::TimeDelta()) { |
| 137 | // TODO(brianderson): We should not be receiving 0 intervals. |
brianderson@chromium.org | 3dc0c77 | 2014-04-26 10:06:05 | [diff] [blame] | 138 | interval = BeginFrameArgs::DefaultInterval(); |
simonhong | 298590fe | 2015-03-25 06:51:13 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | last_vsync_timebase_ = timebase; |
mithro | c34fc0b1 | 2014-09-30 09:10:41 | [diff] [blame] | 142 | |
| 143 | if (vsync_observer_) |
| 144 | vsync_observer_->OnUpdateVSyncParameters(timebase, interval); |
brianderson@chromium.org | 3dc0c77 | 2014-04-26 10:06:05 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | void Scheduler::SetEstimatedParentDrawTime(base::TimeDelta draw_time) { |
brianderson@chromium.org | 1d142de8 | 2014-06-11 12:48:23 | [diff] [blame] | 148 | DCHECK_GE(draw_time.ToInternalValue(), 0); |
brianderson@chromium.org | 3dc0c77 | 2014-04-26 10:06:05 | [diff] [blame] | 149 | estimated_parent_draw_time_ = draw_time; |
| 150 | } |
enne@chromium.org | a8335ac0 | 2013-03-16 09:15:12 | [diff] [blame] | 151 | |
boliu@chromium.org | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 152 | void Scheduler::SetCanStart() { |
| 153 | state_machine_.SetCanStart(); |
enne@chromium.org | a8335ac0 | 2013-03-16 09:15:12 | [diff] [blame] | 154 | ProcessScheduledActions(); |
jamesr@chromium.org | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 155 | } |
| 156 | |
bajones | 27411061 | 2015-01-06 20:53:59 | [diff] [blame] | 157 | void Scheduler::SetVisible(bool visible) { |
| 158 | state_machine_.SetVisible(visible); |
mithro | 4c7c7690 | 2015-04-09 07:05:01 | [diff] [blame] | 159 | ProcessScheduledActions(); |
jamesr@chromium.org | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 160 | } |
| 161 | |
enne@chromium.org | a8335ac0 | 2013-03-16 09:15:12 | [diff] [blame] | 162 | void Scheduler::SetCanDraw(bool can_draw) { |
| 163 | state_machine_.SetCanDraw(can_draw); |
| 164 | ProcessScheduledActions(); |
jamesr@chromium.org | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 165 | } |
| 166 | |
brianderson@chromium.org | 4f48f6e | 2013-08-27 06:33:38 | [diff] [blame] | 167 | void Scheduler::NotifyReadyToActivate() { |
| 168 | state_machine_.NotifyReadyToActivate(); |
enne@chromium.org | a8335ac0 | 2013-03-16 09:15:12 | [diff] [blame] | 169 | ProcessScheduledActions(); |
brianderson@chromium.org | 425e533 | 2013-09-21 04:10:03 | [diff] [blame] | 170 | } |
| 171 | |
ernstm | dfac03e | 2014-11-11 20:18:05 | [diff] [blame] | 172 | void Scheduler::NotifyReadyToDraw() { |
weiliangc | 8dac5a6 | 2015-04-02 06:12:35 | [diff] [blame] | 173 | // Future work might still needed for crbug.com/352894. |
| 174 | state_machine_.NotifyReadyToDraw(); |
| 175 | ProcessScheduledActions(); |
ernstm | dfac03e | 2014-11-11 20:18:05 | [diff] [blame] | 176 | } |
| 177 | |
bajones | 27411061 | 2015-01-06 20:53:59 | [diff] [blame] | 178 | void Scheduler::SetThrottleFrameProduction(bool throttle) { |
| 179 | throttle_frame_production_ = throttle; |
mithro | 4c7c7690 | 2015-04-09 07:05:01 | [diff] [blame] | 180 | if (throttle) { |
| 181 | frame_source_->SetActiveSource(primary_frame_source_); |
| 182 | } else { |
| 183 | frame_source_->SetActiveSource(unthrottled_frame_source_); |
| 184 | } |
| 185 | ProcessScheduledActions(); |
bajones | 27411061 | 2015-01-06 20:53:59 | [diff] [blame] | 186 | } |
| 187 | |
enne@chromium.org | a8335ac0 | 2013-03-16 09:15:12 | [diff] [blame] | 188 | void Scheduler::SetNeedsCommit() { |
| 189 | state_machine_.SetNeedsCommit(); |
| 190 | ProcessScheduledActions(); |
enne@chromium.org | 2e7ca42 | 2012-12-20 02:57:27 | [diff] [blame] | 191 | } |
| 192 | |
enne@chromium.org | a8335ac0 | 2013-03-16 09:15:12 | [diff] [blame] | 193 | void Scheduler::SetNeedsRedraw() { |
| 194 | state_machine_.SetNeedsRedraw(); |
epenner@chromium.org | c48536a5 | 2013-09-14 00:02:08 | [diff] [blame] | 195 | ProcessScheduledActions(); |
| 196 | } |
| 197 | |
skyostil@chromium.org | 43b8f98 | 2014-04-30 21:24:33 | [diff] [blame] | 198 | void Scheduler::SetNeedsAnimate() { |
| 199 | state_machine_.SetNeedsAnimate(); |
| 200 | ProcessScheduledActions(); |
| 201 | } |
| 202 | |
vmiura | 59ea9b404 | 2014-12-09 20:50:39 | [diff] [blame] | 203 | void Scheduler::SetNeedsPrepareTiles() { |
| 204 | DCHECK(!IsInsideAction(SchedulerStateMachine::ACTION_PREPARE_TILES)); |
| 205 | state_machine_.SetNeedsPrepareTiles(); |
weiliangc | 8dac5a6 | 2015-04-02 06:12:35 | [diff] [blame] | 206 | ProcessScheduledActions(); |
| 207 | } |
| 208 | |
| 209 | void Scheduler::SetWaitForReadyToDraw() { |
| 210 | state_machine_.SetWaitForReadyToDraw(); |
enne@chromium.org | a8335ac0 | 2013-03-16 09:15:12 | [diff] [blame] | 211 | ProcessScheduledActions(); |
jamesr@chromium.org | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 212 | } |
| 213 | |
brianderson@chromium.org | c1490266 | 2014-04-18 05:06:11 | [diff] [blame] | 214 | void Scheduler::SetMaxSwapsPending(int max) { |
| 215 | state_machine_.SetMaxSwapsPending(max); |
| 216 | } |
| 217 | |
| 218 | void Scheduler::DidSwapBuffers() { |
| 219 | state_machine_.DidSwapBuffers(); |
simonhong@chromium.org | 30d8214 | 2014-05-12 04:26:02 | [diff] [blame] | 220 | |
brianderson@chromium.org | c1490266 | 2014-04-18 05:06:11 | [diff] [blame] | 221 | // There is no need to call ProcessScheduledActions here because |
| 222 | // swapping should not trigger any new actions. |
| 223 | if (!inside_process_scheduled_actions_) { |
| 224 | DCHECK_EQ(state_machine_.NextAction(), SchedulerStateMachine::ACTION_NONE); |
| 225 | } |
| 226 | } |
| 227 | |
brianderson@chromium.org | c1490266 | 2014-04-18 05:06:11 | [diff] [blame] | 228 | void Scheduler::DidSwapBuffersComplete() { |
brianderson | 1545de0 | 2015-06-05 22:05:44 | [diff] [blame^] | 229 | DCHECK_GT(state_machine_.pending_swaps(), 0) << AsValue()->ToString(); |
brianderson@chromium.org | c1490266 | 2014-04-18 05:06:11 | [diff] [blame] | 230 | state_machine_.DidSwapBuffersComplete(); |
enne@chromium.org | a8335ac0 | 2013-03-16 09:15:12 | [diff] [blame] | 231 | ProcessScheduledActions(); |
brianderson@chromium.org | 74d9063c | 2013-01-18 03:14:47 | [diff] [blame] | 232 | } |
| 233 | |
skyostil | 733d7ab | 2014-09-04 23:11:32 | [diff] [blame] | 234 | void Scheduler::SetImplLatencyTakesPriority(bool impl_latency_takes_priority) { |
| 235 | state_machine_.SetImplLatencyTakesPriority(impl_latency_takes_priority); |
skyostil@chromium.org | b56e320c | 2013-10-22 16:17:28 | [diff] [blame] | 236 | ProcessScheduledActions(); |
| 237 | } |
| 238 | |
simonhong@chromium.org | 6f11845 | 2014-03-10 07:11:11 | [diff] [blame] | 239 | void Scheduler::NotifyReadyToCommit() { |
| 240 | TRACE_EVENT0("cc", "Scheduler::NotifyReadyToCommit"); |
| 241 | state_machine_.NotifyReadyToCommit(); |
enne@chromium.org | a8335ac0 | 2013-03-16 09:15:12 | [diff] [blame] | 242 | ProcessScheduledActions(); |
jamesr@chromium.org | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 243 | } |
| 244 | |
mithro | f7a2150 | 2014-12-17 03:24:48 | [diff] [blame] | 245 | void Scheduler::BeginMainFrameAborted(CommitEarlyOutReason reason) { |
| 246 | TRACE_EVENT1("cc", "Scheduler::BeginMainFrameAborted", "reason", |
| 247 | CommitEarlyOutReasonToString(reason)); |
| 248 | state_machine_.BeginMainFrameAborted(reason); |
enne@chromium.org | a8335ac0 | 2013-03-16 09:15:12 | [diff] [blame] | 249 | ProcessScheduledActions(); |
jamesr@chromium.org | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 250 | } |
| 251 | |
vmiura | 59ea9b404 | 2014-12-09 20:50:39 | [diff] [blame] | 252 | void Scheduler::DidPrepareTiles() { |
| 253 | state_machine_.DidPrepareTiles(); |
enne@chromium.org | bac0e55 | 2013-11-05 22:38:51 | [diff] [blame] | 254 | } |
| 255 | |
enne@chromium.org | a8335ac0 | 2013-03-16 09:15:12 | [diff] [blame] | 256 | void Scheduler::DidLoseOutputSurface() { |
danakj@chromium.org | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 257 | TRACE_EVENT0("cc", "Scheduler::DidLoseOutputSurface"); |
sunnyps | 324cd53 | 2014-12-30 21:28:10 | [diff] [blame] | 258 | begin_retro_frame_args_.clear(); |
| 259 | begin_retro_frame_task_.Cancel(); |
enne@chromium.org | a8335ac0 | 2013-03-16 09:15:12 | [diff] [blame] | 260 | state_machine_.DidLoseOutputSurface(); |
| 261 | ProcessScheduledActions(); |
jamesr@chromium.org | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 262 | } |
| 263 | |
boliu@chromium.org | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 264 | void Scheduler::DidCreateAndInitializeOutputSurface() { |
| 265 | TRACE_EVENT0("cc", "Scheduler::DidCreateAndInitializeOutputSurface"); |
mithro | c34fc0b1 | 2014-09-30 09:10:41 | [diff] [blame] | 266 | DCHECK(!frame_source_->NeedsBeginFrames()); |
brianderson@chromium.org | beed86c | 2014-04-04 04:34:28 | [diff] [blame] | 267 | DCHECK(begin_impl_frame_deadline_task_.IsCancelled()); |
boliu@chromium.org | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 268 | state_machine_.DidCreateAndInitializeOutputSurface(); |
enne@chromium.org | a8335ac0 | 2013-03-16 09:15:12 | [diff] [blame] | 269 | ProcessScheduledActions(); |
jamesr@chromium.org | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 270 | } |
| 271 | |
simonhong@chromium.org | eb2d2abc | 2014-03-07 16:19:59 | [diff] [blame] | 272 | void Scheduler::NotifyBeginMainFrameStarted() { |
| 273 | TRACE_EVENT0("cc", "Scheduler::NotifyBeginMainFrameStarted"); |
| 274 | state_machine_.NotifyBeginMainFrameStarted(); |
| 275 | } |
| 276 | |
skyostil@chromium.org | 5c58f22 | 2014-03-07 03:34:09 | [diff] [blame] | 277 | base::TimeTicks Scheduler::AnticipatedDrawTime() const { |
mithro | c34fc0b1 | 2014-09-30 09:10:41 | [diff] [blame] | 278 | if (!frame_source_->NeedsBeginFrames() || |
mithro | 0bdb49d | 2015-05-27 13:08:01 | [diff] [blame] | 279 | begin_impl_frame_tracker_.DangerousMethodHasFinished()) |
brianderson@chromium.org | 049fc7a | 2013-06-18 12:32:35 | [diff] [blame] | 280 | return base::TimeTicks(); |
| 281 | |
mithro | 0c0ac6a | 2014-09-10 01:03:36 | [diff] [blame] | 282 | base::TimeTicks now = Now(); |
mithro | 0bdb49d | 2015-05-27 13:08:01 | [diff] [blame] | 283 | BeginFrameArgs args = begin_impl_frame_tracker_.Current(); |
| 284 | base::TimeTicks timebase = std::max(args.frame_time, args.deadline); |
| 285 | int64 intervals = |
| 286 | 1 + ((now - timebase) / begin_impl_frame_tracker_.Interval()); |
| 287 | return timebase + (begin_impl_frame_tracker_.Interval() * intervals); |
jamesr@chromium.org | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 288 | } |
| 289 | |
dominikg@chromium.org | 87379cde | 2013-10-21 23:19:52 | [diff] [blame] | 290 | base::TimeTicks Scheduler::LastBeginImplFrameTime() { |
mithro | 0bdb49d | 2015-05-27 13:08:01 | [diff] [blame] | 291 | return begin_impl_frame_tracker_.Current().frame_time; |
reveman@chromium.org | e8e410d | 2012-09-28 01:47:01 | [diff] [blame] | 292 | } |
| 293 | |
brianderson@chromium.org | 97e9ccd6 | 2014-04-12 01:07:15 | [diff] [blame] | 294 | void Scheduler::SetupNextBeginFrameIfNeeded() { |
sunnyps | 32f0125 | 2015-03-19 03:50:29 | [diff] [blame] | 295 | // Never call SetNeedsBeginFrames if the frame source already has the right |
| 296 | // value. |
| 297 | if (frame_source_->NeedsBeginFrames() != state_machine_.BeginFrameNeeded()) { |
| 298 | if (state_machine_.BeginFrameNeeded()) { |
| 299 | // Call SetNeedsBeginFrames(true) as soon as possible. |
| 300 | frame_source_->SetNeedsBeginFrames(true); |
caseq | b6a5889 | 2015-05-27 13:14:29 | [diff] [blame] | 301 | devtools_instrumentation::NeedsBeginFrameChanged(layer_tree_host_id_, |
| 302 | true); |
sunnyps | 32f0125 | 2015-03-19 03:50:29 | [diff] [blame] | 303 | } else if (state_machine_.begin_impl_frame_state() == |
| 304 | SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE) { |
| 305 | // Call SetNeedsBeginFrames(false) in between frames only. |
| 306 | frame_source_->SetNeedsBeginFrames(false); |
rmcilroy | 0a19362a | 2015-02-18 12:34:25 | [diff] [blame] | 307 | client_->SendBeginMainFrameNotExpectedSoon(); |
caseq | b6a5889 | 2015-05-27 13:14:29 | [diff] [blame] | 308 | devtools_instrumentation::NeedsBeginFrameChanged(layer_tree_host_id_, |
| 309 | false); |
rmcilroy | 0a19362a | 2015-02-18 12:34:25 | [diff] [blame] | 310 | } |
mithro | c34fc0b1 | 2014-09-30 09:10:41 | [diff] [blame] | 311 | } |
| 312 | |
brianderson@chromium.org | 3dc0c77 | 2014-04-26 10:06:05 | [diff] [blame] | 313 | PostBeginRetroFrameIfNeeded(); |
brianderson@chromium.org | 3dc0c77 | 2014-04-26 10:06:05 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | // We may need to poll when we can't rely on BeginFrame to advance certain |
| 317 | // state or to avoid deadlock. |
sunnyps | ecc5d20 | 2015-01-05 23:46:53 | [diff] [blame] | 318 | void Scheduler::SetupPollingMechanisms() { |
sunnyps | eab5ac9 | 2015-04-02 20:26:13 | [diff] [blame] | 319 | // At this point we'd prefer to advance through the commit flow by |
| 320 | // drawing a frame, however it's possible that the frame rate controller |
| 321 | // will not give us a BeginFrame until the commit completes. See |
| 322 | // crbug.com/317430 for an example of a swap ack being held on commit. Thus |
| 323 | // we set a repeating timer to poll on ProcessScheduledActions until we |
| 324 | // successfully reach BeginFrame. Synchronous compositor does not use |
| 325 | // frame rate controller or have the circular wait in the bug. |
| 326 | if (IsBeginMainFrameSentOrStarted() && |
| 327 | !settings_.using_synchronous_renderer_compositor) { |
brianderson@chromium.org | beed86c | 2014-04-04 04:34:28 | [diff] [blame] | 328 | if (advance_commit_state_task_.IsCancelled() && |
mithro | 0bdb49d | 2015-05-27 13:08:01 | [diff] [blame] | 329 | begin_impl_frame_tracker_.DangerousMethodCurrentOrLast().IsValid()) { |
boliu@chromium.org | 48abf81 | 2014-03-20 17:41:59 | [diff] [blame] | 330 | // Since we'd rather get a BeginImplFrame by the normal mechanism, we |
| 331 | // set the interval to twice the interval from the previous frame. |
brianderson@chromium.org | beed86c | 2014-04-04 04:34:28 | [diff] [blame] | 332 | advance_commit_state_task_.Reset(advance_commit_state_closure_); |
enne@chromium.org | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 333 | task_runner_->PostDelayedTask(FROM_HERE, |
| 334 | advance_commit_state_task_.callback(), |
mithro | 0bdb49d | 2015-05-27 13:08:01 | [diff] [blame] | 335 | begin_impl_frame_tracker_.Interval() * 2); |
brianderson@chromium.org | 875fb5bc | 2013-12-13 11:58:47 | [diff] [blame] | 336 | } |
brianderson@chromium.org | 22646b0 | 2014-04-03 23:55:32 | [diff] [blame] | 337 | } else { |
brianderson@chromium.org | beed86c | 2014-04-04 04:34:28 | [diff] [blame] | 338 | advance_commit_state_task_.Cancel(); |
brianderson@chromium.org | 049fc7a | 2013-06-18 12:32:35 | [diff] [blame] | 339 | } |
| 340 | } |
| 341 | |
brianderson@chromium.org | 97e9ccd6 | 2014-04-12 01:07:15 | [diff] [blame] | 342 | // BeginFrame is the mechanism that tells us that now is a good time to start |
| 343 | // making a frame. Usually this means that user input for the frame is complete. |
| 344 | // If the scheduler is busy, we queue the BeginFrame to be handled later as |
| 345 | // a BeginRetroFrame. |
mithro | c34fc0b1 | 2014-09-30 09:10:41 | [diff] [blame] | 346 | bool Scheduler::OnBeginFrameMixInDelegate(const BeginFrameArgs& args) { |
miletus | fed8c43b | 2015-01-26 20:04:52 | [diff] [blame] | 347 | TRACE_EVENT1("cc,benchmark", "Scheduler::BeginFrame", "args", args.AsValue()); |
mithro | 0bdb49d | 2015-05-27 13:08:01 | [diff] [blame] | 348 | |
| 349 | // Trace this begin frame time through the Chrome stack |
| 350 | TRACE_EVENT_FLOW_BEGIN0( |
| 351 | TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), "BeginFrameArgs", |
| 352 | args.frame_time.ToInternalValue()); |
mithro | c34fc0b1 | 2014-09-30 09:10:41 | [diff] [blame] | 353 | |
brianderson | 7d4d98d | 2015-05-05 03:24:17 | [diff] [blame] | 354 | // TODO(brianderson): Adjust deadline in the DisplayScheduler. |
sunnyps | b1e2f5ec | 2015-03-24 01:39:45 | [diff] [blame] | 355 | BeginFrameArgs adjusted_args(args); |
| 356 | adjusted_args.deadline -= EstimatedParentDrawTime(); |
| 357 | |
brianderson | 7d4d98d | 2015-05-05 03:24:17 | [diff] [blame] | 358 | // Deliver BeginFrames to children. |
| 359 | // TODO(brianderson): Move this responsibility to the DisplayScheduler. |
| 360 | if (state_machine_.children_need_begin_frames()) |
| 361 | client_->SendBeginFramesToChildren(adjusted_args); |
| 362 | |
sunnyps | eab5ac9 | 2015-04-02 20:26:13 | [diff] [blame] | 363 | if (settings_.using_synchronous_renderer_compositor) { |
| 364 | BeginImplFrameSynchronous(adjusted_args); |
| 365 | return true; |
| 366 | } |
| 367 | |
mithro | c34fc0b1 | 2014-09-30 09:10:41 | [diff] [blame] | 368 | // We have just called SetNeedsBeginFrame(true) and the BeginFrameSource has |
| 369 | // sent us the last BeginFrame we have missed. As we might not be able to |
| 370 | // actually make rendering for this call, handle it like a "retro frame". |
| 371 | // TODO(brainderson): Add a test for this functionality ASAP! |
sunnyps | b1e2f5ec | 2015-03-24 01:39:45 | [diff] [blame] | 372 | if (adjusted_args.type == BeginFrameArgs::MISSED) { |
| 373 | begin_retro_frame_args_.push_back(adjusted_args); |
mithro | c34fc0b1 | 2014-09-30 09:10:41 | [diff] [blame] | 374 | PostBeginRetroFrameIfNeeded(); |
| 375 | return true; |
| 376 | } |
mithro@mithis.com | b62dcb8 | 2014-06-11 13:27:48 | [diff] [blame] | 377 | |
sunnyps | eab5ac9 | 2015-04-02 20:26:13 | [diff] [blame] | 378 | bool should_defer_begin_frame = |
| 379 | !begin_retro_frame_args_.empty() || |
| 380 | !begin_retro_frame_task_.IsCancelled() || |
| 381 | !frame_source_->NeedsBeginFrames() || |
| 382 | (state_machine_.begin_impl_frame_state() != |
| 383 | SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); |
brianderson@chromium.org | 97e9ccd6 | 2014-04-12 01:07:15 | [diff] [blame] | 384 | |
| 385 | if (should_defer_begin_frame) { |
mithro@mithis.com | b62dcb8 | 2014-06-11 13:27:48 | [diff] [blame] | 386 | begin_retro_frame_args_.push_back(adjusted_args); |
brianderson@chromium.org | 97e9ccd6 | 2014-04-12 01:07:15 | [diff] [blame] | 387 | TRACE_EVENT_INSTANT0( |
| 388 | "cc", "Scheduler::BeginFrame deferred", TRACE_EVENT_SCOPE_THREAD); |
mithro | c34fc0b1 | 2014-09-30 09:10:41 | [diff] [blame] | 389 | // Queuing the frame counts as "using it", so we need to return true. |
| 390 | } else { |
sunnyps | eab5ac9 | 2015-04-02 20:26:13 | [diff] [blame] | 391 | BeginImplFrameWithDeadline(adjusted_args); |
brianderson@chromium.org | 97e9ccd6 | 2014-04-12 01:07:15 | [diff] [blame] | 392 | } |
mithro | c34fc0b1 | 2014-09-30 09:10:41 | [diff] [blame] | 393 | return true; |
brianderson@chromium.org | 97e9ccd6 | 2014-04-12 01:07:15 | [diff] [blame] | 394 | } |
| 395 | |
simonhong | d3d5f7f | 2014-11-21 16:38:03 | [diff] [blame] | 396 | void Scheduler::SetChildrenNeedBeginFrames(bool children_need_begin_frames) { |
simonhong | d3d5f7f | 2014-11-21 16:38:03 | [diff] [blame] | 397 | state_machine_.SetChildrenNeedBeginFrames(children_need_begin_frames); |
simonhong | 22c5f0f2 | 2014-12-16 00:06:37 | [diff] [blame] | 398 | ProcessScheduledActions(); |
sunnyps | eab5ac9 | 2015-04-02 20:26:13 | [diff] [blame] | 399 | } |
| 400 | |
brianderson | 2954ab1 | 2015-04-14 05:42:35 | [diff] [blame] | 401 | void Scheduler::SetAuthoritativeVSyncInterval(const base::TimeDelta& interval) { |
| 402 | authoritative_vsync_interval_ = interval; |
| 403 | if (vsync_observer_) |
| 404 | vsync_observer_->OnUpdateVSyncParameters(last_vsync_timebase_, interval); |
| 405 | } |
| 406 | |
sunnyps | 7d073dc | 2015-04-16 23:29:12 | [diff] [blame] | 407 | void Scheduler::SetVideoNeedsBeginFrames(bool video_needs_begin_frames) { |
| 408 | state_machine_.SetVideoNeedsBeginFrames(video_needs_begin_frames); |
| 409 | ProcessScheduledActions(); |
| 410 | } |
| 411 | |
sunnyps | eab5ac9 | 2015-04-02 20:26:13 | [diff] [blame] | 412 | void Scheduler::OnDrawForOutputSurface() { |
| 413 | DCHECK(settings_.using_synchronous_renderer_compositor); |
| 414 | DCHECK_EQ(state_machine_.begin_impl_frame_state(), |
| 415 | SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); |
| 416 | DCHECK(!BeginImplFrameDeadlinePending()); |
| 417 | |
| 418 | state_machine_.OnBeginImplFrameDeadline(); |
| 419 | ProcessScheduledActions(); |
| 420 | |
| 421 | state_machine_.OnBeginImplFrameIdle(); |
| 422 | ProcessScheduledActions(); |
simonhong | 298590fe | 2015-03-25 06:51:13 | [diff] [blame] | 423 | } |
| 424 | |
brianderson@chromium.org | 97e9ccd6 | 2014-04-12 01:07:15 | [diff] [blame] | 425 | // BeginRetroFrame is called for BeginFrames that we've deferred because |
| 426 | // the scheduler was in the middle of processing a previous BeginFrame. |
| 427 | void Scheduler::BeginRetroFrame() { |
miletus | fed8c43b | 2015-01-26 20:04:52 | [diff] [blame] | 428 | TRACE_EVENT0("cc,benchmark", "Scheduler::BeginRetroFrame"); |
brianderson@chromium.org | 97e9ccd6 | 2014-04-12 01:07:15 | [diff] [blame] | 429 | DCHECK(!settings_.using_synchronous_renderer_compositor); |
sunnyps | 324cd53 | 2014-12-30 21:28:10 | [diff] [blame] | 430 | DCHECK(!begin_retro_frame_args_.empty()); |
| 431 | DCHECK(!begin_retro_frame_task_.IsCancelled()); |
brianderson | 8ecfc9c | 2014-12-23 02:42:38 | [diff] [blame] | 432 | DCHECK_EQ(state_machine_.begin_impl_frame_state(), |
| 433 | SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); |
brianderson@chromium.org | 3dc0c77 | 2014-04-26 10:06:05 | [diff] [blame] | 434 | |
sunnyps | 324cd53 | 2014-12-30 21:28:10 | [diff] [blame] | 435 | begin_retro_frame_task_.Cancel(); |
brianderson@chromium.org | 97e9ccd6 | 2014-04-12 01:07:15 | [diff] [blame] | 436 | |
| 437 | // Discard expired BeginRetroFrames |
| 438 | // Today, we should always end up with at most one un-expired BeginRetroFrame |
| 439 | // because deadlines will not be greater than the next frame time. We don't |
| 440 | // DCHECK though because some systems don't always have monotonic timestamps. |
| 441 | // TODO(brianderson): In the future, long deadlines could result in us not |
| 442 | // draining the queue if we don't catch up. If we consistently can't catch |
| 443 | // up, our fallback should be to lower our frame rate. |
mithro | 0c0ac6a | 2014-09-10 01:03:36 | [diff] [blame] | 444 | base::TimeTicks now = Now(); |
mithro | 7deb276 | 2014-09-19 01:07:51 | [diff] [blame] | 445 | |
sunnyps | 977116d | 2014-11-26 20:33:30 | [diff] [blame] | 446 | while (!begin_retro_frame_args_.empty()) { |
| 447 | const BeginFrameArgs& args = begin_retro_frame_args_.front(); |
sunnyps | 7e4f0459 | 2015-05-20 01:43:57 | [diff] [blame] | 448 | base::TimeTicks expiration_time = args.deadline; |
sunnyps | 977116d | 2014-11-26 20:33:30 | [diff] [blame] | 449 | if (now <= expiration_time) |
| 450 | break; |
| 451 | TRACE_EVENT_INSTANT2( |
| 452 | "cc", "Scheduler::BeginRetroFrame discarding", TRACE_EVENT_SCOPE_THREAD, |
| 453 | "expiration_time - now", (expiration_time - now).InMillisecondsF(), |
| 454 | "BeginFrameArgs", begin_retro_frame_args_.front().AsValue()); |
brianderson@chromium.org | 97e9ccd6 | 2014-04-12 01:07:15 | [diff] [blame] | 455 | begin_retro_frame_args_.pop_front(); |
mithro | c34fc0b1 | 2014-09-30 09:10:41 | [diff] [blame] | 456 | frame_source_->DidFinishFrame(begin_retro_frame_args_.size()); |
brianderson@chromium.org | 97e9ccd6 | 2014-04-12 01:07:15 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | if (begin_retro_frame_args_.empty()) { |
mithro@mithis.com | 1ae2e64 | 2014-05-02 05:33:33 | [diff] [blame] | 460 | TRACE_EVENT_INSTANT0("cc", |
| 461 | "Scheduler::BeginRetroFrames all expired", |
| 462 | TRACE_EVENT_SCOPE_THREAD); |
brianderson@chromium.org | 97e9ccd6 | 2014-04-12 01:07:15 | [diff] [blame] | 463 | } else { |
danakj | 8d1716fb | 2014-11-14 23:04:49 | [diff] [blame] | 464 | BeginFrameArgs front = begin_retro_frame_args_.front(); |
brianderson@chromium.org | 97e9ccd6 | 2014-04-12 01:07:15 | [diff] [blame] | 465 | begin_retro_frame_args_.pop_front(); |
sunnyps | eab5ac9 | 2015-04-02 20:26:13 | [diff] [blame] | 466 | BeginImplFrameWithDeadline(front); |
brianderson@chromium.org | 97e9ccd6 | 2014-04-12 01:07:15 | [diff] [blame] | 467 | } |
brianderson@chromium.org | 97e9ccd6 | 2014-04-12 01:07:15 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | // There could be a race between the posted BeginRetroFrame and a new |
| 471 | // BeginFrame arriving via the normal mechanism. Scheduler::BeginFrame |
| 472 | // will check if there is a pending BeginRetroFrame to ensure we handle |
| 473 | // BeginFrames in FIFO order. |
| 474 | void Scheduler::PostBeginRetroFrameIfNeeded() { |
mithro | 0c0ac6a | 2014-09-10 01:03:36 | [diff] [blame] | 475 | TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), |
| 476 | "Scheduler::PostBeginRetroFrameIfNeeded", |
| 477 | "state", |
| 478 | AsValue()); |
mithro | c34fc0b1 | 2014-09-30 09:10:41 | [diff] [blame] | 479 | if (!frame_source_->NeedsBeginFrames()) |
brianderson@chromium.org | 3dc0c77 | 2014-04-26 10:06:05 | [diff] [blame] | 480 | return; |
| 481 | |
sunnyps | 324cd53 | 2014-12-30 21:28:10 | [diff] [blame] | 482 | if (begin_retro_frame_args_.empty() || !begin_retro_frame_task_.IsCancelled()) |
brianderson@chromium.org | 97e9ccd6 | 2014-04-12 01:07:15 | [diff] [blame] | 483 | return; |
| 484 | |
| 485 | // begin_retro_frame_args_ should always be empty for the |
| 486 | // synchronous compositor. |
| 487 | DCHECK(!settings_.using_synchronous_renderer_compositor); |
| 488 | |
| 489 | if (state_machine_.begin_impl_frame_state() != |
| 490 | SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE) |
| 491 | return; |
| 492 | |
sunnyps | 324cd53 | 2014-12-30 21:28:10 | [diff] [blame] | 493 | begin_retro_frame_task_.Reset(begin_retro_frame_closure_); |
| 494 | |
| 495 | task_runner_->PostTask(FROM_HERE, begin_retro_frame_task_.callback()); |
brianderson@chromium.org | 97e9ccd6 | 2014-04-12 01:07:15 | [diff] [blame] | 496 | } |
| 497 | |
sunnyps | eab5ac9 | 2015-04-02 20:26:13 | [diff] [blame] | 498 | void Scheduler::BeginImplFrameWithDeadline(const BeginFrameArgs& args) { |
sunnyps | 79f33c3 | 2015-04-23 20:56:38 | [diff] [blame] | 499 | bool main_thread_is_in_high_latency_mode = |
| 500 | state_machine_.MainThreadIsInHighLatencyMode(); |
| 501 | TRACE_EVENT2("cc,benchmark", "Scheduler::BeginImplFrame", "args", |
| 502 | args.AsValue(), "main_thread_is_high_latency", |
| 503 | main_thread_is_in_high_latency_mode); |
| 504 | TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), |
| 505 | "MainThreadLatency", main_thread_is_in_high_latency_mode); |
| 506 | |
| 507 | advance_commit_state_task_.Cancel(); |
| 508 | |
mithro | 0bdb49d | 2015-05-27 13:08:01 | [diff] [blame] | 509 | BeginFrameArgs adjusted_args = args; |
| 510 | adjusted_args.deadline -= client_->DrawDurationEstimate(); |
sunnyps | 79f33c3 | 2015-04-23 20:56:38 | [diff] [blame] | 511 | |
| 512 | if (!state_machine_.impl_latency_takes_priority() && |
| 513 | main_thread_is_in_high_latency_mode && |
| 514 | CanCommitAndActivateBeforeDeadline()) { |
| 515 | state_machine_.SetSkipNextBeginMainFrameToReduceLatency(); |
| 516 | } |
| 517 | |
mithro | 0bdb49d | 2015-05-27 13:08:01 | [diff] [blame] | 518 | BeginImplFrame(adjusted_args); |
sunnyps | eab5ac9 | 2015-04-02 20:26:13 | [diff] [blame] | 519 | |
| 520 | // The deadline will be scheduled in ProcessScheduledActions. |
| 521 | state_machine_.OnBeginImplFrameDeadlinePending(); |
| 522 | ProcessScheduledActions(); |
| 523 | } |
| 524 | |
| 525 | void Scheduler::BeginImplFrameSynchronous(const BeginFrameArgs& args) { |
sunnyps | 79f33c3 | 2015-04-23 20:56:38 | [diff] [blame] | 526 | TRACE_EVENT1("cc,benchmark", "Scheduler::BeginImplFrame", "args", |
| 527 | args.AsValue()); |
mithro | 0bdb49d | 2015-05-27 13:08:01 | [diff] [blame] | 528 | BeginImplFrame(args); |
sunnyps | eab5ac9 | 2015-04-02 20:26:13 | [diff] [blame] | 529 | FinishImplFrame(); |
| 530 | } |
| 531 | |
| 532 | void Scheduler::FinishImplFrame() { |
| 533 | state_machine_.OnBeginImplFrameIdle(); |
| 534 | ProcessScheduledActions(); |
| 535 | |
mithro | 51693e38 | 2015-05-07 23:52:41 | [diff] [blame] | 536 | client_->DidFinishImplFrame(); |
sunnyps | eab5ac9 | 2015-04-02 20:26:13 | [diff] [blame] | 537 | frame_source_->DidFinishFrame(begin_retro_frame_args_.size()); |
mithro | 0bdb49d | 2015-05-27 13:08:01 | [diff] [blame] | 538 | begin_impl_frame_tracker_.Finish(); |
sunnyps | eab5ac9 | 2015-04-02 20:26:13 | [diff] [blame] | 539 | } |
| 540 | |
brianderson@chromium.org | 97e9ccd6 | 2014-04-12 01:07:15 | [diff] [blame] | 541 | // BeginImplFrame starts a compositor frame that will wait up until a deadline |
| 542 | // for a BeginMainFrame+activation to complete before it times out and draws |
| 543 | // any asynchronous animation and scroll/pinch updates. |
mithro | 0bdb49d | 2015-05-27 13:08:01 | [diff] [blame] | 544 | void Scheduler::BeginImplFrame(const BeginFrameArgs& args) { |
enne@chromium.org | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 545 | DCHECK_EQ(state_machine_.begin_impl_frame_state(), |
| 546 | SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); |
sunnyps | eab5ac9 | 2015-04-02 20:26:13 | [diff] [blame] | 547 | DCHECK(!BeginImplFrameDeadlinePending()); |
brianderson@chromium.org | 67bc099 | 2013-09-24 06:24:03 | [diff] [blame] | 548 | DCHECK(state_machine_.HasInitializedOutputSurface()); |
sunnyps | 79f33c3 | 2015-04-23 20:56:38 | [diff] [blame] | 549 | DCHECK(advance_commit_state_task_.IsCancelled()); |
skyostil@chromium.org | 6d5aa6f | 2014-03-04 21:42:17 | [diff] [blame] | 550 | |
mithro | 0bdb49d | 2015-05-27 13:08:01 | [diff] [blame] | 551 | begin_impl_frame_tracker_.Start(args); |
sunnyps | bd2c8968 | 2015-03-20 00:13:12 | [diff] [blame] | 552 | state_machine_.OnBeginImplFrame(); |
caseq@chromium.org | d7309448 | 2014-02-13 21:28:28 | [diff] [blame] | 553 | devtools_instrumentation::DidBeginFrame(layer_tree_host_id_); |
mithro | 0bdb49d | 2015-05-27 13:08:01 | [diff] [blame] | 554 | client_->WillBeginImplFrame(begin_impl_frame_tracker_.Current()); |
dominikg@chromium.org | 56ec730 | 2013-11-08 00:51:45 | [diff] [blame] | 555 | |
enne@chromium.org | a8335ac0 | 2013-03-16 09:15:12 | [diff] [blame] | 556 | ProcessScheduledActions(); |
skyostil@chromium.org | 46cc0d6 | 2014-03-11 00:35:16 | [diff] [blame] | 557 | } |
| 558 | |
sunnyps | 5d8bb1d2 | 2014-12-08 20:48:10 | [diff] [blame] | 559 | void Scheduler::ScheduleBeginImplFrameDeadline() { |
sunnyps | 977116d | 2014-11-26 20:33:30 | [diff] [blame] | 560 | // The synchronous compositor does not post a deadline task. |
| 561 | DCHECK(!settings_.using_synchronous_renderer_compositor); |
brianderson@chromium.org | 425e533 | 2013-09-21 04:10:03 | [diff] [blame] | 562 | |
brianderson@chromium.org | beed86c | 2014-04-04 04:34:28 | [diff] [blame] | 563 | begin_impl_frame_deadline_task_.Cancel(); |
| 564 | begin_impl_frame_deadline_task_.Reset(begin_impl_frame_deadline_closure_); |
sunnyps | 5d8bb1d2 | 2014-12-08 20:48:10 | [diff] [blame] | 565 | |
| 566 | begin_impl_frame_deadline_mode_ = |
| 567 | state_machine_.CurrentBeginImplFrameDeadlineMode(); |
| 568 | |
| 569 | base::TimeTicks deadline; |
| 570 | switch (begin_impl_frame_deadline_mode_) { |
sunnyps | eab5ac9 | 2015-04-02 20:26:13 | [diff] [blame] | 571 | case SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE: |
| 572 | // No deadline. |
| 573 | return; |
sunnyps | 5d8bb1d2 | 2014-12-08 20:48:10 | [diff] [blame] | 574 | case SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_IMMEDIATE: |
| 575 | // We are ready to draw a new active tree immediately. |
| 576 | // We don't use Now() here because it's somewhat expensive to call. |
| 577 | deadline = base::TimeTicks(); |
| 578 | break; |
| 579 | case SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_REGULAR: |
| 580 | // We are animating on the impl thread but we can wait for some time. |
mithro | 0bdb49d | 2015-05-27 13:08:01 | [diff] [blame] | 581 | deadline = begin_impl_frame_tracker_.Current().deadline; |
sunnyps | 5d8bb1d2 | 2014-12-08 20:48:10 | [diff] [blame] | 582 | break; |
| 583 | case SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_LATE: |
| 584 | // We are blocked for one reason or another and we should wait. |
| 585 | // TODO(brianderson): Handle long deadlines (that are past the next |
| 586 | // frame's frame time) properly instead of using this hack. |
mithro | 0bdb49d | 2015-05-27 13:08:01 | [diff] [blame] | 587 | deadline = begin_impl_frame_tracker_.Current().frame_time + |
| 588 | begin_impl_frame_tracker_.Current().interval; |
sunnyps | 5d8bb1d2 | 2014-12-08 20:48:10 | [diff] [blame] | 589 | break; |
weiliangc | 8dac5a6 | 2015-04-02 06:12:35 | [diff] [blame] | 590 | case SchedulerStateMachine:: |
| 591 | BEGIN_IMPL_FRAME_DEADLINE_MODE_BLOCKED_ON_READY_TO_DRAW: |
| 592 | // We are blocked because we are waiting for ReadyToDraw signal. We would |
| 593 | // post deadline after we received ReadyToDraw singal. |
| 594 | TRACE_EVENT1("cc", "Scheduler::ScheduleBeginImplFrameDeadline", |
| 595 | "deadline_mode", "blocked_on_ready_to_draw"); |
| 596 | return; |
sunnyps | 5d8bb1d2 | 2014-12-08 20:48:10 | [diff] [blame] | 597 | } |
| 598 | |
sunnyps | eab5ac9 | 2015-04-02 20:26:13 | [diff] [blame] | 599 | TRACE_EVENT2("cc", "Scheduler::ScheduleBeginImplFrameDeadline", "mode", |
| 600 | SchedulerStateMachine::BeginImplFrameDeadlineModeToString( |
| 601 | begin_impl_frame_deadline_mode_), |
| 602 | "deadline", deadline); |
boliu@chromium.org | 48abf81 | 2014-03-20 17:41:59 | [diff] [blame] | 603 | |
sunnyps | eab5ac9 | 2015-04-02 20:26:13 | [diff] [blame] | 604 | base::TimeDelta delta = std::max(deadline - Now(), base::TimeDelta()); |
enne@chromium.org | aeeedad | 2014-08-22 18:16:22 | [diff] [blame] | 605 | task_runner_->PostDelayedTask( |
brianderson@chromium.org | beed86c | 2014-04-04 04:34:28 | [diff] [blame] | 606 | FROM_HERE, begin_impl_frame_deadline_task_.callback(), delta); |
sunnyps | 5d8bb1d2 | 2014-12-08 20:48:10 | [diff] [blame] | 607 | } |
| 608 | |
sunnyps | eab5ac9 | 2015-04-02 20:26:13 | [diff] [blame] | 609 | void Scheduler::ScheduleBeginImplFrameDeadlineIfNeeded() { |
sunnyps | b6ee9a21 | 2015-04-02 00:51:03 | [diff] [blame] | 610 | if (settings_.using_synchronous_renderer_compositor) |
| 611 | return; |
| 612 | |
sunnyps | 5d8bb1d2 | 2014-12-08 20:48:10 | [diff] [blame] | 613 | if (state_machine_.begin_impl_frame_state() != |
| 614 | SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME) |
| 615 | return; |
| 616 | |
sunnyps | eab5ac9 | 2015-04-02 20:26:13 | [diff] [blame] | 617 | if (begin_impl_frame_deadline_mode_ == |
| 618 | state_machine_.CurrentBeginImplFrameDeadlineMode() && |
| 619 | BeginImplFrameDeadlinePending()) |
| 620 | return; |
| 621 | |
| 622 | ScheduleBeginImplFrameDeadline(); |
brianderson@chromium.org | 425e533 | 2013-09-21 04:10:03 | [diff] [blame] | 623 | } |
| 624 | |
dominikg@chromium.org | 87379cde | 2013-10-21 23:19:52 | [diff] [blame] | 625 | void Scheduler::OnBeginImplFrameDeadline() { |
miletus | fed8c43b | 2015-01-26 20:04:52 | [diff] [blame] | 626 | TRACE_EVENT0("cc,benchmark", "Scheduler::OnBeginImplFrameDeadline"); |
brianderson@chromium.org | beed86c | 2014-04-04 04:34:28 | [diff] [blame] | 627 | begin_impl_frame_deadline_task_.Cancel(); |
brianderson@chromium.org | 1d8571b5 | 2014-02-08 02:33:58 | [diff] [blame] | 628 | // We split the deadline actions up into two phases so the state machine |
| 629 | // has a chance to trigger actions that should occur durring and after |
| 630 | // the deadline separately. For example: |
| 631 | // * Sending the BeginMainFrame will not occur after the deadline in |
| 632 | // order to wait for more user-input before starting the next commit. |
| 633 | // * Creating a new OuputSurface will not occur during the deadline in |
| 634 | // order to allow the state machine to "settle" first. |
robliao | dd25f5b | 2015-02-27 23:34:02 | [diff] [blame] | 635 | |
| 636 | // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is fixed. |
| 637 | tracked_objects::ScopedTracker tracking_profile1( |
| 638 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 639 | "461509 Scheduler::OnBeginImplFrameDeadline1")); |
dominikg@chromium.org | 7d668551 | 2013-10-19 18:04:38 | [diff] [blame] | 640 | state_machine_.OnBeginImplFrameDeadline(); |
brianderson@chromium.org | 425e533 | 2013-09-21 04:10:03 | [diff] [blame] | 641 | ProcessScheduledActions(); |
sunnyps | eab5ac9 | 2015-04-02 20:26:13 | [diff] [blame] | 642 | FinishImplFrame(); |
brianderson@chromium.org | 049fc7a | 2013-06-18 12:32:35 | [diff] [blame] | 643 | } |
| 644 | |
brianderson@chromium.org | 22646b0 | 2014-04-03 23:55:32 | [diff] [blame] | 645 | |
| 646 | void Scheduler::PollToAdvanceCommitState() { |
| 647 | TRACE_EVENT0("cc", "Scheduler::PollToAdvanceCommitState"); |
brianderson@chromium.org | beed86c | 2014-04-04 04:34:28 | [diff] [blame] | 648 | advance_commit_state_task_.Cancel(); |
brianderson@chromium.org | 22646b0 | 2014-04-03 23:55:32 | [diff] [blame] | 649 | ProcessScheduledActions(); |
brianderson@chromium.org | 02de8f4 | 2013-09-12 05:27:52 | [diff] [blame] | 650 | } |
| 651 | |
brianderson@chromium.org | 049fc7a | 2013-06-18 12:32:35 | [diff] [blame] | 652 | void Scheduler::DrawAndSwapIfPossible() { |
simonhong@chromium.org | 30d8214 | 2014-05-12 04:26:02 | [diff] [blame] | 653 | DrawResult result = client_->ScheduledActionDrawAndSwapIfPossible(); |
| 654 | state_machine_.DidDrawIfPossibleCompleted(result); |
egraether@chromium.org | f0c2a24 | 2013-03-15 19:34:52 | [diff] [blame] | 655 | } |
| 656 | |
simonhong | c6309f79 | 2015-01-31 15:47:15 | [diff] [blame] | 657 | void Scheduler::SetDeferCommits(bool defer_commits) { |
| 658 | TRACE_EVENT1("cc", "Scheduler::SetDeferCommits", |
| 659 | "defer_commits", |
| 660 | defer_commits); |
| 661 | state_machine_.SetDeferCommits(defer_commits); |
| 662 | ProcessScheduledActions(); |
| 663 | } |
| 664 | |
enne@chromium.org | a8335ac0 | 2013-03-16 09:15:12 | [diff] [blame] | 665 | void Scheduler::ProcessScheduledActions() { |
| 666 | // We do not allow ProcessScheduledActions to be recursive. |
| 667 | // The top-level call will iteratively execute the next action for us anyway. |
| 668 | if (inside_process_scheduled_actions_) |
| 669 | return; |
jamesr@chromium.org | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 670 | |
enne@chromium.org | a8335ac0 | 2013-03-16 09:15:12 | [diff] [blame] | 671 | base::AutoReset<bool> mark_inside(&inside_process_scheduled_actions_, true); |
jamesr@chromium.org | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 672 | |
brianderson@chromium.org | 224b452 | 2013-08-21 09:58:30 | [diff] [blame] | 673 | SchedulerStateMachine::Action action; |
| 674 | do { |
| 675 | action = state_machine_.NextAction(); |
| 676 | TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), |
| 677 | "SchedulerStateMachine", |
| 678 | "state", |
yurys@chromium.org | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 679 | AsValue()); |
mithro | 285b5b98 | 2015-05-26 04:57:50 | [diff] [blame] | 680 | DVLOG(2) << "Scheduler::ProcessScheduledActions: " |
| 681 | << SchedulerStateMachine::ActionToString(action) << " " |
| 682 | << state_machine_.GetStatesForDebugging(); |
enne@chromium.org | a8335ac0 | 2013-03-16 09:15:12 | [diff] [blame] | 683 | state_machine_.UpdateState(action); |
epenner@chromium.org | c48536a5 | 2013-09-14 00:02:08 | [diff] [blame] | 684 | base::AutoReset<SchedulerStateMachine::Action> |
| 685 | mark_inside_action(&inside_action_, action); |
enne@chromium.org | a8335ac0 | 2013-03-16 09:15:12 | [diff] [blame] | 686 | switch (action) { |
| 687 | case SchedulerStateMachine::ACTION_NONE: |
skyostil@chromium.org | c232196 | 2014-04-28 19:16:42 | [diff] [blame] | 688 | break; |
robliao | 27728e6 | 2015-03-21 07:39:34 | [diff] [blame] | 689 | case SchedulerStateMachine::ACTION_ANIMATE: |
skyostil@chromium.org | 43b8f98 | 2014-04-30 21:24:33 | [diff] [blame] | 690 | client_->ScheduledActionAnimate(); |
| 691 | break; |
robliao | 27728e6 | 2015-03-21 07:39:34 | [diff] [blame] | 692 | case SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME: |
dominikg@chromium.org | 87379cde | 2013-10-21 23:19:52 | [diff] [blame] | 693 | client_->ScheduledActionSendBeginMainFrame(); |
enne@chromium.org | a8335ac0 | 2013-03-16 09:15:12 | [diff] [blame] | 694 | break; |
robliao | dd25f5b | 2015-02-27 23:34:02 | [diff] [blame] | 695 | case SchedulerStateMachine::ACTION_COMMIT: { |
| 696 | // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is |
| 697 | // fixed. |
| 698 | tracked_objects::ScopedTracker tracking_profile4( |
| 699 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 700 | "461509 Scheduler::ProcessScheduledActions4")); |
enne@chromium.org | a8335ac0 | 2013-03-16 09:15:12 | [diff] [blame] | 701 | client_->ScheduledActionCommit(); |
enne@chromium.org | a8335ac0 | 2013-03-16 09:15:12 | [diff] [blame] | 702 | break; |
robliao | dd25f5b | 2015-02-27 23:34:02 | [diff] [blame] | 703 | } |
robliao | 27728e6 | 2015-03-21 07:39:34 | [diff] [blame] | 704 | case SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE: |
alokp@chromium.org | dea39837 | 2014-07-07 19:37:19 | [diff] [blame] | 705 | client_->ScheduledActionActivateSyncTree(); |
enne@chromium.org | a8335ac0 | 2013-03-16 09:15:12 | [diff] [blame] | 706 | break; |
robliao | dd25f5b | 2015-02-27 23:34:02 | [diff] [blame] | 707 | case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE: { |
| 708 | // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is |
| 709 | // fixed. |
| 710 | tracked_objects::ScopedTracker tracking_profile6( |
| 711 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 712 | "461509 Scheduler::ProcessScheduledActions6")); |
brianderson@chromium.org | 049fc7a | 2013-06-18 12:32:35 | [diff] [blame] | 713 | DrawAndSwapIfPossible(); |
enne@chromium.org | a8335ac0 | 2013-03-16 09:15:12 | [diff] [blame] | 714 | break; |
robliao | dd25f5b | 2015-02-27 23:34:02 | [diff] [blame] | 715 | } |
robliao | 27728e6 | 2015-03-21 07:39:34 | [diff] [blame] | 716 | case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED: |
simonhong@chromium.org | 30d8214 | 2014-05-12 04:26:02 | [diff] [blame] | 717 | client_->ScheduledActionDrawAndSwapForced(); |
enne@chromium.org | a8335ac0 | 2013-03-16 09:15:12 | [diff] [blame] | 718 | break; |
brianderson@chromium.org | 1ef04b2 | 2013-08-23 05:47:16 | [diff] [blame] | 719 | case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT: |
| 720 | // No action is actually performed, but this allows the state machine to |
| 721 | // advance out of its waiting to draw state without actually drawing. |
brianderson@chromium.org | 63e6189 | 2013-09-07 01:47:29 | [diff] [blame] | 722 | break; |
robliao | 27728e6 | 2015-03-21 07:39:34 | [diff] [blame] | 723 | case SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION: |
boliu@chromium.org | 04049fc | 2013-05-01 03:13:20 | [diff] [blame] | 724 | client_->ScheduledActionBeginOutputSurfaceCreation(); |
enne@chromium.org | a8335ac0 | 2013-03-16 09:15:12 | [diff] [blame] | 725 | break; |
robliao | 27728e6 | 2015-03-21 07:39:34 | [diff] [blame] | 726 | case SchedulerStateMachine::ACTION_PREPARE_TILES: |
vmiura | 59ea9b404 | 2014-12-09 20:50:39 | [diff] [blame] | 727 | client_->ScheduledActionPrepareTiles(); |
epenner@chromium.org | c48536a5 | 2013-09-14 00:02:08 | [diff] [blame] | 728 | break; |
sunnyps | eab5ac9 | 2015-04-02 20:26:13 | [diff] [blame] | 729 | case SchedulerStateMachine::ACTION_INVALIDATE_OUTPUT_SURFACE: { |
| 730 | client_->ScheduledActionInvalidateOutputSurface(); |
| 731 | break; |
| 732 | } |
brianderson@chromium.org | d722394 | 2012-09-26 22:43:33 | [diff] [blame] | 733 | } |
brianderson@chromium.org | 224b452 | 2013-08-21 09:58:30 | [diff] [blame] | 734 | } while (action != SchedulerStateMachine::ACTION_NONE); |
sunnyps | 32f0125 | 2015-03-19 03:50:29 | [diff] [blame] | 735 | |
| 736 | SetupPollingMechanisms(); |
| 737 | |
brianderson@chromium.org | 049fc7a | 2013-06-18 12:32:35 | [diff] [blame] | 738 | client_->DidAnticipatedDrawTimeChange(AnticipatedDrawTime()); |
sunnyps | 32f0125 | 2015-03-19 03:50:29 | [diff] [blame] | 739 | |
sunnyps | eab5ac9 | 2015-04-02 20:26:13 | [diff] [blame] | 740 | ScheduleBeginImplFrameDeadlineIfNeeded(); |
sunnyps | 32f0125 | 2015-03-19 03:50:29 | [diff] [blame] | 741 | |
| 742 | SetupNextBeginFrameIfNeeded(); |
jamesr@chromium.org | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 743 | } |
| 744 | |
ssid | 911e40e | 2015-02-09 17:55:20 | [diff] [blame] | 745 | scoped_refptr<base::trace_event::ConvertableToTraceFormat> Scheduler::AsValue() |
yurys@chromium.org | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 746 | const { |
ssid | 911e40e | 2015-02-09 17:55:20 | [diff] [blame] | 747 | scoped_refptr<base::trace_event::TracedValue> state = |
| 748 | new base::trace_event::TracedValue(); |
mithro | d9168de | 2014-09-17 10:25:34 | [diff] [blame] | 749 | AsValueInto(state.get()); |
| 750 | return state; |
| 751 | } |
| 752 | |
ssid | 911e40e | 2015-02-09 17:55:20 | [diff] [blame] | 753 | void Scheduler::AsValueInto(base::trace_event::TracedValue* state) const { |
yurys@chromium.org | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 754 | state->BeginDictionary("state_machine"); |
sunnyps | bd2c8968 | 2015-03-20 00:13:12 | [diff] [blame] | 755 | state_machine_.AsValueInto(state); |
yurys@chromium.org | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 756 | state->EndDictionary(); |
mithro | c34fc0b1 | 2014-09-30 09:10:41 | [diff] [blame] | 757 | |
mithro | 9926287 | 2014-10-09 11:50:14 | [diff] [blame] | 758 | // Only trace frame sources when explicitly enabled - http://crbug.com/420607 |
| 759 | bool frame_tracing_enabled = false; |
| 760 | TRACE_EVENT_CATEGORY_GROUP_ENABLED( |
| 761 | TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), |
| 762 | &frame_tracing_enabled); |
| 763 | if (frame_tracing_enabled) { |
| 764 | state->BeginDictionary("frame_source_"); |
| 765 | frame_source_->AsValueInto(state); |
| 766 | state->EndDictionary(); |
| 767 | } |
brianderson@chromium.org | a14c675 | 2014-04-03 11:42:47 | [diff] [blame] | 768 | |
yurys@chromium.org | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 769 | state->BeginDictionary("scheduler_state"); |
mithro | 0c0ac6a | 2014-09-10 01:03:36 | [diff] [blame] | 770 | state->SetDouble("time_until_anticipated_draw_time_ms", |
| 771 | (AnticipatedDrawTime() - Now()).InMillisecondsF()); |
yurys@chromium.org | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 772 | state->SetDouble("estimated_parent_draw_time_ms", |
| 773 | estimated_parent_draw_time_.InMillisecondsF()); |
mithro | c34fc0b1 | 2014-09-30 09:10:41 | [diff] [blame] | 774 | state->SetBoolean("last_set_needs_begin_frame_", |
| 775 | frame_source_->NeedsBeginFrames()); |
brianderson | 1545de0 | 2015-06-05 22:05:44 | [diff] [blame^] | 776 | state->SetInteger("begin_retro_frame_args", |
vmpstr | 1ba0156d | 2015-06-04 01:38:51 | [diff] [blame] | 777 | static_cast<int>(begin_retro_frame_args_.size())); |
brianderson | 1545de0 | 2015-06-05 22:05:44 | [diff] [blame^] | 778 | state->SetBoolean("begin_retro_frame_task", |
sunnyps | 324cd53 | 2014-12-30 21:28:10 | [diff] [blame] | 779 | !begin_retro_frame_task_.IsCancelled()); |
brianderson | 1545de0 | 2015-06-05 22:05:44 | [diff] [blame^] | 780 | state->SetBoolean("begin_impl_frame_deadline_task", |
yurys@chromium.org | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 781 | !begin_impl_frame_deadline_task_.IsCancelled()); |
brianderson | 1545de0 | 2015-06-05 22:05:44 | [diff] [blame^] | 782 | state->SetBoolean("advance_commit_state_task", |
yurys@chromium.org | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 783 | !advance_commit_state_task_.IsCancelled()); |
brianderson | 1545de0 | 2015-06-05 22:05:44 | [diff] [blame^] | 784 | state->SetString("inside_action", |
| 785 | SchedulerStateMachine::ActionToString(inside_action_)); |
yurys@chromium.org | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 786 | state->BeginDictionary("begin_impl_frame_args"); |
mithro | 0bdb49d | 2015-05-27 13:08:01 | [diff] [blame] | 787 | begin_impl_frame_tracker_.AsValueInto(Now(), state); |
yurys@chromium.org | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 788 | state->EndDictionary(); |
yurys@chromium.org | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 789 | state->EndDictionary(); |
skyostil@chromium.org | 5c58f22 | 2014-03-07 03:34:09 | [diff] [blame] | 790 | |
yurys@chromium.org | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 791 | state->BeginDictionary("client_state"); |
| 792 | state->SetDouble("draw_duration_estimate_ms", |
| 793 | client_->DrawDurationEstimate().InMillisecondsF()); |
| 794 | state->SetDouble( |
skyostil@chromium.org | 5c58f22 | 2014-03-07 03:34:09 | [diff] [blame] | 795 | "begin_main_frame_to_commit_duration_estimate_ms", |
| 796 | client_->BeginMainFrameToCommitDurationEstimate().InMillisecondsF()); |
yurys@chromium.org | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 797 | state->SetDouble( |
skyostil@chromium.org | 5c58f22 | 2014-03-07 03:34:09 | [diff] [blame] | 798 | "commit_to_activate_duration_estimate_ms", |
| 799 | client_->CommitToActivateDurationEstimate().InMillisecondsF()); |
yurys@chromium.org | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 800 | state->EndDictionary(); |
skyostil@chromium.org | 5c58f22 | 2014-03-07 03:34:09 | [diff] [blame] | 801 | } |
| 802 | |
dominikg@chromium.org | 56ec730 | 2013-11-08 00:51:45 | [diff] [blame] | 803 | bool Scheduler::CanCommitAndActivateBeforeDeadline() const { |
mithro | 0bdb49d | 2015-05-27 13:08:01 | [diff] [blame] | 804 | BeginFrameArgs args = |
| 805 | begin_impl_frame_tracker_.DangerousMethodCurrentOrLast(); |
| 806 | |
dominikg@chromium.org | 56ec730 | 2013-11-08 00:51:45 | [diff] [blame] | 807 | // Check if the main thread computation and commit can be finished before the |
| 808 | // impl thread's deadline. |
| 809 | base::TimeTicks estimated_draw_time = |
mithro | 0bdb49d | 2015-05-27 13:08:01 | [diff] [blame] | 810 | args.frame_time + client_->BeginMainFrameToCommitDurationEstimate() + |
dominikg@chromium.org | 56ec730 | 2013-11-08 00:51:45 | [diff] [blame] | 811 | client_->CommitToActivateDurationEstimate(); |
| 812 | |
mithro | 0bdb49d | 2015-05-27 13:08:01 | [diff] [blame] | 813 | TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), |
| 814 | "CanCommitAndActivateBeforeDeadline", |
| 815 | "time_left_after_drawing_ms", |
| 816 | (args.deadline - estimated_draw_time).InMillisecondsF(), "state", |
| 817 | AsValue()); |
skyostil@chromium.org | 5c58f22 | 2014-03-07 03:34:09 | [diff] [blame] | 818 | |
mithro | 0bdb49d | 2015-05-27 13:08:01 | [diff] [blame] | 819 | return estimated_draw_time < args.deadline; |
dominikg@chromium.org | 56ec730 | 2013-11-08 00:51:45 | [diff] [blame] | 820 | } |
| 821 | |
simonhong@chromium.org | eb2d2abc | 2014-03-07 16:19:59 | [diff] [blame] | 822 | bool Scheduler::IsBeginMainFrameSentOrStarted() const { |
| 823 | return (state_machine_.commit_state() == |
| 824 | SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || |
| 825 | state_machine_.commit_state() == |
| 826 | SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); |
| 827 | } |
| 828 | |
tfarina@chromium.org | 0ef6747 | 2012-10-11 21:33:39 | [diff] [blame] | 829 | } // namespace cc |