Chromium Code Reviews| 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/values.h" | 10 #include "base/values.h" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 case ACTION_DRAW_AND_SWAP_FORCED: | 139 case ACTION_DRAW_AND_SWAP_FORCED: |
| 140 return "ACTION_DRAW_AND_SWAP_FORCED"; | 140 return "ACTION_DRAW_AND_SWAP_FORCED"; |
| 141 case ACTION_DRAW_AND_SWAP_ABORT: | 141 case ACTION_DRAW_AND_SWAP_ABORT: |
| 142 return "ACTION_DRAW_AND_SWAP_ABORT"; | 142 return "ACTION_DRAW_AND_SWAP_ABORT"; |
| 143 case ACTION_DRAW_AND_READBACK: | 143 case ACTION_DRAW_AND_READBACK: |
| 144 return "ACTION_DRAW_AND_READBACK"; | 144 return "ACTION_DRAW_AND_READBACK"; |
| 145 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION: | 145 case ACTION_BEGIN_OUTPUT_SURFACE_CREATION: |
| 146 return "ACTION_BEGIN_OUTPUT_SURFACE_CREATION"; | 146 return "ACTION_BEGIN_OUTPUT_SURFACE_CREATION"; |
| 147 case ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: | 147 case ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: |
| 148 return "ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD"; | 148 return "ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD"; |
| 149 case ACTION_MANAGE_TILES: | |
| 150 return "ACTION_MANAGE_TILES"; | |
| 149 } | 151 } |
| 150 NOTREACHED(); | 152 NOTREACHED(); |
| 151 return "???"; | 153 return "???"; |
| 152 } | 154 } |
| 153 | 155 |
| 154 scoped_ptr<base::Value> SchedulerStateMachine::AsValue() const { | 156 scoped_ptr<base::Value> SchedulerStateMachine::AsValue() const { |
| 155 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue); | 157 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue); |
| 156 | 158 |
| 157 scoped_ptr<base::DictionaryValue> major_state(new base::DictionaryValue); | 159 scoped_ptr<base::DictionaryValue> major_state(new base::DictionaryValue); |
| 158 major_state->SetString("next_action", ActionToString(NextAction())); | 160 major_state->SetString("next_action", ActionToString(NextAction())); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 "last_frame_number_where_begin_frame_sent_to_main_thread", | 204 "last_frame_number_where_begin_frame_sent_to_main_thread", |
| 203 last_frame_number_where_begin_frame_sent_to_main_thread_); | 205 last_frame_number_where_begin_frame_sent_to_main_thread_); |
| 204 minor_state->SetInteger("last_frame_number_swap_performed_", | 206 minor_state->SetInteger("last_frame_number_swap_performed_", |
| 205 last_frame_number_swap_performed_); | 207 last_frame_number_swap_performed_); |
| 206 minor_state->SetInteger( | 208 minor_state->SetInteger( |
| 207 "last_frame_number_where_update_visible_tiles_was_called", | 209 "last_frame_number_where_update_visible_tiles_was_called", |
| 208 last_frame_number_where_update_visible_tiles_was_called_); | 210 last_frame_number_where_update_visible_tiles_was_called_); |
| 209 minor_state->SetInteger("consecutive_failed_draws", | 211 minor_state->SetInteger("consecutive_failed_draws", |
| 210 consecutive_failed_draws_); | 212 consecutive_failed_draws_); |
| 211 minor_state->SetBoolean("needs_redraw", needs_redraw_); | 213 minor_state->SetBoolean("needs_redraw", needs_redraw_); |
| 214 minor_state->SetBoolean("needs_manage_tiles", needs_manage_tiles_); | |
| 212 minor_state->SetBoolean("swap_used_incomplete_tile", | 215 minor_state->SetBoolean("swap_used_incomplete_tile", |
| 213 swap_used_incomplete_tile_); | 216 swap_used_incomplete_tile_); |
| 214 minor_state->SetBoolean("needs_commit", needs_commit_); | 217 minor_state->SetBoolean("needs_commit", needs_commit_); |
| 215 minor_state->SetBoolean("main_thread_needs_layer_textures", | 218 minor_state->SetBoolean("main_thread_needs_layer_textures", |
| 216 main_thread_needs_layer_textures_); | 219 main_thread_needs_layer_textures_); |
| 217 minor_state->SetBoolean("inside_begin_frame", inside_begin_frame_); | 220 minor_state->SetBoolean("inside_begin_frame", inside_begin_frame_); |
| 218 minor_state->SetBoolean("visible", visible_); | 221 minor_state->SetBoolean("visible", visible_); |
| 219 minor_state->SetBoolean("can_start", can_start_); | 222 minor_state->SetBoolean("can_start", can_start_); |
| 220 minor_state->SetBoolean("can_draw", can_draw_); | 223 minor_state->SetBoolean("can_draw", can_draw_); |
| 221 minor_state->SetBoolean("has_pending_tree", has_pending_tree_); | 224 minor_state->SetBoolean("has_pending_tree", has_pending_tree_); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 if (!HasInitializedOutputSurface()) | 438 if (!HasInitializedOutputSurface()) |
| 436 return false; | 439 return false; |
| 437 | 440 |
| 438 return true; | 441 return true; |
| 439 } | 442 } |
| 440 | 443 |
| 441 bool SchedulerStateMachine::ShouldCommit() const { | 444 bool SchedulerStateMachine::ShouldCommit() const { |
| 442 return commit_state_ == COMMIT_STATE_READY_TO_COMMIT; | 445 return commit_state_ == COMMIT_STATE_READY_TO_COMMIT; |
| 443 } | 446 } |
| 444 | 447 |
| 448 bool SchedulerStateMachine::ShouldManageTiles() const { | |
|
brianderson
2013/09/11 17:46:27
Should this function be throttling the calls to Ma
epennerAtGoogle
2013/09/11 18:43:00
Yes I was concerned about throttling but I didn't
| |
| 449 return needs_manage_tiles_; | |
| 450 } | |
| 451 | |
| 445 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { | 452 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { |
| 446 if (ShouldAcquireLayerTexturesForMainThread()) | 453 if (ShouldAcquireLayerTexturesForMainThread()) |
| 447 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD; | 454 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD; |
| 448 if (ShouldUpdateVisibleTiles()) | 455 if (ShouldUpdateVisibleTiles()) |
| 449 return ACTION_UPDATE_VISIBLE_TILES; | 456 return ACTION_UPDATE_VISIBLE_TILES; |
| 450 if (ShouldActivatePendingTree()) | 457 if (ShouldActivatePendingTree()) |
| 451 return ACTION_ACTIVATE_PENDING_TREE; | 458 return ACTION_ACTIVATE_PENDING_TREE; |
| 452 if (ShouldCommit()) | 459 if (ShouldCommit()) |
| 453 return ACTION_COMMIT; | 460 return ACTION_COMMIT; |
| 454 if (ShouldDraw()) { | 461 if (ShouldDraw()) { |
| 455 if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) | 462 if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) |
| 456 return ACTION_DRAW_AND_READBACK; | 463 return ACTION_DRAW_AND_READBACK; |
| 457 else if (PendingDrawsShouldBeAborted()) | 464 else if (PendingDrawsShouldBeAborted()) |
| 458 return ACTION_DRAW_AND_SWAP_ABORT; | 465 return ACTION_DRAW_AND_SWAP_ABORT; |
| 459 else if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) | 466 else if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) |
| 460 return ACTION_DRAW_AND_SWAP_FORCED; | 467 return ACTION_DRAW_AND_SWAP_FORCED; |
| 461 else | 468 else |
| 462 return ACTION_DRAW_AND_SWAP_IF_POSSIBLE; | 469 return ACTION_DRAW_AND_SWAP_IF_POSSIBLE; |
| 463 } | 470 } |
| 471 if (ShouldManageTiles()) | |
| 472 return ACTION_MANAGE_TILES; | |
| 464 if (ShouldSendBeginFrameToMainThread()) | 473 if (ShouldSendBeginFrameToMainThread()) |
| 465 return ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; | 474 return ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; |
| 466 if (ShouldBeginOutputSurfaceCreation()) | 475 if (ShouldBeginOutputSurfaceCreation()) |
| 467 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; | 476 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; |
| 468 return ACTION_NONE; | 477 return ACTION_NONE; |
| 469 } | 478 } |
| 470 | 479 |
| 471 void SchedulerStateMachine::CheckInvariants() { | 480 void SchedulerStateMachine::CheckInvariants() { |
| 472 // We should never try to perform a draw for readback and forced draw due to | 481 // We should never try to perform a draw for readback and forced draw due to |
| 473 // timeout simultaneously. | 482 // timeout simultaneously. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 529 // surface creation to avoid complicated corner cases. | 538 // surface creation to avoid complicated corner cases. |
| 530 DCHECK_EQ(commit_state_, COMMIT_STATE_IDLE); | 539 DCHECK_EQ(commit_state_, COMMIT_STATE_IDLE); |
| 531 DCHECK(!has_pending_tree_); | 540 DCHECK(!has_pending_tree_); |
| 532 DCHECK(!active_tree_needs_first_draw_); | 541 DCHECK(!active_tree_needs_first_draw_); |
| 533 return; | 542 return; |
| 534 | 543 |
| 535 case ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: | 544 case ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: |
| 536 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD; | 545 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD; |
| 537 main_thread_needs_layer_textures_ = false; | 546 main_thread_needs_layer_textures_ = false; |
| 538 return; | 547 return; |
| 548 | |
| 549 case ACTION_MANAGE_TILES: | |
| 550 UpdateStateOnManageTiles(); | |
| 551 return; | |
| 539 } | 552 } |
| 540 } | 553 } |
| 541 | 554 |
| 542 void SchedulerStateMachine::UpdateStateOnCommit(bool commit_was_aborted) { | 555 void SchedulerStateMachine::UpdateStateOnCommit(bool commit_was_aborted) { |
| 543 commit_count_++; | 556 commit_count_++; |
| 544 | 557 |
| 545 // If we are impl-side-painting but the commit was aborted, then we behave | 558 // If we are impl-side-painting but the commit was aborted, then we behave |
| 546 // mostly as if we are not impl-side-painting since there is no pending tree. | 559 // mostly as if we are not impl-side-painting since there is no pending tree. |
| 547 has_pending_tree_ = settings_.impl_side_painting && !commit_was_aborted; | 560 has_pending_tree_ = settings_.impl_side_painting && !commit_was_aborted; |
| 548 | 561 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 670 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; | 683 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; |
| 671 | 684 |
| 672 needs_redraw_ = false; | 685 needs_redraw_ = false; |
| 673 draw_if_possible_failed_ = false; | 686 draw_if_possible_failed_ = false; |
| 674 active_tree_needs_first_draw_ = false; | 687 active_tree_needs_first_draw_ = false; |
| 675 | 688 |
| 676 if (did_swap) | 689 if (did_swap) |
| 677 last_frame_number_swap_performed_ = current_frame_number_; | 690 last_frame_number_swap_performed_ = current_frame_number_; |
| 678 } | 691 } |
| 679 | 692 |
| 693 void SchedulerStateMachine::UpdateStateOnManageTiles() { | |
| 694 needs_manage_tiles_ = false; | |
| 695 } | |
| 696 | |
| 680 void SchedulerStateMachine::SetMainThreadNeedsLayerTextures() { | 697 void SchedulerStateMachine::SetMainThreadNeedsLayerTextures() { |
| 681 DCHECK(!main_thread_needs_layer_textures_); | 698 DCHECK(!main_thread_needs_layer_textures_); |
| 682 DCHECK_NE(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD); | 699 DCHECK_NE(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD); |
| 683 main_thread_needs_layer_textures_ = true; | 700 main_thread_needs_layer_textures_ = true; |
| 684 } | 701 } |
| 685 | 702 |
| 686 // These are the cases where we definitely (or almost definitely) have a | 703 // These are the cases where we definitely (or almost definitely) have a |
| 687 // new frame to draw and can draw. | 704 // new frame to draw and can draw. |
| 688 bool SchedulerStateMachine::BeginFrameNeededToDrawByImplThread() const { | 705 bool SchedulerStateMachine::BeginFrameNeededToDrawByImplThread() const { |
| 689 // The output surface is the provider of BeginFrames for the impl thread, | 706 // The output surface is the provider of BeginFrames for the impl thread, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 750 } | 767 } |
| 751 | 768 |
| 752 void SchedulerStateMachine::DidLeaveBeginFrame() { | 769 void SchedulerStateMachine::DidLeaveBeginFrame() { |
| 753 inside_begin_frame_ = false; | 770 inside_begin_frame_ = false; |
| 754 } | 771 } |
| 755 | 772 |
| 756 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } | 773 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } |
| 757 | 774 |
| 758 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } | 775 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } |
| 759 | 776 |
| 777 void SchedulerStateMachine::SetNeedsManageTiles() { | |
| 778 needs_manage_tiles_ = true; | |
| 779 } | |
| 780 | |
| 760 void SchedulerStateMachine::SetSwapUsedIncompleteTile( | 781 void SchedulerStateMachine::SetSwapUsedIncompleteTile( |
| 761 bool used_incomplete_tile) { | 782 bool used_incomplete_tile) { |
| 762 swap_used_incomplete_tile_ = used_incomplete_tile; | 783 swap_used_incomplete_tile_ = used_incomplete_tile; |
| 763 } | 784 } |
| 764 | 785 |
| 765 void SchedulerStateMachine::DidDrawIfPossibleCompleted(bool success) { | 786 void SchedulerStateMachine::DidDrawIfPossibleCompleted(bool success) { |
| 766 draw_if_possible_failed_ = !success; | 787 draw_if_possible_failed_ = !success; |
| 767 if (draw_if_possible_failed_) { | 788 if (draw_if_possible_failed_) { |
| 768 needs_redraw_ = true; | 789 needs_redraw_ = true; |
| 769 needs_commit_ = true; | 790 needs_commit_ = true; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 857 case OUTPUT_SURFACE_ACTIVE: | 878 case OUTPUT_SURFACE_ACTIVE: |
| 858 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: | 879 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: |
| 859 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: | 880 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: |
| 860 return true; | 881 return true; |
| 861 } | 882 } |
| 862 NOTREACHED(); | 883 NOTREACHED(); |
| 863 return false; | 884 return false; |
| 864 } | 885 } |
| 865 | 886 |
| 866 } // namespace cc | 887 } // namespace cc |
| OLD | NEW |