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

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

Issue 2659123004: cc: Add scheduler support for invalidating content on impl thread. (Closed)
Patch Set: .. Created 3 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
« no previous file with comments | « cc/scheduler/scheduler_state_machine.h ('k') | cc/trees/proxy_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
(...skipping 15 matching lines...) Expand all
26 forced_redraw_state_(FORCED_REDRAW_STATE_IDLE), 26 forced_redraw_state_(FORCED_REDRAW_STATE_IDLE),
27 commit_count_(0), 27 commit_count_(0),
28 current_frame_number_(0), 28 current_frame_number_(0),
29 last_frame_number_submit_performed_(-1), 29 last_frame_number_submit_performed_(-1),
30 last_frame_number_draw_performed_(-1), 30 last_frame_number_draw_performed_(-1),
31 last_frame_number_begin_main_frame_sent_(-1), 31 last_frame_number_begin_main_frame_sent_(-1),
32 last_frame_number_invalidate_compositor_frame_sink_performed_(-1), 32 last_frame_number_invalidate_compositor_frame_sink_performed_(-1),
33 draw_funnel_(false), 33 draw_funnel_(false),
34 send_begin_main_frame_funnel_(true), 34 send_begin_main_frame_funnel_(true),
35 invalidate_compositor_frame_sink_funnel_(false), 35 invalidate_compositor_frame_sink_funnel_(false),
36 impl_side_invalidation_funnel_(false),
36 prepare_tiles_funnel_(0), 37 prepare_tiles_funnel_(0),
37 consecutive_checkerboard_animations_(0), 38 consecutive_checkerboard_animations_(0),
38 pending_submit_frames_(0), 39 pending_submit_frames_(0),
39 submit_frames_with_current_compositor_frame_sink_(0), 40 submit_frames_with_current_compositor_frame_sink_(0),
40 needs_redraw_(false), 41 needs_redraw_(false),
41 needs_prepare_tiles_(false), 42 needs_prepare_tiles_(false),
42 needs_begin_main_frame_(false), 43 needs_begin_main_frame_(false),
43 needs_one_begin_impl_frame_(false), 44 needs_one_begin_impl_frame_(false),
44 visible_(false), 45 visible_(false),
45 begin_frame_source_paused_(false), 46 begin_frame_source_paused_(false),
46 resourceless_draw_(false), 47 resourceless_draw_(false),
47 can_draw_(false), 48 can_draw_(false),
48 has_pending_tree_(false), 49 has_pending_tree_(false),
49 pending_tree_is_ready_for_activation_(false), 50 pending_tree_is_ready_for_activation_(false),
50 active_tree_needs_first_draw_(false), 51 active_tree_needs_first_draw_(false),
51 did_create_and_initialize_first_compositor_frame_sink_(false), 52 did_create_and_initialize_first_compositor_frame_sink_(false),
52 tree_priority_(NEW_CONTENT_TAKES_PRIORITY), 53 tree_priority_(NEW_CONTENT_TAKES_PRIORITY),
53 scroll_handler_state_( 54 scroll_handler_state_(
54 ScrollHandlerState::SCROLL_DOES_NOT_AFFECT_SCROLL_HANDLER), 55 ScrollHandlerState::SCROLL_DOES_NOT_AFFECT_SCROLL_HANDLER),
55 critical_begin_main_frame_to_activate_is_fast_(true), 56 critical_begin_main_frame_to_activate_is_fast_(true),
56 main_thread_missed_last_deadline_(false), 57 main_thread_missed_last_deadline_(false),
57 skip_next_begin_main_frame_to_reduce_latency_(false), 58 skip_next_begin_main_frame_to_reduce_latency_(false),
58 defer_commits_(false), 59 defer_commits_(false),
59 video_needs_begin_frames_(false), 60 video_needs_begin_frames_(false),
60 last_commit_had_no_updates_(false), 61 last_commit_had_no_updates_(false),
61 wait_for_ready_to_draw_(false), 62 wait_for_ready_to_draw_(false),
62 did_draw_in_last_frame_(false), 63 did_draw_in_last_frame_(false),
63 did_submit_in_last_frame_(false) {} 64 did_submit_in_last_frame_(false),
65 needs_impl_side_invalidation_(false),
66 run_impl_side_invalidation_after_main_frame_aborted_(false) {}
64 67
65 const char* SchedulerStateMachine::CompositorFrameSinkStateToString( 68 const char* SchedulerStateMachine::CompositorFrameSinkStateToString(
66 CompositorFrameSinkState state) { 69 CompositorFrameSinkState state) {
67 switch (state) { 70 switch (state) {
68 case COMPOSITOR_FRAME_SINK_NONE: 71 case COMPOSITOR_FRAME_SINK_NONE:
69 return "COMPOSITOR_FRAME_SINK_NONE"; 72 return "COMPOSITOR_FRAME_SINK_NONE";
70 case COMPOSITOR_FRAME_SINK_ACTIVE: 73 case COMPOSITOR_FRAME_SINK_ACTIVE:
71 return "COMPOSITOR_FRAME_SINK_ACTIVE"; 74 return "COMPOSITOR_FRAME_SINK_ACTIVE";
72 case COMPOSITOR_FRAME_SINK_CREATING: 75 case COMPOSITOR_FRAME_SINK_CREATING:
73 return "COMPOSITOR_FRAME_SINK_CREATING"; 76 return "COMPOSITOR_FRAME_SINK_CREATING";
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 case ACTION_DRAW_FORCED: 173 case ACTION_DRAW_FORCED:
171 return "ACTION_DRAW_FORCED"; 174 return "ACTION_DRAW_FORCED";
172 case ACTION_DRAW_ABORT: 175 case ACTION_DRAW_ABORT:
173 return "ACTION_DRAW_ABORT"; 176 return "ACTION_DRAW_ABORT";
174 case ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION: 177 case ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION:
175 return "ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION"; 178 return "ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION";
176 case ACTION_PREPARE_TILES: 179 case ACTION_PREPARE_TILES:
177 return "ACTION_PREPARE_TILES"; 180 return "ACTION_PREPARE_TILES";
178 case ACTION_INVALIDATE_COMPOSITOR_FRAME_SINK: 181 case ACTION_INVALIDATE_COMPOSITOR_FRAME_SINK:
179 return "ACTION_INVALIDATE_COMPOSITOR_FRAME_SINK"; 182 return "ACTION_INVALIDATE_COMPOSITOR_FRAME_SINK";
183 case ACTION_RUN_IMPL_SIDE_INVALIDATION:
184 return "ACTION_RUN_IMPL_SIDE_INVALIDATION";
180 } 185 }
181 NOTREACHED(); 186 NOTREACHED();
182 return "???"; 187 return "???";
183 } 188 }
184 189
185 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> 190 std::unique_ptr<base::trace_event::ConvertableToTraceFormat>
186 SchedulerStateMachine::AsValue() const { 191 SchedulerStateMachine::AsValue() const {
187 std::unique_ptr<base::trace_event::TracedValue> state( 192 std::unique_ptr<base::trace_event::TracedValue> state(
188 new base::trace_event::TracedValue()); 193 new base::trace_event::TracedValue());
189 AsValueInto(state.get()); 194 AsValueInto(state.get());
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 return ACTION_DRAW_ABORT; 556 return ACTION_DRAW_ABORT;
552 else if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) 557 else if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW)
553 return ACTION_DRAW_FORCED; 558 return ACTION_DRAW_FORCED;
554 else 559 else
555 return ACTION_DRAW_IF_POSSIBLE; 560 return ACTION_DRAW_IF_POSSIBLE;
556 } 561 }
557 if (ShouldPrepareTiles()) 562 if (ShouldPrepareTiles())
558 return ACTION_PREPARE_TILES; 563 return ACTION_PREPARE_TILES;
559 if (ShouldSendBeginMainFrame()) 564 if (ShouldSendBeginMainFrame())
560 return ACTION_SEND_BEGIN_MAIN_FRAME; 565 return ACTION_SEND_BEGIN_MAIN_FRAME;
566 if (ShouldRunImplSideInvalidation())
567 return ACTION_RUN_IMPL_SIDE_INVALIDATION;
561 if (ShouldInvalidateCompositorFrameSink()) 568 if (ShouldInvalidateCompositorFrameSink())
562 return ACTION_INVALIDATE_COMPOSITOR_FRAME_SINK; 569 return ACTION_INVALIDATE_COMPOSITOR_FRAME_SINK;
563 if (ShouldBeginCompositorFrameSinkCreation()) 570 if (ShouldBeginCompositorFrameSinkCreation())
564 return ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION; 571 return ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION;
565 return ACTION_NONE; 572 return ACTION_NONE;
566 } 573 }
567 574
575 bool SchedulerStateMachine::ShouldRunImplSideInvalidation() const {
576 if (!needs_impl_side_invalidation_)
577 return false;
578
579 if (!CouldCreatePendingTree())
580 return false;
581
582 // If the main thread is ready to commit, the impl-side invalidations will be
583 // merged with the incoming main frame.
584 if (begin_main_frame_state_ == BEGIN_MAIN_FRAME_STATE_READY_TO_COMMIT)
585 return false;
586
587 // Don't invalidate too many times in the same frame.
588 if (impl_side_invalidation_funnel_)
Khushal 2017/01/31 02:04:41 May be this should get set after each commit, irre
589 return false;
590
591 // Don't keep waiting on the main thread if the commits are being aborted.
592 if (run_impl_side_invalidation_after_main_frame_aborted_)
593 return true;
594
595 // If BeginMainFrame has been sent, let's wait for the main thread before
596 // pipelining impl-side invalidations.
597 // TODO(khushalsagar): If the main thread is high latency, may be run
598 // impl-side invalidations instead of waiting on the main thread?
599 if (begin_main_frame_state_ == BEGIN_MAIN_FRAME_STATE_SENT ||
600 begin_main_frame_state_ == BEGIN_MAIN_FRAME_STATE_STARTED)
601 return false;
602
603 // If a main frame request is pending, always prioritize sending a
604 // BeginMainFrame and receiving an update from the main thread before creating
605 // a pending tree for impl-side invalidations.
606 if (CouldSendBeginMainFrame() &&
607 begin_main_frame_state_ ==
608 BeginMainFrameState::BEGIN_MAIN_FRAME_STATE_IDLE)
609 return false;
610
611 // At this point, create a pending tree to run impl-side invalidations.
612 return true;
613 }
614
615 void SchedulerStateMachine::WillRunImplSideInvalidation() {
616 DCHECK(needs_impl_side_invalidation_);
617
618 needs_impl_side_invalidation_ = false;
619 has_pending_tree_ = true;
620 run_impl_side_invalidation_after_main_frame_aborted_ = false;
621 impl_side_invalidation_funnel_ = true;
622 }
623
624 bool SchedulerStateMachine::CouldCreatePendingTree() const {
625 // Can't create a new pending tree till the current one is activated.
626 if (has_pending_tree_)
627 return false;
628
629 // Can't make frames while we're invisible.
630 if (!visible_)
631 return false;
632
633 // If the BeginFrameSource is paused, we will not be able to make any impl
634 // frames.
635 if (begin_frame_source_paused_)
636 return false;
637
638 return true;
639 }
640
568 void SchedulerStateMachine::WillSendBeginMainFrame() { 641 void SchedulerStateMachine::WillSendBeginMainFrame() {
569 DCHECK(!has_pending_tree_ || settings_.main_frame_before_activation_enabled); 642 DCHECK(!has_pending_tree_ || settings_.main_frame_before_activation_enabled);
570 DCHECK(visible_); 643 DCHECK(visible_);
571 DCHECK(!begin_frame_source_paused_); 644 DCHECK(!begin_frame_source_paused_);
572 DCHECK(!send_begin_main_frame_funnel_); 645 DCHECK(!send_begin_main_frame_funnel_);
573 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_SENT; 646 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_SENT;
574 needs_begin_main_frame_ = false; 647 needs_begin_main_frame_ = false;
575 send_begin_main_frame_funnel_ = true; 648 send_begin_main_frame_funnel_ = true;
576 last_frame_number_begin_main_frame_sent_ = current_frame_number_; 649 last_frame_number_begin_main_frame_sent_ = current_frame_number_;
577 } 650 }
578 651
579 void SchedulerStateMachine::WillCommit(bool commit_has_no_updates) { 652 void SchedulerStateMachine::WillCommit(bool commit_has_no_updates) {
580 DCHECK(!has_pending_tree_ || 653 DCHECK(!has_pending_tree_ ||
581 (settings_.main_frame_before_activation_enabled && 654 (settings_.main_frame_before_activation_enabled &&
582 commit_has_no_updates)); 655 commit_has_no_updates));
583 commit_count_++; 656 commit_count_++;
584 last_commit_had_no_updates_ = commit_has_no_updates; 657 last_commit_had_no_updates_ = commit_has_no_updates;
585 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_IDLE; 658 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_IDLE;
586 659
587 if (!commit_has_no_updates) { 660 if (!commit_has_no_updates) {
588 // Pending tree only exists if commit had updates. 661 // Pending tree only exists if commit had updates.
589 has_pending_tree_ = true; 662 has_pending_tree_ = true;
590 pending_tree_is_ready_for_activation_ = false; 663 pending_tree_is_ready_for_activation_ = false;
591 wait_for_ready_to_draw_ = settings_.commit_to_active_tree; 664 wait_for_ready_to_draw_ = settings_.commit_to_active_tree;
665
666 // If there was a commit, the impl-side invalidations will be merged with
667 // it.
668 if (needs_impl_side_invalidation_)
669 WillRunImplSideInvalidation();
670 } else if (needs_impl_side_invalidation_) {
671 run_impl_side_invalidation_after_main_frame_aborted_ = true;
592 } 672 }
593 673
594 // Update state related to forced draws. 674 // Update state related to forced draws.
595 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT) { 675 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT) {
596 forced_redraw_state_ = has_pending_tree_ 676 forced_redraw_state_ = has_pending_tree_
597 ? FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION 677 ? FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION
598 : FORCED_REDRAW_STATE_WAITING_FOR_DRAW; 678 : FORCED_REDRAW_STATE_WAITING_FOR_DRAW;
599 } 679 }
600 680
601 // Update the output surface state. 681 // Update the output surface state.
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 762
683 void SchedulerStateMachine::WillDraw() { 763 void SchedulerStateMachine::WillDraw() {
684 DCHECK(!draw_funnel_); 764 DCHECK(!draw_funnel_);
685 WillDrawInternal(); 765 WillDrawInternal();
686 } 766 }
687 767
688 void SchedulerStateMachine::DidDraw(DrawResult draw_result) { 768 void SchedulerStateMachine::DidDraw(DrawResult draw_result) {
689 DidDrawInternal(draw_result); 769 DidDrawInternal(draw_result);
690 } 770 }
691 771
772 void SchedulerStateMachine::SetNeedsImplSideInvalidation() {
773 needs_impl_side_invalidation_ = true;
774 }
775
692 void SchedulerStateMachine::AbortDraw() { 776 void SchedulerStateMachine::AbortDraw() {
693 // Pretend like the draw was successful. 777 // Pretend like the draw was successful.
694 // Note: We may abort at any time and cannot DCHECK that 778 // Note: We may abort at any time and cannot DCHECK that
695 // we haven't drawn in or swapped in the last frame here. 779 // we haven't drawn in or swapped in the last frame here.
696 WillDrawInternal(); 780 WillDrawInternal();
697 DidDrawInternal(DRAW_ABORTED_DRAINING_PIPELINE); 781 DidDrawInternal(DRAW_ABORTED_DRAINING_PIPELINE);
698 } 782 }
699 783
700 void SchedulerStateMachine::WillPrepareTiles() { 784 void SchedulerStateMachine::WillPrepareTiles() {
701 needs_prepare_tiles_ = false; 785 needs_prepare_tiles_ = false;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 844
761 // These are the cases where we require a BeginFrame message to make progress 845 // These are the cases where we require a BeginFrame message to make progress
762 // on requested actions. 846 // on requested actions.
763 bool SchedulerStateMachine::BeginFrameRequiredForAction() const { 847 bool SchedulerStateMachine::BeginFrameRequiredForAction() const {
764 // The forced draw respects our normal draw scheduling, so we need to 848 // The forced draw respects our normal draw scheduling, so we need to
765 // request a BeginImplFrame for it. 849 // request a BeginImplFrame for it.
766 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW) 850 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_DRAW)
767 return true; 851 return true;
768 852
769 return needs_redraw_ || needs_one_begin_impl_frame_ || 853 return needs_redraw_ || needs_one_begin_impl_frame_ ||
770 (needs_begin_main_frame_ && !defer_commits_); 854 (needs_begin_main_frame_ && !defer_commits_) ||
855 needs_impl_side_invalidation_;
771 } 856 }
772 857
773 // These are cases where we are very likely want a BeginFrame message in the 858 // These are cases where we are very likely want a BeginFrame message in the
774 // near future. Proactively requesting the BeginImplFrame helps hide the round 859 // near future. Proactively requesting the BeginImplFrame helps hide the round
775 // trip latency of the SetNeedsBeginFrame request that has to go to the 860 // trip latency of the SetNeedsBeginFrame request that has to go to the
776 // Browser. 861 // Browser.
777 // This includes things like drawing soon, but might not actually have a new 862 // This includes things like drawing soon, but might not actually have a new
778 // frame to draw when we receive the next BeginImplFrame. 863 // frame to draw when we receive the next BeginImplFrame.
779 bool SchedulerStateMachine::ProactiveBeginFrameWanted() const { 864 bool SchedulerStateMachine::ProactiveBeginFrameWanted() const {
780 // Do not be proactive when invisible. 865 // Do not be proactive when invisible.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 current_frame_number_++; 905 current_frame_number_++;
821 906
822 last_commit_had_no_updates_ = false; 907 last_commit_had_no_updates_ = false;
823 did_draw_in_last_frame_ = false; 908 did_draw_in_last_frame_ = false;
824 did_submit_in_last_frame_ = false; 909 did_submit_in_last_frame_ = false;
825 needs_one_begin_impl_frame_ = false; 910 needs_one_begin_impl_frame_ = false;
826 911
827 // Clear funnels for any actions we perform during the frame. 912 // Clear funnels for any actions we perform during the frame.
828 send_begin_main_frame_funnel_ = false; 913 send_begin_main_frame_funnel_ = false;
829 invalidate_compositor_frame_sink_funnel_ = false; 914 invalidate_compositor_frame_sink_funnel_ = false;
915 impl_side_invalidation_funnel_ = false;
830 916
831 // "Drain" the PrepareTiles funnel. 917 // "Drain" the PrepareTiles funnel.
832 if (prepare_tiles_funnel_ > 0) 918 if (prepare_tiles_funnel_ > 0)
833 prepare_tiles_funnel_--; 919 prepare_tiles_funnel_--;
834 } 920 }
835 921
836 void SchedulerStateMachine::OnBeginImplFrameDeadline() { 922 void SchedulerStateMachine::OnBeginImplFrameDeadline() {
837 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE; 923 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE;
838 924
839 // Clear funnels for any actions we perform during the deadline. 925 // Clear funnels for any actions we perform during the deadline.
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 case COMPOSITOR_FRAME_SINK_ACTIVE: 1189 case COMPOSITOR_FRAME_SINK_ACTIVE:
1104 case COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_COMMIT: 1190 case COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_COMMIT:
1105 case COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_ACTIVATION: 1191 case COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_ACTIVATION:
1106 return true; 1192 return true;
1107 } 1193 }
1108 NOTREACHED(); 1194 NOTREACHED();
1109 return false; 1195 return false;
1110 } 1196 }
1111 1197
1112 } // namespace cc 1198 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler_state_machine.h ('k') | cc/trees/proxy_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698