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/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 | 13 |
14 namespace cc { | 14 namespace cc { |
15 | 15 |
16 namespace { | 16 namespace { |
17 // Surfaces and CompositorTimingHistory don't support more than 1 pending swap. | 17 // Surfaces and CompositorTimingHistory don't support more than 1 pending swap. |
18 const int kMaxPendingSubmitFrames = 1; | 18 const int kMaxPendingSubmitFrames = 1; |
19 } // namespace | 19 } // namespace |
20 | 20 |
21 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) | 21 SchedulerStateMachine::SchedulerStateMachine(const SchedulerSettings& settings) |
22 : settings_(settings), | 22 : settings_(settings), |
23 compositor_frame_sink_state_(COMPOSITOR_FRAME_SINK_NONE), | 23 compositor_frame_sink_state_(COMPOSITOR_FRAME_SINK_NONE), |
24 begin_impl_frame_state_(BEGIN_IMPL_FRAME_STATE_IDLE), | 24 begin_impl_frame_state_(BEGIN_IMPL_FRAME_STATE_IDLE), |
25 begin_main_frame_state_(BEGIN_MAIN_FRAME_STATE_IDLE), | 25 begin_main_frame_state_(BEGIN_MAIN_FRAME_STATE_IDLE), |
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 begin_frame_source_id_(0), | |
28 current_frame_number_(0), | 29 current_frame_number_(0), |
29 last_frame_number_submit_performed_(-1), | 30 last_frame_number_submit_performed_(0), |
30 last_frame_number_draw_performed_(-1), | 31 last_frame_number_draw_performed_(0), |
31 last_frame_number_begin_main_frame_sent_(-1), | 32 last_frame_number_begin_main_frame_sent_(0), |
32 last_frame_number_invalidate_compositor_frame_sink_performed_(-1), | 33 last_frame_number_invalidate_compositor_frame_sink_performed_(0), |
34 last_frame_number_pending_tree_was_fresh_(0), | |
35 last_frame_number_active_tree_was_fresh_(0), | |
36 last_frame_number_compositor_frame_was_fresh_(0), | |
33 draw_funnel_(false), | 37 draw_funnel_(false), |
34 send_begin_main_frame_funnel_(true), | 38 send_begin_main_frame_funnel_(true), |
35 invalidate_compositor_frame_sink_funnel_(false), | 39 invalidate_compositor_frame_sink_funnel_(false), |
36 prepare_tiles_funnel_(0), | 40 prepare_tiles_funnel_(0), |
37 consecutive_checkerboard_animations_(0), | 41 consecutive_checkerboard_animations_(0), |
38 pending_submit_frames_(0), | 42 pending_submit_frames_(0), |
39 submit_frames_with_current_compositor_frame_sink_(0), | 43 submit_frames_with_current_compositor_frame_sink_(0), |
40 needs_redraw_(false), | 44 needs_redraw_(false), |
41 needs_prepare_tiles_(false), | 45 needs_prepare_tiles_(false), |
42 needs_begin_main_frame_(false), | 46 needs_begin_main_frame_(false), |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 BeginMainFrameStateToString(begin_main_frame_state_)); | 204 BeginMainFrameStateToString(begin_main_frame_state_)); |
201 state->SetString( | 205 state->SetString( |
202 "compositor_frame_sink_state_", | 206 "compositor_frame_sink_state_", |
203 CompositorFrameSinkStateToString(compositor_frame_sink_state_)); | 207 CompositorFrameSinkStateToString(compositor_frame_sink_state_)); |
204 state->SetString("forced_redraw_state", | 208 state->SetString("forced_redraw_state", |
205 ForcedRedrawOnTimeoutStateToString(forced_redraw_state_)); | 209 ForcedRedrawOnTimeoutStateToString(forced_redraw_state_)); |
206 state->EndDictionary(); | 210 state->EndDictionary(); |
207 | 211 |
208 state->BeginDictionary("minor_state"); | 212 state->BeginDictionary("minor_state"); |
209 state->SetInteger("commit_count", commit_count_); | 213 state->SetInteger("commit_count", commit_count_); |
214 state->SetInteger("begin_frame_source_id", begin_frame_source_id_); | |
210 state->SetInteger("current_frame_number", current_frame_number_); | 215 state->SetInteger("current_frame_number", current_frame_number_); |
211 state->SetInteger("last_frame_number_submit_performed", | 216 state->SetInteger("last_frame_number_submit_performed", |
212 last_frame_number_submit_performed_); | 217 last_frame_number_submit_performed_); |
213 state->SetInteger("last_frame_number_draw_performed", | 218 state->SetInteger("last_frame_number_draw_performed", |
214 last_frame_number_draw_performed_); | 219 last_frame_number_draw_performed_); |
215 state->SetInteger("last_frame_number_begin_main_frame_sent", | 220 state->SetInteger("last_frame_number_begin_main_frame_sent", |
216 last_frame_number_begin_main_frame_sent_); | 221 last_frame_number_begin_main_frame_sent_); |
222 state->SetInteger("last_frame_number_pending_tree_was_fresh", | |
223 last_frame_number_pending_tree_was_fresh_); | |
224 state->SetInteger("last_frame_number_active_tree_was_fresh", | |
225 last_frame_number_active_tree_was_fresh_); | |
226 state->SetInteger("last_frame_number_compositor_frame_was_fresh", | |
227 last_frame_number_compositor_frame_was_fresh_); | |
217 state->SetBoolean("funnel: draw_funnel", draw_funnel_); | 228 state->SetBoolean("funnel: draw_funnel", draw_funnel_); |
218 state->SetBoolean("funnel: send_begin_main_frame_funnel", | 229 state->SetBoolean("funnel: send_begin_main_frame_funnel", |
219 send_begin_main_frame_funnel_); | 230 send_begin_main_frame_funnel_); |
220 state->SetInteger("funnel: prepare_tiles_funnel", prepare_tiles_funnel_); | 231 state->SetInteger("funnel: prepare_tiles_funnel", prepare_tiles_funnel_); |
221 state->SetBoolean("funnel: invalidate_compositor_frame_sink_funnel", | 232 state->SetBoolean("funnel: invalidate_compositor_frame_sink_funnel", |
222 invalidate_compositor_frame_sink_funnel_); | 233 invalidate_compositor_frame_sink_funnel_); |
223 state->SetInteger("consecutive_checkerboard_animations", | 234 state->SetInteger("consecutive_checkerboard_animations", |
224 consecutive_checkerboard_animations_); | 235 consecutive_checkerboard_animations_); |
225 state->SetInteger("pending_submit_frames_", pending_submit_frames_); | 236 state->SetInteger("pending_submit_frames_", pending_submit_frames_); |
226 state->SetInteger("submit_frames_with_current_compositor_frame_sink", | 237 state->SetInteger("submit_frames_with_current_compositor_frame_sink", |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
582 } | 593 } |
583 | 594 |
584 void SchedulerStateMachine::WillCommit(bool commit_has_no_updates) { | 595 void SchedulerStateMachine::WillCommit(bool commit_has_no_updates) { |
585 DCHECK(!has_pending_tree_ || | 596 DCHECK(!has_pending_tree_ || |
586 (settings_.main_frame_before_activation_enabled && | 597 (settings_.main_frame_before_activation_enabled && |
587 commit_has_no_updates)); | 598 commit_has_no_updates)); |
588 commit_count_++; | 599 commit_count_++; |
589 last_commit_had_no_updates_ = commit_has_no_updates; | 600 last_commit_had_no_updates_ = commit_has_no_updates; |
590 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_IDLE; | 601 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_IDLE; |
591 | 602 |
592 if (!commit_has_no_updates) { | 603 if (commit_has_no_updates) { |
593 // Pending tree only exists if commit had updates. | 604 // Pending tree might still exist from prior commit. |
605 if (has_pending_tree_) { | |
606 DCHECK(settings_.main_frame_before_activation_enabled); | |
607 last_frame_number_pending_tree_was_fresh_ = | |
608 last_frame_number_begin_main_frame_sent_; | |
609 } else { | |
610 last_frame_number_active_tree_was_fresh_ = | |
611 last_frame_number_begin_main_frame_sent_; | |
612 } | |
613 } else { | |
614 // We have a new pending tree. | |
594 has_pending_tree_ = true; | 615 has_pending_tree_ = true; |
595 pending_tree_is_ready_for_activation_ = false; | 616 pending_tree_is_ready_for_activation_ = false; |
617 last_frame_number_pending_tree_was_fresh_ = | |
618 last_frame_number_begin_main_frame_sent_; | |
596 wait_for_ready_to_draw_ = settings_.commit_to_active_tree; | 619 wait_for_ready_to_draw_ = settings_.commit_to_active_tree; |
597 } | 620 } |
598 | 621 |
599 // Update state related to forced draws. | 622 // Update state related to forced draws. |
600 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT) { | 623 if (forced_redraw_state_ == FORCED_REDRAW_STATE_WAITING_FOR_COMMIT) { |
601 forced_redraw_state_ = has_pending_tree_ | 624 forced_redraw_state_ = has_pending_tree_ |
602 ? FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION | 625 ? FORCED_REDRAW_STATE_WAITING_FOR_ACTIVATION |
603 : FORCED_REDRAW_STATE_WAITING_FOR_DRAW; | 626 : FORCED_REDRAW_STATE_WAITING_FOR_DRAW; |
604 } | 627 } |
605 | 628 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
817 return true; | 840 return true; |
818 | 841 |
819 // If the last commit was aborted because of early out (no updates), we should | 842 // If the last commit was aborted because of early out (no updates), we should |
820 // still want a begin frame in case there is a commit coming again. | 843 // still want a begin frame in case there is a commit coming again. |
821 if (last_commit_had_no_updates_) | 844 if (last_commit_had_no_updates_) |
822 return true; | 845 return true; |
823 | 846 |
824 return false; | 847 return false; |
825 } | 848 } |
826 | 849 |
827 void SchedulerStateMachine::OnBeginImplFrame() { | 850 void SchedulerStateMachine::OnBeginImplFrame(uint64_t source_id, |
851 uint64_t sequence_number) { | |
852 if (source_id != begin_frame_source_id_) { | |
853 begin_frame_source_id_ = source_id; | |
854 current_frame_number_ = sequence_number; | |
855 | |
856 // Consider us up to date up to the previous BeginFrame. | |
857 last_frame_number_active_tree_was_fresh_ = | |
858 current_frame_number_ > 0 ? current_frame_number_ - 1 : 0; | |
Sami
2016/12/06 12:41:07
Ditto about 1-based sequence numbers if we decide
Eric Seckler
2016/12/06 17:34:00
Done.
| |
859 last_frame_number_pending_tree_was_fresh_ = | |
860 last_frame_number_active_tree_was_fresh_; | |
861 last_frame_number_compositor_frame_was_fresh_ = | |
862 last_frame_number_active_tree_was_fresh_; | |
863 } | |
864 | |
865 DCHECK_GE(sequence_number, current_frame_number_); | |
866 | |
828 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME; | 867 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME; |
829 current_frame_number_++; | 868 current_frame_number_ = sequence_number; |
830 | 869 |
831 last_commit_had_no_updates_ = false; | 870 last_commit_had_no_updates_ = false; |
832 did_draw_in_last_frame_ = false; | 871 did_draw_in_last_frame_ = false; |
833 did_submit_in_last_frame_ = false; | 872 did_submit_in_last_frame_ = false; |
834 needs_one_begin_impl_frame_ = false; | 873 needs_one_begin_impl_frame_ = false; |
835 | 874 |
836 // Clear funnels for any actions we perform during the frame. | 875 // Clear funnels for any actions we perform during the frame. |
837 send_begin_main_frame_funnel_ = false; | 876 send_begin_main_frame_funnel_ = false; |
838 invalidate_compositor_frame_sink_funnel_ = false; | 877 invalidate_compositor_frame_sink_funnel_ = false; |
839 | 878 |
840 // "Drain" the PrepareTiles funnel. | 879 // "Drain" the PrepareTiles funnel. |
841 if (prepare_tiles_funnel_ > 0) | 880 if (prepare_tiles_funnel_ > 0) |
842 prepare_tiles_funnel_--; | 881 prepare_tiles_funnel_--; |
882 | |
883 // Update frame numbers for freshness if no updates are requested. | |
884 if (!needs_begin_main_frame_) { | |
885 if (has_pending_tree_) { | |
886 last_frame_number_pending_tree_was_fresh_ = current_frame_number_; | |
887 } else { | |
888 last_frame_number_active_tree_was_fresh_ = current_frame_number_; | |
889 | |
890 if (!needs_redraw_) | |
891 last_frame_number_compositor_frame_was_fresh_ = current_frame_number_; | |
892 } | |
893 } | |
843 } | 894 } |
844 | 895 |
845 void SchedulerStateMachine::OnBeginImplFrameDeadline() { | 896 void SchedulerStateMachine::OnBeginImplFrameDeadline() { |
846 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE; | 897 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE; |
847 | 898 |
848 // Clear funnels for any actions we perform during the deadline. | 899 // Clear funnels for any actions we perform during the deadline. |
849 draw_funnel_ = false; | 900 draw_funnel_ = false; |
850 | 901 |
851 // Allow one PrepareTiles per draw for synchronous compositor. | 902 // Allow one PrepareTiles per draw for synchronous compositor. |
852 if (settings_.using_synchronous_renderer_compositor) { | 903 if (settings_.using_synchronous_renderer_compositor) { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
978 void SchedulerStateMachine::DidSubmitCompositorFrame() { | 1029 void SchedulerStateMachine::DidSubmitCompositorFrame() { |
979 TRACE_EVENT_ASYNC_BEGIN1("cc", "Scheduler:pending_submit_frames", this, | 1030 TRACE_EVENT_ASYNC_BEGIN1("cc", "Scheduler:pending_submit_frames", this, |
980 "pending_frames", pending_submit_frames_); | 1031 "pending_frames", pending_submit_frames_); |
981 DCHECK_LT(pending_submit_frames_, kMaxPendingSubmitFrames); | 1032 DCHECK_LT(pending_submit_frames_, kMaxPendingSubmitFrames); |
982 | 1033 |
983 pending_submit_frames_++; | 1034 pending_submit_frames_++; |
984 submit_frames_with_current_compositor_frame_sink_++; | 1035 submit_frames_with_current_compositor_frame_sink_++; |
985 | 1036 |
986 did_submit_in_last_frame_ = true; | 1037 did_submit_in_last_frame_ = true; |
987 last_frame_number_submit_performed_ = current_frame_number_; | 1038 last_frame_number_submit_performed_ = current_frame_number_; |
1039 last_frame_number_compositor_frame_was_fresh_ = | |
1040 last_frame_number_active_tree_was_fresh_; | |
988 } | 1041 } |
989 | 1042 |
990 void SchedulerStateMachine::DidReceiveCompositorFrameAck() { | 1043 void SchedulerStateMachine::DidReceiveCompositorFrameAck() { |
991 TRACE_EVENT_ASYNC_END1("cc", "Scheduler:pending_submit_frames", this, | 1044 TRACE_EVENT_ASYNC_END1("cc", "Scheduler:pending_submit_frames", this, |
992 "pending_frames", pending_submit_frames_); | 1045 "pending_frames", pending_submit_frames_); |
993 pending_submit_frames_--; | 1046 pending_submit_frames_--; |
994 } | 1047 } |
995 | 1048 |
996 void SchedulerStateMachine::SetTreePrioritiesAndScrollState( | 1049 void SchedulerStateMachine::SetTreePrioritiesAndScrollState( |
997 TreePriority tree_priority, | 1050 TreePriority tree_priority, |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1112 case COMPOSITOR_FRAME_SINK_ACTIVE: | 1165 case COMPOSITOR_FRAME_SINK_ACTIVE: |
1113 case COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_COMMIT: | 1166 case COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_COMMIT: |
1114 case COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_ACTIVATION: | 1167 case COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_ACTIVATION: |
1115 return true; | 1168 return true; |
1116 } | 1169 } |
1117 NOTREACHED(); | 1170 NOTREACHED(); |
1118 return false; | 1171 return false; |
1119 } | 1172 } |
1120 | 1173 |
1121 } // namespace cc | 1174 } // namespace cc |
OLD | NEW |