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/single_thread_proxy.h" | 5 #include "cc/trees/single_thread_proxy.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "cc/debug/benchmark_instrumentation.h" | 9 #include "cc/debug/benchmark_instrumentation.h" |
10 #include "cc/output/context_provider.h" | 10 #include "cc/output/context_provider.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 } | 94 } |
95 } | 95 } |
96 | 96 |
97 void SingleThreadProxy::SetVisible(bool visible) { | 97 void SingleThreadProxy::SetVisible(bool visible) { |
98 TRACE_EVENT0("cc", "SingleThreadProxy::SetVisible"); | 98 TRACE_EVENT0("cc", "SingleThreadProxy::SetVisible"); |
99 DebugScopedSetImplThread impl(this); | 99 DebugScopedSetImplThread impl(this); |
100 layer_tree_host_impl_->SetVisible(visible); | 100 layer_tree_host_impl_->SetVisible(visible); |
101 if (scheduler_on_impl_thread_) | 101 if (scheduler_on_impl_thread_) |
102 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); | 102 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); |
103 // Changing visibility could change ShouldComposite(). | 103 // Changing visibility could change ShouldComposite(). |
104 UpdateBackgroundAnimateTicking(); | |
105 } | 104 } |
106 | 105 |
107 void SingleThreadProxy::RequestNewOutputSurface() { | 106 void SingleThreadProxy::RequestNewOutputSurface() { |
108 DCHECK(Proxy::IsMainThread()); | 107 DCHECK(Proxy::IsMainThread()); |
109 DCHECK(layer_tree_host_->output_surface_lost()); | 108 DCHECK(layer_tree_host_->output_surface_lost()); |
110 output_surface_creation_callback_.Cancel(); | 109 output_surface_creation_callback_.Cancel(); |
111 if (output_surface_creation_requested_) | 110 if (output_surface_creation_requested_) |
112 return; | 111 return; |
113 output_surface_creation_requested_ = true; | 112 output_surface_creation_requested_ = true; |
114 layer_tree_host_->RequestNewOutputSurface(); | 113 layer_tree_host_->RequestNewOutputSurface(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 client_->ScheduleAnimation(); | 153 client_->ScheduleAnimation(); |
155 SetNeedsCommit(); | 154 SetNeedsCommit(); |
156 } | 155 } |
157 | 156 |
158 void SingleThreadProxy::SetNeedsUpdateLayers() { | 157 void SingleThreadProxy::SetNeedsUpdateLayers() { |
159 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsUpdateLayers"); | 158 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsUpdateLayers"); |
160 DCHECK(Proxy::IsMainThread()); | 159 DCHECK(Proxy::IsMainThread()); |
161 SetNeedsCommit(); | 160 SetNeedsCommit(); |
162 } | 161 } |
163 | 162 |
163 void SingleThreadProxy::DoAnimate() { | |
164 // Don't animate if there is no root layer. | |
165 // TODO(mithro): Both Animate and UpdateAnimationState already have a | |
166 // "!active_tree_->root_layer()" check? | |
167 if (!layer_tree_host_impl_->active_tree()->root_layer()) { | |
168 return; | |
169 } | |
170 | |
171 layer_tree_host_impl_->Animate( | |
172 layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time); | |
173 | |
174 // If animations are not visible, update the animation state now as it | |
175 // won't happen in DoComposite. | |
176 if (!layer_tree_host_impl_->AnimationsAreVisible()) { | |
177 layer_tree_host_impl_->UpdateAnimationState(true); | |
178 } | |
179 } | |
180 | |
164 void SingleThreadProxy::DoCommit() { | 181 void SingleThreadProxy::DoCommit() { |
165 TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit"); | 182 TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit"); |
166 DCHECK(Proxy::IsMainThread()); | 183 DCHECK(Proxy::IsMainThread()); |
167 | 184 |
168 commit_requested_ = false; | 185 commit_requested_ = false; |
169 layer_tree_host_->WillCommit(); | 186 layer_tree_host_->WillCommit(); |
170 | 187 |
171 // Commit immediately. | 188 // Commit immediately. |
172 { | 189 { |
173 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 190 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
(...skipping 21 matching lines...) Expand all Loading... | |
195 layer_tree_host_impl_->resource_provider()); | 212 layer_tree_host_impl_->resource_provider()); |
196 update_controller->Finalize(); | 213 update_controller->Finalize(); |
197 | 214 |
198 if (layer_tree_host_impl_->EvictedUIResourcesExist()) | 215 if (layer_tree_host_impl_->EvictedUIResourcesExist()) |
199 layer_tree_host_->RecreateUIResources(); | 216 layer_tree_host_->RecreateUIResources(); |
200 | 217 |
201 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get()); | 218 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get()); |
202 | 219 |
203 layer_tree_host_impl_->CommitComplete(); | 220 layer_tree_host_impl_->CommitComplete(); |
204 | 221 |
205 UpdateBackgroundAnimateTicking(); | |
206 | |
207 #if DCHECK_IS_ON | 222 #if DCHECK_IS_ON |
208 // In the single-threaded case, the scale and scroll deltas should never be | 223 // In the single-threaded case, the scale and scroll deltas should never be |
209 // touched on the impl layer tree. | 224 // touched on the impl layer tree. |
210 scoped_ptr<ScrollAndScaleSet> scroll_info = | 225 scoped_ptr<ScrollAndScaleSet> scroll_info = |
211 layer_tree_host_impl_->ProcessScrollDeltas(); | 226 layer_tree_host_impl_->ProcessScrollDeltas(); |
212 DCHECK(!scroll_info->scrolls.size()); | 227 DCHECK(!scroll_info->scrolls.size()); |
213 DCHECK_EQ(1.f, scroll_info->page_scale_delta); | 228 DCHECK_EQ(1.f, scroll_info->page_scale_delta); |
214 #endif | 229 #endif |
215 | 230 |
216 RenderingStatsInstrumentation* stats_instrumentation = | 231 RenderingStatsInstrumentation* stats_instrumentation = |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 scheduler_on_impl_thread_ = nullptr; | 336 scheduler_on_impl_thread_ = nullptr; |
322 layer_tree_host_impl_ = nullptr; | 337 layer_tree_host_impl_ = nullptr; |
323 } | 338 } |
324 layer_tree_host_ = NULL; | 339 layer_tree_host_ = NULL; |
325 } | 340 } |
326 | 341 |
327 void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) { | 342 void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) { |
328 TRACE_EVENT1( | 343 TRACE_EVENT1( |
329 "cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); | 344 "cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); |
330 DCHECK(Proxy::IsImplThread()); | 345 DCHECK(Proxy::IsImplThread()); |
331 UpdateBackgroundAnimateTicking(); | |
332 if (scheduler_on_impl_thread_) | 346 if (scheduler_on_impl_thread_) |
333 scheduler_on_impl_thread_->SetCanDraw(can_draw); | 347 scheduler_on_impl_thread_->SetCanDraw(can_draw); |
334 } | 348 } |
335 | 349 |
336 void SingleThreadProxy::NotifyReadyToActivate() { | 350 void SingleThreadProxy::NotifyReadyToActivate() { |
337 TRACE_EVENT0("cc", "SingleThreadProxy::NotifyReadyToActivate"); | 351 TRACE_EVENT0("cc", "SingleThreadProxy::NotifyReadyToActivate"); |
338 DebugScopedSetImplThread impl(this); | 352 DebugScopedSetImplThread impl(this); |
339 if (scheduler_on_impl_thread_) | 353 if (scheduler_on_impl_thread_) |
340 scheduler_on_impl_thread_->NotifyReadyToActivate(); | 354 scheduler_on_impl_thread_->NotifyReadyToActivate(); |
341 } | 355 } |
342 | 356 |
343 void SingleThreadProxy::SetNeedsRedrawOnImplThread() { | 357 void SingleThreadProxy::SetNeedsRedrawOnImplThread() { |
344 client_->ScheduleComposite(); | 358 client_->ScheduleComposite(); |
345 if (scheduler_on_impl_thread_) | 359 if (scheduler_on_impl_thread_) |
346 scheduler_on_impl_thread_->SetNeedsRedraw(); | 360 scheduler_on_impl_thread_->SetNeedsRedraw(); |
347 } | 361 } |
348 | 362 |
349 void SingleThreadProxy::SetNeedsAnimateOnImplThread() { | 363 void SingleThreadProxy::SetNeedsAnimateOnImplThread() { |
350 SetNeedsRedrawOnImplThread(); | 364 client_->ScheduleComposite(); |
brianderson
2014/11/04 23:32:19
Also, why is ScheduleComposite needed instead of S
mithro-old
2014/11/05 00:02:36
The old code use to just delegate to SetNeedsRedra
| |
365 if (scheduler_on_impl_thread_) | |
366 scheduler_on_impl_thread_->SetNeedsAnimate(); | |
brianderson
2014/11/04 18:54:38
Is this just a cleanup, or is it also needed for t
mithro-old
2014/11/04 22:16:50
Both.
Previously, the SetNeedsAnimateOnImplThread
| |
351 } | 367 } |
352 | 368 |
353 void SingleThreadProxy::SetNeedsManageTilesOnImplThread() { | 369 void SingleThreadProxy::SetNeedsManageTilesOnImplThread() { |
354 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsManageTilesOnImplThread"); | 370 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsManageTilesOnImplThread"); |
355 if (scheduler_on_impl_thread_) | 371 if (scheduler_on_impl_thread_) |
356 scheduler_on_impl_thread_->SetNeedsManageTiles(); | 372 scheduler_on_impl_thread_->SetNeedsManageTiles(); |
357 } | 373 } |
358 | 374 |
359 void SingleThreadProxy::SetNeedsRedrawRectOnImplThread( | 375 void SingleThreadProxy::SetNeedsRedrawRectOnImplThread( |
360 const gfx::Rect& damage_rect) { | 376 const gfx::Rect& damage_rect) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
413 // Since activation could cause tasks to run, post CommitComplete | 429 // Since activation could cause tasks to run, post CommitComplete |
414 // separately so that it runs after these tasks. This is the loose | 430 // separately so that it runs after these tasks. This is the loose |
415 // equivalent of blocking commit until activation and also running | 431 // equivalent of blocking commit until activation and also running |
416 // all tasks posted during commit/activation before CommitComplete. | 432 // all tasks posted during commit/activation before CommitComplete. |
417 MainThreadTaskRunner()->PostTask( | 433 MainThreadTaskRunner()->PostTask( |
418 FROM_HERE, | 434 FROM_HERE, |
419 base::Bind(&SingleThreadProxy::CommitComplete, | 435 base::Bind(&SingleThreadProxy::CommitComplete, |
420 weak_factory_.GetWeakPtr())); | 436 weak_factory_.GetWeakPtr())); |
421 } | 437 } |
422 | 438 |
423 UpdateBackgroundAnimateTicking(); | |
424 timing_history_.DidActivateSyncTree(); | 439 timing_history_.DidActivateSyncTree(); |
425 } | 440 } |
426 | 441 |
427 void SingleThreadProxy::DidManageTiles() { | 442 void SingleThreadProxy::DidManageTiles() { |
428 DCHECK(layer_tree_host_impl_->settings().impl_side_painting); | 443 DCHECK(layer_tree_host_impl_->settings().impl_side_painting); |
429 DCHECK(Proxy::IsImplThread()); | 444 DCHECK(Proxy::IsImplThread()); |
430 if (scheduler_on_impl_thread_) | 445 if (scheduler_on_impl_thread_) |
431 scheduler_on_impl_thread_->DidManageTiles(); | 446 scheduler_on_impl_thread_->DidManageTiles(); |
432 } | 447 } |
433 | 448 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
491 | 506 |
492 { | 507 { |
493 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this)); | 508 DebugScopedSetImplThread impl(const_cast<SingleThreadProxy*>(this)); |
494 if (layer_tree_host_impl_->settings().impl_side_painting) { | 509 if (layer_tree_host_impl_->settings().impl_side_painting) { |
495 layer_tree_host_impl_->ActivateSyncTree(); | 510 layer_tree_host_impl_->ActivateSyncTree(); |
496 layer_tree_host_impl_->active_tree()->UpdateDrawProperties(); | 511 layer_tree_host_impl_->active_tree()->UpdateDrawProperties(); |
497 layer_tree_host_impl_->ManageTiles(); | 512 layer_tree_host_impl_->ManageTiles(); |
498 layer_tree_host_impl_->SynchronouslyInitializeAllTiles(); | 513 layer_tree_host_impl_->SynchronouslyInitializeAllTiles(); |
499 } | 514 } |
500 | 515 |
516 DoAnimate(); | |
517 | |
501 LayerTreeHostImpl::FrameData frame; | 518 LayerTreeHostImpl::FrameData frame; |
502 DoComposite(frame_begin_time, &frame); | 519 DoComposite(frame_begin_time, &frame); |
503 | 520 |
504 // DoComposite could abort, but because this is a synchronous composite | 521 // DoComposite could abort, but because this is a synchronous composite |
505 // another draw will never be scheduled, so break remaining promises. | 522 // another draw will never be scheduled, so break remaining promises. |
506 layer_tree_host_impl_->active_tree()->BreakSwapPromises( | 523 layer_tree_host_impl_->active_tree()->BreakSwapPromises( |
507 SwapPromise::SWAP_FAILS); | 524 SwapPromise::SWAP_FAILS); |
508 } | 525 } |
509 } | 526 } |
510 | 527 |
(...skipping 21 matching lines...) Expand all Loading... | |
532 bool SingleThreadProxy::SupportsImplScrolling() const { | 549 bool SingleThreadProxy::SupportsImplScrolling() const { |
533 return false; | 550 return false; |
534 } | 551 } |
535 | 552 |
536 bool SingleThreadProxy::ShouldComposite() const { | 553 bool SingleThreadProxy::ShouldComposite() const { |
537 DCHECK(Proxy::IsImplThread()); | 554 DCHECK(Proxy::IsImplThread()); |
538 return layer_tree_host_impl_->visible() && | 555 return layer_tree_host_impl_->visible() && |
539 layer_tree_host_impl_->CanDraw(); | 556 layer_tree_host_impl_->CanDraw(); |
540 } | 557 } |
541 | 558 |
542 void SingleThreadProxy::UpdateBackgroundAnimateTicking() { | |
543 DCHECK(Proxy::IsImplThread()); | |
544 layer_tree_host_impl_->UpdateBackgroundAnimateTicking( | |
545 !ShouldComposite() && layer_tree_host_impl_->active_tree()->root_layer()); | |
546 } | |
547 | |
548 void SingleThreadProxy::ScheduleRequestNewOutputSurface() { | 559 void SingleThreadProxy::ScheduleRequestNewOutputSurface() { |
549 if (output_surface_creation_callback_.IsCancelled() && | 560 if (output_surface_creation_callback_.IsCancelled() && |
550 !output_surface_creation_requested_) { | 561 !output_surface_creation_requested_) { |
551 output_surface_creation_callback_.Reset( | 562 output_surface_creation_callback_.Reset( |
552 base::Bind(&SingleThreadProxy::RequestNewOutputSurface, | 563 base::Bind(&SingleThreadProxy::RequestNewOutputSurface, |
553 weak_factory_.GetWeakPtr())); | 564 weak_factory_.GetWeakPtr())); |
554 MainThreadTaskRunner()->PostTask( | 565 MainThreadTaskRunner()->PostTask( |
555 FROM_HERE, output_surface_creation_callback_.callback()); | 566 FROM_HERE, output_surface_creation_callback_.callback()); |
556 } | 567 } |
557 } | 568 } |
558 | 569 |
559 DrawResult SingleThreadProxy::DoComposite(base::TimeTicks frame_begin_time, | 570 DrawResult SingleThreadProxy::DoComposite(base::TimeTicks frame_begin_time, |
560 LayerTreeHostImpl::FrameData* frame) { | 571 LayerTreeHostImpl::FrameData* frame) { |
561 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite"); | 572 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite"); |
562 DCHECK(!layer_tree_host_->output_surface_lost()); | 573 DCHECK(!layer_tree_host_->output_surface_lost()); |
563 | 574 |
564 DrawResult draw_result; | 575 DrawResult draw_result; |
565 bool draw_frame; | 576 bool draw_frame; |
566 { | 577 { |
567 DebugScopedSetImplThread impl(this); | 578 DebugScopedSetImplThread impl(this); |
568 base::AutoReset<bool> mark_inside(&inside_draw_, true); | 579 base::AutoReset<bool> mark_inside(&inside_draw_, true); |
569 | 580 |
570 // We guard PrepareToDraw() with CanDraw() because it always returns a valid | 581 // We guard PrepareToDraw() with CanDraw() because it always returns a valid |
571 // frame, so can only be used when such a frame is possible. Since | 582 // frame, so can only be used when such a frame is possible. Since |
572 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on | 583 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on |
573 // CanDraw() as well. | 584 // CanDraw() as well. |
574 if (!ShouldComposite()) { | 585 if (!ShouldComposite()) { |
575 UpdateBackgroundAnimateTicking(); | |
576 return DRAW_ABORTED_CANT_DRAW; | 586 return DRAW_ABORTED_CANT_DRAW; |
577 } | 587 } |
578 | 588 |
579 timing_history_.DidStartDrawing(); | 589 timing_history_.DidStartDrawing(); |
580 | 590 |
581 layer_tree_host_impl_->Animate( | |
582 layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time); | |
583 UpdateBackgroundAnimateTicking(); | |
584 | |
585 draw_result = layer_tree_host_impl_->PrepareToDraw(frame); | 591 draw_result = layer_tree_host_impl_->PrepareToDraw(frame); |
586 draw_frame = draw_result == DRAW_SUCCESS; | 592 draw_frame = draw_result == DRAW_SUCCESS; |
587 if (draw_frame) | 593 if (draw_frame) |
588 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time); | 594 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time); |
589 layer_tree_host_impl_->DidDrawAllLayers(*frame); | 595 layer_tree_host_impl_->DidDrawAllLayers(*frame); |
590 | 596 |
591 bool start_ready_animations = draw_frame; | 597 bool start_ready_animations = draw_frame; |
592 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); | 598 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); |
593 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame(); | 599 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame(); |
594 | 600 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
735 return INVALID_RESULT; | 741 return INVALID_RESULT; |
736 } | 742 } |
737 | 743 |
738 void SingleThreadProxy::ScheduledActionCommit() { | 744 void SingleThreadProxy::ScheduledActionCommit() { |
739 DebugScopedSetMainThread main(this); | 745 DebugScopedSetMainThread main(this); |
740 DoCommit(); | 746 DoCommit(); |
741 } | 747 } |
742 | 748 |
743 void SingleThreadProxy::ScheduledActionAnimate() { | 749 void SingleThreadProxy::ScheduledActionAnimate() { |
744 TRACE_EVENT0("cc", "ScheduledActionAnimate"); | 750 TRACE_EVENT0("cc", "ScheduledActionAnimate"); |
745 layer_tree_host_impl_->Animate( | 751 DebugScopedSetImplThread impl(this); |
746 layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time); | 752 DoAnimate(); |
747 } | 753 } |
748 | 754 |
749 void SingleThreadProxy::ScheduledActionUpdateVisibleTiles() { | 755 void SingleThreadProxy::ScheduledActionUpdateVisibleTiles() { |
750 DebugScopedSetImplThread impl(this); | 756 DebugScopedSetImplThread impl(this); |
751 layer_tree_host_impl_->UpdateVisibleTiles(); | 757 layer_tree_host_impl_->UpdateVisibleTiles(); |
752 } | 758 } |
753 | 759 |
754 void SingleThreadProxy::ScheduledActionActivateSyncTree() { | 760 void SingleThreadProxy::ScheduledActionActivateSyncTree() { |
755 DebugScopedSetImplThread impl(this); | 761 DebugScopedSetImplThread impl(this); |
756 layer_tree_host_impl_->ActivateSyncTree(); | 762 layer_tree_host_impl_->ActivateSyncTree(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
790 | 796 |
791 base::TimeDelta SingleThreadProxy::CommitToActivateDurationEstimate() { | 797 base::TimeDelta SingleThreadProxy::CommitToActivateDurationEstimate() { |
792 return timing_history_.CommitToActivateDurationEstimate(); | 798 return timing_history_.CommitToActivateDurationEstimate(); |
793 } | 799 } |
794 | 800 |
795 void SingleThreadProxy::DidBeginImplFrameDeadline() { | 801 void SingleThreadProxy::DidBeginImplFrameDeadline() { |
796 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame(); | 802 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame(); |
797 } | 803 } |
798 | 804 |
799 } // namespace cc | 805 } // namespace cc |
OLD | NEW |