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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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_commit_after_animating_(false), | 46 did_commit_after_animating_(false), |
47 did_create_and_initialize_first_output_surface_(false), | 47 did_create_and_initialize_first_output_surface_(false), |
48 impl_latency_takes_priority_(false), | 48 impl_latency_takes_priority_(false), |
49 skip_next_begin_main_frame_to_reduce_latency_(false), | 49 skip_next_begin_main_frame_to_reduce_latency_(false), |
50 skip_begin_main_frame_to_reduce_latency_(false), | 50 skip_begin_main_frame_to_reduce_latency_(false), |
51 continuous_painting_(false), | 51 continuous_painting_(false), |
52 impl_latency_takes_priority_on_battery_(false) { | 52 impl_latency_takes_priority_on_battery_(false), |
53 children_need_begin_frames_(false) { | |
53 } | 54 } |
54 | 55 |
55 const char* SchedulerStateMachine::OutputSurfaceStateToString( | 56 const char* SchedulerStateMachine::OutputSurfaceStateToString( |
56 OutputSurfaceState state) { | 57 OutputSurfaceState state) { |
57 switch (state) { | 58 switch (state) { |
58 case OUTPUT_SURFACE_ACTIVE: | 59 case OUTPUT_SURFACE_ACTIVE: |
59 return "OUTPUT_SURFACE_ACTIVE"; | 60 return "OUTPUT_SURFACE_ACTIVE"; |
60 case OUTPUT_SURFACE_LOST: | 61 case OUTPUT_SURFACE_LOST: |
61 return "OUTPUT_SURFACE_LOST"; | 62 return "OUTPUT_SURFACE_LOST"; |
62 case OUTPUT_SURFACE_CREATING: | 63 case OUTPUT_SURFACE_CREATING: |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 impl_latency_takes_priority_); | 235 impl_latency_takes_priority_); |
235 state->SetBoolean("main_thread_is_in_high_latency_mode", | 236 state->SetBoolean("main_thread_is_in_high_latency_mode", |
236 MainThreadIsInHighLatencyMode()); | 237 MainThreadIsInHighLatencyMode()); |
237 state->SetBoolean("skip_begin_main_frame_to_reduce_latency", | 238 state->SetBoolean("skip_begin_main_frame_to_reduce_latency", |
238 skip_begin_main_frame_to_reduce_latency_); | 239 skip_begin_main_frame_to_reduce_latency_); |
239 state->SetBoolean("skip_next_begin_main_frame_to_reduce_latency", | 240 state->SetBoolean("skip_next_begin_main_frame_to_reduce_latency", |
240 skip_next_begin_main_frame_to_reduce_latency_); | 241 skip_next_begin_main_frame_to_reduce_latency_); |
241 state->SetBoolean("continuous_painting", continuous_painting_); | 242 state->SetBoolean("continuous_painting", continuous_painting_); |
242 state->SetBoolean("impl_latency_takes_priority_on_battery", | 243 state->SetBoolean("impl_latency_takes_priority_on_battery", |
243 impl_latency_takes_priority_on_battery_); | 244 impl_latency_takes_priority_on_battery_); |
245 state->SetBoolean("children_need_begin_frames", children_need_begin_frames_); | |
244 state->EndDictionary(); | 246 state->EndDictionary(); |
245 } | 247 } |
246 | 248 |
247 void SchedulerStateMachine::AdvanceCurrentFrameNumber() { | 249 void SchedulerStateMachine::AdvanceCurrentFrameNumber() { |
248 current_frame_number_++; | 250 current_frame_number_++; |
249 | 251 |
250 // "Drain" the ManageTiles funnel. | 252 // "Drain" the ManageTiles funnel. |
251 if (manage_tiles_funnel_ > 0) | 253 if (manage_tiles_funnel_ > 0) |
252 manage_tiles_funnel_--; | 254 manage_tiles_funnel_--; |
253 | 255 |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
712 needs_manage_tiles_ = false; | 714 needs_manage_tiles_ = false; |
713 } | 715 } |
714 | 716 |
715 void SchedulerStateMachine::SetSkipNextBeginMainFrameToReduceLatency() { | 717 void SchedulerStateMachine::SetSkipNextBeginMainFrameToReduceLatency() { |
716 TRACE_EVENT_INSTANT0("cc", | 718 TRACE_EVENT_INSTANT0("cc", |
717 "Scheduler: SkipNextBeginMainFrameToReduceLatency", | 719 "Scheduler: SkipNextBeginMainFrameToReduceLatency", |
718 TRACE_EVENT_SCOPE_THREAD); | 720 TRACE_EVENT_SCOPE_THREAD); |
719 skip_next_begin_main_frame_to_reduce_latency_ = true; | 721 skip_next_begin_main_frame_to_reduce_latency_ = true; |
720 } | 722 } |
721 | 723 |
724 bool SchedulerStateMachine::BeginFrameNeededForChildren() const { | |
725 if (!HasInitializedOutputSurface()) | |
726 return false; | |
727 | |
picksi1
2014/11/20 13:43:18
nit: [Background: I'm a fan of keeping !'s out of
simonhong
2014/11/20 16:24:09
Thanks! Looks more readable :)
| |
728 return children_need_begin_frames_; | |
729 } | |
730 | |
722 bool SchedulerStateMachine::BeginFrameNeeded() const { | 731 bool SchedulerStateMachine::BeginFrameNeeded() const { |
723 // Proactive BeginFrames are bad for the synchronous compositor because we | 732 // Proactive BeginFrames are bad for the synchronous compositor because we |
724 // have to draw when we get the BeginFrame and could end up drawing many | 733 // have to draw when we get the BeginFrame and could end up drawing many |
725 // duplicate frames if our new frame isn't ready in time. | 734 // duplicate frames if our new frame isn't ready in time. |
726 // To poll for state with the synchronous compositor without having to draw, | 735 // To poll for state with the synchronous compositor without having to draw, |
727 // we rely on ShouldPollForAnticipatedDrawTriggers instead. | 736 // we rely on ShouldPollForAnticipatedDrawTriggers instead. |
728 if (!SupportsProactiveBeginFrame()) | 737 if (!SupportsProactiveBeginFrame()) { |
738 // Synchronous compositor doesn't have a browser. | |
739 DCHECK(!children_need_begin_frames_); | |
729 return BeginFrameNeededToAnimateOrDraw(); | 740 return BeginFrameNeededToAnimateOrDraw(); |
741 } | |
730 | 742 |
731 return BeginFrameNeededToAnimateOrDraw() || ProactiveBeginFrameWanted(); | 743 return (BeginFrameNeededToAnimateOrDraw() || |
744 BeginFrameNeededForChildren() || | |
745 ProactiveBeginFrameWanted()); | |
picksi1
2014/11/20 13:43:18
The above code is starting to get hairy IMO! Begi
simonhong
2014/11/20 16:24:09
Hmm, I think we can understand more easily by divi
| |
732 } | 746 } |
733 | 747 |
734 bool SchedulerStateMachine::ShouldPollForAnticipatedDrawTriggers() const { | 748 bool SchedulerStateMachine::ShouldPollForAnticipatedDrawTriggers() const { |
735 // ShouldPollForAnticipatedDrawTriggers is what we use in place of | 749 // ShouldPollForAnticipatedDrawTriggers is what we use in place of |
736 // ProactiveBeginFrameWanted when we are using the synchronous | 750 // ProactiveBeginFrameWanted when we are using the synchronous |
737 // compositor. | 751 // compositor. |
738 if (!SupportsProactiveBeginFrame()) { | 752 if (!SupportsProactiveBeginFrame()) { |
739 return !BeginFrameNeededToAnimateOrDraw() && ProactiveBeginFrameWanted(); | 753 return !BeginFrameNeededToAnimateOrDraw() && ProactiveBeginFrameWanted(); |
740 } | 754 } |
741 | 755 |
742 // Non synchronous compositors should rely on | 756 // Non synchronous compositors should rely on |
743 // ProactiveBeginFrameWanted to poll for state instead. | 757 // ProactiveBeginFrameWanted to poll for state instead. |
744 return false; | 758 return false; |
745 } | 759 } |
746 | 760 |
747 // Note: If SupportsProactiveBeginFrame is false, the scheduler should poll | 761 // Note: If SupportsProactiveBeginFrame is false, the scheduler should poll |
748 // for changes in it's draw state so it can request a BeginFrame when it's | 762 // for changes in it's draw state so it can request a BeginFrame when it's |
749 // actually ready. | 763 // actually ready. |
750 bool SchedulerStateMachine::SupportsProactiveBeginFrame() const { | 764 bool SchedulerStateMachine::SupportsProactiveBeginFrame() const { |
751 // It is undesirable to proactively request BeginFrames if we are | 765 // It is undesirable to proactively request BeginFrames if we are |
752 // using a synchronous compositor because we *must* draw for every | 766 // using a synchronous compositor because we *must* draw for every |
753 // BeginFrame, which could cause duplicate draws. | 767 // BeginFrame, which could cause duplicate draws. |
754 return !settings_.using_synchronous_renderer_compositor; | 768 return !settings_.using_synchronous_renderer_compositor; |
755 } | 769 } |
756 | 770 |
771 void SchedulerStateMachine::SetChildrenNeedBeginFrames( | |
772 bool children_need_begin_frames) { | |
773 DCHECK(settings_.forward_begin_frames_to_children); | |
774 children_need_begin_frames_ = children_need_begin_frames; | |
775 } | |
776 | |
757 // These are the cases where we definitely (or almost definitely) have a | 777 // These are the cases where we definitely (or almost definitely) have a |
758 // new frame to animate and/or draw and can draw. | 778 // new frame to animate and/or draw and can draw. |
759 bool SchedulerStateMachine::BeginFrameNeededToAnimateOrDraw() const { | 779 bool SchedulerStateMachine::BeginFrameNeededToAnimateOrDraw() const { |
760 // The output surface is the provider of BeginImplFrames, so we are not going | 780 // The output surface is the provider of BeginImplFrames, so we are not going |
761 // to get them even if we ask for them. | 781 // to get them even if we ask for them. |
762 if (!HasInitializedOutputSurface()) | 782 if (!HasInitializedOutputSurface()) |
763 return false; | 783 return false; |
764 | 784 |
765 // The forced draw respects our normal draw scheduling, so we need to | 785 // The forced draw respects our normal draw scheduling, so we need to |
766 // request a BeginImplFrame for it. | 786 // request a BeginImplFrame for it. |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1101 static_cast<int>(begin_impl_frame_state_), | 1121 static_cast<int>(begin_impl_frame_state_), |
1102 static_cast<int>(commit_state_), | 1122 static_cast<int>(commit_state_), |
1103 has_pending_tree_ ? 'T' : 'F', | 1123 has_pending_tree_ ? 'T' : 'F', |
1104 pending_tree_is_ready_for_activation_ ? 'T' : 'F', | 1124 pending_tree_is_ready_for_activation_ ? 'T' : 'F', |
1105 active_tree_needs_first_draw_ ? 'T' : 'F', | 1125 active_tree_needs_first_draw_ ? 'T' : 'F', |
1106 max_pending_swaps_, | 1126 max_pending_swaps_, |
1107 pending_swaps_); | 1127 pending_swaps_); |
1108 } | 1128 } |
1109 | 1129 |
1110 } // namespace cc | 1130 } // namespace cc |
OLD | NEW |