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

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: Another round of cleanup Created 7 years, 4 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
« cc/trees/layer_tree_impl.cc ('K') | « cc/trees/thread_proxy.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 22 matching lines...) Expand all
112 TRACE_EVENT0("cc", "ThreadProxy::CompositeAndReadback"); 113 TRACE_EVENT0("cc", "ThreadProxy::CompositeAndReadback");
113 DCHECK(IsMainThread()); 114 DCHECK(IsMainThread());
114 DCHECK(layer_tree_host_); 115 DCHECK(layer_tree_host_);
115 DCHECK(!defer_commits_); 116 DCHECK(!defer_commits_);
116 117
117 if (!layer_tree_host_->InitializeOutputSurfaceIfNeeded()) { 118 if (!layer_tree_host_->InitializeOutputSurfaceIfNeeded()) {
118 TRACE_EVENT0("cc", "CompositeAndReadback_EarlyOut_LR_Uninitialized"); 119 TRACE_EVENT0("cc", "CompositeAndReadback_EarlyOut_LR_Uninitialized");
119 return false; 120 return false;
120 } 121 }
121 122
122 // Perform a synchronous commit. 123 // Perform a synchronous commit with an associated readback.
124 ReadbackRequest request;
125 request.rect = rect;
126 request.pixels = pixels;
123 { 127 {
124 DebugScopedSetMainThreadBlocked main_thread_blocked(this); 128 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
125 CompletionEvent begin_frame_sent_to_main_thread_completion; 129 CompletionEvent begin_frame_sent_to_main_thread_completion;
126 Proxy::ImplThreadTaskRunner()->PostTask( 130 Proxy::ImplThreadTaskRunner()->PostTask(
127 FROM_HERE, 131 FROM_HERE,
128 base::Bind(&ThreadProxy::ForceCommitOnImplThread, 132 base::Bind(&ThreadProxy::ForceCommitForReadbackOnImplThread,
129 impl_thread_weak_ptr_, 133 impl_thread_weak_ptr_,
130 &begin_frame_sent_to_main_thread_completion)); 134 &begin_frame_sent_to_main_thread_completion,
135 &request));
131 begin_frame_sent_to_main_thread_completion.Wait(); 136 begin_frame_sent_to_main_thread_completion.Wait();
132 } 137 }
133 138
134 in_composite_and_readback_ = true; 139 in_composite_and_readback_ = true;
140 // This is the forced commit.
141 // Note: The Impl thread also queues a separate BeginFrameOnMainThread on the
142 // main thread, which will be called after this CompositeAndReadback
143 // completes, to replace the forced commit.
135 BeginFrameOnMainThread(scoped_ptr<BeginFrameAndCommitState>()); 144 BeginFrameOnMainThread(scoped_ptr<BeginFrameAndCommitState>());
136 in_composite_and_readback_ = false; 145 in_composite_and_readback_ = false;
137 146
138 // Composite and readback requires a second commit to undo any changes 147 // Composite and readback requires a second commit to undo any changes
139 // that it made. 148 // that it made.
140 can_cancel_commit_ = false; 149 can_cancel_commit_ = false;
141 150
142 // Perform a synchronous readback. 151 request.completion.Wait();
143 ReadbackRequest request;
144 request.rect = rect;
145 request.pixels = pixels;
146 {
147 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
148 Proxy::ImplThreadTaskRunner()->PostTask(
149 FROM_HERE,
150 base::Bind(&ThreadProxy::RequestReadbackOnImplThread,
151 impl_thread_weak_ptr_,
152 &request));
153 request.completion.Wait();
154 }
155 return request.success; 152 return request.success;
156 } 153 }
157 154
158 void ThreadProxy::ForceCommitOnImplThread(CompletionEvent* completion) { 155 void ThreadProxy::ForceCommitForReadbackOnImplThread(
159 TRACE_EVENT0("cc", "ThreadProxy::ForceCommitOnImplThread"); 156 CompletionEvent* begin_frame_sent_completion,
157 ReadbackRequest* request) {
158 TRACE_EVENT0("cc", "ThreadProxy::ForceCommitForReadbackOnImplThread");
160 DCHECK(IsImplThread()); 159 DCHECK(IsImplThread());
161 DCHECK(!begin_frame_sent_to_main_thread_completion_event_on_impl_thread_); 160 DCHECK(!begin_frame_sent_to_main_thread_completion_event_on_impl_thread_);
161 DCHECK(!readback_request_on_impl_thread_);
162 162
163 scheduler_on_impl_thread_->SetNeedsForcedCommit();
164 if (scheduler_on_impl_thread_->CommitPending()) {
165 completion->Signal();
166 return;
167 }
168
169 begin_frame_sent_to_main_thread_completion_event_on_impl_thread_ = completion;
170 }
171
172 void ThreadProxy::RequestReadbackOnImplThread(ReadbackRequest* request) {
173 DCHECK(Proxy::IsImplThread());
174 DCHECK(!readback_request_on_impl_thread_);
175 if (!layer_tree_host_impl_) { 163 if (!layer_tree_host_impl_) {
164 begin_frame_sent_completion->Signal();
176 request->success = false; 165 request->success = false;
177 request->completion.Signal(); 166 request->completion.Signal();
178 return; 167 return;
179 } 168 }
180 169
181 readback_request_on_impl_thread_ = request; 170 readback_request_on_impl_thread_ = request;
182 scheduler_on_impl_thread_->SetNeedsRedraw(); 171
183 scheduler_on_impl_thread_->SetNeedsForcedRedraw(); 172 scheduler_on_impl_thread_->SetNeedsForcedCommitForReadback();
173 if (scheduler_on_impl_thread_->CommitPending()) {
174 begin_frame_sent_completion->Signal();
175 return;
176 }
177
178 begin_frame_sent_to_main_thread_completion_event_on_impl_thread_ =
179 begin_frame_sent_completion;
184 } 180 }
185 181
186 void ThreadProxy::FinishAllRendering() { 182 void ThreadProxy::FinishAllRendering() {
187 DCHECK(Proxy::IsMainThread()); 183 DCHECK(Proxy::IsMainThread());
188 DCHECK(!defer_commits_); 184 DCHECK(!defer_commits_);
189 185
190 // Make sure all GL drawing is finished on the impl thread. 186 // Make sure all GL drawing is finished on the impl thread.
191 DebugScopedSetMainThreadBlocked main_thread_blocked(this); 187 DebugScopedSetMainThreadBlocked main_thread_blocked(this);
192 CompletionEvent completion; 188 CompletionEvent completion;
193 Proxy::ImplThreadTaskRunner()->PostTask( 189 Proxy::ImplThreadTaskRunner()->PostTask(
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 Proxy::MainThreadTaskRunner()->PostTask( 376 Proxy::MainThreadTaskRunner()->PostTask(
381 FROM_HERE, 377 FROM_HERE,
382 base::Bind(&ThreadProxy::DidCompleteSwapBuffers, main_thread_weak_ptr_)); 378 base::Bind(&ThreadProxy::DidCompleteSwapBuffers, main_thread_weak_ptr_));
383 } 379 }
384 380
385 void ThreadProxy::SetNeedsBeginFrameOnImplThread(bool enable) { 381 void ThreadProxy::SetNeedsBeginFrameOnImplThread(bool enable) {
386 DCHECK(IsImplThread()); 382 DCHECK(IsImplThread());
387 TRACE_EVENT1("cc", "ThreadProxy::SetNeedsBeginFrameOnImplThread", 383 TRACE_EVENT1("cc", "ThreadProxy::SetNeedsBeginFrameOnImplThread",
388 "enable", enable); 384 "enable", enable);
389 layer_tree_host_impl_->SetNeedsBeginFrame(enable); 385 layer_tree_host_impl_->SetNeedsBeginFrame(enable);
386 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(!enable);
390 } 387 }
391 388
392 void ThreadProxy::BeginFrameOnImplThread(const BeginFrameArgs& args) { 389 void ThreadProxy::BeginFrameOnImplThread(const BeginFrameArgs& args) {
393 DCHECK(IsImplThread()); 390 DCHECK(IsImplThread());
394 TRACE_EVENT0("cc", "ThreadProxy::BeginFrameOnImplThread"); 391 TRACE_EVENT0("cc", "ThreadProxy::BeginFrameOnImplThread");
392
393 base::TimeTicks monotonic_time =
394 layer_tree_host_impl_->CurrentFrameTimeTicks();
395 base::Time wall_clock_time = layer_tree_host_impl_->CurrentFrameTime();
396 layer_tree_host_impl_->Animate(monotonic_time, wall_clock_time);
397
398 // Reinitialize for the current frame.
399 frame_did_draw_ = false;
400
395 scheduler_on_impl_thread_->BeginFrame(args); 401 scheduler_on_impl_thread_->BeginFrame(args);
396 } 402 }
397 403
404 void ThreadProxy::DidBeginFrameDeadlineOnImplThread() {
405 // Do not start animations if we skip drawing the frame to avoid
406 // checkerboarding.
407 layer_tree_host_impl_->UpdateAnimationState(
408 frame_did_draw_ || !layer_tree_host_impl_->CanDraw());
409 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame();
410 }
411
398 void ThreadProxy::OnCanDrawStateChanged(bool can_draw) { 412 void ThreadProxy::OnCanDrawStateChanged(bool can_draw) {
399 DCHECK(IsImplThread()); 413 DCHECK(IsImplThread());
400 TRACE_EVENT1( 414 TRACE_EVENT1(
401 "cc", "ThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); 415 "cc", "ThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw);
402 scheduler_on_impl_thread_->SetCanDraw(can_draw); 416 scheduler_on_impl_thread_->SetCanDraw(can_draw);
403 layer_tree_host_impl_->UpdateBackgroundAnimateTicking( 417 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(
404 !scheduler_on_impl_thread_->WillDrawIfNeeded()); 418 !scheduler_on_impl_thread_->WillDrawIfNeeded());
405 } 419 }
406 420
421 void ThreadProxy::NotifyReadyToActivate() {
422 TRACE_EVENT0("cc", "ThreadProxy::NotifyReadyToActivate");
423 scheduler_on_impl_thread_->NotifyReadyToActivate();
424 }
425
407 void ThreadProxy::OnHasPendingTreeStateChanged(bool has_pending_tree) { 426 void ThreadProxy::OnHasPendingTreeStateChanged(bool has_pending_tree) {
408 DCHECK(IsImplThread()); 427 DCHECK(IsImplThread());
409 TRACE_EVENT1("cc", "ThreadProxy::OnHasPendingTreeStateChanged", 428 TRACE_EVENT1("cc", "ThreadProxy::OnHasPendingTreeStateChanged",
410 "has_pending_tree", has_pending_tree); 429 "has_pending_tree", has_pending_tree);
411 scheduler_on_impl_thread_->SetHasPendingTree(has_pending_tree); 430 scheduler_on_impl_thread_->SetHasTrees(
431 has_pending_tree,
432 layer_tree_host_impl_->active_tree() ?
433 !layer_tree_host_impl_->active_tree()->root_layer() : true);
412 } 434 }
413 435
414 void ThreadProxy::SetNeedsCommitOnImplThread() { 436 void ThreadProxy::SetNeedsCommitOnImplThread() {
415 DCHECK(IsImplThread()); 437 DCHECK(IsImplThread());
416 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsCommitOnImplThread"); 438 TRACE_EVENT0("cc", "ThreadProxy::SetNeedsCommitOnImplThread");
417 scheduler_on_impl_thread_->SetNeedsCommit(); 439 scheduler_on_impl_thread_->SetNeedsCommit();
418 } 440 }
419 441
420 void ThreadProxy::PostAnimationEventsToMainThreadOnImplThread( 442 void ThreadProxy::PostAnimationEventsToMainThreadOnImplThread(
421 scoped_ptr<AnimationEventsVector> events, 443 scoped_ptr<AnimationEventsVector> events,
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 TRACE_EVENT0("cc", "ThreadProxy::FinishAllRenderingOnImplThread"); 677 TRACE_EVENT0("cc", "ThreadProxy::FinishAllRenderingOnImplThread");
656 DCHECK(IsImplThread()); 678 DCHECK(IsImplThread());
657 layer_tree_host_impl_->FinishAllRendering(); 679 layer_tree_host_impl_->FinishAllRendering();
658 completion->Signal(); 680 completion->Signal();
659 } 681 }
660 682
661 void ThreadProxy::ScheduledActionSendBeginFrameToMainThread() { 683 void ThreadProxy::ScheduledActionSendBeginFrameToMainThread() {
662 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionSendBeginFrameToMainThread"); 684 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionSendBeginFrameToMainThread");
663 scoped_ptr<BeginFrameAndCommitState> begin_frame_state( 685 scoped_ptr<BeginFrameAndCommitState> begin_frame_state(
664 new BeginFrameAndCommitState); 686 new BeginFrameAndCommitState);
687
665 begin_frame_state->monotonic_frame_begin_time = 688 begin_frame_state->monotonic_frame_begin_time =
666 layer_tree_host_impl_->CurrentPhysicalTimeTicks(); 689 layer_tree_host_impl_->CurrentPhysicalTimeTicks();
667 begin_frame_state->scroll_info = 690 begin_frame_state->scroll_info =
668 layer_tree_host_impl_->ProcessScrollDeltas(); 691 layer_tree_host_impl_->ProcessScrollDeltas();
669 692
670 if (!layer_tree_host_impl_->settings().impl_side_painting) { 693 if (!layer_tree_host_impl_->settings().impl_side_painting) {
671 DCHECK_GT(layer_tree_host_impl_->memory_allocation_limit_bytes(), 0u); 694 DCHECK_GT(layer_tree_host_impl_->memory_allocation_limit_bytes(), 0u);
672 } 695 }
696
697
673 begin_frame_state->memory_allocation_limit_bytes = 698 begin_frame_state->memory_allocation_limit_bytes =
674 layer_tree_host_impl_->memory_allocation_limit_bytes(); 699 layer_tree_host_impl_->memory_allocation_limit_bytes();
675 Proxy::MainThreadTaskRunner()->PostTask( 700 Proxy::MainThreadTaskRunner()->PostTask(
676 FROM_HERE, 701 FROM_HERE,
677 base::Bind(&ThreadProxy::BeginFrameOnMainThread, 702 base::Bind(&ThreadProxy::BeginFrameOnMainThread,
678 main_thread_weak_ptr_, 703 main_thread_weak_ptr_,
679 base::Passed(&begin_frame_state))); 704 base::Passed(&begin_frame_state)));
680 705
681 if (begin_frame_sent_to_main_thread_completion_event_on_impl_thread_) { 706 if (begin_frame_sent_to_main_thread_completion_event_on_impl_thread_) {
682 begin_frame_sent_to_main_thread_completion_event_on_impl_thread_->Signal(); 707 begin_frame_sent_to_main_thread_completion_event_on_impl_thread_->Signal();
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 } 858 }
834 859
835 layer_tree_host_->CommitComplete(); 860 layer_tree_host_->CommitComplete();
836 layer_tree_host_->DidBeginFrame(); 861 layer_tree_host_->DidBeginFrame();
837 } 862 }
838 863
839 void ThreadProxy::StartCommitOnImplThread( 864 void ThreadProxy::StartCommitOnImplThread(
840 CompletionEvent* completion, 865 CompletionEvent* completion,
841 ResourceUpdateQueue* raw_queue, 866 ResourceUpdateQueue* raw_queue,
842 scoped_refptr<cc::ContextProvider> offscreen_context_provider) { 867 scoped_refptr<cc::ContextProvider> offscreen_context_provider) {
843 scoped_ptr<ResourceUpdateQueue> queue(raw_queue);
844
845 TRACE_EVENT0("cc", "ThreadProxy::StartCommitOnImplThread"); 868 TRACE_EVENT0("cc", "ThreadProxy::StartCommitOnImplThread");
846 DCHECK(!commit_completion_event_on_impl_thread_); 869 DCHECK(!commit_completion_event_on_impl_thread_);
847 DCHECK(IsImplThread() && IsMainThreadBlocked()); 870 DCHECK(IsImplThread() && IsMainThreadBlocked());
848 DCHECK(scheduler_on_impl_thread_); 871 DCHECK(scheduler_on_impl_thread_);
849 DCHECK(scheduler_on_impl_thread_->CommitPending()); 872 DCHECK(scheduler_on_impl_thread_->CommitPending());
850 873
851 if (!layer_tree_host_impl_) { 874 if (!layer_tree_host_impl_) {
852 TRACE_EVENT0("cc", "EarlyOut_NoLayerTree"); 875 TRACE_EVENT0("cc", "EarlyOut_NoLayerTree");
853 completion->Signal(); 876 completion->Signal();
877
854 return; 878 return;
855 } 879 }
856 880
881 scoped_ptr<ResourceUpdateQueue> queue(raw_queue);
882
857 if (offscreen_context_provider.get()) 883 if (offscreen_context_provider.get())
858 offscreen_context_provider->BindToCurrentThread(); 884 offscreen_context_provider->BindToCurrentThread();
859 layer_tree_host_impl_->resource_provider()-> 885 layer_tree_host_impl_->resource_provider()->
860 set_offscreen_context_provider(offscreen_context_provider); 886 set_offscreen_context_provider(offscreen_context_provider);
861 887
862 if (layer_tree_host_->contents_texture_manager()) { 888 if (layer_tree_host_->contents_texture_manager()) {
863 if (layer_tree_host_->contents_texture_manager()-> 889 if (layer_tree_host_->contents_texture_manager()->
864 LinkedEvictedBackingsExist()) { 890 LinkedEvictedBackingsExist()) {
865 // Clear any uploads we were making to textures linked to evicted 891 // Clear any uploads we were making to textures linked to evicted
866 // resources 892 // resources
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 current_resource_update_controller_on_impl_thread_->Finalize(); 938 current_resource_update_controller_on_impl_thread_->Finalize();
913 current_resource_update_controller_on_impl_thread_.reset(); 939 current_resource_update_controller_on_impl_thread_.reset();
914 940
915 layer_tree_host_impl_->BeginCommit(); 941 layer_tree_host_impl_->BeginCommit();
916 layer_tree_host_->BeginCommitOnImplThread(layer_tree_host_impl_.get()); 942 layer_tree_host_->BeginCommitOnImplThread(layer_tree_host_impl_.get());
917 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get()); 943 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get());
918 layer_tree_host_impl_->CommitComplete(); 944 layer_tree_host_impl_->CommitComplete();
919 945
920 SetInputThrottledUntilCommitOnImplThread(false); 946 SetInputThrottledUntilCommitOnImplThread(false);
921 947
922 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(
923 !scheduler_on_impl_thread_->WillDrawIfNeeded());
924
925 next_frame_is_newly_committed_frame_on_impl_thread_ = true; 948 next_frame_is_newly_committed_frame_on_impl_thread_ = true;
926 949
927 if (layer_tree_host_->settings().impl_side_painting && 950 if (layer_tree_host_->settings().impl_side_painting &&
928 layer_tree_host_->BlocksPendingCommit() && 951 layer_tree_host_->BlocksPendingCommit() &&
929 layer_tree_host_impl_->pending_tree()) { 952 layer_tree_host_impl_->pending_tree()) {
930 // For some layer types in impl-side painting, the commit is held until 953 // For some layer types in impl-side painting, the commit is held until
931 // the pending tree is activated. It's also possible that the 954 // the pending tree is activated. It's also possible that the
932 // pending tree has already activated if there was no work to be done. 955 // pending tree has already activated if there was no work to be done.
933 TRACE_EVENT_INSTANT0("cc", "HoldCommit", TRACE_EVENT_SCOPE_THREAD); 956 TRACE_EVENT_INSTANT0("cc", "HoldCommit", TRACE_EVENT_SCOPE_THREAD);
934 completion_event_for_commit_held_on_tree_activation_ = 957 completion_event_for_commit_held_on_tree_activation_ =
935 commit_completion_event_on_impl_thread_; 958 commit_completion_event_on_impl_thread_;
936 commit_completion_event_on_impl_thread_ = NULL; 959 commit_completion_event_on_impl_thread_ = NULL;
937 } else { 960 } else {
938 commit_completion_event_on_impl_thread_->Signal(); 961 commit_completion_event_on_impl_thread_->Signal();
939 commit_completion_event_on_impl_thread_ = NULL; 962 commit_completion_event_on_impl_thread_ = NULL;
940 } 963 }
941 964
942 commit_complete_time_ = base::TimeTicks::HighResNow(); 965 commit_complete_time_ = base::TimeTicks::HighResNow();
943 begin_frame_to_commit_duration_history_.InsertSample( 966 begin_frame_to_commit_duration_history_.InsertSample(
944 commit_complete_time_ - begin_frame_sent_to_main_thread_time_); 967 commit_complete_time_ - begin_frame_sent_to_main_thread_time_);
945 968
969 // The commit may have added animations, requiring us to start
970 // background ticking.
971 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(
972 !scheduler_on_impl_thread_->WillDrawIfNeeded());
946 // SetVisible kicks off the next scheduler action, so this must be last. 973 // SetVisible kicks off the next scheduler action, so this must be last.
947 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); 974 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible());
948 } 975 }
949 976
950 void ThreadProxy::ScheduledActionUpdateVisibleTiles() { 977 void ThreadProxy::ScheduledActionUpdateVisibleTiles() {
951 DCHECK(IsImplThread()); 978 DCHECK(IsImplThread());
952 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionUpdateVisibleTiles"); 979 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionUpdateVisibleTiles");
953 layer_tree_host_impl_->UpdateVisibleTiles(); 980 layer_tree_host_impl_->UpdateVisibleTiles();
954 } 981 }
955 982
956 void ThreadProxy::ScheduledActionActivatePendingTreeIfNeeded() { 983 void ThreadProxy::ScheduledActionActivatePendingTree() {
957 DCHECK(IsImplThread()); 984 DCHECK(IsImplThread());
958 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionActivatePendingTreeIfNeeded"); 985 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionActivatePendingTree");
959 layer_tree_host_impl_->ActivatePendingTreeIfNeeded(); 986 layer_tree_host_impl_->ActivatePendingTree();
960 } 987 }
961 988
962 void ThreadProxy::ScheduledActionBeginOutputSurfaceCreation() { 989 void ThreadProxy::ScheduledActionBeginOutputSurfaceCreation() {
963 DCHECK(IsImplThread()); 990 DCHECK(IsImplThread());
964 Proxy::MainThreadTaskRunner()->PostTask( 991 Proxy::MainThreadTaskRunner()->PostTask(
965 FROM_HERE, 992 FROM_HERE,
966 base::Bind(&ThreadProxy::CreateAndInitializeOutputSurface, 993 base::Bind(&ThreadProxy::CreateAndInitializeOutputSurface,
967 main_thread_weak_ptr_)); 994 main_thread_weak_ptr_));
968 } 995 }
969 996
970 ScheduledActionDrawAndSwapResult 997 DrawSwapReadbackResult
971 ThreadProxy::ScheduledActionDrawAndSwapInternal(bool forced_draw) { 998 ThreadProxy::ScheduledActionDrawSwapReadbackInternal(
972 TRACE_EVENT1( 999 bool forced_draw, bool swap_requested, bool readback_requested) {
973 "cc", "ThreadProxy::ScheduledActionDrawAndSwap", "forced", forced_draw); 1000 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawSwapReadback");
974 1001
975 ScheduledActionDrawAndSwapResult result; 1002 DrawSwapReadbackResult result;
976 result.did_draw = false; 1003 result.did_draw = false;
977 result.did_swap = false; 1004 result.did_swap = false;
978 DCHECK(IsImplThread()); 1005 DCHECK(IsImplThread());
979 DCHECK(layer_tree_host_impl_.get()); 1006 DCHECK(layer_tree_host_impl_.get());
980 if (!layer_tree_host_impl_) 1007 if (!layer_tree_host_impl_)
981 return result; 1008 return result;
982 1009
983 DCHECK(layer_tree_host_impl_->renderer()); 1010 DCHECK(layer_tree_host_impl_->renderer());
984 if (!layer_tree_host_impl_->renderer()) 1011 if (!layer_tree_host_impl_->renderer())
985 return result; 1012 return result;
986 1013
987 base::TimeTicks monotonic_time =
988 layer_tree_host_impl_->CurrentFrameTimeTicks();
989 base::Time wall_clock_time = layer_tree_host_impl_->CurrentFrameTime();
990
991 // TODO(enne): This should probably happen post-animate.
992 if (layer_tree_host_impl_->pending_tree()) {
993 layer_tree_host_impl_->ActivatePendingTreeIfNeeded();
994 if (layer_tree_host_impl_->pending_tree())
995 layer_tree_host_impl_->pending_tree()->UpdateDrawProperties();
996 }
997 layer_tree_host_impl_->Animate(monotonic_time, wall_clock_time);
998 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(false);
999
1000 base::TimeTicks start_time = base::TimeTicks::HighResNow(); 1014 base::TimeTicks start_time = base::TimeTicks::HighResNow();
1001 base::TimeDelta draw_duration_estimate = DrawDurationEstimate(); 1015 base::TimeDelta draw_duration_estimate = DrawDurationEstimate();
1002 base::AutoReset<bool> mark_inside(&inside_draw_, true); 1016 base::AutoReset<bool> mark_inside(&inside_draw_, true);
1003 1017
1004 // This method is called on a forced draw, regardless of whether we are able 1018 // This method is called on a forced draw, regardless of whether we are able
1005 // to produce a frame, as the calling site on main thread is blocked until its 1019 // to produce a frame, as the calling site on main thread is blocked until its
1006 // request completes, and we signal completion here. If CanDraw() is false, we 1020 // request completes, and we signal completion here. If CanDraw() is false, we
1007 // will indicate success=false to the caller, but we must still signal 1021 // will indicate success=false to the caller, but we must still signal
1008 // completion to avoid deadlock. 1022 // completion to avoid deadlock.
1009 1023
1010 // We guard PrepareToDraw() with CanDraw() because it always returns a valid 1024 // We guard PrepareToDraw() with CanDraw() because it always returns a valid
1011 // frame, so can only be used when such a frame is possible. Since 1025 // frame, so can only be used when such a frame is possible. Since
1012 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on 1026 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on
1013 // CanDraw() as well. 1027 // CanDraw() as well.
1014 1028
1015 bool drawing_for_readback = !!readback_request_on_impl_thread_; 1029 bool drawing_for_readback =
1030 readback_requested && !!readback_request_on_impl_thread_;
1016 bool can_do_readback = layer_tree_host_impl_->renderer()->CanReadPixels(); 1031 bool can_do_readback = layer_tree_host_impl_->renderer()->CanReadPixels();
1017 1032
1018 LayerTreeHostImpl::FrameData frame; 1033 LayerTreeHostImpl::FrameData frame;
1019 bool draw_frame = false; 1034 bool draw_frame = false;
1020 bool start_ready_animations = true;
1021 1035
1022 if (layer_tree_host_impl_->CanDraw() && 1036 if (layer_tree_host_impl_->CanDraw() &&
1023 (!drawing_for_readback || can_do_readback)) { 1037 (!drawing_for_readback || can_do_readback)) {
1024 // If it is for a readback, make sure we draw the portion being read back. 1038 // If it is for a readback, make sure we draw the portion being read back.
1025 gfx::Rect readback_rect; 1039 gfx::Rect readback_rect;
1026 if (drawing_for_readback) 1040 if (drawing_for_readback)
1027 readback_rect = readback_request_on_impl_thread_->rect; 1041 readback_rect = readback_request_on_impl_thread_->rect;
1028 1042
1029 // Do not start animations if we skip drawing the frame to avoid
1030 // checkerboarding.
1031 if (layer_tree_host_impl_->PrepareToDraw(&frame, readback_rect) || 1043 if (layer_tree_host_impl_->PrepareToDraw(&frame, readback_rect) ||
1032 forced_draw) 1044 forced_draw)
1033 draw_frame = true; 1045 draw_frame = true;
1034 else
1035 start_ready_animations = false;
1036 } 1046 }
1037 1047
1048 frame_did_draw_ = draw_frame;
1049
1038 if (draw_frame) { 1050 if (draw_frame) {
1039 layer_tree_host_impl_->DrawLayers( 1051 layer_tree_host_impl_->DrawLayers(
1040 &frame, 1052 &frame,
1041 scheduler_on_impl_thread_->LastBeginFrameOnImplThreadTime()); 1053 scheduler_on_impl_thread_->LastBeginFrameOnImplThreadTime());
1042 result.did_draw = true; 1054 result.did_draw = true;
1043 } 1055 }
1044 layer_tree_host_impl_->DidDrawAllLayers(frame); 1056 layer_tree_host_impl_->DidDrawAllLayers(frame);
1045 1057
1046 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations);
1047
1048 // Check for a pending CompositeAndReadback. 1058 // Check for a pending CompositeAndReadback.
1049 if (readback_request_on_impl_thread_) { 1059 if (drawing_for_readback) {
1050 readback_request_on_impl_thread_->success = false; 1060 result.did_readback = false;
1051 if (draw_frame) { 1061 if (draw_frame) {
1052 layer_tree_host_impl_->Readback(readback_request_on_impl_thread_->pixels, 1062 layer_tree_host_impl_->Readback(readback_request_on_impl_thread_->pixels,
1053 readback_request_on_impl_thread_->rect); 1063 readback_request_on_impl_thread_->rect);
1054 readback_request_on_impl_thread_->success = 1064 result.did_readback =
1055 !layer_tree_host_impl_->IsContextLost(); 1065 !layer_tree_host_impl_->IsContextLost();
1056 } 1066 }
1067 readback_request_on_impl_thread_->success = result.did_readback;
1057 readback_request_on_impl_thread_->completion.Signal(); 1068 readback_request_on_impl_thread_->completion.Signal();
1058 readback_request_on_impl_thread_ = NULL; 1069 readback_request_on_impl_thread_ = NULL;
1059 } else if (draw_frame) { 1070 } else if (draw_frame && swap_requested) {
1060 result.did_swap = layer_tree_host_impl_->SwapBuffers(frame); 1071 result.did_swap = layer_tree_host_impl_->SwapBuffers(frame);
1061 1072
1062 if (frame.contains_incomplete_tile) 1073 if (frame.contains_incomplete_tile)
1063 DidSwapUseIncompleteTileOnImplThread(); 1074 DidSwapUseIncompleteTileOnImplThread();
1064 } 1075 }
1065 1076
1066 // Tell the main thread that the the newly-commited frame was drawn. 1077 // Tell the main thread that the the newly-commited frame was drawn.
1067 if (next_frame_is_newly_committed_frame_on_impl_thread_) { 1078 if (next_frame_is_newly_committed_frame_on_impl_thread_) {
1068 next_frame_is_newly_committed_frame_on_impl_thread_ = false; 1079 next_frame_is_newly_committed_frame_on_impl_thread_ = false;
1069 Proxy::MainThreadTaskRunner()->PostTask( 1080 Proxy::MainThreadTaskRunner()->PostTask(
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 texture_acquisition_completion_event_on_impl_thread_ = completion; 1153 texture_acquisition_completion_event_on_impl_thread_ = completion;
1143 scheduler_on_impl_thread_->SetMainThreadNeedsLayerTextures(); 1154 scheduler_on_impl_thread_->SetMainThreadNeedsLayerTextures();
1144 } 1155 }
1145 1156
1146 void ThreadProxy::ScheduledActionAcquireLayerTexturesForMainThread() { 1157 void ThreadProxy::ScheduledActionAcquireLayerTexturesForMainThread() {
1147 DCHECK(texture_acquisition_completion_event_on_impl_thread_); 1158 DCHECK(texture_acquisition_completion_event_on_impl_thread_);
1148 texture_acquisition_completion_event_on_impl_thread_->Signal(); 1159 texture_acquisition_completion_event_on_impl_thread_->Signal();
1149 texture_acquisition_completion_event_on_impl_thread_ = NULL; 1160 texture_acquisition_completion_event_on_impl_thread_ = NULL;
1150 } 1161 }
1151 1162
1152 ScheduledActionDrawAndSwapResult 1163 DrawSwapReadbackResult
1153 ThreadProxy::ScheduledActionDrawAndSwapIfPossible() { 1164 ThreadProxy::ScheduledActionDrawAndSwapIfPossible() {
1154 return ScheduledActionDrawAndSwapInternal(false); 1165 bool forced_draw = false;
1166 bool swap_requested = true;
1167 bool readback_requested = false;
1168 return ScheduledActionDrawSwapReadbackInternal(
1169 forced_draw, swap_requested, readback_requested);
1155 } 1170 }
1156 1171
1157 ScheduledActionDrawAndSwapResult 1172 DrawSwapReadbackResult
1158 ThreadProxy::ScheduledActionDrawAndSwapForced() { 1173 ThreadProxy::ScheduledActionDrawAndSwapForced() {
1159 return ScheduledActionDrawAndSwapInternal(true); 1174 bool forced_draw = true;
1175 bool swap_requested = true;
1176 bool readback_requested = false;
1177 return ScheduledActionDrawSwapReadbackInternal(
1178 forced_draw, swap_requested, readback_requested);
1160 } 1179 }
1161 1180
1181 DrawSwapReadbackResult
1182 ThreadProxy::ScheduledActionDrawAndReadback() {
1183 bool forced_draw = true;
1184 bool swap_requested = false;
1185 bool readback_requested = true;
1186 return ScheduledActionDrawSwapReadbackInternal(
1187 forced_draw, swap_requested, readback_requested);
1188 }
1189
1190
1162 void ThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) { 1191 void ThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) {
1163 if (current_resource_update_controller_on_impl_thread_) 1192 if (current_resource_update_controller_on_impl_thread_)
1164 current_resource_update_controller_on_impl_thread_ 1193 current_resource_update_controller_on_impl_thread_
1165 ->PerformMoreUpdates(time); 1194 ->PerformMoreUpdates(time);
1166 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame();
1167 } 1195 }
1168 1196
1169 base::TimeDelta ThreadProxy::DrawDurationEstimate() { 1197 base::TimeDelta ThreadProxy::DrawDurationEstimate() {
1170 base::TimeDelta historical_estimate = 1198 base::TimeDelta historical_estimate =
1171 draw_duration_history_.Percentile(kDrawDurationEstimationPercentile); 1199 draw_duration_history_.Percentile(kDrawDurationEstimationPercentile);
1172 base::TimeDelta padding = base::TimeDelta::FromMicroseconds( 1200 base::TimeDelta padding = base::TimeDelta::FromMicroseconds(
1173 kDrawDurationEstimatePaddingInMicroseconds); 1201 kDrawDurationEstimatePaddingInMicroseconds);
1174 return historical_estimate + padding; 1202 return historical_estimate + padding;
1175 } 1203 }
1176 1204
1177 base::TimeDelta ThreadProxy::BeginFrameToCommitDurationEstimate() { 1205 base::TimeDelta ThreadProxy::BeginFrameToCommitDurationEstimate() {
1178 return begin_frame_to_commit_duration_history_.Percentile( 1206 return begin_frame_to_commit_duration_history_.Percentile(
1179 kCommitAndActivationDurationEstimationPercentile); 1207 kCommitAndActivationDurationEstimationPercentile);
1180 } 1208 }
1181 1209
1182 base::TimeDelta ThreadProxy::CommitToActivateDurationEstimate() { 1210 base::TimeDelta ThreadProxy::CommitToActivateDurationEstimate() {
1183 return commit_to_activate_duration_history_.Percentile( 1211 return commit_to_activate_duration_history_.Percentile(
1184 kCommitAndActivationDurationEstimationPercentile); 1212 kCommitAndActivationDurationEstimationPercentile);
1185 } 1213 }
1186 1214
1215 void ThreadProxy::PostBeginFrameDeadline(const base::Closure &closure,
1216 base::TimeTicks deadline) {
1217 base::TimeDelta delta = deadline - base::TimeTicks::Now();
1218 if (delta <= base::TimeDelta())
1219 delta = base::TimeDelta();
1220 Proxy::ImplThreadTaskRunner()->PostDelayedTask(FROM_HERE, closure, delta);
1221 }
1222
1187 void ThreadProxy::ReadyToFinalizeTextureUpdates() { 1223 void ThreadProxy::ReadyToFinalizeTextureUpdates() {
1188 DCHECK(IsImplThread()); 1224 DCHECK(IsImplThread());
1189 scheduler_on_impl_thread_->FinishCommit(); 1225 scheduler_on_impl_thread_->FinishCommit();
1190 } 1226 }
1191 1227
1192 void ThreadProxy::DidCommitAndDrawFrame() { 1228 void ThreadProxy::DidCommitAndDrawFrame() {
1193 DCHECK(IsMainThread()); 1229 DCHECK(IsMainThread());
1194 if (!layer_tree_host_) 1230 if (!layer_tree_host_)
1195 return; 1231 return;
1196 layer_tree_host_->DidCommitAndDrawFrame(); 1232 layer_tree_host_->DidCommitAndDrawFrame();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this); 1290 layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this);
1255 const LayerTreeSettings& settings = layer_tree_host_->settings(); 1291 const LayerTreeSettings& settings = layer_tree_host_->settings();
1256 SchedulerSettings scheduler_settings; 1292 SchedulerSettings scheduler_settings;
1257 scheduler_settings.impl_side_painting = settings.impl_side_painting; 1293 scheduler_settings.impl_side_painting = settings.impl_side_painting;
1258 scheduler_settings.timeout_and_draw_when_animation_checkerboards = 1294 scheduler_settings.timeout_and_draw_when_animation_checkerboards =
1259 settings.timeout_and_draw_when_animation_checkerboards; 1295 settings.timeout_and_draw_when_animation_checkerboards;
1260 scheduler_settings.using_synchronous_renderer_compositor = 1296 scheduler_settings.using_synchronous_renderer_compositor =
1261 settings.using_synchronous_renderer_compositor; 1297 settings.using_synchronous_renderer_compositor;
1262 scheduler_settings.throttle_frame_production = 1298 scheduler_settings.throttle_frame_production =
1263 settings.throttle_frame_production; 1299 settings.throttle_frame_production;
1300 scheduler_settings.use_begin_frame_workaround_for_crbug_249806 = true;
1264 scheduler_on_impl_thread_ = Scheduler::Create(this, scheduler_settings); 1301 scheduler_on_impl_thread_ = Scheduler::Create(this, scheduler_settings);
1265 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); 1302 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible());
1266 1303
1267 impl_thread_weak_ptr_ = weak_factory_on_impl_thread_.GetWeakPtr(); 1304 impl_thread_weak_ptr_ = weak_factory_on_impl_thread_.GetWeakPtr();
1268 completion->Signal(); 1305 completion->Signal();
1269 } 1306 }
1270 1307
1271 void ThreadProxy::InitializeOutputSurfaceOnImplThread( 1308 void ThreadProxy::InitializeOutputSurfaceOnImplThread(
1272 CompletionEvent* completion, 1309 CompletionEvent* completion,
1273 scoped_ptr<OutputSurface> output_surface, 1310 scoped_ptr<OutputSurface> output_surface,
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 DCHECK(layer_tree_host_impl_->settings().impl_side_painting); 1540 DCHECK(layer_tree_host_impl_->settings().impl_side_painting);
1504 completion_event_for_commit_held_on_tree_activation_->Signal(); 1541 completion_event_for_commit_held_on_tree_activation_->Signal();
1505 completion_event_for_commit_held_on_tree_activation_ = NULL; 1542 completion_event_for_commit_held_on_tree_activation_ = NULL;
1506 } 1543 }
1507 1544
1508 commit_to_activate_duration_history_.InsertSample( 1545 commit_to_activate_duration_history_.InsertSample(
1509 base::TimeTicks::HighResNow() - commit_complete_time_); 1546 base::TimeTicks::HighResNow() - commit_complete_time_);
1510 } 1547 }
1511 1548
1512 } // namespace cc 1549 } // namespace cc
OLDNEW
« cc/trees/layer_tree_impl.cc ('K') | « cc/trees/thread_proxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698