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

Side by Side Diff: cc/trees/single_thread_proxy.cc

Issue 1099703004: cc: Make SingleThreadProxy::CompositeImmediately match scheduler path. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: [DONT REVIEW] - Upload with deps for try bot running. Created 5 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
« no previous file with comments | « cc/trees/single_thread_proxy.h ('k') | no next file » | 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"
(...skipping 27 matching lines...) Expand all
38 SingleThreadProxy::SingleThreadProxy( 38 SingleThreadProxy::SingleThreadProxy(
39 LayerTreeHost* layer_tree_host, 39 LayerTreeHost* layer_tree_host,
40 LayerTreeHostSingleThreadClient* client, 40 LayerTreeHostSingleThreadClient* client,
41 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, 41 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
42 scoped_ptr<BeginFrameSource> external_begin_frame_source) 42 scoped_ptr<BeginFrameSource> external_begin_frame_source)
43 : Proxy(main_task_runner, NULL), 43 : Proxy(main_task_runner, NULL),
44 layer_tree_host_(layer_tree_host), 44 layer_tree_host_(layer_tree_host),
45 client_(client), 45 client_(client),
46 timing_history_(layer_tree_host->rendering_stats_instrumentation()), 46 timing_history_(layer_tree_host->rendering_stats_instrumentation()),
47 next_frame_is_newly_committed_frame_(false), 47 next_frame_is_newly_committed_frame_(false),
48 inside_impl_frame_(false),
48 inside_draw_(false), 49 inside_draw_(false),
49 defer_commits_(false), 50 defer_commits_(false),
50 animate_requested_(false), 51 animate_requested_(false),
51 commit_requested_(false), 52 commit_requested_(false),
52 inside_synchronous_composite_(false), 53 inside_synchronous_composite_(false),
53 output_surface_creation_requested_(false), 54 output_surface_creation_requested_(false),
54 weak_factory_(this) { 55 weak_factory_(this) {
55 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); 56 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy");
56 DCHECK(Proxy::IsMainThread()); 57 DCHECK(Proxy::IsMainThread());
57 DCHECK(layer_tree_host); 58 DCHECK(layer_tree_host);
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 layer_tree_host_->DidCompleteSwapBuffers(); 580 layer_tree_host_->DidCompleteSwapBuffers();
580 } 581 }
581 582
582 void SingleThreadProxy::OnDrawForOutputSurface() { 583 void SingleThreadProxy::OnDrawForOutputSurface() {
583 NOTREACHED() << "Implemented by ThreadProxy for synchronous compositor."; 584 NOTREACHED() << "Implemented by ThreadProxy for synchronous compositor.";
584 } 585 }
585 586
586 void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { 587 void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) {
587 TRACE_EVENT0("cc,benchmark", "SingleThreadProxy::CompositeImmediately"); 588 TRACE_EVENT0("cc,benchmark", "SingleThreadProxy::CompositeImmediately");
588 DCHECK(Proxy::IsMainThread()); 589 DCHECK(Proxy::IsMainThread());
590 DCHECK(!inside_impl_frame_);
589 base::AutoReset<bool> inside_composite(&inside_synchronous_composite_, true); 591 base::AutoReset<bool> inside_composite(&inside_synchronous_composite_, true);
590 592
591 if (layer_tree_host_->output_surface_lost()) { 593 if (layer_tree_host_->output_surface_lost()) {
592 RequestNewOutputSurface(); 594 RequestNewOutputSurface();
593 // RequestNewOutputSurface could have synchronously created an output 595 // RequestNewOutputSurface could have synchronously created an output
594 // surface, so check again before returning. 596 // surface, so check again before returning.
595 if (layer_tree_host_->output_surface_lost()) 597 if (layer_tree_host_->output_surface_lost())
596 return; 598 return;
597 } 599 }
598 600
601 BeginFrameArgs begin_frame_args(BeginFrameArgs::Create(
602 BEGINFRAME_FROM_HERE, frame_begin_time, base::TimeTicks(),
603 BeginFrameArgs::DefaultInterval(), BeginFrameArgs::NORMAL));
604
605 // Start the impl frame.
599 { 606 {
600 BeginFrameArgs begin_frame_args(BeginFrameArgs::Create( 607 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this));
sunnyps 2015/05/01 00:46:38 Why do you need a const_cast here? 'this' is not c
mithro-old 2015/05/01 03:08:54 Done.
601 BEGINFRAME_FROM_HERE, frame_begin_time, base::TimeTicks(), 608 WillBeginImplFrame(begin_frame_args);
602 BeginFrameArgs::DefaultInterval(), BeginFrameArgs::NORMAL)); 609 }
610
611 // Run the "main thread" and get it to commit.
612 {
613 DCHECK(inside_impl_frame_);
sunnyps 2015/05/01 00:46:38 nit: move this DCHECK to immediately under the Wil
mithro-old 2015/05/01 03:08:54 This DCHCEK is checking that when you call DoBegin
603 DoBeginMainFrame(begin_frame_args); 614 DoBeginMainFrame(begin_frame_args);
604 DoCommit(); 615 DoCommit();
605 616
606 DCHECK_EQ(0u, layer_tree_host_->num_queued_swap_promises()) 617 DCHECK_EQ(0u, layer_tree_host_->num_queued_swap_promises())
607 << "Commit should always succeed and transfer promises."; 618 << "Commit should always succeed and transfer promises.";
608 } 619 }
609 620
621 // Finish the impl frame.
610 { 622 {
611 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this)); 623 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this));
612 if (layer_tree_host_impl_->settings().impl_side_painting) { 624 if (layer_tree_host_impl_->settings().impl_side_painting) {
613 layer_tree_host_impl_->ActivateSyncTree(); 625 layer_tree_host_impl_->ActivateSyncTree();
614 DCHECK(!layer_tree_host_impl_->active_tree() 626 DCHECK(!layer_tree_host_impl_->active_tree()
615 ->needs_update_draw_properties()); 627 ->needs_update_draw_properties());
616 layer_tree_host_impl_->PrepareTiles(); 628 layer_tree_host_impl_->PrepareTiles();
617 layer_tree_host_impl_->SynchronouslyInitializeAllTiles(); 629 layer_tree_host_impl_->SynchronouslyInitializeAllTiles();
618 } 630 }
619 631
620 DoAnimate(); 632 DoAnimate();
621 633
622 LayerTreeHostImpl::FrameData frame; 634 LayerTreeHostImpl::FrameData frame;
623 DoComposite(frame_begin_time, &frame); 635 DoComposite(frame_begin_time, &frame);
624 636
625 // DoComposite could abort, but because this is a synchronous composite 637 // DoComposite could abort, but because this is a synchronous composite
626 // another draw will never be scheduled, so break remaining promises. 638 // another draw will never be scheduled, so break remaining promises.
627 layer_tree_host_impl_->active_tree()->BreakSwapPromises( 639 layer_tree_host_impl_->active_tree()->BreakSwapPromises(
628 SwapPromise::SWAP_FAILS); 640 SwapPromise::SWAP_FAILS);
641
642 DidBeginImplFrameDeadline();
629 } 643 }
630 } 644 }
631 645
632 void SingleThreadProxy::ForceSerializeOnSwapBuffers() { 646 void SingleThreadProxy::ForceSerializeOnSwapBuffers() {
633 { 647 {
634 DebugScopedSetImplThread impl(this); 648 DebugScopedSetImplThread impl(this);
635 if (layer_tree_host_impl_->renderer()) { 649 if (layer_tree_host_impl_->renderer()) {
636 DCHECK(!layer_tree_host_->output_surface_lost()); 650 DCHECK(!layer_tree_host_->output_surface_lost());
637 layer_tree_host_impl_->renderer()->DoNoOp(); 651 layer_tree_host_impl_->renderer()->DoNoOp();
638 } 652 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 "461509 SingleThreadProxy::DoComposite4")); 723 "461509 SingleThreadProxy::DoComposite4"));
710 layer_tree_host_impl_->DidDrawAllLayers(*frame); 724 layer_tree_host_impl_->DidDrawAllLayers(*frame);
711 725
712 bool start_ready_animations = draw_frame; 726 bool start_ready_animations = draw_frame;
713 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 727 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509
714 // is fixed. 728 // is fixed.
715 tracked_objects::ScopedTracker tracking_profile5( 729 tracked_objects::ScopedTracker tracking_profile5(
716 FROM_HERE_WITH_EXPLICIT_FUNCTION( 730 FROM_HERE_WITH_EXPLICIT_FUNCTION(
717 "461509 SingleThreadProxy::DoComposite5")); 731 "461509 SingleThreadProxy::DoComposite5"));
718 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); 732 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations);
719 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509
720 // is fixed.
721 tracked_objects::ScopedTracker tracking_profile6(
sunnyps 2015/05/01 00:46:38 This is related to the other CL right? https://cod
mithro-old 2015/05/01 03:08:55 Yes, this patch is dependent on that CL. I uploade
722 FROM_HERE_WITH_EXPLICIT_FUNCTION(
723 "461509 SingleThreadProxy::DoComposite6"));
724 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame();
725 733
726 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 734 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509
727 // is fixed. 735 // is fixed.
728 tracked_objects::ScopedTracker tracking_profile7( 736 tracked_objects::ScopedTracker tracking_profile7(
729 FROM_HERE_WITH_EXPLICIT_FUNCTION( 737 FROM_HERE_WITH_EXPLICIT_FUNCTION(
730 "461509 SingleThreadProxy::DoComposite7")); 738 "461509 SingleThreadProxy::DoComposite7"));
731 timing_history_.DidFinishDrawing(); 739 timing_history_.DidFinishDrawing();
732 } 740 }
733 741
734 if (draw_frame) { 742 if (draw_frame) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 scheduler_on_impl_thread_->SetChildrenNeedBeginFrames( 792 scheduler_on_impl_thread_->SetChildrenNeedBeginFrames(
785 children_need_begin_frames); 793 children_need_begin_frames);
786 } 794 }
787 795
788 void SingleThreadProxy::SetAuthoritativeVSyncInterval( 796 void SingleThreadProxy::SetAuthoritativeVSyncInterval(
789 const base::TimeDelta& interval) { 797 const base::TimeDelta& interval) {
790 scheduler_on_impl_thread_->SetAuthoritativeVSyncInterval(interval); 798 scheduler_on_impl_thread_->SetAuthoritativeVSyncInterval(interval);
791 } 799 }
792 800
793 void SingleThreadProxy::WillBeginImplFrame(const BeginFrameArgs& args) { 801 void SingleThreadProxy::WillBeginImplFrame(const BeginFrameArgs& args) {
802 DCHECK(!inside_impl_frame_)
803 << "WillBeginImplFrame called while already inside an impl frame!";
804 inside_impl_frame_ = true;
794 layer_tree_host_impl_->WillBeginImplFrame(args); 805 layer_tree_host_impl_->WillBeginImplFrame(args);
795 } 806 }
796 807
797 void SingleThreadProxy::ScheduledActionSendBeginMainFrame() { 808 void SingleThreadProxy::ScheduledActionSendBeginMainFrame() {
798 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionSendBeginMainFrame"); 809 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionSendBeginMainFrame");
799 // Although this proxy is single-threaded, it's problematic to synchronously 810 // Although this proxy is single-threaded, it's problematic to synchronously
800 // have BeginMainFrame happen after ScheduledActionSendBeginMainFrame. This 811 // have BeginMainFrame happen after ScheduledActionSendBeginMainFrame. This
801 // could cause a commit to occur in between a series of SetNeedsCommit calls 812 // could cause a commit to occur in between a series of SetNeedsCommit calls
802 // (i.e. property modifications) causing some to fall on one frame and some to 813 // (i.e. property modifications) causing some to fall on one frame and some to
803 // fall on the next. Doing it asynchronously instead matches the semantics of 814 // fall on the next. Doing it asynchronously instead matches the semantics of
804 // ThreadProxy::SetNeedsCommit where SetNeedsCommit will not cause a 815 // ThreadProxy::SetNeedsCommit where SetNeedsCommit will not cause a
805 // synchronous commit. 816 // synchronous commit.
817 DCHECK(inside_impl_frame_)
sunnyps 2015/05/01 00:46:38 We're pretty sure this is true for SingleThreadPro
mithro-old 2015/05/01 03:08:54 We'd hope so, but as SRE says "hope is not a strat
818 << "BeginMainFrame should only be sent inside a BeginImplFrame";
819 const BeginFrameArgs& begin_frame_args =
820 layer_tree_host_impl_->CurrentBeginFrameArgs();
821
806 MainThreadTaskRunner()->PostTask( 822 MainThreadTaskRunner()->PostTask(
807 FROM_HERE, 823 FROM_HERE, base::Bind(&SingleThreadProxy::BeginMainFrame,
808 base::Bind(&SingleThreadProxy::BeginMainFrame, 824 weak_factory_.GetWeakPtr(), begin_frame_args));
809 weak_factory_.GetWeakPtr()));
810 } 825 }
811 826
812 void SingleThreadProxy::SendBeginMainFrameNotExpectedSoon() { 827 void SingleThreadProxy::SendBeginMainFrameNotExpectedSoon() {
813 layer_tree_host_->BeginMainFrameNotExpectedSoon(); 828 layer_tree_host_->BeginMainFrameNotExpectedSoon();
814 } 829 }
815 830
816 void SingleThreadProxy::BeginMainFrame() { 831 void SingleThreadProxy::BeginMainFrame(const BeginFrameArgs& begin_frame_args) {
817 commit_requested_ = false; 832 commit_requested_ = false;
818 animate_requested_ = false; 833 animate_requested_ = false;
819 834
820 if (defer_commits_) { 835 if (defer_commits_) {
821 TRACE_EVENT_INSTANT0("cc", "EarlyOut_DeferCommit", 836 TRACE_EVENT_INSTANT0("cc", "EarlyOut_DeferCommit",
822 TRACE_EVENT_SCOPE_THREAD); 837 TRACE_EVENT_SCOPE_THREAD);
823 BeginMainFrameAbortedOnImplThread( 838 BeginMainFrameAbortedOnImplThread(
824 CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT); 839 CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT);
825 return; 840 return;
826 } 841 }
(...skipping 15 matching lines...) Expand all
842 BeginMainFrameAbortedOnImplThread( 857 BeginMainFrameAbortedOnImplThread(
843 CommitEarlyOutReason::ABORTED_OUTPUT_SURFACE_LOST); 858 CommitEarlyOutReason::ABORTED_OUTPUT_SURFACE_LOST);
844 return; 859 return;
845 } 860 }
846 861
847 // Prevent new commits from being requested inside DoBeginMainFrame. 862 // Prevent new commits from being requested inside DoBeginMainFrame.
848 // Note: We do not want to prevent SetNeedsAnimate from requesting 863 // Note: We do not want to prevent SetNeedsAnimate from requesting
849 // a commit here. 864 // a commit here.
850 commit_requested_ = true; 865 commit_requested_ = true;
851 866
852 const BeginFrameArgs& begin_frame_args =
853 layer_tree_host_impl_->CurrentBeginFrameArgs();
854 DoBeginMainFrame(begin_frame_args); 867 DoBeginMainFrame(begin_frame_args);
855 } 868 }
856 869
857 void SingleThreadProxy::DoBeginMainFrame( 870 void SingleThreadProxy::DoBeginMainFrame(
858 const BeginFrameArgs& begin_frame_args) { 871 const BeginFrameArgs& begin_frame_args) {
859 layer_tree_host_->WillBeginMainFrame(); 872 layer_tree_host_->WillBeginMainFrame();
860 layer_tree_host_->BeginMainFrame(begin_frame_args); 873 layer_tree_host_->BeginMainFrame(begin_frame_args);
861 layer_tree_host_->AnimateLayers(begin_frame_args.frame_time); 874 layer_tree_host_->AnimateLayers(begin_frame_args.frame_time);
862 layer_tree_host_->Layout(); 875 layer_tree_host_->Layout();
863 876
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 base::TimeDelta SingleThreadProxy::BeginMainFrameToCommitDurationEstimate() { 975 base::TimeDelta SingleThreadProxy::BeginMainFrameToCommitDurationEstimate() {
963 return timing_history_.BeginMainFrameToCommitDurationEstimate(); 976 return timing_history_.BeginMainFrameToCommitDurationEstimate();
964 } 977 }
965 978
966 base::TimeDelta SingleThreadProxy::CommitToActivateDurationEstimate() { 979 base::TimeDelta SingleThreadProxy::CommitToActivateDurationEstimate() {
967 return timing_history_.CommitToActivateDurationEstimate(); 980 return timing_history_.CommitToActivateDurationEstimate();
968 } 981 }
969 982
970 void SingleThreadProxy::DidBeginImplFrameDeadline() { 983 void SingleThreadProxy::DidBeginImplFrameDeadline() {
971 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame(); 984 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame();
985 DCHECK(inside_impl_frame_)
986 << "DidBeginImplFrameDeadline called while not inside an impl frame!";
987 inside_impl_frame_ = false;
972 } 988 }
973 989
974 void SingleThreadProxy::SendBeginFramesToChildren(const BeginFrameArgs& args) { 990 void SingleThreadProxy::SendBeginFramesToChildren(const BeginFrameArgs& args) {
975 layer_tree_host_->SendBeginFramesToChildren(args); 991 layer_tree_host_->SendBeginFramesToChildren(args);
976 } 992 }
977 993
978 } // namespace cc 994 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/single_thread_proxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698