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_FIRST_DRAW: | |
91 return "COMMIT_STATE_WAITING_FOR_FIRST_DRAW"; | |
92 } | 90 } |
93 NOTREACHED(); | 91 NOTREACHED(); |
94 return "???"; | 92 return "???"; |
95 } | 93 } |
96 | 94 |
97 const char* SchedulerStateMachine::TextureStateToString(TextureState state) { | 95 const char* SchedulerStateMachine::TextureStateToString(TextureState state) { |
98 switch (state) { | 96 switch (state) { |
99 case LAYER_TEXTURE_STATE_UNLOCKED: | 97 case LAYER_TEXTURE_STATE_UNLOCKED: |
100 return "LAYER_TEXTURE_STATE_UNLOCKED"; | 98 return "LAYER_TEXTURE_STATE_UNLOCKED"; |
101 case LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD: | 99 case LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD: |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 } | 351 } |
354 | 352 |
355 bool SchedulerStateMachine::ShouldDraw() const { | 353 bool SchedulerStateMachine::ShouldDraw() const { |
356 // After a readback, make sure not to draw again until we've replaced the | 354 // After a readback, make sure not to draw again until we've replaced the |
357 // readback commit with a real one. | 355 // readback commit with a real one. |
358 if (readback_state_ == READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT || | 356 if (readback_state_ == READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT || |
359 readback_state_ == READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION) | 357 readback_state_ == READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION) |
360 return false; | 358 return false; |
361 | 359 |
362 // Draw immediately for readbacks to unblock the main thread quickly. | 360 // Draw immediately for readbacks to unblock the main thread quickly. |
363 if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) { | 361 if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) |
364 DCHECK_EQ(commit_state_, COMMIT_STATE_WAITING_FOR_FIRST_DRAW); | |
365 return true; | 362 return true; |
366 } | |
367 | 363 |
368 // If we need to abort draws, we should do so ASAP since the draw could | 364 // If we need to abort draws, we should do so ASAP since the draw could |
369 // be blocking other important actions (like output surface initialization), | 365 // be blocking other important actions (like output surface initialization), |
370 // from occuring. If we are waiting for the first draw, then perfom the | 366 // from occuring. If we are waiting for the first draw, then perfom the |
371 // aborted draw to keep things moving. If we are not waiting for the first | 367 // aborted draw to keep things moving. If we are not waiting for the first |
372 // draw however, we don't want to abort for no reason. | 368 // draw however, we don't want to abort for no reason. |
373 if (PendingDrawsShouldBeAborted()) | 369 if (PendingDrawsShouldBeAborted()) |
374 return active_tree_needs_first_draw_; | 370 return active_tree_needs_first_draw_; |
375 | 371 |
376 // After this line, we only want to swap once per frame. | 372 // After this line, we only want to swap once per frame. |
377 if (HasSwappedThisFrame()) | 373 if (HasSwappedThisFrame()) |
378 return false; | 374 return false; |
379 | 375 |
380 // Except for the cases above, do not draw outside of the BeginImplFrame | 376 // Except for the cases above, do not draw outside of the BeginImplFrame |
381 // deadline. | 377 // deadline. |
382 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) | 378 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) |
383 return false; | 379 return false; |
384 | 380 |
385 // Only handle forced redraws due to timeouts on the regular deadline. | 381 // Only handle forced redraws due to timeouts on the regular deadline. |
386 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) { | 382 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) |
387 DCHECK_EQ(commit_state_, COMMIT_STATE_WAITING_FOR_FIRST_DRAW); | |
388 return true; | 383 return true; |
389 } | |
390 | 384 |
391 return needs_redraw_; | 385 return needs_redraw_; |
392 } | 386 } |
393 | 387 |
394 bool SchedulerStateMachine::ShouldAcquireLayerTexturesForMainThread() const { | 388 bool SchedulerStateMachine::ShouldAcquireLayerTexturesForMainThread() const { |
395 if (!main_thread_needs_layer_textures_) | 389 if (!main_thread_needs_layer_textures_) |
396 return false; | 390 return false; |
397 if (texture_state_ == LAYER_TEXTURE_STATE_UNLOCKED) | 391 if (texture_state_ == LAYER_TEXTURE_STATE_UNLOCKED) |
398 return true; | 392 return true; |
399 DCHECK_EQ(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD); | 393 DCHECK_EQ(texture_state_, LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 } | 438 } |
445 | 439 |
446 bool SchedulerStateMachine::ShouldSendBeginMainFrame() const { | 440 bool SchedulerStateMachine::ShouldSendBeginMainFrame() const { |
447 if (!needs_commit_) | 441 if (!needs_commit_) |
448 return false; | 442 return false; |
449 | 443 |
450 // Only send BeginMainFrame when there isn't another commit pending already. | 444 // Only send BeginMainFrame when there isn't another commit pending already. |
451 if (commit_state_ != COMMIT_STATE_IDLE) | 445 if (commit_state_ != COMMIT_STATE_IDLE) |
452 return false; | 446 return false; |
453 | 447 |
454 // We can't accept a commit if we have a pending tree. | 448 // Starting the commit while we still have a pending tree will block the |
455 if (has_pending_tree_) | 449 // main thread until the pending tree activates. |
| 450 // Disabled when smoothness takes priority to reduce CPU contention. |
| 451 if (has_pending_tree_ && (!settings_.start_commit_before_activate_enabled || |
| 452 smoothness_takes_priority_)) |
| 453 return false; |
| 454 |
| 455 // If we are not impl-side-painting, starting the commit before the active |
| 456 // tree has drawn will block the main thread until the first draw occurs. |
| 457 // If we are impl-side-painting however, we will not block the main thread |
| 458 // by starting the commit before the active tree has drawn since the pending |
| 459 // tree is free to accept the commit. |
| 460 // Disabled when smoothness takes priority to reduce CPU contention. |
| 461 if (active_tree_needs_first_draw_ && |
| 462 (!settings_.start_commit_before_draw_enabled || |
| 463 smoothness_takes_priority_)) |
456 return false; | 464 return false; |
457 | 465 |
458 // We want to handle readback commits immediately to unblock the main thread. | 466 // We want to handle readback commits immediately to unblock the main thread. |
459 // Note: This BeginMainFrame will correspond to the replacement commit that | 467 // Note: This BeginMainFrame will correspond to the replacement commit that |
460 // comes after the readback commit itself, so we only send the BeginMainFrame | 468 // comes after the readback commit itself, so we only send the BeginMainFrame |
461 // if a commit isn't already pending behind the readback. | 469 // if a commit isn't already pending behind the readback. |
462 if (readback_state_ == READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME) | 470 if (readback_state_ == READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME) |
463 return !CommitPending(); | 471 return !CommitPending(); |
464 | 472 |
465 // We do not need commits if we are not visible, unless there's a | 473 // We do not need commits if we are not visible, unless there's a |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 if (!HasInitializedOutputSurface()) | 508 if (!HasInitializedOutputSurface()) |
501 return false; | 509 return false; |
502 | 510 |
503 if (skip_begin_main_frame_to_reduce_latency_) | 511 if (skip_begin_main_frame_to_reduce_latency_) |
504 return false; | 512 return false; |
505 | 513 |
506 return true; | 514 return true; |
507 } | 515 } |
508 | 516 |
509 bool SchedulerStateMachine::ShouldCommit() const { | 517 bool SchedulerStateMachine::ShouldCommit() const { |
510 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_.start_commit_before_activate_enabled); |
| 524 return false; |
| 525 } |
| 526 |
| 527 // If not impl-side-painting, we must not finish the commit until the |
| 528 // previous commit has been drawn. |
| 529 if (active_tree_needs_first_draw_ && !settings_.impl_side_painting) { |
| 530 DCHECK(settings_.start_commit_before_draw_enabled); |
| 531 return false; |
| 532 } |
| 533 |
| 534 return true; |
511 } | 535 } |
512 | 536 |
513 bool SchedulerStateMachine::IsCommitStateWaiting() const { | 537 bool SchedulerStateMachine::IsCommitStateWaiting() const { |
514 return commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS; | 538 return commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS; |
515 } | 539 } |
516 | 540 |
517 bool SchedulerStateMachine::ShouldManageTiles() const { | 541 bool SchedulerStateMachine::ShouldManageTiles() const { |
518 // ManageTiles only really needs to be called immediately after commit | 542 // ManageTiles only really needs to be called immediately after commit |
519 // and then periodically after that. Use a funnel to make sure we average | 543 // and then periodically after that. Use a funnel to make sure we average |
520 // one ManageTiles per BeginImplFrame in the long run. | 544 // one ManageTiles per BeginImplFrame in the long run. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 case ACTION_UPDATE_VISIBLE_TILES: | 597 case ACTION_UPDATE_VISIBLE_TILES: |
574 last_frame_number_update_visible_tiles_was_called_ = | 598 last_frame_number_update_visible_tiles_was_called_ = |
575 current_frame_number_; | 599 current_frame_number_; |
576 return; | 600 return; |
577 | 601 |
578 case ACTION_ACTIVATE_PENDING_TREE: | 602 case ACTION_ACTIVATE_PENDING_TREE: |
579 UpdateStateOnActivation(); | 603 UpdateStateOnActivation(); |
580 return; | 604 return; |
581 | 605 |
582 case ACTION_SEND_BEGIN_MAIN_FRAME: | 606 case ACTION_SEND_BEGIN_MAIN_FRAME: |
583 DCHECK(!has_pending_tree_); | 607 DCHECK(!has_pending_tree_ || |
| 608 settings_.start_commit_before_activate_enabled); |
| 609 DCHECK(!active_tree_needs_first_draw_ || |
| 610 settings_.start_commit_before_draw_enabled); |
584 DCHECK(visible_ || | 611 DCHECK(visible_ || |
585 readback_state_ == READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME); | 612 readback_state_ == READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME); |
586 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; | 613 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; |
587 needs_commit_ = false; | 614 needs_commit_ = false; |
588 if (readback_state_ == READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME) | 615 if (readback_state_ == READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME) |
589 readback_state_ = READBACK_STATE_WAITING_FOR_COMMIT; | 616 readback_state_ = READBACK_STATE_WAITING_FOR_COMMIT; |
590 last_frame_number_begin_main_frame_sent_ = | 617 last_frame_number_begin_main_frame_sent_ = |
591 current_frame_number_; | 618 current_frame_number_; |
592 return; | 619 return; |
593 | 620 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 | 657 |
631 case ACTION_MANAGE_TILES: | 658 case ACTION_MANAGE_TILES: |
632 UpdateStateOnManageTiles(); | 659 UpdateStateOnManageTiles(); |
633 return; | 660 return; |
634 } | 661 } |
635 } | 662 } |
636 | 663 |
637 void SchedulerStateMachine::UpdateStateOnCommit(bool commit_was_aborted) { | 664 void SchedulerStateMachine::UpdateStateOnCommit(bool commit_was_aborted) { |
638 commit_count_++; | 665 commit_count_++; |
639 | 666 |
| 667 // Transition directly to idle. |
| 668 commit_state_ = COMMIT_STATE_IDLE; |
| 669 |
640 // If we are impl-side-painting but the commit was aborted, then we behave | 670 // If we are impl-side-painting but the commit was aborted, then we behave |
641 // mostly as if we are not impl-side-painting since there is no pending tree. | 671 // mostly as if we are not impl-side-painting since there is no pending tree. |
642 has_pending_tree_ = settings_.impl_side_painting && !commit_was_aborted; | 672 has_pending_tree_ = settings_.impl_side_painting && !commit_was_aborted; |
643 | 673 |
644 // Update state related to readbacks. | 674 // Update state related to readbacks. |
645 if (readback_state_ == READBACK_STATE_WAITING_FOR_COMMIT) { | 675 if (readback_state_ == READBACK_STATE_WAITING_FOR_COMMIT) { |
646 // Update the state if this is the readback commit. | 676 // Update the state if this is the readback commit. |
647 readback_state_ = has_pending_tree_ | 677 readback_state_ = has_pending_tree_ |
648 ? READBACK_STATE_WAITING_FOR_ACTIVATION | 678 ? READBACK_STATE_WAITING_FOR_ACTIVATION |
649 : READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK; | 679 : READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK; |
(...skipping 25 matching lines...) Expand all Loading... |
675 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT) { | 705 if (output_surface_state_ == OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT) { |
676 if (has_pending_tree_) { | 706 if (has_pending_tree_) { |
677 output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION; | 707 output_surface_state_ = OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION; |
678 } else { | 708 } else { |
679 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; | 709 output_surface_state_ = OUTPUT_SURFACE_ACTIVE; |
680 needs_redraw_ = true; | 710 needs_redraw_ = true; |
681 } | 711 } |
682 } | 712 } |
683 } | 713 } |
684 | 714 |
685 // Update the commit state. We expect and wait for a draw if the commit | |
686 // was not aborted or if we are in a readback or forced draw. | |
687 if (!commit_was_aborted) { | |
688 DCHECK(commit_state_ == COMMIT_STATE_READY_TO_COMMIT); | |
689 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; | |
690 } else if (readback_state_ != READBACK_STATE_IDLE || | |
691 forced_redraw_state_ != FORCED_REDRAW_STATE_IDLE) { | |
692 commit_state_ = COMMIT_STATE_WAITING_FOR_FIRST_DRAW; | |
693 } else { | |
694 commit_state_ = COMMIT_STATE_IDLE; | |
695 } | |
696 | |
697 // Update state if we have a new active tree to draw, or if the active tree | 715 // Update state if we have a new active tree to draw, or if the active tree |
698 // was unchanged but we need to do a readback or forced draw. | 716 // was unchanged but we need to do a readback or forced draw. |
699 if (!has_pending_tree_ && | 717 if (!has_pending_tree_ && |
700 (!commit_was_aborted || | 718 (!commit_was_aborted || |
701 readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK || | 719 readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK || |
702 forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW)) { | 720 forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW)) { |
703 needs_redraw_ = true; | 721 needs_redraw_ = true; |
704 active_tree_needs_first_draw_ = true; | 722 active_tree_needs_first_draw_ = true; |
705 } | 723 } |
706 | 724 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 active_tree_needs_first_draw_ = true; | 756 active_tree_needs_first_draw_ = true; |
739 needs_redraw_ = true; | 757 needs_redraw_ = true; |
740 } | 758 } |
741 | 759 |
742 void SchedulerStateMachine::UpdateStateOnDraw(bool did_swap) { | 760 void SchedulerStateMachine::UpdateStateOnDraw(bool did_swap) { |
743 DCHECK(readback_state_ != READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT && | 761 DCHECK(readback_state_ != READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT && |
744 readback_state_ != READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION) | 762 readback_state_ != READBACK_STATE_WAITING_FOR_REPLACEMENT_ACTIVATION) |
745 << *AsValue(); | 763 << *AsValue(); |
746 | 764 |
747 if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) { | 765 if (readback_state_ == READBACK_STATE_WAITING_FOR_DRAW_AND_READBACK) { |
748 // The draw correspons to a readback commit. | 766 // The draw corresponds to a readback commit. |
749 DCHECK_EQ(commit_state_, COMMIT_STATE_WAITING_FOR_FIRST_DRAW); | |
750 // We are blocking commits from the main thread until after this draw, so | 767 // We are blocking commits from the main thread until after this draw, so |
751 // we should not have a pending tree. | 768 // we should not have a pending tree. |
752 DCHECK(!has_pending_tree_); | 769 DCHECK(!has_pending_tree_); |
753 // We transition to COMMIT_STATE_FRAME_IN_PROGRESS because there is a | 770 // We transition to COMMIT_STATE_FRAME_IN_PROGRESS because there is a |
754 // pending BeginMainFrame behind the readback request. | 771 // pending BeginMainFrame behind the readback request. |
755 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; | 772 commit_state_ = COMMIT_STATE_FRAME_IN_PROGRESS; |
756 readback_state_ = READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT; | 773 readback_state_ = READBACK_STATE_WAITING_FOR_REPLACEMENT_COMMIT; |
757 } else if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) { | 774 } else if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) { |
758 DCHECK_EQ(commit_state_, COMMIT_STATE_WAITING_FOR_FIRST_DRAW); | |
759 commit_state_ = COMMIT_STATE_IDLE; | |
760 forced_redraw_state_ = FORCED_REDRAW_STATE_IDLE; | 775 forced_redraw_state_ = FORCED_REDRAW_STATE_IDLE; |
761 } else if (commit_state_ == COMMIT_STATE_WAITING_FOR_FIRST_DRAW && | |
762 !has_pending_tree_) { | |
763 commit_state_ = COMMIT_STATE_IDLE; | |
764 } | 776 } |
765 | 777 |
766 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) | 778 if (texture_state_ == LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD) |
767 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; | 779 texture_state_ = LAYER_TEXTURE_STATE_UNLOCKED; |
768 | 780 |
769 needs_redraw_ = false; | 781 needs_redraw_ = false; |
770 draw_if_possible_failed_ = false; | 782 draw_if_possible_failed_ = false; |
771 active_tree_needs_first_draw_ = false; | 783 active_tree_needs_first_draw_ = false; |
772 | 784 |
773 if (did_swap) | 785 if (did_swap) |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 return true; | 957 return true; |
946 | 958 |
947 // Prioritize impl-thread draws in smoothness mode. | 959 // Prioritize impl-thread draws in smoothness mode. |
948 if (smoothness_takes_priority_) | 960 if (smoothness_takes_priority_) |
949 return true; | 961 return true; |
950 | 962 |
951 return false; | 963 return false; |
952 } | 964 } |
953 | 965 |
954 bool SchedulerStateMachine::MainThreadIsInHighLatencyMode() const { | 966 bool SchedulerStateMachine::MainThreadIsInHighLatencyMode() const { |
| 967 // If a commit is pending before the previous commit has been drawn, we |
| 968 // are definitely in a high latency mode. |
| 969 if (CommitPending() && (active_tree_needs_first_draw_ || has_pending_tree_)) |
| 970 return true; |
| 971 |
955 // If we just sent a BeginMainFrame and haven't hit the deadline yet, the main | 972 // If we just sent a BeginMainFrame and haven't hit the deadline yet, the main |
956 // thread is in a low latency mode. | 973 // thread is in a low latency mode. |
957 if (last_frame_number_begin_main_frame_sent_ == current_frame_number_ && | 974 if (last_frame_number_begin_main_frame_sent_ == current_frame_number_ && |
958 (begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING || | 975 (begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_BEGIN_FRAME_STARTING || |
959 begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME)) | 976 begin_impl_frame_state_ == BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME)) |
960 return false; | 977 return false; |
961 | 978 |
962 // If there's a commit in progress it must either be from the previous frame | 979 // 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 | 980 // or it started after the impl thread's deadline. In either case the main |
964 // thread is in high latency mode. | 981 // thread is in high latency mode. |
965 if (commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS || | 982 if (CommitPending()) |
966 commit_state_ == COMMIT_STATE_READY_TO_COMMIT) | |
967 return true; | 983 return true; |
968 | 984 |
969 // Similarly, if there's a pending tree the main thread is in high latency | 985 // Similarly, if there's a pending tree the main thread is in high latency |
970 // mode, because either | 986 // mode, because either |
971 // it's from the previous frame | 987 // it's from the previous frame |
972 // or | 988 // or |
973 // we're currently drawing the active tree and the pending tree will thus | 989 // we're currently drawing the active tree and the pending tree will thus |
974 // only be drawn in the next frame. | 990 // only be drawn in the next frame. |
975 if (has_pending_tree_) | 991 if (has_pending_tree_) |
976 return true; | 992 return true; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1065 // BeginMainFrame behind the readback request. In that case, we can skip | 1081 // BeginMainFrame behind the readback request. In that case, we can skip |
1066 // READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME and go directly to | 1082 // READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME and go directly to |
1067 // READBACK_STATE_WAITING_FOR_COMMIT | 1083 // READBACK_STATE_WAITING_FOR_COMMIT |
1068 if (commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS) | 1084 if (commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS) |
1069 readback_state_ = READBACK_STATE_WAITING_FOR_COMMIT; | 1085 readback_state_ = READBACK_STATE_WAITING_FOR_COMMIT; |
1070 else | 1086 else |
1071 readback_state_ = READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME; | 1087 readback_state_ = READBACK_STATE_NEEDS_BEGIN_MAIN_FRAME; |
1072 } | 1088 } |
1073 | 1089 |
1074 void SchedulerStateMachine::FinishCommit() { | 1090 void SchedulerStateMachine::FinishCommit() { |
1075 DCHECK(commit_state_ == COMMIT_STATE_FRAME_IN_PROGRESS) << *AsValue(); | 1091 DCHECK(commit_state_ != COMMIT_STATE_IDLE) << *AsValue(); |
1076 commit_state_ = COMMIT_STATE_READY_TO_COMMIT; | 1092 commit_state_ = COMMIT_STATE_READY_TO_COMMIT; |
1077 } | 1093 } |
1078 | 1094 |
1079 void SchedulerStateMachine::BeginMainFrameAborted(bool did_handle) { | 1095 void SchedulerStateMachine::BeginMainFrameAborted(bool did_handle) { |
1080 DCHECK_EQ(commit_state_, COMMIT_STATE_FRAME_IN_PROGRESS); | 1096 DCHECK_EQ(commit_state_, COMMIT_STATE_FRAME_IN_PROGRESS); |
1081 if (did_handle) { | 1097 if (did_handle) { |
1082 bool commit_was_aborted = true; | 1098 bool commit_was_aborted = true; |
1083 UpdateStateOnCommit(commit_was_aborted); | 1099 UpdateStateOnCommit(commit_was_aborted); |
1084 } else { | 1100 } else { |
1085 DCHECK_NE(readback_state_, READBACK_STATE_WAITING_FOR_COMMIT); | 1101 DCHECK_NE(readback_state_, READBACK_STATE_WAITING_FOR_COMMIT); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1129 case OUTPUT_SURFACE_ACTIVE: | 1145 case OUTPUT_SURFACE_ACTIVE: |
1130 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: | 1146 case OUTPUT_SURFACE_WAITING_FOR_FIRST_COMMIT: |
1131 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: | 1147 case OUTPUT_SURFACE_WAITING_FOR_FIRST_ACTIVATION: |
1132 return true; | 1148 return true; |
1133 } | 1149 } |
1134 NOTREACHED(); | 1150 NOTREACHED(); |
1135 return false; | 1151 return false; |
1136 } | 1152 } |
1137 | 1153 |
1138 } // namespace cc | 1154 } // namespace cc |
OLD | NEW |