| 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 | 10 |
| 11 namespace cc { | 11 namespace cc { |
| 12 | 12 |
| 13 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) | 13 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) |
| 14 : settings_(settings), | 14 : settings_(settings), |
| 15 commit_state_(COMMIT_STATE_IDLE), | 15 commit_state_(COMMIT_STATE_IDLE), |
| 16 commit_count_(0), | 16 commit_count_(0), |
| 17 current_frame_number_(0), | 17 current_frame_number_(0), |
| 18 last_frame_number_where_begin_frame_sent_to_main_thread_(-1), |
| 18 last_frame_number_where_draw_was_called_(-1), | 19 last_frame_number_where_draw_was_called_(-1), |
| 19 last_frame_number_where_tree_activation_attempted_(-1), | 20 last_frame_number_where_tree_activation_attempted_(-1), |
| 20 last_frame_number_where_check_for_completed_tile_uploads_called_(-1), | 21 last_frame_number_where_check_for_completed_tile_uploads_called_(-1), |
| 21 consecutive_failed_draws_(0), | 22 consecutive_failed_draws_(0), |
| 22 maximum_number_of_failed_draws_before_draw_is_forced_(3), | 23 maximum_number_of_failed_draws_before_draw_is_forced_(3), |
| 23 needs_redraw_(false), | 24 needs_redraw_(false), |
| 24 swap_used_incomplete_tile_(false), | 25 swap_used_incomplete_tile_(false), |
| 25 needs_forced_redraw_(false), | 26 needs_forced_redraw_(false), |
| 26 needs_forced_redraw_after_next_commit_(false), | 27 needs_forced_redraw_after_next_commit_(false), |
| 27 needs_commit_(false), | 28 needs_commit_(false), |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 if (!BeginFrameNeededToDrawByImplThread()) | 178 if (!BeginFrameNeededToDrawByImplThread()) |
| 178 return true; | 179 return true; |
| 179 return false; | 180 return false; |
| 180 } | 181 } |
| 181 | 182 |
| 182 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { | 183 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { |
| 183 if (ShouldAcquireLayerTexturesForMainThread()) | 184 if (ShouldAcquireLayerTexturesForMainThread()) |
| 184 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD; | 185 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD; |
| 185 | 186 |
| 186 switch (commit_state_) { | 187 switch (commit_state_) { |
| 187 case COMMIT_STATE_IDLE: | 188 case COMMIT_STATE_IDLE: { |
| 188 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && | 189 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && |
| 189 needs_forced_redraw_) | 190 needs_forced_redraw_) |
| 190 return ACTION_DRAW_FORCED; | 191 return ACTION_DRAW_FORCED; |
| 191 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && | 192 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE && |
| 192 needs_forced_commit_) | 193 needs_forced_commit_) |
| 193 // TODO(enne): Should probably drop the active tree on force commit. | 194 // TODO(enne): Should probably drop the active tree on force commit. |
| 194 return has_pending_tree_ ? ACTION_NONE | 195 return has_pending_tree_ ? ACTION_NONE |
| 195 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; | 196 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; |
| 196 if (output_surface_state_ == OUTPUT_SURFACE_LOST && can_start_) | 197 if (output_surface_state_ == OUTPUT_SURFACE_LOST && can_start_) |
| 197 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; | 198 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; |
| 198 if (output_surface_state_ == OUTPUT_SURFACE_CREATING) | 199 if (output_surface_state_ == OUTPUT_SURFACE_CREATING) |
| 199 return ACTION_NONE; | 200 return ACTION_NONE; |
| 200 if (ShouldCheckForCompletedTileUploads()) | 201 if (ShouldCheckForCompletedTileUploads()) |
| 201 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; | 202 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; |
| 202 if (ShouldAttemptTreeActivation()) | 203 if (ShouldAttemptTreeActivation()) |
| 203 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 204 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; |
| 204 if (ShouldDraw()) { | 205 if (ShouldDraw()) { |
| 205 return needs_forced_redraw_ ? ACTION_DRAW_FORCED | 206 return needs_forced_redraw_ ? ACTION_DRAW_FORCED |
| 206 : ACTION_DRAW_IF_POSSIBLE; | 207 : ACTION_DRAW_IF_POSSIBLE; |
| 207 } | 208 } |
| 208 if (needs_commit_ && | 209 bool can_commit_this_frame = |
| 209 ((visible_ && output_surface_state_ == OUTPUT_SURFACE_ACTIVE) | 210 visible_ && |
| 210 || needs_forced_commit_)) | 211 current_frame_number_ > |
| 212 last_frame_number_where_begin_frame_sent_to_main_thread_; |
| 213 if (needs_commit_ && ((can_commit_this_frame && |
| 214 output_surface_state_ == OUTPUT_SURFACE_ACTIVE) || |
| 215 needs_forced_commit_)) |
| 211 // TODO(enne): Should probably drop the active tree on force commit. | 216 // TODO(enne): Should probably drop the active tree on force commit. |
| 212 return has_pending_tree_ ? ACTION_NONE | 217 return has_pending_tree_ ? ACTION_NONE |
| 213 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; | 218 : ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; |
| 214 return ACTION_NONE; | 219 return ACTION_NONE; |
| 215 | 220 } |
| 216 case COMMIT_STATE_FRAME_IN_PROGRESS: | 221 case COMMIT_STATE_FRAME_IN_PROGRESS: |
| 217 if (ShouldCheckForCompletedTileUploads()) | 222 if (ShouldCheckForCompletedTileUploads()) |
| 218 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; | 223 return ACTION_CHECK_FOR_COMPLETED_TILE_UPLOADS; |
| 219 if (ShouldAttemptTreeActivation()) | 224 if (ShouldAttemptTreeActivation()) |
| 220 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; | 225 return ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED; |
| 221 if (ShouldDraw()) { | 226 if (ShouldDraw()) { |
| 222 return needs_forced_redraw_ ? ACTION_DRAW_FORCED | 227 return needs_forced_redraw_ ? ACTION_DRAW_FORCED |
| 223 : ACTION_DRAW_IF_POSSIBLE; | 228 : ACTION_DRAW_IF_POSSIBLE; |
| 224 } | 229 } |
| 225 return ACTION_NONE; | 230 return ACTION_NONE; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 current_frame_number_; | 274 current_frame_number_; |
| 270 return; | 275 return; |
| 271 | 276 |
| 272 case ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED: | 277 case ACTION_ACTIVATE_PENDING_TREE_IF_NEEDED: |
| 273 last_frame_number_where_tree_activation_attempted_ = | 278 last_frame_number_where_tree_activation_attempted_ = |
| 274 current_frame_number_; | 279 current_frame_number_; |
| 275 return; | 280 return; |
| 276 | 281 |
| 277 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: | 282 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: |
| 278 DCHECK(!has_pending_tree_); | 283 DCHECK(!has_pending_tree_); |
| 279 DCHECK(visible_ || needs_forced_commit_); | 284 if (!needs_forced_commit_) { |
| 285 DCHECK(visible_); |
| 286 DCHECK_GT(current_frame_number_, |
| 287 last_frame_number_where_begin_frame_sent_to_main_thread_); |
| 288 } |
| 280 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; | 289 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; |
| 281 needs_commit_ = false; | 290 needs_commit_ = false; |
| 282 needs_forced_commit_ = false; | 291 needs_forced_commit_ = false; |
| 292 last_frame_number_where_begin_frame_sent_to_main_thread_ = |
| 293 current_frame_number_; |
| 283 return; | 294 return; |
| 284 | 295 |
| 285 case ACTION_COMMIT: | 296 case ACTION_COMMIT: |
| 286 commit_count_++; | 297 commit_count_++; |
| 287 if (expect_immediate_begin_frame_for_main_thread_) | 298 if (expect_immediate_begin_frame_for_main_thread_) |
| 288 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW; | 299 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW; |
| 289 else | 300 else |
| 290 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; | 301 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; |
| 291 // When impl-side painting, we draw on activation instead of on commit. | 302 // When impl-side painting, we draw on activation instead of on commit. |
| 292 if (!settings_.impl_side_painting) | 303 if (!settings_.impl_side_painting) |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 } | 426 } |
| 416 | 427 |
| 417 void SchedulerStateMachine::FinishCommit() { | 428 void SchedulerStateMachine::FinishCommit() { |
| 418 DCHECK(commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS || | 429 DCHECK(commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS || |
| 419 (expect_immediate_begin_frame_for_main_thread_ && | 430 (expect_immediate_begin_frame_for_main_thread_ && |
| 420 commit_state_ != COMMIT_STATE_IDLE)) | 431 commit_state_ != COMMIT_STATE_IDLE)) |
| 421 << ToString(); | 432 << ToString(); |
| 422 commit_state_ = COMMIT_STATE_READY_TO_COMMIT; | 433 commit_state_ = COMMIT_STATE_READY_TO_COMMIT; |
| 423 } | 434 } |
| 424 | 435 |
| 425 void SchedulerStateMachine::BeginFrameAbortedByMainThread() { | 436 void SchedulerStateMachine::BeginFrameAbortedByMainThread(bool cancel_commit) { |
| 426 DCHECK_EQ(commit_state_, COMMIT_STATE_FRAME_IN_PROGRESS); | 437 DCHECK_EQ(commit_state_, COMMIT_STATE_FRAME_IN_PROGRESS); |
| 427 if (expect_immediate_begin_frame_for_main_thread_) { | 438 if (expect_immediate_begin_frame_for_main_thread_) { |
| 428 expect_immediate_begin_frame_for_main_thread_ = false; | 439 expect_immediate_begin_frame_for_main_thread_ = false; |
| 440 } else if (cancel_commit) { |
| 441 commit_state_ = COMMIT_STATE_IDLE; |
| 429 } else { | 442 } else { |
| 430 commit_state_ = COMMIT_STATE_IDLE; | 443 commit_state_ = COMMIT_STATE_IDLE; |
| 431 SetNeedsCommit(); | 444 SetNeedsCommit(); |
| 432 } | 445 } |
| 433 } | 446 } |
| 434 | 447 |
| 435 void SchedulerStateMachine::DidLoseOutputSurface() { | 448 void SchedulerStateMachine::DidLoseOutputSurface() { |
| 436 if (output_surface_state_ == OUTPUT_SURFACE_LOST || | 449 if (output_surface_state_ == OUTPUT_SURFACE_LOST || |
| 437 output_surface_state_ == OUTPUT_SURFACE_CREATING) | 450 output_surface_state_ == OUTPUT_SURFACE_CREATING) |
| 438 return; | 451 return; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 464 bool SchedulerStateMachine::HasInitializedOutputSurface() const { | 477 bool SchedulerStateMachine::HasInitializedOutputSurface() const { |
| 465 return output_surface_state_ == OUTPUT_SURFACE_ACTIVE; | 478 return output_surface_state_ == OUTPUT_SURFACE_ACTIVE; |
| 466 } | 479 } |
| 467 | 480 |
| 468 void SchedulerStateMachine::SetMaximumNumberOfFailedDrawsBeforeDrawIsForced( | 481 void SchedulerStateMachine::SetMaximumNumberOfFailedDrawsBeforeDrawIsForced( |
| 469 int num_draws) { | 482 int num_draws) { |
| 470 maximum_number_of_failed_draws_before_draw_is_forced_ = num_draws; | 483 maximum_number_of_failed_draws_before_draw_is_forced_ = num_draws; |
| 471 } | 484 } |
| 472 | 485 |
| 473 } // namespace cc | 486 } // namespace cc |
| OLD | NEW |