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

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

Issue 1184863004: cc: Move timing history to the Scheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add cc:: Created 5 years, 6 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.h ('k') | cc/scheduler/scheduler_unittest.cc » ('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.h" 5 #include "cc/scheduler/scheduler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/profiler/scoped_tracker.h" 11 #include "base/profiler/scoped_tracker.h"
12 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
13 #include "base/trace_event/trace_event.h" 13 #include "base/trace_event/trace_event.h"
14 #include "base/trace_event/trace_event_argument.h" 14 #include "base/trace_event/trace_event_argument.h"
15 #include "cc/debug/devtools_instrumentation.h" 15 #include "cc/debug/devtools_instrumentation.h"
16 #include "cc/debug/traced_value.h" 16 #include "cc/debug/traced_value.h"
17 #include "cc/scheduler/compositor_timing_history.h"
17 #include "cc/scheduler/delay_based_time_source.h" 18 #include "cc/scheduler/delay_based_time_source.h"
18 19
19 namespace cc { 20 namespace cc {
20 21
21 scoped_ptr<Scheduler> Scheduler::Create( 22 scoped_ptr<Scheduler> Scheduler::Create(
22 SchedulerClient* client, 23 SchedulerClient* client,
23 const SchedulerSettings& settings, 24 const SchedulerSettings& settings,
24 int layer_tree_host_id, 25 int layer_tree_host_id,
25 base::SingleThreadTaskRunner* task_runner, 26 base::SingleThreadTaskRunner* task_runner,
26 BeginFrameSource* external_frame_source) { 27 BeginFrameSource* external_frame_source,
28 scoped_ptr<CompositorTimingHistory> compositor_timing_history) {
27 scoped_ptr<SyntheticBeginFrameSource> synthetic_frame_source; 29 scoped_ptr<SyntheticBeginFrameSource> synthetic_frame_source;
28 if (!settings.use_external_begin_frame_source) { 30 if (!settings.use_external_begin_frame_source) {
29 synthetic_frame_source = SyntheticBeginFrameSource::Create( 31 synthetic_frame_source = SyntheticBeginFrameSource::Create(
30 task_runner, BeginFrameArgs::DefaultInterval()); 32 task_runner, BeginFrameArgs::DefaultInterval());
31 } 33 }
32 scoped_ptr<BackToBackBeginFrameSource> unthrottled_frame_source = 34 scoped_ptr<BackToBackBeginFrameSource> unthrottled_frame_source =
33 BackToBackBeginFrameSource::Create(task_runner); 35 BackToBackBeginFrameSource::Create(task_runner);
34 return make_scoped_ptr(new Scheduler( 36 return make_scoped_ptr(new Scheduler(
35 client, settings, layer_tree_host_id, task_runner, external_frame_source, 37 client, settings, layer_tree_host_id, task_runner, external_frame_source,
36 synthetic_frame_source.Pass(), unthrottled_frame_source.Pass())); 38 synthetic_frame_source.Pass(), unthrottled_frame_source.Pass(),
39 compositor_timing_history.Pass()));
37 } 40 }
38 41
39 Scheduler::Scheduler( 42 Scheduler::Scheduler(
40 SchedulerClient* client, 43 SchedulerClient* client,
41 const SchedulerSettings& settings, 44 const SchedulerSettings& settings,
42 int layer_tree_host_id, 45 int layer_tree_host_id,
43 base::SingleThreadTaskRunner* task_runner, 46 base::SingleThreadTaskRunner* task_runner,
44 BeginFrameSource* external_frame_source, 47 BeginFrameSource* external_frame_source,
45 scoped_ptr<SyntheticBeginFrameSource> synthetic_frame_source, 48 scoped_ptr<SyntheticBeginFrameSource> synthetic_frame_source,
46 scoped_ptr<BackToBackBeginFrameSource> unthrottled_frame_source) 49 scoped_ptr<BackToBackBeginFrameSource> unthrottled_frame_source,
50 scoped_ptr<CompositorTimingHistory> compositor_timing_history)
47 : settings_(settings), 51 : settings_(settings),
48 client_(client), 52 client_(client),
49 layer_tree_host_id_(layer_tree_host_id), 53 layer_tree_host_id_(layer_tree_host_id),
50 task_runner_(task_runner), 54 task_runner_(task_runner),
51 external_frame_source_(external_frame_source), 55 external_frame_source_(external_frame_source),
52 synthetic_frame_source_(synthetic_frame_source.Pass()), 56 synthetic_frame_source_(synthetic_frame_source.Pass()),
53 unthrottled_frame_source_(unthrottled_frame_source.Pass()), 57 unthrottled_frame_source_(unthrottled_frame_source.Pass()),
54 frame_source_(BeginFrameSourceMultiplexer::Create()), 58 frame_source_(BeginFrameSourceMultiplexer::Create()),
55 throttle_frame_production_(false), 59 throttle_frame_production_(false),
60 compositor_timing_history_(compositor_timing_history.Pass()),
56 begin_impl_frame_deadline_mode_( 61 begin_impl_frame_deadline_mode_(
57 SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE), 62 SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE),
58 begin_impl_frame_tracker_(BEGINFRAMETRACKER_FROM_HERE), 63 begin_impl_frame_tracker_(BEGINFRAMETRACKER_FROM_HERE),
59 state_machine_(settings), 64 state_machine_(settings),
60 inside_process_scheduled_actions_(false), 65 inside_process_scheduled_actions_(false),
61 inside_action_(SchedulerStateMachine::ACTION_NONE), 66 inside_action_(SchedulerStateMachine::ACTION_NONE),
62 weak_factory_(this) { 67 weak_factory_(this) {
63 TRACE_EVENT1("cc", "Scheduler::Scheduler", "settings", settings_.AsValue()); 68 TRACE_EVENT1("cc", "Scheduler::Scheduler", "settings", settings_.AsValue());
64 DCHECK(client_); 69 DCHECK(client_);
65 DCHECK(!state_machine_.BeginFrameNeeded()); 70 DCHECK(!state_machine_.BeginFrameNeeded());
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 void Scheduler::BeginImplFrameWithDeadline(const BeginFrameArgs& args) { 437 void Scheduler::BeginImplFrameWithDeadline(const BeginFrameArgs& args) {
433 bool main_thread_is_in_high_latency_mode = 438 bool main_thread_is_in_high_latency_mode =
434 state_machine_.MainThreadIsInHighLatencyMode(); 439 state_machine_.MainThreadIsInHighLatencyMode();
435 TRACE_EVENT2("cc,benchmark", "Scheduler::BeginImplFrame", "args", 440 TRACE_EVENT2("cc,benchmark", "Scheduler::BeginImplFrame", "args",
436 args.AsValue(), "main_thread_is_high_latency", 441 args.AsValue(), "main_thread_is_high_latency",
437 main_thread_is_in_high_latency_mode); 442 main_thread_is_in_high_latency_mode);
438 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), 443 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"),
439 "MainThreadLatency", main_thread_is_in_high_latency_mode); 444 "MainThreadLatency", main_thread_is_in_high_latency_mode);
440 445
441 BeginFrameArgs adjusted_args = args; 446 BeginFrameArgs adjusted_args = args;
442 adjusted_args.deadline -= client_->DrawDurationEstimate(); 447 adjusted_args.deadline -= compositor_timing_history_->DrawDurationEstimate();
443 448
444 if (!state_machine_.impl_latency_takes_priority() && 449 if (!state_machine_.impl_latency_takes_priority() &&
445 main_thread_is_in_high_latency_mode && 450 main_thread_is_in_high_latency_mode &&
446 CanCommitAndActivateBeforeDeadline()) { 451 CanCommitAndActivateBeforeDeadline()) {
447 state_machine_.SetSkipNextBeginMainFrameToReduceLatency(); 452 state_machine_.SetSkipNextBeginMainFrameToReduceLatency();
448 } 453 }
449 454
450 BeginImplFrame(adjusted_args); 455 BeginImplFrame(adjusted_args);
451 456
452 // The deadline will be scheduled in ProcessScheduledActions. 457 // The deadline will be scheduled in ProcessScheduledActions.
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is fixed. 572 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is fixed.
568 tracked_objects::ScopedTracker tracking_profile1( 573 tracked_objects::ScopedTracker tracking_profile1(
569 FROM_HERE_WITH_EXPLICIT_FUNCTION( 574 FROM_HERE_WITH_EXPLICIT_FUNCTION(
570 "461509 Scheduler::OnBeginImplFrameDeadline1")); 575 "461509 Scheduler::OnBeginImplFrameDeadline1"));
571 state_machine_.OnBeginImplFrameDeadline(); 576 state_machine_.OnBeginImplFrameDeadline();
572 ProcessScheduledActions(); 577 ProcessScheduledActions();
573 FinishImplFrame(); 578 FinishImplFrame();
574 } 579 }
575 580
576 void Scheduler::DrawAndSwapIfPossible() { 581 void Scheduler::DrawAndSwapIfPossible() {
582 compositor_timing_history_->DidStartDrawing();
577 DrawResult result = client_->ScheduledActionDrawAndSwapIfPossible(); 583 DrawResult result = client_->ScheduledActionDrawAndSwapIfPossible();
578 state_machine_.DidDrawIfPossibleCompleted(result); 584 state_machine_.DidDrawIfPossibleCompleted(result);
585 compositor_timing_history_->DidFinishDrawing();
586 }
587
588 void Scheduler::DrawAndSwapForced() {
589 compositor_timing_history_->DidStartDrawing();
590 client_->ScheduledActionDrawAndSwapForced();
591 compositor_timing_history_->DidFinishDrawing();
579 } 592 }
580 593
581 void Scheduler::SetDeferCommits(bool defer_commits) { 594 void Scheduler::SetDeferCommits(bool defer_commits) {
582 TRACE_EVENT1("cc", "Scheduler::SetDeferCommits", 595 TRACE_EVENT1("cc", "Scheduler::SetDeferCommits",
583 "defer_commits", 596 "defer_commits",
584 defer_commits); 597 defer_commits);
585 state_machine_.SetDeferCommits(defer_commits); 598 state_machine_.SetDeferCommits(defer_commits);
586 ProcessScheduledActions(); 599 ProcessScheduledActions();
587 } 600 }
588 601
(...skipping 18 matching lines...) Expand all
607 state_machine_.UpdateState(action); 620 state_machine_.UpdateState(action);
608 base::AutoReset<SchedulerStateMachine::Action> 621 base::AutoReset<SchedulerStateMachine::Action>
609 mark_inside_action(&inside_action_, action); 622 mark_inside_action(&inside_action_, action);
610 switch (action) { 623 switch (action) {
611 case SchedulerStateMachine::ACTION_NONE: 624 case SchedulerStateMachine::ACTION_NONE:
612 break; 625 break;
613 case SchedulerStateMachine::ACTION_ANIMATE: 626 case SchedulerStateMachine::ACTION_ANIMATE:
614 client_->ScheduledActionAnimate(); 627 client_->ScheduledActionAnimate();
615 break; 628 break;
616 case SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME: 629 case SchedulerStateMachine::ACTION_SEND_BEGIN_MAIN_FRAME:
630 compositor_timing_history_->WillBeginMainFrame();
617 client_->ScheduledActionSendBeginMainFrame(); 631 client_->ScheduledActionSendBeginMainFrame();
618 break; 632 break;
619 case SchedulerStateMachine::ACTION_COMMIT: { 633 case SchedulerStateMachine::ACTION_COMMIT: {
620 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is 634 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is
621 // fixed. 635 // fixed.
622 tracked_objects::ScopedTracker tracking_profile4( 636 tracked_objects::ScopedTracker tracking_profile4(
623 FROM_HERE_WITH_EXPLICIT_FUNCTION( 637 FROM_HERE_WITH_EXPLICIT_FUNCTION(
624 "461509 Scheduler::ProcessScheduledActions4")); 638 "461509 Scheduler::ProcessScheduledActions4"));
625 client_->ScheduledActionCommit(); 639 client_->ScheduledActionCommit();
640 compositor_timing_history_->DidCommit();
626 break; 641 break;
627 } 642 }
628 case SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE: 643 case SchedulerStateMachine::ACTION_ACTIVATE_SYNC_TREE:
629 client_->ScheduledActionActivateSyncTree(); 644 client_->ScheduledActionActivateSyncTree();
645 compositor_timing_history_->DidActivateSyncTree();
630 break; 646 break;
631 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE: { 647 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_IF_POSSIBLE: {
632 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is 648 // TODO(robliao): Remove ScopedTracker below once crbug.com/461509 is
633 // fixed. 649 // fixed.
634 tracked_objects::ScopedTracker tracking_profile6( 650 tracked_objects::ScopedTracker tracking_profile6(
635 FROM_HERE_WITH_EXPLICIT_FUNCTION( 651 FROM_HERE_WITH_EXPLICIT_FUNCTION(
636 "461509 Scheduler::ProcessScheduledActions6")); 652 "461509 Scheduler::ProcessScheduledActions6"));
637 DrawAndSwapIfPossible(); 653 DrawAndSwapIfPossible();
638 break; 654 break;
639 } 655 }
640 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED: 656 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_FORCED:
641 client_->ScheduledActionDrawAndSwapForced(); 657 DrawAndSwapForced();
642 break; 658 break;
643 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT: 659 case SchedulerStateMachine::ACTION_DRAW_AND_SWAP_ABORT:
644 // No action is actually performed, but this allows the state machine to 660 // No action is actually performed, but this allows the state machine to
645 // advance out of its waiting to draw state without actually drawing. 661 // advance out of its waiting to draw state without actually drawing.
646 break; 662 break;
647 case SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION: 663 case SchedulerStateMachine::ACTION_BEGIN_OUTPUT_SURFACE_CREATION:
648 client_->ScheduledActionBeginOutputSurfaceCreation(); 664 client_->ScheduledActionBeginOutputSurfaceCreation();
649 break; 665 break;
650 case SchedulerStateMachine::ACTION_PREPARE_TILES: 666 case SchedulerStateMachine::ACTION_PREPARE_TILES:
651 client_->ScheduledActionPrepareTiles(); 667 client_->ScheduledActionPrepareTiles();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 !begin_retro_frame_task_.IsCancelled()); 712 !begin_retro_frame_task_.IsCancelled());
697 state->SetBoolean("begin_impl_frame_deadline_task", 713 state->SetBoolean("begin_impl_frame_deadline_task",
698 !begin_impl_frame_deadline_task_.IsCancelled()); 714 !begin_impl_frame_deadline_task_.IsCancelled());
699 state->SetString("inside_action", 715 state->SetString("inside_action",
700 SchedulerStateMachine::ActionToString(inside_action_)); 716 SchedulerStateMachine::ActionToString(inside_action_));
701 state->BeginDictionary("begin_impl_frame_args"); 717 state->BeginDictionary("begin_impl_frame_args");
702 begin_impl_frame_tracker_.AsValueInto(Now(), state); 718 begin_impl_frame_tracker_.AsValueInto(Now(), state);
703 state->EndDictionary(); 719 state->EndDictionary();
704 state->EndDictionary(); 720 state->EndDictionary();
705 721
706 state->BeginDictionary("client_state"); 722 state->BeginDictionary("compositor_timing_history");
707 state->SetDouble("draw_duration_estimate_ms", 723 compositor_timing_history_->AsValueInto(state);
708 client_->DrawDurationEstimate().InMillisecondsF());
709 state->SetDouble(
710 "begin_main_frame_to_commit_duration_estimate_ms",
711 client_->BeginMainFrameToCommitDurationEstimate().InMillisecondsF());
712 state->SetDouble(
713 "commit_to_activate_duration_estimate_ms",
714 client_->CommitToActivateDurationEstimate().InMillisecondsF());
715 state->EndDictionary(); 724 state->EndDictionary();
716 } 725 }
717 726
718 bool Scheduler::CanCommitAndActivateBeforeDeadline() const { 727 bool Scheduler::CanCommitAndActivateBeforeDeadline() const {
719 BeginFrameArgs args = 728 BeginFrameArgs args =
720 begin_impl_frame_tracker_.DangerousMethodCurrentOrLast(); 729 begin_impl_frame_tracker_.DangerousMethodCurrentOrLast();
721 730
722 // Check if the main thread computation and commit can be finished before the 731 // Check if the main thread computation and commit can be finished before the
723 // impl thread's deadline. 732 // impl thread's deadline.
724 base::TimeTicks estimated_draw_time = 733 base::TimeTicks estimated_draw_time =
725 args.frame_time + client_->BeginMainFrameToCommitDurationEstimate() + 734 args.frame_time +
726 client_->CommitToActivateDurationEstimate(); 735 compositor_timing_history_->BeginMainFrameToCommitDurationEstimate() +
736 compositor_timing_history_->CommitToActivateDurationEstimate();
727 737
728 TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), 738 TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"),
729 "CanCommitAndActivateBeforeDeadline", 739 "CanCommitAndActivateBeforeDeadline",
730 "time_left_after_drawing_ms", 740 "time_left_after_drawing_ms",
731 (args.deadline - estimated_draw_time).InMillisecondsF(), "state", 741 (args.deadline - estimated_draw_time).InMillisecondsF(), "state",
732 AsValue()); 742 AsValue());
733 743
734 return estimated_draw_time < args.deadline; 744 return estimated_draw_time < args.deadline;
735 } 745 }
736 746
737 bool Scheduler::IsBeginMainFrameSentOrStarted() const { 747 bool Scheduler::IsBeginMainFrameSentOrStarted() const {
738 return (state_machine_.commit_state() == 748 return (state_machine_.commit_state() ==
739 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT || 749 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_SENT ||
740 state_machine_.commit_state() == 750 state_machine_.commit_state() ==
741 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED); 751 SchedulerStateMachine::COMMIT_STATE_BEGIN_MAIN_FRAME_STARTED);
742 } 752 }
743 753
744 } // namespace cc 754 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler.h ('k') | cc/scheduler/scheduler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698