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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 LayerTreeHost* layer_tree_host, | 74 LayerTreeHost* layer_tree_host, |
75 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { | 75 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { |
76 return make_scoped_ptr( | 76 return make_scoped_ptr( |
77 new ThreadProxy(layer_tree_host, impl_task_runner)).PassAs<Proxy>(); | 77 new ThreadProxy(layer_tree_host, impl_task_runner)).PassAs<Proxy>(); |
78 } | 78 } |
79 | 79 |
80 ThreadProxy::ThreadProxy( | 80 ThreadProxy::ThreadProxy( |
81 LayerTreeHost* layer_tree_host, | 81 LayerTreeHost* layer_tree_host, |
82 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) | 82 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) |
83 : Proxy(impl_task_runner), | 83 : Proxy(impl_task_runner), |
84 update_requested_(false), | 84 animate_requested_(false), |
85 commit_requested_(false), | 85 commit_requested_(false), |
86 commit_request_sent_to_impl_thread_(false), | 86 commit_request_sent_to_impl_thread_(false), |
87 created_offscreen_context_provider_(false), | 87 created_offscreen_context_provider_(false), |
88 layer_tree_host_unsafe_(layer_tree_host), | 88 layer_tree_host_unsafe_(layer_tree_host), |
89 contents_texture_manager_unsafe_(NULL), | 89 contents_texture_manager_unsafe_(NULL), |
90 started_(false), | 90 started_(false), |
91 textures_acquired_(true), | 91 textures_acquired_(true), |
92 in_composite_and_readback_(false), | 92 in_composite_and_readback_(false), |
93 manage_tiles_pending_(false), | 93 manage_tiles_pending_(false), |
94 commit_waits_for_activation_(false), | 94 commit_waits_for_activation_(false), |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 base::Bind(&ThreadProxy::SetNeedsCommitOnImplThread, | 343 base::Bind(&ThreadProxy::SetNeedsCommitOnImplThread, |
344 impl_thread_weak_ptr_)); | 344 impl_thread_weak_ptr_)); |
345 } | 345 } |
346 | 346 |
347 const RendererCapabilities& ThreadProxy::GetRendererCapabilities() const { | 347 const RendererCapabilities& ThreadProxy::GetRendererCapabilities() const { |
348 DCHECK(IsMainThread()); | 348 DCHECK(IsMainThread()); |
349 DCHECK(!layer_tree_host()->output_surface_lost()); | 349 DCHECK(!layer_tree_host()->output_surface_lost()); |
350 return renderer_capabilities_main_thread_copy_; | 350 return renderer_capabilities_main_thread_copy_; |
351 } | 351 } |
352 | 352 |
| 353 void ThreadProxy::SetNeedsAnimate() { |
| 354 DCHECK(IsMainThread()); |
| 355 if (animate_requested_) |
| 356 return; |
| 357 |
| 358 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsAnimate"); |
| 359 animate_requested_ = true; |
| 360 can_cancel_commit_ = false; |
| 361 SendCommitRequestToImplThreadIfNeeded(); |
| 362 } |
| 363 |
353 void ThreadProxy::SetNeedsUpdateLayers() { | 364 void ThreadProxy::SetNeedsUpdateLayers() { |
354 DCHECK(IsMainThread()); | 365 DCHECK(IsMainThread()); |
355 | 366 |
356 if (update_requested_) | 367 if (commit_request_sent_to_impl_thread_) |
357 return; | 368 return; |
358 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsUpdateLayers"); | 369 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsUpdateLayers"); |
359 | 370 |
360 update_requested_ = true; | |
361 SendCommitRequestToImplThreadIfNeeded(); | 371 SendCommitRequestToImplThreadIfNeeded(); |
362 } | 372 } |
363 | 373 |
364 void ThreadProxy::SetNeedsCommit() { | 374 void ThreadProxy::SetNeedsCommit() { |
365 DCHECK(IsMainThread()); | 375 DCHECK(IsMainThread()); |
366 // Unconditionally set here to handle SetNeedsCommit calls during a commit. | 376 // Unconditionally set here to handle SetNeedsCommit calls during a commit. |
367 can_cancel_commit_ = false; | 377 can_cancel_commit_ = false; |
368 | 378 |
369 if (commit_requested_) | 379 if (commit_requested_) |
370 return; | 380 return; |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 SwapPromiseChecker swap_promise_checker(layer_tree_host()); | 778 SwapPromiseChecker swap_promise_checker(layer_tree_host()); |
769 | 779 |
770 // Do not notify the impl thread of commit requests that occur during | 780 // Do not notify the impl thread of commit requests that occur during |
771 // the apply/animate/layout part of the BeginMainFrameAndCommit process since | 781 // the apply/animate/layout part of the BeginMainFrameAndCommit process since |
772 // those commit requests will get painted immediately. Once we have done | 782 // those commit requests will get painted immediately. Once we have done |
773 // the paint, commit_requested_ will be set to false to allow new commit | 783 // the paint, commit_requested_ will be set to false to allow new commit |
774 // requests to be scheduled. | 784 // requests to be scheduled. |
775 commit_requested_ = true; | 785 commit_requested_ = true; |
776 commit_request_sent_to_impl_thread_ = true; | 786 commit_request_sent_to_impl_thread_ = true; |
777 | 787 |
778 // On the other hand, the update_requested_ flag needs to be cleared | 788 // On the other hand, the AnimationRequested flag needs to be cleared |
779 // here so that any update requests generated by the apply or animate | 789 // here so that any animation requests generated by the apply or animate |
780 // callbacks will trigger another frame. | 790 // callbacks will trigger another frame. |
781 update_requested_ = false; | 791 animate_requested_ = false; |
782 | 792 |
783 if (!in_composite_and_readback_ && !layer_tree_host()->visible()) { | 793 if (!in_composite_and_readback_ && !layer_tree_host()->visible()) { |
784 commit_requested_ = false; | 794 commit_requested_ = false; |
785 commit_request_sent_to_impl_thread_ = false; | 795 commit_request_sent_to_impl_thread_ = false; |
786 | 796 |
787 TRACE_EVENT0("cc", "EarlyOut_NotVisible"); | 797 TRACE_EVENT0("cc", "EarlyOut_NotVisible"); |
788 bool did_handle = false; | 798 bool did_handle = false; |
789 Proxy::ImplThreadTaskRunner()->PostTask( | 799 Proxy::ImplThreadTaskRunner()->PostTask( |
790 FROM_HERE, | 800 FROM_HERE, |
791 base::Bind(&ThreadProxy::BeginMainFrameAbortedOnImplThread, | 801 base::Bind(&ThreadProxy::BeginMainFrameAbortedOnImplThread, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 TRACE_EVENT_SYNTHETIC_DELAY_END("cc.BeginMainFrame"); | 844 TRACE_EVENT_SYNTHETIC_DELAY_END("cc.BeginMainFrame"); |
835 | 845 |
836 // Clear the commit flag after updating animations and layout here --- objects | 846 // Clear the commit flag after updating animations and layout here --- objects |
837 // that only layout when painted will trigger another SetNeedsCommit inside | 847 // that only layout when painted will trigger another SetNeedsCommit inside |
838 // UpdateLayers. | 848 // UpdateLayers. |
839 commit_requested_ = false; | 849 commit_requested_ = false; |
840 commit_request_sent_to_impl_thread_ = false; | 850 commit_request_sent_to_impl_thread_ = false; |
841 bool can_cancel_this_commit = | 851 bool can_cancel_this_commit = |
842 can_cancel_commit_ && | 852 can_cancel_commit_ && |
843 !in_composite_and_readback_ && | 853 !in_composite_and_readback_ && |
844 !evicted_ui_resources && | 854 !evicted_ui_resources; |
845 !layer_tree_host()->next_commit_forces_redraw(); | |
846 can_cancel_commit_ = true; | 855 can_cancel_commit_ = true; |
847 | 856 |
848 scoped_ptr<ResourceUpdateQueue> queue = | 857 scoped_ptr<ResourceUpdateQueue> queue = |
849 make_scoped_ptr(new ResourceUpdateQueue); | 858 make_scoped_ptr(new ResourceUpdateQueue); |
850 | 859 |
851 bool updated = layer_tree_host()->UpdateLayers(queue.get()); | 860 bool updated = layer_tree_host()->UpdateLayers(queue.get()); |
852 | 861 |
853 // Once single buffered layers are committed, they cannot be modified until | 862 // Once single buffered layers are committed, they cannot be modified until |
854 // they are drawn by the impl thread. | 863 // they are drawn by the impl thread. |
855 textures_acquired_ = false; | 864 textures_acquired_ = false; |
856 | 865 |
857 layer_tree_host()->WillCommit(); | 866 layer_tree_host()->WillCommit(); |
858 | 867 |
859 // Before calling animate, we set update_requested_ to false. If it is true | |
860 // now, it means SetNeedsUpdateLayers was called again. Depending on during | |
861 // which phase of the commit SetNeedsUpdateLayers was called, | |
862 // commit_request_sent_to_impl_thread_ may be already cleared or not. | |
863 // We call SetNeedsUpdateLayers here to make sure a commit always gets posted. | |
864 if (update_requested_) { | |
865 // Forces SetNeedsUpdateLayers to consider posting a commit task. | |
866 update_requested_ = false; | |
867 SetNeedsUpdateLayers(); | |
868 } | |
869 | |
870 if (!updated && can_cancel_this_commit) { | 868 if (!updated && can_cancel_this_commit) { |
871 TRACE_EVENT0("cc", "EarlyOut_NoUpdates"); | 869 TRACE_EVENT0("cc", "EarlyOut_NoUpdates"); |
872 bool did_handle = true; | 870 bool did_handle = true; |
873 Proxy::ImplThreadTaskRunner()->PostTask( | 871 Proxy::ImplThreadTaskRunner()->PostTask( |
874 FROM_HERE, | 872 FROM_HERE, |
875 base::Bind(&ThreadProxy::BeginMainFrameAbortedOnImplThread, | 873 base::Bind(&ThreadProxy::BeginMainFrameAbortedOnImplThread, |
876 impl_thread_weak_ptr_, | 874 impl_thread_weak_ptr_, |
877 did_handle)); | 875 did_handle)); |
878 | 876 |
879 // Although the commit is internally aborted, this is because it has been | 877 // Although the commit is internally aborted, this is because it has been |
880 // detected to be a no-op. From the perspective of an embedder, this commit | 878 // detected to be a no-op. From the perspective of an embedder, this commit |
881 // went through, and input should no longer be throttled, etc. | 879 // went through, and input should no longer be throttled, etc. |
882 layer_tree_host()->CommitComplete(); | 880 layer_tree_host()->CommitComplete(); |
883 layer_tree_host()->DidBeginMainFrame(); | 881 layer_tree_host()->DidBeginMainFrame(); |
884 return; | 882 return; |
885 } | 883 } |
886 | 884 |
| 885 // Before calling animate, we set animate_requested_ to false. If it is true |
| 886 // now, it means SetNeedAnimate was called again, but during a state when |
| 887 // commit_request_sent_to_impl_thread_ = true. We need to force that call to |
| 888 // happen again now so that the commit request is sent to the impl thread. |
| 889 if (animate_requested_) { |
| 890 // Forces SetNeedsAnimate to consider posting a commit task. |
| 891 animate_requested_ = false; |
| 892 SetNeedsAnimate(); |
| 893 } |
| 894 |
887 scoped_refptr<ContextProvider> offscreen_context_provider; | 895 scoped_refptr<ContextProvider> offscreen_context_provider; |
888 if (renderer_capabilities_main_thread_copy_.using_offscreen_context3d && | 896 if (renderer_capabilities_main_thread_copy_.using_offscreen_context3d && |
889 layer_tree_host()->needs_offscreen_context()) { | 897 layer_tree_host()->needs_offscreen_context()) { |
890 offscreen_context_provider = | 898 offscreen_context_provider = |
891 layer_tree_host()->client()->OffscreenContextProvider(); | 899 layer_tree_host()->client()->OffscreenContextProvider(); |
892 if (offscreen_context_provider.get()) | 900 if (offscreen_context_provider.get()) |
893 created_offscreen_context_provider_ = true; | 901 created_offscreen_context_provider_ = true; |
894 } | 902 } |
895 | 903 |
896 // Notify the impl thread that the main thread is ready to commit. This will | 904 // Notify the impl thread that the main thread is ready to commit. This will |
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1641 commit_to_activate_duration_history_.InsertSample( | 1649 commit_to_activate_duration_history_.InsertSample( |
1642 base::TimeTicks::HighResNow() - commit_complete_time_); | 1650 base::TimeTicks::HighResNow() - commit_complete_time_); |
1643 } | 1651 } |
1644 | 1652 |
1645 void ThreadProxy::DidManageTiles() { | 1653 void ThreadProxy::DidManageTiles() { |
1646 DCHECK(IsImplThread()); | 1654 DCHECK(IsImplThread()); |
1647 scheduler_on_impl_thread_->DidManageTiles(); | 1655 scheduler_on_impl_thread_->DidManageTiles(); |
1648 } | 1656 } |
1649 | 1657 |
1650 } // namespace cc | 1658 } // namespace cc |
OLD | NEW |