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

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

Issue 1432463002: cc: Track BeginMainFrame more precisely in CompositorTimingHistory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed unit tests. New tests to be added. Created 5 years, 1 month 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/trees/thread_proxy.h" 5 #include "cc/trees/thread_proxy.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 616
617 void ThreadProxy::SendBeginMainFrameNotExpectedSoon() { 617 void ThreadProxy::SendBeginMainFrameNotExpectedSoon() {
618 impl().channel_impl->BeginMainFrameNotExpectedSoon(); 618 impl().channel_impl->BeginMainFrameNotExpectedSoon();
619 } 619 }
620 620
621 void ThreadProxy::BeginMainFrame( 621 void ThreadProxy::BeginMainFrame(
622 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) { 622 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) {
623 benchmark_instrumentation::ScopedBeginFrameTask begin_frame_task( 623 benchmark_instrumentation::ScopedBeginFrameTask begin_frame_task(
624 benchmark_instrumentation::kDoBeginFrame, 624 benchmark_instrumentation::kDoBeginFrame,
625 begin_main_frame_state->begin_frame_id); 625 begin_main_frame_state->begin_frame_id);
626
627 base::TimeTicks begin_main_frame_start_time = base::TimeTicks::Now();
628
626 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("cc.BeginMainFrame"); 629 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("cc.BeginMainFrame");
627 DCHECK(IsMainThread()); 630 DCHECK(IsMainThread());
628 DCHECK_EQ(NO_PIPELINE_STAGE, main().current_pipeline_stage); 631 DCHECK_EQ(NO_PIPELINE_STAGE, main().current_pipeline_stage);
629 632
630 if (main().defer_commits) { 633 if (main().defer_commits) {
631 TRACE_EVENT_INSTANT0("cc", "EarlyOut_DeferCommit", 634 TRACE_EVENT_INSTANT0("cc", "EarlyOut_DeferCommit",
632 TRACE_EVENT_SCOPE_THREAD); 635 TRACE_EVENT_SCOPE_THREAD);
633 main().channel_main->BeginMainFrameAbortedOnImpl( 636 main().channel_main->BeginMainFrameAbortedOnImpl(
634 CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT); 637 CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT,
638 begin_main_frame_start_time);
635 return; 639 return;
636 } 640 }
637 641
638 // If the commit finishes, LayerTreeHost will transfer its swap promises to 642 // If the commit finishes, LayerTreeHost will transfer its swap promises to
639 // LayerTreeImpl. The destructor of ScopedSwapPromiseChecker aborts the 643 // LayerTreeImpl. The destructor of ScopedSwapPromiseChecker aborts the
640 // remaining swap promises. 644 // remaining swap promises.
641 ScopedAbortRemainingSwapPromises swap_promise_checker(layer_tree_host()); 645 ScopedAbortRemainingSwapPromises swap_promise_checker(layer_tree_host());
642 646
643 main().final_pipeline_stage = main().max_requested_pipeline_stage; 647 main().final_pipeline_stage = main().max_requested_pipeline_stage;
644 main().max_requested_pipeline_stage = NO_PIPELINE_STAGE; 648 main().max_requested_pipeline_stage = NO_PIPELINE_STAGE;
645 649
646 if (!layer_tree_host()->visible()) { 650 if (!layer_tree_host()->visible()) {
647 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD); 651 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD);
648 main().channel_main->BeginMainFrameAbortedOnImpl( 652 main().channel_main->BeginMainFrameAbortedOnImpl(
649 CommitEarlyOutReason::ABORTED_NOT_VISIBLE); 653 CommitEarlyOutReason::ABORTED_NOT_VISIBLE, begin_main_frame_start_time);
650 return; 654 return;
651 } 655 }
652 656
653 if (layer_tree_host()->output_surface_lost()) { 657 if (layer_tree_host()->output_surface_lost()) {
654 TRACE_EVENT_INSTANT0( 658 TRACE_EVENT_INSTANT0(
655 "cc", "EarlyOut_OutputSurfaceLost", TRACE_EVENT_SCOPE_THREAD); 659 "cc", "EarlyOut_OutputSurfaceLost", TRACE_EVENT_SCOPE_THREAD);
656 main().channel_main->BeginMainFrameAbortedOnImpl( 660 main().channel_main->BeginMainFrameAbortedOnImpl(
657 CommitEarlyOutReason::ABORTED_OUTPUT_SURFACE_LOST); 661 CommitEarlyOutReason::ABORTED_OUTPUT_SURFACE_LOST,
662 begin_main_frame_start_time);
658 return; 663 return;
659 } 664 }
660 665
661 main().current_pipeline_stage = ANIMATE_PIPELINE_STAGE; 666 main().current_pipeline_stage = ANIMATE_PIPELINE_STAGE;
662 667
663 layer_tree_host()->ApplyScrollAndScale( 668 layer_tree_host()->ApplyScrollAndScale(
664 begin_main_frame_state->scroll_info.get()); 669 begin_main_frame_state->scroll_info.get());
665 670
666 layer_tree_host()->WillBeginMainFrame(); 671 layer_tree_host()->WillBeginMainFrame();
667 672
(...skipping 19 matching lines...) Expand all
687 bool updated = should_update_layers && layer_tree_host()->UpdateLayers(); 692 bool updated = should_update_layers && layer_tree_host()->UpdateLayers();
688 693
689 layer_tree_host()->WillCommit(); 694 layer_tree_host()->WillCommit();
690 devtools_instrumentation::ScopedCommitTrace commit_task( 695 devtools_instrumentation::ScopedCommitTrace commit_task(
691 layer_tree_host()->id()); 696 layer_tree_host()->id());
692 697
693 main().current_pipeline_stage = COMMIT_PIPELINE_STAGE; 698 main().current_pipeline_stage = COMMIT_PIPELINE_STAGE;
694 if (!updated && can_cancel_this_commit) { 699 if (!updated && can_cancel_this_commit) {
695 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NoUpdates", TRACE_EVENT_SCOPE_THREAD); 700 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NoUpdates", TRACE_EVENT_SCOPE_THREAD);
696 main().channel_main->BeginMainFrameAbortedOnImpl( 701 main().channel_main->BeginMainFrameAbortedOnImpl(
697 CommitEarlyOutReason::FINISHED_NO_UPDATES); 702 CommitEarlyOutReason::FINISHED_NO_UPDATES, begin_main_frame_start_time);
698 703
699 // Although the commit is internally aborted, this is because it has been 704 // Although the commit is internally aborted, this is because it has been
700 // detected to be a no-op. From the perspective of an embedder, this commit 705 // detected to be a no-op. From the perspective of an embedder, this commit
701 // went through, and input should no longer be throttled, etc. 706 // went through, and input should no longer be throttled, etc.
702 main().current_pipeline_stage = NO_PIPELINE_STAGE; 707 main().current_pipeline_stage = NO_PIPELINE_STAGE;
703 layer_tree_host()->CommitComplete(); 708 layer_tree_host()->CommitComplete();
704 layer_tree_host()->DidBeginMainFrame(); 709 layer_tree_host()->DidBeginMainFrame();
705 layer_tree_host()->BreakSwapPromises(SwapPromise::COMMIT_NO_UPDATE); 710 layer_tree_host()->BreakSwapPromises(SwapPromise::COMMIT_NO_UPDATE);
706 return; 711 return;
707 } 712 }
708 713
709 // Notify the impl thread that the main thread is ready to commit. This will 714 // Notify the impl thread that the main thread is ready to commit. This will
710 // begin the commit process, which is blocking from the main thread's 715 // begin the commit process, which is blocking from the main thread's
711 // point of view, but asynchronously performed on the impl thread, 716 // point of view, but asynchronously performed on the impl thread,
712 // coordinated by the Scheduler. 717 // coordinated by the Scheduler.
713 { 718 {
714 TRACE_EVENT0("cc", "ThreadProxy::BeginMainFrame::commit"); 719 TRACE_EVENT0("cc", "ThreadProxy::BeginMainFrame::commit");
715 720
716 DebugScopedSetMainThreadBlocked main_thread_blocked(this); 721 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
717 722
718 // This CapturePostTasks should be destroyed before CommitComplete() is 723 // This CapturePostTasks should be destroyed before CommitComplete() is
719 // called since that goes out to the embedder, and we want the embedder 724 // called since that goes out to the embedder, and we want the embedder
720 // to receive its callbacks before that. 725 // to receive its callbacks before that.
721 BlockingTaskRunner::CapturePostTasks blocked( 726 BlockingTaskRunner::CapturePostTasks blocked(
722 blocking_main_thread_task_runner()); 727 blocking_main_thread_task_runner());
723 728
724 CompletionEvent completion; 729 CompletionEvent completion;
725 main().channel_main->StartCommitOnImpl(&completion); 730 main().channel_main->StartCommitOnImpl(&completion,
731 begin_main_frame_start_time);
726 completion.Wait(); 732 completion.Wait();
727 } 733 }
728 734
729 main().current_pipeline_stage = NO_PIPELINE_STAGE; 735 main().current_pipeline_stage = NO_PIPELINE_STAGE;
730 layer_tree_host()->CommitComplete(); 736 layer_tree_host()->CommitComplete();
731 layer_tree_host()->DidBeginMainFrame(); 737 layer_tree_host()->DidBeginMainFrame();
732 } 738 }
733 739
734 void ThreadProxy::BeginMainFrameNotExpectedSoon() { 740 void ThreadProxy::BeginMainFrameNotExpectedSoon() {
735 TRACE_EVENT0("cc", "ThreadProxy::BeginMainFrameNotExpectedSoon"); 741 TRACE_EVENT0("cc", "ThreadProxy::BeginMainFrameNotExpectedSoon");
736 DCHECK(IsMainThread()); 742 DCHECK(IsMainThread());
737 layer_tree_host()->BeginMainFrameNotExpectedSoon(); 743 layer_tree_host()->BeginMainFrameNotExpectedSoon();
738 } 744 }
739 745
740 void ThreadProxy::StartCommitOnImpl(CompletionEvent* completion) { 746 void ThreadProxy::StartCommitOnImpl(CompletionEvent* completion,
747 base::TimeTicks main_thread_start_time) {
741 TRACE_EVENT0("cc", "ThreadProxy::StartCommitOnImplThread"); 748 TRACE_EVENT0("cc", "ThreadProxy::StartCommitOnImplThread");
742 DCHECK(!impl().commit_completion_event); 749 DCHECK(!impl().commit_completion_event);
743 DCHECK(IsImplThread() && IsMainThreadBlocked()); 750 DCHECK(IsImplThread() && IsMainThreadBlocked());
744 DCHECK(impl().scheduler); 751 DCHECK(impl().scheduler);
745 DCHECK(impl().scheduler->CommitPending()); 752 DCHECK(impl().scheduler->CommitPending());
746 753
747 if (!impl().layer_tree_host_impl) { 754 if (!impl().layer_tree_host_impl) {
748 TRACE_EVENT_INSTANT0( 755 TRACE_EVENT_INSTANT0(
749 "cc", "EarlyOut_NoLayerTree", TRACE_EVENT_SCOPE_THREAD); 756 "cc", "EarlyOut_NoLayerTree", TRACE_EVENT_SCOPE_THREAD);
750 completion->Signal(); 757 completion->Signal();
751 return; 758 return;
752 } 759 }
753 760
754 // Ideally, we should inform to impl thread when BeginMainFrame is started. 761 // Ideally, we should inform to impl thread when BeginMainFrame is started.
755 // But, we can avoid a PostTask in here. 762 // But, we can avoid a PostTask in here.
756 impl().scheduler->NotifyBeginMainFrameStarted(); 763 impl().scheduler->NotifyBeginMainFrameStarted(main_thread_start_time);
757 impl().commit_completion_event = completion; 764 impl().commit_completion_event = completion;
758 impl().scheduler->NotifyReadyToCommit(); 765 impl().scheduler->NotifyReadyToCommit();
759 } 766 }
760 767
761 void ThreadProxy::BeginMainFrameAbortedOnImpl(CommitEarlyOutReason reason) { 768 void ThreadProxy::BeginMainFrameAbortedOnImpl(
769 CommitEarlyOutReason reason,
770 base::TimeTicks main_thread_start_time) {
762 TRACE_EVENT1("cc", "ThreadProxy::BeginMainFrameAbortedOnImplThread", "reason", 771 TRACE_EVENT1("cc", "ThreadProxy::BeginMainFrameAbortedOnImplThread", "reason",
763 CommitEarlyOutReasonToString(reason)); 772 CommitEarlyOutReasonToString(reason));
764 DCHECK(IsImplThread()); 773 DCHECK(IsImplThread());
765 DCHECK(impl().scheduler); 774 DCHECK(impl().scheduler);
766 DCHECK(impl().scheduler->CommitPending()); 775 DCHECK(impl().scheduler->CommitPending());
767 DCHECK(!impl().layer_tree_host_impl->pending_tree()); 776 DCHECK(!impl().layer_tree_host_impl->pending_tree());
768 777
769 if (CommitEarlyOutHandledCommit(reason)) { 778 if (CommitEarlyOutHandledCommit(reason)) {
770 SetInputThrottledUntilCommitOnImpl(false); 779 SetInputThrottledUntilCommitOnImpl(false);
771 impl().last_processed_begin_main_frame_args = 780 impl().last_processed_begin_main_frame_args =
772 impl().last_begin_main_frame_args; 781 impl().last_begin_main_frame_args;
773 } 782 }
774 impl().layer_tree_host_impl->BeginMainFrameAborted(reason); 783 impl().layer_tree_host_impl->BeginMainFrameAborted(reason);
784 impl().scheduler->NotifyBeginMainFrameStarted(main_thread_start_time);
775 impl().scheduler->BeginMainFrameAborted(reason); 785 impl().scheduler->BeginMainFrameAborted(reason);
776 } 786 }
777 787
778 void ThreadProxy::ScheduledActionAnimate() { 788 void ThreadProxy::ScheduledActionAnimate() {
779 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionAnimate"); 789 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionAnimate");
780 DCHECK(IsImplThread()); 790 DCHECK(IsImplThread());
781 791
782 impl().layer_tree_host_impl->Animate(); 792 impl().layer_tree_host_impl->Animate();
783 } 793 }
784 794
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 1198
1189 base::WeakPtr<ProxyMain> ThreadProxy::GetMainWeakPtr() { 1199 base::WeakPtr<ProxyMain> ThreadProxy::GetMainWeakPtr() {
1190 return main_thread_weak_ptr_; 1200 return main_thread_weak_ptr_;
1191 } 1201 }
1192 1202
1193 base::WeakPtr<ProxyImpl> ThreadProxy::GetImplWeakPtr() { 1203 base::WeakPtr<ProxyImpl> ThreadProxy::GetImplWeakPtr() {
1194 return impl_thread_weak_ptr_; 1204 return impl_thread_weak_ptr_;
1195 } 1205 }
1196 1206
1197 } // namespace cc 1207 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698