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

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

Issue 2632563003: [cc] Calculate the correct latest_confirmed_sequence_number in cc::Scheduler. (Closed)
Patch Set: rebase. 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
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"
11 #include "base/trace_event/trace_event_argument.h" 11 #include "base/trace_event/trace_event_argument.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "cc/output/begin_frame_args.h"
13 14
14 namespace cc { 15 namespace cc {
15 16
16 namespace { 17 namespace {
17 // Surfaces and CompositorTimingHistory don't support more than 1 pending swap. 18 // Surfaces and CompositorTimingHistory don't support more than 1 pending swap.
18 const int kMaxPendingSubmitFrames = 1; 19 const int kMaxPendingSubmitFrames = 1;
19 } // namespace 20 } // namespace
20 21
21 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) 22 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings)
22 : settings_(settings), 23 : settings_(settings),
23 compositor_frame_sink_state_(COMPOSITOR_FRAME_SINK_NONE), 24 compositor_frame_sink_state_(COMPOSITOR_FRAME_SINK_NONE),
24 begin_impl_frame_state_(BEGIN_IMPL_FRAME_STATE_IDLE), 25 begin_impl_frame_state_(BEGIN_IMPL_FRAME_STATE_IDLE),
25 begin_main_frame_state_(BEGIN_MAIN_FRAME_STATE_IDLE), 26 begin_main_frame_state_(BEGIN_MAIN_FRAME_STATE_IDLE),
26 forced_redraw_state_(FORCED_REDRAW_STATE_IDLE), 27 forced_redraw_state_(FORCED_REDRAW_STATE_IDLE),
28 begin_frame_source_id_(0),
29 begin_frame_sequence_number_(BeginFrameArgs::kStartingFrameNumber),
30 last_begin_frame_sequence_number_begin_main_frame_sent_(
31 BeginFrameArgs::kInvalidFrameNumber),
32 last_begin_frame_sequence_number_pending_tree_was_fresh_(
33 BeginFrameArgs::kInvalidFrameNumber),
34 last_begin_frame_sequence_number_active_tree_was_fresh_(
35 BeginFrameArgs::kInvalidFrameNumber),
36 last_begin_frame_sequence_number_compositor_frame_was_fresh_(
37 BeginFrameArgs::kInvalidFrameNumber),
27 commit_count_(0), 38 commit_count_(0),
28 current_frame_number_(0), 39 current_frame_number_(0),
29 last_frame_number_submit_performed_(-1), 40 last_frame_number_submit_performed_(-1),
30 last_frame_number_draw_performed_(-1), 41 last_frame_number_draw_performed_(-1),
31 last_frame_number_begin_main_frame_sent_(-1), 42 last_frame_number_begin_main_frame_sent_(-1),
32 last_frame_number_invalidate_compositor_frame_sink_performed_(-1), 43 last_frame_number_invalidate_compositor_frame_sink_performed_(-1),
33 draw_funnel_(false), 44 draw_funnel_(false),
34 send_begin_main_frame_funnel_(true), 45 send_begin_main_frame_funnel_(true),
35 invalidate_compositor_frame_sink_funnel_(false), 46 invalidate_compositor_frame_sink_funnel_(false),
36 prepare_tiles_funnel_(0), 47 prepare_tiles_funnel_(0),
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 218
208 state->BeginDictionary("minor_state"); 219 state->BeginDictionary("minor_state");
209 state->SetInteger("commit_count", commit_count_); 220 state->SetInteger("commit_count", commit_count_);
210 state->SetInteger("current_frame_number", current_frame_number_); 221 state->SetInteger("current_frame_number", current_frame_number_);
211 state->SetInteger("last_frame_number_submit_performed", 222 state->SetInteger("last_frame_number_submit_performed",
212 last_frame_number_submit_performed_); 223 last_frame_number_submit_performed_);
213 state->SetInteger("last_frame_number_draw_performed", 224 state->SetInteger("last_frame_number_draw_performed",
214 last_frame_number_draw_performed_); 225 last_frame_number_draw_performed_);
215 state->SetInteger("last_frame_number_begin_main_frame_sent", 226 state->SetInteger("last_frame_number_begin_main_frame_sent",
216 last_frame_number_begin_main_frame_sent_); 227 last_frame_number_begin_main_frame_sent_);
228 state->SetInteger("begin_frame_source_id", begin_frame_source_id_);
229 state->SetInteger("begin_frame_sequence_number",
230 begin_frame_sequence_number_);
231 state->SetInteger("last_begin_frame_sequence_number_begin_main_frame_sent",
232 last_begin_frame_sequence_number_begin_main_frame_sent_);
233 state->SetInteger("last_begin_frame_sequence_number_pending_tree_was_fresh",
234 last_begin_frame_sequence_number_pending_tree_was_fresh_);
235 state->SetInteger("last_begin_frame_sequence_number_active_tree_was_fresh",
236 last_begin_frame_sequence_number_active_tree_was_fresh_);
237 state->SetInteger(
238 "last_begin_frame_sequence_number_compositor_frame_was_fresh",
239 last_begin_frame_sequence_number_compositor_frame_was_fresh_);
217 state->SetBoolean("funnel: draw_funnel", draw_funnel_); 240 state->SetBoolean("funnel: draw_funnel", draw_funnel_);
218 state->SetBoolean("funnel: send_begin_main_frame_funnel", 241 state->SetBoolean("funnel: send_begin_main_frame_funnel",
219 send_begin_main_frame_funnel_); 242 send_begin_main_frame_funnel_);
220 state->SetInteger("funnel: prepare_tiles_funnel", prepare_tiles_funnel_); 243 state->SetInteger("funnel: prepare_tiles_funnel", prepare_tiles_funnel_);
221 state->SetBoolean("funnel: invalidate_compositor_frame_sink_funnel", 244 state->SetBoolean("funnel: invalidate_compositor_frame_sink_funnel",
222 invalidate_compositor_frame_sink_funnel_); 245 invalidate_compositor_frame_sink_funnel_);
223 state->SetInteger("consecutive_checkerboard_animations", 246 state->SetInteger("consecutive_checkerboard_animations",
224 consecutive_checkerboard_animations_); 247 consecutive_checkerboard_animations_);
225 state->SetInteger("pending_submit_frames_", pending_submit_frames_); 248 state->SetInteger("pending_submit_frames_", pending_submit_frames_);
226 state->SetInteger("submit_frames_with_current_compositor_frame_sink", 249 state->SetInteger("submit_frames_with_current_compositor_frame_sink",
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 590
568 void SchedulerStateMachine::WillSendBeginMainFrame() { 591 void SchedulerStateMachine::WillSendBeginMainFrame() {
569 DCHECK(!has_pending_tree_ || settings_.main_frame_before_activation_enabled); 592 DCHECK(!has_pending_tree_ || settings_.main_frame_before_activation_enabled);
570 DCHECK(visible_); 593 DCHECK(visible_);
571 DCHECK(!begin_frame_source_paused_); 594 DCHECK(!begin_frame_source_paused_);
572 DCHECK(!send_begin_main_frame_funnel_); 595 DCHECK(!send_begin_main_frame_funnel_);
573 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_SENT; 596 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_SENT;
574 needs_begin_main_frame_ = false; 597 needs_begin_main_frame_ = false;
575 send_begin_main_frame_funnel_ = true; 598 send_begin_main_frame_funnel_ = true;
576 last_frame_number_begin_main_frame_sent_ = current_frame_number_; 599 last_frame_number_begin_main_frame_sent_ = current_frame_number_;
600 last_begin_frame_sequence_number_begin_main_frame_sent_ =
601 begin_frame_sequence_number_;
577 } 602 }
578 603
579 void SchedulerStateMachine::WillCommit(bool commit_has_no_updates) { 604 void SchedulerStateMachine::WillCommit(bool commit_has_no_updates) {
580 DCHECK(!has_pending_tree_ || 605 DCHECK(!has_pending_tree_ ||
581 (settings_.main_frame_before_activation_enabled && 606 (settings_.main_frame_before_activation_enabled &&
582 commit_has_no_updates)); 607 commit_has_no_updates));
583 commit_count_++; 608 commit_count_++;
584 last_commit_had_no_updates_ = commit_has_no_updates; 609 last_commit_had_no_updates_ = commit_has_no_updates;
585 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_IDLE; 610 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_IDLE;
586 611
587 if (!commit_has_no_updates) { 612 if (commit_has_no_updates) {
588 // Pending tree only exists if commit had updates. 613 // Pending tree might still exist from prior commit.
614 if (has_pending_tree_) {
615 DCHECK(settings_.main_frame_before_activation_enabled);
616 last_begin_frame_sequence_number_pending_tree_was_fresh_ =
617 last_begin_frame_sequence_number_begin_main_frame_sent_;
618 } else {
619 last_begin_frame_sequence_number_active_tree_was_fresh_ =
620 last_begin_frame_sequence_number_begin_main_frame_sent_;
brianderson 2017/02/14 23:58:56 Do you also need to do: if (...active_tree_was_fre
Eric Seckler 2017/02/17 00:07:26 Brian and I chatted about why this works, even if
621 }
622 } else {
623 // We have a new pending tree.
589 has_pending_tree_ = true; 624 has_pending_tree_ = true;
590 pending_tree_is_ready_for_activation_ = false; 625 pending_tree_is_ready_for_activation_ = false;
626 last_begin_frame_sequence_number_pending_tree_was_fresh_ =
627 last_begin_frame_sequence_number_begin_main_frame_sent_;
591 wait_for_ready_to_draw_ = settings_.commit_to_active_tree; 628 wait_for_ready_to_draw_ = settings_.commit_to_active_tree;
592 } 629 }
593 630
594 // Update state related to forced draws. 631 // Update state related to forced draws.
595 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT) { 632 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT) {
596 forced_redraw_state_ = has_pending_tree_ 633 forced_redraw_state_ = has_pending_tree_
597 ? FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION 634 ? FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION
598 : FORCED_REDRAW_STATE_WAITING_FOR_DRAW; 635 : FORCED_REDRAW_STATE_WAITING_FOR_DRAW;
599 } 636 }
600 637
(...skipping 11 matching lines...) Expand all
612 COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_ACTIVATION) 649 COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_ACTIVATION)
613 compositor_frame_sink_state_ = COMPOSITOR_FRAME_SINK_ACTIVE; 650 compositor_frame_sink_state_ = COMPOSITOR_FRAME_SINK_ACTIVE;
614 651
615 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION) 652 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION)
616 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_DRAW; 653 forced_redraw_state_ = FORCED_REDRAW_STATE_WAITING_FOR_DRAW;
617 654
618 has_pending_tree_ = false; 655 has_pending_tree_ = false;
619 pending_tree_is_ready_for_activation_ = false; 656 pending_tree_is_ready_for_activation_ = false;
620 active_tree_needs_first_draw_ = true; 657 active_tree_needs_first_draw_ = true;
621 needs_redraw_ = true; 658 needs_redraw_ = true;
659 last_begin_frame_sequence_number_active_tree_was_fresh_ =
660 last_begin_frame_sequence_number_pending_tree_was_fresh_;
622 } 661 }
623 662
624 void SchedulerStateMachine::WillDrawInternal() { 663 void SchedulerStateMachine::WillDrawInternal() {
625 // If a new active tree is pending after the one we are about to draw, 664 // If a new active tree is pending after the one we are about to draw,
626 // the main thread is in a high latency mode. 665 // the main thread is in a high latency mode.
627 // main_thread_missed_last_deadline_ is here in addition to 666 // main_thread_missed_last_deadline_ is here in addition to
628 // OnBeginImplFrameIdle for cases where the scheduler aborts draws outside 667 // OnBeginImplFrameIdle for cases where the scheduler aborts draws outside
629 // of the deadline. 668 // of the deadline.
630 main_thread_missed_last_deadline_ = CommitPending() || has_pending_tree_; 669 main_thread_missed_last_deadline_ = CommitPending() || has_pending_tree_;
631 670
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 return true; 847 return true;
809 848
810 // If the last commit was aborted because of early out (no updates), we should 849 // If the last commit was aborted because of early out (no updates), we should
811 // still want a begin frame in case there is a commit coming again. 850 // still want a begin frame in case there is a commit coming again.
812 if (last_commit_had_no_updates_) 851 if (last_commit_had_no_updates_)
813 return true; 852 return true;
814 853
815 return false; 854 return false;
816 } 855 }
817 856
818 void SchedulerStateMachine::OnBeginImplFrame() { 857 void SchedulerStateMachine::OnBeginFrameDroppedNotObserving(
858 uint32_t source_id,
859 uint64_t sequence_number) {
860 DCHECK(!BeginFrameNeeded());
861 DCHECK_EQ(BEGIN_IMPL_FRAME_STATE_IDLE, begin_impl_frame_state_);
862
863 // Confirms the dropped BeginFrame, since we don't have updates.
864 UpdateBeginFrameSequenceNumbersForBeginFrame(source_id, sequence_number);
865 UpdateBeginFrameSequenceNumbersForBeginFrameDeadline();
866 }
867
868 void SchedulerStateMachine::UpdateBeginFrameSequenceNumbersForBeginFrame(
869 uint32_t source_id,
870 uint64_t sequence_number) {
871 if (source_id != begin_frame_source_id_) {
872 begin_frame_source_id_ = source_id;
873 begin_frame_sequence_number_ = sequence_number;
874
875 // Reset freshness sequence numbers.
876 last_begin_frame_sequence_number_begin_main_frame_sent_ =
877 BeginFrameArgs::kInvalidFrameNumber;
878 last_begin_frame_sequence_number_active_tree_was_fresh_ =
879 BeginFrameArgs::kInvalidFrameNumber;
880 last_begin_frame_sequence_number_pending_tree_was_fresh_ =
881 BeginFrameArgs::kInvalidFrameNumber;
882 last_begin_frame_sequence_number_compositor_frame_was_fresh_ =
883 BeginFrameArgs::kInvalidFrameNumber;
884 } else {
885 DCHECK_GE(sequence_number, begin_frame_sequence_number_);
brianderson 2017/02/14 22:51:08 DCHECK_GT?
Eric Seckler 2017/02/14 23:43:45 This requires that we set begin_frame_sequence_num
886 begin_frame_sequence_number_ = sequence_number;
887 }
888 }
889
890 void SchedulerStateMachine::
891 UpdateBeginFrameSequenceNumbersForBeginFrameDeadline() {
892 // Update frame numbers for freshness in case no updates were necessary.
893 if (begin_main_frame_state_ == BEGIN_MAIN_FRAME_STATE_IDLE &&
brianderson 2017/02/14 22:51:09 Can you restructure this with early returns to red
Eric Seckler 2017/02/14 23:43:45 Done.
894 !needs_begin_main_frame_) {
895 if (has_pending_tree_) {
896 last_begin_frame_sequence_number_pending_tree_was_fresh_ =
897 begin_frame_sequence_number_;
898 } else {
899 last_begin_frame_sequence_number_active_tree_was_fresh_ =
900 begin_frame_sequence_number_;
901
902 if (!needs_redraw_)
903 last_begin_frame_sequence_number_compositor_frame_was_fresh_ =
904 begin_frame_sequence_number_;
905 }
906 }
907 }
908
909 void SchedulerStateMachine::OnBeginImplFrame(uint32_t source_id,
910 uint64_t sequence_number) {
911 UpdateBeginFrameSequenceNumbersForBeginFrame(source_id, sequence_number);
912
819 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME; 913 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME;
820 current_frame_number_++; 914 current_frame_number_++;
821 915
822 last_commit_had_no_updates_ = false; 916 last_commit_had_no_updates_ = false;
823 did_draw_in_last_frame_ = false; 917 did_draw_in_last_frame_ = false;
824 did_submit_in_last_frame_ = false; 918 did_submit_in_last_frame_ = false;
825 needs_one_begin_impl_frame_ = false; 919 needs_one_begin_impl_frame_ = false;
826 920
827 // Clear funnels for any actions we perform during the frame. 921 // Clear funnels for any actions we perform during the frame.
828 send_begin_main_frame_funnel_ = false; 922 send_begin_main_frame_funnel_ = false;
829 invalidate_compositor_frame_sink_funnel_ = false; 923 invalidate_compositor_frame_sink_funnel_ = false;
830 924
831 // "Drain" the PrepareTiles funnel. 925 // "Drain" the PrepareTiles funnel.
832 if (prepare_tiles_funnel_ > 0) 926 if (prepare_tiles_funnel_ > 0)
833 prepare_tiles_funnel_--; 927 prepare_tiles_funnel_--;
834 } 928 }
835 929
836 void SchedulerStateMachine::OnBeginImplFrameDeadline() { 930 void SchedulerStateMachine::OnBeginImplFrameDeadline() {
837 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE; 931 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE;
838 932
839 // Clear funnels for any actions we perform during the deadline. 933 // Clear funnels for any actions we perform during the deadline.
840 draw_funnel_ = false; 934 draw_funnel_ = false;
841 935
842 // Allow one PrepareTiles per draw for synchronous compositor. 936 // Allow one PrepareTiles per draw for synchronous compositor.
843 if (settings_.using_synchronous_renderer_compositor) { 937 if (settings_.using_synchronous_renderer_compositor) {
844 if (prepare_tiles_funnel_ > 0) 938 if (prepare_tiles_funnel_ > 0)
845 prepare_tiles_funnel_--; 939 prepare_tiles_funnel_--;
846 } 940 }
941
942 UpdateBeginFrameSequenceNumbersForBeginFrameDeadline();
847 } 943 }
848 944
849 void SchedulerStateMachine::OnBeginImplFrameIdle() { 945 void SchedulerStateMachine::OnBeginImplFrameIdle() {
850 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_IDLE; 946 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_IDLE;
851 947
852 skip_next_begin_main_frame_to_reduce_latency_ = false; 948 skip_next_begin_main_frame_to_reduce_latency_ = false;
853 949
854 // If a new or undrawn active tree is pending after the deadline, 950 // If a new or undrawn active tree is pending after the deadline,
855 // then the main thread is in a high latency mode. 951 // then the main thread is in a high latency mode.
856 main_thread_missed_last_deadline_ = 952 main_thread_missed_last_deadline_ =
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 void SchedulerStateMachine::DidSubmitCompositorFrame() { 1065 void SchedulerStateMachine::DidSubmitCompositorFrame() {
970 TRACE_EVENT_ASYNC_BEGIN1("cc", "Scheduler:pending_submit_frames", this, 1066 TRACE_EVENT_ASYNC_BEGIN1("cc", "Scheduler:pending_submit_frames", this,
971 "pending_frames", pending_submit_frames_); 1067 "pending_frames", pending_submit_frames_);
972 DCHECK_LT(pending_submit_frames_, kMaxPendingSubmitFrames); 1068 DCHECK_LT(pending_submit_frames_, kMaxPendingSubmitFrames);
973 1069
974 pending_submit_frames_++; 1070 pending_submit_frames_++;
975 submit_frames_with_current_compositor_frame_sink_++; 1071 submit_frames_with_current_compositor_frame_sink_++;
976 1072
977 did_submit_in_last_frame_ = true; 1073 did_submit_in_last_frame_ = true;
978 last_frame_number_submit_performed_ = current_frame_number_; 1074 last_frame_number_submit_performed_ = current_frame_number_;
1075 last_begin_frame_sequence_number_compositor_frame_was_fresh_ =
1076 last_begin_frame_sequence_number_active_tree_was_fresh_;
979 } 1077 }
980 1078
981 void SchedulerStateMachine::DidReceiveCompositorFrameAck() { 1079 void SchedulerStateMachine::DidReceiveCompositorFrameAck() {
982 TRACE_EVENT_ASYNC_END1("cc", "Scheduler:pending_submit_frames", this, 1080 TRACE_EVENT_ASYNC_END1("cc", "Scheduler:pending_submit_frames", this,
983 "pending_frames", pending_submit_frames_); 1081 "pending_frames", pending_submit_frames_);
984 pending_submit_frames_--; 1082 pending_submit_frames_--;
985 } 1083 }
986 1084
987 void SchedulerStateMachine::SetTreePrioritiesAndScrollState( 1085 void SchedulerStateMachine::SetTreePrioritiesAndScrollState(
988 TreePriority tree_priority, 1086 TreePriority tree_priority,
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 case COMPOSITOR_FRAME_SINK_ACTIVE: 1201 case COMPOSITOR_FRAME_SINK_ACTIVE:
1104 case COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_COMMIT: 1202 case COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_COMMIT:
1105 case COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_ACTIVATION: 1203 case COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_ACTIVATION:
1106 return true; 1204 return true;
1107 } 1205 }
1108 NOTREACHED(); 1206 NOTREACHED();
1109 return false; 1207 return false;
1110 } 1208 }
1111 1209
1112 } // namespace cc 1210 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698