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 animate_requested_(false), | 84 update_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 | |
364 void ThreadProxy::SetNeedsUpdateLayers() { | 353 void ThreadProxy::SetNeedsUpdateLayers() { |
365 DCHECK(IsMainThread()); | 354 DCHECK(IsMainThread()); |
366 | 355 |
367 if (commit_request_sent_to_impl_thread_) | 356 if (update_requested_) |
368 return; | 357 return; |
369 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsUpdateLayers"); | 358 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsUpdateLayers"); |
370 | 359 |
| 360 update_requested_ = true; |
371 SendCommitRequestToImplThreadIfNeeded(); | 361 SendCommitRequestToImplThreadIfNeeded(); |
372 } | 362 } |
373 | 363 |
374 void ThreadProxy::SetNeedsCommit() { | 364 void ThreadProxy::SetNeedsCommit() { |
375 DCHECK(IsMainThread()); | 365 DCHECK(IsMainThread()); |
376 // Unconditionally set here to handle SetNeedsCommit calls during a commit. | 366 // Unconditionally set here to handle SetNeedsCommit calls during a commit. |
377 can_cancel_commit_ = false; | 367 can_cancel_commit_ = false; |
378 | 368 |
379 if (commit_requested_) | 369 if (commit_requested_) |
380 return; | 370 return; |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 SwapPromiseChecker swap_promise_checker(layer_tree_host()); | 768 SwapPromiseChecker swap_promise_checker(layer_tree_host()); |
779 | 769 |
780 // Do not notify the impl thread of commit requests that occur during | 770 // Do not notify the impl thread of commit requests that occur during |
781 // the apply/animate/layout part of the BeginMainFrameAndCommit process since | 771 // the apply/animate/layout part of the BeginMainFrameAndCommit process since |
782 // those commit requests will get painted immediately. Once we have done | 772 // those commit requests will get painted immediately. Once we have done |
783 // the paint, commit_requested_ will be set to false to allow new commit | 773 // the paint, commit_requested_ will be set to false to allow new commit |
784 // requests to be scheduled. | 774 // requests to be scheduled. |
785 commit_requested_ = true; | 775 commit_requested_ = true; |
786 commit_request_sent_to_impl_thread_ = true; | 776 commit_request_sent_to_impl_thread_ = true; |
787 | 777 |
788 // On the other hand, the AnimationRequested flag needs to be cleared | 778 // On the other hand, the update_requested_ flag needs to be cleared |
789 // here so that any animation requests generated by the apply or animate | 779 // here so that any update requests generated by the apply or animate |
790 // callbacks will trigger another frame. | 780 // callbacks will trigger another frame. |
791 animate_requested_ = false; | 781 update_requested_ = false; |
792 | 782 |
793 if (!in_composite_and_readback_ && !layer_tree_host()->visible()) { | 783 if (!in_composite_and_readback_ && !layer_tree_host()->visible()) { |
794 commit_requested_ = false; | 784 commit_requested_ = false; |
795 commit_request_sent_to_impl_thread_ = false; | 785 commit_request_sent_to_impl_thread_ = false; |
796 | 786 |
797 TRACE_EVENT0("cc", "EarlyOut_NotVisible"); | 787 TRACE_EVENT0("cc", "EarlyOut_NotVisible"); |
798 bool did_handle = false; | 788 bool did_handle = false; |
799 Proxy::ImplThreadTaskRunner()->PostTask( | 789 Proxy::ImplThreadTaskRunner()->PostTask( |
800 FROM_HERE, | 790 FROM_HERE, |
801 base::Bind(&ThreadProxy::BeginMainFrameAbortedOnImplThread, | 791 base::Bind(&ThreadProxy::BeginMainFrameAbortedOnImplThread, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 TRACE_EVENT_SYNTHETIC_DELAY_END("cc.BeginMainFrame"); | 834 TRACE_EVENT_SYNTHETIC_DELAY_END("cc.BeginMainFrame"); |
845 | 835 |
846 // Clear the commit flag after updating animations and layout here --- objects | 836 // Clear the commit flag after updating animations and layout here --- objects |
847 // that only layout when painted will trigger another SetNeedsCommit inside | 837 // that only layout when painted will trigger another SetNeedsCommit inside |
848 // UpdateLayers. | 838 // UpdateLayers. |
849 commit_requested_ = false; | 839 commit_requested_ = false; |
850 commit_request_sent_to_impl_thread_ = false; | 840 commit_request_sent_to_impl_thread_ = false; |
851 bool can_cancel_this_commit = | 841 bool can_cancel_this_commit = |
852 can_cancel_commit_ && | 842 can_cancel_commit_ && |
853 !in_composite_and_readback_ && | 843 !in_composite_and_readback_ && |
854 !evicted_ui_resources; | 844 !evicted_ui_resources && |
| 845 !layer_tree_host()->next_commit_forces_redraw(); |
855 can_cancel_commit_ = true; | 846 can_cancel_commit_ = true; |
856 | 847 |
857 scoped_ptr<ResourceUpdateQueue> queue = | 848 scoped_ptr<ResourceUpdateQueue> queue = |
858 make_scoped_ptr(new ResourceUpdateQueue); | 849 make_scoped_ptr(new ResourceUpdateQueue); |
859 | 850 |
860 bool updated = layer_tree_host()->UpdateLayers(queue.get()); | 851 bool updated = layer_tree_host()->UpdateLayers(queue.get()); |
861 | 852 |
862 // Once single buffered layers are committed, they cannot be modified until | 853 // Once single buffered layers are committed, they cannot be modified until |
863 // they are drawn by the impl thread. | 854 // they are drawn by the impl thread. |
864 textures_acquired_ = false; | 855 textures_acquired_ = false; |
865 | 856 |
866 layer_tree_host()->WillCommit(); | 857 layer_tree_host()->WillCommit(); |
867 | 858 |
| 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 |
868 if (!updated && can_cancel_this_commit) { | 870 if (!updated && can_cancel_this_commit) { |
869 TRACE_EVENT0("cc", "EarlyOut_NoUpdates"); | 871 TRACE_EVENT0("cc", "EarlyOut_NoUpdates"); |
870 bool did_handle = true; | 872 bool did_handle = true; |
871 Proxy::ImplThreadTaskRunner()->PostTask( | 873 Proxy::ImplThreadTaskRunner()->PostTask( |
872 FROM_HERE, | 874 FROM_HERE, |
873 base::Bind(&ThreadProxy::BeginMainFrameAbortedOnImplThread, | 875 base::Bind(&ThreadProxy::BeginMainFrameAbortedOnImplThread, |
874 impl_thread_weak_ptr_, | 876 impl_thread_weak_ptr_, |
875 did_handle)); | 877 did_handle)); |
876 | 878 |
877 // Although the commit is internally aborted, this is because it has been | 879 // Although the commit is internally aborted, this is because it has been |
878 // detected to be a no-op. From the perspective of an embedder, this commit | 880 // detected to be a no-op. From the perspective of an embedder, this commit |
879 // went through, and input should no longer be throttled, etc. | 881 // went through, and input should no longer be throttled, etc. |
880 layer_tree_host()->CommitComplete(); | 882 layer_tree_host()->CommitComplete(); |
881 layer_tree_host()->DidBeginMainFrame(); | 883 layer_tree_host()->DidBeginMainFrame(); |
882 return; | 884 return; |
883 } | 885 } |
884 | 886 |
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 | |
895 scoped_refptr<ContextProvider> offscreen_context_provider; | 887 scoped_refptr<ContextProvider> offscreen_context_provider; |
896 if (renderer_capabilities_main_thread_copy_.using_offscreen_context3d && | 888 if (renderer_capabilities_main_thread_copy_.using_offscreen_context3d && |
897 layer_tree_host()->needs_offscreen_context()) { | 889 layer_tree_host()->needs_offscreen_context()) { |
898 offscreen_context_provider = | 890 offscreen_context_provider = |
899 layer_tree_host()->client()->OffscreenContextProvider(); | 891 layer_tree_host()->client()->OffscreenContextProvider(); |
900 if (offscreen_context_provider.get()) | 892 if (offscreen_context_provider.get()) |
901 created_offscreen_context_provider_ = true; | 893 created_offscreen_context_provider_ = true; |
902 } | 894 } |
903 | 895 |
904 // Notify the impl thread that the main thread is ready to commit. This will | 896 // Notify the impl thread that the main thread is ready to commit. This will |
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1647 commit_to_activate_duration_history_.InsertSample( | 1639 commit_to_activate_duration_history_.InsertSample( |
1648 base::TimeTicks::HighResNow() - commit_complete_time_); | 1640 base::TimeTicks::HighResNow() - commit_complete_time_); |
1649 } | 1641 } |
1650 | 1642 |
1651 void ThreadProxy::DidManageTiles() { | 1643 void ThreadProxy::DidManageTiles() { |
1652 DCHECK(IsImplThread()); | 1644 DCHECK(IsImplThread()); |
1653 scheduler_on_impl_thread_->DidManageTiles(); | 1645 scheduler_on_impl_thread_->DidManageTiles(); |
1654 } | 1646 } |
1655 | 1647 |
1656 } // namespace cc | 1648 } // namespace cc |
OLD | NEW |