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), |
32 needs_manage_tiles_(false), | 33 needs_manage_tiles_(false), |
33 swap_used_incomplete_tile_(false), | 34 swap_used_incomplete_tile_(false), |
34 needs_commit_(false), | 35 needs_commit_(false), |
35 main_thread_needs_layer_textures_(false), | 36 main_thread_needs_layer_textures_(false), |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 return "FORCED_REDRAW_STATE_WAITING_FOR_DRAW"; | 148 return "FORCED_REDRAW_STATE_WAITING_FOR_DRAW"; |
148 } | 149 } |
149 NOTREACHED(); | 150 NOTREACHED(); |
150 return "???"; | 151 return "???"; |
151 } | 152 } |
152 | 153 |
153 const char* SchedulerStateMachine::ActionToString(Action action) { | 154 const char* SchedulerStateMachine::ActionToString(Action action) { |
154 switch (action) { | 155 switch (action) { |
155 case ACTION_NONE: | 156 case ACTION_NONE: |
156 return "ACTION_NONE"; | 157 return "ACTION_NONE"; |
| 158 case ACTION_ANIMATE: |
| 159 return "ACTION_ANIMATE"; |
157 case ACTION_SEND_BEGIN_MAIN_FRAME: | 160 case ACTION_SEND_BEGIN_MAIN_FRAME: |
158 return "ACTION_SEND_BEGIN_MAIN_FRAME"; | 161 return "ACTION_SEND_BEGIN_MAIN_FRAME"; |
159 case ACTION_COMMIT: | 162 case ACTION_COMMIT: |
160 return "ACTION_COMMIT"; | 163 return "ACTION_COMMIT"; |
161 case ACTION_UPDATE_VISIBLE_TILES: | 164 case ACTION_UPDATE_VISIBLE_TILES: |
162 return "ACTION_UPDATE_VISIBLE_TILES"; | 165 return "ACTION_UPDATE_VISIBLE_TILES"; |
163 case ACTION_ACTIVATE_PENDING_TREE: | 166 case ACTION_ACTIVATE_PENDING_TREE: |
164 return "ACTION_ACTIVATE_PENDING_TREE"; | 167 return "ACTION_ACTIVATE_PENDING_TREE"; |
165 case ACTION_DRAW_AND_SWAP_IF_POSSIBLE: | 168 case ACTION_DRAW_AND_SWAP_IF_POSSIBLE: |
166 return "ACTION_DRAW_AND_SWAP_IF_POSSIBLE"; | 169 return "ACTION_DRAW_AND_SWAP_IF_POSSIBLE"; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 "6_deadline", | 231 "6_deadline", |
229 (last_begin_impl_frame_args_.deadline - base::TimeTicks()) | 232 (last_begin_impl_frame_args_.deadline - base::TimeTicks()) |
230 .InMicroseconds() / | 233 .InMicroseconds() / |
231 1000.0L); | 234 1000.0L); |
232 state->Set("major_timestamps_in_ms", timestamps_state.release()); | 235 state->Set("major_timestamps_in_ms", timestamps_state.release()); |
233 | 236 |
234 scoped_ptr<base::DictionaryValue> minor_state(new base::DictionaryValue); | 237 scoped_ptr<base::DictionaryValue> minor_state(new base::DictionaryValue); |
235 minor_state->SetInteger("commit_count", commit_count_); | 238 minor_state->SetInteger("commit_count", commit_count_); |
236 minor_state->SetInteger("current_frame_number", current_frame_number_); | 239 minor_state->SetInteger("current_frame_number", current_frame_number_); |
237 | 240 |
| 241 minor_state->SetInteger("last_frame_number_animate_performed", |
| 242 last_frame_number_animate_performed_); |
238 minor_state->SetInteger("last_frame_number_swap_performed", | 243 minor_state->SetInteger("last_frame_number_swap_performed", |
239 last_frame_number_swap_performed_); | 244 last_frame_number_swap_performed_); |
240 minor_state->SetInteger( | 245 minor_state->SetInteger( |
241 "last_frame_number_begin_main_frame_sent", | 246 "last_frame_number_begin_main_frame_sent", |
242 last_frame_number_begin_main_frame_sent_); | 247 last_frame_number_begin_main_frame_sent_); |
243 minor_state->SetInteger( | 248 minor_state->SetInteger( |
244 "last_frame_number_update_visible_tiles_was_called", | 249 "last_frame_number_update_visible_tiles_was_called", |
245 last_frame_number_update_visible_tiles_was_called_); | 250 last_frame_number_update_visible_tiles_was_called_); |
246 | 251 |
247 minor_state->SetInteger("manage_tiles_funnel", manage_tiles_funnel_); | 252 minor_state->SetInteger("manage_tiles_funnel", manage_tiles_funnel_); |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 | 453 |
449 // If the last swap drew with checkerboard or missing tiles, we should | 454 // 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 | 455 // poll for any new visible tiles so we can be notified to draw again |
451 // when there are. | 456 // when there are. |
452 if (swap_used_incomplete_tile_) | 457 if (swap_used_incomplete_tile_) |
453 return true; | 458 return true; |
454 | 459 |
455 return false; | 460 return false; |
456 } | 461 } |
457 | 462 |
| 463 bool SchedulerStateMachine::ShouldAnimate() const { |
| 464 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING) |
| 465 return false; |
| 466 |
| 467 if (last_frame_number_animate_performed_ == current_frame_number_) |
| 468 return false; |
| 469 |
| 470 return true; |
| 471 } |
| 472 |
458 bool SchedulerStateMachine::ShouldSendBeginMainFrame() const { | 473 bool SchedulerStateMachine::ShouldSendBeginMainFrame() const { |
459 if (!needs_commit_) | 474 if (!needs_commit_) |
460 return false; | 475 return false; |
461 | 476 |
462 // Only send BeginMainFrame when there isn't another commit pending already. | 477 // Only send BeginMainFrame when there isn't another commit pending already. |
463 if (commit_state_ != COMMIT_STATE_IDLE) | 478 if (commit_state_ != COMMIT_STATE_IDLE) |
464 return false; | 479 return false; |
465 | 480 |
466 // Don't send BeginMainFrame early if we are prioritizing the active tree | 481 // Don't send BeginMainFrame early if we are prioritizing the active tree |
467 // because of smoothness_takes_priority. | 482 // because of smoothness_takes_priority. |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 return ACTION_DRAW_AND_READBACK; | 576 return ACTION_DRAW_AND_READBACK; |
562 else if (PendingDrawsShouldBeAborted()) | 577 else if (PendingDrawsShouldBeAborted()) |
563 return ACTION_DRAW_AND_SWAP_ABORT; | 578 return ACTION_DRAW_AND_SWAP_ABORT; |
564 else if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) | 579 else if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) |
565 return ACTION_DRAW_AND_SWAP_FORCED; | 580 return ACTION_DRAW_AND_SWAP_FORCED; |
566 else | 581 else |
567 return ACTION_DRAW_AND_SWAP_IF_POSSIBLE; | 582 return ACTION_DRAW_AND_SWAP_IF_POSSIBLE; |
568 } | 583 } |
569 if (ShouldManageTiles()) | 584 if (ShouldManageTiles()) |
570 return ACTION_MANAGE_TILES; | 585 return ACTION_MANAGE_TILES; |
| 586 if (ShouldAnimate()) |
| 587 return ACTION_ANIMATE; |
571 if (ShouldSendBeginMainFrame()) | 588 if (ShouldSendBeginMainFrame()) |
572 return ACTION_SEND_BEGIN_MAIN_FRAME; | 589 return ACTION_SEND_BEGIN_MAIN_FRAME; |
573 if (ShouldBeginOutputSurfaceCreation()) | 590 if (ShouldBeginOutputSurfaceCreation()) |
574 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; | 591 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; |
575 return ACTION_NONE; | 592 return ACTION_NONE; |
576 } | 593 } |
577 | 594 |
578 void SchedulerStateMachine::CheckInvariants() { | 595 void SchedulerStateMachine::CheckInvariants() { |
579 // We should never try to perform a draw for readback and forced draw due to | 596 // We should never try to perform a draw for readback and forced draw due to |
580 // timeout simultaneously. | 597 // timeout simultaneously. |
(...skipping 13 matching lines...) Expand all Loading... |
594 | 611 |
595 case ACTION_UPDATE_VISIBLE_TILES: | 612 case ACTION_UPDATE_VISIBLE_TILES: |
596 last_frame_number_update_visible_tiles_was_called_ = | 613 last_frame_number_update_visible_tiles_was_called_ = |
597 current_frame_number_; | 614 current_frame_number_; |
598 return; | 615 return; |
599 | 616 |
600 case ACTION_ACTIVATE_PENDING_TREE: | 617 case ACTION_ACTIVATE_PENDING_TREE: |
601 UpdateStateOnActivation(); | 618 UpdateStateOnActivation(); |
602 return; | 619 return; |
603 | 620 |
| 621 case ACTION_ANIMATE: |
| 622 last_frame_number_animate_performed_ = current_frame_number_; |
| 623 return; |
| 624 |
604 case ACTION_SEND_BEGIN_MAIN_FRAME: | 625 case ACTION_SEND_BEGIN_MAIN_FRAME: |
605 DCHECK(!has_pending_tree_ || | 626 DCHECK(!has_pending_tree_ || |
606 settings_.main_frame_before_activation_enabled); | 627 settings_.main_frame_before_activation_enabled); |
607 DCHECK(!active_tree_needs_first_draw_ || | 628 DCHECK(!active_tree_needs_first_draw_ || |
608 settings_.main_frame_before_draw_enabled); | 629 settings_.main_frame_before_draw_enabled); |
609 DCHECK(visible_ || | 630 DCHECK(visible_ || |
610 readback_state_ == READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME); | 631 readback_state_ == READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME); |
611 commit_state_ = COMMIT_STATE_BEGIN_MAIN_FRAME_SENT; | 632 commit_state_ = COMMIT_STATE_BEGIN_MAIN_FRAME_SENT; |
612 needs_commit_ = false; | 633 needs_commit_ = false; |
613 if (readback_state_ == READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME) | 634 if (readback_state_ == READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME) |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1186 case OUTPUT_SURFACE_ACTIVE: | 1207 case OUTPUT_SURFACE_ACTIVE: |
1187 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: | 1208 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: |
1188 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: | 1209 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: |
1189 return true; | 1210 return true; |
1190 } | 1211 } |
1191 NOTREACHED(); | 1212 NOTREACHED(); |
1192 return false; | 1213 return false; |
1193 } | 1214 } |
1194 | 1215 |
1195 } // namespace cc | 1216 } // namespace cc |
OLD | NEW |