| 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" | |
| 8 #include "base/logging.h" | 7 #include "base/logging.h" |
| 9 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 10 | 9 |
| 11 namespace cc { | 10 namespace cc { |
| 12 | 11 |
| 13 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) | 12 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) |
| 14 : settings_(settings), | 13 : settings_(settings), |
| 15 commit_state_(COMMIT_STATE_IDLE), | 14 commit_state_(COMMIT_STATE_IDLE), |
| 16 commit_count_(0), | |
| 17 current_frame_number_(0), | 15 current_frame_number_(0), |
| 18 last_frame_number_where_draw_was_called_(-1), | 16 last_frame_number_where_draw_was_called_(-1), |
| 19 last_frame_number_where_tree_activation_attempted_(-1), | 17 last_frame_number_where_tree_activation_attempted_(-1), |
| 20 last_frame_number_where_check_for_completed_tile_uploads_called_(-1), | 18 last_frame_number_where_check_for_completed_tile_uploads_called_(-1), |
| 21 consecutive_failed_draws_(0), | 19 consecutive_failed_draws_(0), |
| 22 maximum_number_of_failed_draws_before_draw_is_forced_(3), | 20 maximum_number_of_failed_draws_before_draw_is_forced_(3), |
| 23 needs_redraw_(false), | 21 needs_redraw_(false), |
| 24 swap_used_incomplete_tile_(false), | 22 swap_used_incomplete_tile_(false), |
| 25 needs_forced_redraw_(false), | 23 needs_forced_redraw_(false), |
| 26 needs_forced_redraw_after_next_commit_(false), | 24 needs_forced_redraw_after_next_commit_(false), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 37 texture_state_(LAYER_TEXTURE_STATE_UNLOCKED), | 35 texture_state_(LAYER_TEXTURE_STATE_UNLOCKED), |
| 38 output_surface_state_(OUTPUT_SURFACE_LOST), | 36 output_surface_state_(OUTPUT_SURFACE_LOST), |
| 39 did_create_and_initialize_first_output_surface_(false) {} | 37 did_create_and_initialize_first_output_surface_(false) {} |
| 40 | 38 |
| 41 std::string SchedulerStateMachine::ToString() { | 39 std::string SchedulerStateMachine::ToString() { |
| 42 std::string str; | 40 std::string str; |
| 43 base::StringAppendF(&str, | 41 base::StringAppendF(&str, |
| 44 "settings_.impl_side_painting = %d; ", | 42 "settings_.impl_side_painting = %d; ", |
| 45 settings_.impl_side_painting); | 43 settings_.impl_side_painting); |
| 46 base::StringAppendF(&str, "commit_state_ = %d; ", commit_state_); | 44 base::StringAppendF(&str, "commit_state_ = %d; ", commit_state_); |
| 47 base::StringAppendF(&str, "commit_count_ = %d; ", commit_count_); | |
| 48 base::StringAppendF( | 45 base::StringAppendF( |
| 49 &str, "current_frame_number_ = %d; ", current_frame_number_); | 46 &str, "current_frame_number_ = %d; ", current_frame_number_); |
| 50 base::StringAppendF(&str, | 47 base::StringAppendF(&str, |
| 51 "last_frame_number_where_draw_was_called_ = %d; ", | 48 "last_frame_number_where_draw_was_called_ = %d; ", |
| 52 last_frame_number_where_draw_was_called_); | 49 last_frame_number_where_draw_was_called_); |
| 53 base::StringAppendF( | 50 base::StringAppendF( |
| 54 &str, | 51 &str, |
| 55 "last_frame_number_where_tree_activation_attempted_ = %d; ", | 52 "last_frame_number_where_tree_activation_attempted_ = %d; ", |
| 56 last_frame_number_where_tree_activation_attempted_); | 53 last_frame_number_where_tree_activation_attempted_); |
| 57 base::StringAppendF( | 54 base::StringAppendF( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 76 base::StringAppendF( | 73 base::StringAppendF( |
| 77 &str, "needs_forced_commit_ = %d; ", needs_forced_commit_); | 74 &str, "needs_forced_commit_ = %d; ", needs_forced_commit_); |
| 78 base::StringAppendF(&str, | 75 base::StringAppendF(&str, |
| 79 "expect_immediate_begin_frame_for_main_thread_ = %d; ", | 76 "expect_immediate_begin_frame_for_main_thread_ = %d; ", |
| 80 expect_immediate_begin_frame_for_main_thread_); | 77 expect_immediate_begin_frame_for_main_thread_); |
| 81 base::StringAppendF(&str, | 78 base::StringAppendF(&str, |
| 82 "main_thread_needs_layer_textures_ = %d; ", | 79 "main_thread_needs_layer_textures_ = %d; ", |
| 83 main_thread_needs_layer_textures_); | 80 main_thread_needs_layer_textures_); |
| 84 base::StringAppendF(&str, "inside_begin_frame_ = %d; ", | 81 base::StringAppendF(&str, "inside_begin_frame_ = %d; ", |
| 85 inside_begin_frame_); | 82 inside_begin_frame_); |
| 86 base::StringAppendF(&str, "last_frame_time_ = %"PRId64"; ", | |
| 87 (last_frame_time_ - base::TimeTicks()).InMilliseconds()); | |
| 88 base::StringAppendF(&str, "visible_ = %d; ", visible_); | 83 base::StringAppendF(&str, "visible_ = %d; ", visible_); |
| 89 base::StringAppendF(&str, "can_start_ = %d; ", can_start_); | 84 base::StringAppendF(&str, "can_start_ = %d; ", can_start_); |
| 90 base::StringAppendF(&str, "can_draw_ = %d; ", can_draw_); | 85 base::StringAppendF(&str, "can_draw_ = %d; ", can_draw_); |
| 91 base::StringAppendF( | 86 base::StringAppendF( |
| 92 &str, "draw_if_possible_failed_ = %d; ", draw_if_possible_failed_); | 87 &str, "draw_if_possible_failed_ = %d; ", draw_if_possible_failed_); |
| 93 base::StringAppendF(&str, "has_pending_tree_ = %d; ", has_pending_tree_); | 88 base::StringAppendF(&str, "has_pending_tree_ = %d; ", has_pending_tree_); |
| 94 base::StringAppendF(&str, "texture_state_ = %d; ", texture_state_); | 89 base::StringAppendF(&str, "texture_state_ = %d; ", texture_state_); |
| 95 base::StringAppendF( | 90 base::StringAppendF( |
| 96 &str, "output_surface_state_ = %d; ", output_surface_state_); | 91 &str, "output_surface_state_ = %d; ", output_surface_state_); |
| 97 return str; | 92 return str; |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 266 |
| 272 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: | 267 case ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD: |
| 273 DCHECK(!has_pending_tree_); | 268 DCHECK(!has_pending_tree_); |
| 274 DCHECK(visible_ || needs_forced_commit_); | 269 DCHECK(visible_ || needs_forced_commit_); |
| 275 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; | 270 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; |
| 276 needs_commit_ = false; | 271 needs_commit_ = false; |
| 277 needs_forced_commit_ = false; | 272 needs_forced_commit_ = false; |
| 278 return; | 273 return; |
| 279 | 274 |
| 280 case ACTION_COMMIT: | 275 case ACTION_COMMIT: |
| 281 commit_count_++; | |
| 282 if (expect_immediate_begin_frame_for_main_thread_) | 276 if (expect_immediate_begin_frame_for_main_thread_) |
| 283 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW; | 277 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_FORCED_DRAW; |
| 284 else | 278 else |
| 285 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; | 279 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; |
| 286 // When impl-side painting, we draw on activation instead of on commit. | 280 // When impl-side painting, we draw on activation instead of on commit. |
| 287 if (!settings_.impl_side_painting) | 281 if (!settings_.impl_side_painting) |
| 288 needs_redraw_ = true; | 282 needs_redraw_ = true; |
| 289 if (draw_if_possible_failed_) | 283 if (draw_if_possible_failed_) |
| 290 last_frame_number_where_draw_was_called_ = -1; | 284 last_frame_number_where_draw_was_called_ = -1; |
| 291 | 285 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 } | 325 } |
| 332 } | 326 } |
| 333 | 327 |
| 334 void SchedulerStateMachine::SetMainThreadNeedsLayerTextures() { | 328 void SchedulerStateMachine::SetMainThreadNeedsLayerTextures() { |
| 335 DCHECK(!main_thread_needs_layer_textures_); | 329 DCHECK(!main_thread_needs_layer_textures_); |
| 336 DCHECK_NE(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD); | 330 DCHECK_NE(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD); |
| 337 main_thread_needs_layer_textures_ = true; | 331 main_thread_needs_layer_textures_ = true; |
| 338 } | 332 } |
| 339 | 333 |
| 340 bool SchedulerStateMachine::BeginFrameNeededByImplThread() const { | 334 bool SchedulerStateMachine::BeginFrameNeededByImplThread() const { |
| 341 // We should proactively request a BeginFrame if a commit is pending. | |
| 342 if (needs_commit_ || needs_forced_commit_ || | |
| 343 commit_state_ != COMMIT_STATE_IDLE) | |
| 344 return true; | |
| 345 | |
| 346 // If we have a pending tree, need to keep getting notifications until | 335 // If we have a pending tree, need to keep getting notifications until |
| 347 // the tree is ready to be swapped. | 336 // the tree is ready to be swapped. |
| 348 if (has_pending_tree_) | 337 if (has_pending_tree_) |
| 349 return true; | 338 return true; |
| 350 | 339 |
| 351 // If we can't draw, don't tick until we are notified that we can draw again. | 340 // If we can't draw, don't tick until we are notified that we can draw again. |
| 352 if (!can_draw_) | 341 if (!can_draw_) |
| 353 return false; | 342 return false; |
| 354 | 343 |
| 355 if (needs_forced_redraw_) | 344 if (needs_forced_redraw_) |
| 356 return true; | 345 return true; |
| 357 | 346 |
| 358 if (visible_ && swap_used_incomplete_tile_) | 347 if (visible_ && swap_used_incomplete_tile_) |
| 359 return true; | 348 return true; |
| 360 | 349 |
| 361 return needs_redraw_ && visible_ && | 350 return needs_redraw_ && visible_ && |
| 362 output_surface_state_ == OUTPUT_SURFACE_ACTIVE; | 351 output_surface_state_ == OUTPUT_SURFACE_ACTIVE; |
| 363 } | 352 } |
| 364 | 353 |
| 365 void SchedulerStateMachine::DidEnterBeginFrame() { | 354 void SchedulerStateMachine::DidEnterBeginFrame() { |
| 366 inside_begin_frame_ = true; | 355 inside_begin_frame_ = true; |
| 367 } | 356 } |
| 368 | 357 |
| 369 void SchedulerStateMachine::SetFrameTime(base::TimeTicks frame_time) { | |
| 370 last_frame_time_ = frame_time; | |
| 371 } | |
| 372 | |
| 373 void SchedulerStateMachine::DidLeaveBeginFrame() { | 358 void SchedulerStateMachine::DidLeaveBeginFrame() { |
| 374 current_frame_number_++; | 359 current_frame_number_++; |
| 375 inside_begin_frame_ = false; | 360 inside_begin_frame_ = false; |
| 376 } | 361 } |
| 377 | 362 |
| 378 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } | 363 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } |
| 379 | 364 |
| 380 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } | 365 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } |
| 381 | 366 |
| 382 void SchedulerStateMachine::DidSwapUseIncompleteTile() { | 367 void SchedulerStateMachine::DidSwapUseIncompleteTile() { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 bool SchedulerStateMachine::HasInitializedOutputSurface() const { | 448 bool SchedulerStateMachine::HasInitializedOutputSurface() const { |
| 464 return output_surface_state_ == OUTPUT_SURFACE_ACTIVE; | 449 return output_surface_state_ == OUTPUT_SURFACE_ACTIVE; |
| 465 } | 450 } |
| 466 | 451 |
| 467 void SchedulerStateMachine::SetMaximumNumberOfFailedDrawsBeforeDrawIsForced( | 452 void SchedulerStateMachine::SetMaximumNumberOfFailedDrawsBeforeDrawIsForced( |
| 468 int num_draws) { | 453 int num_draws) { |
| 469 maximum_number_of_failed_draws_before_draw_is_forced_ = num_draws; | 454 maximum_number_of_failed_draws_before_draw_is_forced_ = num_draws; |
| 470 } | 455 } |
| 471 | 456 |
| 472 } // namespace cc | 457 } // namespace cc |
| OLD | NEW |