| OLD | NEW |
| 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 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 | 588 |
| 589 void ThreadProxy::SendBeginMainFrameNotExpectedSoon() { | 589 void ThreadProxy::SendBeginMainFrameNotExpectedSoon() { |
| 590 impl().channel_impl->BeginMainFrameNotExpectedSoon(); | 590 impl().channel_impl->BeginMainFrameNotExpectedSoon(); |
| 591 } | 591 } |
| 592 | 592 |
| 593 void ThreadProxy::BeginMainFrame( | 593 void ThreadProxy::BeginMainFrame( |
| 594 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) { | 594 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) { |
| 595 benchmark_instrumentation::ScopedBeginFrameTask begin_frame_task( | 595 benchmark_instrumentation::ScopedBeginFrameTask begin_frame_task( |
| 596 benchmark_instrumentation::kDoBeginFrame, | 596 benchmark_instrumentation::kDoBeginFrame, |
| 597 begin_main_frame_state->begin_frame_id); | 597 begin_main_frame_state->begin_frame_id); |
| 598 |
| 599 base::TimeTicks begin_main_frame_start_time = base::TimeTicks::Now(); |
| 600 |
| 598 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("cc.BeginMainFrame"); | 601 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("cc.BeginMainFrame"); |
| 599 DCHECK(IsMainThread()); | 602 DCHECK(IsMainThread()); |
| 600 DCHECK_EQ(NO_PIPELINE_STAGE, main().current_pipeline_stage); | 603 DCHECK_EQ(NO_PIPELINE_STAGE, main().current_pipeline_stage); |
| 601 | 604 |
| 602 if (main().defer_commits) { | 605 if (main().defer_commits) { |
| 603 TRACE_EVENT_INSTANT0("cc", "EarlyOut_DeferCommit", | 606 TRACE_EVENT_INSTANT0("cc", "EarlyOut_DeferCommit", |
| 604 TRACE_EVENT_SCOPE_THREAD); | 607 TRACE_EVENT_SCOPE_THREAD); |
| 605 main().channel_main->BeginMainFrameAbortedOnImpl( | 608 main().channel_main->BeginMainFrameAbortedOnImpl( |
| 606 CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT); | 609 CommitEarlyOutReason::ABORTED_DEFERRED_COMMIT, |
| 610 begin_main_frame_start_time); |
| 607 return; | 611 return; |
| 608 } | 612 } |
| 609 | 613 |
| 610 // If the commit finishes, LayerTreeHost will transfer its swap promises to | 614 // If the commit finishes, LayerTreeHost will transfer its swap promises to |
| 611 // LayerTreeImpl. The destructor of ScopedSwapPromiseChecker aborts the | 615 // LayerTreeImpl. The destructor of ScopedSwapPromiseChecker aborts the |
| 612 // remaining swap promises. | 616 // remaining swap promises. |
| 613 ScopedAbortRemainingSwapPromises swap_promise_checker(main().layer_tree_host); | 617 ScopedAbortRemainingSwapPromises swap_promise_checker(main().layer_tree_host); |
| 614 | 618 |
| 615 main().final_pipeline_stage = main().max_requested_pipeline_stage; | 619 main().final_pipeline_stage = main().max_requested_pipeline_stage; |
| 616 main().max_requested_pipeline_stage = NO_PIPELINE_STAGE; | 620 main().max_requested_pipeline_stage = NO_PIPELINE_STAGE; |
| 617 | 621 |
| 618 if (!main().layer_tree_host->visible()) { | 622 if (!main().layer_tree_host->visible()) { |
| 619 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD); | 623 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD); |
| 620 main().channel_main->BeginMainFrameAbortedOnImpl( | 624 main().channel_main->BeginMainFrameAbortedOnImpl( |
| 621 CommitEarlyOutReason::ABORTED_NOT_VISIBLE); | 625 CommitEarlyOutReason::ABORTED_NOT_VISIBLE, begin_main_frame_start_time); |
| 622 return; | 626 return; |
| 623 } | 627 } |
| 624 | 628 |
| 625 if (main().layer_tree_host->output_surface_lost()) { | 629 if (main().layer_tree_host->output_surface_lost()) { |
| 626 TRACE_EVENT_INSTANT0( | 630 TRACE_EVENT_INSTANT0( |
| 627 "cc", "EarlyOut_OutputSurfaceLost", TRACE_EVENT_SCOPE_THREAD); | 631 "cc", "EarlyOut_OutputSurfaceLost", TRACE_EVENT_SCOPE_THREAD); |
| 628 main().channel_main->BeginMainFrameAbortedOnImpl( | 632 main().channel_main->BeginMainFrameAbortedOnImpl( |
| 629 CommitEarlyOutReason::ABORTED_OUTPUT_SURFACE_LOST); | 633 CommitEarlyOutReason::ABORTED_OUTPUT_SURFACE_LOST, |
| 634 begin_main_frame_start_time); |
| 630 return; | 635 return; |
| 631 } | 636 } |
| 632 | 637 |
| 633 main().current_pipeline_stage = ANIMATE_PIPELINE_STAGE; | 638 main().current_pipeline_stage = ANIMATE_PIPELINE_STAGE; |
| 634 | 639 |
| 635 main().layer_tree_host->ApplyScrollAndScale( | 640 main().layer_tree_host->ApplyScrollAndScale( |
| 636 begin_main_frame_state->scroll_info.get()); | 641 begin_main_frame_state->scroll_info.get()); |
| 637 | 642 |
| 638 main().layer_tree_host->WillBeginMainFrame(); | 643 main().layer_tree_host->WillBeginMainFrame(); |
| 639 | 644 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 660 bool updated = should_update_layers && main().layer_tree_host->UpdateLayers(); | 665 bool updated = should_update_layers && main().layer_tree_host->UpdateLayers(); |
| 661 | 666 |
| 662 main().layer_tree_host->WillCommit(); | 667 main().layer_tree_host->WillCommit(); |
| 663 devtools_instrumentation::ScopedCommitTrace commit_task( | 668 devtools_instrumentation::ScopedCommitTrace commit_task( |
| 664 main().layer_tree_host->id()); | 669 main().layer_tree_host->id()); |
| 665 | 670 |
| 666 main().current_pipeline_stage = COMMIT_PIPELINE_STAGE; | 671 main().current_pipeline_stage = COMMIT_PIPELINE_STAGE; |
| 667 if (!updated && can_cancel_this_commit) { | 672 if (!updated && can_cancel_this_commit) { |
| 668 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NoUpdates", TRACE_EVENT_SCOPE_THREAD); | 673 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NoUpdates", TRACE_EVENT_SCOPE_THREAD); |
| 669 main().channel_main->BeginMainFrameAbortedOnImpl( | 674 main().channel_main->BeginMainFrameAbortedOnImpl( |
| 670 CommitEarlyOutReason::FINISHED_NO_UPDATES); | 675 CommitEarlyOutReason::FINISHED_NO_UPDATES, begin_main_frame_start_time); |
| 671 | 676 |
| 672 // Although the commit is internally aborted, this is because it has been | 677 // Although the commit is internally aborted, this is because it has been |
| 673 // detected to be a no-op. From the perspective of an embedder, this commit | 678 // detected to be a no-op. From the perspective of an embedder, this commit |
| 674 // went through, and input should no longer be throttled, etc. | 679 // went through, and input should no longer be throttled, etc. |
| 675 main().current_pipeline_stage = NO_PIPELINE_STAGE; | 680 main().current_pipeline_stage = NO_PIPELINE_STAGE; |
| 676 main().layer_tree_host->CommitComplete(); | 681 main().layer_tree_host->CommitComplete(); |
| 677 main().layer_tree_host->DidBeginMainFrame(); | 682 main().layer_tree_host->DidBeginMainFrame(); |
| 678 main().layer_tree_host->BreakSwapPromises(SwapPromise::COMMIT_NO_UPDATE); | 683 main().layer_tree_host->BreakSwapPromises(SwapPromise::COMMIT_NO_UPDATE); |
| 679 return; | 684 return; |
| 680 } | 685 } |
| 681 | 686 |
| 682 // Notify the impl thread that the main thread is ready to commit. This will | 687 // Notify the impl thread that the main thread is ready to commit. This will |
| 683 // begin the commit process, which is blocking from the main thread's | 688 // begin the commit process, which is blocking from the main thread's |
| 684 // point of view, but asynchronously performed on the impl thread, | 689 // point of view, but asynchronously performed on the impl thread, |
| 685 // coordinated by the Scheduler. | 690 // coordinated by the Scheduler. |
| 686 { | 691 { |
| 687 TRACE_EVENT0("cc", "ThreadProxy::BeginMainFrame::commit"); | 692 TRACE_EVENT0("cc", "ThreadProxy::BeginMainFrame::commit"); |
| 688 | 693 |
| 689 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 694 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 690 | 695 |
| 691 // This CapturePostTasks should be destroyed before CommitComplete() is | 696 // This CapturePostTasks should be destroyed before CommitComplete() is |
| 692 // called since that goes out to the embedder, and we want the embedder | 697 // called since that goes out to the embedder, and we want the embedder |
| 693 // to receive its callbacks before that. | 698 // to receive its callbacks before that. |
| 694 BlockingTaskRunner::CapturePostTasks blocked( | 699 BlockingTaskRunner::CapturePostTasks blocked( |
| 695 blocking_main_thread_task_runner()); | 700 blocking_main_thread_task_runner()); |
| 696 | 701 |
| 697 CompletionEvent completion; | 702 CompletionEvent completion; |
| 698 main().channel_main->StartCommitOnImpl(&completion, main().layer_tree_host, | 703 main().channel_main->StartCommitOnImpl(&completion, main().layer_tree_host, |
| 704 begin_main_frame_start_time, |
| 699 main().commit_waits_for_activation); | 705 main().commit_waits_for_activation); |
| 700 completion.Wait(); | 706 completion.Wait(); |
| 701 main().commit_waits_for_activation = false; | 707 main().commit_waits_for_activation = false; |
| 702 } | 708 } |
| 703 | 709 |
| 704 main().current_pipeline_stage = NO_PIPELINE_STAGE; | 710 main().current_pipeline_stage = NO_PIPELINE_STAGE; |
| 705 main().layer_tree_host->CommitComplete(); | 711 main().layer_tree_host->CommitComplete(); |
| 706 main().layer_tree_host->DidBeginMainFrame(); | 712 main().layer_tree_host->DidBeginMainFrame(); |
| 707 } | 713 } |
| 708 | 714 |
| 709 void ThreadProxy::BeginMainFrameNotExpectedSoon() { | 715 void ThreadProxy::BeginMainFrameNotExpectedSoon() { |
| 710 TRACE_EVENT0("cc", "ThreadProxy::BeginMainFrameNotExpectedSoon"); | 716 TRACE_EVENT0("cc", "ThreadProxy::BeginMainFrameNotExpectedSoon"); |
| 711 DCHECK(IsMainThread()); | 717 DCHECK(IsMainThread()); |
| 712 main().layer_tree_host->BeginMainFrameNotExpectedSoon(); | 718 main().layer_tree_host->BeginMainFrameNotExpectedSoon(); |
| 713 } | 719 } |
| 714 | 720 |
| 715 void ThreadProxy::StartCommitOnImpl(CompletionEvent* completion, | 721 void ThreadProxy::StartCommitOnImpl(CompletionEvent* completion, |
| 716 LayerTreeHost* layer_tree_host, | 722 LayerTreeHost* layer_tree_host, |
| 723 base::TimeTicks main_thread_start_time, |
| 717 bool hold_commit_for_activation) { | 724 bool hold_commit_for_activation) { |
| 718 TRACE_EVENT0("cc", "ThreadProxy::StartCommitOnImplThread"); | 725 TRACE_EVENT0("cc", "ThreadProxy::StartCommitOnImplThread"); |
| 719 DCHECK(!impl().commit_completion_event); | 726 DCHECK(!impl().commit_completion_event); |
| 720 DCHECK(IsImplThread() && IsMainThreadBlocked()); | 727 DCHECK(IsImplThread() && IsMainThreadBlocked()); |
| 721 DCHECK(impl().scheduler); | 728 DCHECK(impl().scheduler); |
| 722 DCHECK(impl().scheduler->CommitPending()); | 729 DCHECK(impl().scheduler->CommitPending()); |
| 723 | 730 |
| 724 if (hold_commit_for_activation) { | 731 if (hold_commit_for_activation) { |
| 725 // This commit may be aborted. Store the value for | 732 // This commit may be aborted. Store the value for |
| 726 // hold_commit_for_activation so that whenever the next commit is started, | 733 // hold_commit_for_activation so that whenever the next commit is started, |
| 727 // the main thread will be unblocked only after pending tree activation. | 734 // the main thread will be unblocked only after pending tree activation. |
| 728 impl().next_commit_waits_for_activation = hold_commit_for_activation; | 735 impl().next_commit_waits_for_activation = hold_commit_for_activation; |
| 729 } | 736 } |
| 730 | 737 |
| 731 if (!impl().layer_tree_host_impl) { | 738 if (!impl().layer_tree_host_impl) { |
| 732 TRACE_EVENT_INSTANT0( | 739 TRACE_EVENT_INSTANT0( |
| 733 "cc", "EarlyOut_NoLayerTree", TRACE_EVENT_SCOPE_THREAD); | 740 "cc", "EarlyOut_NoLayerTree", TRACE_EVENT_SCOPE_THREAD); |
| 734 completion->Signal(); | 741 completion->Signal(); |
| 735 return; | 742 return; |
| 736 } | 743 } |
| 737 | 744 |
| 738 // Ideally, we should inform to impl thread when BeginMainFrame is started. | 745 // Ideally, we should inform to impl thread when BeginMainFrame is started. |
| 739 // But, we can avoid a PostTask in here. | 746 // But, we can avoid a PostTask in here. |
| 740 impl().scheduler->NotifyBeginMainFrameStarted(); | 747 impl().scheduler->NotifyBeginMainFrameStarted(main_thread_start_time); |
| 741 impl().commit_completion_event = completion; | 748 impl().commit_completion_event = completion; |
| 742 DCHECK(!blocked_main_commit().layer_tree_host); | 749 DCHECK(!blocked_main_commit().layer_tree_host); |
| 743 blocked_main_commit().layer_tree_host = layer_tree_host; | 750 blocked_main_commit().layer_tree_host = layer_tree_host; |
| 744 impl().scheduler->NotifyReadyToCommit(); | 751 impl().scheduler->NotifyReadyToCommit(); |
| 745 } | 752 } |
| 746 | 753 |
| 747 void ThreadProxy::BeginMainFrameAbortedOnImpl(CommitEarlyOutReason reason) { | 754 void ThreadProxy::BeginMainFrameAbortedOnImpl( |
| 755 CommitEarlyOutReason reason, |
| 756 base::TimeTicks main_thread_start_time) { |
| 748 TRACE_EVENT1("cc", "ThreadProxy::BeginMainFrameAbortedOnImplThread", "reason", | 757 TRACE_EVENT1("cc", "ThreadProxy::BeginMainFrameAbortedOnImplThread", "reason", |
| 749 CommitEarlyOutReasonToString(reason)); | 758 CommitEarlyOutReasonToString(reason)); |
| 750 DCHECK(IsImplThread()); | 759 DCHECK(IsImplThread()); |
| 751 DCHECK(impl().scheduler); | 760 DCHECK(impl().scheduler); |
| 752 DCHECK(impl().scheduler->CommitPending()); | 761 DCHECK(impl().scheduler->CommitPending()); |
| 753 DCHECK(!impl().layer_tree_host_impl->pending_tree()); | 762 DCHECK(!impl().layer_tree_host_impl->pending_tree()); |
| 754 | 763 |
| 755 if (CommitEarlyOutHandledCommit(reason)) { | 764 if (CommitEarlyOutHandledCommit(reason)) { |
| 756 SetInputThrottledUntilCommitOnImpl(false); | 765 SetInputThrottledUntilCommitOnImpl(false); |
| 757 impl().last_processed_begin_main_frame_args = | 766 impl().last_processed_begin_main_frame_args = |
| 758 impl().last_begin_main_frame_args; | 767 impl().last_begin_main_frame_args; |
| 759 } | 768 } |
| 760 impl().layer_tree_host_impl->BeginMainFrameAborted(reason); | 769 impl().layer_tree_host_impl->BeginMainFrameAborted(reason); |
| 770 impl().scheduler->NotifyBeginMainFrameStarted(main_thread_start_time); |
| 761 impl().scheduler->BeginMainFrameAborted(reason); | 771 impl().scheduler->BeginMainFrameAborted(reason); |
| 762 } | 772 } |
| 763 | 773 |
| 764 void ThreadProxy::ScheduledActionAnimate() { | 774 void ThreadProxy::ScheduledActionAnimate() { |
| 765 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionAnimate"); | 775 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionAnimate"); |
| 766 DCHECK(IsImplThread()); | 776 DCHECK(IsImplThread()); |
| 767 | 777 |
| 768 impl().layer_tree_host_impl->Animate(); | 778 impl().layer_tree_host_impl->Animate(); |
| 769 } | 779 } |
| 770 | 780 |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1177 | 1187 |
| 1178 base::WeakPtr<ProxyMain> ThreadProxy::GetMainWeakPtr() { | 1188 base::WeakPtr<ProxyMain> ThreadProxy::GetMainWeakPtr() { |
| 1179 return main_thread_weak_ptr_; | 1189 return main_thread_weak_ptr_; |
| 1180 } | 1190 } |
| 1181 | 1191 |
| 1182 base::WeakPtr<ProxyImpl> ThreadProxy::GetImplWeakPtr() { | 1192 base::WeakPtr<ProxyImpl> ThreadProxy::GetImplWeakPtr() { |
| 1183 return impl_thread_weak_ptr_; | 1193 return impl_thread_weak_ptr_; |
| 1184 } | 1194 } |
| 1185 | 1195 |
| 1186 } // namespace cc | 1196 } // namespace cc |
| OLD | NEW |