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 { | |
enne (OOO)
2013/09/11 23:45:11
Yeah, I agree strongly with brianderson's suggesti
epennerAtGoogle
2013/09/12 00:09:59
Just for clarity: The extra throttling is only req
brianderson
2013/09/12 00:24:08
Yes, the extra throttling is only required for the
| |
449 if (!inside_begin_frame_) | |
450 return false; | |
451 return needs_manage_tiles_; | |
452 } | |
453 | |
445 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { | 454 SchedulerStateMachine::Action SchedulerStateMachine::NextAction() const { |
446 if (ShouldAcquireLayerTexturesForMainThread()) | 455 if (ShouldAcquireLayerTexturesForMainThread()) |
447 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD; | 456 return ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD; |
448 if (ShouldUpdateVisibleTiles()) | 457 if (ShouldUpdateVisibleTiles()) |
449 return ACTION_UPDATE_VISIBLE_TILES; | 458 return ACTION_UPDATE_VISIBLE_TILES; |
450 if (ShouldActivatePendingTree()) | 459 if (ShouldActivatePendingTree()) |
451 return ACTION_ACTIVATE_PENDING_TREE; | 460 return ACTION_ACTIVATE_PENDING_TREE; |
452 if (ShouldCommit()) | 461 if (ShouldCommit()) |
453 return ACTION_COMMIT; | 462 return ACTION_COMMIT; |
454 if (ShouldDraw()) { | 463 if (ShouldDraw()) { |
455 if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) | 464 if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) |
456 return ACTION_DRAW_AND_READBACK; | 465 return ACTION_DRAW_AND_READBACK; |
457 else if (PendingDrawsShouldBeAborted()) | 466 else if (PendingDrawsShouldBeAborted()) |
458 return ACTION_DRAW_AND_SWAP_ABORT; | 467 return ACTION_DRAW_AND_SWAP_ABORT; |
459 else if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) | 468 else if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) |
460 return ACTION_DRAW_AND_SWAP_FORCED; | 469 return ACTION_DRAW_AND_SWAP_FORCED; |
461 else | 470 else |
462 return ACTION_DRAW_AND_SWAP_IF_POSSIBLE; | 471 return ACTION_DRAW_AND_SWAP_IF_POSSIBLE; |
463 } | 472 } |
473 if (ShouldManageTiles()) | |
474 return ACTION_MANAGE_TILES; | |
464 if (ShouldSendBeginFrameToMainThread()) | 475 if (ShouldSendBeginFrameToMainThread()) |
465 return ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; | 476 return ACTION_SEND_BEGIN_FRAME_TO_MAIN_THREAD; |
466 if (ShouldBeginOutputSurfaceCreation()) | 477 if (ShouldBeginOutputSurfaceCreation()) |
467 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; | 478 return ACTION_BEGIN_OUTPUT_SURFACE_CREATION; |
468 return ACTION_NONE; | 479 return ACTION_NONE; |
469 } | 480 } |
470 | 481 |
471 void SchedulerStateMachine::CheckInvariants() { | 482 void SchedulerStateMachine::CheckInvariants() { |
472 // We should never try to perform a draw for readback and forced draw due to | 483 // We should never try to perform a draw for readback and forced draw due to |
473 // timeout simultaneously. | 484 // timeout simultaneously. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
529 // surface creation to avoid complicated corner cases. | 540 // surface creation to avoid complicated corner cases. |
530 DCHECK_EQ(commit_state_, COMMIT_STATE_IDLE); | 541 DCHECK_EQ(commit_state_, COMMIT_STATE_IDLE); |
531 DCHECK(!has_pending_tree_); | 542 DCHECK(!has_pending_tree_); |
532 DCHECK(!active_tree_needs_first_draw_); | 543 DCHECK(!active_tree_needs_first_draw_); |
533 return; | 544 return; |
534 | 545 |
535 case ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: | 546 case ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD: |
536 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD; | 547 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD; |
537 main_thread_needs_layer_textures_ = false; | 548 main_thread_needs_layer_textures_ = false; |
538 return; | 549 return; |
550 | |
551 case ACTION_MANAGE_TILES: | |
552 UpdateStateOnManageTiles(); | |
553 return; | |
539 } | 554 } |
540 } | 555 } |
541 | 556 |
542 void SchedulerStateMachine::UpdateStateOnCommit(bool commit_was_aborted) { | 557 void SchedulerStateMachine::UpdateStateOnCommit(bool commit_was_aborted) { |
543 commit_count_++; | 558 commit_count_++; |
544 | 559 |
545 // If we are impl-side-painting but the commit was aborted, then we behave | 560 // 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. | 561 // 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; | 562 has_pending_tree_ = settings_.impl_side_painting && !commit_was_aborted; |
548 | 563 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
670 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; | 685 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; |
671 | 686 |
672 needs_redraw_ = false; | 687 needs_redraw_ = false; |
673 draw_if_possible_failed_ = false; | 688 draw_if_possible_failed_ = false; |
674 active_tree_needs_first_draw_ = false; | 689 active_tree_needs_first_draw_ = false; |
675 | 690 |
676 if (did_swap) | 691 if (did_swap) |
677 last_frame_number_swap_performed_ = current_frame_number_; | 692 last_frame_number_swap_performed_ = current_frame_number_; |
678 } | 693 } |
679 | 694 |
695 void SchedulerStateMachine::UpdateStateOnManageTiles() { | |
696 needs_manage_tiles_ = false; | |
697 } | |
698 | |
680 void SchedulerStateMachine::SetMainThreadNeedsLayerTextures() { | 699 void SchedulerStateMachine::SetMainThreadNeedsLayerTextures() { |
681 DCHECK(!main_thread_needs_layer_textures_); | 700 DCHECK(!main_thread_needs_layer_textures_); |
682 DCHECK_NE(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD); | 701 DCHECK_NE(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD); |
683 main_thread_needs_layer_textures_ = true; | 702 main_thread_needs_layer_textures_ = true; |
684 } | 703 } |
685 | 704 |
686 // These are the cases where we definitely (or almost definitely) have a | 705 // These are the cases where we definitely (or almost definitely) have a |
687 // new frame to draw and can draw. | 706 // new frame to draw and can draw. |
688 bool SchedulerStateMachine::BeginFrameNeededToDrawByImplThread() const { | 707 bool SchedulerStateMachine::BeginFrameNeededToDrawByImplThread() const { |
689 // The output surface is the provider of BeginFrames for the impl thread, | 708 // The output surface is the provider of BeginFrames for the impl thread, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
733 // We should proactively request a BeginFrame if a commit is pending | 752 // We should proactively request a BeginFrame if a commit is pending |
734 // because we will want to draw if the commit completes quickly. | 753 // because we will want to draw if the commit completes quickly. |
735 if (needs_commit_ || commit_state_ != COMMIT_STATE_IDLE) | 754 if (needs_commit_ || commit_state_ != COMMIT_STATE_IDLE) |
736 return true; | 755 return true; |
737 | 756 |
738 // If the pending tree activates quickly, we'll want a BeginFrame soon | 757 // If the pending tree activates quickly, we'll want a BeginFrame soon |
739 // to draw the new active tree. | 758 // to draw the new active tree. |
740 if (has_pending_tree_) | 759 if (has_pending_tree_) |
741 return true; | 760 return true; |
742 | 761 |
762 // Changing priorities may allow us to activate (given the new priorities), | |
763 // which may result in a new frame. | |
764 if (needs_manage_tiles_) | |
765 return true; | |
epenner
2013/09/11 22:55:47
Brianderson@, is there anything I need to worry ab
brianderson
2013/09/11 23:14:37
I'm working on a patch to fix issues like this, wh
| |
766 | |
743 return false; | 767 return false; |
744 } | 768 } |
745 | 769 |
746 void SchedulerStateMachine::DidEnterBeginFrame(const BeginFrameArgs& args) { | 770 void SchedulerStateMachine::DidEnterBeginFrame(const BeginFrameArgs& args) { |
747 current_frame_number_++; | 771 current_frame_number_++; |
748 inside_begin_frame_ = true; | 772 inside_begin_frame_ = true; |
749 last_begin_frame_args_ = args; | 773 last_begin_frame_args_ = args; |
750 } | 774 } |
751 | 775 |
752 void SchedulerStateMachine::DidLeaveBeginFrame() { | 776 void SchedulerStateMachine::DidLeaveBeginFrame() { |
753 inside_begin_frame_ = false; | 777 inside_begin_frame_ = false; |
754 } | 778 } |
755 | 779 |
756 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } | 780 void SchedulerStateMachine::SetVisible(bool visible) { visible_ = visible; } |
757 | 781 |
758 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } | 782 void SchedulerStateMachine::SetNeedsRedraw() { needs_redraw_ = true; } |
759 | 783 |
784 void SchedulerStateMachine::SetNeedsManageTiles() { | |
785 needs_manage_tiles_ = true; | |
786 } | |
787 | |
760 void SchedulerStateMachine::SetSwapUsedIncompleteTile( | 788 void SchedulerStateMachine::SetSwapUsedIncompleteTile( |
761 bool used_incomplete_tile) { | 789 bool used_incomplete_tile) { |
762 swap_used_incomplete_tile_ = used_incomplete_tile; | 790 swap_used_incomplete_tile_ = used_incomplete_tile; |
763 } | 791 } |
764 | 792 |
765 void SchedulerStateMachine::DidDrawIfPossibleCompleted(bool success) { | 793 void SchedulerStateMachine::DidDrawIfPossibleCompleted(bool success) { |
766 draw_if_possible_failed_ = !success; | 794 draw_if_possible_failed_ = !success; |
767 if (draw_if_possible_failed_) { | 795 if (draw_if_possible_failed_) { |
768 needs_redraw_ = true; | 796 needs_redraw_ = true; |
769 needs_commit_ = true; | 797 needs_commit_ = true; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
857 case OUTPUT_SURFACE_ACTIVE: | 885 case OUTPUT_SURFACE_ACTIVE: |
858 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: | 886 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: |
859 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: | 887 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: |
860 return true; | 888 return true; |
861 } | 889 } |
862 NOTREACHED(); | 890 NOTREACHED(); |
863 return false; | 891 return false; |
864 } | 892 } |
865 | 893 |
866 } // namespace cc | 894 } // namespace cc |
OLD | NEW |