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

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

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

Powered by Google App Engine
This is Rietveld 408576698