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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 } | 80 } |
81 | 81 |
82 const char* SchedulerStateMachine::CommitStateToString(CommitState state) { | 82 const char* SchedulerStateMachine::CommitStateToString(CommitState state) { |
83 switch (state) { | 83 switch (state) { |
84 case COMMIT_STATE_IDLE: | 84 case COMMIT_STATE_IDLE: |
85 return "COMMIT_STATE_IDLE"; | 85 return "COMMIT_STATE_IDLE"; |
86 case COMMIT_STATE_FRAME_IN_PROGRESS: | 86 case COMMIT_STATE_FRAME_IN_PROGRESS: |
87 return "COMMIT_STATE_FRAME_IN_PROGRESS"; | 87 return "COMMIT_STATE_FRAME_IN_PROGRESS"; |
88 case COMMIT_STATE_READY_TO_COMMIT: | 88 case COMMIT_STATE_READY_TO_COMMIT: |
89 return "COMMIT_STATE_READY_TO_COMMIT"; | 89 return "COMMIT_STATE_READY_TO_COMMIT"; |
90 case COMMIT_STATE_WAITING_FOR_ACTIVATION: | |
91 return "COMMIT_STATE_WAITING_FOR_ACTIVATION"; | |
90 case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: | 92 case COMMIT_STATE_WAITING_FOR_FIRST_DRAW: |
91 return "COMMIT_STATE_WAITING_FOR_FIRST_DRAW"; | 93 return "COMMIT_STATE_WAITING_FOR_FIRST_DRAW"; |
92 } | 94 } |
93 NOTREACHED(); | 95 NOTREACHED(); |
94 return "???"; | 96 return "???"; |
95 } | 97 } |
96 | 98 |
97 const char* SchedulerStateMachine::TextureStateToString(TextureState state) { | 99 const char* SchedulerStateMachine::TextureStateToString(TextureState state) { |
98 switch (state) { | 100 switch (state) { |
99 case LAYER_TEXTURE_STATE_UNLOCKED: | 101 case LAYER_TEXTURE_STATE_UNLOCKED: |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
358 } | 360 } |
359 | 361 |
360 bool SchedulerStateMachine::ShouldDraw() const { | 362 bool SchedulerStateMachine::ShouldDraw() const { |
361 // After a readback, make sure not to draw again until we've replaced the | 363 // After a readback, make sure not to draw again until we've replaced the |
362 // readback commit with a real one. | 364 // readback commit with a real one. |
363 if (readback_state_ == READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT || | 365 if (readback_state_ == READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT || |
364 readback_state_ == READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION) | 366 readback_state_ == READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION) |
365 return false; | 367 return false; |
366 | 368 |
367 // Draw immediately for readbacks to unblock the main thread quickly. | 369 // Draw immediately for readbacks to unblock the main thread quickly. |
368 if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) { | 370 if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) |
369 DCHECK_EQ(commit_state_, COMMIT_STATE_WAITING_FOR_FIRST_DRAW); | |
370 return true; | 371 return true; |
371 } | |
372 | 372 |
373 // If we need to abort draws, we should do so ASAP since the draw could | 373 // If we need to abort draws, we should do so ASAP since the draw could |
374 // be blocking other important actions (like output surface initialization), | 374 // be blocking other important actions (like output surface initialization), |
375 // from occuring. If we are waiting for the first draw, then perfom the | 375 // from occuring. If we are waiting for the first draw, then perfom the |
376 // aborted draw to keep things moving. If we are not waiting for the first | 376 // aborted draw to keep things moving. If we are not waiting for the first |
377 // draw however, we don't want to abort for no reason. | 377 // draw however, we don't want to abort for no reason. |
378 if (PendingDrawsShouldBeAborted()) | 378 if (PendingDrawsShouldBeAborted()) |
379 return active_tree_needs_first_draw_; | 379 return active_tree_needs_first_draw_; |
380 | 380 |
381 // After this line, we only want to swap once per frame. | 381 // After this line, we only want to swap once per frame. |
382 if (HasSwappedThisFrame()) | 382 if (HasSwappedThisFrame()) |
383 return false; | 383 return false; |
384 | 384 |
385 // Except for the cases above, do not draw outside of the BeginImplFrame | 385 // Except for the cases above, do not draw outside of the BeginImplFrame |
386 // deadline. | 386 // deadline. |
387 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) | 387 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) |
388 return false; | 388 return false; |
389 | 389 |
390 // Only handle forced redraws due to timeouts on the regular deadline. | 390 // Only handle forced redraws due to timeouts on the regular deadline. |
391 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) { | 391 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) |
392 DCHECK_EQ(commit_state_, COMMIT_STATE_WAITING_FOR_FIRST_DRAW); | |
393 return true; | 392 return true; |
394 } | |
395 | 393 |
396 return needs_redraw_; | 394 return needs_redraw_; |
397 } | 395 } |
398 | 396 |
399 bool SchedulerStateMachine::ShouldAcquireLayerTexturesForMainThread() const { | 397 bool SchedulerStateMachine::ShouldAcquireLayerTexturesForMainThread() const { |
400 if (!main_thread_needs_layer_textures_) | 398 if (!main_thread_needs_layer_textures_) |
401 return false; | 399 return false; |
402 if (texture_state_ == LAYER_TEXTURE_STATE_UNLOCKED) | 400 if (texture_state_ == LAYER_TEXTURE_STATE_UNLOCKED) |
403 return true; | 401 return true; |
404 DCHECK_EQ(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD); | 402 DCHECK_EQ(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
449 } | 447 } |
450 | 448 |
451 bool SchedulerStateMachine::ShouldSendBeginMainFrame() const { | 449 bool SchedulerStateMachine::ShouldSendBeginMainFrame() const { |
452 if (!needs_commit_) | 450 if (!needs_commit_) |
453 return false; | 451 return false; |
454 | 452 |
455 // Only send BeginMainFrame when there isn't another commit pending already. | 453 // Only send BeginMainFrame when there isn't another commit pending already. |
456 if (commit_state_ != COMMIT_STATE_IDLE) | 454 if (commit_state_ != COMMIT_STATE_IDLE) |
457 return false; | 455 return false; |
458 | 456 |
459 // We can't accept a commit if we have a pending tree. | 457 // Don't send BeginMainFrame early if we are prioritizing the active tree |
460 if (has_pending_tree_) | 458 // because of smoothness_takes_priority. |
459 if (smoothness_takes_priority_ && | |
460 (has_pending_tree_ || active_tree_needs_first_draw_)) { | |
461 return false; | 461 return false; |
462 } | |
462 | 463 |
463 // We want to handle readback commits immediately to unblock the main thread. | 464 // We want to handle readback commits immediately to unblock the main thread. |
464 // Note: This BeginMainFrame will correspond to the replacement commit that | 465 // Note: This BeginMainFrame will correspond to the replacement commit that |
465 // comes after the readback commit itself, so we only send the BeginMainFrame | 466 // comes after the readback commit itself, so we only send the BeginMainFrame |
466 // if a commit isn't already pending behind the readback. | 467 // if a commit isn't already pending behind the readback. |
467 if (readback_state_ == READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME) | 468 if (readback_state_ == READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME) |
468 return !CommitPending(); | 469 return !CommitPending(); |
469 | 470 |
470 // We do not need commits if we are not visible, unless there's a | 471 // We do not need commits if we are not visible, unless there's a |
471 // request for a readback. | 472 // request for a readback. |
(...skipping 26 matching lines...) Expand all Loading... | |
498 if (!HasInitializedOutputSurface()) | 499 if (!HasInitializedOutputSurface()) |
499 return false; | 500 return false; |
500 | 501 |
501 if (skip_begin_main_frame_to_reduce_latency_) | 502 if (skip_begin_main_frame_to_reduce_latency_) |
502 return false; | 503 return false; |
503 | 504 |
504 return true; | 505 return true; |
505 } | 506 } |
506 | 507 |
507 bool SchedulerStateMachine::ShouldCommit() const { | 508 bool SchedulerStateMachine::ShouldCommit() const { |
508 return commit_state_ == COMMIT_STATE_READY_TO_COMMIT; | 509 if (commit_state_ != COMMIT_STATE_READY_TO_COMMIT) |
510 return false; | |
511 | |
512 // We must not finish the commit until the pending tree is free. | |
513 if (has_pending_tree_) { | |
514 DCHECK(settings_.start_commit_before_activate_enabled); | |
515 return false; | |
516 } | |
517 | |
518 // Prioritize drawing the previous commit before finishing the next commit. | |
519 if (active_tree_needs_first_draw_) | |
520 return false; | |
521 | |
522 return true; | |
509 } | 523 } |
510 | 524 |
511 bool SchedulerStateMachine::IsCommitStateWaiting() const { | 525 bool SchedulerStateMachine::IsCommitStateWaiting() const { |
512 return commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS; | 526 return commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS; |
513 } | 527 } |
514 | 528 |
515 bool SchedulerStateMachine::ShouldManageTiles() const { | 529 bool SchedulerStateMachine::ShouldManageTiles() const { |
516 // ManageTiles only really needs to be called immediately after commit | 530 // ManageTiles only really needs to be called immediately after commit |
517 // and then periodically after that. Use a funnel to make sure we average | 531 // and then periodically after that. Use a funnel to make sure we average |
518 // one ManageTiles per BeginImplFrame in the long run. | 532 // one ManageTiles per BeginImplFrame in the long run. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
571 case ACTION_UPDATE_VISIBLE_TILES: | 585 case ACTION_UPDATE_VISIBLE_TILES: |
572 last_frame_number_update_visible_tiles_was_called_ = | 586 last_frame_number_update_visible_tiles_was_called_ = |
573 current_frame_number_; | 587 current_frame_number_; |
574 return; | 588 return; |
575 | 589 |
576 case ACTION_ACTIVATE_PENDING_TREE: | 590 case ACTION_ACTIVATE_PENDING_TREE: |
577 UpdateStateOnActivation(); | 591 UpdateStateOnActivation(); |
578 return; | 592 return; |
579 | 593 |
580 case ACTION_SEND_BEGIN_MAIN_FRAME: | 594 case ACTION_SEND_BEGIN_MAIN_FRAME: |
581 DCHECK(!has_pending_tree_); | 595 DCHECK(!has_pending_tree_ || |
596 settings_.start_commit_before_activate_enabled); | |
597 DCHECK(!active_tree_needs_first_draw_ || | |
598 settings_.start_commit_before_draw_enabled); | |
582 DCHECK(visible_ || | 599 DCHECK(visible_ || |
583 readback_state_ == READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME); | 600 readback_state_ == READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME); |
584 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; | 601 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; |
585 needs_commit_ = false; | 602 needs_commit_ = false; |
586 if (readback_state_ == READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME) | 603 if (readback_state_ == READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME) |
587 readback_state_ = READBACK_STATE_WAITING_FOR_COMMIT; | 604 readback_state_ = READBACK_STATE_WAITING_FOR_COMMIT; |
588 last_frame_number_begin_main_frame_sent_ = | 605 last_frame_number_begin_main_frame_sent_ = |
589 current_frame_number_; | 606 current_frame_number_; |
590 return; | 607 return; |
591 | 608 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
628 | 645 |
629 case ACTION_MANAGE_TILES: | 646 case ACTION_MANAGE_TILES: |
630 UpdateStateOnManageTiles(); | 647 UpdateStateOnManageTiles(); |
631 return; | 648 return; |
632 } | 649 } |
633 } | 650 } |
634 | 651 |
635 void SchedulerStateMachine::UpdateStateOnCommit(bool commit_was_aborted) { | 652 void SchedulerStateMachine::UpdateStateOnCommit(bool commit_was_aborted) { |
636 commit_count_++; | 653 commit_count_++; |
637 | 654 |
655 if (commit_was_aborted || settings_.start_commit_before_activate_enabled) { | |
656 commit_state_ = COMMIT_STATE_IDLE; | |
657 } else if (settings_.start_commit_before_draw_enabled) { | |
658 commit_state_ = settings_.impl_side_painting | |
659 ? COMMIT_STATE_WAITING_FOR_ACTIVATION | |
660 : COMMIT_STATE_IDLE; | |
661 } else { | |
662 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; | |
663 } | |
664 | |
638 // If we are impl-side-painting but the commit was aborted, then we behave | 665 // If we are impl-side-painting but the commit was aborted, then we behave |
639 // mostly as if we are not impl-side-painting since there is no pending tree. | 666 // mostly as if we are not impl-side-painting since there is no pending tree. |
640 has_pending_tree_ = settings_.impl_side_painting && !commit_was_aborted; | 667 has_pending_tree_ = settings_.impl_side_painting && !commit_was_aborted; |
641 | 668 |
642 // Update state related to readbacks. | 669 // Update state related to readbacks. |
643 if (readback_state_ == READBACK_STATE_WAITING_FOR_COMMIT) { | 670 if (readback_state_ == READBACK_STATE_WAITING_FOR_COMMIT) { |
644 // Update the state if this is the readback commit. | 671 // Update the state if this is the readback commit. |
645 readback_state_ = has_pending_tree_ | 672 readback_state_ = has_pending_tree_ |
646 ? READBACK_STATE_WAITING_FOR_ACTIVATION | 673 ? READBACK_STATE_WAITING_FOR_ACTIVATION |
647 : READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK; | 674 : READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK; |
(...skipping 25 matching lines...) Expand all Loading... | |
673 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT) { | 700 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT) { |
674 if (has_pending_tree_) { | 701 if (has_pending_tree_) { |
675 output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION; | 702 output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION; |
676 } else { | 703 } else { |
677 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; | 704 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; |
678 needs_redraw_ = true; | 705 needs_redraw_ = true; |
679 } | 706 } |
680 } | 707 } |
681 } | 708 } |
682 | 709 |
683 // Update the commit state. We expect and wait for a draw if the commit | |
684 // was not aborted or if we are in a readback or forced draw. | |
685 if (!commit_was_aborted) { | |
686 DCHECK(commit_state_ == COMMIT_STATE_READY_TO_COMMIT); | |
687 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; | |
688 } else if (readback_state_ != READBACK_STATE_IDLE || | |
689 forced_redraw_state_ != FORCED_REDRAW_STATE_IDLE) { | |
690 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; | |
691 } else { | |
692 commit_state_ = COMMIT_STATE_IDLE; | |
693 } | |
694 | |
695 // Update state if we have a new active tree to draw, or if the active tree | 710 // Update state if we have a new active tree to draw, or if the active tree |
696 // was unchanged but we need to do a readback or forced draw. | 711 // was unchanged but we need to do a readback or forced draw. |
697 if (!has_pending_tree_ && | 712 if (!has_pending_tree_ && |
698 (!commit_was_aborted || | 713 (!commit_was_aborted || |
699 readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK || | 714 readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK || |
700 forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW)) { | 715 forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW)) { |
701 needs_redraw_ = true; | 716 needs_redraw_ = true; |
702 active_tree_needs_first_draw_ = true; | 717 active_tree_needs_first_draw_ = true; |
703 } | 718 } |
704 | 719 |
705 // This post-commit work is common to both completed and aborted commits. | 720 // This post-commit work is common to both completed and aborted commits. |
706 pending_tree_is_ready_for_activation_ = false; | 721 pending_tree_is_ready_for_activation_ = false; |
707 | 722 |
708 if (draw_if_possible_failed_) | 723 if (draw_if_possible_failed_) |
709 last_frame_number_swap_performed_ = -1; | 724 last_frame_number_swap_performed_ = -1; |
710 | 725 |
711 // If we are planing to draw with the new commit, lock the layer textures for | 726 // If we are planing to draw with the new commit, lock the layer textures for |
712 // use on the impl thread. Otherwise, leave them unlocked. | 727 // use on the impl thread. Otherwise, leave them unlocked. |
713 if (has_pending_tree_ || needs_redraw_) | 728 if (has_pending_tree_ || needs_redraw_) |
714 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD; | 729 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD; |
715 else | 730 else |
716 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; | 731 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; |
717 } | 732 } |
718 | 733 |
719 void SchedulerStateMachine::UpdateStateOnActivation() { | 734 void SchedulerStateMachine::UpdateStateOnActivation() { |
735 if (commit_state_ == COMMIT_STATE_WAITING_FOR_ACTIVATION) | |
736 commit_state_ = COMMIT_STATE_IDLE; | |
737 | |
720 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION) | 738 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION) |
721 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; | 739 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; |
722 | 740 |
723 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION) | 741 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION) |
724 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_DRAW; | 742 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_DRAW; |
725 | 743 |
726 if (readback_state_ == READBACK_STATE_WAITING_FOR_ACTIVATION) | 744 if (readback_state_ == READBACK_STATE_WAITING_FOR_ACTIVATION) |
727 readback_state_ = READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK; | 745 readback_state_ = READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK; |
728 else if (readback_state_ == READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION) | 746 else if (readback_state_ == READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION) |
729 readback_state_ = READBACK_STATE_IDLE; | 747 readback_state_ = READBACK_STATE_IDLE; |
730 | 748 |
731 has_pending_tree_ = false; | 749 has_pending_tree_ = false; |
732 pending_tree_is_ready_for_activation_ = false; | 750 pending_tree_is_ready_for_activation_ = false; |
733 active_tree_needs_first_draw_ = true; | 751 active_tree_needs_first_draw_ = true; |
734 needs_redraw_ = true; | 752 needs_redraw_ = true; |
735 } | 753 } |
736 | 754 |
737 void SchedulerStateMachine::UpdateStateOnDraw(bool did_swap) { | 755 void SchedulerStateMachine::UpdateStateOnDraw(bool did_swap) { |
738 DCHECK(readback_state_ != READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT && | 756 DCHECK(readback_state_ != READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT && |
739 readback_state_ != READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION) | 757 readback_state_ != READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION) |
740 << *AsValue(); | 758 << *AsValue(); |
741 | 759 |
742 if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) { | 760 if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) { |
743 // The draw correspons to a readback commit. | 761 // The draw corresponds to a readback commit. |
744 DCHECK_EQ(commit_state_, COMMIT_STATE_WAITING_FOR_FIRST_DRAW); | |
745 // We are blocking commits from the main thread until after this draw, so | 762 // We are blocking commits from the main thread until after this draw, so |
746 // we should not have a pending tree. | 763 // we should not have a pending tree. |
747 DCHECK(!has_pending_tree_); | 764 DCHECK(!has_pending_tree_); |
748 // We transition to COMMIT_STATE_FRAME_IN_PROGRESS because there is a | 765 // We transition to COMMIT_STATE_FRAME_IN_PROGRESS because there is a |
749 // pending BeginMainFrame behind the readback request. | 766 // pending BeginMainFrame behind the readback request. |
750 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; | 767 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; |
751 readback_state_ = READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT; | 768 readback_state_ = READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT; |
752 } else if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) { | 769 } else if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) { |
753 DCHECK_EQ(commit_state_, COMMIT_STATE_WAITING_FOR_FIRST_DRAW); | 770 forced_redraw_state_ = FORCED_REDRAW_STATE_IDLE; |
771 } | |
772 | |
773 if (did_swap && commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW) | |
brianderson
2014/03/05 00:30:48
This broke the old code path. I should not have ad
| |
754 commit_state_ = COMMIT_STATE_IDLE; | 774 commit_state_ = COMMIT_STATE_IDLE; |
755 forced_redraw_state_ = FORCED_REDRAW_STATE_IDLE; | |
756 } else if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW && | |
757 !has_pending_tree_) { | |
758 commit_state_ = COMMIT_STATE_IDLE; | |
759 } | |
760 | 775 |
761 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) | 776 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) |
762 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; | 777 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; |
763 | 778 |
764 needs_redraw_ = false; | 779 needs_redraw_ = false; |
765 draw_if_possible_failed_ = false; | 780 draw_if_possible_failed_ = false; |
766 active_tree_needs_first_draw_ = false; | 781 active_tree_needs_first_draw_ = false; |
767 | 782 |
768 if (did_swap) | 783 if (did_swap) |
769 last_frame_number_swap_performed_ = current_frame_number_; | 784 last_frame_number_swap_performed_ = current_frame_number_; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
945 return true; | 960 return true; |
946 | 961 |
947 // Prioritize impl-thread draws in smoothness mode. | 962 // Prioritize impl-thread draws in smoothness mode. |
948 if (smoothness_takes_priority_) | 963 if (smoothness_takes_priority_) |
949 return true; | 964 return true; |
950 | 965 |
951 return false; | 966 return false; |
952 } | 967 } |
953 | 968 |
954 bool SchedulerStateMachine::MainThreadIsInHighLatencyMode() const { | 969 bool SchedulerStateMachine::MainThreadIsInHighLatencyMode() const { |
970 // If a commit is pending before the previous commit has been drawn, we | |
971 // are definitely in a high latency mode. | |
972 if (CommitPending() && (active_tree_needs_first_draw_ || has_pending_tree_)) | |
973 return true; | |
974 | |
955 // If we just sent a BeginMainFrame and haven't hit the deadline yet, the main | 975 // If we just sent a BeginMainFrame and haven't hit the deadline yet, the main |
956 // thread is in a low latency mode. | 976 // thread is in a low latency mode. |
957 if (last_frame_number_begin_main_frame_sent_ == current_frame_number_ && | 977 if (last_frame_number_begin_main_frame_sent_ == current_frame_number_ && |
958 (begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING || | 978 (begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING || |
959 begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME)) | 979 begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME)) |
960 return false; | 980 return false; |
961 | 981 |
962 // If there's a commit in progress it must either be from the previous frame | 982 // If there's a commit in progress it must either be from the previous frame |
963 // or it started after the impl thread's deadline. In either case the main | 983 // or it started after the impl thread's deadline. In either case the main |
964 // thread is in high latency mode. | 984 // thread is in high latency mode. |
965 if (commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS || | 985 if (CommitPending()) |
966 commit_state_ == COMMIT_STATE_READY_TO_COMMIT) | |
967 return true; | 986 return true; |
968 | 987 |
969 // Similarly, if there's a pending tree the main thread is in high latency | 988 // Similarly, if there's a pending tree the main thread is in high latency |
970 // mode, because either | 989 // mode, because either |
971 // it's from the previous frame | 990 // it's from the previous frame |
972 // or | 991 // or |
973 // we're currently drawing the active tree and the pending tree will thus | 992 // we're currently drawing the active tree and the pending tree will thus |
974 // only be drawn in the next frame. | 993 // only be drawn in the next frame. |
975 if (has_pending_tree_) | 994 if (has_pending_tree_) |
976 return true; | 995 return true; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1087 if (commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS) { | 1106 if (commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS) { |
1088 readback_state_ = READBACK_STATE_WAITING_FOR_COMMIT; | 1107 readback_state_ = READBACK_STATE_WAITING_FOR_COMMIT; |
1089 } else { | 1108 } else { |
1090 // Set needs_commit_ to true to trigger scheduling BeginMainFrame(). | 1109 // Set needs_commit_ to true to trigger scheduling BeginMainFrame(). |
1091 needs_commit_ = true; | 1110 needs_commit_ = true; |
1092 readback_state_ = READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME; | 1111 readback_state_ = READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME; |
1093 } | 1112 } |
1094 } | 1113 } |
1095 | 1114 |
1096 void SchedulerStateMachine::FinishCommit() { | 1115 void SchedulerStateMachine::FinishCommit() { |
1097 DCHECK(commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS) << *AsValue(); | 1116 DCHECK(commit_state_ != COMMIT_STATE_IDLE) << *AsValue(); |
1098 commit_state_ = COMMIT_STATE_READY_TO_COMMIT; | 1117 commit_state_ = COMMIT_STATE_READY_TO_COMMIT; |
1099 } | 1118 } |
1100 | 1119 |
1101 void SchedulerStateMachine::BeginMainFrameAborted(bool did_handle) { | 1120 void SchedulerStateMachine::BeginMainFrameAborted(bool did_handle) { |
1102 DCHECK_EQ(commit_state_, COMMIT_STATE_FRAME_IN_PROGRESS); | 1121 DCHECK_EQ(commit_state_, COMMIT_STATE_FRAME_IN_PROGRESS); |
1103 if (did_handle) { | 1122 if (did_handle) { |
1104 bool commit_was_aborted = true; | 1123 bool commit_was_aborted = true; |
1105 UpdateStateOnCommit(commit_was_aborted); | 1124 UpdateStateOnCommit(commit_was_aborted); |
1106 } else { | 1125 } else { |
1107 DCHECK_NE(readback_state_, READBACK_STATE_WAITING_FOR_COMMIT); | 1126 DCHECK_NE(readback_state_, READBACK_STATE_WAITING_FOR_COMMIT); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1150 case OUTPUT_SURFACE_ACTIVE: | 1169 case OUTPUT_SURFACE_ACTIVE: |
1151 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: | 1170 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: |
1152 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: | 1171 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: |
1153 return true; | 1172 return true; |
1154 } | 1173 } |
1155 NOTREACHED(); | 1174 NOTREACHED(); |
1156 return false; | 1175 return false; |
1157 } | 1176 } |
1158 | 1177 |
1159 } // namespace cc | 1178 } // namespace cc |
OLD | NEW |