| 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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 minor_state->SetInteger( | 242 minor_state->SetInteger( |
| 241 "last_frame_number_begin_main_frame_sent", | 243 "last_frame_number_begin_main_frame_sent", |
| 242 last_frame_number_begin_main_frame_sent_); | 244 last_frame_number_begin_main_frame_sent_); |
| 243 minor_state->SetInteger( | 245 minor_state->SetInteger( |
| 244 "last_frame_number_update_visible_tiles_was_called", | 246 "last_frame_number_update_visible_tiles_was_called", |
| 245 last_frame_number_update_visible_tiles_was_called_); | 247 last_frame_number_update_visible_tiles_was_called_); |
| 246 | 248 |
| 247 minor_state->SetInteger("manage_tiles_funnel", manage_tiles_funnel_); | 249 minor_state->SetInteger("manage_tiles_funnel", manage_tiles_funnel_); |
| 248 minor_state->SetInteger("consecutive_checkerboard_animations", | 250 minor_state->SetInteger("consecutive_checkerboard_animations", |
| 249 consecutive_checkerboard_animations_); | 251 consecutive_checkerboard_animations_); |
| 252 minor_state->SetInteger("max_pending_swaps_", max_pending_swaps_); |
| 253 minor_state->SetInteger("pending_swaps_", pending_swaps_); |
| 250 minor_state->SetBoolean("needs_redraw", needs_redraw_); | 254 minor_state->SetBoolean("needs_redraw", needs_redraw_); |
| 251 minor_state->SetBoolean("needs_manage_tiles", needs_manage_tiles_); | 255 minor_state->SetBoolean("needs_manage_tiles", needs_manage_tiles_); |
| 252 minor_state->SetBoolean("swap_used_incomplete_tile", | 256 minor_state->SetBoolean("swap_used_incomplete_tile", |
| 253 swap_used_incomplete_tile_); | 257 swap_used_incomplete_tile_); |
| 254 minor_state->SetBoolean("needs_commit", needs_commit_); | 258 minor_state->SetBoolean("needs_commit", needs_commit_); |
| 255 minor_state->SetBoolean("main_thread_needs_layer_textures", | 259 minor_state->SetBoolean("main_thread_needs_layer_textures", |
| 256 main_thread_needs_layer_textures_); | 260 main_thread_needs_layer_textures_); |
| 257 minor_state->SetBoolean("visible", visible_); | 261 minor_state->SetBoolean("visible", visible_); |
| 258 minor_state->SetBoolean("can_start", can_start_); | 262 minor_state->SetBoolean("can_start", can_start_); |
| 259 minor_state->SetBoolean("can_draw", can_draw_); | 263 minor_state->SetBoolean("can_draw", can_draw_); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 // from occuring. If we are waiting for the first draw, then perfom the | 388 // from occuring. If we are waiting for the first draw, then perfom the |
| 385 // aborted draw to keep things moving. If we are not waiting for the first | 389 // aborted draw to keep things moving. If we are not waiting for the first |
| 386 // draw however, we don't want to abort for no reason. | 390 // draw however, we don't want to abort for no reason. |
| 387 if (PendingDrawsShouldBeAborted()) | 391 if (PendingDrawsShouldBeAborted()) |
| 388 return active_tree_needs_first_draw_; | 392 return active_tree_needs_first_draw_; |
| 389 | 393 |
| 390 // After this line, we only want to swap once per frame. | 394 // After this line, we only want to swap once per frame. |
| 391 if (HasSwappedThisFrame()) | 395 if (HasSwappedThisFrame()) |
| 392 return false; | 396 return false; |
| 393 | 397 |
| 398 // Do not queue too many swaps. |
| 399 if (pending_swaps_ >= max_pending_swaps_) |
| 400 return false; |
| 401 |
| 394 // Except for the cases above, do not draw outside of the BeginImplFrame | 402 // Except for the cases above, do not draw outside of the BeginImplFrame |
| 395 // deadline. | 403 // deadline. |
| 396 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) | 404 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) |
| 397 return false; | 405 return false; |
| 398 | 406 |
| 399 // Only handle forced redraws due to timeouts on the regular deadline. | 407 // Only handle forced redraws due to timeouts on the regular deadline. |
| 400 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) | 408 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) |
| 401 return true; | 409 return true; |
| 402 | 410 |
| 403 return needs_redraw_; | 411 return needs_redraw_; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 return true; | 509 return true; |
| 502 | 510 |
| 503 // After this point, we only start a commit once per frame. | 511 // After this point, we only start a commit once per frame. |
| 504 if (HasSentBeginMainFrameThisFrame()) | 512 if (HasSentBeginMainFrameThisFrame()) |
| 505 return false; | 513 return false; |
| 506 | 514 |
| 507 // We shouldn't normally accept commits if there isn't an OutputSurface. | 515 // We shouldn't normally accept commits if there isn't an OutputSurface. |
| 508 if (!HasInitializedOutputSurface()) | 516 if (!HasInitializedOutputSurface()) |
| 509 return false; | 517 return false; |
| 510 | 518 |
| 519 // SwapAck throttle the BeginMainFrames |
| 520 // TODO(brianderson): Remove this restriction to improve throughput. |
| 521 if (pending_swaps_ >= max_pending_swaps_) |
| 522 return false; |
| 523 |
| 511 if (skip_begin_main_frame_to_reduce_latency_) | 524 if (skip_begin_main_frame_to_reduce_latency_) |
| 512 return false; | 525 return false; |
| 513 | 526 |
| 514 return true; | 527 return true; |
| 515 } | 528 } |
| 516 | 529 |
| 517 bool SchedulerStateMachine::ShouldCommit() const { | 530 bool SchedulerStateMachine::ShouldCommit() const { |
| 518 if (commit_state_ != COMMIT_STATE_READY_TO_COMMIT) | 531 if (commit_state_ != COMMIT_STATE_READY_TO_COMMIT) |
| 519 return false; | 532 return false; |
| 520 | 533 |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 | 845 |
| 833 // Non synchronous compositors should rely on | 846 // Non synchronous compositors should rely on |
| 834 // ProactiveBeginImplFrameWanted to poll for state instead. | 847 // ProactiveBeginImplFrameWanted to poll for state instead. |
| 835 return false; | 848 return false; |
| 836 } | 849 } |
| 837 | 850 |
| 838 bool SchedulerStateMachine::SupportsProactiveBeginImplFrame() const { | 851 bool SchedulerStateMachine::SupportsProactiveBeginImplFrame() const { |
| 839 // Both the synchronous compositor and disabled vsync settings | 852 // Both the synchronous compositor and disabled vsync settings |
| 840 // make it undesirable to proactively request BeginImplFrames. | 853 // make it undesirable to proactively request BeginImplFrames. |
| 841 // If this is true, the scheduler should poll. | 854 // If this is true, the scheduler should poll. |
| 842 return !settings_.using_synchronous_renderer_compositor && | 855 return !settings_.using_synchronous_renderer_compositor; |
| 843 settings_.throttle_frame_production; | |
| 844 } | 856 } |
| 845 | 857 |
| 846 // These are the cases where we definitely (or almost definitely) have a | 858 // These are the cases where we definitely (or almost definitely) have a |
| 847 // new frame to draw and can draw. | 859 // new frame to draw and can draw. |
| 848 bool SchedulerStateMachine::BeginImplFrameNeededToDraw() const { | 860 bool SchedulerStateMachine::BeginImplFrameNeededToDraw() const { |
| 849 // The output surface is the provider of BeginImplFrames, so we are not going | 861 // The output surface is the provider of BeginImplFrames, so we are not going |
| 850 // to get them even if we ask for them. | 862 // to get them even if we ask for them. |
| 851 if (!HasInitializedOutputSurface()) | 863 if (!HasInitializedOutputSurface()) |
| 852 return false; | 864 return false; |
| 853 | 865 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 return false; | 960 return false; |
| 949 | 961 |
| 950 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME) | 962 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME) |
| 951 return false; | 963 return false; |
| 952 | 964 |
| 953 // If we've lost the output surface, end the current BeginImplFrame ASAP | 965 // If we've lost the output surface, end the current BeginImplFrame ASAP |
| 954 // so we can start creating the next output surface. | 966 // so we can start creating the next output surface. |
| 955 if (output_surface_state_ == OUTPUT_SURFACE_LOST) | 967 if (output_surface_state_ == OUTPUT_SURFACE_LOST) |
| 956 return true; | 968 return true; |
| 957 | 969 |
| 970 // SwapAck throttle the deadline since we wont draw and swap anyway. |
| 971 if (pending_swaps_ >= max_pending_swaps_) |
| 972 return false; |
| 973 |
| 958 if (active_tree_needs_first_draw_) | 974 if (active_tree_needs_first_draw_) |
| 959 return true; | 975 return true; |
| 960 | 976 |
| 961 if (!needs_redraw_) | 977 if (!needs_redraw_) |
| 962 return false; | 978 return false; |
| 963 | 979 |
| 964 // This is used to prioritize impl-thread draws when the main thread isn't | 980 // This is used to prioritize impl-thread draws when the main thread isn't |
| 965 // producing anything, e.g., after an aborted commit. We also check that we | 981 // producing anything, e.g., after an aborted commit. We also check that we |
| 966 // don't have a pending tree -- otherwise we should give it a chance to | 982 // don't have a pending tree -- otherwise we should give it a chance to |
| 967 // activate. | 983 // activate. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1036 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } | 1052 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } |
| 1037 | 1053 |
| 1038 void SchedulerStateMachine::SetNeedsManageTiles() { | 1054 void SchedulerStateMachine::SetNeedsManageTiles() { |
| 1039 if (!needs_manage_tiles_) { | 1055 if (!needs_manage_tiles_) { |
| 1040 TRACE_EVENT0("cc", | 1056 TRACE_EVENT0("cc", |
| 1041 "SchedulerStateMachine::SetNeedsManageTiles"); | 1057 "SchedulerStateMachine::SetNeedsManageTiles"); |
| 1042 needs_manage_tiles_ = true; | 1058 needs_manage_tiles_ = true; |
| 1043 } | 1059 } |
| 1044 } | 1060 } |
| 1045 | 1061 |
| 1062 void SchedulerStateMachine::SetMaxSwapsPending(int max) { |
| 1063 max_pending_swaps_ = max; |
| 1064 } |
| 1065 |
| 1066 void SchedulerStateMachine::DidSwapBuffers() { |
| 1067 pending_swaps_++; |
| 1068 DCHECK_LE(pending_swaps_, max_pending_swaps_); |
| 1069 } |
| 1070 |
| 1046 void SchedulerStateMachine::SetSwapUsedIncompleteTile( | 1071 void SchedulerStateMachine::SetSwapUsedIncompleteTile( |
| 1047 bool used_incomplete_tile) { | 1072 bool used_incomplete_tile) { |
| 1048 swap_used_incomplete_tile_ = used_incomplete_tile; | 1073 swap_used_incomplete_tile_ = used_incomplete_tile; |
| 1049 } | 1074 } |
| 1050 | 1075 |
| 1076 void SchedulerStateMachine::OnSwapBuffersComplete() { |
| 1077 DCHECK(HasInitializedOutputSurface()); |
| 1078 DCHECK_GT(pending_swaps_, 0); |
| 1079 pending_swaps_--; |
| 1080 } |
| 1081 |
| 1051 void SchedulerStateMachine::SetSmoothnessTakesPriority( | 1082 void SchedulerStateMachine::SetSmoothnessTakesPriority( |
| 1052 bool smoothness_takes_priority) { | 1083 bool smoothness_takes_priority) { |
| 1053 smoothness_takes_priority_ = smoothness_takes_priority; | 1084 smoothness_takes_priority_ = smoothness_takes_priority; |
| 1054 } | 1085 } |
| 1055 | 1086 |
| 1056 void SchedulerStateMachine::DidDrawIfPossibleCompleted( | 1087 void SchedulerStateMachine::DidDrawIfPossibleCompleted( |
| 1057 DrawSwapReadbackResult::DrawResult result) { | 1088 DrawSwapReadbackResult::DrawResult result) { |
| 1058 switch (result) { | 1089 switch (result) { |
| 1059 case DrawSwapReadbackResult::INVALID_RESULT: | 1090 case DrawSwapReadbackResult::INVALID_RESULT: |
| 1060 NOTREACHED() << "Uninitialized DrawSwapReadbackResult."; | 1091 NOTREACHED() << "Uninitialized DrawSwapReadbackResult."; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1146 // "Fill" the ManageTiles funnel. | 1177 // "Fill" the ManageTiles funnel. |
| 1147 manage_tiles_funnel_++; | 1178 manage_tiles_funnel_++; |
| 1148 } | 1179 } |
| 1149 | 1180 |
| 1150 void SchedulerStateMachine::DidLoseOutputSurface() { | 1181 void SchedulerStateMachine::DidLoseOutputSurface() { |
| 1151 if (output_surface_state_ == OUTPUT_SURFACE_LOST || | 1182 if (output_surface_state_ == OUTPUT_SURFACE_LOST || |
| 1152 output_surface_state_ == OUTPUT_SURFACE_CREATING) | 1183 output_surface_state_ == OUTPUT_SURFACE_CREATING) |
| 1153 return; | 1184 return; |
| 1154 output_surface_state_ = OUTPUT_SURFACE_LOST; | 1185 output_surface_state_ = OUTPUT_SURFACE_LOST; |
| 1155 needs_redraw_ = false; | 1186 needs_redraw_ = false; |
| 1187 pending_swaps_ = 0; |
| 1156 } | 1188 } |
| 1157 | 1189 |
| 1158 void SchedulerStateMachine::NotifyReadyToActivate() { | 1190 void SchedulerStateMachine::NotifyReadyToActivate() { |
| 1159 if (has_pending_tree_) | 1191 if (has_pending_tree_) |
| 1160 pending_tree_is_ready_for_activation_ = true; | 1192 pending_tree_is_ready_for_activation_ = true; |
| 1161 } | 1193 } |
| 1162 | 1194 |
| 1163 void SchedulerStateMachine::DidCreateAndInitializeOutputSurface() { | 1195 void SchedulerStateMachine::DidCreateAndInitializeOutputSurface() { |
| 1164 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_CREATING); | 1196 DCHECK_EQ(output_surface_state_, OUTPUT_SURFACE_CREATING); |
| 1165 output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT; | 1197 output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1186 case OUTPUT_SURFACE_ACTIVE: | 1218 case OUTPUT_SURFACE_ACTIVE: |
| 1187 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: | 1219 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: |
| 1188 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: | 1220 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: |
| 1189 return true; | 1221 return true; |
| 1190 } | 1222 } |
| 1191 NOTREACHED(); | 1223 NOTREACHED(); |
| 1192 return false; | 1224 return false; |
| 1193 } | 1225 } |
| 1194 | 1226 |
| 1195 } // namespace cc | 1227 } // namespace cc |
| OLD | NEW |