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

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

Issue 222003007: cc: Advance commit state with a CancelableClosure (Closed) Base URL: http://git.chromium.org/chromium/src.git@schedAsValue
Patch Set: use default settings Created 6 years, 8 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
« no previous file with comments | « cc/scheduler/scheduler.h ('k') | cc/scheduler/scheduler_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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/logging.h" 10 #include "base/logging.h"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 // will not give us a BeginImplFrame until the commit completes. See 195 // will not give us a BeginImplFrame until the commit completes. See
196 // crbug.com/317430 for an example of a swap ack being held on commit. Thus 196 // crbug.com/317430 for an example of a swap ack being held on commit. Thus
197 // we set a repeating timer to poll on ProcessScheduledActions until we 197 // we set a repeating timer to poll on ProcessScheduledActions until we
198 // successfully reach BeginImplFrame. Synchronous compositor does not use 198 // successfully reach BeginImplFrame. Synchronous compositor does not use
199 // frame rate controller or have the circular wait in the bug. 199 // frame rate controller or have the circular wait in the bug.
200 if (IsBeginMainFrameSentOrStarted() && 200 if (IsBeginMainFrameSentOrStarted() &&
201 !settings_.using_synchronous_renderer_compositor) { 201 !settings_.using_synchronous_renderer_compositor) {
202 needs_advance_commit_state_timer = true; 202 needs_advance_commit_state_timer = true;
203 } 203 }
204 } 204 }
205 if (needs_advance_commit_state_timer != 205
206 advance_commit_state_timer_.IsRunning()) { 206 if (needs_advance_commit_state_timer) {
207 if (needs_advance_commit_state_timer && 207 if (advance_commit_state_closure_.IsCancelled() &&
208 last_begin_impl_frame_args_.IsValid()) { 208 last_begin_impl_frame_args_.IsValid()) {
209 // Since we'd rather get a BeginImplFrame by the normal mechanism, we 209 // Since we'd rather get a BeginImplFrame by the normal mechanism, we
210 // set the interval to twice the interval from the previous frame. 210 // set the interval to twice the interval from the previous frame.
211 advance_commit_state_timer_.Start( 211 advance_commit_state_closure_.Reset(base::Bind(
212 &Scheduler::PollToAdvanceCommitState, weak_factory_.GetWeakPtr()));
213 impl_task_runner_->PostDelayedTask(
212 FROM_HERE, 214 FROM_HERE,
213 last_begin_impl_frame_args_.interval * 2, 215 advance_commit_state_closure_.callback(),
214 base::Bind(&Scheduler::ProcessScheduledActions, 216 last_begin_impl_frame_args_.interval * 2);
215 base::Unretained(this)));
216 } else {
217 advance_commit_state_timer_.Stop();
218 } 217 }
218 } else {
219 advance_commit_state_closure_.Cancel();
219 } 220 }
220 } 221 }
221 222
222 void Scheduler::BeginImplFrame(const BeginFrameArgs& args) { 223 void Scheduler::BeginImplFrame(const BeginFrameArgs& args) {
223 TRACE_EVENT0("cc", "Scheduler::BeginImplFrame"); 224 TRACE_EVENT0("cc", "Scheduler::BeginImplFrame");
224 DCHECK(state_machine_.begin_impl_frame_state() == 225 DCHECK(state_machine_.begin_impl_frame_state() ==
225 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); 226 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
226 DCHECK(state_machine_.HasInitializedOutputSurface()); 227 DCHECK(state_machine_.HasInitializedOutputSurface());
227 228
229 advance_commit_state_closure_.Cancel();
230
228 last_begin_impl_frame_args_ = args; 231 last_begin_impl_frame_args_ = args;
229 last_begin_impl_frame_args_.deadline -= client_->DrawDurationEstimate(); 232 last_begin_impl_frame_args_.deadline -= client_->DrawDurationEstimate();
230 233
231 if (!state_machine_.smoothness_takes_priority() && 234 if (!state_machine_.smoothness_takes_priority() &&
232 state_machine_.MainThreadIsInHighLatencyMode() && 235 state_machine_.MainThreadIsInHighLatencyMode() &&
233 CanCommitAndActivateBeforeDeadline()) { 236 CanCommitAndActivateBeforeDeadline()) {
234 state_machine_.SetSkipNextBeginMainFrameToReduceLatency(); 237 state_machine_.SetSkipNextBeginMainFrameToReduceLatency();
235 } 238 }
236 239
237 state_machine_.OnBeginImplFrame(last_begin_impl_frame_args_); 240 state_machine_.OnBeginImplFrame(last_begin_impl_frame_args_);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 } 316 }
314 317
315 void Scheduler::PollForAnticipatedDrawTriggers() { 318 void Scheduler::PollForAnticipatedDrawTriggers() {
316 TRACE_EVENT0("cc", "Scheduler::PollForAnticipatedDrawTriggers"); 319 TRACE_EVENT0("cc", "Scheduler::PollForAnticipatedDrawTriggers");
317 poll_for_draw_triggers_closure_.Cancel(); 320 poll_for_draw_triggers_closure_.Cancel();
318 state_machine_.DidEnterPollForAnticipatedDrawTriggers(); 321 state_machine_.DidEnterPollForAnticipatedDrawTriggers();
319 ProcessScheduledActions(); 322 ProcessScheduledActions();
320 state_machine_.DidLeavePollForAnticipatedDrawTriggers(); 323 state_machine_.DidLeavePollForAnticipatedDrawTriggers();
321 } 324 }
322 325
326 void Scheduler::PollToAdvanceCommitState() {
327 TRACE_EVENT0("cc", "Scheduler::PollToAdvanceCommitState");
328 advance_commit_state_closure_.Cancel();
329 ProcessScheduledActions();
330 }
331
323 bool Scheduler::IsBeginMainFrameSent() const { 332 bool Scheduler::IsBeginMainFrameSent() const {
324 return state_machine_.commit_state() == 333 return state_machine_.commit_state() ==
325 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT; 334 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT;
326 } 335 }
327 336
328 void Scheduler::DrawAndSwapIfPossible() { 337 void Scheduler::DrawAndSwapIfPossible() {
329 DrawSwapReadbackResult result = 338 DrawSwapReadbackResult result =
330 client_->ScheduledActionDrawAndSwapIfPossible(); 339 client_->ScheduledActionDrawAndSwapIfPossible();
331 state_machine_.DidDrawIfPossibleCompleted(result.draw_result); 340 state_machine_.DidDrawIfPossibleCompleted(result.draw_result);
332 } 341 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 scheduler_state->SetDouble( 429 scheduler_state->SetDouble(
421 "time_until_anticipated_draw_time_ms", 430 "time_until_anticipated_draw_time_ms",
422 (AnticipatedDrawTime() - base::TimeTicks::Now()).InMillisecondsF()); 431 (AnticipatedDrawTime() - base::TimeTicks::Now()).InMillisecondsF());
423 scheduler_state->SetBoolean("last_set_needs_begin_impl_frame_", 432 scheduler_state->SetBoolean("last_set_needs_begin_impl_frame_",
424 last_set_needs_begin_impl_frame_); 433 last_set_needs_begin_impl_frame_);
425 scheduler_state->SetBoolean( 434 scheduler_state->SetBoolean(
426 "begin_impl_frame_deadline_closure_", 435 "begin_impl_frame_deadline_closure_",
427 !begin_impl_frame_deadline_closure_.IsCancelled()); 436 !begin_impl_frame_deadline_closure_.IsCancelled());
428 scheduler_state->SetBoolean("poll_for_draw_triggers_closure_", 437 scheduler_state->SetBoolean("poll_for_draw_triggers_closure_",
429 !poll_for_draw_triggers_closure_.IsCancelled()); 438 !poll_for_draw_triggers_closure_.IsCancelled());
430 scheduler_state->SetBoolean("advance_commit_state_timer_", 439 scheduler_state->SetBoolean("advance_commit_state_closure_",
431 advance_commit_state_timer_.IsRunning()); 440 !advance_commit_state_closure_.IsCancelled());
432 state->Set("scheduler_state", scheduler_state.release()); 441 state->Set("scheduler_state", scheduler_state.release());
433 442
434 scoped_ptr<base::DictionaryValue> client_state(new base::DictionaryValue); 443 scoped_ptr<base::DictionaryValue> client_state(new base::DictionaryValue);
435 client_state->SetDouble("draw_duration_estimate_ms", 444 client_state->SetDouble("draw_duration_estimate_ms",
436 client_->DrawDurationEstimate().InMillisecondsF()); 445 client_->DrawDurationEstimate().InMillisecondsF());
437 client_state->SetDouble( 446 client_state->SetDouble(
438 "begin_main_frame_to_commit_duration_estimate_ms", 447 "begin_main_frame_to_commit_duration_estimate_ms",
439 client_->BeginMainFrameToCommitDurationEstimate().InMillisecondsF()); 448 client_->BeginMainFrameToCommitDurationEstimate().InMillisecondsF());
440 client_state->SetDouble( 449 client_state->SetDouble(
441 "commit_to_activate_duration_estimate_ms", 450 "commit_to_activate_duration_estimate_ms",
(...skipping 22 matching lines...) Expand all
464 } 473 }
465 474
466 bool Scheduler::IsBeginMainFrameSentOrStarted() const { 475 bool Scheduler::IsBeginMainFrameSentOrStarted() const {
467 return (state_machine_.commit_state() == 476 return (state_machine_.commit_state() ==
468 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || 477 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT ||
469 state_machine_.commit_state() == 478 state_machine_.commit_state() ==
470 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); 479 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED);
471 } 480 }
472 481
473 } // namespace cc 482 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler.h ('k') | cc/scheduler/scheduler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698