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 29 matching lines...) Expand all Loading... | |
40 visible_(false), | 40 visible_(false), |
41 can_start_(false), | 41 can_start_(false), |
42 can_draw_(false), | 42 can_draw_(false), |
43 has_pending_tree_(false), | 43 has_pending_tree_(false), |
44 pending_tree_is_ready_for_activation_(false), | 44 pending_tree_is_ready_for_activation_(false), |
45 active_tree_needs_first_draw_(false), | 45 active_tree_needs_first_draw_(false), |
46 did_create_and_initialize_first_output_surface_(false), | 46 did_create_and_initialize_first_output_surface_(false), |
47 smoothness_takes_priority_(false), | 47 smoothness_takes_priority_(false), |
48 skip_next_begin_main_frame_to_reduce_latency_(false), | 48 skip_next_begin_main_frame_to_reduce_latency_(false), |
49 skip_begin_main_frame_to_reduce_latency_(false), | 49 skip_begin_main_frame_to_reduce_latency_(false), |
50 continuous_painting_(false) { | 50 continuous_painting_(false), |
51 children_need_begin_frames_(false) { | |
51 } | 52 } |
52 | 53 |
53 const char* SchedulerStateMachine::OutputSurfaceStateToString( | 54 const char* SchedulerStateMachine::OutputSurfaceStateToString( |
54 OutputSurfaceState state) { | 55 OutputSurfaceState state) { |
55 switch (state) { | 56 switch (state) { |
56 case OUTPUT_SURFACE_ACTIVE: | 57 case OUTPUT_SURFACE_ACTIVE: |
57 return "OUTPUT_SURFACE_ACTIVE"; | 58 return "OUTPUT_SURFACE_ACTIVE"; |
58 case OUTPUT_SURFACE_LOST: | 59 case OUTPUT_SURFACE_LOST: |
59 return "OUTPUT_SURFACE_LOST"; | 60 return "OUTPUT_SURFACE_LOST"; |
60 case OUTPUT_SURFACE_CREATING: | 61 case OUTPUT_SURFACE_CREATING: |
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
697 void SchedulerStateMachine::SetSkipNextBeginMainFrameToReduceLatency() { | 698 void SchedulerStateMachine::SetSkipNextBeginMainFrameToReduceLatency() { |
698 skip_next_begin_main_frame_to_reduce_latency_ = true; | 699 skip_next_begin_main_frame_to_reduce_latency_ = true; |
699 } | 700 } |
700 | 701 |
701 bool SchedulerStateMachine::BeginFrameNeeded() const { | 702 bool SchedulerStateMachine::BeginFrameNeeded() const { |
702 // Proactive BeginFrames are bad for the synchronous compositor because we | 703 // Proactive BeginFrames are bad for the synchronous compositor because we |
703 // have to draw when we get the BeginFrame and could end up drawing many | 704 // have to draw when we get the BeginFrame and could end up drawing many |
704 // duplicate frames if our new frame isn't ready in time. | 705 // duplicate frames if our new frame isn't ready in time. |
705 // To poll for state with the synchronous compositor without having to draw, | 706 // To poll for state with the synchronous compositor without having to draw, |
706 // we rely on ShouldPollForAnticipatedDrawTriggers instead. | 707 // we rely on ShouldPollForAnticipatedDrawTriggers instead. |
707 if (!SupportsProactiveBeginFrame()) | 708 if (!SupportsProactiveBeginFrame()) { |
709 DCHECK(!BeginFrameNeededToChildren()); | |
brianderson
2014/09/04 18:45:46
Can you add a comment regarding why we added this
| |
708 return BeginFrameNeededToAnimateOrDraw(); | 710 return BeginFrameNeededToAnimateOrDraw(); |
711 } | |
709 | 712 |
710 return BeginFrameNeededToAnimateOrDraw() || ProactiveBeginFrameWanted(); | 713 return (BeginFrameNeededToAnimateOrDraw() || |
714 BeginFrameNeededToChildren() || | |
715 ProactiveBeginFrameWanted()); | |
711 } | 716 } |
712 | 717 |
713 bool SchedulerStateMachine::ShouldPollForAnticipatedDrawTriggers() const { | 718 bool SchedulerStateMachine::ShouldPollForAnticipatedDrawTriggers() const { |
714 // ShouldPollForAnticipatedDrawTriggers is what we use in place of | 719 // ShouldPollForAnticipatedDrawTriggers is what we use in place of |
715 // ProactiveBeginFrameWanted when we are using the synchronous | 720 // ProactiveBeginFrameWanted when we are using the synchronous |
716 // compositor. | 721 // compositor. |
717 if (!SupportsProactiveBeginFrame()) { | 722 if (!SupportsProactiveBeginFrame()) { |
718 return !BeginFrameNeededToAnimateOrDraw() && ProactiveBeginFrameWanted(); | 723 return !BeginFrameNeededToAnimateOrDraw() && ProactiveBeginFrameWanted(); |
719 } | 724 } |
720 | 725 |
721 // Non synchronous compositors should rely on | 726 // Non synchronous compositors should rely on |
722 // ProactiveBeginFrameWanted to poll for state instead. | 727 // ProactiveBeginFrameWanted to poll for state instead. |
723 return false; | 728 return false; |
724 } | 729 } |
725 | 730 |
726 // Note: If SupportsProactiveBeginFrame is false, the scheduler should poll | 731 // Note: If SupportsProactiveBeginFrame is false, the scheduler should poll |
727 // for changes in it's draw state so it can request a BeginFrame when it's | 732 // for changes in it's draw state so it can request a BeginFrame when it's |
728 // actually ready. | 733 // actually ready. |
729 bool SchedulerStateMachine::SupportsProactiveBeginFrame() const { | 734 bool SchedulerStateMachine::SupportsProactiveBeginFrame() const { |
730 // It is undesirable to proactively request BeginFrames if we are | 735 // It is undesirable to proactively request BeginFrames if we are |
731 // using a synchronous compositor because we *must* draw for every | 736 // using a synchronous compositor because we *must* draw for every |
732 // BeginFrame, which could cause duplicate draws. | 737 // BeginFrame, which could cause duplicate draws. |
733 return !settings_.using_synchronous_renderer_compositor; | 738 return !settings_.using_synchronous_renderer_compositor; |
734 } | 739 } |
735 | 740 |
741 void SchedulerStateMachine::SetChildrenNeedBeginFrames( | |
742 bool children_need_begin_frames) { | |
743 #if !defined(OS_ANDROID) && !defined(OS_MACOSX) | |
brianderson
2014/09/04 18:45:46
We try to avoid platforms-specific defines in cc i
| |
744 DCHECK(settings_.begin_frame_publisher && !settings_.begin_frame_receiver); | |
745 #endif | |
746 children_need_begin_frames_ = children_need_begin_frames; | |
747 } | |
748 | |
736 // These are the cases where we definitely (or almost definitely) have a | 749 // These are the cases where we definitely (or almost definitely) have a |
737 // new frame to animate and/or draw and can draw. | 750 // new frame to animate and/or draw and can draw. |
738 bool SchedulerStateMachine::BeginFrameNeededToAnimateOrDraw() const { | 751 bool SchedulerStateMachine::BeginFrameNeededToAnimateOrDraw() const { |
739 // The output surface is the provider of BeginImplFrames, so we are not going | 752 // The output surface is the provider of BeginImplFrames, so we are not going |
740 // to get them even if we ask for them. | 753 // to get them even if we ask for them. |
741 if (!HasInitializedOutputSurface()) | 754 if (!HasInitializedOutputSurface()) |
742 return false; | 755 return false; |
743 | 756 |
744 // If we can't draw, don't tick until we are notified that we can draw again. | 757 // If we can't draw, don't tick until we are notified that we can draw again. |
745 if (!can_draw_) | 758 if (!can_draw_) |
(...skipping 13 matching lines...) Expand all Loading... | |
759 // additional visible tiles. | 772 // additional visible tiles. |
760 if (swap_used_incomplete_tile_) | 773 if (swap_used_incomplete_tile_) |
761 return true; | 774 return true; |
762 | 775 |
763 if (needs_animate_) | 776 if (needs_animate_) |
764 return true; | 777 return true; |
765 | 778 |
766 return needs_redraw_; | 779 return needs_redraw_; |
767 } | 780 } |
768 | 781 |
782 bool SchedulerStateMachine::BeginFrameNeededToChildren() const { | |
783 if (!HasInitializedOutputSurface()) | |
784 return false; | |
785 | |
786 // If we can't draw, don't tick until we are notified that we can draw again. | |
787 if (!can_draw_) | |
788 return false; | |
789 | |
790 return children_need_begin_frames_; | |
791 } | |
792 | |
769 // These are cases where we are very likely to draw soon, but might not | 793 // These are cases where we are very likely to draw soon, but might not |
770 // actually have a new frame to draw when we receive the next BeginImplFrame. | 794 // actually have a new frame to draw when we receive the next BeginImplFrame. |
771 // Proactively requesting the BeginImplFrame helps hide the round trip latency | 795 // Proactively requesting the BeginImplFrame helps hide the round trip latency |
772 // of the SetNeedsBeginFrame request that has to go to the Browser. | 796 // of the SetNeedsBeginFrame request that has to go to the Browser. |
773 bool SchedulerStateMachine::ProactiveBeginFrameWanted() const { | 797 bool SchedulerStateMachine::ProactiveBeginFrameWanted() const { |
774 // The output surface is the provider of BeginImplFrames, | 798 // The output surface is the provider of BeginImplFrames, |
775 // so we are not going to get them even if we ask for them. | 799 // so we are not going to get them even if we ask for them. |
776 if (!HasInitializedOutputSurface()) | 800 if (!HasInitializedOutputSurface()) |
777 return false; | 801 return false; |
778 | 802 |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1073 case OUTPUT_SURFACE_ACTIVE: | 1097 case OUTPUT_SURFACE_ACTIVE: |
1074 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: | 1098 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: |
1075 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: | 1099 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: |
1076 return true; | 1100 return true; |
1077 } | 1101 } |
1078 NOTREACHED(); | 1102 NOTREACHED(); |
1079 return false; | 1103 return false; |
1080 } | 1104 } |
1081 | 1105 |
1082 } // namespace cc | 1106 } // namespace cc |
OLD | NEW |