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/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/debug/trace_event_argument.h" | 8 #include "base/debug/trace_event_argument.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 DCHECK(!has_pending_tree_ || | 543 DCHECK(!has_pending_tree_ || |
544 settings_.main_frame_before_activation_enabled); | 544 settings_.main_frame_before_activation_enabled); |
545 DCHECK(visible_); | 545 DCHECK(visible_); |
546 commit_state_ = COMMIT_STATE_BEGIN_MAIN_FRAME_SENT; | 546 commit_state_ = COMMIT_STATE_BEGIN_MAIN_FRAME_SENT; |
547 needs_commit_ = false; | 547 needs_commit_ = false; |
548 last_frame_number_begin_main_frame_sent_ = | 548 last_frame_number_begin_main_frame_sent_ = |
549 current_frame_number_; | 549 current_frame_number_; |
550 return; | 550 return; |
551 | 551 |
552 case ACTION_COMMIT: { | 552 case ACTION_COMMIT: { |
553 bool commit_was_aborted = false; | 553 bool commit_has_no_updates = false; |
554 UpdateStateOnCommit(commit_was_aborted); | 554 UpdateStateOnCommit(commit_has_no_updates); |
555 return; | 555 return; |
556 } | 556 } |
557 | 557 |
558 case ACTION_DRAW_AND_SWAP_FORCED: | 558 case ACTION_DRAW_AND_SWAP_FORCED: |
559 case ACTION_DRAW_AND_SWAP_IF_POSSIBLE: { | 559 case ACTION_DRAW_AND_SWAP_IF_POSSIBLE: { |
560 bool did_request_swap = true; | 560 bool did_request_swap = true; |
561 UpdateStateOnDraw(did_request_swap); | 561 UpdateStateOnDraw(did_request_swap); |
562 return; | 562 return; |
563 } | 563 } |
564 | 564 |
(...skipping 14 matching lines...) Expand all Loading... |
579 DCHECK(!has_pending_tree_); | 579 DCHECK(!has_pending_tree_); |
580 DCHECK(!active_tree_needs_first_draw_); | 580 DCHECK(!active_tree_needs_first_draw_); |
581 return; | 581 return; |
582 | 582 |
583 case ACTION_PREPARE_TILES: | 583 case ACTION_PREPARE_TILES: |
584 UpdateStateOnPrepareTiles(); | 584 UpdateStateOnPrepareTiles(); |
585 return; | 585 return; |
586 } | 586 } |
587 } | 587 } |
588 | 588 |
589 void SchedulerStateMachine::UpdateStateOnCommit(bool commit_was_aborted) { | 589 void SchedulerStateMachine::UpdateStateOnCommit(bool commit_has_no_updates) { |
590 commit_count_++; | 590 commit_count_++; |
591 | 591 |
592 if (!commit_was_aborted && HasAnimatedThisFrame()) | 592 if (!commit_has_no_updates && HasAnimatedThisFrame()) |
593 did_commit_after_animating_ = true; | 593 did_commit_after_animating_ = true; |
594 | 594 |
595 if (commit_was_aborted || settings_.main_frame_before_activation_enabled) { | 595 if (commit_has_no_updates || settings_.main_frame_before_activation_enabled) { |
596 commit_state_ = COMMIT_STATE_IDLE; | 596 commit_state_ = COMMIT_STATE_IDLE; |
597 } else if (settings_.impl_side_painting) { | 597 } else if (settings_.impl_side_painting) { |
598 commit_state_ = COMMIT_STATE_WAITING_FOR_ACTIVATION; | 598 commit_state_ = COMMIT_STATE_WAITING_FOR_ACTIVATION; |
599 } else { | 599 } else { |
600 commit_state_ = settings_.main_thread_should_always_be_low_latency | 600 commit_state_ = settings_.main_thread_should_always_be_low_latency |
601 ? COMMIT_STATE_WAITING_FOR_DRAW | 601 ? COMMIT_STATE_WAITING_FOR_DRAW |
602 : COMMIT_STATE_IDLE; | 602 : COMMIT_STATE_IDLE; |
603 } | 603 } |
604 | 604 |
605 // If we are impl-side-painting but the commit was aborted, then we behave | 605 // If we are impl-side-painting but the commit was aborted, then we behave |
606 // mostly as if we are not impl-side-painting since there is no pending tree. | 606 // mostly as if we are not impl-side-painting since there is no pending tree. |
607 has_pending_tree_ = settings_.impl_side_painting && !commit_was_aborted; | 607 has_pending_tree_ = settings_.impl_side_painting && !commit_has_no_updates; |
608 | 608 |
609 // Update state related to forced draws. | 609 // Update state related to forced draws. |
610 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT) { | 610 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT) { |
611 forced_redraw_state_ = has_pending_tree_ | 611 forced_redraw_state_ = has_pending_tree_ |
612 ? FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION | 612 ? FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION |
613 : FORCED_REDRAW_STATE_WAITING_FOR_DRAW; | 613 : FORCED_REDRAW_STATE_WAITING_FOR_DRAW; |
614 } | 614 } |
615 | 615 |
616 // Update the output surface state. | 616 // Update the output surface state. |
617 DCHECK_NE(output_surface_state_, OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION); | 617 DCHECK_NE(output_surface_state_, OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION); |
618 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT) { | 618 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT) { |
619 if (has_pending_tree_) { | 619 if (has_pending_tree_) { |
620 output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION; | 620 output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION; |
621 } else { | 621 } else { |
622 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; | 622 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; |
623 needs_redraw_ = true; | 623 needs_redraw_ = true; |
624 } | 624 } |
625 } | 625 } |
626 | 626 |
627 // Update state if we have a new active tree to draw, or if the active tree | 627 // Update state if we have a new active tree to draw, or if the active tree |
628 // was unchanged but we need to do a forced draw. | 628 // was unchanged but we need to do a forced draw. |
629 if (!has_pending_tree_ && | 629 if (!has_pending_tree_ && |
630 (!commit_was_aborted || | 630 (!commit_has_no_updates || |
631 forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW)) { | 631 forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW)) { |
632 needs_redraw_ = true; | 632 needs_redraw_ = true; |
633 active_tree_needs_first_draw_ = true; | 633 active_tree_needs_first_draw_ = true; |
634 } | 634 } |
635 | 635 |
636 // This post-commit work is common to both completed and aborted commits. | 636 // This post-commit work is common to both completed and aborted commits. |
637 pending_tree_is_ready_for_activation_ = false; | 637 pending_tree_is_ready_for_activation_ = false; |
638 | 638 |
639 if (continuous_painting_) | 639 if (continuous_painting_) |
640 needs_commit_ = true; | 640 needs_commit_ = true; |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1018 DCHECK(commit_state_ == COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED) | 1018 DCHECK(commit_state_ == COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED) |
1019 << AsValue()->ToString(); | 1019 << AsValue()->ToString(); |
1020 commit_state_ = COMMIT_STATE_READY_TO_COMMIT; | 1020 commit_state_ = COMMIT_STATE_READY_TO_COMMIT; |
1021 // In main thread low latency mode, commit should happen right after | 1021 // In main thread low latency mode, commit should happen right after |
1022 // BeginFrame, meaning when this function is called, next action should be | 1022 // BeginFrame, meaning when this function is called, next action should be |
1023 // commit. | 1023 // commit. |
1024 if (settings_.main_thread_should_always_be_low_latency) | 1024 if (settings_.main_thread_should_always_be_low_latency) |
1025 DCHECK(ShouldCommit()); | 1025 DCHECK(ShouldCommit()); |
1026 } | 1026 } |
1027 | 1027 |
1028 void SchedulerStateMachine::BeginMainFrameAborted(bool did_handle) { | 1028 void SchedulerStateMachine::BeginMainFrameAborted(CommitEarlyOutReason reason) { |
1029 DCHECK_EQ(commit_state_, COMMIT_STATE_BEGIN_MAIN_FRAME_SENT); | 1029 DCHECK_EQ(commit_state_, COMMIT_STATE_BEGIN_MAIN_FRAME_SENT); |
1030 if (did_handle) { | 1030 switch (reason) { |
1031 bool commit_was_aborted = true; | 1031 case CommitEarlyOutReason::ABORTED_OUTPUT_SURFACE_LOST: |
1032 UpdateStateOnCommit(commit_was_aborted); | 1032 case CommitEarlyOutReason::ABORTED_NOT_VISIBLE: |
1033 } else { | 1033 commit_state_ = COMMIT_STATE_IDLE; |
1034 commit_state_ = COMMIT_STATE_IDLE; | 1034 SetNeedsCommit(); |
1035 SetNeedsCommit(); | 1035 return; |
| 1036 case CommitEarlyOutReason::FINISHED_NO_UPDATES: |
| 1037 bool commit_has_no_updates = true; |
| 1038 UpdateStateOnCommit(commit_has_no_updates); |
| 1039 return; |
1036 } | 1040 } |
1037 } | 1041 } |
1038 | 1042 |
1039 void SchedulerStateMachine::DidPrepareTiles() { | 1043 void SchedulerStateMachine::DidPrepareTiles() { |
1040 needs_prepare_tiles_ = false; | 1044 needs_prepare_tiles_ = false; |
1041 // "Fill" the PrepareTiles funnel. | 1045 // "Fill" the PrepareTiles funnel. |
1042 prepare_tiles_funnel_++; | 1046 prepare_tiles_funnel_++; |
1043 } | 1047 } |
1044 | 1048 |
1045 void SchedulerStateMachine::DidLoseOutputSurface() { | 1049 void SchedulerStateMachine::DidLoseOutputSurface() { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1095 static_cast<int>(begin_impl_frame_state_), | 1099 static_cast<int>(begin_impl_frame_state_), |
1096 static_cast<int>(commit_state_), | 1100 static_cast<int>(commit_state_), |
1097 has_pending_tree_ ? 'T' : 'F', | 1101 has_pending_tree_ ? 'T' : 'F', |
1098 pending_tree_is_ready_for_activation_ ? 'T' : 'F', | 1102 pending_tree_is_ready_for_activation_ ? 'T' : 'F', |
1099 active_tree_needs_first_draw_ ? 'T' : 'F', | 1103 active_tree_needs_first_draw_ ? 'T' : 'F', |
1100 max_pending_swaps_, | 1104 max_pending_swaps_, |
1101 pending_swaps_); | 1105 pending_swaps_); |
1102 } | 1106 } |
1103 | 1107 |
1104 } // namespace cc | 1108 } // namespace cc |
OLD | NEW |