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

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

Issue 16871016: cc: Use BeginFrameArgs (Closed) Base URL: http://git.chromium.org/chromium/src.git@bfargs2
Patch Set: Fixed all existing tests! New tests pending... Created 7 years, 5 months 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
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 commit_requested_(false), 70 commit_requested_(false),
71 commit_request_sent_to_impl_thread_(false), 71 commit_request_sent_to_impl_thread_(false),
72 created_offscreen_context_provider_(false), 72 created_offscreen_context_provider_(false),
73 layer_tree_host_(layer_tree_host), 73 layer_tree_host_(layer_tree_host),
74 started_(false), 74 started_(false),
75 textures_acquired_(true), 75 textures_acquired_(true),
76 in_composite_and_readback_(false), 76 in_composite_and_readback_(false),
77 manage_tiles_pending_(false), 77 manage_tiles_pending_(false),
78 weak_factory_on_impl_thread_(this), 78 weak_factory_on_impl_thread_(this),
79 weak_factory_(this), 79 weak_factory_(this),
80 frame_did_draw_(false),
80 begin_frame_sent_to_main_thread_completion_event_on_impl_thread_(NULL), 81 begin_frame_sent_to_main_thread_completion_event_on_impl_thread_(NULL),
81 readback_request_on_impl_thread_(NULL), 82 readback_request_on_impl_thread_(NULL),
82 commit_completion_event_on_impl_thread_(NULL), 83 commit_completion_event_on_impl_thread_(NULL),
83 completion_event_for_commit_held_on_tree_activation_(NULL), 84 completion_event_for_commit_held_on_tree_activation_(NULL),
84 texture_acquisition_completion_event_on_impl_thread_(NULL), 85 texture_acquisition_completion_event_on_impl_thread_(NULL),
85 next_frame_is_newly_committed_frame_on_impl_thread_(false), 86 next_frame_is_newly_committed_frame_on_impl_thread_(false),
86 throttle_frame_production_( 87 throttle_frame_production_(
87 layer_tree_host->settings().throttle_frame_production), 88 layer_tree_host->settings().throttle_frame_production),
88 begin_frame_scheduling_enabled_( 89 begin_frame_scheduling_enabled_(
89 layer_tree_host->settings().begin_frame_scheduling_enabled), 90 layer_tree_host->settings().begin_frame_scheduling_enabled),
(...skipping 20 matching lines...) Expand all
110 TRACE_EVENT0("cc", "ThreadProxy::CompositeAndReadback"); 111 TRACE_EVENT0("cc", "ThreadProxy::CompositeAndReadback");
111 DCHECK(IsMainThread()); 112 DCHECK(IsMainThread());
112 DCHECK(layer_tree_host_); 113 DCHECK(layer_tree_host_);
113 DCHECK(!defer_commits_); 114 DCHECK(!defer_commits_);
114 115
115 if (!layer_tree_host_->InitializeOutputSurfaceIfNeeded()) { 116 if (!layer_tree_host_->InitializeOutputSurfaceIfNeeded()) {
116 TRACE_EVENT0("cc", "CompositeAndReadback_EarlyOut_LR_Uninitialized"); 117 TRACE_EVENT0("cc", "CompositeAndReadback_EarlyOut_LR_Uninitialized");
117 return false; 118 return false;
118 } 119 }
119 120
120 // Perform a synchronous commit. 121 // Perform a synchronous commit with an associated readback.
122 ReadbackRequest request;
123 request.rect = rect;
124 request.pixels = pixels;
121 { 125 {
122 DebugScopedSetMainThreadBlocked main_thread_blocked(this); 126 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
123 CompletionEvent begin_frame_sent_to_main_thread_completion; 127 CompletionEvent begin_frame_sent_to_main_thread_completion;
124 Proxy::ImplThreadTaskRunner()->PostTask( 128 Proxy::ImplThreadTaskRunner()->PostTask(
125 FROM_HERE, 129 FROM_HERE,
126 base::Bind(&ThreadProxy::ForceCommitOnImplThread, 130 base::Bind(&ThreadProxy::ForceCommitForReadbackOnImplThread,
127 impl_thread_weak_ptr_, 131 impl_thread_weak_ptr_,
128 &begin_frame_sent_to_main_thread_completion)); 132 &begin_frame_sent_to_main_thread_completion,
133 &request));
129 begin_frame_sent_to_main_thread_completion.Wait(); 134 begin_frame_sent_to_main_thread_completion.Wait();
130 } 135 }
131 in_composite_and_readback_ = true; 136 in_composite_and_readback_ = true;
137 // This is the forced commit.
138 // Note: The Impl thread also queues a separate BeginFrameOnMainThread on the
139 // main thread, which will be called after this CompositeAndReadback
140 // completes, to replace the forced commit.
132 BeginFrameOnMainThread(scoped_ptr<BeginFrameAndCommitState>()); 141 BeginFrameOnMainThread(scoped_ptr<BeginFrameAndCommitState>());
133 in_composite_and_readback_ = false; 142 in_composite_and_readback_ = false;
134 143
135 // Perform a synchronous readback. 144 request.completion.Wait();
136 ReadbackRequest request;
137 request.rect = rect;
138 request.pixels = pixels;
139 {
140 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
141 Proxy::ImplThreadTaskRunner()->PostTask(
142 FROM_HERE,
143 base::Bind(&ThreadProxy::RequestReadbackOnImplThread,
brianderson 2013/07/18 02:02:49 This method has been made part of ForceCommitForRe
144 impl_thread_weak_ptr_,
145 &request));
146 request.completion.Wait();
147 }
148 return request.success; 145 return request.success;
149 } 146 }
150 147
151 void ThreadProxy::ForceCommitOnImplThread(CompletionEvent* completion) { 148 void ThreadProxy::ForceCommitForReadbackOnImplThread(
152 TRACE_EVENT0("cc", "ThreadProxy::ForceCommitOnImplThread"); 149 CompletionEvent* begin_frame_sent_completion,
150 ReadbackRequest* request) {
151 TRACE_EVENT0("cc", "ThreadProxy::ForceCommitForReadbackOnImplThread");
153 DCHECK(IsImplThread()); 152 DCHECK(IsImplThread());
154 DCHECK(!begin_frame_sent_to_main_thread_completion_event_on_impl_thread_); 153 DCHECK(!begin_frame_sent_to_main_thread_completion_event_on_impl_thread_);
154 DCHECK(!readback_request_on_impl_thread_);
155 155
156 scheduler_on_impl_thread_->SetNeedsForcedCommit();
157 if (scheduler_on_impl_thread_->CommitPending()) {
158 completion->Signal();
159 return;
160 }
161
162 begin_frame_sent_to_main_thread_completion_event_on_impl_thread_ = completion;
163 }
164
165 void ThreadProxy::RequestReadbackOnImplThread(ReadbackRequest* request) {
166 DCHECK(Proxy::IsImplThread());
167 DCHECK(!readback_request_on_impl_thread_);
168 if (!layer_tree_host_impl_) { 156 if (!layer_tree_host_impl_) {
157 begin_frame_sent_completion->Signal();
169 request->success = false; 158 request->success = false;
170 request->completion.Signal(); 159 request->completion.Signal();
171 return; 160 return;
172 } 161 }
173 162
174 readback_request_on_impl_thread_ = request; 163 readback_request_on_impl_thread_ = request;
175 scheduler_on_impl_thread_->SetNeedsRedraw(); 164
176 scheduler_on_impl_thread_->SetNeedsForcedRedraw(); 165 scheduler_on_impl_thread_->SetNeedsForcedCommitForReadback();
166 if (scheduler_on_impl_thread_->CommitPending()) {
167 begin_frame_sent_completion->Signal();
168 return;
169 }
170
171 begin_frame_sent_to_main_thread_completion_event_on_impl_thread_ =
172 begin_frame_sent_completion;
177 } 173 }
178 174
179 void ThreadProxy::FinishAllRendering() { 175 void ThreadProxy::FinishAllRendering() {
180 DCHECK(Proxy::IsMainThread()); 176 DCHECK(Proxy::IsMainThread());
181 DCHECK(!defer_commits_); 177 DCHECK(!defer_commits_);
182 178
183 // Make sure all GL drawing is finished on the impl thread. 179 // Make sure all GL drawing is finished on the impl thread.
184 DebugScopedSetMainThreadBlocked main_thread_blocked(this); 180 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
185 CompletionEvent completion; 181 CompletionEvent completion;
186 Proxy::ImplThreadTaskRunner()->PostTask( 182 Proxy::ImplThreadTaskRunner()->PostTask(
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 Proxy::MainThreadTaskRunner()->PostTask( 362 Proxy::MainThreadTaskRunner()->PostTask(
367 FROM_HERE, 363 FROM_HERE,
368 base::Bind(&ThreadProxy::DidCompleteSwapBuffers, main_thread_weak_ptr_)); 364 base::Bind(&ThreadProxy::DidCompleteSwapBuffers, main_thread_weak_ptr_));
369 } 365 }
370 366
371 void ThreadProxy::SetNeedsBeginFrameOnImplThread(bool enable) { 367 void ThreadProxy::SetNeedsBeginFrameOnImplThread(bool enable) {
372 DCHECK(IsImplThread()); 368 DCHECK(IsImplThread());
373 TRACE_EVENT1("cc", "ThreadProxy::SetNeedsBeginFrameOnImplThread", 369 TRACE_EVENT1("cc", "ThreadProxy::SetNeedsBeginFrameOnImplThread",
374 "enable", enable); 370 "enable", enable);
375 layer_tree_host_impl_->SetNeedsBeginFrame(enable); 371 layer_tree_host_impl_->SetNeedsBeginFrame(enable);
372 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(!enable);
376 } 373 }
377 374
378 void ThreadProxy::BeginFrameOnImplThread(const BeginFrameArgs& args) { 375 void ThreadProxy::BeginFrameOnImplThread(const BeginFrameArgs& args) {
379 DCHECK(IsImplThread()); 376 DCHECK(IsImplThread());
380 TRACE_EVENT0("cc", "ThreadProxy::BeginFrameOnImplThread"); 377 TRACE_EVENT0("cc", "ThreadProxy::BeginFrameOnImplThread");
378
379 base::TimeTicks monotonic_time =
380 layer_tree_host_impl_->CurrentFrameTimeTicks();
381 base::Time wall_clock_time = layer_tree_host_impl_->CurrentFrameTime();
382 layer_tree_host_impl_->Animate(monotonic_time, wall_clock_time);
383
384 // Reinitialize for the current frame.
385 frame_did_draw_ = false;
386
381 scheduler_on_impl_thread_->BeginFrame(args); 387 scheduler_on_impl_thread_->BeginFrame(args);
382 } 388 }
383 389
390 void ThreadProxy::DidBeginFrameDeadlineOnImplThread() {
391 // Do not start animations if we skip drawing the frame to avoid
392 // checkerboarding.
393 layer_tree_host_impl_->UpdateAnimationState(
394 frame_did_draw_ || !layer_tree_host_impl_->CanDraw());
395 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame();
396 }
397
384 void ThreadProxy::OnCanDrawStateChanged(bool can_draw) { 398 void ThreadProxy::OnCanDrawStateChanged(bool can_draw) {
385 DCHECK(IsImplThread()); 399 DCHECK(IsImplThread());
386 TRACE_EVENT1( 400 TRACE_EVENT1(
387 "cc", "ThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); 401 "cc", "ThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw);
388 scheduler_on_impl_thread_->SetCanDraw(can_draw); 402 scheduler_on_impl_thread_->SetCanDraw(can_draw);
389 layer_tree_host_impl_->UpdateBackgroundAnimateTicking( 403 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(
390 !scheduler_on_impl_thread_->WillDrawIfNeeded()); 404 !scheduler_on_impl_thread_->WillDrawIfNeeded());
391 } 405 }
392 406
393 void ThreadProxy::OnHasPendingTreeStateChanged(bool has_pending_tree) { 407 void ThreadProxy::OnHasPendingTreeStateChanged(bool has_pending_tree) {
394 DCHECK(IsImplThread()); 408 DCHECK(IsImplThread());
395 TRACE_EVENT1("cc", "ThreadProxy::OnHasPendingTreeStateChanged", 409 TRACE_EVENT1("cc", "ThreadProxy::OnHasPendingTreeStateChanged",
396 "has_pending_tree", has_pending_tree); 410 "has_pending_tree", has_pending_tree);
397 scheduler_on_impl_thread_->SetHasPendingTree(has_pending_tree); 411 scheduler_on_impl_thread_->SetHasTrees(
412 has_pending_tree,
413 layer_tree_host_impl_->active_tree() ?
414 !layer_tree_host_impl_->active_tree()->root_layer() : true);
415
416 if (!has_pending_tree && !deferred_start_commit_on_impl_thread_.is_null()) {
417 Proxy::ImplThreadTaskRunner()->PostTask(
418 FROM_HERE,
419 deferred_start_commit_on_impl_thread_);
420 deferred_start_commit_on_impl_thread_.Reset();
421 }
398 } 422 }
399 423
400 void ThreadProxy::SetNeedsCommitOnImplThread() { 424 void ThreadProxy::SetNeedsCommitOnImplThread() {
401 DCHECK(IsImplThread()); 425 DCHECK(IsImplThread());
402 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsCommitOnImplThread"); 426 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsCommitOnImplThread");
403 scheduler_on_impl_thread_->SetNeedsCommit(); 427 scheduler_on_impl_thread_->SetNeedsCommit();
404 } 428 }
405 429
406 void ThreadProxy::PostAnimationEventsToMainThreadOnImplThread( 430 void ThreadProxy::PostAnimationEventsToMainThreadOnImplThread(
407 scoped_ptr<AnimationEventsVector> events, 431 scoped_ptr<AnimationEventsVector> events,
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 TRACE_EVENT0("cc", "ThreadProxy::FinishAllRenderingOnImplThread"); 647 TRACE_EVENT0("cc", "ThreadProxy::FinishAllRenderingOnImplThread");
624 DCHECK(IsImplThread()); 648 DCHECK(IsImplThread());
625 layer_tree_host_impl_->FinishAllRendering(); 649 layer_tree_host_impl_->FinishAllRendering();
626 completion->Signal(); 650 completion->Signal();
627 } 651 }
628 652
629 void ThreadProxy::ScheduledActionSendBeginFrameToMainThread() { 653 void ThreadProxy::ScheduledActionSendBeginFrameToMainThread() {
630 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionSendBeginFrameToMainThread"); 654 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionSendBeginFrameToMainThread");
631 scoped_ptr<BeginFrameAndCommitState> begin_frame_state( 655 scoped_ptr<BeginFrameAndCommitState> begin_frame_state(
632 new BeginFrameAndCommitState); 656 new BeginFrameAndCommitState);
657
633 begin_frame_state->monotonic_frame_begin_time = 658 begin_frame_state->monotonic_frame_begin_time =
634 layer_tree_host_impl_->CurrentPhysicalTimeTicks(); 659 layer_tree_host_impl_->CurrentPhysicalTimeTicks();
635 begin_frame_state->scroll_info = 660 begin_frame_state->scroll_info =
636 layer_tree_host_impl_->ProcessScrollDeltas(); 661 layer_tree_host_impl_->ProcessScrollDeltas();
637 662
638 if (!layer_tree_host_impl_->settings().impl_side_painting) { 663 if (!layer_tree_host_impl_->settings().impl_side_painting) {
639 DCHECK_GT(layer_tree_host_impl_->memory_allocation_limit_bytes(), 0u); 664 DCHECK_GT(layer_tree_host_impl_->memory_allocation_limit_bytes(), 0u);
640 } 665 }
666
667
641 begin_frame_state->memory_allocation_limit_bytes = 668 begin_frame_state->memory_allocation_limit_bytes =
642 layer_tree_host_impl_->memory_allocation_limit_bytes(); 669 layer_tree_host_impl_->memory_allocation_limit_bytes();
643 Proxy::MainThreadTaskRunner()->PostTask( 670 Proxy::MainThreadTaskRunner()->PostTask(
644 FROM_HERE, 671 FROM_HERE,
645 base::Bind(&ThreadProxy::BeginFrameOnMainThread, 672 base::Bind(&ThreadProxy::BeginFrameOnMainThread,
646 main_thread_weak_ptr_, 673 main_thread_weak_ptr_,
647 base::Passed(&begin_frame_state))); 674 base::Passed(&begin_frame_state)));
648 675
649 if (begin_frame_sent_to_main_thread_completion_event_on_impl_thread_) { 676 if (begin_frame_sent_to_main_thread_completion_event_on_impl_thread_) {
650 begin_frame_sent_to_main_thread_completion_event_on_impl_thread_->Signal(); 677 begin_frame_sent_to_main_thread_completion_event_on_impl_thread_->Signal();
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 } 806 }
780 807
781 layer_tree_host_->CommitComplete(); 808 layer_tree_host_->CommitComplete();
782 layer_tree_host_->DidBeginFrame(); 809 layer_tree_host_->DidBeginFrame();
783 } 810 }
784 811
785 void ThreadProxy::StartCommitOnImplThread( 812 void ThreadProxy::StartCommitOnImplThread(
786 CompletionEvent* completion, 813 CompletionEvent* completion,
787 ResourceUpdateQueue* raw_queue, 814 ResourceUpdateQueue* raw_queue,
788 scoped_refptr<cc::ContextProvider> offscreen_context_provider) { 815 scoped_refptr<cc::ContextProvider> offscreen_context_provider) {
789 scoped_ptr<ResourceUpdateQueue> queue(raw_queue);
790
791 TRACE_EVENT0("cc", "ThreadProxy::StartCommitOnImplThread"); 816 TRACE_EVENT0("cc", "ThreadProxy::StartCommitOnImplThread");
792 DCHECK(!commit_completion_event_on_impl_thread_); 817 DCHECK(!commit_completion_event_on_impl_thread_);
793 DCHECK(IsImplThread() && IsMainThreadBlocked()); 818 DCHECK(IsImplThread() && IsMainThreadBlocked());
794 DCHECK(scheduler_on_impl_thread_); 819 DCHECK(scheduler_on_impl_thread_);
795 DCHECK(scheduler_on_impl_thread_->CommitPending()); 820 DCHECK(scheduler_on_impl_thread_->CommitPending());
796 821
797 if (!layer_tree_host_impl_) { 822 if (!layer_tree_host_impl_) {
798 TRACE_EVENT0("cc", "EarlyOut_NoLayerTree"); 823 TRACE_EVENT0("cc", "EarlyOut_NoLayerTree");
799 completion->Signal(); 824 completion->Signal();
825
800 return; 826 return;
801 } 827 }
802 828
829 // We defer forced commits while there is a pending tree here.
brianderson 2013/07/18 02:02:49 This code is no longer needed to make composite an
830 if (layer_tree_host_impl_->pending_tree()) {
831 NOTREACHED();
832 TRACE_EVENT0("cc", "EarlyOut_DeferringDueToPendingTree");
833 DCHECK(deferred_start_commit_on_impl_thread_.is_null());
834 deferred_start_commit_on_impl_thread_ =
835 base::Bind(&ThreadProxy::StartCommitOnImplThread,
836 impl_thread_weak_ptr_,
837 completion,
838 raw_queue,
839 offscreen_context_provider);
840 return;
841 }
842
843 scoped_ptr<ResourceUpdateQueue> queue(raw_queue);
844
803 if (offscreen_context_provider.get()) 845 if (offscreen_context_provider.get())
804 offscreen_context_provider->BindToCurrentThread(); 846 offscreen_context_provider->BindToCurrentThread();
805 layer_tree_host_impl_->resource_provider()-> 847 layer_tree_host_impl_->resource_provider()->
806 set_offscreen_context_provider(offscreen_context_provider); 848 set_offscreen_context_provider(offscreen_context_provider);
807 849
808 if (layer_tree_host_->contents_texture_manager()) { 850 if (layer_tree_host_->contents_texture_manager()) {
809 if (layer_tree_host_->contents_texture_manager()-> 851 if (layer_tree_host_->contents_texture_manager()->
810 LinkedEvictedBackingsExist()) { 852 LinkedEvictedBackingsExist()) {
811 // Clear any uploads we were making to textures linked to evicted 853 // Clear any uploads we were making to textures linked to evicted
812 // resources 854 // resources
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 890
849 // Complete all remaining texture updates. 891 // Complete all remaining texture updates.
850 current_resource_update_controller_on_impl_thread_->Finalize(); 892 current_resource_update_controller_on_impl_thread_->Finalize();
851 current_resource_update_controller_on_impl_thread_.reset(); 893 current_resource_update_controller_on_impl_thread_.reset();
852 894
853 layer_tree_host_impl_->BeginCommit(); 895 layer_tree_host_impl_->BeginCommit();
854 layer_tree_host_->BeginCommitOnImplThread(layer_tree_host_impl_.get()); 896 layer_tree_host_->BeginCommitOnImplThread(layer_tree_host_impl_.get());
855 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get()); 897 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get());
856 layer_tree_host_impl_->CommitComplete(); 898 layer_tree_host_impl_->CommitComplete();
857 899
858 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(
859 !scheduler_on_impl_thread_->WillDrawIfNeeded());
860
861 next_frame_is_newly_committed_frame_on_impl_thread_ = true; 900 next_frame_is_newly_committed_frame_on_impl_thread_ = true;
862 901
863 if (layer_tree_host_->settings().impl_side_painting && 902 if (layer_tree_host_->settings().impl_side_painting &&
864 layer_tree_host_->BlocksPendingCommit() && 903 layer_tree_host_->BlocksPendingCommit() &&
865 layer_tree_host_impl_->pending_tree()) { 904 layer_tree_host_impl_->pending_tree()) {
866 // For some layer types in impl-side painting, the commit is held until 905 // For some layer types in impl-side painting, the commit is held until
867 // the pending tree is activated. It's also possible that the 906 // the pending tree is activated. It's also possible that the
868 // pending tree has already activated if there was no work to be done. 907 // pending tree has already activated if there was no work to be done.
869 TRACE_EVENT_INSTANT0("cc", "HoldCommit", TRACE_EVENT_SCOPE_THREAD); 908 TRACE_EVENT_INSTANT0("cc", "HoldCommit", TRACE_EVENT_SCOPE_THREAD);
870 completion_event_for_commit_held_on_tree_activation_ = 909 completion_event_for_commit_held_on_tree_activation_ =
871 commit_completion_event_on_impl_thread_; 910 commit_completion_event_on_impl_thread_;
872 commit_completion_event_on_impl_thread_ = NULL; 911 commit_completion_event_on_impl_thread_ = NULL;
873 } else { 912 } else {
874 commit_completion_event_on_impl_thread_->Signal(); 913 commit_completion_event_on_impl_thread_->Signal();
875 commit_completion_event_on_impl_thread_ = NULL; 914 commit_completion_event_on_impl_thread_ = NULL;
876 } 915 }
877 916
878 commit_complete_time_ = base::TimeTicks::HighResNow(); 917 commit_complete_time_ = base::TimeTicks::HighResNow();
879 begin_frame_to_commit_duration_history_.InsertSample( 918 begin_frame_to_commit_duration_history_.InsertSample(
880 commit_complete_time_ - begin_frame_sent_to_main_thread_time_); 919 commit_complete_time_ - begin_frame_sent_to_main_thread_time_);
881 920
921 // The commit may have added animations, requiring us to start
922 // background ticking.
923 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(
924 !scheduler_on_impl_thread_->WillDrawIfNeeded());
882 // SetVisible kicks off the next scheduler action, so this must be last. 925 // SetVisible kicks off the next scheduler action, so this must be last.
883 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); 926 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible());
884 } 927 }
885 928
886 void ThreadProxy::ScheduledActionCheckForCompletedTileUploads() { 929 void ThreadProxy::ScheduledActionCheckForCompletedTileUploads() {
887 DCHECK(IsImplThread()); 930 DCHECK(IsImplThread());
888 TRACE_EVENT0("cc", 931 TRACE_EVENT0("cc",
889 "ThreadProxy::ScheduledActionCheckForCompletedTileUploads"); 932 "ThreadProxy::ScheduledActionCheckForCompletedTileUploads");
890 layer_tree_host_impl_->CheckForCompletedTileUploads(); 933 layer_tree_host_impl_->CheckForCompletedTileUploads();
891 } 934 }
892 935
893 void ThreadProxy::ScheduledActionActivatePendingTreeIfNeeded() { 936 void ThreadProxy::ScheduledActionActivatePendingTreeIfNeeded() {
894 DCHECK(IsImplThread()); 937 DCHECK(IsImplThread());
895 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionActivatePendingTreeIfNeeded"); 938 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionActivatePendingTreeIfNeeded");
896 layer_tree_host_impl_->ActivatePendingTreeIfNeeded(); 939 layer_tree_host_impl_->ActivatePendingTreeIfNeeded();
897 } 940 }
898 941
899 void ThreadProxy::ScheduledActionBeginOutputSurfaceCreation() { 942 void ThreadProxy::ScheduledActionBeginOutputSurfaceCreation() {
900 DCHECK(IsImplThread()); 943 DCHECK(IsImplThread());
901 Proxy::MainThreadTaskRunner()->PostTask( 944 Proxy::MainThreadTaskRunner()->PostTask(
902 FROM_HERE, 945 FROM_HERE,
903 base::Bind(&ThreadProxy::CreateAndInitializeOutputSurface, 946 base::Bind(&ThreadProxy::CreateAndInitializeOutputSurface,
904 main_thread_weak_ptr_)); 947 main_thread_weak_ptr_));
905 } 948 }
906 949
907 ScheduledActionDrawAndSwapResult 950 DrawSwapReadbackResult
908 ThreadProxy::ScheduledActionDrawAndSwapInternal(bool forced_draw) { 951 ThreadProxy::ScheduledActionDrawSwapReadbackInternal(
952 bool forced_draw, bool swap_requested, bool readback_requested) {
909 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwap"); 953 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwap");
910 954
911 ScheduledActionDrawAndSwapResult result; 955 DrawSwapReadbackResult result;
912 result.did_draw = false; 956 result.did_draw = false;
913 result.did_swap = false; 957 result.did_swap = false;
914 DCHECK(IsImplThread()); 958 DCHECK(IsImplThread());
915 DCHECK(layer_tree_host_impl_.get()); 959 DCHECK(layer_tree_host_impl_.get());
916 if (!layer_tree_host_impl_) 960 if (!layer_tree_host_impl_)
917 return result; 961 return result;
918 962
919 DCHECK(layer_tree_host_impl_->renderer()); 963 DCHECK(layer_tree_host_impl_->renderer());
920 if (!layer_tree_host_impl_->renderer()) 964 if (!layer_tree_host_impl_->renderer())
921 return result; 965 return result;
922 966
923 base::TimeTicks monotonic_time =
924 layer_tree_host_impl_->CurrentFrameTimeTicks();
925 base::Time wall_clock_time = layer_tree_host_impl_->CurrentFrameTime();
926
927 // TODO(enne): This should probably happen post-animate.
928 if (layer_tree_host_impl_->pending_tree()) {
929 layer_tree_host_impl_->ActivatePendingTreeIfNeeded();
930 if (layer_tree_host_impl_->pending_tree())
931 layer_tree_host_impl_->pending_tree()->UpdateDrawProperties();
932 }
933 layer_tree_host_impl_->Animate(monotonic_time, wall_clock_time);
934 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(false);
935
936 base::TimeTicks start_time = base::TimeTicks::HighResNow(); 967 base::TimeTicks start_time = base::TimeTicks::HighResNow();
937 base::TimeDelta draw_duration_estimate = DrawDurationEstimate(); 968 base::TimeDelta draw_duration_estimate = DrawDurationEstimate();
938 base::AutoReset<bool> mark_inside(&inside_draw_, true); 969 base::AutoReset<bool> mark_inside(&inside_draw_, true);
939 970
940 // This method is called on a forced draw, regardless of whether we are able 971 // This method is called on a forced draw, regardless of whether we are able
941 // to produce a frame, as the calling site on main thread is blocked until its 972 // to produce a frame, as the calling site on main thread is blocked until its
942 // request completes, and we signal completion here. If CanDraw() is false, we 973 // request completes, and we signal completion here. If CanDraw() is false, we
943 // will indicate success=false to the caller, but we must still signal 974 // will indicate success=false to the caller, but we must still signal
944 // completion to avoid deadlock. 975 // completion to avoid deadlock.
945 976
946 // We guard PrepareToDraw() with CanDraw() because it always returns a valid 977 // We guard PrepareToDraw() with CanDraw() because it always returns a valid
947 // frame, so can only be used when such a frame is possible. Since 978 // frame, so can only be used when such a frame is possible. Since
948 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on 979 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on
949 // CanDraw() as well. 980 // CanDraw() as well.
950 981
951 bool drawing_for_readback = !!readback_request_on_impl_thread_; 982 bool drawing_for_readback =
983 readback_requested && !!readback_request_on_impl_thread_;
952 bool can_do_readback = layer_tree_host_impl_->renderer()->CanReadPixels(); 984 bool can_do_readback = layer_tree_host_impl_->renderer()->CanReadPixels();
953 985
954 LayerTreeHostImpl::FrameData frame; 986 LayerTreeHostImpl::FrameData frame;
955 bool draw_frame = false; 987 bool draw_frame = false;
956 bool start_ready_animations = true;
957 988
958 if (layer_tree_host_impl_->CanDraw() && 989 if (layer_tree_host_impl_->CanDraw() &&
959 (!drawing_for_readback || can_do_readback)) { 990 (!drawing_for_readback || can_do_readback)) {
960 // If it is for a readback, make sure we draw the portion being read back. 991 // If it is for a readback, make sure we draw the portion being read back.
961 gfx::Rect readback_rect; 992 gfx::Rect readback_rect;
962 if (drawing_for_readback) 993 if (drawing_for_readback)
963 readback_rect = readback_request_on_impl_thread_->rect; 994 readback_rect = readback_request_on_impl_thread_->rect;
964 995
965 // Do not start animations if we skip drawing the frame to avoid
966 // checkerboarding.
967 if (layer_tree_host_impl_->PrepareToDraw(&frame, readback_rect) || 996 if (layer_tree_host_impl_->PrepareToDraw(&frame, readback_rect) ||
968 forced_draw) 997 forced_draw)
969 draw_frame = true; 998 draw_frame = true;
970 else
971 start_ready_animations = false;
972 } 999 }
973 1000
1001 frame_did_draw_ = draw_frame;
1002
974 if (draw_frame) { 1003 if (draw_frame) {
975 layer_tree_host_impl_->DrawLayers( 1004 layer_tree_host_impl_->DrawLayers(
976 &frame, 1005 &frame,
977 scheduler_on_impl_thread_->LastBeginFrameOnImplThreadTime()); 1006 scheduler_on_impl_thread_->LastBeginFrameOnImplThreadTime());
978 result.did_draw = true; 1007 result.did_draw = true;
979 } 1008 }
980 layer_tree_host_impl_->DidDrawAllLayers(frame); 1009 layer_tree_host_impl_->DidDrawAllLayers(frame);
981 1010
982 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations);
983
984 // Check for a pending CompositeAndReadback. 1011 // Check for a pending CompositeAndReadback.
985 if (readback_request_on_impl_thread_) { 1012 if (drawing_for_readback) {
986 readback_request_on_impl_thread_->success = false; 1013 result.did_readback = false;
987 if (draw_frame) { 1014 if (draw_frame) {
988 layer_tree_host_impl_->Readback(readback_request_on_impl_thread_->pixels, 1015 layer_tree_host_impl_->Readback(readback_request_on_impl_thread_->pixels,
989 readback_request_on_impl_thread_->rect); 1016 readback_request_on_impl_thread_->rect);
990 readback_request_on_impl_thread_->success = 1017 result.did_readback =
991 !layer_tree_host_impl_->IsContextLost(); 1018 !layer_tree_host_impl_->IsContextLost();
992 } 1019 }
1020 readback_request_on_impl_thread_->success = result.did_readback;
993 readback_request_on_impl_thread_->completion.Signal(); 1021 readback_request_on_impl_thread_->completion.Signal();
994 readback_request_on_impl_thread_ = NULL; 1022 readback_request_on_impl_thread_ = NULL;
995 } else if (draw_frame) { 1023 } else if (draw_frame && swap_requested) {
996 result.did_swap = layer_tree_host_impl_->SwapBuffers(frame); 1024 result.did_swap = layer_tree_host_impl_->SwapBuffers(frame);
997 1025
998 if (frame.contains_incomplete_tile) 1026 if (frame.contains_incomplete_tile)
999 DidSwapUseIncompleteTileOnImplThread(); 1027 DidSwapUseIncompleteTileOnImplThread();
1000 } 1028 }
1001 1029
1002 // Tell the main thread that the the newly-commited frame was drawn. 1030 // Tell the main thread that the the newly-commited frame was drawn.
1003 if (next_frame_is_newly_committed_frame_on_impl_thread_) { 1031 if (next_frame_is_newly_committed_frame_on_impl_thread_) {
1004 next_frame_is_newly_committed_frame_on_impl_thread_ = false; 1032 next_frame_is_newly_committed_frame_on_impl_thread_ = false;
1005 Proxy::MainThreadTaskRunner()->PostTask( 1033 Proxy::MainThreadTaskRunner()->PostTask(
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 texture_acquisition_completion_event_on_impl_thread_ = completion; 1105 texture_acquisition_completion_event_on_impl_thread_ = completion;
1078 scheduler_on_impl_thread_->SetMainThreadNeedsLayerTextures(); 1106 scheduler_on_impl_thread_->SetMainThreadNeedsLayerTextures();
1079 } 1107 }
1080 1108
1081 void ThreadProxy::ScheduledActionAcquireLayerTexturesForMainThread() { 1109 void ThreadProxy::ScheduledActionAcquireLayerTexturesForMainThread() {
1082 DCHECK(texture_acquisition_completion_event_on_impl_thread_); 1110 DCHECK(texture_acquisition_completion_event_on_impl_thread_);
1083 texture_acquisition_completion_event_on_impl_thread_->Signal(); 1111 texture_acquisition_completion_event_on_impl_thread_->Signal();
1084 texture_acquisition_completion_event_on_impl_thread_ = NULL; 1112 texture_acquisition_completion_event_on_impl_thread_ = NULL;
1085 } 1113 }
1086 1114
1087 ScheduledActionDrawAndSwapResult 1115 DrawSwapReadbackResult
1088 ThreadProxy::ScheduledActionDrawAndSwapIfPossible() { 1116 ThreadProxy::ScheduledActionDrawAndSwapIfPossible() {
1089 return ScheduledActionDrawAndSwapInternal(false); 1117 bool forced_draw = false;
1118 bool swap_requested = true;
1119 bool readback_requested = false;
1120 return ScheduledActionDrawSwapReadbackInternal(
1121 forced_draw, swap_requested, readback_requested);
1090 } 1122 }
1091 1123
1092 ScheduledActionDrawAndSwapResult 1124 DrawSwapReadbackResult
1093 ThreadProxy::ScheduledActionDrawAndSwapForced() { 1125 ThreadProxy::ScheduledActionDrawAndSwapForced() {
1094 return ScheduledActionDrawAndSwapInternal(true); 1126 bool forced_draw = true;
1127 bool swap_requested = true;
1128 bool readback_requested = false;
1129 return ScheduledActionDrawSwapReadbackInternal(
1130 forced_draw, swap_requested, readback_requested);
1095 } 1131 }
1096 1132
1133 DrawSwapReadbackResult
1134 ThreadProxy::ScheduledActionDrawAndReadback() {
1135 bool forced_draw = true;
1136 bool swap_requested = false;
1137 bool readback_requested = true;
1138 return ScheduledActionDrawSwapReadbackInternal(
1139 forced_draw, swap_requested, readback_requested);
1140 }
1141
1142
1097 void ThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) { 1143 void ThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) {
1098 if (current_resource_update_controller_on_impl_thread_) 1144 if (current_resource_update_controller_on_impl_thread_)
1099 current_resource_update_controller_on_impl_thread_ 1145 current_resource_update_controller_on_impl_thread_
1100 ->PerformMoreUpdates(time); 1146 ->PerformMoreUpdates(time);
1101 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame();
1102 } 1147 }
1103 1148
1104 base::TimeDelta ThreadProxy::DrawDurationEstimate() { 1149 base::TimeDelta ThreadProxy::DrawDurationEstimate() {
1105 base::TimeDelta historical_estimate = 1150 base::TimeDelta historical_estimate =
1106 draw_duration_history_.Percentile(kDrawDurationEstimationPercentile); 1151 draw_duration_history_.Percentile(kDrawDurationEstimationPercentile);
1107 base::TimeDelta padding = base::TimeDelta::FromMicroseconds( 1152 base::TimeDelta padding = base::TimeDelta::FromMicroseconds(
1108 kDrawDurationEstimatePaddingInMicroseconds); 1153 kDrawDurationEstimatePaddingInMicroseconds);
1109 return historical_estimate + padding; 1154 return historical_estimate + padding;
1110 } 1155 }
1111 1156
1112 base::TimeDelta ThreadProxy::BeginFrameToCommitDurationEstimate() { 1157 base::TimeDelta ThreadProxy::BeginFrameToCommitDurationEstimate() {
1113 return begin_frame_to_commit_duration_history_.Percentile( 1158 return begin_frame_to_commit_duration_history_.Percentile(
1114 kCommitAndActivationDurationEstimationPercentile); 1159 kCommitAndActivationDurationEstimationPercentile);
1115 } 1160 }
1116 1161
1117 base::TimeDelta ThreadProxy::CommitToActivateDurationEstimate() { 1162 base::TimeDelta ThreadProxy::CommitToActivateDurationEstimate() {
1118 return commit_to_activate_duration_history_.Percentile( 1163 return commit_to_activate_duration_history_.Percentile(
1119 kCommitAndActivationDurationEstimationPercentile); 1164 kCommitAndActivationDurationEstimationPercentile);
1120 } 1165 }
1121 1166
1167 void ThreadProxy::PostBeginFrameDeadline(const base::Closure &closure,
1168 base::TimeTicks deadline) {
1169 base::TimeDelta delta = deadline - base::TimeTicks::Now();
1170 if (delta <= base::TimeDelta())
1171 delta = base::TimeDelta();
1172 Proxy::ImplThreadTaskRunner()->PostDelayedTask(FROM_HERE, closure, delta);
1173 }
1174
1122 void ThreadProxy::ReadyToFinalizeTextureUpdates() { 1175 void ThreadProxy::ReadyToFinalizeTextureUpdates() {
1123 DCHECK(IsImplThread()); 1176 DCHECK(IsImplThread());
1124 scheduler_on_impl_thread_->FinishCommit(); 1177 scheduler_on_impl_thread_->FinishCommit();
1125 } 1178 }
1126 1179
1127 void ThreadProxy::DidCommitAndDrawFrame() { 1180 void ThreadProxy::DidCommitAndDrawFrame() {
1128 DCHECK(IsMainThread()); 1181 DCHECK(IsMainThread());
1129 if (!layer_tree_host_) 1182 if (!layer_tree_host_)
1130 return; 1183 return;
1131 layer_tree_host_->DidCommitAndDrawFrame(); 1184 layer_tree_host_->DidCommitAndDrawFrame();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this); 1242 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this);
1190 const LayerTreeSettings& settings = layer_tree_host_->settings(); 1243 const LayerTreeSettings& settings = layer_tree_host_->settings();
1191 SchedulerSettings scheduler_settings; 1244 SchedulerSettings scheduler_settings;
1192 scheduler_settings.impl_side_painting = settings.impl_side_painting; 1245 scheduler_settings.impl_side_painting = settings.impl_side_painting;
1193 scheduler_settings.timeout_and_draw_when_animation_checkerboards = 1246 scheduler_settings.timeout_and_draw_when_animation_checkerboards =
1194 settings.timeout_and_draw_when_animation_checkerboards; 1247 settings.timeout_and_draw_when_animation_checkerboards;
1195 scheduler_settings.using_synchronous_renderer_compositor = 1248 scheduler_settings.using_synchronous_renderer_compositor =
1196 settings.using_synchronous_renderer_compositor; 1249 settings.using_synchronous_renderer_compositor;
1197 scheduler_settings.throttle_frame_production = 1250 scheduler_settings.throttle_frame_production =
1198 settings.throttle_frame_production; 1251 settings.throttle_frame_production;
1252 scheduler_settings.use_begin_frame_workaround_for_crbug_249806 = true;
1199 scheduler_on_impl_thread_ = Scheduler::Create(this, scheduler_settings); 1253 scheduler_on_impl_thread_ = Scheduler::Create(this, scheduler_settings);
1200 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); 1254 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible());
1201 1255
1202 impl_thread_weak_ptr_ = weak_factory_on_impl_thread_.GetWeakPtr(); 1256 impl_thread_weak_ptr_ = weak_factory_on_impl_thread_.GetWeakPtr();
1203 completion->Signal(); 1257 completion->Signal();
1204 } 1258 }
1205 1259
1206 void ThreadProxy::InitializeOutputSurfaceOnImplThread( 1260 void ThreadProxy::InitializeOutputSurfaceOnImplThread(
1207 CompletionEvent* completion, 1261 CompletionEvent* completion,
1208 scoped_ptr<OutputSurface> output_surface, 1262 scoped_ptr<OutputSurface> output_surface,
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1436 DCHECK(layer_tree_host_impl_->settings().impl_side_painting); 1490 DCHECK(layer_tree_host_impl_->settings().impl_side_painting);
1437 completion_event_for_commit_held_on_tree_activation_->Signal(); 1491 completion_event_for_commit_held_on_tree_activation_->Signal();
1438 completion_event_for_commit_held_on_tree_activation_ = NULL; 1492 completion_event_for_commit_held_on_tree_activation_ = NULL;
1439 } 1493 }
1440 1494
1441 commit_to_activate_duration_history_.InsertSample( 1495 commit_to_activate_duration_history_.InsertSample(
1442 base::TimeTicks::HighResNow() - commit_complete_time_); 1496 base::TimeTicks::HighResNow() - commit_complete_time_);
1443 } 1497 }
1444 1498
1445 } // namespace cc 1499 } // namespace cc
OLDNEW
« cc/scheduler/scheduler_state_machine.h ('K') | « cc/trees/thread_proxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698