| 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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 } | 250 } |
| 251 } | 251 } |
| 252 | 252 |
| 253 void ThreadProxy::SetRendererCapabilitiesMainThreadCopy( | 253 void ThreadProxy::SetRendererCapabilitiesMainThreadCopy( |
| 254 const RendererCapabilities& capabilities) { | 254 const RendererCapabilities& capabilities) { |
| 255 main().renderer_capabilities_main_thread_copy = capabilities; | 255 main().renderer_capabilities_main_thread_copy = capabilities; |
| 256 } | 256 } |
| 257 | 257 |
| 258 void ThreadProxy::SendCommitRequestToImplThreadIfNeeded() { | 258 void ThreadProxy::SendCommitRequestToImplThreadIfNeeded() { |
| 259 DCHECK(IsMainThread()); | 259 DCHECK(IsMainThread()); |
| 260 VLOG(2) << "ThreadProxy::SendCommitRequestToImplThreadIfNeeded: " | |
| 261 << "already_sent = " << main().commit_request_sent_to_impl_thread; | |
| 262 if (main().commit_request_sent_to_impl_thread) | 260 if (main().commit_request_sent_to_impl_thread) |
| 263 return; | 261 return; |
| 264 main().commit_request_sent_to_impl_thread = true; | 262 main().commit_request_sent_to_impl_thread = true; |
| 265 Proxy::ImplThreadTaskRunner()->PostTask( | 263 Proxy::ImplThreadTaskRunner()->PostTask( |
| 266 FROM_HERE, | 264 FROM_HERE, |
| 267 base::Bind(&ThreadProxy::SetNeedsCommitOnImplThread, | 265 base::Bind(&ThreadProxy::SetNeedsCommitOnImplThread, |
| 268 impl_thread_weak_ptr_)); | 266 impl_thread_weak_ptr_)); |
| 269 } | 267 } |
| 270 | 268 |
| 271 const RendererCapabilities& ThreadProxy::GetRendererCapabilities() const { | 269 const RendererCapabilities& ThreadProxy::GetRendererCapabilities() const { |
| 272 DCHECK(IsMainThread()); | 270 DCHECK(IsMainThread()); |
| 273 DCHECK(!layer_tree_host()->output_surface_lost()); | 271 DCHECK(!layer_tree_host()->output_surface_lost()); |
| 274 return main().renderer_capabilities_main_thread_copy; | 272 return main().renderer_capabilities_main_thread_copy; |
| 275 } | 273 } |
| 276 | 274 |
| 277 void ThreadProxy::SetNeedsAnimate() { | 275 void ThreadProxy::SetNeedsAnimate() { |
| 278 DCHECK(IsMainThread()); | 276 DCHECK(IsMainThread()); |
| 279 VLOG(2) << "ThreadProxy::SetNeedsAnimate: already_requested = " | |
| 280 << main().animate_requested; | |
| 281 if (main().animate_requested) | 277 if (main().animate_requested) |
| 282 return; | 278 return; |
| 283 | 279 |
| 284 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsAnimate"); | 280 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsAnimate"); |
| 285 main().animate_requested = true; | 281 main().animate_requested = true; |
| 286 SendCommitRequestToImplThreadIfNeeded(); | 282 SendCommitRequestToImplThreadIfNeeded(); |
| 287 } | 283 } |
| 288 | 284 |
| 289 void ThreadProxy::SetNeedsUpdateLayers() { | 285 void ThreadProxy::SetNeedsUpdateLayers() { |
| 290 DCHECK(IsMainThread()); | 286 DCHECK(IsMainThread()); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 UpdateBackgroundAnimateTicking(); | 373 UpdateBackgroundAnimateTicking(); |
| 378 } | 374 } |
| 379 | 375 |
| 380 void ThreadProxy::NotifyReadyToActivate() { | 376 void ThreadProxy::NotifyReadyToActivate() { |
| 381 TRACE_EVENT0("cc", "ThreadProxy::NotifyReadyToActivate"); | 377 TRACE_EVENT0("cc", "ThreadProxy::NotifyReadyToActivate"); |
| 382 impl().scheduler->NotifyReadyToActivate(); | 378 impl().scheduler->NotifyReadyToActivate(); |
| 383 } | 379 } |
| 384 | 380 |
| 385 void ThreadProxy::SetNeedsCommitOnImplThread() { | 381 void ThreadProxy::SetNeedsCommitOnImplThread() { |
| 386 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsCommitOnImplThread"); | 382 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsCommitOnImplThread"); |
| 387 VLOG(2) << "ThreadProxy::SetNeedsCommitOnImplThread"; | |
| 388 DCHECK(IsImplThread()); | 383 DCHECK(IsImplThread()); |
| 389 impl().scheduler->SetNeedsCommit(); | 384 impl().scheduler->SetNeedsCommit(); |
| 390 } | 385 } |
| 391 | 386 |
| 392 void ThreadProxy::PostAnimationEventsToMainThreadOnImplThread( | 387 void ThreadProxy::PostAnimationEventsToMainThreadOnImplThread( |
| 393 scoped_ptr<AnimationEventsVector> events) { | 388 scoped_ptr<AnimationEventsVector> events) { |
| 394 TRACE_EVENT0("cc", | 389 TRACE_EVENT0("cc", |
| 395 "ThreadProxy::PostAnimationEventsToMainThreadOnImplThread"); | 390 "ThreadProxy::PostAnimationEventsToMainThreadOnImplThread"); |
| 396 DCHECK(IsImplThread()); | 391 DCHECK(IsImplThread()); |
| 397 Proxy::MainThreadTaskRunner()->PostTask( | 392 Proxy::MainThreadTaskRunner()->PostTask( |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 } | 671 } |
| 677 | 672 |
| 678 void ThreadProxy::FinishAllRenderingOnImplThread(CompletionEvent* completion) { | 673 void ThreadProxy::FinishAllRenderingOnImplThread(CompletionEvent* completion) { |
| 679 TRACE_EVENT0("cc", "ThreadProxy::FinishAllRenderingOnImplThread"); | 674 TRACE_EVENT0("cc", "ThreadProxy::FinishAllRenderingOnImplThread"); |
| 680 DCHECK(IsImplThread()); | 675 DCHECK(IsImplThread()); |
| 681 impl().layer_tree_host_impl->FinishAllRendering(); | 676 impl().layer_tree_host_impl->FinishAllRendering(); |
| 682 completion->Signal(); | 677 completion->Signal(); |
| 683 } | 678 } |
| 684 | 679 |
| 685 void ThreadProxy::ScheduledActionSendBeginMainFrame() { | 680 void ThreadProxy::ScheduledActionSendBeginMainFrame() { |
| 686 VLOG(2) << "ThreadProxy::ScheduledActionSendBeginMainFrame"; | |
| 687 unsigned int begin_frame_id = nextBeginFrameId++; | 681 unsigned int begin_frame_id = nextBeginFrameId++; |
| 688 benchmark_instrumentation::ScopedBeginFrameTask begin_frame_task( | 682 benchmark_instrumentation::ScopedBeginFrameTask begin_frame_task( |
| 689 benchmark_instrumentation::kSendBeginFrame, begin_frame_id); | 683 benchmark_instrumentation::kSendBeginFrame, begin_frame_id); |
| 690 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state( | 684 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state( |
| 691 new BeginMainFrameAndCommitState); | 685 new BeginMainFrameAndCommitState); |
| 692 begin_main_frame_state->begin_frame_id = begin_frame_id; | 686 begin_main_frame_state->begin_frame_id = begin_frame_id; |
| 693 begin_main_frame_state->begin_frame_args = | 687 begin_main_frame_state->begin_frame_args = |
| 694 impl().layer_tree_host_impl->CurrentBeginFrameArgs(); | 688 impl().layer_tree_host_impl->CurrentBeginFrameArgs(); |
| 695 begin_main_frame_state->scroll_info = | 689 begin_main_frame_state->scroll_info = |
| 696 impl().layer_tree_host_impl->ProcessScrollDeltas(); | 690 impl().layer_tree_host_impl->ProcessScrollDeltas(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 715 } | 709 } |
| 716 | 710 |
| 717 void ThreadProxy::BeginMainFrame( | 711 void ThreadProxy::BeginMainFrame( |
| 718 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) { | 712 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) { |
| 719 benchmark_instrumentation::ScopedBeginFrameTask begin_frame_task( | 713 benchmark_instrumentation::ScopedBeginFrameTask begin_frame_task( |
| 720 benchmark_instrumentation::kDoBeginFrame, | 714 benchmark_instrumentation::kDoBeginFrame, |
| 721 begin_main_frame_state->begin_frame_id); | 715 begin_main_frame_state->begin_frame_id); |
| 722 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("cc.BeginMainFrame"); | 716 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("cc.BeginMainFrame"); |
| 723 DCHECK(IsMainThread()); | 717 DCHECK(IsMainThread()); |
| 724 | 718 |
| 725 VLOG(2) << "ThreadProxy::BeginMainFrame - BEGIN"; | |
| 726 | |
| 727 if (main().defer_commits) { | 719 if (main().defer_commits) { |
| 728 main().pending_deferred_commit = begin_main_frame_state.Pass(); | 720 main().pending_deferred_commit = begin_main_frame_state.Pass(); |
| 729 layer_tree_host()->DidDeferCommit(); | 721 layer_tree_host()->DidDeferCommit(); |
| 730 TRACE_EVENT_INSTANT0( | 722 TRACE_EVENT_INSTANT0( |
| 731 "cc", "EarlyOut_DeferCommits", TRACE_EVENT_SCOPE_THREAD); | 723 "cc", "EarlyOut_DeferCommits", TRACE_EVENT_SCOPE_THREAD); |
| 732 VLOG(2) << "ThreadProxy::BeginMainFrame: EarlyOut_DeferCommits"; | |
| 733 return; | 724 return; |
| 734 } | 725 } |
| 735 | 726 |
| 736 // If the commit finishes, LayerTreeHost will transfer its swap promises to | 727 // If the commit finishes, LayerTreeHost will transfer its swap promises to |
| 737 // LayerTreeImpl. The destructor of ScopedSwapPromiseChecker aborts the | 728 // LayerTreeImpl. The destructor of ScopedSwapPromiseChecker aborts the |
| 738 // remaining swap promises. | 729 // remaining swap promises. |
| 739 ScopedAbortRemainingSwapPromises swap_promise_checker(layer_tree_host()); | 730 ScopedAbortRemainingSwapPromises swap_promise_checker(layer_tree_host()); |
| 740 | 731 |
| 741 main().commit_requested = false; | 732 main().commit_requested = false; |
| 742 main().commit_request_sent_to_impl_thread = false; | 733 main().commit_request_sent_to_impl_thread = false; |
| 743 main().animate_requested = false; | 734 main().animate_requested = false; |
| 744 | 735 |
| 745 if (!layer_tree_host()->visible()) { | 736 if (!layer_tree_host()->visible()) { |
| 746 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD); | 737 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD); |
| 747 VLOG(2) << "ThreadProxy::BeginMainFrame: EarlyOut_NotVisible"; | |
| 748 bool did_handle = false; | 738 bool did_handle = false; |
| 749 Proxy::ImplThreadTaskRunner()->PostTask( | 739 Proxy::ImplThreadTaskRunner()->PostTask( |
| 750 FROM_HERE, | 740 FROM_HERE, |
| 751 base::Bind(&ThreadProxy::BeginMainFrameAbortedOnImplThread, | 741 base::Bind(&ThreadProxy::BeginMainFrameAbortedOnImplThread, |
| 752 impl_thread_weak_ptr_, | 742 impl_thread_weak_ptr_, |
| 753 did_handle)); | 743 did_handle)); |
| 754 return; | 744 return; |
| 755 } | 745 } |
| 756 | 746 |
| 757 if (layer_tree_host()->output_surface_lost()) { | 747 if (layer_tree_host()->output_surface_lost()) { |
| 758 TRACE_EVENT_INSTANT0( | 748 TRACE_EVENT_INSTANT0( |
| 759 "cc", "EarlyOut_OutputSurfaceLost", TRACE_EVENT_SCOPE_THREAD); | 749 "cc", "EarlyOut_OutputSurfaceLost", TRACE_EVENT_SCOPE_THREAD); |
| 760 VLOG(2) << "ThreadProxy::BeginMainFrame: EarlyOut_OutputSurfaceLost"; | |
| 761 bool did_handle = false; | 750 bool did_handle = false; |
| 762 Proxy::ImplThreadTaskRunner()->PostTask( | 751 Proxy::ImplThreadTaskRunner()->PostTask( |
| 763 FROM_HERE, | 752 FROM_HERE, |
| 764 base::Bind(&ThreadProxy::BeginMainFrameAbortedOnImplThread, | 753 base::Bind(&ThreadProxy::BeginMainFrameAbortedOnImplThread, |
| 765 impl_thread_weak_ptr_, | 754 impl_thread_weak_ptr_, |
| 766 did_handle)); | 755 did_handle)); |
| 767 return; | 756 return; |
| 768 } | 757 } |
| 769 | 758 |
| 770 // Do not notify the impl thread of commit requests that occur during | 759 // Do not notify the impl thread of commit requests that occur during |
| 771 // the apply/animate/layout part of the BeginMainFrameAndCommit process since | 760 // the apply/animate/layout part of the BeginMainFrameAndCommit process since |
| 772 // those commit requests will get painted immediately. Once we have done | 761 // those commit requests will get painted immediately. Once we have done |
| 773 // the paint, main().commit_requested will be set to false to allow new commit | 762 // the paint, main().commit_requested will be set to false to allow new commit |
| 774 // requests to be scheduled. | 763 // requests to be scheduled. |
| 775 // On the other hand, the animate_requested flag should remain cleared | 764 // On the other hand, the animate_requested flag should remain cleared |
| 776 // here so that any animation requests generated by the apply or animate | 765 // here so that any animation requests generated by the apply or animate |
| 777 // callbacks will trigger another frame. | 766 // callbacks will trigger another frame. |
| 778 main().commit_requested = true; | 767 main().commit_requested = true; |
| 779 main().commit_request_sent_to_impl_thread = true; | 768 main().commit_request_sent_to_impl_thread = true; |
| 780 VLOG(2) << "ThreadProxy::BeginMainFrame: Commit requests silenced."; | |
| 781 | 769 |
| 782 layer_tree_host()->ApplyScrollAndScale( | 770 layer_tree_host()->ApplyScrollAndScale( |
| 783 begin_main_frame_state->scroll_info.get()); | 771 begin_main_frame_state->scroll_info.get()); |
| 784 | 772 |
| 785 layer_tree_host()->WillBeginMainFrame(); | 773 layer_tree_host()->WillBeginMainFrame(); |
| 786 | 774 |
| 787 layer_tree_host()->BeginMainFrame(begin_main_frame_state->begin_frame_args); | 775 layer_tree_host()->BeginMainFrame(begin_main_frame_state->begin_frame_args); |
| 788 layer_tree_host()->AnimateLayers( | 776 layer_tree_host()->AnimateLayers( |
| 789 begin_main_frame_state->begin_frame_args.frame_time); | 777 begin_main_frame_state->begin_frame_args.frame_time); |
| 790 blocked_main().last_monotonic_frame_begin_time = | 778 blocked_main().last_monotonic_frame_begin_time = |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 | 813 |
| 826 layer_tree_host()->WillCommit(); | 814 layer_tree_host()->WillCommit(); |
| 827 | 815 |
| 828 // Before calling animate, we set main().animate_requested to false. If it is | 816 // Before calling animate, we set main().animate_requested to false. If it is |
| 829 // true now, it means SetNeedAnimate was called again, but during a state when | 817 // true now, it means SetNeedAnimate was called again, but during a state when |
| 830 // main().commit_request_sent_to_impl_thread = true. We need to force that | 818 // main().commit_request_sent_to_impl_thread = true. We need to force that |
| 831 // call to happen again now so that the commit request is sent to the impl | 819 // call to happen again now so that the commit request is sent to the impl |
| 832 // thread. | 820 // thread. |
| 833 if (main().animate_requested) { | 821 if (main().animate_requested) { |
| 834 // Forces SetNeedsAnimate to consider posting a commit task. | 822 // Forces SetNeedsAnimate to consider posting a commit task. |
| 835 VLOG(2) << "ThreadProxy::BeginMainFrame: RAF requested."; | |
| 836 main().animate_requested = false; | 823 main().animate_requested = false; |
| 837 SetNeedsAnimate(); | 824 SetNeedsAnimate(); |
| 838 } else { | |
| 839 VLOG(2) << "ThreadProxy::BeginMainFrame: RAF NOT requested."; | |
| 840 } | 825 } |
| 841 | 826 |
| 842 if (!updated && can_cancel_this_commit) { | 827 if (!updated && can_cancel_this_commit) { |
| 843 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NoUpdates", TRACE_EVENT_SCOPE_THREAD); | 828 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NoUpdates", TRACE_EVENT_SCOPE_THREAD); |
| 844 VLOG(2) << "ThreadProxy::BeginMainFrame: EarlyOut_NoUpdates"; | |
| 845 bool did_handle = true; | 829 bool did_handle = true; |
| 846 Proxy::ImplThreadTaskRunner()->PostTask( | 830 Proxy::ImplThreadTaskRunner()->PostTask( |
| 847 FROM_HERE, | 831 FROM_HERE, |
| 848 base::Bind(&ThreadProxy::BeginMainFrameAbortedOnImplThread, | 832 base::Bind(&ThreadProxy::BeginMainFrameAbortedOnImplThread, |
| 849 impl_thread_weak_ptr_, | 833 impl_thread_weak_ptr_, |
| 850 did_handle)); | 834 did_handle)); |
| 851 | 835 |
| 852 // Although the commit is internally aborted, this is because it has been | 836 // Although the commit is internally aborted, this is because it has been |
| 853 // detected to be a no-op. From the perspective of an embedder, this commit | 837 // detected to be a no-op. From the perspective of an embedder, this commit |
| 854 // went through, and input should no longer be throttled, etc. | 838 // went through, and input should no longer be throttled, etc. |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1419 | 1403 |
| 1420 impl().timing_history.DidActivateSyncTree(); | 1404 impl().timing_history.DidActivateSyncTree(); |
| 1421 } | 1405 } |
| 1422 | 1406 |
| 1423 void ThreadProxy::DidManageTiles() { | 1407 void ThreadProxy::DidManageTiles() { |
| 1424 DCHECK(IsImplThread()); | 1408 DCHECK(IsImplThread()); |
| 1425 impl().scheduler->DidManageTiles(); | 1409 impl().scheduler->DidManageTiles(); |
| 1426 } | 1410 } |
| 1427 | 1411 |
| 1428 } // namespace cc | 1412 } // namespace cc |
| OLD | NEW |