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 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
708 current_frame_number_; | 708 current_frame_number_; |
709 } | 709 } |
710 | 710 |
711 void SchedulerStateMachine::SetSkipNextBeginMainFrameToReduceLatency() { | 711 void SchedulerStateMachine::SetSkipNextBeginMainFrameToReduceLatency() { |
712 TRACE_EVENT_INSTANT0("cc", | 712 TRACE_EVENT_INSTANT0("cc", |
713 "Scheduler: SkipNextBeginMainFrameToReduceLatency", | 713 "Scheduler: SkipNextBeginMainFrameToReduceLatency", |
714 TRACE_EVENT_SCOPE_THREAD); | 714 TRACE_EVENT_SCOPE_THREAD); |
715 skip_next_begin_main_frame_to_reduce_latency_ = true; | 715 skip_next_begin_main_frame_to_reduce_latency_ = true; |
716 } | 716 } |
717 | 717 |
718 bool SchedulerStateMachine::BeginFrameNeededForChildren() const { | 718 bool SchedulerStateMachine::BeginFrameRequiredForChildren() const { |
719 return children_need_begin_frames_; | 719 return children_need_begin_frames_; |
720 } | 720 } |
721 | 721 |
722 bool SchedulerStateMachine::BeginFrameNeeded() const { | 722 bool SchedulerStateMachine::BeginFrameNeeded() const { |
723 // We can't handle BeginFrames when output surface isn't initialized. | 723 // We can't handle BeginFrames when output surface isn't initialized. |
724 // TODO(brianderson): Support output surface creation inside a BeginFrame. | 724 // TODO(brianderson): Support output surface creation inside a BeginFrame. |
725 if (!HasInitializedOutputSurface()) | 725 if (!HasInitializedOutputSurface()) |
726 return false; | 726 return false; |
727 return (BeginFrameNeededToAnimateOrDraw() || BeginFrameNeededForChildren() || | 727 return (BeginFrameRequiredForAction() || BeginFrameRequiredForChildren() || |
brianderson
2015/04/08 01:46:56
Should we put BeginFrameRequiredForChildren above
mithro-old
2015/04/09 04:08:07
I'll do that in a different CL.
| |
728 ProactiveBeginFrameWanted()); | 728 ProactiveBeginFrameWanted()); |
729 } | 729 } |
730 | 730 |
731 void SchedulerStateMachine::SetChildrenNeedBeginFrames( | 731 void SchedulerStateMachine::SetChildrenNeedBeginFrames( |
732 bool children_need_begin_frames) { | 732 bool children_need_begin_frames) { |
733 children_need_begin_frames_ = children_need_begin_frames; | 733 children_need_begin_frames_ = children_need_begin_frames; |
734 } | 734 } |
735 | 735 |
736 void SchedulerStateMachine::SetDeferCommits(bool defer_commits) { | 736 void SchedulerStateMachine::SetDeferCommits(bool defer_commits) { |
737 defer_commits_ = defer_commits; | 737 defer_commits_ = defer_commits; |
738 } | 738 } |
739 | 739 |
740 // These are the cases where we definitely (or almost definitely) have a | 740 // These are the cases where we require a BeginFrame message to make progress |
741 // new frame to animate and/or draw and can draw. | 741 // on requested actions. |
742 bool SchedulerStateMachine::BeginFrameNeededToAnimateOrDraw() const { | 742 bool SchedulerStateMachine::BeginFrameRequiredForAction() const { |
743 // If we are not visible, we don't need BeginFrame messages. | 743 // If we are not visible, we don't need BeginFrame messages. |
744 if (!visible_) | 744 if (!visible_) |
745 return false; | 745 return false; |
746 | 746 |
747 // The forced draw respects our normal draw scheduling, so we need to | 747 // The forced draw respects our normal draw scheduling, so we need to |
748 // request a BeginImplFrame for it. | 748 // request a BeginImplFrame for it. |
749 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) | 749 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) |
750 return true; | 750 return true; |
751 | 751 |
752 return needs_animate_ || needs_redraw_; | 752 return needs_animate_ || needs_redraw_ || (needs_commit_ && !defer_commits_); |
753 } | 753 } |
754 | 754 |
755 // These are cases where we are very likely to draw soon, but might not | 755 // These are cases where we are very likely want a BeginFrame message in the |
756 // actually have a new frame to draw when we receive the next BeginImplFrame. | 756 // near future. Proactively requesting the BeginImplFrame helps hide the round |
757 // Proactively requesting the BeginImplFrame helps hide the round trip latency | 757 // trip latency of the SetNeedsBeginFrame request that has to go to the |
758 // of the SetNeedsBeginFrame request that has to go to the Browser. | 758 // Browser. |
759 // This includes things like drawing soon, but might not actually have a new | |
760 // frame to draw when we receive the next BeginImplFrame. | |
759 bool SchedulerStateMachine::ProactiveBeginFrameWanted() const { | 761 bool SchedulerStateMachine::ProactiveBeginFrameWanted() const { |
760 // Do not be proactive when invisible. | 762 // Do not be proactive when invisible. |
761 if (!visible_) | 763 if (!visible_) |
762 return false; | 764 return false; |
763 | 765 |
764 // We should proactively request a BeginImplFrame if a commit is pending | 766 // We should proactively request a BeginImplFrame if a commit is pending |
765 // because we will want to draw if the commit completes quickly. Do not | 767 // because we will want to draw if the commit completes quickly. Do not |
766 // request frames when commits are disabled, because the frame requests will | 768 // request frames when commits are disabled, because the frame requests will |
767 // not provide the needed commit (and will wake up the process when it could | 769 // not provide the needed commit (and will wake up the process when it could |
768 // stay idle). | 770 // stay idle). |
769 if ((needs_commit_ || commit_state_ != COMMIT_STATE_IDLE) && !defer_commits_) | 771 if ((commit_state_ != COMMIT_STATE_IDLE) && !defer_commits_) |
770 return true; | 772 return true; |
771 | 773 |
772 // If the pending tree activates quickly, we'll want a BeginImplFrame soon | 774 // If the pending tree activates quickly, we'll want a BeginImplFrame soon |
773 // to draw the new active tree. | 775 // to draw the new active tree. |
774 if (has_pending_tree_) | 776 if (has_pending_tree_) |
775 return true; | 777 return true; |
776 | 778 |
777 // Changing priorities may allow us to activate (given the new priorities), | 779 // Changing priorities may allow us to activate (given the new priorities), |
778 // which may result in a new frame. | 780 // which may result in a new frame. |
779 if (needs_prepare_tiles_) | 781 if (needs_prepare_tiles_) |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1102 static_cast<int>(begin_impl_frame_state_), | 1104 static_cast<int>(begin_impl_frame_state_), |
1103 static_cast<int>(commit_state_), | 1105 static_cast<int>(commit_state_), |
1104 has_pending_tree_ ? 'T' : 'F', | 1106 has_pending_tree_ ? 'T' : 'F', |
1105 pending_tree_is_ready_for_activation_ ? 'T' : 'F', | 1107 pending_tree_is_ready_for_activation_ ? 'T' : 'F', |
1106 active_tree_needs_first_draw_ ? 'T' : 'F', | 1108 active_tree_needs_first_draw_ ? 'T' : 'F', |
1107 max_pending_swaps_, | 1109 max_pending_swaps_, |
1108 pending_swaps_); | 1110 pending_swaps_); |
1109 } | 1111 } |
1110 | 1112 |
1111 } // namespace cc | 1113 } // namespace cc |
OLD | NEW |