| 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_animate_performed_(-1), |
| 26 last_frame_number_swap_performed_(-1), | 27 last_frame_number_swap_performed_(-1), |
| 27 last_frame_number_begin_main_frame_sent_(-1), | 28 last_frame_number_begin_main_frame_sent_(-1), |
| 28 last_frame_number_update_visible_tiles_was_called_(-1), | 29 last_frame_number_update_visible_tiles_was_called_(-1), |
| 29 manage_tiles_funnel_(0), | 30 manage_tiles_funnel_(0), |
| 30 consecutive_checkerboard_animations_(0), | 31 consecutive_checkerboard_animations_(0), |
| 31 needs_redraw_(false), | 32 needs_redraw_(false), |
| 33 needs_animate_(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), |
| 41 pending_tree_is_ready_for_activation_(false), | 43 pending_tree_is_ready_for_activation_(false), |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 return "FORCED_REDRAW_STATE_WAITING_FOR_DRAW"; | 149 return "FORCED_REDRAW_STATE_WAITING_FOR_DRAW"; |
| 148 } | 150 } |
| 149 NOTREACHED(); | 151 NOTREACHED(); |
| 150 return "???"; | 152 return "???"; |
| 151 } | 153 } |
| 152 | 154 |
| 153 const char* SchedulerStateMachine::ActionToString(Action action) { | 155 const char* SchedulerStateMachine::ActionToString(Action action) { |
| 154 switch (action) { | 156 switch (action) { |
| 155 case ACTION_NONE: | 157 case ACTION_NONE: |
| 156 return "ACTION_NONE"; | 158 return "ACTION_NONE"; |
| 159 case ACTION_ANIMATE: |
| 160 return "ACTION_ANIMATE"; |
| 157 case ACTION_SEND_BEGIN_MAIN_FRAME: | 161 case ACTION_SEND_BEGIN_MAIN_FRAME: |
| 158 return "ACTION_SEND_BEGIN_MAIN_FRAME"; | 162 return "ACTION_SEND_BEGIN_MAIN_FRAME"; |
| 159 case ACTION_COMMIT: | 163 case ACTION_COMMIT: |
| 160 return "ACTION_COMMIT"; | 164 return "ACTION_COMMIT"; |
| 161 case ACTION_UPDATE_VISIBLE_TILES: | 165 case ACTION_UPDATE_VISIBLE_TILES: |
| 162 return "ACTION_UPDATE_VISIBLE_TILES"; | 166 return "ACTION_UPDATE_VISIBLE_TILES"; |
| 163 case ACTION_ACTIVATE_PENDING_TREE: | 167 case ACTION_ACTIVATE_PENDING_TREE: |
| 164 return "ACTION_ACTIVATE_PENDING_TREE"; | 168 return "ACTION_ACTIVATE_PENDING_TREE"; |
| 165 case ACTION_DRAW_AND_SWAP_IF_POSSIBLE: | 169 case ACTION_DRAW_AND_SWAP_IF_POSSIBLE: |
| 166 return "ACTION_DRAW_AND_SWAP_IF_POSSIBLE"; | 170 return "ACTION_DRAW_AND_SWAP_IF_POSSIBLE"; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 "6_deadline", | 232 "6_deadline", |
| 229 (last_begin_impl_frame_args_.deadline - base::TimeTicks()) | 233 (last_begin_impl_frame_args_.deadline - base::TimeTicks()) |
| 230 .InMicroseconds() / | 234 .InMicroseconds() / |
| 231 1000.0L); | 235 1000.0L); |
| 232 state->Set("major_timestamps_in_ms", timestamps_state.release()); | 236 state->Set("major_timestamps_in_ms", timestamps_state.release()); |
| 233 | 237 |
| 234 scoped_ptr<base::DictionaryValue> minor_state(new base::DictionaryValue); | 238 scoped_ptr<base::DictionaryValue> minor_state(new base::DictionaryValue); |
| 235 minor_state->SetInteger("commit_count", commit_count_); | 239 minor_state->SetInteger("commit_count", commit_count_); |
| 236 minor_state->SetInteger("current_frame_number", current_frame_number_); | 240 minor_state->SetInteger("current_frame_number", current_frame_number_); |
| 237 | 241 |
| 242 minor_state->SetInteger("last_frame_number_animate_performed", |
| 243 last_frame_number_animate_performed_); |
| 238 minor_state->SetInteger("last_frame_number_swap_performed", | 244 minor_state->SetInteger("last_frame_number_swap_performed", |
| 239 last_frame_number_swap_performed_); | 245 last_frame_number_swap_performed_); |
| 240 minor_state->SetInteger( | 246 minor_state->SetInteger( |
| 241 "last_frame_number_begin_main_frame_sent", | 247 "last_frame_number_begin_main_frame_sent", |
| 242 last_frame_number_begin_main_frame_sent_); | 248 last_frame_number_begin_main_frame_sent_); |
| 243 minor_state->SetInteger( | 249 minor_state->SetInteger( |
| 244 "last_frame_number_update_visible_tiles_was_called", | 250 "last_frame_number_update_visible_tiles_was_called", |
| 245 last_frame_number_update_visible_tiles_was_called_); | 251 last_frame_number_update_visible_tiles_was_called_); |
| 246 | 252 |
| 247 minor_state->SetInteger("manage_tiles_funnel", manage_tiles_funnel_); | 253 minor_state->SetInteger("manage_tiles_funnel", manage_tiles_funnel_); |
| 248 minor_state->SetInteger("consecutive_checkerboard_animations", | 254 minor_state->SetInteger("consecutive_checkerboard_animations", |
| 249 consecutive_checkerboard_animations_); | 255 consecutive_checkerboard_animations_); |
| 250 minor_state->SetBoolean("needs_redraw", needs_redraw_); | 256 minor_state->SetBoolean("needs_redraw", needs_redraw_); |
| 257 minor_state->SetBoolean("needs_animate_", needs_animate_); |
| 251 minor_state->SetBoolean("needs_manage_tiles", needs_manage_tiles_); | 258 minor_state->SetBoolean("needs_manage_tiles", needs_manage_tiles_); |
| 252 minor_state->SetBoolean("swap_used_incomplete_tile", | 259 minor_state->SetBoolean("swap_used_incomplete_tile", |
| 253 swap_used_incomplete_tile_); | 260 swap_used_incomplete_tile_); |
| 254 minor_state->SetBoolean("needs_commit", needs_commit_); | 261 minor_state->SetBoolean("needs_commit", needs_commit_); |
| 255 minor_state->SetBoolean("main_thread_needs_layer_textures", | 262 minor_state->SetBoolean("main_thread_needs_layer_textures", |
| 256 main_thread_needs_layer_textures_); | 263 main_thread_needs_layer_textures_); |
| 257 minor_state->SetBoolean("visible", visible_); | 264 minor_state->SetBoolean("visible", visible_); |
| 258 minor_state->SetBoolean("can_start", can_start_); | 265 minor_state->SetBoolean("can_start", can_start_); |
| 259 minor_state->SetBoolean("can_draw", can_draw_); | 266 minor_state->SetBoolean("can_draw", can_draw_); |
| 260 minor_state->SetBoolean("has_pending_tree", has_pending_tree_); | 267 minor_state->SetBoolean("has_pending_tree", has_pending_tree_); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 | 455 |
| 449 // If the last swap drew with checkerboard or missing tiles, we should | 456 // If the last swap drew with checkerboard or missing tiles, we should |
| 450 // poll for any new visible tiles so we can be notified to draw again | 457 // poll for any new visible tiles so we can be notified to draw again |
| 451 // when there are. | 458 // when there are. |
| 452 if (swap_used_incomplete_tile_) | 459 if (swap_used_incomplete_tile_) |
| 453 return true; | 460 return true; |
| 454 | 461 |
| 455 return false; | 462 return false; |
| 456 } | 463 } |
| 457 | 464 |
| 465 bool SchedulerStateMachine::ShouldAnimate() const { |
| 466 if (!can_draw_) |
| 467 return false; |
| 468 |
| 469 if (last_frame_number_animate_performed_ == current_frame_number_) |
| 470 return false; |
| 471 |
| 472 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING && |
| 473 begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) |
| 474 return false; |
| 475 |
| 476 return needs_redraw_ || needs_animate_; |
| 477 } |
| 478 |
| 458 bool SchedulerStateMachine::ShouldSendBeginMainFrame() const { | 479 bool SchedulerStateMachine::ShouldSendBeginMainFrame() const { |
| 459 if (!needs_commit_) | 480 if (!needs_commit_) |
| 460 return false; | 481 return false; |
| 461 | 482 |
| 462 // Only send BeginMainFrame when there isn't another commit pending already. | 483 // Only send BeginMainFrame when there isn't another commit pending already. |
| 463 if (commit_state_ != COMMIT_STATE_IDLE) | 484 if (commit_state_ != COMMIT_STATE_IDLE) |
| 464 return false; | 485 return false; |
| 465 | 486 |
| 466 // Don't send BeginMainFrame early if we are prioritizing the active tree | 487 // Don't send BeginMainFrame early if we are prioritizing the active tree |
| 467 // because of smoothness_takes_priority. | 488 // because of smoothness_takes_priority. |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 | 570 |
| 550 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { | 571 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { |
| 551 if (ShouldAcquireLayerTexturesForMainThread()) | 572 if (ShouldAcquireLayerTexturesForMainThread()) |
| 552 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD; | 573 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD; |
| 553 if (ShouldUpdateVisibleTiles()) | 574 if (ShouldUpdateVisibleTiles()) |
| 554 return ACTION_UPDATE_VISIBLE_TILES; | 575 return ACTION_UPDATE_VISIBLE_TILES; |
| 555 if (ShouldActivatePendingTree()) | 576 if (ShouldActivatePendingTree()) |
| 556 return ACTION_ACTIVATE_PENDING_TREE; | 577 return ACTION_ACTIVATE_PENDING_TREE; |
| 557 if (ShouldCommit()) | 578 if (ShouldCommit()) |
| 558 return ACTION_COMMIT; | 579 return ACTION_COMMIT; |
| 580 if (ShouldAnimate()) |
| 581 return ACTION_ANIMATE; |
| 559 if (ShouldDraw()) { | 582 if (ShouldDraw()) { |
| 560 if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) | 583 if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) |
| 561 return ACTION_DRAW_AND_READBACK; | 584 return ACTION_DRAW_AND_READBACK; |
| 562 else if (PendingDrawsShouldBeAborted()) | 585 else if (PendingDrawsShouldBeAborted()) |
| 563 return ACTION_DRAW_AND_SWAP_ABORT; | 586 return ACTION_DRAW_AND_SWAP_ABORT; |
| 564 else if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) | 587 else if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) |
| 565 return ACTION_DRAW_AND_SWAP_FORCED; | 588 return ACTION_DRAW_AND_SWAP_FORCED; |
| 566 else | 589 else |
| 567 return ACTION_DRAW_AND_SWAP_IF_POSSIBLE; | 590 return ACTION_DRAW_AND_SWAP_IF_POSSIBLE; |
| 568 } | 591 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 594 | 617 |
| 595 case ACTION_UPDATE_VISIBLE_TILES: | 618 case ACTION_UPDATE_VISIBLE_TILES: |
| 596 last_frame_number_update_visible_tiles_was_called_ = | 619 last_frame_number_update_visible_tiles_was_called_ = |
| 597 current_frame_number_; | 620 current_frame_number_; |
| 598 return; | 621 return; |
| 599 | 622 |
| 600 case ACTION_ACTIVATE_PENDING_TREE: | 623 case ACTION_ACTIVATE_PENDING_TREE: |
| 601 UpdateStateOnActivation(); | 624 UpdateStateOnActivation(); |
| 602 return; | 625 return; |
| 603 | 626 |
| 627 case ACTION_ANIMATE: |
| 628 last_frame_number_animate_performed_ = current_frame_number_; |
| 629 needs_animate_ = false; |
| 630 // TODO(skyostil): Instead of assuming this, require the client to tell |
| 631 // us. |
| 632 SetNeedsRedraw(); |
| 633 return; |
| 634 |
| 604 case ACTION_SEND_BEGIN_MAIN_FRAME: | 635 case ACTION_SEND_BEGIN_MAIN_FRAME: |
| 605 DCHECK(!has_pending_tree_ || | 636 DCHECK(!has_pending_tree_ || |
| 606 settings_.main_frame_before_activation_enabled); | 637 settings_.main_frame_before_activation_enabled); |
| 607 DCHECK(!active_tree_needs_first_draw_ || | 638 DCHECK(!active_tree_needs_first_draw_ || |
| 608 settings_.main_frame_before_draw_enabled); | 639 settings_.main_frame_before_draw_enabled); |
| 609 DCHECK(visible_ || | 640 DCHECK(visible_ || |
| 610 readback_state_ == READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME); | 641 readback_state_ == READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME); |
| 611 commit_state_ = COMMIT_STATE_BEGIN_MAIN_FRAME_SENT; | 642 commit_state_ = COMMIT_STATE_BEGIN_MAIN_FRAME_SENT; |
| 612 needs_commit_ = false; | 643 needs_commit_ = false; |
| 613 if (readback_state_ == READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME) | 644 if (readback_state_ == READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME) |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 // There's no need to produce frames if we are not visible. | 894 // There's no need to produce frames if we are not visible. |
| 864 if (!visible_) | 895 if (!visible_) |
| 865 return false; | 896 return false; |
| 866 | 897 |
| 867 // We need to draw a more complete frame than we did the last BeginImplFrame, | 898 // We need to draw a more complete frame than we did the last BeginImplFrame, |
| 868 // so request another BeginImplFrame in anticipation that we will have | 899 // so request another BeginImplFrame in anticipation that we will have |
| 869 // additional visible tiles. | 900 // additional visible tiles. |
| 870 if (swap_used_incomplete_tile_) | 901 if (swap_used_incomplete_tile_) |
| 871 return true; | 902 return true; |
| 872 | 903 |
| 904 if (needs_animate_) |
| 905 return true; |
| 906 |
| 873 return needs_redraw_; | 907 return needs_redraw_; |
| 874 } | 908 } |
| 875 | 909 |
| 876 // These are cases where we are very likely to draw soon, but might not | 910 // These are cases where we are very likely to draw soon, but might not |
| 877 // actually have a new frame to draw when we receive the next BeginImplFrame. | 911 // actually have a new frame to draw when we receive the next BeginImplFrame. |
| 878 // Proactively requesting the BeginImplFrame helps hide the round trip latency | 912 // Proactively requesting the BeginImplFrame helps hide the round trip latency |
| 879 // of the SetNeedsBeginImplFrame request that has to go to the Browser. | 913 // of the SetNeedsBeginImplFrame request that has to go to the Browser. |
| 880 bool SchedulerStateMachine::ProactiveBeginImplFrameWanted() const { | 914 bool SchedulerStateMachine::ProactiveBeginImplFrameWanted() const { |
| 881 // The output surface is the provider of BeginImplFrames, | 915 // The output surface is the provider of BeginImplFrames, |
| 882 // so we are not going to get them even if we ask for them. | 916 // so we are not going to get them even if we ask for them. |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1028 void SchedulerStateMachine::DidLeavePollForAnticipatedDrawTriggers() { | 1062 void SchedulerStateMachine::DidLeavePollForAnticipatedDrawTriggers() { |
| 1029 inside_poll_for_anticipated_draw_triggers_ = false; | 1063 inside_poll_for_anticipated_draw_triggers_ = false; |
| 1030 } | 1064 } |
| 1031 | 1065 |
| 1032 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } | 1066 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } |
| 1033 | 1067 |
| 1034 void SchedulerStateMachine::SetCanDraw(bool can_draw) { can_draw_ = can_draw; } | 1068 void SchedulerStateMachine::SetCanDraw(bool can_draw) { can_draw_ = can_draw; } |
| 1035 | 1069 |
| 1036 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } | 1070 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } |
| 1037 | 1071 |
| 1072 void SchedulerStateMachine::SetNeedsAnimate() { needs_animate_ = true; } |
| 1073 |
| 1038 void SchedulerStateMachine::SetNeedsManageTiles() { | 1074 void SchedulerStateMachine::SetNeedsManageTiles() { |
| 1039 if (!needs_manage_tiles_) { | 1075 if (!needs_manage_tiles_) { |
| 1040 TRACE_EVENT0("cc", | 1076 TRACE_EVENT0("cc", |
| 1041 "SchedulerStateMachine::SetNeedsManageTiles"); | 1077 "SchedulerStateMachine::SetNeedsManageTiles"); |
| 1042 needs_manage_tiles_ = true; | 1078 needs_manage_tiles_ = true; |
| 1043 } | 1079 } |
| 1044 } | 1080 } |
| 1045 | 1081 |
| 1046 void SchedulerStateMachine::SetSwapUsedIncompleteTile( | 1082 void SchedulerStateMachine::SetSwapUsedIncompleteTile( |
| 1047 bool used_incomplete_tile) { | 1083 bool used_incomplete_tile) { |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1186 case OUTPUT_SURFACE_ACTIVE: | 1222 case OUTPUT_SURFACE_ACTIVE: |
| 1187 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: | 1223 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: |
| 1188 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: | 1224 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: |
| 1189 return true; | 1225 return true; |
| 1190 } | 1226 } |
| 1191 NOTREACHED(); | 1227 NOTREACHED(); |
| 1192 return false; | 1228 return false; |
| 1193 } | 1229 } |
| 1194 | 1230 |
| 1195 } // namespace cc | 1231 } // namespace cc |
| OLD | NEW |