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

Side by Side Diff: cc/trees/single_thread_proxy.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/trees/single_thread_proxy.h ('k') | cc/trees/thread_proxy.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/trees/single_thread_proxy.h" 5 #include "cc/trees/single_thread_proxy.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/profiler/scoped_tracker.h" 8 #include "base/profiler/scoped_tracker.h"
9 #include "base/trace_event/trace_event.h" 9 #include "base/trace_event/trace_event.h"
10 #include "cc/debug/benchmark_instrumentation.h" 10 #include "cc/debug/benchmark_instrumentation.h"
11 #include "cc/debug/devtools_instrumentation.h" 11 #include "cc/debug/devtools_instrumentation.h"
12 #include "cc/output/context_provider.h" 12 #include "cc/output/context_provider.h"
13 #include "cc/output/output_surface.h" 13 #include "cc/output/output_surface.h"
14 #include "cc/quads/draw_quad.h" 14 #include "cc/quads/draw_quad.h"
15 #include "cc/scheduler/commit_earlyout_reason.h" 15 #include "cc/scheduler/commit_earlyout_reason.h"
16 #include "cc/scheduler/compositor_timing_history.h"
17 #include "cc/scheduler/scheduler.h"
16 #include "cc/trees/layer_tree_host.h" 18 #include "cc/trees/layer_tree_host.h"
17 #include "cc/trees/layer_tree_host_single_thread_client.h" 19 #include "cc/trees/layer_tree_host_single_thread_client.h"
18 #include "cc/trees/layer_tree_impl.h" 20 #include "cc/trees/layer_tree_impl.h"
19 #include "cc/trees/scoped_abort_remaining_swap_promises.h" 21 #include "cc/trees/scoped_abort_remaining_swap_promises.h"
20 22
21 namespace cc { 23 namespace cc {
22 24
23 scoped_ptr<Proxy> SingleThreadProxy::Create( 25 scoped_ptr<Proxy> SingleThreadProxy::Create(
24 LayerTreeHost* layer_tree_host, 26 LayerTreeHost* layer_tree_host,
25 LayerTreeHostSingleThreadClient* client, 27 LayerTreeHostSingleThreadClient* client,
26 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, 28 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
27 scoped_ptr<BeginFrameSource> external_begin_frame_source) { 29 scoped_ptr<BeginFrameSource> external_begin_frame_source) {
28 return make_scoped_ptr(new SingleThreadProxy( 30 return make_scoped_ptr(new SingleThreadProxy(
29 layer_tree_host, 31 layer_tree_host,
30 client, 32 client,
31 main_task_runner, 33 main_task_runner,
32 external_begin_frame_source.Pass())); 34 external_begin_frame_source.Pass()));
33 } 35 }
34 36
35 SingleThreadProxy::SingleThreadProxy( 37 SingleThreadProxy::SingleThreadProxy(
36 LayerTreeHost* layer_tree_host, 38 LayerTreeHost* layer_tree_host,
37 LayerTreeHostSingleThreadClient* client, 39 LayerTreeHostSingleThreadClient* client,
38 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, 40 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
39 scoped_ptr<BeginFrameSource> external_begin_frame_source) 41 scoped_ptr<BeginFrameSource> external_begin_frame_source)
40 : Proxy(main_task_runner, NULL), 42 : Proxy(main_task_runner, NULL),
41 layer_tree_host_(layer_tree_host), 43 layer_tree_host_(layer_tree_host),
42 client_(client), 44 client_(client),
43 external_begin_frame_source_(external_begin_frame_source.Pass()), 45 external_begin_frame_source_(external_begin_frame_source.Pass()),
44 timing_history_(layer_tree_host->rendering_stats_instrumentation()),
45 next_frame_is_newly_committed_frame_(false), 46 next_frame_is_newly_committed_frame_(false),
46 #if DCHECK_IS_ON() 47 #if DCHECK_IS_ON()
47 inside_impl_frame_(false), 48 inside_impl_frame_(false),
48 #endif 49 #endif
49 inside_draw_(false), 50 inside_draw_(false),
50 defer_commits_(false), 51 defer_commits_(false),
51 animate_requested_(false), 52 animate_requested_(false),
52 commit_requested_(false), 53 commit_requested_(false),
53 inside_synchronous_composite_(false), 54 inside_synchronous_composite_(false),
54 output_surface_creation_requested_(false), 55 output_surface_creation_requested_(false),
55 weak_factory_(this) { 56 weak_factory_(this) {
56 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); 57 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy");
57 DCHECK(Proxy::IsMainThread()); 58 DCHECK(Proxy::IsMainThread());
58 DCHECK(layer_tree_host); 59 DCHECK(layer_tree_host);
59 60
60 if (layer_tree_host->settings().single_thread_proxy_scheduler && 61 if (layer_tree_host->settings().single_thread_proxy_scheduler &&
61 !scheduler_on_impl_thread_) { 62 !scheduler_on_impl_thread_) {
62 SchedulerSettings scheduler_settings( 63 SchedulerSettings scheduler_settings(
63 layer_tree_host->settings().ToSchedulerSettings()); 64 layer_tree_host->settings().ToSchedulerSettings());
64 scheduler_settings.commit_to_active_tree = CommitToActiveTree(); 65 scheduler_settings.commit_to_active_tree = CommitToActiveTree();
66
67 scoped_ptr<CompositorTimingHistory> compositor_timing_history(
68 new CompositorTimingHistory(
69 layer_tree_host->rendering_stats_instrumentation()));
70
65 scheduler_on_impl_thread_ = Scheduler::Create( 71 scheduler_on_impl_thread_ = Scheduler::Create(
66 this, scheduler_settings, layer_tree_host_->id(), 72 this, scheduler_settings, layer_tree_host_->id(),
67 MainThreadTaskRunner(), external_begin_frame_source_.get()); 73 MainThreadTaskRunner(), external_begin_frame_source_.get(),
74 compositor_timing_history.Pass());
68 } 75 }
69 } 76 }
70 77
71 void SingleThreadProxy::Start() { 78 void SingleThreadProxy::Start() {
72 DebugScopedSetImplThread impl(this); 79 DebugScopedSetImplThread impl(this);
73 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this); 80 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this);
74 } 81 }
75 82
76 SingleThreadProxy::~SingleThreadProxy() { 83 SingleThreadProxy::~SingleThreadProxy() {
77 TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy"); 84 TRACE_EVENT0("cc", "SingleThreadProxy::~SingleThreadProxy");
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 DCHECK(commit_blocking_task_runner_); 291 DCHECK(commit_blocking_task_runner_);
285 292
286 // Notify commit complete on the impl side after activate to satisfy any 293 // Notify commit complete on the impl side after activate to satisfy any
287 // SetNextCommitWaitsForActivation calls. 294 // SetNextCommitWaitsForActivation calls.
288 layer_tree_host_impl_->CommitComplete(); 295 layer_tree_host_impl_->CommitComplete();
289 296
290 DebugScopedSetMainThread main(this); 297 DebugScopedSetMainThread main(this);
291 commit_blocking_task_runner_.reset(); 298 commit_blocking_task_runner_.reset();
292 layer_tree_host_->CommitComplete(); 299 layer_tree_host_->CommitComplete();
293 layer_tree_host_->DidBeginMainFrame(); 300 layer_tree_host_->DidBeginMainFrame();
294 timing_history_.DidCommit();
295 301
296 next_frame_is_newly_committed_frame_ = true; 302 next_frame_is_newly_committed_frame_ = true;
297 } 303 }
298 304
299 void SingleThreadProxy::SetNeedsCommit() { 305 void SingleThreadProxy::SetNeedsCommit() {
300 DCHECK(Proxy::IsMainThread()); 306 DCHECK(Proxy::IsMainThread());
301 client_->ScheduleComposite(); 307 client_->ScheduleComposite();
302 if (commit_requested_) 308 if (commit_requested_)
303 return; 309 return;
304 commit_requested_ = true; 310 commit_requested_ = true;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 void SingleThreadProxy::DidActivateSyncTree() { 446 void SingleThreadProxy::DidActivateSyncTree() {
441 // This is required because NotifyReadyToActivate gets called immediately 447 // This is required because NotifyReadyToActivate gets called immediately
442 // after commit since single thread commits directly to the active tree. 448 // after commit since single thread commits directly to the active tree.
443 if (scheduler_on_impl_thread_) 449 if (scheduler_on_impl_thread_)
444 scheduler_on_impl_thread_->SetWaitForReadyToDraw(); 450 scheduler_on_impl_thread_->SetWaitForReadyToDraw();
445 451
446 // Synchronously call to CommitComplete. Resetting 452 // Synchronously call to CommitComplete. Resetting
447 // |commit_blocking_task_runner| would make sure all tasks posted during 453 // |commit_blocking_task_runner| would make sure all tasks posted during
448 // commit/activation before CommitComplete. 454 // commit/activation before CommitComplete.
449 CommitComplete(); 455 CommitComplete();
450
451 timing_history_.DidActivateSyncTree();
452 } 456 }
453 457
454 void SingleThreadProxy::DidPrepareTiles() { 458 void SingleThreadProxy::DidPrepareTiles() {
455 DCHECK(Proxy::IsImplThread()); 459 DCHECK(Proxy::IsImplThread());
456 if (scheduler_on_impl_thread_) 460 if (scheduler_on_impl_thread_)
457 scheduler_on_impl_thread_->DidPrepareTiles(); 461 scheduler_on_impl_thread_->DidPrepareTiles();
458 } 462 }
459 463
460 void SingleThreadProxy::DidCompletePageScaleAnimationOnImplThread() { 464 void SingleThreadProxy::DidCompletePageScaleAnimationOnImplThread() {
461 layer_tree_host_->DidCompletePageScaleAnimation(); 465 layer_tree_host_->DidCompletePageScaleAnimation();
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 "461509 SingleThreadProxy::DoComposite1")); 635 "461509 SingleThreadProxy::DoComposite1"));
632 636
633 // We guard PrepareToDraw() with CanDraw() because it always returns a valid 637 // We guard PrepareToDraw() with CanDraw() because it always returns a valid
634 // frame, so can only be used when such a frame is possible. Since 638 // frame, so can only be used when such a frame is possible. Since
635 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on 639 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on
636 // CanDraw() as well. 640 // CanDraw() as well.
637 if (!ShouldComposite()) { 641 if (!ShouldComposite()) {
638 return DRAW_ABORTED_CANT_DRAW; 642 return DRAW_ABORTED_CANT_DRAW;
639 } 643 }
640 644
641 timing_history_.DidStartDrawing();
642
643 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 645 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509
644 // is fixed. 646 // is fixed.
645 tracked_objects::ScopedTracker tracking_profile2( 647 tracked_objects::ScopedTracker tracking_profile2(
646 FROM_HERE_WITH_EXPLICIT_FUNCTION( 648 FROM_HERE_WITH_EXPLICIT_FUNCTION(
647 "461509 SingleThreadProxy::DoComposite2")); 649 "461509 SingleThreadProxy::DoComposite2"));
648 draw_result = layer_tree_host_impl_->PrepareToDraw(frame); 650 draw_result = layer_tree_host_impl_->PrepareToDraw(frame);
649 draw_frame = draw_result == DRAW_SUCCESS; 651 draw_frame = draw_result == DRAW_SUCCESS;
650 if (draw_frame) { 652 if (draw_frame) {
651 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 653 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509
652 // is fixed. 654 // is fixed.
(...skipping 15 matching lines...) Expand all
668 tracked_objects::ScopedTracker tracking_profile5( 670 tracked_objects::ScopedTracker tracking_profile5(
669 FROM_HERE_WITH_EXPLICIT_FUNCTION( 671 FROM_HERE_WITH_EXPLICIT_FUNCTION(
670 "461509 SingleThreadProxy::DoComposite5")); 672 "461509 SingleThreadProxy::DoComposite5"));
671 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); 673 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations);
672 674
673 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 675 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509
674 // is fixed. 676 // is fixed.
675 tracked_objects::ScopedTracker tracking_profile7( 677 tracked_objects::ScopedTracker tracking_profile7(
676 FROM_HERE_WITH_EXPLICIT_FUNCTION( 678 FROM_HERE_WITH_EXPLICIT_FUNCTION(
677 "461509 SingleThreadProxy::DoComposite7")); 679 "461509 SingleThreadProxy::DoComposite7"));
678 timing_history_.DidFinishDrawing();
679 } 680 }
680 681
681 if (draw_frame) { 682 if (draw_frame) {
682 DebugScopedSetImplThread impl(this); 683 DebugScopedSetImplThread impl(this);
683 684
684 // This CapturePostTasks should be destroyed before 685 // This CapturePostTasks should be destroyed before
685 // DidCommitAndDrawFrame() is called since that goes out to the 686 // DidCommitAndDrawFrame() is called since that goes out to the
686 // embedder, 687 // embedder,
687 // and we want the embedder to receive its callbacks before that. 688 // and we want the embedder to receive its callbacks before that.
688 // NOTE: This maintains consistent ordering with the ThreadProxy since 689 // NOTE: This maintains consistent ordering with the ThreadProxy since
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 layer_tree_host_->WillBeginMainFrame(); 816 layer_tree_host_->WillBeginMainFrame();
816 layer_tree_host_->BeginMainFrame(begin_frame_args); 817 layer_tree_host_->BeginMainFrame(begin_frame_args);
817 layer_tree_host_->AnimateLayers(begin_frame_args.frame_time); 818 layer_tree_host_->AnimateLayers(begin_frame_args.frame_time);
818 layer_tree_host_->Layout(); 819 layer_tree_host_->Layout();
819 820
820 // New commits requested inside UpdateLayers should be respected. 821 // New commits requested inside UpdateLayers should be respected.
821 commit_requested_ = false; 822 commit_requested_ = false;
822 823
823 layer_tree_host_->UpdateLayers(); 824 layer_tree_host_->UpdateLayers();
824 825
825 timing_history_.DidBeginMainFrame();
826
827 // TODO(enne): SingleThreadProxy does not support cancelling commits yet, 826 // TODO(enne): SingleThreadProxy does not support cancelling commits yet,
828 // search for CommitEarlyOutReason::FINISHED_NO_UPDATES inside 827 // search for CommitEarlyOutReason::FINISHED_NO_UPDATES inside
829 // thread_proxy.cc 828 // thread_proxy.cc
830 if (scheduler_on_impl_thread_) { 829 if (scheduler_on_impl_thread_) {
831 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted(); 830 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted();
832 scheduler_on_impl_thread_->NotifyReadyToCommit(); 831 scheduler_on_impl_thread_->NotifyReadyToCommit();
833 } 832 }
834 } 833 }
835 834
836 void SingleThreadProxy::BeginMainFrameAbortedOnImplThread( 835 void SingleThreadProxy::BeginMainFrameAbortedOnImplThread(
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 void SingleThreadProxy::ScheduledActionPrepareTiles() { 886 void SingleThreadProxy::ScheduledActionPrepareTiles() {
888 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionPrepareTiles"); 887 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionPrepareTiles");
889 DebugScopedSetImplThread impl(this); 888 DebugScopedSetImplThread impl(this);
890 layer_tree_host_impl_->PrepareTiles(); 889 layer_tree_host_impl_->PrepareTiles();
891 } 890 }
892 891
893 void SingleThreadProxy::ScheduledActionInvalidateOutputSurface() { 892 void SingleThreadProxy::ScheduledActionInvalidateOutputSurface() {
894 NOTREACHED(); 893 NOTREACHED();
895 } 894 }
896 895
897 base::TimeDelta SingleThreadProxy::DrawDurationEstimate() {
898 return timing_history_.DrawDurationEstimate();
899 }
900
901 base::TimeDelta SingleThreadProxy::BeginMainFrameToCommitDurationEstimate() {
902 return timing_history_.BeginMainFrameToCommitDurationEstimate();
903 }
904
905 base::TimeDelta SingleThreadProxy::CommitToActivateDurationEstimate() {
906 return timing_history_.CommitToActivateDurationEstimate();
907 }
908
909 void SingleThreadProxy::DidFinishImplFrame() { 896 void SingleThreadProxy::DidFinishImplFrame() {
910 layer_tree_host_impl_->DidFinishImplFrame(); 897 layer_tree_host_impl_->DidFinishImplFrame();
911 #if DCHECK_IS_ON() 898 #if DCHECK_IS_ON()
912 DCHECK(inside_impl_frame_) 899 DCHECK(inside_impl_frame_)
913 << "DidFinishImplFrame called while not inside an impl frame!"; 900 << "DidFinishImplFrame called while not inside an impl frame!";
914 inside_impl_frame_ = false; 901 inside_impl_frame_ = false;
915 #endif 902 #endif
916 } 903 }
917 904
918 void SingleThreadProxy::SendBeginFramesToChildren(const BeginFrameArgs& args) { 905 void SingleThreadProxy::SendBeginFramesToChildren(const BeginFrameArgs& args) {
919 layer_tree_host_->SendBeginFramesToChildren(args); 906 layer_tree_host_->SendBeginFramesToChildren(args);
920 } 907 }
921 908
922 } // namespace cc 909 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/single_thread_proxy.h ('k') | cc/trees/thread_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698