| 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" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "ui/gfx/frame_time.h" | 12 #include "ui/gfx/frame_time.h" |
| 13 | 13 |
| 14 namespace cc { | 14 namespace cc { |
| 15 | 15 |
| 16 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) | 16 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) |
| 17 : settings_(settings), | 17 : settings_(settings), |
| 18 output_surface_state_(OUTPUT_SURFACE_LOST), | 18 output_surface_state_(OUTPUT_SURFACE_LOST), |
| 19 begin_impl_frame_state_(BEGIN_IMPL_FRAME_STATE_IDLE), | 19 begin_impl_frame_state_(BEGIN_IMPL_FRAME_STATE_IDLE), |
| 20 commit_state_(COMMIT_STATE_IDLE), | 20 commit_state_(COMMIT_STATE_IDLE), |
| 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_failed_draws_(0), | 30 consecutive_checkerboard_animations_(0), |
| 31 needs_redraw_(false), | 31 needs_redraw_(false), |
| 32 needs_manage_tiles_(false), | 32 needs_manage_tiles_(false), |
| 33 swap_used_incomplete_tile_(false), | 33 swap_used_incomplete_tile_(false), |
| 34 needs_commit_(false), | 34 needs_commit_(false), |
| 35 main_thread_needs_layer_textures_(false), | 35 main_thread_needs_layer_textures_(false), |
| 36 inside_poll_for_anticipated_draw_triggers_(false), | 36 inside_poll_for_anticipated_draw_triggers_(false), |
| 37 visible_(false), | 37 visible_(false), |
| 38 can_start_(false), | 38 can_start_(false), |
| 39 can_draw_(false), | 39 can_draw_(false), |
| 40 has_pending_tree_(false), | 40 has_pending_tree_(false), |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 minor_state->SetInteger("last_frame_number_swap_performed", | 233 minor_state->SetInteger("last_frame_number_swap_performed", |
| 234 last_frame_number_swap_performed_); | 234 last_frame_number_swap_performed_); |
| 235 minor_state->SetInteger( | 235 minor_state->SetInteger( |
| 236 "last_frame_number_begin_main_frame_sent", | 236 "last_frame_number_begin_main_frame_sent", |
| 237 last_frame_number_begin_main_frame_sent_); | 237 last_frame_number_begin_main_frame_sent_); |
| 238 minor_state->SetInteger( | 238 minor_state->SetInteger( |
| 239 "last_frame_number_update_visible_tiles_was_called", | 239 "last_frame_number_update_visible_tiles_was_called", |
| 240 last_frame_number_update_visible_tiles_was_called_); | 240 last_frame_number_update_visible_tiles_was_called_); |
| 241 | 241 |
| 242 minor_state->SetInteger("manage_tiles_funnel", manage_tiles_funnel_); | 242 minor_state->SetInteger("manage_tiles_funnel", manage_tiles_funnel_); |
| 243 minor_state->SetInteger("consecutive_failed_draws", | 243 minor_state->SetInteger("consecutive_checkerboard_animations", |
| 244 consecutive_failed_draws_); | 244 consecutive_checkerboard_animations_); |
| 245 minor_state->SetBoolean("needs_redraw", needs_redraw_); | 245 minor_state->SetBoolean("needs_redraw", needs_redraw_); |
| 246 minor_state->SetBoolean("needs_manage_tiles", needs_manage_tiles_); | 246 minor_state->SetBoolean("needs_manage_tiles", needs_manage_tiles_); |
| 247 minor_state->SetBoolean("swap_used_incomplete_tile", | 247 minor_state->SetBoolean("swap_used_incomplete_tile", |
| 248 swap_used_incomplete_tile_); | 248 swap_used_incomplete_tile_); |
| 249 minor_state->SetBoolean("needs_commit", needs_commit_); | 249 minor_state->SetBoolean("needs_commit", needs_commit_); |
| 250 minor_state->SetBoolean("main_thread_needs_layer_textures", | 250 minor_state->SetBoolean("main_thread_needs_layer_textures", |
| 251 main_thread_needs_layer_textures_); | 251 main_thread_needs_layer_textures_); |
| 252 minor_state->SetBoolean("visible", visible_); | 252 minor_state->SetBoolean("visible", visible_); |
| 253 minor_state->SetBoolean("can_start", can_start_); | 253 minor_state->SetBoolean("can_start", can_start_); |
| 254 minor_state->SetBoolean("can_draw", can_draw_); | 254 minor_state->SetBoolean("can_draw", can_draw_); |
| (...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 void SchedulerStateMachine::SetSwapUsedIncompleteTile( | 1015 void SchedulerStateMachine::SetSwapUsedIncompleteTile( |
| 1016 bool used_incomplete_tile) { | 1016 bool used_incomplete_tile) { |
| 1017 swap_used_incomplete_tile_ = used_incomplete_tile; | 1017 swap_used_incomplete_tile_ = used_incomplete_tile; |
| 1018 } | 1018 } |
| 1019 | 1019 |
| 1020 void SchedulerStateMachine::SetSmoothnessTakesPriority( | 1020 void SchedulerStateMachine::SetSmoothnessTakesPriority( |
| 1021 bool smoothness_takes_priority) { | 1021 bool smoothness_takes_priority) { |
| 1022 smoothness_takes_priority_ = smoothness_takes_priority; | 1022 smoothness_takes_priority_ = smoothness_takes_priority; |
| 1023 } | 1023 } |
| 1024 | 1024 |
| 1025 void SchedulerStateMachine::DidDrawIfPossibleCompleted(bool success) { | 1025 void SchedulerStateMachine::DidDrawIfPossibleCompleted( |
| 1026 draw_if_possible_failed_ = !success; | 1026 DrawSwapReadbackResult::DrawResult result) { |
| 1027 if (draw_if_possible_failed_) { | 1027 switch (result) { |
| 1028 needs_redraw_ = true; | 1028 case DrawSwapReadbackResult::INVALID_RESULT: |
| 1029 NOTREACHED() << "Uninitialized DrawSwapReadbackResult."; |
| 1030 break; |
| 1031 case DrawSwapReadbackResult::DRAW_SUCCESS: |
| 1032 consecutive_checkerboard_animations_ = 0; |
| 1033 forced_redraw_state_ = FORCED_REDRAW_STATE_IDLE; |
| 1034 break; |
| 1035 case DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS: |
| 1036 needs_redraw_ = true; |
| 1029 | 1037 |
| 1030 // If we're already in the middle of a redraw, we don't need to | 1038 // If we're already in the middle of a redraw, we don't need to |
| 1031 // restart it. | 1039 // restart it. |
| 1032 if (forced_redraw_state_ != FORCED_REDRAW_STATE_IDLE) | 1040 if (forced_redraw_state_ != FORCED_REDRAW_STATE_IDLE) |
| 1033 return; | 1041 return; |
| 1034 | 1042 |
| 1035 needs_commit_ = true; | 1043 needs_commit_ = true; |
| 1036 consecutive_failed_draws_++; | 1044 consecutive_checkerboard_animations_++; |
| 1037 if (settings_.timeout_and_draw_when_animation_checkerboards && | 1045 if (settings_.timeout_and_draw_when_animation_checkerboards && |
| 1038 consecutive_failed_draws_ >= | 1046 consecutive_checkerboard_animations_ >= |
| 1039 settings_.maximum_number_of_failed_draws_before_draw_is_forced_) { | 1047 settings_.maximum_number_of_failed_draws_before_draw_is_forced_) { |
| 1040 consecutive_failed_draws_ = 0; | 1048 consecutive_checkerboard_animations_ = 0; |
| 1041 // We need to force a draw, but it doesn't make sense to do this until | 1049 // We need to force a draw, but it doesn't make sense to do this until |
| 1042 // we've committed and have new textures. | 1050 // we've committed and have new textures. |
| 1043 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_COMMIT; | 1051 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_COMMIT; |
| 1044 } | 1052 } |
| 1045 } else { | 1053 break; |
| 1046 consecutive_failed_draws_ = 0; | |
| 1047 forced_redraw_state_ = FORCED_REDRAW_STATE_IDLE; | |
| 1048 } | 1054 } |
| 1049 } | 1055 } |
| 1050 | 1056 |
| 1051 void SchedulerStateMachine::SetNeedsCommit() { needs_commit_ = true; } | 1057 void SchedulerStateMachine::SetNeedsCommit() { needs_commit_ = true; } |
| 1052 | 1058 |
| 1053 void SchedulerStateMachine::SetNeedsForcedCommitForReadback() { | 1059 void SchedulerStateMachine::SetNeedsForcedCommitForReadback() { |
| 1054 // If this is called in READBACK_STATE_IDLE, this is a "first" readback | 1060 // If this is called in READBACK_STATE_IDLE, this is a "first" readback |
| 1055 // request. | 1061 // request. |
| 1056 // If this is called in READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT, this | 1062 // If this is called in READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT, this |
| 1057 // is a back-to-back readback request that started before the replacement | 1063 // is a back-to-back readback request that started before the replacement |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1129 case OUTPUT_SURFACE_ACTIVE: | 1135 case OUTPUT_SURFACE_ACTIVE: |
| 1130 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: | 1136 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: |
| 1131 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: | 1137 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: |
| 1132 return true; | 1138 return true; |
| 1133 } | 1139 } |
| 1134 NOTREACHED(); | 1140 NOTREACHED(); |
| 1135 return false; | 1141 return false; |
| 1136 } | 1142 } |
| 1137 | 1143 |
| 1138 } // namespace cc | 1144 } // namespace cc |
| OLD | NEW |