| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 LayerTreeHost* layer_tree_host, | 73 LayerTreeHost* layer_tree_host, |
| 74 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { | 74 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { |
| 75 return make_scoped_ptr( | 75 return make_scoped_ptr( |
| 76 new ThreadProxy(layer_tree_host, impl_task_runner)).PassAs<Proxy>(); | 76 new ThreadProxy(layer_tree_host, impl_task_runner)).PassAs<Proxy>(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 ThreadProxy::ThreadProxy( | 79 ThreadProxy::ThreadProxy( |
| 80 LayerTreeHost* layer_tree_host, | 80 LayerTreeHost* layer_tree_host, |
| 81 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) | 81 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) |
| 82 : Proxy(impl_task_runner), | 82 : Proxy(impl_task_runner), |
| 83 animate_requested_(false), | 83 update_requested_(false), |
| 84 commit_requested_(false), | 84 commit_requested_(false), |
| 85 commit_request_sent_to_impl_thread_(false), | 85 commit_request_sent_to_impl_thread_(false), |
| 86 created_offscreen_context_provider_(false), | 86 created_offscreen_context_provider_(false), |
| 87 layer_tree_host_unsafe_(layer_tree_host), | 87 layer_tree_host_unsafe_(layer_tree_host), |
| 88 contents_texture_manager_unsafe_(NULL), | 88 contents_texture_manager_unsafe_(NULL), |
| 89 started_(false), | 89 started_(false), |
| 90 textures_acquired_(true), | 90 textures_acquired_(true), |
| 91 in_composite_and_readback_(false), | 91 in_composite_and_readback_(false), |
| 92 manage_tiles_pending_(false), | 92 manage_tiles_pending_(false), |
| 93 commit_waits_for_activation_(false), | 93 commit_waits_for_activation_(false), |
| (...skipping 249 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 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 SwapPromiseChecker swap_promise_checker(layer_tree_host()); | 769 SwapPromiseChecker swap_promise_checker(layer_tree_host()); |
| 780 | 770 |
| 781 // Do not notify the impl thread of commit requests that occur during | 771 // Do not notify the impl thread of commit requests that occur during |
| 782 // the apply/animate/layout part of the BeginMainFrameAndCommit process since | 772 // the apply/animate/layout part of the BeginMainFrameAndCommit process since |
| 783 // those commit requests will get painted immediately. Once we have done | 773 // those commit requests will get painted immediately. Once we have done |
| 784 // the paint, commit_requested_ will be set to false to allow new commit | 774 // the paint, commit_requested_ will be set to false to allow new commit |
| 785 // requests to be scheduled. | 775 // requests to be scheduled. |
| 786 commit_requested_ = true; | 776 commit_requested_ = true; |
| 787 commit_request_sent_to_impl_thread_ = true; | 777 commit_request_sent_to_impl_thread_ = true; |
| 788 | 778 |
| 789 // On the other hand, the AnimationRequested flag needs to be cleared | 779 // On the other hand, the update_requested_ flag needs to be cleared |
| 790 // here so that any animation requests generated by the apply or animate | 780 // here so that any update requests generated by the apply or animate |
| 791 // callbacks will trigger another frame. | 781 // callbacks will trigger another frame. |
| 792 animate_requested_ = false; | 782 update_requested_ = false; |
| 793 | 783 |
| 794 if (!in_composite_and_readback_ && !layer_tree_host()->visible()) { | 784 if (!in_composite_and_readback_ && !layer_tree_host()->visible()) { |
| 795 commit_requested_ = false; | 785 commit_requested_ = false; |
| 796 commit_request_sent_to_impl_thread_ = false; | 786 commit_request_sent_to_impl_thread_ = false; |
| 797 | 787 |
| 798 TRACE_EVENT0("cc", "EarlyOut_NotVisible"); | 788 TRACE_EVENT0("cc", "EarlyOut_NotVisible"); |
| 799 bool did_handle = false; | 789 bool did_handle = false; |
| 800 Proxy::ImplThreadTaskRunner()->PostTask( | 790 Proxy::ImplThreadTaskRunner()->PostTask( |
| 801 FROM_HERE, | 791 FROM_HERE, |
| 802 base::Bind(&ThreadProxy::BeginMainFrameAbortedOnImplThread, | 792 base::Bind(&ThreadProxy::BeginMainFrameAbortedOnImplThread, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 layer_tree_host()->Layout(); | 834 layer_tree_host()->Layout(); |
| 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 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1651 commit_to_activate_duration_history_.InsertSample( | 1643 commit_to_activate_duration_history_.InsertSample( |
| 1652 base::TimeTicks::HighResNow() - commit_complete_time_); | 1644 base::TimeTicks::HighResNow() - commit_complete_time_); |
| 1653 } | 1645 } |
| 1654 | 1646 |
| 1655 void ThreadProxy::DidManageTiles() { | 1647 void ThreadProxy::DidManageTiles() { |
| 1656 DCHECK(IsImplThread()); | 1648 DCHECK(IsImplThread()); |
| 1657 scheduler_on_impl_thread_->DidManageTiles(); | 1649 scheduler_on_impl_thread_->DidManageTiles(); |
| 1658 } | 1650 } |
| 1659 | 1651 |
| 1660 } // namespace cc | 1652 } // namespace cc |
| OLD | NEW |