Chromium Code Reviews| 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 29 matching lines...) Expand all Loading... | |
| 40 needs_prepare_tiles_(false), | 40 needs_prepare_tiles_(false), |
| 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 main_thread_missed_last_deadline_(false), | |
| 50 skip_next_begin_main_frame_to_reduce_latency_(false), | 51 skip_next_begin_main_frame_to_reduce_latency_(false), |
| 51 continuous_painting_(false), | 52 continuous_painting_(false), |
| 52 children_need_begin_frames_(false), | 53 children_need_begin_frames_(false), |
| 53 defer_commits_(false), | 54 defer_commits_(false), |
| 54 video_needs_begin_frames_(false), | 55 video_needs_begin_frames_(false), |
| 55 last_commit_had_no_updates_(false), | 56 last_commit_had_no_updates_(false), |
| 56 wait_for_active_tree_ready_to_draw_(false), | 57 wait_for_active_tree_ready_to_draw_(false), |
| 57 did_request_swap_in_last_frame_(false), | 58 did_request_swap_in_last_frame_(false), |
| 58 did_perform_swap_in_last_draw_(false) { | 59 did_perform_swap_in_last_draw_(false) { |
| 59 } | 60 } |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 state->SetBoolean("pending_tree_is_ready_for_activation", | 231 state->SetBoolean("pending_tree_is_ready_for_activation", |
| 231 pending_tree_is_ready_for_activation_); | 232 pending_tree_is_ready_for_activation_); |
| 232 state->SetBoolean("active_tree_needs_first_draw", | 233 state->SetBoolean("active_tree_needs_first_draw", |
| 233 active_tree_needs_first_draw_); | 234 active_tree_needs_first_draw_); |
| 234 state->SetBoolean("wait_for_active_tree_ready_to_draw", | 235 state->SetBoolean("wait_for_active_tree_ready_to_draw", |
| 235 wait_for_active_tree_ready_to_draw_); | 236 wait_for_active_tree_ready_to_draw_); |
| 236 state->SetBoolean("did_create_and_initialize_first_output_surface", | 237 state->SetBoolean("did_create_and_initialize_first_output_surface", |
| 237 did_create_and_initialize_first_output_surface_); | 238 did_create_and_initialize_first_output_surface_); |
| 238 state->SetBoolean("impl_latency_takes_priority", | 239 state->SetBoolean("impl_latency_takes_priority", |
| 239 impl_latency_takes_priority_); | 240 impl_latency_takes_priority_); |
| 240 state->SetBoolean("main_thread_is_in_high_latency_mode", | 241 state->SetBoolean("main_thread_missed_last_deadline", |
| 241 MainThreadIsInHighLatencyMode()); | 242 main_thread_missed_last_deadline_); |
| 242 state->SetBoolean("skip_next_begin_main_frame_to_reduce_latency", | 243 state->SetBoolean("skip_next_begin_main_frame_to_reduce_latency", |
| 243 skip_next_begin_main_frame_to_reduce_latency_); | 244 skip_next_begin_main_frame_to_reduce_latency_); |
| 244 state->SetBoolean("continuous_painting", continuous_painting_); | 245 state->SetBoolean("continuous_painting", continuous_painting_); |
| 245 state->SetBoolean("children_need_begin_frames", children_need_begin_frames_); | 246 state->SetBoolean("children_need_begin_frames", children_need_begin_frames_); |
| 246 state->SetBoolean("video_needs_begin_frames", video_needs_begin_frames_); | 247 state->SetBoolean("video_needs_begin_frames", video_needs_begin_frames_); |
| 247 state->SetBoolean("defer_commits", defer_commits_); | 248 state->SetBoolean("defer_commits", defer_commits_); |
| 248 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_); |
| 249 state->SetBoolean("did_request_swap_in_last_frame", | 250 state->SetBoolean("did_request_swap_in_last_frame", |
| 250 did_request_swap_in_last_frame_); | 251 did_request_swap_in_last_frame_); |
| 251 state->SetBoolean("did_perform_swap_in_last_draw", | 252 state->SetBoolean("did_perform_swap_in_last_draw", |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 872 if (settings_.using_synchronous_renderer_compositor) { | 873 if (settings_.using_synchronous_renderer_compositor) { |
| 873 if (prepare_tiles_funnel_ > 0) | 874 if (prepare_tiles_funnel_ > 0) |
| 874 prepare_tiles_funnel_--; | 875 prepare_tiles_funnel_--; |
| 875 } | 876 } |
| 876 } | 877 } |
| 877 | 878 |
| 878 void SchedulerStateMachine::OnBeginImplFrameIdle() { | 879 void SchedulerStateMachine::OnBeginImplFrameIdle() { |
| 879 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_IDLE; | 880 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_IDLE; |
| 880 | 881 |
| 881 skip_next_begin_main_frame_to_reduce_latency_ = false; | 882 skip_next_begin_main_frame_to_reduce_latency_ = false; |
| 883 | |
| 884 // If a new or undrawn active tree is pending after the deadline, | |
| 885 // then the main thread is in a high latency mode. | |
| 886 main_thread_missed_last_deadline_ = | |
| 887 CommitPending() || has_pending_tree_ || active_tree_needs_first_draw_; | |
| 882 } | 888 } |
| 883 | 889 |
| 884 SchedulerStateMachine::BeginImplFrameDeadlineMode | 890 SchedulerStateMachine::BeginImplFrameDeadlineMode |
| 885 SchedulerStateMachine::CurrentBeginImplFrameDeadlineMode() const { | 891 SchedulerStateMachine::CurrentBeginImplFrameDeadlineMode() const { |
| 886 if (settings_.using_synchronous_renderer_compositor) { | 892 if (settings_.using_synchronous_renderer_compositor) { |
| 887 // No deadline for synchronous compositor. | 893 // No deadline for synchronous compositor. |
| 888 return BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE; | 894 return BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE; |
| 889 } else if (wait_for_active_tree_ready_to_draw_) { | 895 } else if (wait_for_active_tree_ready_to_draw_) { |
| 890 // When we are waiting for ready to draw signal, we do not wait to post a | 896 // When we are waiting for ready to draw signal, we do not wait to post a |
| 891 // deadline yet. | 897 // deadline yet. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 932 if (commit_state_ == COMMIT_STATE_IDLE && !has_pending_tree_) | 938 if (commit_state_ == COMMIT_STATE_IDLE && !has_pending_tree_) |
| 933 return true; | 939 return true; |
| 934 | 940 |
| 935 // Prioritize impl-thread draws in impl_latency_takes_priority_ mode. | 941 // Prioritize impl-thread draws in impl_latency_takes_priority_ mode. |
| 936 if (impl_latency_takes_priority_) | 942 if (impl_latency_takes_priority_) |
| 937 return true; | 943 return true; |
| 938 | 944 |
| 939 return false; | 945 return false; |
| 940 } | 946 } |
| 941 | 947 |
| 942 bool SchedulerStateMachine::MainThreadIsInHighLatencyMode() const { | 948 bool SchedulerStateMachine::main_thread_missed_last_deadline() const { |
| 943 // If a commit is pending before the previous commit has been drawn, we | 949 return main_thread_missed_last_deadline_; |
| 944 // are definitely in a high latency mode. | |
| 945 if (CommitPending() && (active_tree_needs_first_draw_ || has_pending_tree_)) | |
| 946 return true; | |
| 947 | |
| 948 // If we just sent a BeginMainFrame and haven't hit the deadline yet, the main | |
| 949 // thread is in a low latency mode. | |
| 950 if (send_begin_main_frame_funnel_ && | |
| 951 (begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING || | |
| 952 begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME)) | |
| 953 return false; | |
| 954 | |
| 955 // If there's a commit in progress it must either be from the previous frame | |
| 956 // or it started after the impl thread's deadline. In either case the main | |
| 957 // thread is in high latency mode. | |
| 958 if (CommitPending()) | |
| 959 return true; | |
| 960 | |
| 961 // Similarly, if there's a pending tree the main thread is in high latency | |
| 962 // mode, because either | |
| 963 // it's from the previous frame | |
| 964 // or | |
| 965 // we're currently drawing the active tree and the pending tree will thus | |
| 966 // only be drawn in the next frame. | |
| 967 if (has_pending_tree_) | |
| 968 return true; | |
| 969 | |
| 970 if (begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) { | |
| 971 // Even if there's a new active tree to draw at the deadline or we've just | |
| 972 // swapped it, it may have been triggered by a previous BeginImplFrame, in | |
| 973 // which case the main thread is in a high latency mode. | |
| 974 return (active_tree_needs_first_draw_ || did_perform_swap_in_last_draw_) && | |
| 975 !send_begin_main_frame_funnel_; | |
| 976 } | |
| 977 | |
| 978 // If the active tree needs its first draw in any other state, we know the | |
| 979 // main thread is in a high latency mode. | |
| 980 return active_tree_needs_first_draw_; | |
| 981 } | 950 } |
| 982 | 951 |
| 983 bool SchedulerStateMachine::SwapThrottled() const { | 952 bool SchedulerStateMachine::SwapThrottled() const { |
| 984 return pending_swaps_ >= max_pending_swaps_; | 953 return pending_swaps_ >= max_pending_swaps_; |
| 985 } | 954 } |
| 986 | 955 |
| 987 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } | 956 void SchedulerStateMachine::SetVisible(bool visible) { |
| 957 if (visible_ == visible) | |
| 958 return; | |
| 959 | |
| 960 if (visible) | |
| 961 main_thread_missed_last_deadline_ = false; | |
| 962 | |
| 963 visible_ = visible; | |
| 964 } | |
| 988 | 965 |
| 989 void SchedulerStateMachine::SetCanDraw(bool can_draw) { can_draw_ = can_draw; } | 966 void SchedulerStateMachine::SetCanDraw(bool can_draw) { can_draw_ = can_draw; } |
| 990 | 967 |
| 991 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } | 968 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } |
| 992 | 969 |
| 993 void SchedulerStateMachine::SetNeedsAnimate() { | 970 void SchedulerStateMachine::SetNeedsAnimate() { |
| 994 needs_animate_ = true; | 971 needs_animate_ = true; |
| 995 } | 972 } |
| 996 | 973 |
| 997 void SchedulerStateMachine::SetWaitForReadyToDraw() { | 974 void SchedulerStateMachine::SetWaitForReadyToDraw() { |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1138 output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT; | 1115 output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT; |
| 1139 | 1116 |
| 1140 if (did_create_and_initialize_first_output_surface_) { | 1117 if (did_create_and_initialize_first_output_surface_) { |
| 1141 // TODO(boliu): See if we can remove this when impl-side painting is always | 1118 // TODO(boliu): See if we can remove this when impl-side painting is always |
| 1142 // on. Does anything on the main thread need to update after recreate? | 1119 // on. Does anything on the main thread need to update after recreate? |
| 1143 needs_commit_ = true; | 1120 needs_commit_ = true; |
| 1144 } | 1121 } |
| 1145 did_create_and_initialize_first_output_surface_ = true; | 1122 did_create_and_initialize_first_output_surface_ = true; |
| 1146 pending_swaps_ = 0; | 1123 pending_swaps_ = 0; |
| 1147 swaps_with_current_output_surface_ = 0; | 1124 swaps_with_current_output_surface_ = 0; |
| 1125 main_thread_missed_last_deadline_ = false; | |
|
sunnyps
2015/07/13 20:03:09
It looks like we need to set main_thread_missed_la
| |
| 1148 } | 1126 } |
| 1149 | 1127 |
| 1150 void SchedulerStateMachine::NotifyBeginMainFrameStarted() { | 1128 void SchedulerStateMachine::NotifyBeginMainFrameStarted() { |
| 1151 DCHECK_EQ(commit_state_, COMMIT_STATE_BEGIN_MAIN_FRAME_SENT); | 1129 DCHECK_EQ(commit_state_, COMMIT_STATE_BEGIN_MAIN_FRAME_SENT); |
| 1152 commit_state_ = COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED; | 1130 commit_state_ = COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED; |
| 1153 } | 1131 } |
| 1154 | 1132 |
| 1155 bool SchedulerStateMachine::HasInitializedOutputSurface() const { | 1133 bool SchedulerStateMachine::HasInitializedOutputSurface() const { |
| 1156 switch (output_surface_state_) { | 1134 switch (output_surface_state_) { |
| 1157 case OUTPUT_SURFACE_LOST: | 1135 case OUTPUT_SURFACE_LOST: |
| 1158 case OUTPUT_SURFACE_CREATING: | 1136 case OUTPUT_SURFACE_CREATING: |
| 1159 return false; | 1137 return false; |
| 1160 | 1138 |
| 1161 case OUTPUT_SURFACE_ACTIVE: | 1139 case OUTPUT_SURFACE_ACTIVE: |
| 1162 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: | 1140 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: |
| 1163 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: | 1141 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: |
| 1164 return true; | 1142 return true; |
| 1165 } | 1143 } |
| 1166 NOTREACHED(); | 1144 NOTREACHED(); |
| 1167 return false; | 1145 return false; |
| 1168 } | 1146 } |
| 1169 | 1147 |
| 1170 } // namespace cc | 1148 } // namespace cc |
| OLD | NEW |