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

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

Issue 1131633003: cc: Use multiple PrepareTiles approaches Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 7 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_settings.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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 void Scheduler::SetCanDraw(bool can_draw) { 161 void Scheduler::SetCanDraw(bool can_draw) {
162 state_machine_.SetCanDraw(can_draw); 162 state_machine_.SetCanDraw(can_draw);
163 ProcessScheduledActions(); 163 ProcessScheduledActions();
164 } 164 }
165 165
166 void Scheduler::NotifyReadyToActivate() { 166 void Scheduler::NotifyReadyToActivate() {
167 state_machine_.NotifyReadyToActivate(); 167 state_machine_.NotifyReadyToActivate();
168 ProcessScheduledActions(); 168 ProcessScheduledActions();
169 } 169 }
170 170
171 void Scheduler::SetRequiresHighResToDraw(bool required) {
172 state_machine_.SetRequiresHighResToDraw(required);
173 ProcessScheduledActions();
174 }
175
171 void Scheduler::NotifyReadyToDraw() { 176 void Scheduler::NotifyReadyToDraw() {
172 // Future work might still needed for crbug.com/352894. 177 // Future work might still needed for crbug.com/352894.
173 state_machine_.NotifyReadyToDraw(); 178 state_machine_.NotifyReadyToDraw();
174 ProcessScheduledActions(); 179 ProcessScheduledActions();
175 } 180 }
176 181
177 void Scheduler::SetThrottleFrameProduction(bool throttle) { 182 void Scheduler::SetThrottleFrameProduction(bool throttle) {
178 throttle_frame_production_ = throttle; 183 throttle_frame_production_ = throttle;
179 if (throttle) { 184 if (throttle) {
180 frame_source_->SetActiveSource(primary_frame_source_); 185 frame_source_->SetActiveSource(primary_frame_source_);
(...skipping 11 matching lines...) Expand all
192 void Scheduler::SetNeedsRedraw() { 197 void Scheduler::SetNeedsRedraw() {
193 state_machine_.SetNeedsRedraw(); 198 state_machine_.SetNeedsRedraw();
194 ProcessScheduledActions(); 199 ProcessScheduledActions();
195 } 200 }
196 201
197 void Scheduler::SetNeedsAnimate() { 202 void Scheduler::SetNeedsAnimate() {
198 state_machine_.SetNeedsAnimate(); 203 state_machine_.SetNeedsAnimate();
199 ProcessScheduledActions(); 204 ProcessScheduledActions();
200 } 205 }
201 206
202 void Scheduler::SetNeedsPrepareTiles() { 207 void Scheduler::SetNeedsPrepareTiles(bool for_commit) {
203 DCHECK(!IsInsideAction(SchedulerStateMachine::ACTION_PREPARE_TILES)); 208 state_machine_.SetNeedsPrepareTiles(for_commit);
204 state_machine_.SetNeedsPrepareTiles();
205 ProcessScheduledActions(); 209 ProcessScheduledActions();
206 } 210 }
207 211
208 void Scheduler::SetWaitForReadyToDraw() { 212 void Scheduler::SetWaitForReadyToDraw() {
209 state_machine_.SetWaitForReadyToDraw(); 213 state_machine_.SetWaitForReadyToDraw();
210 ProcessScheduledActions(); 214 ProcessScheduledActions();
211 } 215 }
212 216
213 void Scheduler::SetMaxSwapsPending(int max) { 217 void Scheduler::SetMaxSwapsPending(int max) {
214 state_machine_.SetMaxSwapsPending(max); 218 state_machine_.SetMaxSwapsPending(max);
(...skipping 25 matching lines...) Expand all
240 ProcessScheduledActions(); 244 ProcessScheduledActions();
241 } 245 }
242 246
243 void Scheduler::BeginMainFrameAborted(CommitEarlyOutReason reason) { 247 void Scheduler::BeginMainFrameAborted(CommitEarlyOutReason reason) {
244 TRACE_EVENT1("cc", "Scheduler::BeginMainFrameAborted", "reason", 248 TRACE_EVENT1("cc", "Scheduler::BeginMainFrameAborted", "reason",
245 CommitEarlyOutReasonToString(reason)); 249 CommitEarlyOutReasonToString(reason));
246 state_machine_.BeginMainFrameAborted(reason); 250 state_machine_.BeginMainFrameAborted(reason);
247 ProcessScheduledActions(); 251 ProcessScheduledActions();
248 } 252 }
249 253
250 void Scheduler::DidPrepareTiles() {
251 state_machine_.DidPrepareTiles();
252 }
253
254 void Scheduler::DidLoseOutputSurface() { 254 void Scheduler::DidLoseOutputSurface() {
255 TRACE_EVENT0("cc", "Scheduler::DidLoseOutputSurface"); 255 TRACE_EVENT0("cc", "Scheduler::DidLoseOutputSurface");
256 begin_retro_frame_args_.clear(); 256 begin_retro_frame_args_.clear();
257 begin_retro_frame_task_.Cancel(); 257 begin_retro_frame_task_.Cancel();
258 state_machine_.DidLoseOutputSurface(); 258 state_machine_.DidLoseOutputSurface();
259 ProcessScheduledActions(); 259 ProcessScheduledActions();
260 } 260 }
261 261
262 void Scheduler::DidCreateAndInitializeOutputSurface() { 262 void Scheduler::DidCreateAndInitializeOutputSurface() {
263 TRACE_EVENT0("cc", "Scheduler::DidCreateAndInitializeOutputSurface"); 263 TRACE_EVENT0("cc", "Scheduler::DidCreateAndInitializeOutputSurface");
(...skipping 20 matching lines...) Expand all
284 return timebase + (begin_impl_frame_args_.interval * intervals); 284 return timebase + (begin_impl_frame_args_.interval * intervals);
285 } 285 }
286 286
287 base::TimeTicks Scheduler::LastBeginImplFrameTime() { 287 base::TimeTicks Scheduler::LastBeginImplFrameTime() {
288 return begin_impl_frame_args_.frame_time; 288 return begin_impl_frame_args_.frame_time;
289 } 289 }
290 290
291 void Scheduler::SetupNextBeginFrameIfNeeded() { 291 void Scheduler::SetupNextBeginFrameIfNeeded() {
292 // Never call SetNeedsBeginFrames if the frame source already has the right 292 // Never call SetNeedsBeginFrames if the frame source already has the right
293 // value. 293 // value.
294 if (frame_source_->NeedsBeginFrames() != state_machine_.BeginFrameNeeded()) { 294 bool begin_frames_needed = state_machine_.BeginFrameNeeded();
295 if (state_machine_.BeginFrameNeeded()) { 295 if (frame_source_->NeedsBeginFrames() != begin_frames_needed) {
296 if (begin_frames_needed) {
296 // Call SetNeedsBeginFrames(true) as soon as possible. 297 // Call SetNeedsBeginFrames(true) as soon as possible.
297 frame_source_->SetNeedsBeginFrames(true); 298 frame_source_->SetNeedsBeginFrames(true);
298 } else if (state_machine_.begin_impl_frame_state() == 299 } else if (state_machine_.begin_impl_frame_state() ==
299 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE) { 300 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE) {
300 // Call SetNeedsBeginFrames(false) in between frames only. 301 // Call SetNeedsBeginFrames(false) in between frames only.
301 frame_source_->SetNeedsBeginFrames(false); 302 frame_source_->SetNeedsBeginFrames(false);
302 client_->SendBeginMainFrameNotExpectedSoon(); 303 client_->SendBeginMainFrameNotExpectedSoon();
303 } 304 }
305 state_machine_.NotifyBeginFrameSourceActive(begin_frames_needed);
304 } 306 }
305 307
306 PostBeginRetroFrameIfNeeded(); 308 PostBeginRetroFrameIfNeeded();
307 } 309 }
308 310
309 // We may need to poll when we can't rely on BeginFrame to advance certain 311 // We may need to poll when we can't rely on BeginFrame to advance certain
310 // state or to avoid deadlock. 312 // state or to avoid deadlock.
311 void Scheduler::SetupPollingMechanisms() { 313 void Scheduler::SetupPollingMechanisms() {
312 // At this point we'd prefer to advance through the commit flow by 314 // At this point we'd prefer to advance through the commit flow by
313 // drawing a frame, however it's possible that the frame rate controller 315 // drawing a frame, however it's possible that the frame rate controller
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 } 513 }
512 514
513 void Scheduler::BeginImplFrameSynchronous(const BeginFrameArgs& args) { 515 void Scheduler::BeginImplFrameSynchronous(const BeginFrameArgs& args) {
514 TRACE_EVENT1("cc,benchmark", "Scheduler::BeginImplFrame", "args", 516 TRACE_EVENT1("cc,benchmark", "Scheduler::BeginImplFrame", "args",
515 args.AsValue()); 517 args.AsValue());
516 begin_impl_frame_args_ = args; 518 begin_impl_frame_args_ = args;
517 BeginImplFrame(); 519 BeginImplFrame();
518 FinishImplFrame(); 520 FinishImplFrame();
519 } 521 }
520 522
523 // Retry the BeginImplFrame if the draw aborted due to checkerboards and
524 // we need a new commit to get a new RasterSource.
525 void Scheduler::RetryBeginImplFrameWithDeadline() {
526 TRACE_EVENT0("cc", "Scheduler::RetryBeginImplFrameWithDeadline");
527 state_machine_.ResetRetryBeginImplFrame();
528
529 BeginImplFrame();
530
531 // The deadline will be scheduled in ProcessScheduledActions.
532 state_machine_.OnBeginImplFrameDeadlinePending();
533 ProcessScheduledActions();
534 }
535
536 // Retry the deadline if the draw aborted due to checkerboards, but we
537 // do not need a new commit to get a new RasterSource.
538 void Scheduler::RetryBeginImplFrameDeadline() {
539 TRACE_EVENT0("cc", "Scheduler::RetryImplFrameDeadline");
540 state_machine_.ResetRetryBeginImplFrame();
541
542 // The deadline will be scheduled in ProcessScheduledActions.
543 state_machine_.OnBeginImplFrameDeadlinePending();
544 ProcessScheduledActions();
545 }
546
521 void Scheduler::FinishImplFrame() { 547 void Scheduler::FinishImplFrame() {
522 state_machine_.OnBeginImplFrameIdle(); 548 state_machine_.OnBeginImplFrameIdle();
523 ProcessScheduledActions(); 549 ProcessScheduledActions();
524 550
525 client_->DidFinishImplFrame(); 551 client_->DidFinishImplFrame();
526 frame_source_->DidFinishFrame(begin_retro_frame_args_.size()); 552 frame_source_->DidFinishFrame(begin_retro_frame_args_.size());
527 } 553 }
528 554
529 // BeginImplFrame starts a compositor frame that will wait up until a deadline 555 // BeginImplFrame starts a compositor frame that will wait up until a deadline
530 // for a BeginMainFrame+activation to complete before it times out and draws 556 // for a BeginMainFrame+activation to complete before it times out and draws
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 deadline = begin_impl_frame_args_.deadline; 594 deadline = begin_impl_frame_args_.deadline;
569 break; 595 break;
570 case SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_LATE: 596 case SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_LATE:
571 // We are blocked for one reason or another and we should wait. 597 // We are blocked for one reason or another and we should wait.
572 // TODO(brianderson): Handle long deadlines (that are past the next 598 // TODO(brianderson): Handle long deadlines (that are past the next
573 // frame's frame time) properly instead of using this hack. 599 // frame's frame time) properly instead of using this hack.
574 deadline = 600 deadline =
575 begin_impl_frame_args_.frame_time + begin_impl_frame_args_.interval; 601 begin_impl_frame_args_.frame_time + begin_impl_frame_args_.interval;
576 break; 602 break;
577 case SchedulerStateMachine:: 603 case SchedulerStateMachine::
604 BEGIN_IMPL_FRAME_DEADLINE_MODE_TRY_TO_AVOID_CHECKERBOARD:
605 // We will wait up until this deadline for the ReadyToDraw signal.
606 // TODO(brianderson): Use a different timeout for touch vs. mouse wheel.
607 deadline = begin_impl_frame_args_.frame_time +
608 (5 * begin_impl_frame_args_.interval);
609 break;
610 case SchedulerStateMachine::
578 BEGIN_IMPL_FRAME_DEADLINE_MODE_BLOCKED_ON_READY_TO_DRAW: 611 BEGIN_IMPL_FRAME_DEADLINE_MODE_BLOCKED_ON_READY_TO_DRAW:
579 // We are blocked because we are waiting for ReadyToDraw signal. We would 612 // We are blocked because we are waiting for ReadyToDraw signal. We would
580 // post deadline after we received ReadyToDraw singal. 613 // post deadline after we received ReadyToDraw singal.
581 TRACE_EVENT1("cc", "Scheduler::ScheduleBeginImplFrameDeadline", 614 TRACE_EVENT1("cc", "Scheduler::ScheduleBeginImplFrameDeadline",
582 "deadline_mode", "blocked_on_ready_to_draw"); 615 "deadline_mode", "blocked_on_ready_to_draw");
583 return; 616 return;
584 } 617 }
585 618
586 TRACE_EVENT2("cc", "Scheduler::ScheduleBeginImplFrameDeadline", "mode", 619 TRACE_EVENT2("cc", "Scheduler::ScheduleBeginImplFrameDeadline", "mode",
587 SchedulerStateMachine::BeginImplFrameDeadlineModeToString( 620 SchedulerStateMachine::BeginImplFrameDeadlineModeToString(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 // order to wait for more user-input before starting the next commit. 652 // order to wait for more user-input before starting the next commit.
620 // * Creating a new OuputSurface will not occur during the deadline in 653 // * Creating a new OuputSurface will not occur during the deadline in
621 // order to allow the state machine to "settle" first. 654 // order to allow the state machine to "settle" first.
622 655
623 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is fixed. 656 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is fixed.
624 tracked_objects::ScopedTracker tracking_profile1( 657 tracked_objects::ScopedTracker tracking_profile1(
625 FROM_HERE_WITH_EXPLICIT_FUNCTION( 658 FROM_HERE_WITH_EXPLICIT_FUNCTION(
626 "461509 Scheduler::OnBeginImplFrameDeadline1")); 659 "461509 Scheduler::OnBeginImplFrameDeadline1"));
627 state_machine_.OnBeginImplFrameDeadline(); 660 state_machine_.OnBeginImplFrameDeadline();
628 ProcessScheduledActions(); 661 ProcessScheduledActions();
629 FinishImplFrame(); 662
663 if (state_machine_.retry_begin_impl_frame()) {
664 RetryBeginImplFrameWithDeadline();
665 } else if (state_machine_.retry_begin_impl_frame_deadline()) {
666 RetryBeginImplFrameDeadline();
667 } else {
668 FinishImplFrame();
669 }
630 } 670 }
631 671
632 672
633 void Scheduler::PollToAdvanceCommitState() { 673 void Scheduler::PollToAdvanceCommitState() {
634 TRACE_EVENT0("cc", "Scheduler::PollToAdvanceCommitState"); 674 TRACE_EVENT0("cc", "Scheduler::PollToAdvanceCommitState");
635 advance_commit_state_task_.Cancel(); 675 advance_commit_state_task_.Cancel();
636 ProcessScheduledActions(); 676 ProcessScheduledActions();
637 } 677 }
638 678
639 void Scheduler::DrawAndSwapIfPossible() { 679 void Scheduler::DrawAndSwapIfPossible() {
640 DrawResult result = client_->ScheduledActionDrawAndSwapIfPossible(); 680 DrawResult result = client_->ScheduledActionDrawAndSwapIfPossible();
641 state_machine_.DidDrawIfPossibleCompleted(result); 681 state_machine_.SetDrawResult(result);
682 }
683
684 void Scheduler::DrawAndSwapForced() {
685 DrawResult result = client_->ScheduledActionDrawAndSwapForced();
686 state_machine_.SetDrawResult(result);
642 } 687 }
643 688
644 void Scheduler::SetDeferCommits(bool defer_commits) { 689 void Scheduler::SetDeferCommits(bool defer_commits) {
645 TRACE_EVENT1("cc", "Scheduler::SetDeferCommits", 690 TRACE_EVENT1("cc", "Scheduler::SetDeferCommits",
646 "defer_commits", 691 "defer_commits",
647 defer_commits); 692 defer_commits);
648 state_machine_.SetDeferCommits(defer_commits); 693 state_machine_.SetDeferCommits(defer_commits);
649 ProcessScheduledActions(); 694 ProcessScheduledActions();
650 } 695 }
651 696
652 void Scheduler::ProcessScheduledActions() { 697 void Scheduler::ProcessScheduledActions() {
653 // We do not allow ProcessScheduledActions to be recursive. 698 // We do not allow ProcessScheduledActions to be recursive.
654 // The top-level call will iteratively execute the next action for us anyway. 699 // The top-level call will iteratively execute the next action for us anyway.
655 if (inside_process_scheduled_actions_) 700 if (inside_process_scheduled_actions_)
656 return; 701 return;
657 702
658 base::AutoReset<bool> mark_inside(&inside_process_scheduled_actions_, true); 703 base::AutoReset<bool> mark_inside(&inside_process_scheduled_actions_, true);
659 704
660 SchedulerStateMachine::Action action; 705 SchedulerStateMachine::Action action;
661 do { 706 do {
662 action = state_machine_.NextAction(); 707 action = state_machine_.NextAction();
663 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), 708 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"),
664 "SchedulerStateMachine", 709 "SchedulerStateMachine",
665 "state", 710 "state",
666 AsValue()); 711 AsValue());
667 DVLOG(2) << "Scheduler::ProcessScheduledActions: " 712 DVLOG(2) << "Scheduler::ProcessScheduledActions: "
668 << SchedulerStateMachine::ActionToString(action) << " " 713 << SchedulerStateMachine::ActionToString(action) << " "
669 << state_machine_.GetStatesForDebugging(); 714 << state_machine_.GetStatesForDebugging();
670 state_machine_.UpdateState(action);
671 base::AutoReset<SchedulerStateMachine::Action> 715 base::AutoReset<SchedulerStateMachine::Action>
672 mark_inside_action(&inside_action_, action); 716 mark_inside_action(&inside_action_, action);
717 state_machine_.WillAction(action);
673 switch (action) { 718 switch (action) {
674 case SchedulerStateMachine::ACTION_NONE: 719 case SchedulerStateMachine::ACTION_NONE:
675 break; 720 break;
676 case SchedulerStateMachine::ACTION_ANIMATE: 721 case SchedulerStateMachine::ACTION_ANIMATE:
677 client_->ScheduledActionAnimate(); 722 client_->ScheduledActionAnimate();
678 break; 723 break;
679 case SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME: 724 case SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME:
680 client_->ScheduledActionSendBeginMainFrame(); 725 client_->ScheduledActionSendBeginMainFrame();
681 break; 726 break;
682 case SchedulerStateMachine::ACTION_COMMIT: { 727 case SchedulerStateMachine::ACTION_COMMIT: {
(...skipping 28 matching lines...) Expand all
711 client_->ScheduledActionBeginOutputSurfaceCreation(); 756 client_->ScheduledActionBeginOutputSurfaceCreation();
712 break; 757 break;
713 case SchedulerStateMachine::ACTION_PREPARE_TILES: 758 case SchedulerStateMachine::ACTION_PREPARE_TILES:
714 client_->ScheduledActionPrepareTiles(); 759 client_->ScheduledActionPrepareTiles();
715 break; 760 break;
716 case SchedulerStateMachine::ACTION_INVALIDATE_OUTPUT_SURFACE: { 761 case SchedulerStateMachine::ACTION_INVALIDATE_OUTPUT_SURFACE: {
717 client_->ScheduledActionInvalidateOutputSurface(); 762 client_->ScheduledActionInvalidateOutputSurface();
718 break; 763 break;
719 } 764 }
720 } 765 }
766 state_machine_.DidAction(action);
721 } while (action != SchedulerStateMachine::ACTION_NONE); 767 } while (action != SchedulerStateMachine::ACTION_NONE);
722 768
723 SetupPollingMechanisms(); 769 SetupPollingMechanisms();
724 770
725 client_->DidAnticipatedDrawTimeChange(AnticipatedDrawTime()); 771 client_->DidAnticipatedDrawTimeChange(AnticipatedDrawTime());
726 772
727 ScheduleBeginImplFrameDeadlineIfNeeded(); 773 ScheduleBeginImplFrameDeadlineIfNeeded();
728 774
729 SetupNextBeginFrameIfNeeded(); 775 SetupNextBeginFrameIfNeeded();
730 } 776 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 } 868 }
823 869
824 bool Scheduler::IsBeginMainFrameSentOrStarted() const { 870 bool Scheduler::IsBeginMainFrameSentOrStarted() const {
825 return (state_machine_.commit_state() == 871 return (state_machine_.commit_state() ==
826 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || 872 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT ||
827 state_machine_.commit_state() == 873 state_machine_.commit_state() ==
828 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); 874 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED);
829 } 875 }
830 876
831 } // namespace cc 877 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler.h ('k') | cc/scheduler/scheduler_settings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698