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

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

Issue 1055743002: Revert of cc: Make scheduling be driven by vsync for android webview. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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_state_machine.h » ('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 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 primary_frame_source_internal_(external_begin_frame_source.Pass()), 87 primary_frame_source_internal_(external_begin_frame_source.Pass()),
88 background_frame_source_internal_(), 88 background_frame_source_internal_(),
89 vsync_observer_(NULL), 89 vsync_observer_(NULL),
90 authoritative_vsync_interval_(base::TimeDelta()), 90 authoritative_vsync_interval_(base::TimeDelta()),
91 last_vsync_timebase_(base::TimeTicks()), 91 last_vsync_timebase_(base::TimeTicks()),
92 throttle_frame_production_(scheduler_settings.throttle_frame_production), 92 throttle_frame_production_(scheduler_settings.throttle_frame_production),
93 settings_(scheduler_settings), 93 settings_(scheduler_settings),
94 client_(client), 94 client_(client),
95 layer_tree_host_id_(layer_tree_host_id), 95 layer_tree_host_id_(layer_tree_host_id),
96 task_runner_(task_runner), 96 task_runner_(task_runner),
97 begin_impl_frame_deadline_mode_(
98 SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE),
99 state_machine_(scheduler_settings), 97 state_machine_(scheduler_settings),
100 inside_process_scheduled_actions_(false), 98 inside_process_scheduled_actions_(false),
101 inside_action_(SchedulerStateMachine::ACTION_NONE), 99 inside_action_(SchedulerStateMachine::ACTION_NONE),
102 weak_factory_(this) { 100 weak_factory_(this) {
103 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), 101 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"),
104 "Scheduler::Scheduler", 102 "Scheduler::Scheduler",
105 "settings", 103 "settings",
106 settings_.AsValue()); 104 settings_.AsValue());
107 DCHECK(client_); 105 DCHECK(client_);
108 DCHECK(!state_machine_.BeginFrameNeeded()); 106 DCHECK(!state_machine_.BeginFrameNeeded());
109 107
110 begin_retro_frame_closure_ = 108 begin_retro_frame_closure_ =
111 base::Bind(&Scheduler::BeginRetroFrame, weak_factory_.GetWeakPtr()); 109 base::Bind(&Scheduler::BeginRetroFrame, weak_factory_.GetWeakPtr());
112 begin_impl_frame_deadline_closure_ = base::Bind( 110 begin_impl_frame_deadline_closure_ = base::Bind(
113 &Scheduler::OnBeginImplFrameDeadline, weak_factory_.GetWeakPtr()); 111 &Scheduler::OnBeginImplFrameDeadline, weak_factory_.GetWeakPtr());
112 poll_for_draw_triggers_closure_ = base::Bind(
113 &Scheduler::PollForAnticipatedDrawTriggers, weak_factory_.GetWeakPtr());
114 advance_commit_state_closure_ = base::Bind( 114 advance_commit_state_closure_ = base::Bind(
115 &Scheduler::PollToAdvanceCommitState, weak_factory_.GetWeakPtr()); 115 &Scheduler::PollToAdvanceCommitState, weak_factory_.GetWeakPtr());
116 116
117 frame_source_ = BeginFrameSourceMultiplexer::Create(); 117 frame_source_ = BeginFrameSourceMultiplexer::Create();
118 frame_source_->AddObserver(this); 118 frame_source_->AddObserver(this);
119 119
120 // Primary frame source 120 // Primary frame source
121 primary_frame_source_ = 121 primary_frame_source_ =
122 frame_sources_constructor->ConstructPrimaryFrameSource(this); 122 frame_sources_constructor->ConstructPrimaryFrameSource(this);
123 frame_source_->AddSource(primary_frame_source_); 123 frame_source_->AddSource(primary_frame_source_);
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 client_->SendBeginMainFrameNotExpectedSoon(); 324 client_->SendBeginMainFrameNotExpectedSoon();
325 } 325 }
326 } 326 }
327 327
328 PostBeginRetroFrameIfNeeded(); 328 PostBeginRetroFrameIfNeeded();
329 } 329 }
330 330
331 // We may need to poll when we can't rely on BeginFrame to advance certain 331 // We may need to poll when we can't rely on BeginFrame to advance certain
332 // state or to avoid deadlock. 332 // state or to avoid deadlock.
333 void Scheduler::SetupPollingMechanisms() { 333 void Scheduler::SetupPollingMechanisms() {
334 // At this point we'd prefer to advance through the commit flow by 334 bool needs_advance_commit_state_timer = false;
335 // drawing a frame, however it's possible that the frame rate controller 335 // Setup PollForAnticipatedDrawTriggers if we need to monitor state but
336 // will not give us a BeginFrame until the commit completes. See 336 // aren't expecting any more BeginFrames. This should only be needed by
337 // crbug.com/317430 for an example of a swap ack being held on commit. Thus 337 // the synchronous compositor when BeginFrameNeeded is false.
338 // we set a repeating timer to poll on ProcessScheduledActions until we 338 if (state_machine_.ShouldPollForAnticipatedDrawTriggers()) {
339 // successfully reach BeginFrame. Synchronous compositor does not use 339 DCHECK(!state_machine_.SupportsProactiveBeginFrame());
340 // frame rate controller or have the circular wait in the bug. 340 if (poll_for_draw_triggers_task_.IsCancelled()) {
341 if (IsBeginMainFrameSentOrStarted() && 341 poll_for_draw_triggers_task_.Reset(poll_for_draw_triggers_closure_);
342 !settings_.using_synchronous_renderer_compositor) { 342 base::TimeDelta delay = begin_impl_frame_args_.IsValid()
343 ? begin_impl_frame_args_.interval
344 : BeginFrameArgs::DefaultInterval();
345 task_runner_->PostDelayedTask(
346 FROM_HERE, poll_for_draw_triggers_task_.callback(), delay);
347 }
348 } else {
349 poll_for_draw_triggers_task_.Cancel();
350
351 // At this point we'd prefer to advance through the commit flow by
352 // drawing a frame, however it's possible that the frame rate controller
353 // will not give us a BeginFrame until the commit completes. See
354 // crbug.com/317430 for an example of a swap ack being held on commit. Thus
355 // we set a repeating timer to poll on ProcessScheduledActions until we
356 // successfully reach BeginFrame. Synchronous compositor does not use
357 // frame rate controller or have the circular wait in the bug.
358 if (IsBeginMainFrameSentOrStarted() &&
359 !settings_.using_synchronous_renderer_compositor) {
360 needs_advance_commit_state_timer = true;
361 }
362 }
363
364 if (needs_advance_commit_state_timer) {
343 if (advance_commit_state_task_.IsCancelled() && 365 if (advance_commit_state_task_.IsCancelled() &&
344 begin_impl_frame_args_.IsValid()) { 366 begin_impl_frame_args_.IsValid()) {
345 // Since we'd rather get a BeginImplFrame by the normal mechanism, we 367 // Since we'd rather get a BeginImplFrame by the normal mechanism, we
346 // set the interval to twice the interval from the previous frame. 368 // set the interval to twice the interval from the previous frame.
347 advance_commit_state_task_.Reset(advance_commit_state_closure_); 369 advance_commit_state_task_.Reset(advance_commit_state_closure_);
348 task_runner_->PostDelayedTask(FROM_HERE, 370 task_runner_->PostDelayedTask(FROM_HERE,
349 advance_commit_state_task_.callback(), 371 advance_commit_state_task_.callback(),
350 begin_impl_frame_args_.interval * 2); 372 begin_impl_frame_args_.interval * 2);
351 } 373 }
352 } else { 374 } else {
(...skipping 18 matching lines...) Expand all
371 adjusted_args_for_children.deadline -= 393 adjusted_args_for_children.deadline -=
372 (client_->BeginMainFrameToCommitDurationEstimate() + 394 (client_->BeginMainFrameToCommitDurationEstimate() +
373 client_->CommitToActivateDurationEstimate() + 395 client_->CommitToActivateDurationEstimate() +
374 client_->DrawDurationEstimate() + EstimatedParentDrawTime()); 396 client_->DrawDurationEstimate() + EstimatedParentDrawTime());
375 client_->SendBeginFramesToChildren(adjusted_args_for_children); 397 client_->SendBeginFramesToChildren(adjusted_args_for_children);
376 } 398 }
377 399
378 BeginFrameArgs adjusted_args(args); 400 BeginFrameArgs adjusted_args(args);
379 adjusted_args.deadline -= EstimatedParentDrawTime(); 401 adjusted_args.deadline -= EstimatedParentDrawTime();
380 402
381 if (settings_.using_synchronous_renderer_compositor) {
382 BeginImplFrameSynchronous(adjusted_args);
383 return true;
384 }
385
386 // We have just called SetNeedsBeginFrame(true) and the BeginFrameSource has 403 // We have just called SetNeedsBeginFrame(true) and the BeginFrameSource has
387 // sent us the last BeginFrame we have missed. As we might not be able to 404 // sent us the last BeginFrame we have missed. As we might not be able to
388 // actually make rendering for this call, handle it like a "retro frame". 405 // actually make rendering for this call, handle it like a "retro frame".
389 // TODO(brainderson): Add a test for this functionality ASAP! 406 // TODO(brainderson): Add a test for this functionality ASAP!
390 if (adjusted_args.type == BeginFrameArgs::MISSED) { 407 if (adjusted_args.type == BeginFrameArgs::MISSED) {
391 begin_retro_frame_args_.push_back(adjusted_args); 408 begin_retro_frame_args_.push_back(adjusted_args);
392 PostBeginRetroFrameIfNeeded(); 409 PostBeginRetroFrameIfNeeded();
393 return true; 410 return true;
394 } 411 }
395 412
396 bool should_defer_begin_frame = 413 bool should_defer_begin_frame;
397 !begin_retro_frame_args_.empty() || 414 if (settings_.using_synchronous_renderer_compositor) {
398 !begin_retro_frame_task_.IsCancelled() || 415 should_defer_begin_frame = false;
399 !frame_source_->NeedsBeginFrames() || 416 } else {
400 (state_machine_.begin_impl_frame_state() != 417 should_defer_begin_frame =
401 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); 418 !begin_retro_frame_args_.empty() ||
419 !begin_retro_frame_task_.IsCancelled() ||
420 !frame_source_->NeedsBeginFrames() ||
421 (state_machine_.begin_impl_frame_state() !=
422 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
423 }
402 424
403 if (should_defer_begin_frame) { 425 if (should_defer_begin_frame) {
404 begin_retro_frame_args_.push_back(adjusted_args); 426 begin_retro_frame_args_.push_back(adjusted_args);
405 TRACE_EVENT_INSTANT0( 427 TRACE_EVENT_INSTANT0(
406 "cc", "Scheduler::BeginFrame deferred", TRACE_EVENT_SCOPE_THREAD); 428 "cc", "Scheduler::BeginFrame deferred", TRACE_EVENT_SCOPE_THREAD);
407 // Queuing the frame counts as "using it", so we need to return true. 429 // Queuing the frame counts as "using it", so we need to return true.
408 } else { 430 } else {
409 BeginImplFrameWithDeadline(adjusted_args); 431 BeginImplFrame(adjusted_args);
410 } 432 }
411 return true; 433 return true;
412 } 434 }
413 435
414 void Scheduler::SetChildrenNeedBeginFrames(bool children_need_begin_frames) { 436 void Scheduler::SetChildrenNeedBeginFrames(bool children_need_begin_frames) {
415 state_machine_.SetChildrenNeedBeginFrames(children_need_begin_frames); 437 state_machine_.SetChildrenNeedBeginFrames(children_need_begin_frames);
416 ProcessScheduledActions(); 438 ProcessScheduledActions();
417 } 439 }
418 440
419 void Scheduler::SetAuthoritativeVSyncInterval(const base::TimeDelta& interval) { 441 void Scheduler::SetAuthoritativeVSyncInterval(const base::TimeDelta& interval) {
420 authoritative_vsync_interval_ = interval; 442 authoritative_vsync_interval_ = interval;
421 if (vsync_observer_) 443 if (vsync_observer_)
422 vsync_observer_->OnUpdateVSyncParameters(last_vsync_timebase_, interval); 444 vsync_observer_->OnUpdateVSyncParameters(last_vsync_timebase_, interval);
423 } 445 }
424 446
425 void Scheduler::OnDrawForOutputSurface() {
426 DCHECK(settings_.using_synchronous_renderer_compositor);
427 DCHECK_EQ(state_machine_.begin_impl_frame_state(),
428 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
429 DCHECK(!BeginImplFrameDeadlinePending());
430
431 state_machine_.OnBeginImplFrameDeadline();
432 ProcessScheduledActions();
433
434 state_machine_.OnBeginImplFrameIdle();
435 ProcessScheduledActions();
436 }
437
438 // BeginRetroFrame is called for BeginFrames that we've deferred because 447 // BeginRetroFrame is called for BeginFrames that we've deferred because
439 // the scheduler was in the middle of processing a previous BeginFrame. 448 // the scheduler was in the middle of processing a previous BeginFrame.
440 void Scheduler::BeginRetroFrame() { 449 void Scheduler::BeginRetroFrame() {
441 TRACE_EVENT0("cc,benchmark", "Scheduler::BeginRetroFrame"); 450 TRACE_EVENT0("cc,benchmark", "Scheduler::BeginRetroFrame");
442 DCHECK(!settings_.using_synchronous_renderer_compositor); 451 DCHECK(!settings_.using_synchronous_renderer_compositor);
443 DCHECK(!begin_retro_frame_args_.empty()); 452 DCHECK(!begin_retro_frame_args_.empty());
444 DCHECK(!begin_retro_frame_task_.IsCancelled()); 453 DCHECK(!begin_retro_frame_task_.IsCancelled());
445 DCHECK_EQ(state_machine_.begin_impl_frame_state(), 454 DCHECK_EQ(state_machine_.begin_impl_frame_state(),
446 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); 455 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
447 456
(...skipping 21 matching lines...) Expand all
469 frame_source_->DidFinishFrame(begin_retro_frame_args_.size()); 478 frame_source_->DidFinishFrame(begin_retro_frame_args_.size());
470 } 479 }
471 480
472 if (begin_retro_frame_args_.empty()) { 481 if (begin_retro_frame_args_.empty()) {
473 TRACE_EVENT_INSTANT0("cc", 482 TRACE_EVENT_INSTANT0("cc",
474 "Scheduler::BeginRetroFrames all expired", 483 "Scheduler::BeginRetroFrames all expired",
475 TRACE_EVENT_SCOPE_THREAD); 484 TRACE_EVENT_SCOPE_THREAD);
476 } else { 485 } else {
477 BeginFrameArgs front = begin_retro_frame_args_.front(); 486 BeginFrameArgs front = begin_retro_frame_args_.front();
478 begin_retro_frame_args_.pop_front(); 487 begin_retro_frame_args_.pop_front();
479 BeginImplFrameWithDeadline(front); 488 BeginImplFrame(front);
480 } 489 }
481 } 490 }
482 491
483 // There could be a race between the posted BeginRetroFrame and a new 492 // There could be a race between the posted BeginRetroFrame and a new
484 // BeginFrame arriving via the normal mechanism. Scheduler::BeginFrame 493 // BeginFrame arriving via the normal mechanism. Scheduler::BeginFrame
485 // will check if there is a pending BeginRetroFrame to ensure we handle 494 // will check if there is a pending BeginRetroFrame to ensure we handle
486 // BeginFrames in FIFO order. 495 // BeginFrames in FIFO order.
487 void Scheduler::PostBeginRetroFrameIfNeeded() { 496 void Scheduler::PostBeginRetroFrameIfNeeded() {
488 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), 497 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"),
489 "Scheduler::PostBeginRetroFrameIfNeeded", 498 "Scheduler::PostBeginRetroFrameIfNeeded",
(...skipping 11 matching lines...) Expand all
501 510
502 if (state_machine_.begin_impl_frame_state() != 511 if (state_machine_.begin_impl_frame_state() !=
503 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE) 512 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE)
504 return; 513 return;
505 514
506 begin_retro_frame_task_.Reset(begin_retro_frame_closure_); 515 begin_retro_frame_task_.Reset(begin_retro_frame_closure_);
507 516
508 task_runner_->PostTask(FROM_HERE, begin_retro_frame_task_.callback()); 517 task_runner_->PostTask(FROM_HERE, begin_retro_frame_task_.callback());
509 } 518 }
510 519
511 void Scheduler::BeginImplFrameWithDeadline(const BeginFrameArgs& args) {
512 BeginImplFrame(args);
513
514 // The deadline will be scheduled in ProcessScheduledActions.
515 state_machine_.OnBeginImplFrameDeadlinePending();
516 ProcessScheduledActions();
517 }
518
519 void Scheduler::BeginImplFrameSynchronous(const BeginFrameArgs& args) {
520 BeginImplFrame(args);
521 FinishImplFrame();
522 }
523
524 void Scheduler::FinishImplFrame() {
525 state_machine_.OnBeginImplFrameIdle();
526 ProcessScheduledActions();
527
528 client_->DidBeginImplFrameDeadline();
529 frame_source_->DidFinishFrame(begin_retro_frame_args_.size());
530 }
531
532 // BeginImplFrame starts a compositor frame that will wait up until a deadline 520 // BeginImplFrame starts a compositor frame that will wait up until a deadline
533 // for a BeginMainFrame+activation to complete before it times out and draws 521 // for a BeginMainFrame+activation to complete before it times out and draws
534 // any asynchronous animation and scroll/pinch updates. 522 // any asynchronous animation and scroll/pinch updates.
535 void Scheduler::BeginImplFrame(const BeginFrameArgs& args) { 523 void Scheduler::BeginImplFrame(const BeginFrameArgs& args) {
536 bool main_thread_is_in_high_latency_mode = 524 bool main_thread_is_in_high_latency_mode =
537 state_machine_.MainThreadIsInHighLatencyMode(); 525 state_machine_.MainThreadIsInHighLatencyMode();
538 TRACE_EVENT2("cc,benchmark", 526 TRACE_EVENT2("cc,benchmark",
539 "Scheduler::BeginImplFrame", 527 "Scheduler::BeginImplFrame",
540 "args", 528 "args",
541 args.AsValue(), 529 args.AsValue(),
542 "main_thread_is_high_latency", 530 "main_thread_is_high_latency",
543 main_thread_is_in_high_latency_mode); 531 main_thread_is_in_high_latency_mode);
544 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), 532 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"),
545 "MainThreadLatency", 533 "MainThreadLatency",
546 main_thread_is_in_high_latency_mode); 534 main_thread_is_in_high_latency_mode);
547 DCHECK_EQ(state_machine_.begin_impl_frame_state(), 535 DCHECK_EQ(state_machine_.begin_impl_frame_state(),
548 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); 536 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
549 DCHECK(!BeginImplFrameDeadlinePending());
550 DCHECK(state_machine_.HasInitializedOutputSurface()); 537 DCHECK(state_machine_.HasInitializedOutputSurface());
551 538
552 advance_commit_state_task_.Cancel(); 539 advance_commit_state_task_.Cancel();
553 540
554 begin_impl_frame_args_ = args; 541 begin_impl_frame_args_ = args;
555 begin_impl_frame_args_.deadline -= client_->DrawDurationEstimate(); 542 begin_impl_frame_args_.deadline -= client_->DrawDurationEstimate();
556 543
557 if (!state_machine_.impl_latency_takes_priority() && 544 if (!state_machine_.impl_latency_takes_priority() &&
558 main_thread_is_in_high_latency_mode && 545 main_thread_is_in_high_latency_mode &&
559 CanCommitAndActivateBeforeDeadline()) { 546 CanCommitAndActivateBeforeDeadline()) {
560 state_machine_.SetSkipNextBeginMainFrameToReduceLatency(); 547 state_machine_.SetSkipNextBeginMainFrameToReduceLatency();
561 } 548 }
562 549
563 state_machine_.OnBeginImplFrame(); 550 state_machine_.OnBeginImplFrame();
564 devtools_instrumentation::DidBeginFrame(layer_tree_host_id_); 551 devtools_instrumentation::DidBeginFrame(layer_tree_host_id_);
565 client_->WillBeginImplFrame(begin_impl_frame_args_); 552 client_->WillBeginImplFrame(begin_impl_frame_args_);
566 553
567 ProcessScheduledActions(); 554 ProcessScheduledActions();
555
556 state_machine_.OnBeginImplFrameDeadlinePending();
557
558 if (settings_.using_synchronous_renderer_compositor) {
559 // The synchronous renderer compositor has to make its GL calls
560 // within this call.
561 // TODO(brianderson): Have the OutputSurface initiate the deadline tasks
562 // so the synchronous renderer compositor can take advantage of splitting
563 // up the BeginImplFrame and deadline as well.
564 OnBeginImplFrameDeadline();
565 } else {
566 ScheduleBeginImplFrameDeadline();
567 }
568 } 568 }
569 569
570 void Scheduler::ScheduleBeginImplFrameDeadline() { 570 void Scheduler::ScheduleBeginImplFrameDeadline() {
571 // The synchronous compositor does not post a deadline task. 571 // The synchronous compositor does not post a deadline task.
572 DCHECK(!settings_.using_synchronous_renderer_compositor); 572 DCHECK(!settings_.using_synchronous_renderer_compositor);
573 573
574 begin_impl_frame_deadline_task_.Cancel(); 574 begin_impl_frame_deadline_task_.Cancel();
575 begin_impl_frame_deadline_task_.Reset(begin_impl_frame_deadline_closure_); 575 begin_impl_frame_deadline_task_.Reset(begin_impl_frame_deadline_closure_);
576 576
577 begin_impl_frame_deadline_mode_ = 577 begin_impl_frame_deadline_mode_ =
578 state_machine_.CurrentBeginImplFrameDeadlineMode(); 578 state_machine_.CurrentBeginImplFrameDeadlineMode();
579 579
580 base::TimeTicks deadline; 580 base::TimeTicks deadline;
581 switch (begin_impl_frame_deadline_mode_) { 581 switch (begin_impl_frame_deadline_mode_) {
582 case SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE:
583 // No deadline.
584 return;
585 case SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_IMMEDIATE: 582 case SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_IMMEDIATE:
586 // We are ready to draw a new active tree immediately. 583 // We are ready to draw a new active tree immediately.
587 // We don't use Now() here because it's somewhat expensive to call. 584 // We don't use Now() here because it's somewhat expensive to call.
588 deadline = base::TimeTicks(); 585 deadline = base::TimeTicks();
589 break; 586 break;
590 case SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_REGULAR: 587 case SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_REGULAR:
591 // We are animating on the impl thread but we can wait for some time. 588 // We are animating on the impl thread but we can wait for some time.
592 deadline = begin_impl_frame_args_.deadline; 589 deadline = begin_impl_frame_args_.deadline;
593 break; 590 break;
594 case SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_LATE: 591 case SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_LATE:
595 // We are blocked for one reason or another and we should wait. 592 // We are blocked for one reason or another and we should wait.
596 // TODO(brianderson): Handle long deadlines (that are past the next 593 // TODO(brianderson): Handle long deadlines (that are past the next
597 // frame's frame time) properly instead of using this hack. 594 // frame's frame time) properly instead of using this hack.
598 deadline = 595 deadline =
599 begin_impl_frame_args_.frame_time + begin_impl_frame_args_.interval; 596 begin_impl_frame_args_.frame_time + begin_impl_frame_args_.interval;
600 break; 597 break;
601 } 598 }
602 599
603 TRACE_EVENT2("cc", "Scheduler::ScheduleBeginImplFrameDeadline", "mode", 600 TRACE_EVENT1(
604 SchedulerStateMachine::BeginImplFrameDeadlineModeToString( 601 "cc", "Scheduler::ScheduleBeginImplFrameDeadline", "deadline", deadline);
605 begin_impl_frame_deadline_mode_),
606 "deadline", deadline);
607 602
608 base::TimeDelta delta = std::max(deadline - Now(), base::TimeDelta()); 603 base::TimeDelta delta = deadline - Now();
604 if (delta <= base::TimeDelta())
605 delta = base::TimeDelta();
609 task_runner_->PostDelayedTask( 606 task_runner_->PostDelayedTask(
610 FROM_HERE, begin_impl_frame_deadline_task_.callback(), delta); 607 FROM_HERE, begin_impl_frame_deadline_task_.callback(), delta);
611 } 608 }
612 609
613 void Scheduler::ScheduleBeginImplFrameDeadlineIfNeeded() { 610 void Scheduler::RescheduleBeginImplFrameDeadlineIfNeeded() {
614 if (settings_.using_synchronous_renderer_compositor) 611 if (settings_.using_synchronous_renderer_compositor)
615 return; 612 return;
616 613
617 if (state_machine_.begin_impl_frame_state() != 614 if (state_machine_.begin_impl_frame_state() !=
618 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME) 615 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME)
619 return; 616 return;
620 617
621 if (begin_impl_frame_deadline_mode_ == 618 if (begin_impl_frame_deadline_mode_ !=
622 state_machine_.CurrentBeginImplFrameDeadlineMode() && 619 state_machine_.CurrentBeginImplFrameDeadlineMode())
623 BeginImplFrameDeadlinePending()) 620 ScheduleBeginImplFrameDeadline();
624 return;
625
626 ScheduleBeginImplFrameDeadline();
627 } 621 }
628 622
629 void Scheduler::OnBeginImplFrameDeadline() { 623 void Scheduler::OnBeginImplFrameDeadline() {
630 TRACE_EVENT0("cc,benchmark", "Scheduler::OnBeginImplFrameDeadline"); 624 TRACE_EVENT0("cc,benchmark", "Scheduler::OnBeginImplFrameDeadline");
631 begin_impl_frame_deadline_task_.Cancel(); 625 begin_impl_frame_deadline_task_.Cancel();
632 // We split the deadline actions up into two phases so the state machine 626 // We split the deadline actions up into two phases so the state machine
633 // has a chance to trigger actions that should occur durring and after 627 // has a chance to trigger actions that should occur durring and after
634 // the deadline separately. For example: 628 // the deadline separately. For example:
635 // * Sending the BeginMainFrame will not occur after the deadline in 629 // * Sending the BeginMainFrame will not occur after the deadline in
636 // order to wait for more user-input before starting the next commit. 630 // order to wait for more user-input before starting the next commit.
637 // * Creating a new OuputSurface will not occur during the deadline in 631 // * Creating a new OuputSurface will not occur during the deadline in
638 // order to allow the state machine to "settle" first. 632 // order to allow the state machine to "settle" first.
639 633
640 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is fixed. 634 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is fixed.
641 tracked_objects::ScopedTracker tracking_profile1( 635 tracked_objects::ScopedTracker tracking_profile1(
642 FROM_HERE_WITH_EXPLICIT_FUNCTION( 636 FROM_HERE_WITH_EXPLICIT_FUNCTION(
643 "461509 Scheduler::OnBeginImplFrameDeadline1")); 637 "461509 Scheduler::OnBeginImplFrameDeadline1"));
644 state_machine_.OnBeginImplFrameDeadline(); 638 state_machine_.OnBeginImplFrameDeadline();
645 ProcessScheduledActions(); 639 ProcessScheduledActions();
646 FinishImplFrame(); 640 state_machine_.OnBeginImplFrameIdle();
641 ProcessScheduledActions();
642
643 client_->DidBeginImplFrameDeadline();
644 frame_source_->DidFinishFrame(begin_retro_frame_args_.size());
647 } 645 }
648 646
647 void Scheduler::PollForAnticipatedDrawTriggers() {
648 TRACE_EVENT0("cc", "Scheduler::PollForAnticipatedDrawTriggers");
649 poll_for_draw_triggers_task_.Cancel();
650 state_machine_.DidEnterPollForAnticipatedDrawTriggers();
651 ProcessScheduledActions();
652 state_machine_.DidLeavePollForAnticipatedDrawTriggers();
653 }
649 654
650 void Scheduler::PollToAdvanceCommitState() { 655 void Scheduler::PollToAdvanceCommitState() {
651 TRACE_EVENT0("cc", "Scheduler::PollToAdvanceCommitState"); 656 TRACE_EVENT0("cc", "Scheduler::PollToAdvanceCommitState");
652 advance_commit_state_task_.Cancel(); 657 advance_commit_state_task_.Cancel();
653 ProcessScheduledActions(); 658 ProcessScheduledActions();
654 } 659 }
655 660
656 void Scheduler::DrawAndSwapIfPossible() { 661 void Scheduler::DrawAndSwapIfPossible() {
657 DrawResult result = client_->ScheduledActionDrawAndSwapIfPossible(); 662 DrawResult result = client_->ScheduledActionDrawAndSwapIfPossible();
658 state_machine_.DidDrawIfPossibleCompleted(result); 663 state_machine_.DidDrawIfPossibleCompleted(result);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT: 728 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT:
724 // No action is actually performed, but this allows the state machine to 729 // No action is actually performed, but this allows the state machine to
725 // advance out of its waiting to draw state without actually drawing. 730 // advance out of its waiting to draw state without actually drawing.
726 break; 731 break;
727 case SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION: 732 case SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION:
728 client_->ScheduledActionBeginOutputSurfaceCreation(); 733 client_->ScheduledActionBeginOutputSurfaceCreation();
729 break; 734 break;
730 case SchedulerStateMachine::ACTION_PREPARE_TILES: 735 case SchedulerStateMachine::ACTION_PREPARE_TILES:
731 client_->ScheduledActionPrepareTiles(); 736 client_->ScheduledActionPrepareTiles();
732 break; 737 break;
733 case SchedulerStateMachine::ACTION_INVALIDATE_OUTPUT_SURFACE: {
734 client_->ScheduledActionInvalidateOutputSurface();
735 break;
736 }
737 } 738 }
738 } while (action != SchedulerStateMachine::ACTION_NONE); 739 } while (action != SchedulerStateMachine::ACTION_NONE);
739 740
740 SetupPollingMechanisms(); 741 SetupPollingMechanisms();
741 742
742 client_->DidAnticipatedDrawTimeChange(AnticipatedDrawTime()); 743 client_->DidAnticipatedDrawTimeChange(AnticipatedDrawTime());
743 744
744 ScheduleBeginImplFrameDeadlineIfNeeded(); 745 RescheduleBeginImplFrameDeadlineIfNeeded();
745 746
746 SetupNextBeginFrameIfNeeded(); 747 SetupNextBeginFrameIfNeeded();
747 } 748 }
748 749
749 scoped_refptr<base::trace_event::ConvertableToTraceFormat> Scheduler::AsValue() 750 scoped_refptr<base::trace_event::ConvertableToTraceFormat> Scheduler::AsValue()
750 const { 751 const {
751 scoped_refptr<base::trace_event::TracedValue> state = 752 scoped_refptr<base::trace_event::TracedValue> state =
752 new base::trace_event::TracedValue(); 753 new base::trace_event::TracedValue();
753 AsValueInto(state.get()); 754 AsValueInto(state.get());
754 return state; 755 return state;
(...skipping 20 matching lines...) Expand all
775 (AnticipatedDrawTime() - Now()).InMillisecondsF()); 776 (AnticipatedDrawTime() - Now()).InMillisecondsF());
776 state->SetDouble("estimated_parent_draw_time_ms", 777 state->SetDouble("estimated_parent_draw_time_ms",
777 estimated_parent_draw_time_.InMillisecondsF()); 778 estimated_parent_draw_time_.InMillisecondsF());
778 state->SetBoolean("last_set_needs_begin_frame_", 779 state->SetBoolean("last_set_needs_begin_frame_",
779 frame_source_->NeedsBeginFrames()); 780 frame_source_->NeedsBeginFrames());
780 state->SetInteger("begin_retro_frame_args_", begin_retro_frame_args_.size()); 781 state->SetInteger("begin_retro_frame_args_", begin_retro_frame_args_.size());
781 state->SetBoolean("begin_retro_frame_task_", 782 state->SetBoolean("begin_retro_frame_task_",
782 !begin_retro_frame_task_.IsCancelled()); 783 !begin_retro_frame_task_.IsCancelled());
783 state->SetBoolean("begin_impl_frame_deadline_task_", 784 state->SetBoolean("begin_impl_frame_deadline_task_",
784 !begin_impl_frame_deadline_task_.IsCancelled()); 785 !begin_impl_frame_deadline_task_.IsCancelled());
786 state->SetBoolean("poll_for_draw_triggers_task_",
787 !poll_for_draw_triggers_task_.IsCancelled());
785 state->SetBoolean("advance_commit_state_task_", 788 state->SetBoolean("advance_commit_state_task_",
786 !advance_commit_state_task_.IsCancelled()); 789 !advance_commit_state_task_.IsCancelled());
787 state->BeginDictionary("begin_impl_frame_args"); 790 state->BeginDictionary("begin_impl_frame_args");
788 begin_impl_frame_args_.AsValueInto(state); 791 begin_impl_frame_args_.AsValueInto(state);
789 state->EndDictionary(); 792 state->EndDictionary();
790 793
791 base::TimeTicks now = Now(); 794 base::TimeTicks now = Now();
792 base::TimeTicks frame_time = begin_impl_frame_args_.frame_time; 795 base::TimeTicks frame_time = begin_impl_frame_args_.frame_time;
793 base::TimeTicks deadline = begin_impl_frame_args_.deadline; 796 base::TimeTicks deadline = begin_impl_frame_args_.deadline;
794 base::TimeDelta interval = begin_impl_frame_args_.interval; 797 base::TimeDelta interval = begin_impl_frame_args_.interval;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 } 842 }
840 843
841 bool Scheduler::IsBeginMainFrameSentOrStarted() const { 844 bool Scheduler::IsBeginMainFrameSentOrStarted() const {
842 return (state_machine_.commit_state() == 845 return (state_machine_.commit_state() ==
843 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || 846 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT ||
844 state_machine_.commit_state() == 847 state_machine_.commit_state() ==
845 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); 848 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED);
846 } 849 }
847 850
848 } // namespace cc 851 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler.h ('k') | cc/scheduler/scheduler_state_machine.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698