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