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

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

Issue 2753843003: Create a new action triggered when a BeginMainFrame is not expected before vsync (Closed)
Patch Set: Add BeginMainFrameNotExpectedUntil to content::CompositorImpl for Android. Created 3 years, 7 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"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 case ACTION_DRAW_ABORT: 133 case ACTION_DRAW_ABORT:
134 return "ACTION_DRAW_ABORT"; 134 return "ACTION_DRAW_ABORT";
135 case ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION: 135 case ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION:
136 return "ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION"; 136 return "ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION";
137 case ACTION_PREPARE_TILES: 137 case ACTION_PREPARE_TILES:
138 return "ACTION_PREPARE_TILES"; 138 return "ACTION_PREPARE_TILES";
139 case ACTION_INVALIDATE_COMPOSITOR_FRAME_SINK: 139 case ACTION_INVALIDATE_COMPOSITOR_FRAME_SINK:
140 return "ACTION_INVALIDATE_COMPOSITOR_FRAME_SINK"; 140 return "ACTION_INVALIDATE_COMPOSITOR_FRAME_SINK";
141 case ACTION_PERFORM_IMPL_SIDE_INVALIDATION: 141 case ACTION_PERFORM_IMPL_SIDE_INVALIDATION:
142 return "ACTION_PERFORM_IMPL_SIDE_INVALIDATION"; 142 return "ACTION_PERFORM_IMPL_SIDE_INVALIDATION";
143 case ACTION_NOTIFY_BEGIN_MAIN_FRAME_NOT_SENT:
144 return "ACTION_NOTIFY_BEGIN_MAIN_FRAME_NOT_SENT";
143 } 145 }
144 NOTREACHED(); 146 NOTREACHED();
145 return "???"; 147 return "???";
146 } 148 }
147 149
148 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> 150 std::unique_ptr<base::trace_event::ConvertableToTraceFormat>
149 SchedulerStateMachine::AsValue() const { 151 SchedulerStateMachine::AsValue() const {
150 std::unique_ptr<base::trace_event::TracedValue> state( 152 std::unique_ptr<base::trace_event::TracedValue> state(
151 new base::trace_event::TracedValue()); 153 new base::trace_event::TracedValue());
152 AsValueInto(state.get()); 154 AsValueInto(state.get());
(...skipping 30 matching lines...) Expand all
183 state->SetInteger("last_begin_frame_sequence_number_begin_main_frame_sent", 185 state->SetInteger("last_begin_frame_sequence_number_begin_main_frame_sent",
184 last_begin_frame_sequence_number_begin_main_frame_sent_); 186 last_begin_frame_sequence_number_begin_main_frame_sent_);
185 state->SetInteger("last_begin_frame_sequence_number_pending_tree_was_fresh", 187 state->SetInteger("last_begin_frame_sequence_number_pending_tree_was_fresh",
186 last_begin_frame_sequence_number_pending_tree_was_fresh_); 188 last_begin_frame_sequence_number_pending_tree_was_fresh_);
187 state->SetInteger("last_begin_frame_sequence_number_active_tree_was_fresh", 189 state->SetInteger("last_begin_frame_sequence_number_active_tree_was_fresh",
188 last_begin_frame_sequence_number_active_tree_was_fresh_); 190 last_begin_frame_sequence_number_active_tree_was_fresh_);
189 state->SetInteger( 191 state->SetInteger(
190 "last_begin_frame_sequence_number_compositor_frame_was_fresh", 192 "last_begin_frame_sequence_number_compositor_frame_was_fresh",
191 last_begin_frame_sequence_number_compositor_frame_was_fresh_); 193 last_begin_frame_sequence_number_compositor_frame_was_fresh_);
192 state->SetBoolean("did_draw", did_draw_); 194 state->SetBoolean("did_draw", did_draw_);
193 state->SetBoolean("did_send_begin_main_frame", did_send_begin_main_frame_); 195 state->SetBoolean("did_send_begin_main_frame_for_current_frame",
196 did_send_begin_main_frame_for_current_frame_);
197 state->SetBoolean("did_notify_begin_main_frame_not_sent",
198 did_notify_begin_main_frame_not_sent_);
199 state->SetBoolean("did_commit_during_frame", did_commit_during_frame_);
194 state->SetBoolean("did_invalidate_compositor_frame_sink", 200 state->SetBoolean("did_invalidate_compositor_frame_sink",
195 did_invalidate_compositor_frame_sink_); 201 did_invalidate_compositor_frame_sink_);
196 state->SetBoolean("did_perform_impl_side_invalidaion", 202 state->SetBoolean("did_perform_impl_side_invalidaion",
197 did_perform_impl_side_invalidation_); 203 did_perform_impl_side_invalidation_);
198 state->SetBoolean("did_prepare_tiles", did_prepare_tiles_); 204 state->SetBoolean("did_prepare_tiles", did_prepare_tiles_);
199 state->SetInteger("consecutive_checkerboard_animations", 205 state->SetInteger("consecutive_checkerboard_animations",
200 consecutive_checkerboard_animations_); 206 consecutive_checkerboard_animations_);
201 state->SetInteger("pending_submit_frames", pending_submit_frames_); 207 state->SetInteger("pending_submit_frames", pending_submit_frames_);
202 state->SetInteger("submit_frames_with_current_compositor_frame_sink", 208 state->SetInteger("submit_frames_with_current_compositor_frame_sink",
203 submit_frames_with_current_compositor_frame_sink_); 209 submit_frames_with_current_compositor_frame_sink_);
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 return false; 375 return false;
370 376
371 // If we want to force activation, do so ASAP. 377 // If we want to force activation, do so ASAP.
372 if (PendingActivationsShouldBeForced()) 378 if (PendingActivationsShouldBeForced())
373 return true; 379 return true;
374 380
375 // At this point, only activate if we are ready to activate. 381 // At this point, only activate if we are ready to activate.
376 return pending_tree_is_ready_for_activation_; 382 return pending_tree_is_ready_for_activation_;
377 } 383 }
378 384
385 bool SchedulerStateMachine::ShouldNotifyBeginMainFrameNotSent() const {
386 // This method returns true if most of the conditions for sending a
387 // BeginMainFrame are met, but one is not actually requested. This gives the
388 // main thread the chance to do something else.
389
390 // Don't notify if a BeginMainFrame has already been requested or is in
391 // progress.
392 if (needs_begin_main_frame_ ||
393 begin_main_frame_state_ != BEGIN_MAIN_FRAME_STATE_IDLE)
394 return false;
395
396 // Only notify when we're visible.
397 if (!visible_)
398 return false;
399
400 // There are no BeginImplFrames while BeginFrameSource is paused, meaning
401 // the scheduler should send SendBeginMainFrameNotExpectedSoon instead,
402 // indicating a longer period of inactivity.
403 if (begin_frame_source_paused_)
404 return false;
405
406 // Do not notify that no BeginMainFrame was sent too many times in a single
407 // frame.
408 if (did_notify_begin_main_frame_not_sent_)
409 return false;
410
411 // Do not notify if a commit happened during this frame as the main thread
412 // will already be active and does not need to be woken up to make further
413 // actions. (This occurs if the main frame was scheduled but didn't complete
414 // before the vsync deadline).
415 if (did_commit_during_frame_)
416 return false;
417
418 return true;
419 }
420
379 bool SchedulerStateMachine::CouldSendBeginMainFrame() const { 421 bool SchedulerStateMachine::CouldSendBeginMainFrame() const {
380 if (!needs_begin_main_frame_) 422 if (!needs_begin_main_frame_)
381 return false; 423 return false;
382 424
383 // We can not perform commits if we are not visible. 425 // We can not perform commits if we are not visible.
384 if (!visible_) 426 if (!visible_)
385 return false; 427 return false;
386 428
387 // There are no BeginImplFrames while BeginFrameSource is paused, 429 // There are no BeginImplFrames while BeginFrameSource is paused,
388 // so should also stop BeginMainFrames. 430 // so should also stop BeginMainFrames.
389 if (begin_frame_source_paused_) 431 if (begin_frame_source_paused_)
390 return false; 432 return false;
391 433
392 // Do not make a new commits when it is deferred. 434 // Do not make a new commits when it is deferred.
393 if (defer_commits_) 435 if (defer_commits_)
394 return false; 436 return false;
395 437
396 return true; 438 return true;
397 } 439 }
398 440
399 bool SchedulerStateMachine::ShouldSendBeginMainFrame() const { 441 bool SchedulerStateMachine::ShouldSendBeginMainFrame() const {
400 if (!CouldSendBeginMainFrame()) 442 if (!CouldSendBeginMainFrame())
401 return false; 443 return false;
402 444
403 // Do not send more than one begin main frame in a begin frame. 445 // Do not send more than one begin main frame in a begin frame.
404 if (did_send_begin_main_frame_) 446 if (did_send_begin_main_frame_for_current_frame_)
405 return false; 447 return false;
406 448
407 // Only send BeginMainFrame when there isn't another commit pending already. 449 // Only send BeginMainFrame when there isn't another commit pending already.
408 // Other parts of the state machine indirectly defer the BeginMainFrame 450 // Other parts of the state machine indirectly defer the BeginMainFrame
409 // by transitioning to WAITING commit states rather than going 451 // by transitioning to WAITING commit states rather than going
410 // immediately to IDLE. 452 // immediately to IDLE.
411 if (begin_main_frame_state_ != BEGIN_MAIN_FRAME_STATE_IDLE) 453 if (begin_main_frame_state_ != BEGIN_MAIN_FRAME_STATE_IDLE)
412 return false; 454 return false;
413 455
414 // MFBA is disabled and we are waiting for previous activation. 456 // MFBA is disabled and we are waiting for previous activation.
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 if (ShouldPerformImplSideInvalidation()) 579 if (ShouldPerformImplSideInvalidation())
538 return ACTION_PERFORM_IMPL_SIDE_INVALIDATION; 580 return ACTION_PERFORM_IMPL_SIDE_INVALIDATION;
539 if (ShouldPrepareTiles()) 581 if (ShouldPrepareTiles())
540 return ACTION_PREPARE_TILES; 582 return ACTION_PREPARE_TILES;
541 if (ShouldSendBeginMainFrame()) 583 if (ShouldSendBeginMainFrame())
542 return ACTION_SEND_BEGIN_MAIN_FRAME; 584 return ACTION_SEND_BEGIN_MAIN_FRAME;
543 if (ShouldInvalidateCompositorFrameSink()) 585 if (ShouldInvalidateCompositorFrameSink())
544 return ACTION_INVALIDATE_COMPOSITOR_FRAME_SINK; 586 return ACTION_INVALIDATE_COMPOSITOR_FRAME_SINK;
545 if (ShouldBeginCompositorFrameSinkCreation()) 587 if (ShouldBeginCompositorFrameSinkCreation())
546 return ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION; 588 return ACTION_BEGIN_COMPOSITOR_FRAME_SINK_CREATION;
589 if (ShouldNotifyBeginMainFrameNotSent())
590 return ACTION_NOTIFY_BEGIN_MAIN_FRAME_NOT_SENT;
547 return ACTION_NONE; 591 return ACTION_NONE;
548 } 592 }
549 593
550 bool SchedulerStateMachine::ShouldPerformImplSideInvalidation() const { 594 bool SchedulerStateMachine::ShouldPerformImplSideInvalidation() const {
551 if (!needs_impl_side_invalidation_) 595 if (!needs_impl_side_invalidation_)
552 return false; 596 return false;
553 597
554 // Only perform impl side invalidation after the frame ends so that we wait 598 // Only perform impl side invalidation after the frame ends so that we wait
555 // for any commit to happen before invalidating. 599 // for any commit to happen before invalidating.
556 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) 600 if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE)
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 if (!HasInitializedCompositorFrameSink()) 657 if (!HasInitializedCompositorFrameSink())
614 return false; 658 return false;
615 659
616 return true; 660 return true;
617 } 661 }
618 662
619 void SchedulerStateMachine::WillSendBeginMainFrame() { 663 void SchedulerStateMachine::WillSendBeginMainFrame() {
620 DCHECK(!has_pending_tree_ || settings_.main_frame_before_activation_enabled); 664 DCHECK(!has_pending_tree_ || settings_.main_frame_before_activation_enabled);
621 DCHECK(visible_); 665 DCHECK(visible_);
622 DCHECK(!begin_frame_source_paused_); 666 DCHECK(!begin_frame_source_paused_);
623 DCHECK(!did_send_begin_main_frame_); 667 DCHECK(!did_send_begin_main_frame_for_current_frame_);
624 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_SENT; 668 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_SENT;
625 needs_begin_main_frame_ = false; 669 needs_begin_main_frame_ = false;
626 did_send_begin_main_frame_ = true; 670 did_send_begin_main_frame_for_current_frame_ = true;
627 last_frame_number_begin_main_frame_sent_ = current_frame_number_; 671 last_frame_number_begin_main_frame_sent_ = current_frame_number_;
628 last_begin_frame_sequence_number_begin_main_frame_sent_ = 672 last_begin_frame_sequence_number_begin_main_frame_sent_ =
629 begin_frame_sequence_number_; 673 begin_frame_sequence_number_;
630 } 674 }
631 675
676 void SchedulerStateMachine::WillNotifyBeginMainFrameNotSent() {
677 DCHECK(visible_);
678 DCHECK(!begin_frame_source_paused_);
679 DCHECK(!did_notify_begin_main_frame_not_sent_);
680 did_notify_begin_main_frame_not_sent_ = true;
681 }
682
632 void SchedulerStateMachine::WillCommit(bool commit_has_no_updates) { 683 void SchedulerStateMachine::WillCommit(bool commit_has_no_updates) {
633 bool can_have_pending_tree = 684 bool can_have_pending_tree =
634 commit_has_no_updates && 685 commit_has_no_updates &&
635 (settings_.main_frame_before_activation_enabled || 686 (settings_.main_frame_before_activation_enabled ||
636 current_pending_tree_is_impl_side_); 687 current_pending_tree_is_impl_side_);
637 DCHECK(!has_pending_tree_ || can_have_pending_tree); 688 DCHECK(!has_pending_tree_ || can_have_pending_tree);
638 commit_count_++; 689 commit_count_++;
639 last_commit_had_no_updates_ = commit_has_no_updates; 690 last_commit_had_no_updates_ = commit_has_no_updates;
640 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_IDLE; 691 begin_main_frame_state_ = BEGIN_MAIN_FRAME_STATE_IDLE;
692 did_commit_during_frame_ = true;
641 693
642 if (commit_has_no_updates) { 694 if (commit_has_no_updates) {
643 // Pending tree might still exist from prior commit. 695 // Pending tree might still exist from prior commit.
644 if (has_pending_tree_) { 696 if (has_pending_tree_) {
645 DCHECK(can_have_pending_tree); 697 DCHECK(can_have_pending_tree);
646 last_begin_frame_sequence_number_pending_tree_was_fresh_ = 698 last_begin_frame_sequence_number_pending_tree_was_fresh_ =
647 last_begin_frame_sequence_number_begin_main_frame_sent_; 699 last_begin_frame_sequence_number_begin_main_frame_sent_;
648 } else { 700 } else {
649 if (last_begin_frame_sequence_number_compositor_frame_was_fresh_ == 701 if (last_begin_frame_sequence_number_compositor_frame_was_fresh_ ==
650 last_begin_frame_sequence_number_active_tree_was_fresh_) { 702 last_begin_frame_sequence_number_active_tree_was_fresh_) {
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 UpdateBeginFrameSequenceNumbersForBeginFrame(source_id, sequence_number); 1028 UpdateBeginFrameSequenceNumbersForBeginFrame(source_id, sequence_number);
977 1029
978 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME; 1030 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME;
979 current_frame_number_++; 1031 current_frame_number_++;
980 1032
981 last_commit_had_no_updates_ = false; 1033 last_commit_had_no_updates_ = false;
982 did_draw_in_last_frame_ = false; 1034 did_draw_in_last_frame_ = false;
983 did_submit_in_last_frame_ = false; 1035 did_submit_in_last_frame_ = false;
984 needs_one_begin_impl_frame_ = false; 1036 needs_one_begin_impl_frame_ = false;
985 1037
986 did_send_begin_main_frame_ = false; 1038 did_notify_begin_main_frame_not_sent_ = false;
1039 did_send_begin_main_frame_for_current_frame_ = false;
1040 did_commit_during_frame_ = false;
987 did_invalidate_compositor_frame_sink_ = false; 1041 did_invalidate_compositor_frame_sink_ = false;
988 did_perform_impl_side_invalidation_ = false; 1042 did_perform_impl_side_invalidation_ = false;
989 } 1043 }
990 1044
991 void SchedulerStateMachine::OnBeginImplFrameDeadline() { 1045 void SchedulerStateMachine::OnBeginImplFrameDeadline() {
992 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE; 1046 begin_impl_frame_state_ = BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE;
993 1047
994 // Clear funnels for any actions we perform during the deadline. 1048 // Clear funnels for any actions we perform during the deadline.
995 did_draw_ = false; 1049 did_draw_ = false;
996 1050
(...skipping 13 matching lines...) Expand all
1010 skip_next_begin_main_frame_to_reduce_latency_ = false; 1064 skip_next_begin_main_frame_to_reduce_latency_ = false;
1011 1065
1012 // If a new or undrawn active tree is pending after the deadline, 1066 // If a new or undrawn active tree is pending after the deadline,
1013 // then the main thread is in a high latency mode. 1067 // then the main thread is in a high latency mode.
1014 main_thread_missed_last_deadline_ = 1068 main_thread_missed_last_deadline_ =
1015 CommitPending() || has_pending_tree_ || active_tree_needs_first_draw_; 1069 CommitPending() || has_pending_tree_ || active_tree_needs_first_draw_;
1016 1070
1017 // If we're entering a state where we won't get BeginFrames set all the 1071 // If we're entering a state where we won't get BeginFrames set all the
1018 // funnels so that we don't perform any actions that we shouldn't. 1072 // funnels so that we don't perform any actions that we shouldn't.
1019 if (!BeginFrameNeeded()) 1073 if (!BeginFrameNeeded())
1020 did_send_begin_main_frame_ = true; 1074 did_send_begin_main_frame_for_current_frame_ = true;
1021 1075
1022 // Synchronous compositor finishes BeginFrames before triggering their 1076 // Synchronous compositor finishes BeginFrames before triggering their
1023 // deadline. Therefore, we update sequence numbers when becoming idle, before 1077 // deadline. Therefore, we update sequence numbers when becoming idle, before
1024 // the Scheduler sends its BeginFrameAck. 1078 // the Scheduler sends its BeginFrameAck.
1025 if (settings_.using_synchronous_renderer_compositor) 1079 if (settings_.using_synchronous_renderer_compositor)
1026 UpdateBeginFrameSequenceNumbersForBeginFrameDeadline(); 1080 UpdateBeginFrameSequenceNumbersForBeginFrameDeadline();
1027 } 1081 }
1028 1082
1029 SchedulerStateMachine::BeginImplFrameDeadlineMode 1083 SchedulerStateMachine::BeginImplFrameDeadlineMode
1030 SchedulerStateMachine::CurrentBeginImplFrameDeadlineMode() const { 1084 SchedulerStateMachine::CurrentBeginImplFrameDeadlineMode() const {
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 case COMPOSITOR_FRAME_SINK_ACTIVE: 1319 case COMPOSITOR_FRAME_SINK_ACTIVE:
1266 case COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_COMMIT: 1320 case COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_COMMIT:
1267 case COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_ACTIVATION: 1321 case COMPOSITOR_FRAME_SINK_WAITING_FOR_FIRST_ACTIVATION:
1268 return true; 1322 return true;
1269 } 1323 }
1270 NOTREACHED(); 1324 NOTREACHED();
1271 return false; 1325 return false;
1272 } 1326 }
1273 1327
1274 } // namespace cc 1328 } // 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