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

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

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