| 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/format_macros.h" | 8 #include "base/format_macros.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 texture_state_(LAYER_TEXTURE_STATE_UNLOCKED), | 21 texture_state_(LAYER_TEXTURE_STATE_UNLOCKED), |
| 22 forced_redraw_state_(FORCED_REDRAW_STATE_IDLE), | 22 forced_redraw_state_(FORCED_REDRAW_STATE_IDLE), |
| 23 readback_state_(READBACK_STATE_IDLE), | 23 readback_state_(READBACK_STATE_IDLE), |
| 24 commit_count_(0), | 24 commit_count_(0), |
| 25 current_frame_number_(0), | 25 current_frame_number_(0), |
| 26 last_frame_number_swap_performed_(-1), | 26 last_frame_number_swap_performed_(-1), |
| 27 last_frame_number_begin_main_frame_sent_(-1), | 27 last_frame_number_begin_main_frame_sent_(-1), |
| 28 last_frame_number_update_visible_tiles_was_called_(-1), | 28 last_frame_number_update_visible_tiles_was_called_(-1), |
| 29 manage_tiles_funnel_(0), | 29 manage_tiles_funnel_(0), |
| 30 consecutive_checkerboard_animations_(0), | 30 consecutive_checkerboard_animations_(0), |
| 31 max_pending_swaps_(1), |
| 32 pending_swaps_(0), |
| 31 needs_redraw_(false), | 33 needs_redraw_(false), |
| 32 needs_manage_tiles_(false), | 34 needs_manage_tiles_(false), |
| 33 swap_used_incomplete_tile_(false), | 35 swap_used_incomplete_tile_(false), |
| 34 needs_commit_(false), | 36 needs_commit_(false), |
| 35 main_thread_needs_layer_textures_(false), | 37 main_thread_needs_layer_textures_(false), |
| 36 inside_poll_for_anticipated_draw_triggers_(false), | 38 inside_poll_for_anticipated_draw_triggers_(false), |
| 37 visible_(false), | 39 visible_(false), |
| 38 can_start_(false), | 40 can_start_(false), |
| 39 can_draw_(false), | 41 can_draw_(false), |
| 40 has_pending_tree_(false), | 42 has_pending_tree_(false), |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 minor_state->SetInteger( | 240 minor_state->SetInteger( |
| 239 "last_frame_number_begin_main_frame_sent", | 241 "last_frame_number_begin_main_frame_sent", |
| 240 last_frame_number_begin_main_frame_sent_); | 242 last_frame_number_begin_main_frame_sent_); |
| 241 minor_state->SetInteger( | 243 minor_state->SetInteger( |
| 242 "last_frame_number_update_visible_tiles_was_called", | 244 "last_frame_number_update_visible_tiles_was_called", |
| 243 last_frame_number_update_visible_tiles_was_called_); | 245 last_frame_number_update_visible_tiles_was_called_); |
| 244 | 246 |
| 245 minor_state->SetInteger("manage_tiles_funnel", manage_tiles_funnel_); | 247 minor_state->SetInteger("manage_tiles_funnel", manage_tiles_funnel_); |
| 246 minor_state->SetInteger("consecutive_checkerboard_animations", | 248 minor_state->SetInteger("consecutive_checkerboard_animations", |
| 247 consecutive_checkerboard_animations_); | 249 consecutive_checkerboard_animations_); |
| 250 minor_state->SetInteger("max_pending_swaps_", max_pending_swaps_); |
| 251 minor_state->SetInteger("pending_swaps_", pending_swaps_); |
| 248 minor_state->SetBoolean("needs_redraw", needs_redraw_); | 252 minor_state->SetBoolean("needs_redraw", needs_redraw_); |
| 249 minor_state->SetBoolean("needs_manage_tiles", needs_manage_tiles_); | 253 minor_state->SetBoolean("needs_manage_tiles", needs_manage_tiles_); |
| 250 minor_state->SetBoolean("swap_used_incomplete_tile", | 254 minor_state->SetBoolean("swap_used_incomplete_tile", |
| 251 swap_used_incomplete_tile_); | 255 swap_used_incomplete_tile_); |
| 252 minor_state->SetBoolean("needs_commit", needs_commit_); | 256 minor_state->SetBoolean("needs_commit", needs_commit_); |
| 253 minor_state->SetBoolean("main_thread_needs_layer_textures", | 257 minor_state->SetBoolean("main_thread_needs_layer_textures", |
| 254 main_thread_needs_layer_textures_); | 258 main_thread_needs_layer_textures_); |
| 255 minor_state->SetBoolean("visible", visible_); | 259 minor_state->SetBoolean("visible", visible_); |
| 256 minor_state->SetBoolean("can_start", can_start_); | 260 minor_state->SetBoolean("can_start", can_start_); |
| 257 minor_state->SetBoolean("can_draw", can_draw_); | 261 minor_state->SetBoolean("can_draw", can_draw_); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 // from occuring. If we are waiting for the first draw, then perfom the | 387 // from occuring. If we are waiting for the first draw, then perfom the |
| 384 // aborted draw to keep things moving. If we are not waiting for the first | 388 // aborted draw to keep things moving. If we are not waiting for the first |
| 385 // draw however, we don't want to abort for no reason. | 389 // draw however, we don't want to abort for no reason. |
| 386 if (PendingDrawsShouldBeAborted()) | 390 if (PendingDrawsShouldBeAborted()) |
| 387 return active_tree_needs_first_draw_; | 391 return active_tree_needs_first_draw_; |
| 388 | 392 |
| 389 // After this line, we only want to swap once per frame. | 393 // After this line, we only want to swap once per frame. |
| 390 if (HasSwappedThisFrame()) | 394 if (HasSwappedThisFrame()) |
| 391 return false; | 395 return false; |
| 392 | 396 |
| 397 // Do not queue too many swaps. |
| 398 if (pending_swaps_ >= max_pending_swaps_) |
| 399 return false; |
| 400 |
| 393 // Except for the cases above, do not draw outside of the BeginImplFrame | 401 // Except for the cases above, do not draw outside of the BeginImplFrame |
| 394 // deadline. | 402 // deadline. |
| 395 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) | 403 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) |
| 396 return false; | 404 return false; |
| 397 | 405 |
| 398 // Only handle forced redraws due to timeouts on the regular deadline. | 406 // Only handle forced redraws due to timeouts on the regular deadline. |
| 399 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) | 407 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) |
| 400 return true; | 408 return true; |
| 401 | 409 |
| 402 return needs_redraw_; | 410 return needs_redraw_; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 return true; | 508 return true; |
| 501 | 509 |
| 502 // After this point, we only start a commit once per frame. | 510 // After this point, we only start a commit once per frame. |
| 503 if (HasSentBeginMainFrameThisFrame()) | 511 if (HasSentBeginMainFrameThisFrame()) |
| 504 return false; | 512 return false; |
| 505 | 513 |
| 506 // We shouldn't normally accept commits if there isn't an OutputSurface. | 514 // We shouldn't normally accept commits if there isn't an OutputSurface. |
| 507 if (!HasInitializedOutputSurface()) | 515 if (!HasInitializedOutputSurface()) |
| 508 return false; | 516 return false; |
| 509 | 517 |
| 518 // SwapAck throttle the BeginMainFrames |
| 519 // TODO(brianderson): Remove this restriction to improve throughput. |
| 520 if (pending_swaps_ >= max_pending_swaps_) |
| 521 return false; |
| 522 |
| 510 if (skip_begin_main_frame_to_reduce_latency_) | 523 if (skip_begin_main_frame_to_reduce_latency_) |
| 511 return false; | 524 return false; |
| 512 | 525 |
| 513 return true; | 526 return true; |
| 514 } | 527 } |
| 515 | 528 |
| 516 bool SchedulerStateMachine::ShouldCommit() const { | 529 bool SchedulerStateMachine::ShouldCommit() const { |
| 517 if (commit_state_ != COMMIT_STATE_READY_TO_COMMIT) | 530 if (commit_state_ != COMMIT_STATE_READY_TO_COMMIT) |
| 518 return false; | 531 return false; |
| 519 | 532 |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 | 861 |
| 849 // Non synchronous compositors should rely on | 862 // Non synchronous compositors should rely on |
| 850 // ProactiveBeginFrameWanted to poll for state instead. | 863 // ProactiveBeginFrameWanted to poll for state instead. |
| 851 return false; | 864 return false; |
| 852 } | 865 } |
| 853 | 866 |
| 854 bool SchedulerStateMachine::SupportsProactiveBeginFrame() const { | 867 bool SchedulerStateMachine::SupportsProactiveBeginFrame() const { |
| 855 // Both the synchronous compositor and disabled vsync settings | 868 // Both the synchronous compositor and disabled vsync settings |
| 856 // make it undesirable to proactively request BeginImplFrames. | 869 // make it undesirable to proactively request BeginImplFrames. |
| 857 // If this is true, the scheduler should poll. | 870 // If this is true, the scheduler should poll. |
| 858 return !settings_.using_synchronous_renderer_compositor && | 871 return !settings_.using_synchronous_renderer_compositor; |
| 859 settings_.throttle_frame_production; | |
| 860 } | 872 } |
| 861 | 873 |
| 862 // These are the cases where we definitely (or almost definitely) have a | 874 // These are the cases where we definitely (or almost definitely) have a |
| 863 // new frame to draw and can draw. | 875 // new frame to draw and can draw. |
| 864 bool SchedulerStateMachine::BeginFrameNeededToDraw() const { | 876 bool SchedulerStateMachine::BeginFrameNeededToDraw() const { |
| 865 // The output surface is the provider of BeginImplFrames, so we are not going | 877 // The output surface is the provider of BeginImplFrames, so we are not going |
| 866 // to get them even if we ask for them. | 878 // to get them even if we ask for them. |
| 867 if (!HasInitializedOutputSurface()) | 879 if (!HasInitializedOutputSurface()) |
| 868 return false; | 880 return false; |
| 869 | 881 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 964 return false; | 976 return false; |
| 965 | 977 |
| 966 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME) | 978 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME) |
| 967 return false; | 979 return false; |
| 968 | 980 |
| 969 // If we've lost the output surface, end the current BeginImplFrame ASAP | 981 // If we've lost the output surface, end the current BeginImplFrame ASAP |
| 970 // so we can start creating the next output surface. | 982 // so we can start creating the next output surface. |
| 971 if (output_surface_state_ == OUTPUT_SURFACE_LOST) | 983 if (output_surface_state_ == OUTPUT_SURFACE_LOST) |
| 972 return true; | 984 return true; |
| 973 | 985 |
| 986 // SwapAck throttle the deadline since we wont draw and swap anyway. |
| 987 if (pending_swaps_ >= max_pending_swaps_) |
| 988 return false; |
| 989 |
| 974 if (active_tree_needs_first_draw_) | 990 if (active_tree_needs_first_draw_) |
| 975 return true; | 991 return true; |
| 976 | 992 |
| 977 if (!needs_redraw_) | 993 if (!needs_redraw_) |
| 978 return false; | 994 return false; |
| 979 | 995 |
| 980 // This is used to prioritize impl-thread draws when the main thread isn't | 996 // This is used to prioritize impl-thread draws when the main thread isn't |
| 981 // producing anything, e.g., after an aborted commit. We also check that we | 997 // producing anything, e.g., after an aborted commit. We also check that we |
| 982 // don't have a pending tree -- otherwise we should give it a chance to | 998 // don't have a pending tree -- otherwise we should give it a chance to |
| 983 // activate. | 999 // activate. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1052 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } | 1068 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } |
| 1053 | 1069 |
| 1054 void SchedulerStateMachine::SetNeedsManageTiles() { | 1070 void SchedulerStateMachine::SetNeedsManageTiles() { |
| 1055 if (!needs_manage_tiles_) { | 1071 if (!needs_manage_tiles_) { |
| 1056 TRACE_EVENT0("cc", | 1072 TRACE_EVENT0("cc", |
| 1057 "SchedulerStateMachine::SetNeedsManageTiles"); | 1073 "SchedulerStateMachine::SetNeedsManageTiles"); |
| 1058 needs_manage_tiles_ = true; | 1074 needs_manage_tiles_ = true; |
| 1059 } | 1075 } |
| 1060 } | 1076 } |
| 1061 | 1077 |
| 1078 void SchedulerStateMachine::SetMaxSwapsPending(int max) { |
| 1079 max_pending_swaps_ = max; |
| 1080 } |
| 1081 |
| 1082 void SchedulerStateMachine::DidSwapBuffers() { |
| 1083 pending_swaps_++; |
| 1084 DCHECK_LE(pending_swaps_, max_pending_swaps_); |
| 1085 } |
| 1086 |
| 1062 void SchedulerStateMachine::SetSwapUsedIncompleteTile( | 1087 void SchedulerStateMachine::SetSwapUsedIncompleteTile( |
| 1063 bool used_incomplete_tile) { | 1088 bool used_incomplete_tile) { |
| 1064 swap_used_incomplete_tile_ = used_incomplete_tile; | 1089 swap_used_incomplete_tile_ = used_incomplete_tile; |
| 1065 } | 1090 } |
| 1066 | 1091 |
| 1092 void SchedulerStateMachine::OnSwapBuffersComplete() { |
| 1093 DCHECK(HasInitializedOutputSurface()); |
| 1094 DCHECK_GT(pending_swaps_, 0); |
| 1095 pending_swaps_--; |
| 1096 } |
| 1097 |
| 1067 void SchedulerStateMachine::SetSmoothnessTakesPriority( | 1098 void SchedulerStateMachine::SetSmoothnessTakesPriority( |
| 1068 bool smoothness_takes_priority) { | 1099 bool smoothness_takes_priority) { |
| 1069 smoothness_takes_priority_ = smoothness_takes_priority; | 1100 smoothness_takes_priority_ = smoothness_takes_priority; |
| 1070 } | 1101 } |
| 1071 | 1102 |
| 1072 void SchedulerStateMachine::DidDrawIfPossibleCompleted( | 1103 void SchedulerStateMachine::DidDrawIfPossibleCompleted( |
| 1073 DrawSwapReadbackResult::DrawResult result) { | 1104 DrawSwapReadbackResult::DrawResult result) { |
| 1074 switch (result) { | 1105 switch (result) { |
| 1075 case DrawSwapReadbackResult::INVALID_RESULT: | 1106 case DrawSwapReadbackResult::INVALID_RESULT: |
| 1076 NOTREACHED() << "Uninitialized DrawSwapReadbackResult."; | 1107 NOTREACHED() << "Uninitialized DrawSwapReadbackResult."; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1171 // "Fill" the ManageTiles funnel. | 1202 // "Fill" the ManageTiles funnel. |
| 1172 manage_tiles_funnel_++; | 1203 manage_tiles_funnel_++; |
| 1173 } | 1204 } |
| 1174 | 1205 |
| 1175 void SchedulerStateMachine::DidLoseOutputSurface() { | 1206 void SchedulerStateMachine::DidLoseOutputSurface() { |
| 1176 if (output_surface_state_ == OUTPUT_SURFACE_LOST || | 1207 if (output_surface_state_ == OUTPUT_SURFACE_LOST || |
| 1177 output_surface_state_ == OUTPUT_SURFACE_CREATING) | 1208 output_surface_state_ == OUTPUT_SURFACE_CREATING) |
| 1178 return; | 1209 return; |
| 1179 output_surface_state_ = OUTPUT_SURFACE_LOST; | 1210 output_surface_state_ = OUTPUT_SURFACE_LOST; |
| 1180 needs_redraw_ = false; | 1211 needs_redraw_ = false; |
| 1212 pending_swaps_ = 0; |
| 1181 } | 1213 } |
| 1182 | 1214 |
| 1183 void SchedulerStateMachine::NotifyReadyToActivate() { | 1215 void SchedulerStateMachine::NotifyReadyToActivate() { |
| 1184 if (has_pending_tree_) | 1216 if (has_pending_tree_) |
| 1185 pending_tree_is_ready_for_activation_ = true; | 1217 pending_tree_is_ready_for_activation_ = true; |
| 1186 } | 1218 } |
| 1187 | 1219 |
| 1188 void SchedulerStateMachine::DidCreateAndInitializeOutputSurface() { | 1220 void SchedulerStateMachine::DidCreateAndInitializeOutputSurface() { |
| 1189 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_CREATING); | 1221 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_CREATING); |
| 1190 output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT; | 1222 output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1216 case OUTPUT_SURFACE_ACTIVE: | 1248 case OUTPUT_SURFACE_ACTIVE: |
| 1217 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: | 1249 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: |
| 1218 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: | 1250 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: |
| 1219 return true; | 1251 return true; |
| 1220 } | 1252 } |
| 1221 NOTREACHED(); | 1253 NOTREACHED(); |
| 1222 return false; | 1254 return false; |
| 1223 } | 1255 } |
| 1224 | 1256 |
| 1225 } // namespace cc | 1257 } // namespace cc |
| OLD | NEW |