OLD | NEW |
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_state_machine.h" | 5 #include "cc/scheduler/scheduler_state_machine.h" |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 return ACTION_PREPARE_TILES; | 553 return ACTION_PREPARE_TILES; |
554 if (ShouldSendBeginMainFrame()) | 554 if (ShouldSendBeginMainFrame()) |
555 return ACTION_SEND_BEGIN_MAIN_FRAME; | 555 return ACTION_SEND_BEGIN_MAIN_FRAME; |
556 if (ShouldInvalidateOutputSurface()) | 556 if (ShouldInvalidateOutputSurface()) |
557 return ACTION_INVALIDATE_OUTPUT_SURFACE; | 557 return ACTION_INVALIDATE_OUTPUT_SURFACE; |
558 if (ShouldBeginOutputSurfaceCreation()) | 558 if (ShouldBeginOutputSurfaceCreation()) |
559 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; | 559 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; |
560 return ACTION_NONE; | 560 return ACTION_NONE; |
561 } | 561 } |
562 | 562 |
563 void SchedulerStateMachine::UpdateState(Action action) { | 563 void SchedulerStateMachine::WillAnimate() { |
564 switch (action) { | |
565 case ACTION_NONE: | |
566 return; | |
567 | |
568 case ACTION_ACTIVATE_SYNC_TREE: | |
569 UpdateStateOnActivation(); | |
570 return; | |
571 | |
572 case ACTION_ANIMATE: | |
573 UpdateStateOnAnimate(); | |
574 return; | |
575 | |
576 case ACTION_SEND_BEGIN_MAIN_FRAME: | |
577 UpdateStateOnSendBeginMainFrame(); | |
578 return; | |
579 | |
580 case ACTION_COMMIT: { | |
581 bool commit_has_no_updates = false; | |
582 UpdateStateOnCommit(commit_has_no_updates); | |
583 return; | |
584 } | |
585 | |
586 case ACTION_DRAW_AND_SWAP_FORCED: | |
587 case ACTION_DRAW_AND_SWAP_IF_POSSIBLE: { | |
588 bool did_request_swap = true; | |
589 UpdateStateOnDraw(did_request_swap); | |
590 return; | |
591 } | |
592 | |
593 case ACTION_DRAW_AND_SWAP_ABORT: { | |
594 bool did_request_swap = false; | |
595 UpdateStateOnDraw(did_request_swap); | |
596 return; | |
597 } | |
598 | |
599 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION: | |
600 UpdateStateOnBeginOutputSurfaceCreation(); | |
601 return; | |
602 | |
603 case ACTION_PREPARE_TILES: | |
604 UpdateStateOnPrepareTiles(); | |
605 return; | |
606 | |
607 case ACTION_INVALIDATE_OUTPUT_SURFACE: | |
608 UpdateStateOnInvalidateOutputSurface(); | |
609 return; | |
610 } | |
611 } | |
612 | |
613 void SchedulerStateMachine::UpdateStateOnAnimate() { | |
614 DCHECK(!animate_funnel_); | 564 DCHECK(!animate_funnel_); |
615 last_frame_number_animate_performed_ = current_frame_number_; | 565 last_frame_number_animate_performed_ = current_frame_number_; |
616 animate_funnel_ = true; | 566 animate_funnel_ = true; |
617 needs_animate_ = false; | 567 needs_animate_ = false; |
618 // TODO(skyostil): Instead of assuming this, require the client to tell us. | 568 // TODO(skyostil): Instead of assuming this, require the client to tell us. |
619 SetNeedsRedraw(); | 569 SetNeedsRedraw(); |
620 } | 570 } |
621 | 571 |
622 void SchedulerStateMachine::UpdateStateOnSendBeginMainFrame() { | 572 void SchedulerStateMachine::WillSendBeginMainFrame() { |
623 DCHECK(!has_pending_tree_ || settings_.main_frame_before_activation_enabled); | 573 DCHECK(!has_pending_tree_ || settings_.main_frame_before_activation_enabled); |
624 DCHECK(visible_); | 574 DCHECK(visible_); |
625 DCHECK(!send_begin_main_frame_funnel_); | 575 DCHECK(!send_begin_main_frame_funnel_); |
626 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_SENT; | 576 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_SENT; |
627 needs_begin_main_frame_ = false; | 577 needs_begin_main_frame_ = false; |
628 send_begin_main_frame_funnel_ = true; | 578 send_begin_main_frame_funnel_ = true; |
629 last_frame_number_begin_main_frame_sent_ = current_frame_number_; | 579 last_frame_number_begin_main_frame_sent_ = current_frame_number_; |
630 } | 580 } |
631 | 581 |
632 void SchedulerStateMachine::UpdateStateOnCommit(bool commit_has_no_updates) { | 582 void SchedulerStateMachine::WillCommit(bool commit_has_no_updates) { |
633 commit_count_++; | 583 commit_count_++; |
634 | 584 |
635 // Animate after commit even if we've already animated. | 585 // Animate after commit even if we've already animated. |
636 if (!commit_has_no_updates) | 586 if (!commit_has_no_updates) |
637 animate_funnel_ = false; | 587 animate_funnel_ = false; |
638 | 588 |
639 if (commit_has_no_updates || settings_.main_frame_before_activation_enabled) { | 589 if (commit_has_no_updates || settings_.main_frame_before_activation_enabled) { |
640 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_IDLE; | 590 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_IDLE; |
641 } else { | 591 } else { |
642 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_WAITING_FOR_ACTIVATION; | 592 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_WAITING_FOR_ACTIVATION; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 } | 626 } |
677 | 627 |
678 // This post-commit work is common to both completed and aborted commits. | 628 // This post-commit work is common to both completed and aborted commits. |
679 pending_tree_is_ready_for_activation_ = false; | 629 pending_tree_is_ready_for_activation_ = false; |
680 | 630 |
681 if (continuous_painting_) | 631 if (continuous_painting_) |
682 needs_begin_main_frame_ = true; | 632 needs_begin_main_frame_ = true; |
683 last_commit_had_no_updates_ = commit_has_no_updates; | 633 last_commit_had_no_updates_ = commit_has_no_updates; |
684 } | 634 } |
685 | 635 |
686 void SchedulerStateMachine::UpdateStateOnActivation() { | 636 void SchedulerStateMachine::WillActivate() { |
687 if (begin_main_frame_state_ == | 637 if (begin_main_frame_state_ == |
688 BEGIN_MAIN_FRAME_STATE_WAITING_FOR_ACTIVATION) { | 638 BEGIN_MAIN_FRAME_STATE_WAITING_FOR_ACTIVATION) { |
689 begin_main_frame_state_ = settings_.commit_to_active_tree | 639 begin_main_frame_state_ = settings_.commit_to_active_tree |
690 ? BEGIN_MAIN_FRAME_STATE_WAITING_FOR_DRAW | 640 ? BEGIN_MAIN_FRAME_STATE_WAITING_FOR_DRAW |
691 : BEGIN_MAIN_FRAME_STATE_IDLE; | 641 : BEGIN_MAIN_FRAME_STATE_IDLE; |
692 } | 642 } |
693 | 643 |
694 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION) | 644 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION) |
695 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; | 645 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; |
696 | 646 |
697 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION) | 647 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION) |
698 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_DRAW; | 648 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_DRAW; |
699 | 649 |
700 has_pending_tree_ = false; | 650 has_pending_tree_ = false; |
701 pending_tree_is_ready_for_activation_ = false; | 651 pending_tree_is_ready_for_activation_ = false; |
702 active_tree_needs_first_draw_ = true; | 652 active_tree_needs_first_draw_ = true; |
703 needs_redraw_ = true; | 653 needs_redraw_ = true; |
704 } | 654 } |
705 | 655 |
706 void SchedulerStateMachine::UpdateStateOnDraw(bool did_request_swap) { | 656 void SchedulerStateMachine::WillDraw(bool did_request_swap) { |
707 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) | 657 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) |
708 forced_redraw_state_ = FORCED_REDRAW_STATE_IDLE; | 658 forced_redraw_state_ = FORCED_REDRAW_STATE_IDLE; |
709 | 659 |
710 if (begin_main_frame_state_ == BEGIN_MAIN_FRAME_STATE_WAITING_FOR_DRAW) | 660 if (begin_main_frame_state_ == BEGIN_MAIN_FRAME_STATE_WAITING_FOR_DRAW) |
711 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_IDLE; | 661 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_IDLE; |
712 | 662 |
713 needs_redraw_ = false; | 663 needs_redraw_ = false; |
714 active_tree_needs_first_draw_ = false; | 664 active_tree_needs_first_draw_ = false; |
715 | 665 |
716 if (did_request_swap) { | 666 if (did_request_swap) { |
717 DCHECK(!request_swap_funnel_); | 667 DCHECK(!request_swap_funnel_); |
718 request_swap_funnel_ = true; | 668 request_swap_funnel_ = true; |
719 did_request_swap_in_last_frame_ = true; | 669 did_request_swap_in_last_frame_ = true; |
720 last_frame_number_swap_requested_ = current_frame_number_; | 670 last_frame_number_swap_requested_ = current_frame_number_; |
721 } | 671 } |
722 } | 672 } |
723 | 673 |
724 void SchedulerStateMachine::UpdateStateOnPrepareTiles() { | 674 void SchedulerStateMachine::WillPrepareTiles() { |
725 needs_prepare_tiles_ = false; | 675 needs_prepare_tiles_ = false; |
726 } | 676 } |
727 | 677 |
728 void SchedulerStateMachine::UpdateStateOnBeginOutputSurfaceCreation() { | 678 void SchedulerStateMachine::WillBeginOutputSurfaceCreation() { |
729 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_LOST); | 679 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_LOST); |
730 output_surface_state_ = OUTPUT_SURFACE_CREATING; | 680 output_surface_state_ = OUTPUT_SURFACE_CREATING; |
731 | 681 |
732 // The following DCHECKs make sure we are in the proper quiescent state. | 682 // The following DCHECKs make sure we are in the proper quiescent state. |
733 // The pipeline should be flushed entirely before we start output | 683 // The pipeline should be flushed entirely before we start output |
734 // surface creation to avoid complicated corner cases. | 684 // surface creation to avoid complicated corner cases. |
735 DCHECK_EQ(begin_main_frame_state_, BEGIN_MAIN_FRAME_STATE_IDLE); | 685 DCHECK_EQ(begin_main_frame_state_, BEGIN_MAIN_FRAME_STATE_IDLE); |
736 DCHECK(!has_pending_tree_); | 686 DCHECK(!has_pending_tree_); |
737 DCHECK(!active_tree_needs_first_draw_); | 687 DCHECK(!active_tree_needs_first_draw_); |
738 } | 688 } |
739 | 689 |
740 void SchedulerStateMachine::UpdateStateOnInvalidateOutputSurface() { | 690 void SchedulerStateMachine::WillInvalidateOutputSurface() { |
741 DCHECK(!invalidate_output_surface_funnel_); | 691 DCHECK(!invalidate_output_surface_funnel_); |
742 invalidate_output_surface_funnel_ = true; | 692 invalidate_output_surface_funnel_ = true; |
743 last_frame_number_invalidate_output_surface_performed_ = | 693 last_frame_number_invalidate_output_surface_performed_ = |
744 current_frame_number_; | 694 current_frame_number_; |
745 | 695 |
746 // The synchronous compositor makes no guarantees about a draw coming in after | 696 // The synchronous compositor makes no guarantees about a draw coming in after |
747 // an invalidate so clear any flags that would cause the compositor's pipeline | 697 // an invalidate so clear any flags that would cause the compositor's pipeline |
748 // to stall. | 698 // to stall. |
749 active_tree_needs_first_draw_ = false; // blocks commit if true | 699 active_tree_needs_first_draw_ = false; // blocks commit if true |
750 } | 700 } |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1094 DCHECK_EQ(begin_main_frame_state_, BEGIN_MAIN_FRAME_STATE_SENT); | 1044 DCHECK_EQ(begin_main_frame_state_, BEGIN_MAIN_FRAME_STATE_SENT); |
1095 switch (reason) { | 1045 switch (reason) { |
1096 case CommitEarlyOutReason::ABORTED_OUTPUT_SURFACE_LOST: | 1046 case CommitEarlyOutReason::ABORTED_OUTPUT_SURFACE_LOST: |
1097 case CommitEarlyOutReason::ABORTED_NOT_VISIBLE: | 1047 case CommitEarlyOutReason::ABORTED_NOT_VISIBLE: |
1098 case CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT: | 1048 case CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT: |
1099 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_IDLE; | 1049 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_IDLE; |
1100 SetNeedsBeginMainFrame(); | 1050 SetNeedsBeginMainFrame(); |
1101 return; | 1051 return; |
1102 case CommitEarlyOutReason::FINISHED_NO_UPDATES: | 1052 case CommitEarlyOutReason::FINISHED_NO_UPDATES: |
1103 bool commit_has_no_updates = true; | 1053 bool commit_has_no_updates = true; |
1104 UpdateStateOnCommit(commit_has_no_updates); | 1054 WillCommit(commit_has_no_updates); |
1105 return; | 1055 return; |
1106 } | 1056 } |
1107 } | 1057 } |
1108 | 1058 |
1109 void SchedulerStateMachine::DidPrepareTiles() { | 1059 void SchedulerStateMachine::DidPrepareTiles() { |
1110 needs_prepare_tiles_ = false; | 1060 needs_prepare_tiles_ = false; |
1111 // "Fill" the PrepareTiles funnel. | 1061 // "Fill" the PrepareTiles funnel. |
1112 prepare_tiles_funnel_++; | 1062 prepare_tiles_funnel_++; |
1113 } | 1063 } |
1114 | 1064 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1159 case OUTPUT_SURFACE_ACTIVE: | 1109 case OUTPUT_SURFACE_ACTIVE: |
1160 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: | 1110 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: |
1161 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: | 1111 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: |
1162 return true; | 1112 return true; |
1163 } | 1113 } |
1164 NOTREACHED(); | 1114 NOTREACHED(); |
1165 return false; | 1115 return false; |
1166 } | 1116 } |
1167 | 1117 |
1168 } // namespace cc | 1118 } // namespace cc |
OLD | NEW |