| 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" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 const char* SchedulerStateMachine::CommitStateToString(CommitState state) { | 83 const char* SchedulerStateMachine::CommitStateToString(CommitState state) { |
| 84 switch (state) { | 84 switch (state) { |
| 85 case COMMIT_STATE_IDLE: | 85 case COMMIT_STATE_IDLE: |
| 86 return "COMMIT_STATE_IDLE"; | 86 return "COMMIT_STATE_IDLE"; |
| 87 case COMMIT_STATE_BEGIN_MAIN_FRAME_SENT: | 87 case COMMIT_STATE_BEGIN_MAIN_FRAME_SENT: |
| 88 return "COMMIT_STATE_BEGIN_MAIN_FRAME_SENT"; | 88 return "COMMIT_STATE_BEGIN_MAIN_FRAME_SENT"; |
| 89 case COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED: | 89 case COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED: |
| 90 return "COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED"; | 90 return "COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED"; |
| 91 case COMMIT_STATE_READY_TO_COMMIT: | 91 case COMMIT_STATE_READY_TO_COMMIT: |
| 92 return "COMMIT_STATE_READY_TO_COMMIT"; | 92 return "COMMIT_STATE_READY_TO_COMMIT"; |
| 93 case COMMIT_STATE_WAITING_FOR_ACTIVATION: |
| 94 return "COMMIT_STATE_WAITING_FOR_ACTIVATION"; |
| 93 case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: | 95 case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: |
| 94 return "COMMIT_STATE_WAITING_FOR_FIRST_DRAW"; | 96 return "COMMIT_STATE_WAITING_FOR_FIRST_DRAW"; |
| 95 } | 97 } |
| 96 NOTREACHED(); | 98 NOTREACHED(); |
| 97 return "???"; | 99 return "???"; |
| 98 } | 100 } |
| 99 | 101 |
| 100 const char* SchedulerStateMachine::TextureStateToString(TextureState state) { | 102 const char* SchedulerStateMachine::TextureStateToString(TextureState state) { |
| 101 switch (state) { | 103 switch (state) { |
| 102 case LAYER_TEXTURE_STATE_UNLOCKED: | 104 case LAYER_TEXTURE_STATE_UNLOCKED: |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 } | 369 } |
| 368 | 370 |
| 369 bool SchedulerStateMachine::ShouldDraw() const { | 371 bool SchedulerStateMachine::ShouldDraw() const { |
| 370 // After a readback, make sure not to draw again until we've replaced the | 372 // After a readback, make sure not to draw again until we've replaced the |
| 371 // readback commit with a real one. | 373 // readback commit with a real one. |
| 372 if (readback_state_ == READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT || | 374 if (readback_state_ == READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT || |
| 373 readback_state_ == READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION) | 375 readback_state_ == READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION) |
| 374 return false; | 376 return false; |
| 375 | 377 |
| 376 // Draw immediately for readbacks to unblock the main thread quickly. | 378 // Draw immediately for readbacks to unblock the main thread quickly. |
| 377 if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) { | 379 if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) |
| 378 DCHECK_EQ(commit_state_, COMMIT_STATE_WAITING_FOR_FIRST_DRAW); | |
| 379 return true; | 380 return true; |
| 380 } | |
| 381 | 381 |
| 382 // If we need to abort draws, we should do so ASAP since the draw could | 382 // If we need to abort draws, we should do so ASAP since the draw could |
| 383 // be blocking other important actions (like output surface initialization), | 383 // be blocking other important actions (like output surface initialization), |
| 384 // from occuring. If we are waiting for the first draw, then perfom the | 384 // from occuring. If we are waiting for the first draw, then perfom the |
| 385 // aborted draw to keep things moving. If we are not waiting for the first | 385 // aborted draw to keep things moving. If we are not waiting for the first |
| 386 // draw however, we don't want to abort for no reason. | 386 // draw however, we don't want to abort for no reason. |
| 387 if (PendingDrawsShouldBeAborted()) | 387 if (PendingDrawsShouldBeAborted()) |
| 388 return active_tree_needs_first_draw_; | 388 return active_tree_needs_first_draw_; |
| 389 | 389 |
| 390 // After this line, we only want to swap once per frame. | 390 // After this line, we only want to swap once per frame. |
| 391 if (HasSwappedThisFrame()) | 391 if (HasSwappedThisFrame()) |
| 392 return false; | 392 return false; |
| 393 | 393 |
| 394 // Except for the cases above, do not draw outside of the BeginImplFrame | 394 // Except for the cases above, do not draw outside of the BeginImplFrame |
| 395 // deadline. | 395 // deadline. |
| 396 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) | 396 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) |
| 397 return false; | 397 return false; |
| 398 | 398 |
| 399 // Only handle forced redraws due to timeouts on the regular deadline. | 399 // Only handle forced redraws due to timeouts on the regular deadline. |
| 400 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) { | 400 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) |
| 401 DCHECK_EQ(commit_state_, COMMIT_STATE_WAITING_FOR_FIRST_DRAW); | |
| 402 return true; | 401 return true; |
| 403 } | |
| 404 | 402 |
| 405 return needs_redraw_; | 403 return needs_redraw_; |
| 406 } | 404 } |
| 407 | 405 |
| 408 bool SchedulerStateMachine::ShouldAcquireLayerTexturesForMainThread() const { | 406 bool SchedulerStateMachine::ShouldAcquireLayerTexturesForMainThread() const { |
| 409 if (!main_thread_needs_layer_textures_) | 407 if (!main_thread_needs_layer_textures_) |
| 410 return false; | 408 return false; |
| 411 if (texture_state_ == LAYER_TEXTURE_STATE_UNLOCKED) | 409 if (texture_state_ == LAYER_TEXTURE_STATE_UNLOCKED) |
| 412 return true; | 410 return true; |
| 413 DCHECK_EQ(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD); | 411 DCHECK_EQ(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 } | 456 } |
| 459 | 457 |
| 460 bool SchedulerStateMachine::ShouldSendBeginMainFrame() const { | 458 bool SchedulerStateMachine::ShouldSendBeginMainFrame() const { |
| 461 if (!needs_commit_) | 459 if (!needs_commit_) |
| 462 return false; | 460 return false; |
| 463 | 461 |
| 464 // Only send BeginMainFrame when there isn't another commit pending already. | 462 // Only send BeginMainFrame when there isn't another commit pending already. |
| 465 if (commit_state_ != COMMIT_STATE_IDLE) | 463 if (commit_state_ != COMMIT_STATE_IDLE) |
| 466 return false; | 464 return false; |
| 467 | 465 |
| 468 // We can't accept a commit if we have a pending tree. | 466 // Don't send BeginMainFrame early if we are prioritizing the active tree |
| 469 if (has_pending_tree_) | 467 // because of smoothness_takes_priority. |
| 468 if (smoothness_takes_priority_ && |
| 469 (has_pending_tree_ || active_tree_needs_first_draw_)) { |
| 470 return false; | 470 return false; |
| 471 } |
| 471 | 472 |
| 472 // We want to handle readback commits immediately to unblock the main thread. | 473 // We want to handle readback commits immediately to unblock the main thread. |
| 473 // Note: This BeginMainFrame will correspond to the replacement commit that | 474 // Note: This BeginMainFrame will correspond to the replacement commit that |
| 474 // comes after the readback commit itself, so we only send the BeginMainFrame | 475 // comes after the readback commit itself, so we only send the BeginMainFrame |
| 475 // if a commit isn't already pending behind the readback. | 476 // if a commit isn't already pending behind the readback. |
| 476 if (readback_state_ == READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME) | 477 if (readback_state_ == READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME) |
| 477 return !CommitPending(); | 478 return !CommitPending(); |
| 478 | 479 |
| 479 // We do not need commits if we are not visible, unless there's a | 480 // We do not need commits if we are not visible, unless there's a |
| 480 // request for a readback. | 481 // request for a readback. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 507 if (!HasInitializedOutputSurface()) | 508 if (!HasInitializedOutputSurface()) |
| 508 return false; | 509 return false; |
| 509 | 510 |
| 510 if (skip_begin_main_frame_to_reduce_latency_) | 511 if (skip_begin_main_frame_to_reduce_latency_) |
| 511 return false; | 512 return false; |
| 512 | 513 |
| 513 return true; | 514 return true; |
| 514 } | 515 } |
| 515 | 516 |
| 516 bool SchedulerStateMachine::ShouldCommit() const { | 517 bool SchedulerStateMachine::ShouldCommit() const { |
| 517 return commit_state_ == COMMIT_STATE_READY_TO_COMMIT; | 518 if (commit_state_ != COMMIT_STATE_READY_TO_COMMIT) |
| 519 return false; |
| 520 |
| 521 // We must not finish the commit until the pending tree is free. |
| 522 if (has_pending_tree_) { |
| 523 DCHECK(settings_.main_frame_before_activation_enabled); |
| 524 return false; |
| 525 } |
| 526 |
| 527 // Prioritize drawing the previous commit before finishing the next commit. |
| 528 if (active_tree_needs_first_draw_) |
| 529 return false; |
| 530 |
| 531 return true; |
| 518 } | 532 } |
| 519 | 533 |
| 520 bool SchedulerStateMachine::ShouldManageTiles() const { | 534 bool SchedulerStateMachine::ShouldManageTiles() const { |
| 521 // ManageTiles only really needs to be called immediately after commit | 535 // ManageTiles only really needs to be called immediately after commit |
| 522 // and then periodically after that. Use a funnel to make sure we average | 536 // and then periodically after that. Use a funnel to make sure we average |
| 523 // one ManageTiles per BeginImplFrame in the long run. | 537 // one ManageTiles per BeginImplFrame in the long run. |
| 524 if (manage_tiles_funnel_ > 0) | 538 if (manage_tiles_funnel_ > 0) |
| 525 return false; | 539 return false; |
| 526 | 540 |
| 527 // Limiting to once per-frame is not enough, since we only want to | 541 // Limiting to once per-frame is not enough, since we only want to |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 case ACTION_UPDATE_VISIBLE_TILES: | 595 case ACTION_UPDATE_VISIBLE_TILES: |
| 582 last_frame_number_update_visible_tiles_was_called_ = | 596 last_frame_number_update_visible_tiles_was_called_ = |
| 583 current_frame_number_; | 597 current_frame_number_; |
| 584 return; | 598 return; |
| 585 | 599 |
| 586 case ACTION_ACTIVATE_PENDING_TREE: | 600 case ACTION_ACTIVATE_PENDING_TREE: |
| 587 UpdateStateOnActivation(); | 601 UpdateStateOnActivation(); |
| 588 return; | 602 return; |
| 589 | 603 |
| 590 case ACTION_SEND_BEGIN_MAIN_FRAME: | 604 case ACTION_SEND_BEGIN_MAIN_FRAME: |
| 591 DCHECK(!has_pending_tree_); | 605 DCHECK(!has_pending_tree_ || |
| 606 settings_.main_frame_before_activation_enabled); |
| 607 DCHECK(!active_tree_needs_first_draw_ || |
| 608 settings_.main_frame_before_draw_enabled); |
| 592 DCHECK(visible_ || | 609 DCHECK(visible_ || |
| 593 readback_state_ == READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME); | 610 readback_state_ == READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME); |
| 594 commit_state_ = COMMIT_STATE_BEGIN_MAIN_FRAME_SENT; | 611 commit_state_ = COMMIT_STATE_BEGIN_MAIN_FRAME_SENT; |
| 595 needs_commit_ = false; | 612 needs_commit_ = false; |
| 596 if (readback_state_ == READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME) | 613 if (readback_state_ == READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME) |
| 597 readback_state_ = READBACK_STATE_WAITING_FOR_COMMIT; | 614 readback_state_ = READBACK_STATE_WAITING_FOR_COMMIT; |
| 598 last_frame_number_begin_main_frame_sent_ = | 615 last_frame_number_begin_main_frame_sent_ = |
| 599 current_frame_number_; | 616 current_frame_number_; |
| 600 return; | 617 return; |
| 601 | 618 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 | 655 |
| 639 case ACTION_MANAGE_TILES: | 656 case ACTION_MANAGE_TILES: |
| 640 UpdateStateOnManageTiles(); | 657 UpdateStateOnManageTiles(); |
| 641 return; | 658 return; |
| 642 } | 659 } |
| 643 } | 660 } |
| 644 | 661 |
| 645 void SchedulerStateMachine::UpdateStateOnCommit(bool commit_was_aborted) { | 662 void SchedulerStateMachine::UpdateStateOnCommit(bool commit_was_aborted) { |
| 646 commit_count_++; | 663 commit_count_++; |
| 647 | 664 |
| 665 if (commit_was_aborted || settings_.main_frame_before_activation_enabled) { |
| 666 commit_state_ = COMMIT_STATE_IDLE; |
| 667 } else if (settings_.main_frame_before_draw_enabled) { |
| 668 commit_state_ = settings_.impl_side_painting |
| 669 ? COMMIT_STATE_WAITING_FOR_ACTIVATION |
| 670 : COMMIT_STATE_IDLE; |
| 671 } else { |
| 672 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; |
| 673 } |
| 674 |
| 648 // If we are impl-side-painting but the commit was aborted, then we behave | 675 // If we are impl-side-painting but the commit was aborted, then we behave |
| 649 // mostly as if we are not impl-side-painting since there is no pending tree. | 676 // mostly as if we are not impl-side-painting since there is no pending tree. |
| 650 has_pending_tree_ = settings_.impl_side_painting && !commit_was_aborted; | 677 has_pending_tree_ = settings_.impl_side_painting && !commit_was_aborted; |
| 651 | 678 |
| 652 // Update state related to readbacks. | 679 // Update state related to readbacks. |
| 653 if (readback_state_ == READBACK_STATE_WAITING_FOR_COMMIT) { | 680 if (readback_state_ == READBACK_STATE_WAITING_FOR_COMMIT) { |
| 654 // Update the state if this is the readback commit. | 681 // Update the state if this is the readback commit. |
| 655 readback_state_ = has_pending_tree_ | 682 readback_state_ = has_pending_tree_ |
| 656 ? READBACK_STATE_WAITING_FOR_ACTIVATION | 683 ? READBACK_STATE_WAITING_FOR_ACTIVATION |
| 657 : READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK; | 684 : READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 683 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT) { | 710 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT) { |
| 684 if (has_pending_tree_) { | 711 if (has_pending_tree_) { |
| 685 output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION; | 712 output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION; |
| 686 } else { | 713 } else { |
| 687 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; | 714 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; |
| 688 needs_redraw_ = true; | 715 needs_redraw_ = true; |
| 689 } | 716 } |
| 690 } | 717 } |
| 691 } | 718 } |
| 692 | 719 |
| 693 // Update the commit state. We expect and wait for a draw if the commit | |
| 694 // was not aborted or if we are in a readback or forced draw. | |
| 695 if (!commit_was_aborted) { | |
| 696 DCHECK(commit_state_ == COMMIT_STATE_READY_TO_COMMIT); | |
| 697 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; | |
| 698 } else if (readback_state_ != READBACK_STATE_IDLE || | |
| 699 forced_redraw_state_ != FORCED_REDRAW_STATE_IDLE) { | |
| 700 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; | |
| 701 } else { | |
| 702 commit_state_ = COMMIT_STATE_IDLE; | |
| 703 } | |
| 704 | |
| 705 // Update state if we have a new active tree to draw, or if the active tree | 720 // Update state if we have a new active tree to draw, or if the active tree |
| 706 // was unchanged but we need to do a readback or forced draw. | 721 // was unchanged but we need to do a readback or forced draw. |
| 707 if (!has_pending_tree_ && | 722 if (!has_pending_tree_ && |
| 708 (!commit_was_aborted || | 723 (!commit_was_aborted || |
| 709 readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK || | 724 readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK || |
| 710 forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW)) { | 725 forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW)) { |
| 711 needs_redraw_ = true; | 726 needs_redraw_ = true; |
| 712 active_tree_needs_first_draw_ = true; | 727 active_tree_needs_first_draw_ = true; |
| 713 } | 728 } |
| 714 | 729 |
| 715 // This post-commit work is common to both completed and aborted commits. | 730 // This post-commit work is common to both completed and aborted commits. |
| 716 pending_tree_is_ready_for_activation_ = false; | 731 pending_tree_is_ready_for_activation_ = false; |
| 717 | 732 |
| 718 if (draw_if_possible_failed_) | 733 if (draw_if_possible_failed_) |
| 719 last_frame_number_swap_performed_ = -1; | 734 last_frame_number_swap_performed_ = -1; |
| 720 | 735 |
| 721 // If we are planing to draw with the new commit, lock the layer textures for | 736 // If we are planing to draw with the new commit, lock the layer textures for |
| 722 // use on the impl thread. Otherwise, leave them unlocked. | 737 // use on the impl thread. Otherwise, leave them unlocked. |
| 723 if (has_pending_tree_ || needs_redraw_) | 738 if (has_pending_tree_ || needs_redraw_) |
| 724 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD; | 739 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD; |
| 725 else | 740 else |
| 726 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; | 741 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; |
| 727 } | 742 } |
| 728 | 743 |
| 729 void SchedulerStateMachine::UpdateStateOnActivation() { | 744 void SchedulerStateMachine::UpdateStateOnActivation() { |
| 745 if (commit_state_ == COMMIT_STATE_WAITING_FOR_ACTIVATION) |
| 746 commit_state_ = COMMIT_STATE_IDLE; |
| 747 |
| 730 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION) | 748 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION) |
| 731 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; | 749 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; |
| 732 | 750 |
| 733 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION) | 751 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION) |
| 734 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_DRAW; | 752 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_DRAW; |
| 735 | 753 |
| 736 if (readback_state_ == READBACK_STATE_WAITING_FOR_ACTIVATION) | 754 if (readback_state_ == READBACK_STATE_WAITING_FOR_ACTIVATION) |
| 737 readback_state_ = READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK; | 755 readback_state_ = READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK; |
| 738 else if (readback_state_ == READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION) | 756 else if (readback_state_ == READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION) |
| 739 readback_state_ = READBACK_STATE_IDLE; | 757 readback_state_ = READBACK_STATE_IDLE; |
| 740 | 758 |
| 741 has_pending_tree_ = false; | 759 has_pending_tree_ = false; |
| 742 pending_tree_is_ready_for_activation_ = false; | 760 pending_tree_is_ready_for_activation_ = false; |
| 743 active_tree_needs_first_draw_ = true; | 761 active_tree_needs_first_draw_ = true; |
| 744 needs_redraw_ = true; | 762 needs_redraw_ = true; |
| 745 } | 763 } |
| 746 | 764 |
| 747 void SchedulerStateMachine::UpdateStateOnDraw(bool did_swap) { | 765 void SchedulerStateMachine::UpdateStateOnDraw(bool did_swap) { |
| 748 DCHECK(readback_state_ != READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT && | 766 DCHECK(readback_state_ != READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT && |
| 749 readback_state_ != READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION) | 767 readback_state_ != READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION) |
| 750 << *AsValue(); | 768 << *AsValue(); |
| 751 | 769 |
| 752 if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) { | 770 if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) { |
| 753 // The draw correspons to a readback commit. | 771 // The draw corresponds to a readback commit. |
| 754 DCHECK_EQ(commit_state_, COMMIT_STATE_WAITING_FOR_FIRST_DRAW); | |
| 755 // We are blocking commits from the main thread until after this draw, so | 772 // We are blocking commits from the main thread until after this draw, so |
| 756 // we should not have a pending tree. | 773 // we should not have a pending tree. |
| 757 DCHECK(!has_pending_tree_); | 774 DCHECK(!has_pending_tree_); |
| 758 // We transition to COMMIT_STATE_BEGIN_MAIN_FRAME_SENT because there is a | 775 // We transition to COMMIT_STATE_BEGIN_MAIN_FRAME_SENT because there is a |
| 759 // pending BeginMainFrame behind the readback request. | 776 // pending BeginMainFrame behind the readback request. |
| 760 commit_state_ = COMMIT_STATE_BEGIN_MAIN_FRAME_SENT; | 777 commit_state_ = COMMIT_STATE_BEGIN_MAIN_FRAME_SENT; |
| 761 readback_state_ = READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT; | 778 readback_state_ = READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT; |
| 762 } else if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) { | 779 } else if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) { |
| 763 DCHECK_EQ(commit_state_, COMMIT_STATE_WAITING_FOR_FIRST_DRAW); | 780 forced_redraw_state_ = FORCED_REDRAW_STATE_IDLE; |
| 781 } |
| 782 |
| 783 if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW) |
| 764 commit_state_ = COMMIT_STATE_IDLE; | 784 commit_state_ = COMMIT_STATE_IDLE; |
| 765 forced_redraw_state_ = FORCED_REDRAW_STATE_IDLE; | |
| 766 } else if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW && | |
| 767 !has_pending_tree_) { | |
| 768 commit_state_ = COMMIT_STATE_IDLE; | |
| 769 } | |
| 770 | 785 |
| 771 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) | 786 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) |
| 772 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; | 787 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; |
| 773 | 788 |
| 774 needs_redraw_ = false; | 789 needs_redraw_ = false; |
| 775 draw_if_possible_failed_ = false; | 790 draw_if_possible_failed_ = false; |
| 776 active_tree_needs_first_draw_ = false; | 791 active_tree_needs_first_draw_ = false; |
| 777 | 792 |
| 778 if (did_swap) | 793 if (did_swap) |
| 779 last_frame_number_swap_performed_ = current_frame_number_; | 794 last_frame_number_swap_performed_ = current_frame_number_; |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 return true; | 970 return true; |
| 956 | 971 |
| 957 // Prioritize impl-thread draws in smoothness mode. | 972 // Prioritize impl-thread draws in smoothness mode. |
| 958 if (smoothness_takes_priority_) | 973 if (smoothness_takes_priority_) |
| 959 return true; | 974 return true; |
| 960 | 975 |
| 961 return false; | 976 return false; |
| 962 } | 977 } |
| 963 | 978 |
| 964 bool SchedulerStateMachine::MainThreadIsInHighLatencyMode() const { | 979 bool SchedulerStateMachine::MainThreadIsInHighLatencyMode() const { |
| 980 // If a commit is pending before the previous commit has been drawn, we |
| 981 // are definitely in a high latency mode. |
| 982 if (CommitPending() && (active_tree_needs_first_draw_ || has_pending_tree_)) |
| 983 return true; |
| 984 |
| 965 // If we just sent a BeginMainFrame and haven't hit the deadline yet, the main | 985 // If we just sent a BeginMainFrame and haven't hit the deadline yet, the main |
| 966 // thread is in a low latency mode. | 986 // thread is in a low latency mode. |
| 967 if (last_frame_number_begin_main_frame_sent_ == current_frame_number_ && | 987 if (last_frame_number_begin_main_frame_sent_ == current_frame_number_ && |
| 968 (begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING || | 988 (begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING || |
| 969 begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME)) | 989 begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME)) |
| 970 return false; | 990 return false; |
| 971 | 991 |
| 972 // If there's a commit in progress it must either be from the previous frame | 992 // If there's a commit in progress it must either be from the previous frame |
| 973 // or it started after the impl thread's deadline. In either case the main | 993 // or it started after the impl thread's deadline. In either case the main |
| 974 // thread is in high latency mode. | 994 // thread is in high latency mode. |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1166 case OUTPUT_SURFACE_ACTIVE: | 1186 case OUTPUT_SURFACE_ACTIVE: |
| 1167 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: | 1187 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: |
| 1168 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: | 1188 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: |
| 1169 return true; | 1189 return true; |
| 1170 } | 1190 } |
| 1171 NOTREACHED(); | 1191 NOTREACHED(); |
| 1172 return false; | 1192 return false; |
| 1173 } | 1193 } |
| 1174 | 1194 |
| 1175 } // namespace cc | 1195 } // namespace cc |
| OLD | NEW |