Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: cc/trees/thread_proxy.cc

Issue 68893031: Unifies LayerTreeHost::SetNeedsUpdateLayers and SetNeedsAnimate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed cc animation unittest Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 make_scoped_ptr(new ResourceUpdateQueue); 848 make_scoped_ptr(new ResourceUpdateQueue);
859 849
860 bool updated = layer_tree_host()->UpdateLayers(queue.get()); 850 bool updated = layer_tree_host()->UpdateLayers(queue.get());
861 851
862 // Once single buffered layers are committed, they cannot be modified until 852 // Once single buffered layers are committed, they cannot be modified until
863 // they are drawn by the impl thread. 853 // they are drawn by the impl thread.
864 textures_acquired_ = false; 854 textures_acquired_ = false;
865 855
866 layer_tree_host()->WillCommit(); 856 layer_tree_host()->WillCommit();
867 857
858 // Before calling animate, we set update_requested_ to false. If it is true
859 // now, it means SetNeedsUpdateLayers was called again, but during a state
860 // when commit_request_sent_to_impl_thread_ = true. We need to force that call
danakj 2013/12/05 18:28:16 Can you explain this? The SetNeedsUpdateLayers() f
ajuma 2013/12/05 19:01:06 SetNeedsUpdateLayers calls SendCommitRequestToImpl
danakj 2013/12/05 19:18:51 Ah, thanks. I see. SendCommitRequestToImplThreadIf
trchen 2013/12/06 03:42:39 It is doing the right thing. The comment is a bit
danakj 2013/12/06 17:21:33 Ah, that will do something different though, as SN
861 // to happen again now so that the commit request is sent to the impl thread.
862 if (update_requested_) {
863 // Forces SetNeedsUpdateLayers to consider posting a commit task.
864 update_requested_ = false;
865 SetNeedsUpdateLayers();
866 }
867
868 if (!updated && can_cancel_this_commit) { 868 if (!updated && can_cancel_this_commit) {
869 TRACE_EVENT0("cc", "EarlyOut_NoUpdates"); 869 TRACE_EVENT0("cc", "EarlyOut_NoUpdates");
870 bool did_handle = true; 870 bool did_handle = true;
871 Proxy::ImplThreadTaskRunner()->PostTask( 871 Proxy::ImplThreadTaskRunner()->PostTask(
872 FROM_HERE, 872 FROM_HERE,
873 base::Bind(&ThreadProxy::BeginMainFrameAbortedOnImplThread, 873 base::Bind(&ThreadProxy::BeginMainFrameAbortedOnImplThread,
874 impl_thread_weak_ptr_, 874 impl_thread_weak_ptr_,
875 did_handle)); 875 did_handle));
876 876
877 // 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
878 // 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
879 // went through, and input should no longer be throttled, etc. 879 // went through, and input should no longer be throttled, etc.
880 layer_tree_host()->CommitComplete(); 880 layer_tree_host()->CommitComplete();
881 layer_tree_host()->DidBeginMainFrame(); 881 layer_tree_host()->DidBeginMainFrame();
882 return; 882 return;
883 } 883 }
884 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
895 scoped_refptr<cc::ContextProvider> offscreen_context_provider; 885 scoped_refptr<cc::ContextProvider> offscreen_context_provider;
896 if (renderer_capabilities_main_thread_copy_.using_offscreen_context3d && 886 if (renderer_capabilities_main_thread_copy_.using_offscreen_context3d &&
897 layer_tree_host()->needs_offscreen_context()) { 887 layer_tree_host()->needs_offscreen_context()) {
898 offscreen_context_provider = 888 offscreen_context_provider =
899 layer_tree_host()->client()->OffscreenContextProvider(); 889 layer_tree_host()->client()->OffscreenContextProvider();
900 if (offscreen_context_provider.get()) 890 if (offscreen_context_provider.get())
901 created_offscreen_context_provider_ = true; 891 created_offscreen_context_provider_ = true;
902 } 892 }
903 893
904 // Notify the impl thread that the main thread is ready to commit. This will 894 // 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
1651 commit_to_activate_duration_history_.InsertSample( 1641 commit_to_activate_duration_history_.InsertSample(
1652 base::TimeTicks::HighResNow() - commit_complete_time_); 1642 base::TimeTicks::HighResNow() - commit_complete_time_);
1653 } 1643 }
1654 1644
1655 void ThreadProxy::DidManageTiles() { 1645 void ThreadProxy::DidManageTiles() {
1656 DCHECK(IsImplThread()); 1646 DCHECK(IsImplThread());
1657 scheduler_on_impl_thread_->DidManageTiles(); 1647 scheduler_on_impl_thread_->DidManageTiles();
1658 } 1648 }
1659 1649
1660 } // namespace cc 1650 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698