| 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/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 9 | 9 |
| 10 namespace cc { | 10 namespace cc { |
| 11 | 11 |
| 12 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) | 12 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) |
| 13 : settings_(settings), | 13 : settings_(settings), |
| 14 commit_state_(COMMIT_STATE_IDLE), | 14 commit_state_(COMMIT_STATE_IDLE), |
| 15 current_frame_number_(0), | 15 current_frame_number_(0), |
| 16 last_frame_number_where_draw_was_called_(-1), | 16 last_frame_number_where_draw_was_called_(-1), |
| 17 last_frame_number_where_tree_activation_attempted_(-1), | 17 last_frame_number_where_tree_activation_attempted_(-1), |
| 18 last_frame_number_where_check_for_completed_tile_uploads_called_(-1), | 18 last_frame_number_where_check_for_completed_tile_uploads_called_(-1), |
| 19 consecutive_failed_draws_(0), | 19 consecutive_failed_draws_(0), |
| 20 maximum_number_of_failed_draws_before_draw_is_forced_(3), | 20 maximum_number_of_failed_draws_before_draw_is_forced_(3), |
| 21 needs_redraw_(false), | 21 needs_redraw_(false), |
| 22 swap_used_incomplete_tile_(false), | 22 swap_used_incomplete_tile_(false), |
| 23 needs_forced_redraw_(false), | 23 needs_forced_redraw_(false), |
| 24 needs_forced_redraw_after_next_commit_(false), | 24 needs_forced_redraw_after_next_commit_(false), |
| 25 needs_commit_(false), | 25 needs_commit_(false), |
| 26 needs_forced_commit_(false), | 26 needs_forced_commit_(false), |
| 27 expect_immediate_begin_frame_(false), | 27 expect_immediate_begin_frame_(false), |
| 28 main_thread_needs_layer_textures_(false), | 28 main_thread_needs_layer_textures_(false), |
| 29 inside_vsync_(false), | 29 inside_begin_frame_(false), |
| 30 visible_(false), | 30 visible_(false), |
| 31 can_start_(false), | 31 can_start_(false), |
| 32 can_draw_(false), | 32 can_draw_(false), |
| 33 has_pending_tree_(false), | 33 has_pending_tree_(false), |
| 34 draw_if_possible_failed_(false), | 34 draw_if_possible_failed_(false), |
| 35 texture_state_(LAYER_TEXTURE_STATE_UNLOCKED), | 35 texture_state_(LAYER_TEXTURE_STATE_UNLOCKED), |
| 36 output_surface_state_(OUTPUT_SURFACE_LOST), | 36 output_surface_state_(OUTPUT_SURFACE_LOST), |
| 37 did_create_and_initialize_first_output_surface_(false) {} | 37 did_create_and_initialize_first_output_surface_(false) {} |
| 38 | 38 |
| 39 std::string SchedulerStateMachine::ToString() { | 39 std::string SchedulerStateMachine::ToString() { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 needs_forced_redraw_after_next_commit_); | 71 needs_forced_redraw_after_next_commit_); |
| 72 base::StringAppendF(&str, "needs_commit_ = %d; ", needs_commit_); | 72 base::StringAppendF(&str, "needs_commit_ = %d; ", needs_commit_); |
| 73 base::StringAppendF( | 73 base::StringAppendF( |
| 74 &str, "needs_forced_commit_ = %d; ", needs_forced_commit_); | 74 &str, "needs_forced_commit_ = %d; ", needs_forced_commit_); |
| 75 base::StringAppendF(&str, | 75 base::StringAppendF(&str, |
| 76 "expect_immediate_begin_frame_ = %d; ", | 76 "expect_immediate_begin_frame_ = %d; ", |
| 77 expect_immediate_begin_frame_); | 77 expect_immediate_begin_frame_); |
| 78 base::StringAppendF(&str, | 78 base::StringAppendF(&str, |
| 79 "main_thread_needs_layer_textures_ = %d; ", | 79 "main_thread_needs_layer_textures_ = %d; ", |
| 80 main_thread_needs_layer_textures_); | 80 main_thread_needs_layer_textures_); |
| 81 base::StringAppendF(&str, "inside_vsync_ = %d; ", inside_vsync_); | 81 base::StringAppendF(&str, "inside_begin_frame_ = %d; ", inside_begin_frame_); |
| 82 base::StringAppendF(&str, "visible_ = %d; ", visible_); | 82 base::StringAppendF(&str, "visible_ = %d; ", visible_); |
| 83 base::StringAppendF(&str, "can_start_ = %d; ", can_start_); | 83 base::StringAppendF(&str, "can_start_ = %d; ", can_start_); |
| 84 base::StringAppendF(&str, "can_draw_ = %d; ", can_draw_); | 84 base::StringAppendF(&str, "can_draw_ = %d; ", can_draw_); |
| 85 base::StringAppendF( | 85 base::StringAppendF( |
| 86 &str, "draw_if_possible_failed_ = %d; ", draw_if_possible_failed_); | 86 &str, "draw_if_possible_failed_ = %d; ", draw_if_possible_failed_); |
| 87 base::StringAppendF(&str, "has_pending_tree_ = %d; ", has_pending_tree_); | 87 base::StringAppendF(&str, "has_pending_tree_ = %d; ", has_pending_tree_); |
| 88 base::StringAppendF(&str, "texture_state_ = %d; ", texture_state_); | 88 base::StringAppendF(&str, "texture_state_ = %d; ", texture_state_); |
| 89 base::StringAppendF( | 89 base::StringAppendF( |
| 90 &str, "output_surface_state_ = %d; ", output_surface_state_); | 90 &str, "output_surface_state_ = %d; ", output_surface_state_); |
| 91 return str; | 91 return str; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 122 return false; | 122 return false; |
| 123 return true; | 123 return true; |
| 124 } | 124 } |
| 125 | 125 |
| 126 bool SchedulerStateMachine::ShouldDraw() const { | 126 bool SchedulerStateMachine::ShouldDraw() const { |
| 127 if (needs_forced_redraw_) | 127 if (needs_forced_redraw_) |
| 128 return true; | 128 return true; |
| 129 | 129 |
| 130 if (!ScheduledToDraw()) | 130 if (!ScheduledToDraw()) |
| 131 return false; | 131 return false; |
| 132 if (!inside_vsync_) | 132 if (!inside_begin_frame_) |
| 133 return false; | 133 return false; |
| 134 if (HasDrawnThisFrame()) | 134 if (HasDrawnThisFrame()) |
| 135 return false; | 135 return false; |
| 136 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE) | 136 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE) |
| 137 return false; | 137 return false; |
| 138 return true; | 138 return true; |
| 139 } | 139 } |
| 140 | 140 |
| 141 bool SchedulerStateMachine::ShouldAttemptTreeActivation() const { | 141 bool SchedulerStateMachine::ShouldAttemptTreeActivation() const { |
| 142 return has_pending_tree_ && inside_vsync_ && | 142 return has_pending_tree_ && inside_begin_frame_ && |
| 143 !HasAttemptedTreeActivationThisFrame(); | 143 !HasAttemptedTreeActivationThisFrame(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 bool SchedulerStateMachine::ShouldCheckForCompletedTileUploads() const { | 146 bool SchedulerStateMachine::ShouldCheckForCompletedTileUploads() const { |
| 147 if (!settings_.impl_side_painting) | 147 if (!settings_.impl_side_painting) |
| 148 return false; | 148 return false; |
| 149 if (HasCheckedForCompletedTileUploadsThisFrame()) | 149 if (HasCheckedForCompletedTileUploadsThisFrame()) |
| 150 return false; | 150 return false; |
| 151 | 151 |
| 152 return ShouldAttemptTreeActivation() || ShouldDraw() || | 152 return ShouldAttemptTreeActivation() || ShouldDraw() || |
| 153 swap_used_incomplete_tile_; | 153 swap_used_incomplete_tile_; |
| 154 } | 154 } |
| 155 | 155 |
| 156 bool SchedulerStateMachine::ShouldAcquireLayerTexturesForMainThread() const { | 156 bool SchedulerStateMachine::ShouldAcquireLayerTexturesForMainThread() const { |
| 157 if (!main_thread_needs_layer_textures_) | 157 if (!main_thread_needs_layer_textures_) |
| 158 return false; | 158 return false; |
| 159 if (texture_state_ == LAYER_TEXTURE_STATE_UNLOCKED) | 159 if (texture_state_ == LAYER_TEXTURE_STATE_UNLOCKED) |
| 160 return true; | 160 return true; |
| 161 DCHECK_EQ(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD); | 161 DCHECK_EQ(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD); |
| 162 // Transfer the lock from impl thread to main thread immediately if the | 162 // Transfer the lock from impl thread to main thread immediately if the |
| 163 // impl thread is not even scheduled to draw. Guards against deadlocking. | 163 // impl thread is not even scheduled to draw. Guards against deadlocking. |
| 164 if (!ScheduledToDraw()) | 164 if (!ScheduledToDraw()) |
| 165 return true; | 165 return true; |
| 166 if (!VSyncCallbackNeeded()) | 166 if (!BeginFrameCallbackNeeded()) |
| 167 return true; | 167 return true; |
| 168 return false; | 168 return false; |
| 169 } | 169 } |
| 170 | 170 |
| 171 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { | 171 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { |
| 172 if (ShouldAcquireLayerTexturesForMainThread()) | 172 if (ShouldAcquireLayerTexturesForMainThread()) |
| 173 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD; | 173 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD; |
| 174 | 174 |
| 175 switch (commit_state_) { | 175 switch (commit_state_) { |
| 176 case COMMIT_STATE_IDLE: | 176 case COMMIT_STATE_IDLE: |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 | 286 |
| 287 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD; | 287 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD; |
| 288 return; | 288 return; |
| 289 | 289 |
| 290 case ACTION_DRAW_FORCED: | 290 case ACTION_DRAW_FORCED: |
| 291 case ACTION_DRAW_IF_POSSIBLE: | 291 case ACTION_DRAW_IF_POSSIBLE: |
| 292 needs_redraw_ = false; | 292 needs_redraw_ = false; |
| 293 needs_forced_redraw_ = false; | 293 needs_forced_redraw_ = false; |
| 294 draw_if_possible_failed_ = false; | 294 draw_if_possible_failed_ = false; |
| 295 swap_used_incomplete_tile_ = false; | 295 swap_used_incomplete_tile_ = false; |
| 296 if (inside_vsync_) | 296 if (inside_begin_frame_) |
| 297 last_frame_number_where_draw_was_called_ = current_frame_number_; | 297 last_frame_number_where_draw_was_called_ = current_frame_number_; |
| 298 if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW) { | 298 if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW) { |
| 299 DCHECK(expect_immediate_begin_frame_); | 299 DCHECK(expect_immediate_begin_frame_); |
| 300 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; | 300 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; |
| 301 expect_immediate_begin_frame_ = false; | 301 expect_immediate_begin_frame_ = false; |
| 302 } else if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW) { | 302 } else if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW) { |
| 303 commit_state_ = COMMIT_STATE_IDLE; | 303 commit_state_ = COMMIT_STATE_IDLE; |
| 304 } | 304 } |
| 305 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) | 305 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) |
| 306 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; | 306 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 320 return; | 320 return; |
| 321 } | 321 } |
| 322 } | 322 } |
| 323 | 323 |
| 324 void SchedulerStateMachine::SetMainThreadNeedsLayerTextures() { | 324 void SchedulerStateMachine::SetMainThreadNeedsLayerTextures() { |
| 325 DCHECK(!main_thread_needs_layer_textures_); | 325 DCHECK(!main_thread_needs_layer_textures_); |
| 326 DCHECK_NE(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD); | 326 DCHECK_NE(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD); |
| 327 main_thread_needs_layer_textures_ = true; | 327 main_thread_needs_layer_textures_ = true; |
| 328 } | 328 } |
| 329 | 329 |
| 330 bool SchedulerStateMachine::VSyncCallbackNeeded() const { | 330 bool SchedulerStateMachine::BeginFrameCallbackNeeded() const { |
| 331 // If we have a pending tree, need to keep getting notifications until | 331 // If we have a pending tree, need to keep getting notifications until |
| 332 // the tree is ready to be swapped. | 332 // the tree is ready to be swapped. |
| 333 if (has_pending_tree_) | 333 if (has_pending_tree_) |
| 334 return true; | 334 return true; |
| 335 | 335 |
| 336 // If we can't draw, don't tick until we are notified that we can draw again. | 336 // If we can't draw, don't tick until we are notified that we can draw again. |
| 337 if (!can_draw_) | 337 if (!can_draw_) |
| 338 return false; | 338 return false; |
| 339 | 339 |
| 340 if (needs_forced_redraw_) | 340 if (needs_forced_redraw_) |
| 341 return true; | 341 return true; |
| 342 | 342 |
| 343 if (visible_ && swap_used_incomplete_tile_) | 343 if (visible_ && swap_used_incomplete_tile_) |
| 344 return true; | 344 return true; |
| 345 | 345 |
| 346 return needs_redraw_ && visible_ && | 346 return needs_redraw_ && visible_ && |
| 347 output_surface_state_ == OUTPUT_SURFACE_ACTIVE; | 347 output_surface_state_ == OUTPUT_SURFACE_ACTIVE; |
| 348 } | 348 } |
| 349 | 349 |
| 350 void SchedulerStateMachine::DidEnterVSync() { inside_vsync_ = true; } | 350 void SchedulerStateMachine::DidEnterBeginFrame() { inside_begin_frame_ = true; } |
| 351 | 351 |
| 352 void SchedulerStateMachine::DidLeaveVSync() { | 352 void SchedulerStateMachine::DidLeaveBeginFrame() { |
| 353 current_frame_number_++; | 353 current_frame_number_++; |
| 354 inside_vsync_ = false; | 354 inside_begin_frame_ = false; |
| 355 } | 355 } |
| 356 | 356 |
| 357 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } | 357 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } |
| 358 | 358 |
| 359 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } | 359 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } |
| 360 | 360 |
| 361 void SchedulerStateMachine::DidSwapUseIncompleteTile() { | 361 void SchedulerStateMachine::DidSwapUseIncompleteTile() { |
| 362 swap_used_incomplete_tile_ = true; | 362 swap_used_incomplete_tile_ = true; |
| 363 } | 363 } |
| 364 | 364 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 bool SchedulerStateMachine::HasInitializedOutputSurface() const { | 441 bool SchedulerStateMachine::HasInitializedOutputSurface() const { |
| 442 return output_surface_state_ == OUTPUT_SURFACE_ACTIVE; | 442 return output_surface_state_ == OUTPUT_SURFACE_ACTIVE; |
| 443 } | 443 } |
| 444 | 444 |
| 445 void SchedulerStateMachine::SetMaximumNumberOfFailedDrawsBeforeDrawIsForced( | 445 void SchedulerStateMachine::SetMaximumNumberOfFailedDrawsBeforeDrawIsForced( |
| 446 int num_draws) { | 446 int num_draws) { |
| 447 maximum_number_of_failed_draws_before_draw_is_forced_ = num_draws; | 447 maximum_number_of_failed_draws_before_draw_is_forced_ = num_draws; |
| 448 } | 448 } |
| 449 | 449 |
| 450 } // namespace cc | 450 } // namespace cc |
| OLD | NEW |