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 17 matching lines...) Expand all Loading... | |
28 last_frame_number_begin_main_frame_sent_(-1), | 28 last_frame_number_begin_main_frame_sent_(-1), |
29 last_frame_number_invalidate_output_surface_performed_(-1), | 29 last_frame_number_invalidate_output_surface_performed_(-1), |
30 animate_funnel_(false), | 30 animate_funnel_(false), |
31 request_swap_funnel_(false), | 31 request_swap_funnel_(false), |
32 send_begin_main_frame_funnel_(false), | 32 send_begin_main_frame_funnel_(false), |
33 invalidate_output_surface_funnel_(false), | 33 invalidate_output_surface_funnel_(false), |
34 prepare_tiles_funnel_(0), | 34 prepare_tiles_funnel_(0), |
35 consecutive_checkerboard_animations_(0), | 35 consecutive_checkerboard_animations_(0), |
36 max_pending_swaps_(1), | 36 max_pending_swaps_(1), |
37 pending_swaps_(0), | 37 pending_swaps_(0), |
38 swaps_are_likely_high_latency_(false), | |
39 was_swap_throttled_on_begin_impl_frame_(false), | |
38 needs_redraw_(false), | 40 needs_redraw_(false), |
39 needs_animate_(false), | 41 needs_animate_(false), |
40 needs_prepare_tiles_(false), | 42 needs_prepare_tiles_(false), |
41 needs_commit_(false), | 43 needs_commit_(false), |
42 visible_(false), | 44 visible_(false), |
43 can_start_(false), | 45 can_start_(false), |
44 can_draw_(false), | 46 can_draw_(false), |
45 has_pending_tree_(false), | 47 has_pending_tree_(false), |
46 pending_tree_is_ready_for_activation_(false), | 48 pending_tree_is_ready_for_activation_(false), |
47 active_tree_needs_first_draw_(false), | 49 active_tree_needs_first_draw_(false), |
48 did_create_and_initialize_first_output_surface_(false), | 50 did_create_and_initialize_first_output_surface_(false), |
49 impl_latency_takes_priority_(false), | 51 impl_latency_takes_priority_(false), |
50 skip_next_begin_main_frame_to_reduce_latency_(false), | 52 skip_next_begin_main_frame_to_reduce_latency_(false), |
51 skip_begin_main_frame_to_reduce_latency_(false), | 53 skip_next_swap_to_reduce_latency_(false), |
52 continuous_painting_(false), | 54 continuous_painting_(false), |
53 children_need_begin_frames_(false), | 55 children_need_begin_frames_(false), |
54 defer_commits_(false), | 56 defer_commits_(false), |
55 video_needs_begin_frames_(false), | 57 video_needs_begin_frames_(false), |
56 last_commit_had_no_updates_(false), | 58 last_commit_had_no_updates_(false), |
57 wait_for_active_tree_ready_to_draw_(false), | 59 wait_for_active_tree_ready_to_draw_(false), |
58 did_request_swap_in_last_frame_(false), | 60 did_request_swap_in_last_frame_(false), |
59 did_perform_swap_in_last_draw_(false) { | 61 did_perform_swap_in_last_draw_(false) { |
60 } | 62 } |
61 | 63 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 state->SetBoolean("active_tree_needs_first_draw", | 233 state->SetBoolean("active_tree_needs_first_draw", |
232 active_tree_needs_first_draw_); | 234 active_tree_needs_first_draw_); |
233 state->SetBoolean("wait_for_active_tree_ready_to_draw", | 235 state->SetBoolean("wait_for_active_tree_ready_to_draw", |
234 wait_for_active_tree_ready_to_draw_); | 236 wait_for_active_tree_ready_to_draw_); |
235 state->SetBoolean("did_create_and_initialize_first_output_surface", | 237 state->SetBoolean("did_create_and_initialize_first_output_surface", |
236 did_create_and_initialize_first_output_surface_); | 238 did_create_and_initialize_first_output_surface_); |
237 state->SetBoolean("impl_latency_takes_priority", | 239 state->SetBoolean("impl_latency_takes_priority", |
238 impl_latency_takes_priority_); | 240 impl_latency_takes_priority_); |
239 state->SetBoolean("main_thread_is_in_high_latency_mode", | 241 state->SetBoolean("main_thread_is_in_high_latency_mode", |
240 MainThreadIsInHighLatencyMode()); | 242 MainThreadIsInHighLatencyMode()); |
241 state->SetBoolean("skip_begin_main_frame_to_reduce_latency", | |
242 skip_begin_main_frame_to_reduce_latency_); | |
243 state->SetBoolean("skip_next_begin_main_frame_to_reduce_latency", | 243 state->SetBoolean("skip_next_begin_main_frame_to_reduce_latency", |
244 skip_next_begin_main_frame_to_reduce_latency_); | 244 skip_next_begin_main_frame_to_reduce_latency_); |
245 state->SetBoolean("continuous_painting", continuous_painting_); | 245 state->SetBoolean("continuous_painting", continuous_painting_); |
246 state->SetBoolean("children_need_begin_frames", children_need_begin_frames_); | 246 state->SetBoolean("children_need_begin_frames", children_need_begin_frames_); |
247 state->SetBoolean("video_needs_begin_frames", video_needs_begin_frames_); | 247 state->SetBoolean("video_needs_begin_frames", video_needs_begin_frames_); |
248 state->SetBoolean("defer_commits", defer_commits_); | 248 state->SetBoolean("defer_commits", defer_commits_); |
249 state->SetBoolean("last_commit_had_no_updates", last_commit_had_no_updates_); | 249 state->SetBoolean("last_commit_had_no_updates", last_commit_had_no_updates_); |
250 state->SetBoolean("did_request_swap_in_last_frame", | 250 state->SetBoolean("did_request_swap_in_last_frame", |
251 did_request_swap_in_last_frame_); | 251 did_request_swap_in_last_frame_); |
252 state->SetBoolean("did_perform_swap_in_last_draw", | 252 state->SetBoolean("did_perform_swap_in_last_draw", |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
338 | 338 |
339 // Do not queue too many swaps. | 339 // Do not queue too many swaps. |
340 if (pending_swaps_ >= max_pending_swaps_) | 340 if (pending_swaps_ >= max_pending_swaps_) |
341 return false; | 341 return false; |
342 | 342 |
343 // Except for the cases above, do not draw outside of the BeginImplFrame | 343 // Except for the cases above, do not draw outside of the BeginImplFrame |
344 // deadline. | 344 // deadline. |
345 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) | 345 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) |
346 return false; | 346 return false; |
347 | 347 |
348 // We are intentionally skipping this swap to reduce our latency. | |
349 if (skip_next_swap_to_reduce_latency_) | |
350 return false; | |
351 | |
348 // Only handle forced redraws due to timeouts on the regular deadline. | 352 // Only handle forced redraws due to timeouts on the regular deadline. |
349 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) | 353 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) |
350 return true; | 354 return true; |
351 | 355 |
352 return needs_redraw_; | 356 return needs_redraw_; |
353 } | 357 } |
354 | 358 |
355 bool SchedulerStateMachine::ShouldActivatePendingTree() const { | 359 bool SchedulerStateMachine::ShouldActivatePendingTree() const { |
356 // There is nothing to activate. | 360 // There is nothing to activate. |
357 if (!has_pending_tree_) | 361 if (!has_pending_tree_) |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
440 return false; | 444 return false; |
441 | 445 |
442 // SwapAck throttle the BeginMainFrames unless we just swapped. | 446 // SwapAck throttle the BeginMainFrames unless we just swapped. |
443 // TODO(brianderson): Remove this restriction to improve throughput. | 447 // TODO(brianderson): Remove this restriction to improve throughput. |
444 bool just_swapped_in_deadline = | 448 bool just_swapped_in_deadline = |
445 begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE && | 449 begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE && |
446 did_perform_swap_in_last_draw_; | 450 did_perform_swap_in_last_draw_; |
447 if (pending_swaps_ >= max_pending_swaps_ && !just_swapped_in_deadline) | 451 if (pending_swaps_ >= max_pending_swaps_ && !just_swapped_in_deadline) |
448 return false; | 452 return false; |
449 | 453 |
450 if (skip_begin_main_frame_to_reduce_latency_) | 454 if (skip_next_begin_main_frame_to_reduce_latency_) |
451 return false; | 455 return false; |
452 | 456 |
453 return true; | 457 return true; |
454 } | 458 } |
455 | 459 |
456 bool SchedulerStateMachine::ShouldCommit() const { | 460 bool SchedulerStateMachine::ShouldCommit() const { |
457 if (commit_state_ != COMMIT_STATE_READY_TO_COMMIT) | 461 if (commit_state_ != COMMIT_STATE_READY_TO_COMMIT) |
458 return false; | 462 return false; |
459 | 463 |
460 // We must not finish the commit until the pending tree is free. | 464 // We must not finish the commit until the pending tree is free. |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
720 active_tree_needs_first_draw_ = false; // blocks commit if true | 724 active_tree_needs_first_draw_ = false; // blocks commit if true |
721 } | 725 } |
722 | 726 |
723 void SchedulerStateMachine::SetSkipNextBeginMainFrameToReduceLatency() { | 727 void SchedulerStateMachine::SetSkipNextBeginMainFrameToReduceLatency() { |
724 TRACE_EVENT_INSTANT0("cc", | 728 TRACE_EVENT_INSTANT0("cc", |
725 "Scheduler: SkipNextBeginMainFrameToReduceLatency", | 729 "Scheduler: SkipNextBeginMainFrameToReduceLatency", |
726 TRACE_EVENT_SCOPE_THREAD); | 730 TRACE_EVENT_SCOPE_THREAD); |
727 skip_next_begin_main_frame_to_reduce_latency_ = true; | 731 skip_next_begin_main_frame_to_reduce_latency_ = true; |
728 } | 732 } |
729 | 733 |
734 void SchedulerStateMachine::SetSkipNextSwapToReduceLatency() { | |
735 TRACE_EVENT_INSTANT0("cc", "Scheduler: SetSkipNextSwapToReduceLatency", | |
736 TRACE_EVENT_SCOPE_THREAD); | |
737 // We need to skip both the BeginMainFrame and swap to make sure we | |
738 // don't keep stuffing the pipeline. | |
739 skip_next_swap_to_reduce_latency_ = true; | |
740 skip_next_begin_main_frame_to_reduce_latency_ = true; | |
741 | |
742 // If there are no swap ack's pending to update swaps_are_likely_high_latency | |
743 // later, reset it now. | |
744 // TODO(brianderson): A unittest that fails without this. | |
745 if (!pending_swaps_) | |
sunnyps
2015/05/21 23:42:23
nit: Don't use boolean operators on numeric types.
brianderson
2015/05/22 01:12:53
Done.
| |
746 swaps_are_likely_high_latency_ = false; | |
747 } | |
748 | |
730 bool SchedulerStateMachine::BeginFrameRequiredForChildren() const { | 749 bool SchedulerStateMachine::BeginFrameRequiredForChildren() const { |
731 return children_need_begin_frames_; | 750 return children_need_begin_frames_; |
732 } | 751 } |
733 bool SchedulerStateMachine::BeginFrameNeededForVideo() const { | 752 bool SchedulerStateMachine::BeginFrameNeededForVideo() const { |
734 return video_needs_begin_frames_; | 753 return video_needs_begin_frames_; |
735 } | 754 } |
736 | 755 |
737 bool SchedulerStateMachine::BeginFrameNeeded() const { | 756 bool SchedulerStateMachine::BeginFrameNeeded() const { |
738 // We can't handle BeginFrames when output surface isn't initialized. | 757 // We can't handle BeginFrames when output surface isn't initialized. |
739 // TODO(brianderson): Support output surface creation inside a BeginFrame. | 758 // TODO(brianderson): Support output surface creation inside a BeginFrame. |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
827 | 846 |
828 // Clear funnels for any actions we perform during the frame. | 847 // Clear funnels for any actions we perform during the frame. |
829 animate_funnel_ = false; | 848 animate_funnel_ = false; |
830 send_begin_main_frame_funnel_ = false; | 849 send_begin_main_frame_funnel_ = false; |
831 invalidate_output_surface_funnel_ = false; | 850 invalidate_output_surface_funnel_ = false; |
832 | 851 |
833 // "Drain" the PrepareTiles funnel. | 852 // "Drain" the PrepareTiles funnel. |
834 if (prepare_tiles_funnel_ > 0) | 853 if (prepare_tiles_funnel_ > 0) |
835 prepare_tiles_funnel_--; | 854 prepare_tiles_funnel_--; |
836 | 855 |
837 skip_begin_main_frame_to_reduce_latency_ = | 856 was_swap_throttled_on_begin_impl_frame_ = |
838 skip_next_begin_main_frame_to_reduce_latency_; | 857 pending_swaps_ >= max_pending_swaps_; |
858 swaps_are_likely_high_latency_ = | |
859 swaps_are_likely_high_latency_ || was_swap_throttled_on_begin_impl_frame_; | |
860 | |
839 skip_next_begin_main_frame_to_reduce_latency_ = false; | 861 skip_next_begin_main_frame_to_reduce_latency_ = false; |
862 skip_next_swap_to_reduce_latency_ = false; | |
840 } | 863 } |
841 | 864 |
842 void SchedulerStateMachine::OnBeginImplFrameDeadlinePending() { | 865 void SchedulerStateMachine::OnBeginImplFrameDeadlinePending() { |
843 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME; | 866 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME; |
844 } | 867 } |
845 | 868 |
846 void SchedulerStateMachine::OnBeginImplFrameDeadline() { | 869 void SchedulerStateMachine::OnBeginImplFrameDeadline() { |
847 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE; | 870 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE; |
848 | 871 |
849 did_perform_swap_in_last_draw_ = false; | 872 did_perform_swap_in_last_draw_ = false; |
(...skipping 25 matching lines...) Expand all Loading... | |
875 } else { | 898 } else { |
876 // The impl thread doesn't have anything it wants to draw and we are just | 899 // The impl thread doesn't have anything it wants to draw and we are just |
877 // waiting for a new active tree or we are swap throttled. In short we are | 900 // waiting for a new active tree or we are swap throttled. In short we are |
878 // blocked. | 901 // blocked. |
879 return BEGIN_IMPL_FRAME_DEADLINE_MODE_LATE; | 902 return BEGIN_IMPL_FRAME_DEADLINE_MODE_LATE; |
880 } | 903 } |
881 } | 904 } |
882 | 905 |
883 bool SchedulerStateMachine::ShouldTriggerBeginImplFrameDeadlineImmediately() | 906 bool SchedulerStateMachine::ShouldTriggerBeginImplFrameDeadlineImmediately() |
884 const { | 907 const { |
885 // TODO(brianderson): This should take into account multiple commit sources. | |
886 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME) | 908 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME) |
887 return false; | 909 return false; |
888 | 910 |
889 // If we just forced activation, we should end the deadline right now. | 911 // If we just forced activation, we should end the deadline right now. |
890 if (PendingActivationsShouldBeForced() && !has_pending_tree_) | 912 if (PendingActivationsShouldBeForced() && !has_pending_tree_) |
891 return true; | 913 return true; |
892 | 914 |
915 // We aren't going to draw in the deadline if we want to reduce our latency, | |
916 // so we might as well trigger the deadline immediately. | |
917 if (skip_next_swap_to_reduce_latency_) | |
918 return true; | |
919 | |
893 // SwapAck throttle the deadline since we wont draw and swap anyway. | 920 // SwapAck throttle the deadline since we wont draw and swap anyway. |
894 if (pending_swaps_ >= max_pending_swaps_) | 921 if (pending_swaps_ >= max_pending_swaps_) |
895 return false; | 922 return false; |
896 | 923 |
897 if (active_tree_needs_first_draw_) | 924 if (active_tree_needs_first_draw_) |
898 return true; | 925 return true; |
899 | 926 |
900 if (!needs_redraw_) | 927 if (!needs_redraw_) |
901 return false; | 928 return false; |
902 | 929 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
986 pending_swaps_++; | 1013 pending_swaps_++; |
987 DCHECK_LE(pending_swaps_, max_pending_swaps_); | 1014 DCHECK_LE(pending_swaps_, max_pending_swaps_); |
988 | 1015 |
989 did_perform_swap_in_last_draw_ = true; | 1016 did_perform_swap_in_last_draw_ = true; |
990 last_frame_number_swap_performed_ = current_frame_number_; | 1017 last_frame_number_swap_performed_ = current_frame_number_; |
991 } | 1018 } |
992 | 1019 |
993 void SchedulerStateMachine::DidSwapBuffersComplete() { | 1020 void SchedulerStateMachine::DidSwapBuffersComplete() { |
994 DCHECK_GT(pending_swaps_, 0); | 1021 DCHECK_GT(pending_swaps_, 0); |
995 pending_swaps_--; | 1022 pending_swaps_--; |
1023 | |
1024 // If we just skipped a swap, assume the attempt to reduce latency | |
1025 // was successful. | |
1026 swaps_are_likely_high_latency_ = was_swap_throttled_on_begin_impl_frame_ && | |
1027 !skip_next_swap_to_reduce_latency_; | |
996 } | 1028 } |
997 | 1029 |
998 void SchedulerStateMachine::SetImplLatencyTakesPriority( | 1030 void SchedulerStateMachine::SetImplLatencyTakesPriority( |
999 bool impl_latency_takes_priority) { | 1031 bool impl_latency_takes_priority) { |
1000 impl_latency_takes_priority_ = impl_latency_takes_priority; | 1032 impl_latency_takes_priority_ = impl_latency_takes_priority; |
1001 } | 1033 } |
1002 | 1034 |
1003 void SchedulerStateMachine::DidDrawIfPossibleCompleted(DrawResult result) { | 1035 void SchedulerStateMachine::DidDrawIfPossibleCompleted(DrawResult result) { |
1004 switch (result) { | 1036 switch (result) { |
1005 case INVALID_RESULT: | 1037 case INVALID_RESULT: |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1138 static_cast<int>(begin_impl_frame_state_), | 1170 static_cast<int>(begin_impl_frame_state_), |
1139 static_cast<int>(commit_state_), | 1171 static_cast<int>(commit_state_), |
1140 has_pending_tree_ ? 'T' : 'F', | 1172 has_pending_tree_ ? 'T' : 'F', |
1141 pending_tree_is_ready_for_activation_ ? 'T' : 'F', | 1173 pending_tree_is_ready_for_activation_ ? 'T' : 'F', |
1142 active_tree_needs_first_draw_ ? 'T' : 'F', | 1174 active_tree_needs_first_draw_ ? 'T' : 'F', |
1143 max_pending_swaps_, | 1175 max_pending_swaps_, |
1144 pending_swaps_); | 1176 pending_swaps_); |
1145 } | 1177 } |
1146 | 1178 |
1147 } // namespace cc | 1179 } // namespace cc |
OLD | NEW |