Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Side by Side Diff: cc/scheduler/scheduler_state_machine.cc

Issue 23907006: cc: Allow sending BeginMainFrame before draw or activation (Closed) Base URL: http://git.chromium.org/chromium/src.git@schedDeadline3
Patch Set: Make commit waiting states explicit Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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 start commits early if we are prioritizing the active tree because
460 if (has_pending_tree_) 458 // of smoothnes_takes_priority.
enne (OOO) 2014/02/14 22:53:59 typo
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 if (!HasInitializedOutputSurface()) 506 if (!HasInitializedOutputSurface())
506 return false; 507 return false;
507 508
508 if (skip_begin_main_frame_to_reduce_latency_) 509 if (skip_begin_main_frame_to_reduce_latency_)
509 return false; 510 return false;
510 511
511 return true; 512 return true;
512 } 513 }
513 514
514 bool SchedulerStateMachine::ShouldCommit() const { 515 bool SchedulerStateMachine::ShouldCommit() const {
515 return commit_state_ == COMMIT_STATE_READY_TO_COMMIT; 516 if (commit_state_ != COMMIT_STATE_READY_TO_COMMIT)
517 return false;
518
519 // We must not finish the commit until the pending tree is free.
520 if (has_pending_tree_) {
521 DCHECK(settings_.start_commit_before_activate_enabled);
522 return false;
523 }
524
525 // If not impl-side-painting, we must not finish the commit until the
526 // previous commit has been drawn.
527 if (active_tree_needs_first_draw_ && !settings_.impl_side_painting) {
528 DCHECK(settings_.start_commit_before_draw_enabled);
529 return false;
530 }
531
532 return true;
516 } 533 }
517 534
518 bool SchedulerStateMachine::IsCommitStateWaiting() const { 535 bool SchedulerStateMachine::IsCommitStateWaiting() const {
519 return commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS; 536 return commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS;
520 } 537 }
521 538
522 bool SchedulerStateMachine::ShouldManageTiles() const { 539 bool SchedulerStateMachine::ShouldManageTiles() const {
523 // ManageTiles only really needs to be called immediately after commit 540 // ManageTiles only really needs to be called immediately after commit
524 // and then periodically after that. Use a funnel to make sure we average 541 // and then periodically after that. Use a funnel to make sure we average
525 // one ManageTiles per BeginImplFrame in the long run. 542 // one ManageTiles per BeginImplFrame in the long run.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 case ACTION_UPDATE_VISIBLE_TILES: 595 case ACTION_UPDATE_VISIBLE_TILES:
579 last_frame_number_update_visible_tiles_was_called_ = 596 last_frame_number_update_visible_tiles_was_called_ =
580 current_frame_number_; 597 current_frame_number_;
581 return; 598 return;
582 599
583 case ACTION_ACTIVATE_PENDING_TREE: 600 case ACTION_ACTIVATE_PENDING_TREE:
584 UpdateStateOnActivation(); 601 UpdateStateOnActivation();
585 return; 602 return;
586 603
587 case ACTION_SEND_BEGIN_MAIN_FRAME: 604 case ACTION_SEND_BEGIN_MAIN_FRAME:
588 DCHECK(!has_pending_tree_); 605 DCHECK(!has_pending_tree_ ||
606 settings_.start_commit_before_activate_enabled);
607 DCHECK(!active_tree_needs_first_draw_ ||
608 settings_.start_commit_before_draw_enabled);
589 DCHECK(visible_ || 609 DCHECK(visible_ ||
590 readback_state_ == READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME); 610 readback_state_ == READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME);
591 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; 611 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS;
592 needs_commit_ = false; 612 needs_commit_ = false;
593 if (readback_state_ == READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME) 613 if (readback_state_ == READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME)
594 readback_state_ = READBACK_STATE_WAITING_FOR_COMMIT; 614 readback_state_ = READBACK_STATE_WAITING_FOR_COMMIT;
595 last_frame_number_begin_main_frame_sent_ = 615 last_frame_number_begin_main_frame_sent_ =
596 current_frame_number_; 616 current_frame_number_;
597 return; 617 return;
598 618
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 655
636 case ACTION_MANAGE_TILES: 656 case ACTION_MANAGE_TILES:
637 UpdateStateOnManageTiles(); 657 UpdateStateOnManageTiles();
638 return; 658 return;
639 } 659 }
640 } 660 }
641 661
642 void SchedulerStateMachine::UpdateStateOnCommit(bool commit_was_aborted) { 662 void SchedulerStateMachine::UpdateStateOnCommit(bool commit_was_aborted) {
643 commit_count_++; 663 commit_count_++;
644 664
665 if (commit_was_aborted || settings_.start_commit_before_activate_enabled) {
666 commit_state_ = COMMIT_STATE_IDLE;
667 } else if (settings_.start_commit_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
645 // 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
646 // 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.
647 has_pending_tree_ = settings_.impl_side_painting && !commit_was_aborted; 677 has_pending_tree_ = settings_.impl_side_painting && !commit_was_aborted;
648 678
649 // Update state related to readbacks. 679 // Update state related to readbacks.
650 if (readback_state_ == READBACK_STATE_WAITING_FOR_COMMIT) { 680 if (readback_state_ == READBACK_STATE_WAITING_FOR_COMMIT) {
651 // Update the state if this is the readback commit. 681 // Update the state if this is the readback commit.
652 readback_state_ = has_pending_tree_ 682 readback_state_ = has_pending_tree_
653 ? READBACK_STATE_WAITING_FOR_ACTIVATION 683 ? READBACK_STATE_WAITING_FOR_ACTIVATION
654 : READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK; 684 : READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK;
(...skipping 25 matching lines...) Expand all
680 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT) { 710 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT) {
681 if (has_pending_tree_) { 711 if (has_pending_tree_) {
682 output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION; 712 output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION;
683 } else { 713 } else {
684 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; 714 output_surface_state_ = OUTPUT_SURFACE_ACTIVE;
685 needs_redraw_ = true; 715 needs_redraw_ = true;
686 } 716 }
687 } 717 }
688 } 718 }
689 719
690 // Update the commit state. We expect and wait for a draw if the commit
691 // was not aborted or if we are in a readback or forced draw.
692 if (!commit_was_aborted) {
693 DCHECK(commit_state_ == COMMIT_STATE_READY_TO_COMMIT);
694 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW;
695 } else if (readback_state_ != READBACK_STATE_IDLE ||
696 forced_redraw_state_ != FORCED_REDRAW_STATE_IDLE) {
697 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW;
698 } else {
699 commit_state_ = COMMIT_STATE_IDLE;
700 }
701
702 // 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
703 // 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.
704 if (!has_pending_tree_ && 722 if (!has_pending_tree_ &&
705 (!commit_was_aborted || 723 (!commit_was_aborted ||
706 readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK || 724 readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK ||
707 forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW)) { 725 forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW)) {
708 needs_redraw_ = true; 726 needs_redraw_ = true;
709 active_tree_needs_first_draw_ = true; 727 active_tree_needs_first_draw_ = true;
710 } 728 }
711 729
712 // 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.
713 pending_tree_is_ready_for_activation_ = false; 731 pending_tree_is_ready_for_activation_ = false;
714 732
715 if (draw_if_possible_failed_) 733 if (draw_if_possible_failed_)
716 last_frame_number_swap_performed_ = -1; 734 last_frame_number_swap_performed_ = -1;
717 735
718 // 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
719 // use on the impl thread. Otherwise, leave them unlocked. 737 // use on the impl thread. Otherwise, leave them unlocked.
720 if (has_pending_tree_ || needs_redraw_) 738 if (has_pending_tree_ || needs_redraw_)
721 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD; 739 texture_state_ = LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD;
722 else 740 else
723 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; 741 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED;
724 } 742 }
725 743
726 void SchedulerStateMachine::UpdateStateOnActivation() { 744 void SchedulerStateMachine::UpdateStateOnActivation() {
745 if (commit_state_ == COMMIT_STATE_WAITING_FOR_ACTIVATION)
746 commit_state_ = COMMIT_STATE_IDLE;
747
727 // Update output surface state. 748 // Update output surface state.
728 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION) 749 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION)
729 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; 750 output_surface_state_ = OUTPUT_SURFACE_ACTIVE;
730 751
731 // Update readback state 752 // Update readback state
732 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION) 753 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION)
733 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_DRAW; 754 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_DRAW;
734 755
735 // Update forced redraw state 756 // Update forced redraw state
736 if (readback_state_ == READBACK_STATE_WAITING_FOR_ACTIVATION) 757 if (readback_state_ == READBACK_STATE_WAITING_FOR_ACTIVATION)
737 readback_state_ = READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK; 758 readback_state_ = READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK;
738 else if (readback_state_ == READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION) 759 else if (readback_state_ == READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION)
739 readback_state_ = READBACK_STATE_IDLE; 760 readback_state_ = READBACK_STATE_IDLE;
740 761
741 has_pending_tree_ = false; 762 has_pending_tree_ = false;
742 pending_tree_is_ready_for_activation_ = false; 763 pending_tree_is_ready_for_activation_ = false;
743 active_tree_needs_first_draw_ = true; 764 active_tree_needs_first_draw_ = true;
744 needs_redraw_ = true; 765 needs_redraw_ = true;
745 } 766 }
746 767
747 void SchedulerStateMachine::UpdateStateOnDraw(bool did_swap) { 768 void SchedulerStateMachine::UpdateStateOnDraw(bool did_swap) {
748 DCHECK(readback_state_ != READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT && 769 DCHECK(readback_state_ != READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT &&
749 readback_state_ != READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION) 770 readback_state_ != READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION)
750 << *AsValue(); 771 << *AsValue();
751 772
752 if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) { 773 if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) {
753 // The draw correspons to a readback commit. 774 // 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 775 // We are blocking commits from the main thread until after this draw, so
756 // we should not have a pending tree. 776 // we should not have a pending tree.
757 DCHECK(!has_pending_tree_); 777 DCHECK(!has_pending_tree_);
758 // We transition to COMMIT_STATE_FRAME_IN_PROGRESS because there is a 778 // We transition to COMMIT_STATE_FRAME_IN_PROGRESS because there is a
759 // pending BeginMainFrame behind the readback request. 779 // pending BeginMainFrame behind the readback request.
760 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; 780 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS;
761 readback_state_ = READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT; 781 readback_state_ = READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT;
762 } else if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) { 782 } else if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) {
763 DCHECK_EQ(commit_state_, COMMIT_STATE_WAITING_FOR_FIRST_DRAW); 783 forced_redraw_state_ = FORCED_REDRAW_STATE_IDLE;
784 }
785
786 if (did_swap && commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW)
764 commit_state_ = COMMIT_STATE_IDLE; 787 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 788
771 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) 789 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD)
772 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; 790 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED;
773 791
774 needs_redraw_ = false; 792 needs_redraw_ = false;
775 draw_if_possible_failed_ = false; 793 draw_if_possible_failed_ = false;
776 active_tree_needs_first_draw_ = false; 794 active_tree_needs_first_draw_ = false;
777 795
778 if (did_swap) 796 if (did_swap)
779 last_frame_number_swap_performed_ = current_frame_number_; 797 last_frame_number_swap_performed_ = current_frame_number_;
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 return true; 973 return true;
956 974
957 // Prioritize impl-thread draws in smoothness mode. 975 // Prioritize impl-thread draws in smoothness mode.
958 if (smoothness_takes_priority_) 976 if (smoothness_takes_priority_)
959 return true; 977 return true;
960 978
961 return false; 979 return false;
962 } 980 }
963 981
964 bool SchedulerStateMachine::MainThreadIsInHighLatencyMode() const { 982 bool SchedulerStateMachine::MainThreadIsInHighLatencyMode() const {
983 // If a commit is pending before the previous commit has been drawn, we
984 // are definitely in a high latency mode.
985 if (CommitPending() && (active_tree_needs_first_draw_ || has_pending_tree_))
986 return true;
987
965 // If we just sent a BeginMainFrame and haven't hit the deadline yet, the main 988 // If we just sent a BeginMainFrame and haven't hit the deadline yet, the main
966 // thread is in a low latency mode. 989 // thread is in a low latency mode.
967 if (last_frame_number_begin_main_frame_sent_ == current_frame_number_ && 990 if (last_frame_number_begin_main_frame_sent_ == current_frame_number_ &&
968 (begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING || 991 (begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING ||
969 begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME)) 992 begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME))
970 return false; 993 return false;
971 994
972 // If there's a commit in progress it must either be from the previous frame 995 // 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 996 // or it started after the impl thread's deadline. In either case the main
974 // thread is in high latency mode. 997 // thread is in high latency mode.
975 if (commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS || 998 if (CommitPending())
976 commit_state_ == COMMIT_STATE_READY_TO_COMMIT)
977 return true; 999 return true;
978 1000
979 // Similarly, if there's a pending tree the main thread is in high latency 1001 // Similarly, if there's a pending tree the main thread is in high latency
980 // mode, because either 1002 // mode, because either
981 // it's from the previous frame 1003 // it's from the previous frame
982 // or 1004 // or
983 // we're currently drawing the active tree and the pending tree will thus 1005 // we're currently drawing the active tree and the pending tree will thus
984 // only be drawn in the next frame. 1006 // only be drawn in the next frame.
985 if (has_pending_tree_) 1007 if (has_pending_tree_)
986 return true; 1008 return true;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 // BeginMainFrame behind the readback request. In that case, we can skip 1110 // BeginMainFrame behind the readback request. In that case, we can skip
1089 // READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME and go directly to 1111 // READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME and go directly to
1090 // READBACK_STATE_WAITING_FOR_COMMIT 1112 // READBACK_STATE_WAITING_FOR_COMMIT
1091 if (commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS) 1113 if (commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS)
1092 readback_state_ = READBACK_STATE_WAITING_FOR_COMMIT; 1114 readback_state_ = READBACK_STATE_WAITING_FOR_COMMIT;
1093 else 1115 else
1094 readback_state_ = READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME; 1116 readback_state_ = READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME;
1095 } 1117 }
1096 1118
1097 void SchedulerStateMachine::FinishCommit() { 1119 void SchedulerStateMachine::FinishCommit() {
1098 DCHECK(commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS) << *AsValue(); 1120 DCHECK(commit_state_ != COMMIT_STATE_IDLE) << *AsValue();
1099 commit_state_ = COMMIT_STATE_READY_TO_COMMIT; 1121 commit_state_ = COMMIT_STATE_READY_TO_COMMIT;
1100 } 1122 }
1101 1123
1102 void SchedulerStateMachine::BeginMainFrameAborted(bool did_handle) { 1124 void SchedulerStateMachine::BeginMainFrameAborted(bool did_handle) {
1103 DCHECK_EQ(commit_state_, COMMIT_STATE_FRAME_IN_PROGRESS); 1125 DCHECK_EQ(commit_state_, COMMIT_STATE_FRAME_IN_PROGRESS);
1104 if (did_handle) { 1126 if (did_handle) {
1105 bool commit_was_aborted = true; 1127 bool commit_was_aborted = true;
1106 UpdateStateOnCommit(commit_was_aborted); 1128 UpdateStateOnCommit(commit_was_aborted);
1107 } else { 1129 } else {
1108 DCHECK_NE(readback_state_, READBACK_STATE_WAITING_FOR_COMMIT); 1130 DCHECK_NE(readback_state_, READBACK_STATE_WAITING_FOR_COMMIT);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 case OUTPUT_SURFACE_ACTIVE: 1173 case OUTPUT_SURFACE_ACTIVE:
1152 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: 1174 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT:
1153 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: 1175 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION:
1154 return true; 1176 return true;
1155 } 1177 }
1156 NOTREACHED(); 1178 NOTREACHED();
1157 return false; 1179 return false;
1158 } 1180 }
1159 1181
1160 } // namespace cc 1182 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler_state_machine.h ('k') | cc/scheduler/scheduler_state_machine_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698