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

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: Address boliu's comments. Created 5 years, 9 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 "Scheduler::Scheduler", 100 "Scheduler::Scheduler",
101 "settings", 101 "settings",
102 settings_.AsValue()); 102 settings_.AsValue());
103 DCHECK(client_); 103 DCHECK(client_);
104 DCHECK(!state_machine_.BeginFrameNeeded()); 104 DCHECK(!state_machine_.BeginFrameNeeded());
105 105
106 begin_retro_frame_closure_ = 106 begin_retro_frame_closure_ =
107 base::Bind(&Scheduler::BeginRetroFrame, weak_factory_.GetWeakPtr()); 107 base::Bind(&Scheduler::BeginRetroFrame, weak_factory_.GetWeakPtr());
108 begin_impl_frame_deadline_closure_ = base::Bind( 108 begin_impl_frame_deadline_closure_ = base::Bind(
109 &Scheduler::OnBeginImplFrameDeadline, weak_factory_.GetWeakPtr()); 109 &Scheduler::OnBeginImplFrameDeadline, weak_factory_.GetWeakPtr());
110 poll_for_draw_triggers_closure_ = base::Bind(
111 &Scheduler::PollForAnticipatedDrawTriggers, weak_factory_.GetWeakPtr());
112 advance_commit_state_closure_ = base::Bind( 110 advance_commit_state_closure_ = base::Bind(
113 &Scheduler::PollToAdvanceCommitState, weak_factory_.GetWeakPtr()); 111 &Scheduler::PollToAdvanceCommitState, weak_factory_.GetWeakPtr());
114 112
115 frame_source_ = BeginFrameSourceMultiplexer::Create(); 113 frame_source_ = BeginFrameSourceMultiplexer::Create();
116 frame_source_->AddObserver(this); 114 frame_source_->AddObserver(this);
117 115
118 // Primary frame source 116 // Primary frame source
119 primary_frame_source_ = 117 primary_frame_source_ =
120 frame_sources_constructor->ConstructPrimaryFrameSource(this); 118 frame_sources_constructor->ConstructPrimaryFrameSource(this);
121 frame_source_->AddSource(primary_frame_source_); 119 frame_source_->AddSource(primary_frame_source_);
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 client_->SendBeginMainFrameNotExpectedSoon(); 315 client_->SendBeginMainFrameNotExpectedSoon();
318 } 316 }
319 } 317 }
320 318
321 PostBeginRetroFrameIfNeeded(); 319 PostBeginRetroFrameIfNeeded();
322 } 320 }
323 321
324 // We may need to poll when we can't rely on BeginFrame to advance certain 322 // We may need to poll when we can't rely on BeginFrame to advance certain
325 // state or to avoid deadlock. 323 // state or to avoid deadlock.
326 void Scheduler::SetupPollingMechanisms() { 324 void Scheduler::SetupPollingMechanisms() {
327 bool needs_advance_commit_state_timer = false; 325 // At this point we'd prefer to advance through the commit flow by
328 // Setup PollForAnticipatedDrawTriggers if we need to monitor state but 326 // drawing a frame, however it's possible that the frame rate controller
329 // aren't expecting any more BeginFrames. This should only be needed by 327 // will not give us a BeginFrame until the commit completes. See
330 // the synchronous compositor when BeginFrameNeeded is false. 328 // crbug.com/317430 for an example of a swap ack being held on commit. Thus
mithro-old 2015/03/23 12:47:09 Is the stuff in crbug.com/317430 the only reason k
sunnyps 2015/03/23 22:53:19 I don't know for sure but I imagine so.
331 if (state_machine_.ShouldPollForAnticipatedDrawTriggers()) { 329 // we set a repeating timer to poll on ProcessScheduledActions until we
332 DCHECK(!state_machine_.SupportsProactiveBeginFrame()); 330 // successfully reach BeginFrame. Synchronous compositor does not use
333 if (poll_for_draw_triggers_task_.IsCancelled()) { 331 // frame rate controller or have the circular wait in the bug.
334 poll_for_draw_triggers_task_.Reset(poll_for_draw_triggers_closure_); 332 if (IsBeginMainFrameSentOrStarted() &&
335 base::TimeDelta delay = begin_impl_frame_args_.IsValid() 333 !settings_.using_synchronous_renderer_compositor) {
336 ? begin_impl_frame_args_.interval
337 : BeginFrameArgs::DefaultInterval();
338 task_runner_->PostDelayedTask(
339 FROM_HERE, poll_for_draw_triggers_task_.callback(), delay);
340 }
341 } else {
342 poll_for_draw_triggers_task_.Cancel();
343
344 // At this point we'd prefer to advance through the commit flow by
345 // drawing a frame, however it's possible that the frame rate controller
346 // will not give us a BeginFrame until the commit completes. See
347 // crbug.com/317430 for an example of a swap ack being held on commit. Thus
348 // we set a repeating timer to poll on ProcessScheduledActions until we
349 // successfully reach BeginFrame. Synchronous compositor does not use
350 // frame rate controller or have the circular wait in the bug.
351 if (IsBeginMainFrameSentOrStarted() &&
352 !settings_.using_synchronous_renderer_compositor) {
353 needs_advance_commit_state_timer = true;
354 }
355 }
356
357 if (needs_advance_commit_state_timer) {
358 if (advance_commit_state_task_.IsCancelled() && 334 if (advance_commit_state_task_.IsCancelled() &&
359 begin_impl_frame_args_.IsValid()) { 335 begin_impl_frame_args_.IsValid()) {
360 // Since we'd rather get a BeginImplFrame by the normal mechanism, we 336 // Since we'd rather get a BeginImplFrame by the normal mechanism, we
361 // set the interval to twice the interval from the previous frame. 337 // set the interval to twice the interval from the previous frame.
362 advance_commit_state_task_.Reset(advance_commit_state_closure_); 338 advance_commit_state_task_.Reset(advance_commit_state_closure_);
363 task_runner_->PostDelayedTask(FROM_HERE, 339 task_runner_->PostDelayedTask(FROM_HERE,
364 advance_commit_state_task_.callback(), 340 advance_commit_state_task_.callback(),
365 begin_impl_frame_args_.interval * 2); 341 begin_impl_frame_args_.interval * 2);
366 } 342 }
367 } else { 343 } else {
(...skipping 15 matching lines...) Expand all
383 // TODO(simonhong): Once we have commitless update, we can get rid of 359 // TODO(simonhong): Once we have commitless update, we can get rid of
384 // BeginMainFrameToCommitDurationEstimate() + 360 // BeginMainFrameToCommitDurationEstimate() +
385 // CommitToActivateDurationEstimate(). 361 // CommitToActivateDurationEstimate().
386 adjusted_args_for_children.deadline -= 362 adjusted_args_for_children.deadline -=
387 (client_->BeginMainFrameToCommitDurationEstimate() + 363 (client_->BeginMainFrameToCommitDurationEstimate() +
388 client_->CommitToActivateDurationEstimate() + 364 client_->CommitToActivateDurationEstimate() +
389 client_->DrawDurationEstimate() + EstimatedParentDrawTime()); 365 client_->DrawDurationEstimate() + EstimatedParentDrawTime());
390 client_->SendBeginFramesToChildren(adjusted_args_for_children); 366 client_->SendBeginFramesToChildren(adjusted_args_for_children);
391 } 367 }
392 368
369 BeginFrameArgs adjusted_args(args);
370 adjusted_args.deadline -= EstimatedParentDrawTime();
371
372 if (settings_.using_synchronous_renderer_compositor) {
373 BeginImplFrame(adjusted_args);
374 return true;
375 }
376
393 // We have just called SetNeedsBeginFrame(true) and the BeginFrameSource has 377 // We have just called SetNeedsBeginFrame(true) and the BeginFrameSource has
394 // sent us the last BeginFrame we have missed. As we might not be able to 378 // sent us the last BeginFrame we have missed. As we might not be able to
395 // actually make rendering for this call, handle it like a "retro frame". 379 // actually make rendering for this call, handle it like a "retro frame".
396 // TODO(brainderson): Add a test for this functionality ASAP! 380 // TODO(brainderson): Add a test for this functionality ASAP!
397 if (args.type == BeginFrameArgs::MISSED) { 381 if (args.type == BeginFrameArgs::MISSED) {
398 begin_retro_frame_args_.push_back(args); 382 begin_retro_frame_args_.push_back(adjusted_args);
mithro-old 2015/03/23 12:47:09 Changing this too adjusted_args seems like an unre
sunnyps 2015/03/23 22:53:19 Done. I moved this to another CL: https://coderevi
399 PostBeginRetroFrameIfNeeded(); 383 PostBeginRetroFrameIfNeeded();
400 return true; 384 return true;
401 } 385 }
402 386
403 BeginFrameArgs adjusted_args(args); 387 bool should_defer_begin_frame =
404 adjusted_args.deadline -= EstimatedParentDrawTime(); 388 !begin_retro_frame_args_.empty() ||
405 389 !begin_retro_frame_task_.IsCancelled() ||
406 bool should_defer_begin_frame; 390 !frame_source_->NeedsBeginFrames() ||
407 if (settings_.using_synchronous_renderer_compositor) { 391 (state_machine_.begin_impl_frame_state() !=
408 should_defer_begin_frame = false; 392 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
409 } else {
410 should_defer_begin_frame =
411 !begin_retro_frame_args_.empty() ||
412 !begin_retro_frame_task_.IsCancelled() ||
413 !frame_source_->NeedsBeginFrames() ||
414 (state_machine_.begin_impl_frame_state() !=
415 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
416 }
417 393
418 if (should_defer_begin_frame) { 394 if (should_defer_begin_frame) {
419 begin_retro_frame_args_.push_back(adjusted_args); 395 begin_retro_frame_args_.push_back(adjusted_args);
420 TRACE_EVENT_INSTANT0( 396 TRACE_EVENT_INSTANT0(
421 "cc", "Scheduler::BeginFrame deferred", TRACE_EVENT_SCOPE_THREAD); 397 "cc", "Scheduler::BeginFrame deferred", TRACE_EVENT_SCOPE_THREAD);
422 // Queuing the frame counts as "using it", so we need to return true. 398 // Queuing the frame counts as "using it", so we need to return true.
423 } else { 399 } else {
424 BeginImplFrame(adjusted_args); 400 BeginImplFrame(adjusted_args);
425 } 401 }
426 return true; 402 return true;
427 } 403 }
428 404
429 void Scheduler::SetChildrenNeedBeginFrames(bool children_need_begin_frames) { 405 void Scheduler::SetChildrenNeedBeginFrames(bool children_need_begin_frames) {
430 state_machine_.SetChildrenNeedBeginFrames(children_need_begin_frames); 406 state_machine_.SetChildrenNeedBeginFrames(children_need_begin_frames);
431 ProcessScheduledActions(); 407 ProcessScheduledActions();
432 } 408 }
433 409
410 void Scheduler::OnDrawForOutputSurface() {
mithro-old 2015/03/23 12:47:09 This "hack" for forcing the state_machine_ like th
sunnyps 2015/03/23 22:53:19 I don't intend for this to be a hack for long. Aft
mithro-old 2015/03/24 05:43:45 Excellent, I think that will be great to do!
411 DCHECK(settings_.using_synchronous_renderer_compositor);
412 DCHECK_EQ(state_machine_.begin_impl_frame_state(),
413 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
414 DCHECK(!BeginImplFrameDeadlinePending());
415
416 state_machine_.OnBeginImplFrameDeadline();
417 ProcessScheduledActions();
418
419 state_machine_.OnBeginImplFrameIdle();
420 ProcessScheduledActions();
421 }
422
434 // BeginRetroFrame is called for BeginFrames that we've deferred because 423 // BeginRetroFrame is called for BeginFrames that we've deferred because
435 // the scheduler was in the middle of processing a previous BeginFrame. 424 // the scheduler was in the middle of processing a previous BeginFrame.
436 void Scheduler::BeginRetroFrame() { 425 void Scheduler::BeginRetroFrame() {
437 TRACE_EVENT0("cc,benchmark", "Scheduler::BeginRetroFrame"); 426 TRACE_EVENT0("cc,benchmark", "Scheduler::BeginRetroFrame");
438 DCHECK(!settings_.using_synchronous_renderer_compositor); 427 DCHECK(!settings_.using_synchronous_renderer_compositor);
439 DCHECK(!begin_retro_frame_args_.empty()); 428 DCHECK(!begin_retro_frame_args_.empty());
440 DCHECK(!begin_retro_frame_task_.IsCancelled()); 429 DCHECK(!begin_retro_frame_task_.IsCancelled());
441 DCHECK_EQ(state_machine_.begin_impl_frame_state(), 430 DCHECK_EQ(state_machine_.begin_impl_frame_state(),
442 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); 431 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
443 432
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 "Scheduler::BeginImplFrame", 503 "Scheduler::BeginImplFrame",
515 "args", 504 "args",
516 args.AsValue(), 505 args.AsValue(),
517 "main_thread_is_high_latency", 506 "main_thread_is_high_latency",
518 main_thread_is_in_high_latency_mode); 507 main_thread_is_in_high_latency_mode);
519 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), 508 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"),
520 "MainThreadLatency", 509 "MainThreadLatency",
521 main_thread_is_in_high_latency_mode); 510 main_thread_is_in_high_latency_mode);
522 DCHECK_EQ(state_machine_.begin_impl_frame_state(), 511 DCHECK_EQ(state_machine_.begin_impl_frame_state(),
523 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); 512 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
513 DCHECK(!BeginImplFrameDeadlinePending());
524 DCHECK(state_machine_.HasInitializedOutputSurface()); 514 DCHECK(state_machine_.HasInitializedOutputSurface());
525 515
526 advance_commit_state_task_.Cancel(); 516 advance_commit_state_task_.Cancel();
527 517
528 begin_impl_frame_args_ = args; 518 begin_impl_frame_args_ = args;
529 begin_impl_frame_args_.deadline -= client_->DrawDurationEstimate(); 519 begin_impl_frame_args_.deadline -= client_->DrawDurationEstimate();
530 520
531 if (!state_machine_.impl_latency_takes_priority() && 521 if (!state_machine_.impl_latency_takes_priority() &&
532 main_thread_is_in_high_latency_mode && 522 main_thread_is_in_high_latency_mode &&
533 CanCommitAndActivateBeforeDeadline()) { 523 CanCommitAndActivateBeforeDeadline()) {
534 state_machine_.SetSkipNextBeginMainFrameToReduceLatency(); 524 state_machine_.SetSkipNextBeginMainFrameToReduceLatency();
535 } 525 }
536 526
537 state_machine_.OnBeginImplFrame(); 527 state_machine_.OnBeginImplFrame();
538 devtools_instrumentation::DidBeginFrame(layer_tree_host_id_); 528 devtools_instrumentation::DidBeginFrame(layer_tree_host_id_);
539 client_->WillBeginImplFrame(begin_impl_frame_args_); 529 client_->WillBeginImplFrame(begin_impl_frame_args_);
540 530
541 ProcessScheduledActions(); 531 ProcessScheduledActions();
542 532
543 state_machine_.OnBeginImplFrameDeadlinePending();
544
545 if (settings_.using_synchronous_renderer_compositor) { 533 if (settings_.using_synchronous_renderer_compositor) {
mithro-old 2015/03/23 12:47:09 Should we be switching on begin_impl_frame_deadlin
sunnyps 2015/03/23 22:53:19 That won't work because the deadline mode is NONE
546 // The synchronous renderer compositor has to make its GL calls 534 // Synchronous compositor has no deadline.
547 // within this call. 535 state_machine_.OnBeginImplFrameIdle();
mithro-old 2015/03/23 12:47:09 This feels very similar to the OnBeginImplFrameDea
sunnyps 2015/03/23 22:53:19 Done. There are some differences, notably that we
548 // TODO(brianderson): Have the OutputSurface initiate the deadline tasks 536 ProcessScheduledActions();
549 // so the synchronous renderer compositor can take advantage of splitting 537 // Simulate the "finishing" of a frame here.
550 // up the BeginImplFrame and deadline as well. 538 client_->DidBeginImplFrameDeadline();
551 OnBeginImplFrameDeadline(); 539 frame_source_->DidFinishFrame(begin_retro_frame_args_.size());
552 } else { 540 } else {
553 ScheduleBeginImplFrameDeadline(); 541 // The deadline will be scheduled in ProcessScheduledActions.
542 state_machine_.OnBeginImplFrameDeadlinePending();
543 ProcessScheduledActions();
554 } 544 }
555 } 545 }
556 546
557 void Scheduler::ScheduleBeginImplFrameDeadline() { 547 void Scheduler::ScheduleBeginImplFrameDeadline() {
558 // The synchronous compositor does not post a deadline task.
559 DCHECK(!settings_.using_synchronous_renderer_compositor);
560
561 begin_impl_frame_deadline_task_.Cancel(); 548 begin_impl_frame_deadline_task_.Cancel();
562 begin_impl_frame_deadline_task_.Reset(begin_impl_frame_deadline_closure_); 549 begin_impl_frame_deadline_task_.Reset(begin_impl_frame_deadline_closure_);
563 550
564 begin_impl_frame_deadline_mode_ = 551 begin_impl_frame_deadline_mode_ =
565 state_machine_.CurrentBeginImplFrameDeadlineMode(); 552 state_machine_.CurrentBeginImplFrameDeadlineMode();
566 553
567 base::TimeTicks deadline; 554 base::TimeTicks deadline;
568 switch (begin_impl_frame_deadline_mode_) { 555 switch (begin_impl_frame_deadline_mode_) {
556 case SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE:
557 // No deadline.
558 return;
569 case SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_IMMEDIATE: 559 case SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_IMMEDIATE:
570 // We are ready to draw a new active tree immediately. 560 // We are ready to draw a new active tree immediately.
571 // We don't use Now() here because it's somewhat expensive to call. 561 // We don't use Now() here because it's somewhat expensive to call.
572 deadline = base::TimeTicks(); 562 deadline = base::TimeTicks();
573 break; 563 break;
574 case SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_REGULAR: 564 case SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_REGULAR:
575 // We are animating on the impl thread but we can wait for some time. 565 // We are animating on the impl thread but we can wait for some time.
576 deadline = begin_impl_frame_args_.deadline; 566 deadline = begin_impl_frame_args_.deadline;
577 break; 567 break;
578 case SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_LATE: 568 case SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_LATE:
579 // We are blocked for one reason or another and we should wait. 569 // We are blocked for one reason or another and we should wait.
580 // TODO(brianderson): Handle long deadlines (that are past the next 570 // TODO(brianderson): Handle long deadlines (that are past the next
581 // frame's frame time) properly instead of using this hack. 571 // frame's frame time) properly instead of using this hack.
582 deadline = 572 deadline =
583 begin_impl_frame_args_.frame_time + begin_impl_frame_args_.interval; 573 begin_impl_frame_args_.frame_time + begin_impl_frame_args_.interval;
584 break; 574 break;
585 } 575 }
586 576
587 TRACE_EVENT1( 577 TRACE_EVENT2("cc", "Scheduler::ScheduleBeginImplFrameDeadline", "mode",
588 "cc", "Scheduler::ScheduleBeginImplFrameDeadline", "deadline", deadline); 578 SchedulerStateMachine::BeginImplFrameDeadlineModeToString(
579 begin_impl_frame_deadline_mode_),
580 "deadline", deadline);
589 581
590 base::TimeDelta delta = deadline - Now(); 582 base::TimeDelta delta = std::max(deadline - Now(), base::TimeDelta());
591 if (delta <= base::TimeDelta())
592 delta = base::TimeDelta();
593 task_runner_->PostDelayedTask( 583 task_runner_->PostDelayedTask(
594 FROM_HERE, begin_impl_frame_deadline_task_.callback(), delta); 584 FROM_HERE, begin_impl_frame_deadline_task_.callback(), delta);
595 } 585 }
596 586
597 void Scheduler::RescheduleBeginImplFrameDeadlineIfNeeded() { 587 void Scheduler::ScheduleBeginImplFrameDeadlineIfNeeded() {
598 if (settings_.using_synchronous_renderer_compositor)
599 return;
600
601 if (state_machine_.begin_impl_frame_state() != 588 if (state_machine_.begin_impl_frame_state() !=
602 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME) 589 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME)
603 return; 590 return;
604 591
605 if (begin_impl_frame_deadline_mode_ != 592 if (begin_impl_frame_deadline_mode_ ==
606 state_machine_.CurrentBeginImplFrameDeadlineMode()) 593 state_machine_.CurrentBeginImplFrameDeadlineMode() &&
607 ScheduleBeginImplFrameDeadline(); 594 BeginImplFrameDeadlinePending())
595 return;
596
597 ScheduleBeginImplFrameDeadline();
608 } 598 }
609 599
610 void Scheduler::OnBeginImplFrameDeadline() { 600 void Scheduler::OnBeginImplFrameDeadline() {
mithro-old 2015/03/23 12:47:08 Does it make sense to split up this in some way so
sunnyps 2015/03/23 22:53:19 Done. Factored the common stuff out into a FinishI
611 TRACE_EVENT0("cc,benchmark", "Scheduler::OnBeginImplFrameDeadline"); 601 TRACE_EVENT0("cc,benchmark", "Scheduler::OnBeginImplFrameDeadline");
612 begin_impl_frame_deadline_task_.Cancel(); 602 begin_impl_frame_deadline_task_.Cancel();
613 // We split the deadline actions up into two phases so the state machine 603 // We split the deadline actions up into two phases so the state machine
614 // has a chance to trigger actions that should occur durring and after 604 // has a chance to trigger actions that should occur durring and after
615 // the deadline separately. For example: 605 // the deadline separately. For example:
616 // * Sending the BeginMainFrame will not occur after the deadline in 606 // * Sending the BeginMainFrame will not occur after the deadline in
617 // order to wait for more user-input before starting the next commit. 607 // order to wait for more user-input before starting the next commit.
618 // * Creating a new OuputSurface will not occur during the deadline in 608 // * Creating a new OuputSurface will not occur during the deadline in
619 // order to allow the state machine to "settle" first. 609 // order to allow the state machine to "settle" first.
620 610
(...skipping 12 matching lines...) Expand all
633 ProcessScheduledActions(); 623 ProcessScheduledActions();
634 624
635 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is fixed. 625 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is fixed.
636 tracked_objects::ScopedTracker tracking_profile3( 626 tracked_objects::ScopedTracker tracking_profile3(
637 FROM_HERE_WITH_EXPLICIT_FUNCTION( 627 FROM_HERE_WITH_EXPLICIT_FUNCTION(
638 "461509 Scheduler::OnBeginImplFrameDeadline3")); 628 "461509 Scheduler::OnBeginImplFrameDeadline3"));
639 client_->DidBeginImplFrameDeadline(); 629 client_->DidBeginImplFrameDeadline();
640 frame_source_->DidFinishFrame(begin_retro_frame_args_.size()); 630 frame_source_->DidFinishFrame(begin_retro_frame_args_.size());
641 } 631 }
642 632
643 void Scheduler::PollForAnticipatedDrawTriggers() {
644 TRACE_EVENT0("cc", "Scheduler::PollForAnticipatedDrawTriggers");
645 poll_for_draw_triggers_task_.Cancel();
646 state_machine_.DidEnterPollForAnticipatedDrawTriggers();
647 ProcessScheduledActions();
648 state_machine_.DidLeavePollForAnticipatedDrawTriggers();
649 }
650 633
651 void Scheduler::PollToAdvanceCommitState() { 634 void Scheduler::PollToAdvanceCommitState() {
652 TRACE_EVENT0("cc", "Scheduler::PollToAdvanceCommitState"); 635 TRACE_EVENT0("cc", "Scheduler::PollToAdvanceCommitState");
653 advance_commit_state_task_.Cancel(); 636 advance_commit_state_task_.Cancel();
654 ProcessScheduledActions(); 637 ProcessScheduledActions();
655 } 638 }
656 639
657 void Scheduler::DrawAndSwapIfPossible() { 640 void Scheduler::DrawAndSwapIfPossible() {
658 DrawResult result = client_->ScheduledActionDrawAndSwapIfPossible(); 641 DrawResult result = client_->ScheduledActionDrawAndSwapIfPossible();
659 state_machine_.DidDrawIfPossibleCompleted(result); 642 state_machine_.DidDrawIfPossibleCompleted(result);
660 } 643 }
661 644
662 void Scheduler::SetDeferCommits(bool defer_commits) { 645 void Scheduler::SetDeferCommits(bool defer_commits) {
663 TRACE_EVENT1("cc", "Scheduler::SetDeferCommits", 646 TRACE_EVENT1("cc", "Scheduler::SetDeferCommits",
664 "defer_commits", 647 "defer_commits",
665 defer_commits); 648 defer_commits);
666 state_machine_.SetDeferCommits(defer_commits); 649 state_machine_.SetDeferCommits(defer_commits);
667 ProcessScheduledActions(); 650 ProcessScheduledActions();
668 } 651 }
669 652
670 void Scheduler::ProcessScheduledActions() { 653 void Scheduler::ProcessScheduledActions() {
671 // We do not allow ProcessScheduledActions to be recursive. 654 // We do not allow ProcessScheduledActions to be recursive.
672 // The top-level call will iteratively execute the next action for us anyway. 655 // The top-level call will iteratively execute the next action for us anyway.
673 if (inside_process_scheduled_actions_) 656 if (inside_process_scheduled_actions_)
674 return; 657 return;
675 658
676 base::AutoReset<bool> mark_inside(&inside_process_scheduled_actions_, true); 659 { // Separate scope for mark_inside.
660 base::AutoReset<bool> mark_inside(&inside_process_scheduled_actions_, true);
677 661
678 SchedulerStateMachine::Action action; 662 SchedulerStateMachine::Action action;
679 do { 663 do {
680 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is fixed. 664 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is
681 tracked_objects::ScopedTracker tracking_profile1( 665 // fixed.
682 FROM_HERE_WITH_EXPLICIT_FUNCTION( 666 tracked_objects::ScopedTracker tracking_profile1(
683 "461509 Scheduler::ProcessScheduledActions1")); 667 FROM_HERE_WITH_EXPLICIT_FUNCTION(
684 action = state_machine_.NextAction(); 668 "461509 Scheduler::ProcessScheduledActions1"));
685 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), 669 action = state_machine_.NextAction();
686 "SchedulerStateMachine", 670 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"),
687 "state", 671 "SchedulerStateMachine", "state", AsValue());
688 AsValue()); 672 VLOG(2) << "Scheduler::ProcessScheduledActions: "
689 VLOG(2) << "Scheduler::ProcessScheduledActions: " 673 << SchedulerStateMachine::ActionToString(action) << " "
690 << SchedulerStateMachine::ActionToString(action) << " " 674 << state_machine_.GetStatesForDebugging();
691 << state_machine_.GetStatesForDebugging(); 675 state_machine_.UpdateState(action);
692 state_machine_.UpdateState(action); 676 base::AutoReset<SchedulerStateMachine::Action> mark_inside_action(
693 base::AutoReset<SchedulerStateMachine::Action> 677 &inside_action_, action);
694 mark_inside_action(&inside_action_, action); 678 switch (action) {
695 switch (action) { 679 case SchedulerStateMachine::ACTION_NONE:
696 case SchedulerStateMachine::ACTION_NONE: 680 break;
697 break; 681 case SchedulerStateMachine::ACTION_ANIMATE: {
698 case SchedulerStateMachine::ACTION_ANIMATE: { 682 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is
699 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is 683 // fixed.
700 // fixed. 684 tracked_objects::ScopedTracker tracking_profile2(
701 tracked_objects::ScopedTracker tracking_profile2( 685 FROM_HERE_WITH_EXPLICIT_FUNCTION(
702 FROM_HERE_WITH_EXPLICIT_FUNCTION( 686 "461509 Scheduler::ProcessScheduledActions2"));
mithro-old 2015/03/23 12:47:09 Is changing these FROM_HERE_WITH_EXPLICIT_FUNCTION
sunnyps 2015/03/23 22:53:19 Yeah, I agree with that. I think robliao@ is remov
mithro-old 2015/03/24 05:43:45 Just want to make sure you don't break robliao@'s
703 "461509 Scheduler::ProcessScheduledActions2")); 687 client_->ScheduledActionAnimate();
704 client_->ScheduledActionAnimate(); 688 break;
705 break; 689 }
690 case SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME: {
691 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is
692 // fixed.
693 tracked_objects::ScopedTracker tracking_profile3(
694 FROM_HERE_WITH_EXPLICIT_FUNCTION(
695 "461509 Scheduler::ProcessScheduledActions3"));
696 client_->ScheduledActionSendBeginMainFrame();
697 break;
698 }
699 case SchedulerStateMachine::ACTION_COMMIT: {
700 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is
701 // fixed.
702 tracked_objects::ScopedTracker tracking_profile4(
703 FROM_HERE_WITH_EXPLICIT_FUNCTION(
704 "461509 Scheduler::ProcessScheduledActions4"));
705 client_->ScheduledActionCommit();
706 break;
707 }
708 case SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE: {
709 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is
710 // fixed.
711 tracked_objects::ScopedTracker tracking_profile5(
712 FROM_HERE_WITH_EXPLICIT_FUNCTION(
713 "461509 Scheduler::ProcessScheduledActions5"));
714 client_->ScheduledActionActivateSyncTree();
715 break;
716 }
717 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE: {
718 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is
719 // fixed.
720 tracked_objects::ScopedTracker tracking_profile6(
721 FROM_HERE_WITH_EXPLICIT_FUNCTION(
722 "461509 Scheduler::ProcessScheduledActions6"));
723 DrawAndSwapIfPossible();
724 break;
725 }
726 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED: {
727 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is
728 // fixed.
729 tracked_objects::ScopedTracker tracking_profile7(
730 FROM_HERE_WITH_EXPLICIT_FUNCTION(
731 "461509 Scheduler::ProcessScheduledActions7"));
732 client_->ScheduledActionDrawAndSwapForced();
733 break;
734 }
735 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT:
736 // No action is actually performed, but this allows the state machine
737 // to advance out of it's waiting to draw state without actually
738 // drawing.
739 break;
740 case SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION: {
741 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is
742 // fixed.
743 tracked_objects::ScopedTracker tracking_profile8(
744 FROM_HERE_WITH_EXPLICIT_FUNCTION(
745 "461509 Scheduler::ProcessScheduledActions8"));
746 client_->ScheduledActionBeginOutputSurfaceCreation();
747 break;
748 }
749 case SchedulerStateMachine::ACTION_PREPARE_TILES: {
750 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is
751 // fixed.
752 tracked_objects::ScopedTracker tracking_profile9(
753 FROM_HERE_WITH_EXPLICIT_FUNCTION(
754 "461509 Scheduler::ProcessScheduledActions9"));
755 client_->ScheduledActionPrepareTiles();
756 break;
757 }
758 case SchedulerStateMachine::ACTION_INVALIDATE_OUTPUT_SURFACE: {
759 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is
760 // fixed.
761 tracked_objects::ScopedTracker tracking_profile10(
762 FROM_HERE_WITH_EXPLICIT_FUNCTION(
763 "461509 Scheduler::ProcessScheduledActions10"));
764 client_->ScheduledActionInvalidateOutputSurface();
765 break;
766 }
706 } 767 }
707 case SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME: { 768 } while (action != SchedulerStateMachine::ACTION_NONE);
708 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is 769 } // Separate scope for mark_inside.
709 // fixed.
710 tracked_objects::ScopedTracker tracking_profile3(
711 FROM_HERE_WITH_EXPLICIT_FUNCTION(
712 "461509 Scheduler::ProcessScheduledActions3"));
713 client_->ScheduledActionSendBeginMainFrame();
714 break;
715 }
716 case SchedulerStateMachine::ACTION_COMMIT: {
717 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is
718 // fixed.
719 tracked_objects::ScopedTracker tracking_profile4(
720 FROM_HERE_WITH_EXPLICIT_FUNCTION(
721 "461509 Scheduler::ProcessScheduledActions4"));
722 client_->ScheduledActionCommit();
723 break;
724 }
725 case SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE: {
726 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is
727 // fixed.
728 tracked_objects::ScopedTracker tracking_profile5(
729 FROM_HERE_WITH_EXPLICIT_FUNCTION(
730 "461509 Scheduler::ProcessScheduledActions5"));
731 client_->ScheduledActionActivateSyncTree();
732 break;
733 }
734 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE: {
735 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is
736 // fixed.
737 tracked_objects::ScopedTracker tracking_profile6(
738 FROM_HERE_WITH_EXPLICIT_FUNCTION(
739 "461509 Scheduler::ProcessScheduledActions6"));
740 DrawAndSwapIfPossible();
741 break;
742 }
743 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED: {
744 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is
745 // fixed.
746 tracked_objects::ScopedTracker tracking_profile7(
747 FROM_HERE_WITH_EXPLICIT_FUNCTION(
748 "461509 Scheduler::ProcessScheduledActions7"));
749 client_->ScheduledActionDrawAndSwapForced();
750 break;
751 }
752 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT:
753 // No action is actually performed, but this allows the state machine to
754 // advance out of its waiting to draw state without actually drawing.
755 break;
756 case SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION: {
757 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is
758 // fixed.
759 tracked_objects::ScopedTracker tracking_profile8(
760 FROM_HERE_WITH_EXPLICIT_FUNCTION(
761 "461509 Scheduler::ProcessScheduledActions8"));
762 client_->ScheduledActionBeginOutputSurfaceCreation();
763 break;
764 }
765 case SchedulerStateMachine::ACTION_PREPARE_TILES: {
766 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is
767 // fixed.
768 tracked_objects::ScopedTracker tracking_profile9(
769 FROM_HERE_WITH_EXPLICIT_FUNCTION(
770 "461509 Scheduler::ProcessScheduledActions9"));
771 client_->ScheduledActionPrepareTiles();
772 break;
773 }
774 }
775 } while (action != SchedulerStateMachine::ACTION_NONE);
776
777 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is fixed.
778 tracked_objects::ScopedTracker tracking_profile10(
779 FROM_HERE_WITH_EXPLICIT_FUNCTION(
780 "461509 Scheduler::ProcessScheduledActions10"));
781
782 SetupPollingMechanisms();
783
784 client_->DidAnticipatedDrawTimeChange(AnticipatedDrawTime());
785 770
786 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is fixed. 771 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is fixed.
787 tracked_objects::ScopedTracker tracking_profile11( 772 tracked_objects::ScopedTracker tracking_profile11(
788 FROM_HERE_WITH_EXPLICIT_FUNCTION( 773 FROM_HERE_WITH_EXPLICIT_FUNCTION(
789 "461509 Scheduler::ProcessScheduledActions11")); 774 "461509 Scheduler::ProcessScheduledActions11"));
775 SetupPollingMechanisms();
790 776
791 RescheduleBeginImplFrameDeadlineIfNeeded(); 777 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is fixed.
778 tracked_objects::ScopedTracker tracking_profile12(
779 FROM_HERE_WITH_EXPLICIT_FUNCTION(
780 "461509 Scheduler::ProcessScheduledActions12"));
781 client_->DidAnticipatedDrawTimeChange(AnticipatedDrawTime());
792 782
783 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is fixed.
784 tracked_objects::ScopedTracker tracking_profile13(
785 FROM_HERE_WITH_EXPLICIT_FUNCTION(
786 "461509 Scheduler::ProcessScheduledActions13"));
787 ScheduleBeginImplFrameDeadlineIfNeeded();
788
789 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is fixed.
790 tracked_objects::ScopedTracker tracking_profile14(
791 FROM_HERE_WITH_EXPLICIT_FUNCTION(
792 "461509 Scheduler::ProcessScheduledActions14"));
793 SetupNextBeginFrameIfNeeded(); 793 SetupNextBeginFrameIfNeeded();
794 } 794 }
795 795
796 scoped_refptr<base::trace_event::ConvertableToTraceFormat> Scheduler::AsValue() 796 scoped_refptr<base::trace_event::ConvertableToTraceFormat> Scheduler::AsValue()
797 const { 797 const {
798 scoped_refptr<base::trace_event::TracedValue> state = 798 scoped_refptr<base::trace_event::TracedValue> state =
799 new base::trace_event::TracedValue(); 799 new base::trace_event::TracedValue();
800 AsValueInto(state.get()); 800 AsValueInto(state.get());
801 return state; 801 return state;
802 } 802 }
(...skipping 19 matching lines...) Expand all
822 (AnticipatedDrawTime() - Now()).InMillisecondsF()); 822 (AnticipatedDrawTime() - Now()).InMillisecondsF());
823 state->SetDouble("estimated_parent_draw_time_ms", 823 state->SetDouble("estimated_parent_draw_time_ms",
824 estimated_parent_draw_time_.InMillisecondsF()); 824 estimated_parent_draw_time_.InMillisecondsF());
825 state->SetBoolean("last_set_needs_begin_frame_", 825 state->SetBoolean("last_set_needs_begin_frame_",
826 frame_source_->NeedsBeginFrames()); 826 frame_source_->NeedsBeginFrames());
827 state->SetInteger("begin_retro_frame_args_", begin_retro_frame_args_.size()); 827 state->SetInteger("begin_retro_frame_args_", begin_retro_frame_args_.size());
828 state->SetBoolean("begin_retro_frame_task_", 828 state->SetBoolean("begin_retro_frame_task_",
829 !begin_retro_frame_task_.IsCancelled()); 829 !begin_retro_frame_task_.IsCancelled());
830 state->SetBoolean("begin_impl_frame_deadline_task_", 830 state->SetBoolean("begin_impl_frame_deadline_task_",
831 !begin_impl_frame_deadline_task_.IsCancelled()); 831 !begin_impl_frame_deadline_task_.IsCancelled());
832 state->SetBoolean("poll_for_draw_triggers_task_",
833 !poll_for_draw_triggers_task_.IsCancelled());
834 state->SetBoolean("advance_commit_state_task_", 832 state->SetBoolean("advance_commit_state_task_",
835 !advance_commit_state_task_.IsCancelled()); 833 !advance_commit_state_task_.IsCancelled());
836 state->BeginDictionary("begin_impl_frame_args"); 834 state->BeginDictionary("begin_impl_frame_args");
837 begin_impl_frame_args_.AsValueInto(state); 835 begin_impl_frame_args_.AsValueInto(state);
838 state->EndDictionary(); 836 state->EndDictionary();
839 837
840 base::TimeTicks now = Now(); 838 base::TimeTicks now = Now();
841 base::TimeTicks frame_time = begin_impl_frame_args_.frame_time; 839 base::TimeTicks frame_time = begin_impl_frame_args_.frame_time;
842 base::TimeTicks deadline = begin_impl_frame_args_.deadline; 840 base::TimeTicks deadline = begin_impl_frame_args_.deadline;
843 base::TimeDelta interval = begin_impl_frame_args_.interval; 841 base::TimeDelta interval = begin_impl_frame_args_.interval;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 } 886 }
889 887
890 bool Scheduler::IsBeginMainFrameSentOrStarted() const { 888 bool Scheduler::IsBeginMainFrameSentOrStarted() const {
891 return (state_machine_.commit_state() == 889 return (state_machine_.commit_state() ==
892 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || 890 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT ||
893 state_machine_.commit_state() == 891 state_machine_.commit_state() ==
894 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); 892 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED);
895 } 893 }
896 894
897 } // namespace cc 895 } // 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