| 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 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| 11 #include "base/trace_event/trace_event_argument.h" | 11 #include "base/trace_event/trace_event_argument.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "ui/gfx/frame_time.h" | 13 #include "ui/gfx/frame_time.h" |
| 14 | 14 |
| 15 namespace cc { | 15 namespace cc { |
| 16 | 16 |
| 17 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) | 17 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) |
| 18 : settings_(settings), | 18 : settings_(settings), |
| 19 output_surface_state_(OUTPUT_SURFACE_LOST), | 19 output_surface_state_(OUTPUT_SURFACE_LOST), |
| 20 begin_impl_frame_state_(BEGIN_IMPL_FRAME_STATE_IDLE), | 20 begin_impl_frame_state_(BEGIN_IMPL_FRAME_STATE_IDLE), |
| 21 commit_state_(COMMIT_STATE_IDLE), | 21 commit_state_(COMMIT_STATE_IDLE), |
| 22 forced_redraw_state_(FORCED_REDRAW_STATE_IDLE), | 22 forced_redraw_state_(FORCED_REDRAW_STATE_IDLE), |
| 23 commit_count_(0), | 23 commit_count_(0), |
| 24 current_frame_number_(0), | 24 current_frame_number_(0), |
| 25 last_frame_number_animate_performed_(-1), | 25 last_frame_number_animate_performed_(-1), |
| 26 last_frame_number_custom_mutate_performed_(-1), |
| 26 last_frame_number_swap_performed_(-1), | 27 last_frame_number_swap_performed_(-1), |
| 27 last_frame_number_swap_requested_(-1), | 28 last_frame_number_swap_requested_(-1), |
| 28 last_frame_number_begin_main_frame_sent_(-1), | 29 last_frame_number_begin_main_frame_sent_(-1), |
| 29 prepare_tiles_funnel_(0), | 30 prepare_tiles_funnel_(0), |
| 30 consecutive_checkerboard_animations_(0), | 31 consecutive_checkerboard_animations_(0), |
| 31 max_pending_swaps_(1), | 32 max_pending_swaps_(1), |
| 32 pending_swaps_(0), | 33 pending_swaps_(0), |
| 33 needs_redraw_(false), | 34 needs_redraw_(false), |
| 34 needs_animate_(false), | 35 needs_animate_(false), |
| 35 needs_prepare_tiles_(false), | 36 needs_prepare_tiles_(false), |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 NOTREACHED(); | 120 NOTREACHED(); |
| 120 return "???"; | 121 return "???"; |
| 121 } | 122 } |
| 122 | 123 |
| 123 const char* SchedulerStateMachine::ActionToString(Action action) { | 124 const char* SchedulerStateMachine::ActionToString(Action action) { |
| 124 switch (action) { | 125 switch (action) { |
| 125 case ACTION_NONE: | 126 case ACTION_NONE: |
| 126 return "ACTION_NONE"; | 127 return "ACTION_NONE"; |
| 127 case ACTION_ANIMATE: | 128 case ACTION_ANIMATE: |
| 128 return "ACTION_ANIMATE"; | 129 return "ACTION_ANIMATE"; |
| 130 case ACTION_CUSTOM_MUTATE: |
| 131 return "ACTION_CUSTOM_MUTATE"; |
| 129 case ACTION_SEND_BEGIN_MAIN_FRAME: | 132 case ACTION_SEND_BEGIN_MAIN_FRAME: |
| 130 return "ACTION_SEND_BEGIN_MAIN_FRAME"; | 133 return "ACTION_SEND_BEGIN_MAIN_FRAME"; |
| 131 case ACTION_COMMIT: | 134 case ACTION_COMMIT: |
| 132 return "ACTION_COMMIT"; | 135 return "ACTION_COMMIT"; |
| 133 case ACTION_ACTIVATE_SYNC_TREE: | 136 case ACTION_ACTIVATE_SYNC_TREE: |
| 134 return "ACTION_ACTIVATE_SYNC_TREE"; | 137 return "ACTION_ACTIVATE_SYNC_TREE"; |
| 135 case ACTION_DRAW_AND_SWAP_IF_POSSIBLE: | 138 case ACTION_DRAW_AND_SWAP_IF_POSSIBLE: |
| 136 return "ACTION_DRAW_AND_SWAP_IF_POSSIBLE"; | 139 return "ACTION_DRAW_AND_SWAP_IF_POSSIBLE"; |
| 137 case ACTION_DRAW_AND_SWAP_FORCED: | 140 case ACTION_DRAW_AND_SWAP_FORCED: |
| 138 return "ACTION_DRAW_AND_SWAP_FORCED"; | 141 return "ACTION_DRAW_AND_SWAP_FORCED"; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 (begin_impl_frame_args_.deadline - base::TimeTicks()).InMicroseconds() / | 195 (begin_impl_frame_args_.deadline - base::TimeTicks()).InMicroseconds() / |
| 193 1000.0L); | 196 1000.0L); |
| 194 state->EndDictionary(); | 197 state->EndDictionary(); |
| 195 | 198 |
| 196 state->BeginDictionary("minor_state"); | 199 state->BeginDictionary("minor_state"); |
| 197 state->SetInteger("commit_count", commit_count_); | 200 state->SetInteger("commit_count", commit_count_); |
| 198 state->SetInteger("current_frame_number", current_frame_number_); | 201 state->SetInteger("current_frame_number", current_frame_number_); |
| 199 | 202 |
| 200 state->SetInteger("last_frame_number_animate_performed", | 203 state->SetInteger("last_frame_number_animate_performed", |
| 201 last_frame_number_animate_performed_); | 204 last_frame_number_animate_performed_); |
| 205 state->SetInteger("last_frame_number_custom_mutate_performed", |
| 206 last_frame_number_custom_mutate_performed_); |
| 202 state->SetInteger("last_frame_number_swap_performed", | 207 state->SetInteger("last_frame_number_swap_performed", |
| 203 last_frame_number_swap_performed_); | 208 last_frame_number_swap_performed_); |
| 204 state->SetInteger("last_frame_number_swap_requested", | 209 state->SetInteger("last_frame_number_swap_requested", |
| 205 last_frame_number_swap_requested_); | 210 last_frame_number_swap_requested_); |
| 206 state->SetInteger("last_frame_number_begin_main_frame_sent", | 211 state->SetInteger("last_frame_number_begin_main_frame_sent", |
| 207 last_frame_number_begin_main_frame_sent_); | 212 last_frame_number_begin_main_frame_sent_); |
| 208 | 213 |
| 209 state->SetInteger("prepare_tiles_funnel", prepare_tiles_funnel_); | 214 state->SetInteger("prepare_tiles_funnel", prepare_tiles_funnel_); |
| 210 state->SetInteger("consecutive_checkerboard_animations", | 215 state->SetInteger("consecutive_checkerboard_animations", |
| 211 consecutive_checkerboard_animations_); | 216 consecutive_checkerboard_animations_); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 | 254 |
| 250 skip_begin_main_frame_to_reduce_latency_ = | 255 skip_begin_main_frame_to_reduce_latency_ = |
| 251 skip_next_begin_main_frame_to_reduce_latency_; | 256 skip_next_begin_main_frame_to_reduce_latency_; |
| 252 skip_next_begin_main_frame_to_reduce_latency_ = false; | 257 skip_next_begin_main_frame_to_reduce_latency_ = false; |
| 253 } | 258 } |
| 254 | 259 |
| 255 bool SchedulerStateMachine::HasAnimatedThisFrame() const { | 260 bool SchedulerStateMachine::HasAnimatedThisFrame() const { |
| 256 return last_frame_number_animate_performed_ == current_frame_number_; | 261 return last_frame_number_animate_performed_ == current_frame_number_; |
| 257 } | 262 } |
| 258 | 263 |
| 264 bool SchedulerStateMachine::HasCustomMutatedThisFrame() const { |
| 265 return last_frame_number_custom_mutate_performed_ == current_frame_number_; |
| 266 } |
| 267 |
| 259 bool SchedulerStateMachine::HasSentBeginMainFrameThisFrame() const { | 268 bool SchedulerStateMachine::HasSentBeginMainFrameThisFrame() const { |
| 260 return current_frame_number_ == | 269 return current_frame_number_ == |
| 261 last_frame_number_begin_main_frame_sent_; | 270 last_frame_number_begin_main_frame_sent_; |
| 262 } | 271 } |
| 263 | 272 |
| 264 bool SchedulerStateMachine::HasSwappedThisFrame() const { | 273 bool SchedulerStateMachine::HasSwappedThisFrame() const { |
| 265 return current_frame_number_ == last_frame_number_swap_performed_; | 274 return current_frame_number_ == last_frame_number_swap_performed_; |
| 266 } | 275 } |
| 267 | 276 |
| 268 bool SchedulerStateMachine::HasRequestedSwapThisFrame() const { | 277 bool SchedulerStateMachine::HasRequestedSwapThisFrame() const { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 if (HasAnimatedThisFrame() && !did_commit_after_animating_) | 407 if (HasAnimatedThisFrame() && !did_commit_after_animating_) |
| 399 return false; | 408 return false; |
| 400 | 409 |
| 401 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING && | 410 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING && |
| 402 begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) | 411 begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) |
| 403 return false; | 412 return false; |
| 404 | 413 |
| 405 return needs_redraw_ || needs_animate_; | 414 return needs_redraw_ || needs_animate_; |
| 406 } | 415 } |
| 407 | 416 |
| 417 bool SchedulerStateMachine::ShouldCustomMutate() const { |
| 418 // Don't mutate if we are waiting on the first commit after a surface. |
| 419 if (output_surface_state_ != OUTPUT_SURFACE_ACTIVE) |
| 420 return false; |
| 421 |
| 422 if (HasCustomMutatedThisFrame() || !needs_custom_mutate_) |
| 423 return false; |
| 424 |
| 425 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING && |
| 426 begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) |
| 427 return false; |
| 428 |
| 429 return true; |
| 430 } |
| 431 |
| 408 bool SchedulerStateMachine::CouldSendBeginMainFrame() const { | 432 bool SchedulerStateMachine::CouldSendBeginMainFrame() const { |
| 409 if (!needs_commit_) | 433 if (!needs_commit_) |
| 410 return false; | 434 return false; |
| 411 | 435 |
| 412 // We can not perform commits if we are not visible. | 436 // We can not perform commits if we are not visible. |
| 413 if (!visible_) | 437 if (!visible_) |
| 414 return false; | 438 return false; |
| 415 | 439 |
| 416 // Do not make a new commits when it is deferred. | 440 // Do not make a new commits when it is deferred. |
| 417 if (defer_commits_) | 441 if (defer_commits_) |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 return needs_prepare_tiles_; | 528 return needs_prepare_tiles_; |
| 505 } | 529 } |
| 506 | 530 |
| 507 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { | 531 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { |
| 508 if (ShouldActivatePendingTree()) | 532 if (ShouldActivatePendingTree()) |
| 509 return ACTION_ACTIVATE_SYNC_TREE; | 533 return ACTION_ACTIVATE_SYNC_TREE; |
| 510 if (ShouldCommit()) | 534 if (ShouldCommit()) |
| 511 return ACTION_COMMIT; | 535 return ACTION_COMMIT; |
| 512 if (ShouldAnimate()) | 536 if (ShouldAnimate()) |
| 513 return ACTION_ANIMATE; | 537 return ACTION_ANIMATE; |
| 538 if (ShouldCustomMutate()) |
| 539 return ACTION_CUSTOM_MUTATE; |
| 514 if (ShouldDraw()) { | 540 if (ShouldDraw()) { |
| 515 if (PendingDrawsShouldBeAborted()) | 541 if (PendingDrawsShouldBeAborted()) |
| 516 return ACTION_DRAW_AND_SWAP_ABORT; | 542 return ACTION_DRAW_AND_SWAP_ABORT; |
| 517 else if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) | 543 else if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) |
| 518 return ACTION_DRAW_AND_SWAP_FORCED; | 544 return ACTION_DRAW_AND_SWAP_FORCED; |
| 519 else | 545 else |
| 520 return ACTION_DRAW_AND_SWAP_IF_POSSIBLE; | 546 return ACTION_DRAW_AND_SWAP_IF_POSSIBLE; |
| 521 } | 547 } |
| 522 if (ShouldPrepareTiles()) | 548 if (ShouldPrepareTiles()) |
| 523 return ACTION_PREPARE_TILES; | 549 return ACTION_PREPARE_TILES; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 539 | 565 |
| 540 case ACTION_ANIMATE: | 566 case ACTION_ANIMATE: |
| 541 last_frame_number_animate_performed_ = current_frame_number_; | 567 last_frame_number_animate_performed_ = current_frame_number_; |
| 542 needs_animate_ = false; | 568 needs_animate_ = false; |
| 543 did_commit_after_animating_ = false; | 569 did_commit_after_animating_ = false; |
| 544 // TODO(skyostil): Instead of assuming this, require the client to tell | 570 // TODO(skyostil): Instead of assuming this, require the client to tell |
| 545 // us. | 571 // us. |
| 546 SetNeedsRedraw(); | 572 SetNeedsRedraw(); |
| 547 return; | 573 return; |
| 548 | 574 |
| 575 case ACTION_CUSTOM_MUTATE: |
| 576 last_frame_number_custom_mutate_performed_ = current_frame_number_; |
| 577 needs_custom_mutate_ = false; |
| 578 return; |
| 579 |
| 549 case ACTION_SEND_BEGIN_MAIN_FRAME: | 580 case ACTION_SEND_BEGIN_MAIN_FRAME: |
| 550 DCHECK(!has_pending_tree_ || | 581 DCHECK(!has_pending_tree_ || |
| 551 settings_.main_frame_before_activation_enabled); | 582 settings_.main_frame_before_activation_enabled); |
| 552 DCHECK(visible_); | 583 DCHECK(visible_); |
| 553 commit_state_ = COMMIT_STATE_BEGIN_MAIN_FRAME_SENT; | 584 commit_state_ = COMMIT_STATE_BEGIN_MAIN_FRAME_SENT; |
| 554 needs_commit_ = false; | 585 needs_commit_ = false; |
| 555 last_frame_number_begin_main_frame_sent_ = | 586 last_frame_number_begin_main_frame_sent_ = |
| 556 current_frame_number_; | 587 current_frame_number_; |
| 557 return; | 588 return; |
| 558 | 589 |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } | 986 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } |
| 956 | 987 |
| 957 void SchedulerStateMachine::SetCanDraw(bool can_draw) { can_draw_ = can_draw; } | 988 void SchedulerStateMachine::SetCanDraw(bool can_draw) { can_draw_ = can_draw; } |
| 958 | 989 |
| 959 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } | 990 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } |
| 960 | 991 |
| 961 void SchedulerStateMachine::SetNeedsAnimate() { | 992 void SchedulerStateMachine::SetNeedsAnimate() { |
| 962 needs_animate_ = true; | 993 needs_animate_ = true; |
| 963 } | 994 } |
| 964 | 995 |
| 996 void SchedulerStateMachine::SetNeedsCustomMutate() { |
| 997 needs_custom_mutate_ = true; |
| 998 } |
| 999 |
| 965 void SchedulerStateMachine::SetNeedsPrepareTiles() { | 1000 void SchedulerStateMachine::SetNeedsPrepareTiles() { |
| 966 if (!needs_prepare_tiles_) { | 1001 if (!needs_prepare_tiles_) { |
| 967 TRACE_EVENT0("cc", "SchedulerStateMachine::SetNeedsPrepareTiles"); | 1002 TRACE_EVENT0("cc", "SchedulerStateMachine::SetNeedsPrepareTiles"); |
| 968 needs_prepare_tiles_ = true; | 1003 needs_prepare_tiles_ = true; |
| 969 } | 1004 } |
| 970 } | 1005 } |
| 971 | 1006 |
| 972 void SchedulerStateMachine::SetMaxSwapsPending(int max) { | 1007 void SchedulerStateMachine::SetMaxSwapsPending(int max) { |
| 973 max_pending_swaps_ = max; | 1008 max_pending_swaps_ = max; |
| 974 } | 1009 } |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1123 static_cast<int>(begin_impl_frame_state_), | 1158 static_cast<int>(begin_impl_frame_state_), |
| 1124 static_cast<int>(commit_state_), | 1159 static_cast<int>(commit_state_), |
| 1125 has_pending_tree_ ? 'T' : 'F', | 1160 has_pending_tree_ ? 'T' : 'F', |
| 1126 pending_tree_is_ready_for_activation_ ? 'T' : 'F', | 1161 pending_tree_is_ready_for_activation_ ? 'T' : 'F', |
| 1127 active_tree_needs_first_draw_ ? 'T' : 'F', | 1162 active_tree_needs_first_draw_ ? 'T' : 'F', |
| 1128 max_pending_swaps_, | 1163 max_pending_swaps_, |
| 1129 pending_swaps_); | 1164 pending_swaps_); |
| 1130 } | 1165 } |
| 1131 | 1166 |
| 1132 } // namespace cc | 1167 } // namespace cc |
| OLD | NEW |