| 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 30 matching lines...) Expand all Loading... |
| 41 needs_commit_(false), | 41 needs_commit_(false), |
| 42 visible_(false), | 42 visible_(false), |
| 43 can_start_(false), | 43 can_start_(false), |
| 44 can_draw_(false), | 44 can_draw_(false), |
| 45 has_pending_tree_(false), | 45 has_pending_tree_(false), |
| 46 pending_tree_is_ready_for_activation_(false), | 46 pending_tree_is_ready_for_activation_(false), |
| 47 active_tree_needs_first_draw_(false), | 47 active_tree_needs_first_draw_(false), |
| 48 did_create_and_initialize_first_output_surface_(false), | 48 did_create_and_initialize_first_output_surface_(false), |
| 49 impl_latency_takes_priority_(false), | 49 impl_latency_takes_priority_(false), |
| 50 skip_next_begin_main_frame_to_reduce_latency_(false), | 50 skip_next_begin_main_frame_to_reduce_latency_(false), |
| 51 skip_begin_main_frame_to_reduce_latency_(false), | |
| 52 continuous_painting_(false), | 51 continuous_painting_(false), |
| 53 children_need_begin_frames_(false), | 52 children_need_begin_frames_(false), |
| 54 defer_commits_(false), | 53 defer_commits_(false), |
| 55 video_needs_begin_frames_(false), | 54 video_needs_begin_frames_(false), |
| 56 last_commit_had_no_updates_(false), | 55 last_commit_had_no_updates_(false), |
| 57 wait_for_active_tree_ready_to_draw_(false), | 56 wait_for_active_tree_ready_to_draw_(false), |
| 58 did_request_swap_in_last_frame_(false), | 57 did_request_swap_in_last_frame_(false), |
| 59 did_perform_swap_in_last_draw_(false) { | 58 did_perform_swap_in_last_draw_(false) { |
| 60 } | 59 } |
| 61 | 60 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 state->SetBoolean("active_tree_needs_first_draw", | 230 state->SetBoolean("active_tree_needs_first_draw", |
| 232 active_tree_needs_first_draw_); | 231 active_tree_needs_first_draw_); |
| 233 state->SetBoolean("wait_for_active_tree_ready_to_draw", | 232 state->SetBoolean("wait_for_active_tree_ready_to_draw", |
| 234 wait_for_active_tree_ready_to_draw_); | 233 wait_for_active_tree_ready_to_draw_); |
| 235 state->SetBoolean("did_create_and_initialize_first_output_surface", | 234 state->SetBoolean("did_create_and_initialize_first_output_surface", |
| 236 did_create_and_initialize_first_output_surface_); | 235 did_create_and_initialize_first_output_surface_); |
| 237 state->SetBoolean("impl_latency_takes_priority", | 236 state->SetBoolean("impl_latency_takes_priority", |
| 238 impl_latency_takes_priority_); | 237 impl_latency_takes_priority_); |
| 239 state->SetBoolean("main_thread_is_in_high_latency_mode", | 238 state->SetBoolean("main_thread_is_in_high_latency_mode", |
| 240 MainThreadIsInHighLatencyMode()); | 239 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", | 240 state->SetBoolean("skip_next_begin_main_frame_to_reduce_latency", |
| 244 skip_next_begin_main_frame_to_reduce_latency_); | 241 skip_next_begin_main_frame_to_reduce_latency_); |
| 245 state->SetBoolean("continuous_painting", continuous_painting_); | 242 state->SetBoolean("continuous_painting", continuous_painting_); |
| 246 state->SetBoolean("children_need_begin_frames", children_need_begin_frames_); | 243 state->SetBoolean("children_need_begin_frames", children_need_begin_frames_); |
| 247 state->SetBoolean("video_needs_begin_frames", video_needs_begin_frames_); | 244 state->SetBoolean("video_needs_begin_frames", video_needs_begin_frames_); |
| 248 state->SetBoolean("defer_commits", defer_commits_); | 245 state->SetBoolean("defer_commits", defer_commits_); |
| 249 state->SetBoolean("last_commit_had_no_updates", last_commit_had_no_updates_); | 246 state->SetBoolean("last_commit_had_no_updates", last_commit_had_no_updates_); |
| 250 state->SetBoolean("did_request_swap_in_last_frame", | 247 state->SetBoolean("did_request_swap_in_last_frame", |
| 251 did_request_swap_in_last_frame_); | 248 did_request_swap_in_last_frame_); |
| 252 state->SetBoolean("did_perform_swap_in_last_draw", | 249 state->SetBoolean("did_perform_swap_in_last_draw", |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 // potentially improve impl-thread latency over main-thread throughput. | 464 // potentially improve impl-thread latency over main-thread throughput. |
| 468 // TODO(brianderson): Remove this restriction to improve throughput or | 465 // TODO(brianderson): Remove this restriction to improve throughput or |
| 469 // make it conditional on impl_latency_takes_priority_. | 466 // make it conditional on impl_latency_takes_priority_. |
| 470 bool just_swapped_in_deadline = | 467 bool just_swapped_in_deadline = |
| 471 begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE && | 468 begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE && |
| 472 did_perform_swap_in_last_draw_; | 469 did_perform_swap_in_last_draw_; |
| 473 if (pending_swaps_ >= max_pending_swaps_ && !just_swapped_in_deadline) | 470 if (pending_swaps_ >= max_pending_swaps_ && !just_swapped_in_deadline) |
| 474 return false; | 471 return false; |
| 475 } | 472 } |
| 476 | 473 |
| 477 if (skip_begin_main_frame_to_reduce_latency_) | 474 if (skip_next_begin_main_frame_to_reduce_latency_) |
| 478 return false; | 475 return false; |
| 479 | 476 |
| 480 return true; | 477 return true; |
| 481 } | 478 } |
| 482 | 479 |
| 483 bool SchedulerStateMachine::ShouldCommit() const { | 480 bool SchedulerStateMachine::ShouldCommit() const { |
| 484 if (commit_state_ != COMMIT_STATE_READY_TO_COMMIT) | 481 if (commit_state_ != COMMIT_STATE_READY_TO_COMMIT) |
| 485 return false; | 482 return false; |
| 486 | 483 |
| 487 // We must not finish the commit until the pending tree is free. | 484 // We must not finish the commit until the pending tree is free. |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 did_request_swap_in_last_frame_ = false; | 853 did_request_swap_in_last_frame_ = false; |
| 857 | 854 |
| 858 // Clear funnels for any actions we perform during the frame. | 855 // Clear funnels for any actions we perform during the frame. |
| 859 animate_funnel_ = false; | 856 animate_funnel_ = false; |
| 860 send_begin_main_frame_funnel_ = false; | 857 send_begin_main_frame_funnel_ = false; |
| 861 invalidate_output_surface_funnel_ = false; | 858 invalidate_output_surface_funnel_ = false; |
| 862 | 859 |
| 863 // "Drain" the PrepareTiles funnel. | 860 // "Drain" the PrepareTiles funnel. |
| 864 if (prepare_tiles_funnel_ > 0) | 861 if (prepare_tiles_funnel_ > 0) |
| 865 prepare_tiles_funnel_--; | 862 prepare_tiles_funnel_--; |
| 866 | |
| 867 skip_begin_main_frame_to_reduce_latency_ = | |
| 868 skip_next_begin_main_frame_to_reduce_latency_; | |
| 869 skip_next_begin_main_frame_to_reduce_latency_ = false; | |
| 870 } | 863 } |
| 871 | 864 |
| 872 void SchedulerStateMachine::OnBeginImplFrameDeadlinePending() { | 865 void SchedulerStateMachine::OnBeginImplFrameDeadlinePending() { |
| 873 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME; | 866 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME; |
| 874 } | 867 } |
| 875 | 868 |
| 876 void SchedulerStateMachine::OnBeginImplFrameDeadline() { | 869 void SchedulerStateMachine::OnBeginImplFrameDeadline() { |
| 877 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE; | 870 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE; |
| 878 | 871 |
| 879 did_perform_swap_in_last_draw_ = false; | 872 did_perform_swap_in_last_draw_ = false; |
| 880 | 873 |
| 881 // Clear funnels for any actions we perform during the deadline. | 874 // Clear funnels for any actions we perform during the deadline. |
| 882 request_swap_funnel_ = false; | 875 request_swap_funnel_ = false; |
| 883 } | 876 } |
| 884 | 877 |
| 885 void SchedulerStateMachine::OnBeginImplFrameIdle() { | 878 void SchedulerStateMachine::OnBeginImplFrameIdle() { |
| 886 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_IDLE; | 879 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_IDLE; |
| 880 |
| 881 skip_next_begin_main_frame_to_reduce_latency_ = false; |
| 887 } | 882 } |
| 888 | 883 |
| 889 SchedulerStateMachine::BeginImplFrameDeadlineMode | 884 SchedulerStateMachine::BeginImplFrameDeadlineMode |
| 890 SchedulerStateMachine::CurrentBeginImplFrameDeadlineMode() const { | 885 SchedulerStateMachine::CurrentBeginImplFrameDeadlineMode() const { |
| 891 if (settings_.using_synchronous_renderer_compositor) { | 886 if (settings_.using_synchronous_renderer_compositor) { |
| 892 // No deadline for synchronous compositor. | 887 // No deadline for synchronous compositor. |
| 893 return BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE; | 888 return BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE; |
| 894 } else if (wait_for_active_tree_ready_to_draw_) { | 889 } else if (wait_for_active_tree_ready_to_draw_) { |
| 895 // When we are waiting for ready to draw signal, we do not wait to post a | 890 // When we are waiting for ready to draw signal, we do not wait to post a |
| 896 // deadline yet. | 891 // deadline yet. |
| 897 return BEGIN_IMPL_FRAME_DEADLINE_MODE_BLOCKED_ON_READY_TO_DRAW; | 892 return BEGIN_IMPL_FRAME_DEADLINE_MODE_BLOCKED_ON_READY_TO_DRAW; |
| 898 } else if (ShouldTriggerBeginImplFrameDeadlineImmediately()) { | 893 } else if (ShouldTriggerBeginImplFrameDeadlineImmediately()) { |
| 899 return BEGIN_IMPL_FRAME_DEADLINE_MODE_IMMEDIATE; | 894 return BEGIN_IMPL_FRAME_DEADLINE_MODE_IMMEDIATE; |
| 900 } else if (needs_redraw_ && pending_swaps_ < max_pending_swaps_) { | 895 } else if (needs_redraw_ && pending_swaps_ < max_pending_swaps_) { |
| 901 // We have an animation or fast input path on the impl thread that wants | 896 // We have an animation or fast input path on the impl thread that wants |
| 902 // to draw, so don't wait too long for a new active tree. | 897 // to draw, so don't wait too long for a new active tree. |
| 903 // If we are swap throttled we should wait until we are unblocked. | 898 // If we are swap throttled we should wait until we are unblocked. |
| 904 return BEGIN_IMPL_FRAME_DEADLINE_MODE_REGULAR; | 899 return BEGIN_IMPL_FRAME_DEADLINE_MODE_REGULAR; |
| 905 } else { | 900 } else { |
| 906 // The impl thread doesn't have anything it wants to draw and we are just | 901 // The impl thread doesn't have anything it wants to draw and we are just |
| 907 // waiting for a new active tree or we are swap throttled. In short we are | 902 // waiting for a new active tree or we are swap throttled. In short we are |
| 908 // blocked. | 903 // blocked. |
| 909 return BEGIN_IMPL_FRAME_DEADLINE_MODE_LATE; | 904 return BEGIN_IMPL_FRAME_DEADLINE_MODE_LATE; |
| 910 } | 905 } |
| 911 } | 906 } |
| 912 | 907 |
| 913 bool SchedulerStateMachine::ShouldTriggerBeginImplFrameDeadlineImmediately() | 908 bool SchedulerStateMachine::ShouldTriggerBeginImplFrameDeadlineImmediately() |
| 914 const { | 909 const { |
| 915 // TODO(brianderson): This should take into account multiple commit sources. | |
| 916 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME) | 910 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME) |
| 917 return false; | 911 return false; |
| 918 | 912 |
| 919 // If we just forced activation, we should end the deadline right now. | 913 // If we just forced activation, we should end the deadline right now. |
| 920 if (PendingActivationsShouldBeForced() && !has_pending_tree_) | 914 if (PendingActivationsShouldBeForced() && !has_pending_tree_) |
| 921 return true; | 915 return true; |
| 922 | 916 |
| 923 // SwapAck throttle the deadline since we wont draw and swap anyway. | 917 // SwapAck throttle the deadline since we wont draw and swap anyway. |
| 924 if (pending_swaps_ >= max_pending_swaps_) | 918 if (pending_swaps_ >= max_pending_swaps_) |
| 925 return false; | 919 return false; |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1168 static_cast<int>(begin_impl_frame_state_), | 1162 static_cast<int>(begin_impl_frame_state_), |
| 1169 static_cast<int>(commit_state_), | 1163 static_cast<int>(commit_state_), |
| 1170 has_pending_tree_ ? 'T' : 'F', | 1164 has_pending_tree_ ? 'T' : 'F', |
| 1171 pending_tree_is_ready_for_activation_ ? 'T' : 'F', | 1165 pending_tree_is_ready_for_activation_ ? 'T' : 'F', |
| 1172 active_tree_needs_first_draw_ ? 'T' : 'F', | 1166 active_tree_needs_first_draw_ ? 'T' : 'F', |
| 1173 max_pending_swaps_, | 1167 max_pending_swaps_, |
| 1174 pending_swaps_); | 1168 pending_swaps_); |
| 1175 } | 1169 } |
| 1176 | 1170 |
| 1177 } // namespace cc | 1171 } // namespace cc |
| OLD | NEW |