| 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" |
| 11 #include "cc/output/output_surface.h" | 11 #include "cc/output/output_surface.h" |
| 12 #include "cc/quads/draw_quad.h" | 12 #include "cc/quads/draw_quad.h" |
| 13 #include "cc/resources/prioritized_resource_manager.h" | 13 #include "cc/resources/prioritized_resource_manager.h" |
| 14 #include "cc/resources/resource_update_controller.h" | 14 #include "cc/resources/resource_update_controller.h" |
| 15 #include "cc/scheduler/commit_earlyout_reason.h" |
| 15 #include "cc/trees/layer_tree_host.h" | 16 #include "cc/trees/layer_tree_host.h" |
| 16 #include "cc/trees/layer_tree_host_single_thread_client.h" | 17 #include "cc/trees/layer_tree_host_single_thread_client.h" |
| 17 #include "cc/trees/layer_tree_impl.h" | 18 #include "cc/trees/layer_tree_impl.h" |
| 18 #include "cc/trees/scoped_abort_remaining_swap_promises.h" | 19 #include "cc/trees/scoped_abort_remaining_swap_promises.h" |
| 19 #include "ui/gfx/frame_time.h" | 20 #include "ui/gfx/frame_time.h" |
| 20 | 21 |
| 21 namespace cc { | 22 namespace cc { |
| 22 | 23 |
| 23 scoped_ptr<Proxy> SingleThreadProxy::Create( | 24 scoped_ptr<Proxy> SingleThreadProxy::Create( |
| 24 LayerTreeHost* layer_tree_host, | 25 LayerTreeHost* layer_tree_host, |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; } | 419 bool SingleThreadProxy::IsInsideDraw() { return inside_draw_; } |
| 419 | 420 |
| 420 void SingleThreadProxy::DidActivateSyncTree() { | 421 void SingleThreadProxy::DidActivateSyncTree() { |
| 421 // Non-impl-side painting finishes commit in DoCommit. Impl-side painting | 422 // Non-impl-side painting finishes commit in DoCommit. Impl-side painting |
| 422 // defers until here to simulate SetNextCommitWaitsForActivation. | 423 // defers until here to simulate SetNextCommitWaitsForActivation. |
| 423 if (layer_tree_host_impl_->settings().impl_side_painting) { | 424 if (layer_tree_host_impl_->settings().impl_side_painting) { |
| 424 // This is required because NotifyReadyToActivate gets called when | 425 // This is required because NotifyReadyToActivate gets called when |
| 425 // the pending tree is not actually ready in the SingleThreadProxy. | 426 // the pending tree is not actually ready in the SingleThreadProxy. |
| 426 layer_tree_host_impl_->SetRequiresHighResToDraw(); | 427 layer_tree_host_impl_->SetRequiresHighResToDraw(); |
| 427 | 428 |
| 428 // Since activation could cause tasks to run, post CommitComplete | 429 CommitComplete(); |
| 429 // separately so that it runs after these tasks. This is the loose | |
| 430 // equivalent of blocking commit until activation and also running | |
| 431 // all tasks posted during commit/activation before CommitComplete. | |
| 432 MainThreadTaskRunner()->PostTask( | |
| 433 FROM_HERE, base::Bind(&SingleThreadProxy::CommitComplete, | |
| 434 weak_factory_.GetWeakPtr())); | |
| 435 } | 430 } |
| 436 | 431 |
| 437 timing_history_.DidActivateSyncTree(); | 432 timing_history_.DidActivateSyncTree(); |
| 438 } | 433 } |
| 439 | 434 |
| 440 void SingleThreadProxy::DidPrepareTiles() { | 435 void SingleThreadProxy::DidPrepareTiles() { |
| 441 DCHECK(layer_tree_host_impl_->settings().impl_side_painting); | 436 DCHECK(layer_tree_host_impl_->settings().impl_side_painting); |
| 442 DCHECK(Proxy::IsImplThread()); | 437 DCHECK(Proxy::IsImplThread()); |
| 443 if (scheduler_on_impl_thread_) | 438 if (scheduler_on_impl_thread_) |
| 444 scheduler_on_impl_thread_->DidPrepareTiles(); | 439 scheduler_on_impl_thread_->DidPrepareTiles(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 456 DebugScopedSetMainThread main(this); | 451 DebugScopedSetMainThread main(this); |
| 457 // This must happen before we notify the scheduler as it may try to recreate | 452 // This must happen before we notify the scheduler as it may try to recreate |
| 458 // the output surface if already in BEGIN_IMPL_FRAME_STATE_IDLE. | 453 // the output surface if already in BEGIN_IMPL_FRAME_STATE_IDLE. |
| 459 layer_tree_host_->DidLoseOutputSurface(); | 454 layer_tree_host_->DidLoseOutputSurface(); |
| 460 } | 455 } |
| 461 client_->DidAbortSwapBuffers(); | 456 client_->DidAbortSwapBuffers(); |
| 462 if (scheduler_on_impl_thread_) | 457 if (scheduler_on_impl_thread_) |
| 463 scheduler_on_impl_thread_->DidLoseOutputSurface(); | 458 scheduler_on_impl_thread_->DidLoseOutputSurface(); |
| 464 } | 459 } |
| 465 | 460 |
| 461 void SingleThreadProxy::CommitVSyncParameters(base::TimeTicks timebase, |
| 462 base::TimeDelta interval) { |
| 463 if (scheduler_on_impl_thread_) |
| 464 scheduler_on_impl_thread_->CommitVSyncParameters(timebase, interval); |
| 465 } |
| 466 |
| 466 void SingleThreadProxy::DidSwapBuffersOnImplThread() { | 467 void SingleThreadProxy::DidSwapBuffersOnImplThread() { |
| 467 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersOnImplThread"); | 468 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersOnImplThread"); |
| 468 if (scheduler_on_impl_thread_) | 469 if (scheduler_on_impl_thread_) |
| 469 scheduler_on_impl_thread_->DidSwapBuffers(); | 470 scheduler_on_impl_thread_->DidSwapBuffers(); |
| 470 client_->DidPostSwapBuffers(); | 471 client_->DidPostSwapBuffers(); |
| 471 } | 472 } |
| 472 | 473 |
| 473 void SingleThreadProxy::DidSwapBuffersCompleteOnImplThread() { | 474 void SingleThreadProxy::DidSwapBuffersCompleteOnImplThread() { |
| 474 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread"); | 475 TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread"); |
| 475 if (scheduler_on_impl_thread_) | 476 if (scheduler_on_impl_thread_) |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 layer_tree_host_->DidDeferCommit(); | 665 layer_tree_host_->DidDeferCommit(); |
| 665 return; | 666 return; |
| 666 } | 667 } |
| 667 | 668 |
| 668 // This checker assumes NotifyReadyToCommit in this stack causes a synchronous | 669 // This checker assumes NotifyReadyToCommit in this stack causes a synchronous |
| 669 // commit. | 670 // commit. |
| 670 ScopedAbortRemainingSwapPromises swap_promise_checker(layer_tree_host_); | 671 ScopedAbortRemainingSwapPromises swap_promise_checker(layer_tree_host_); |
| 671 | 672 |
| 672 if (!layer_tree_host_->visible()) { | 673 if (!layer_tree_host_->visible()) { |
| 673 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD); | 674 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD); |
| 674 BeginMainFrameAbortedOnImplThread(); | 675 BeginMainFrameAbortedOnImplThread( |
| 676 CommitEarlyOutReason::ABORTED_NOT_VISIBLE); |
| 675 return; | 677 return; |
| 676 } | 678 } |
| 677 | 679 |
| 678 if (layer_tree_host_->output_surface_lost()) { | 680 if (layer_tree_host_->output_surface_lost()) { |
| 679 TRACE_EVENT_INSTANT0( | 681 TRACE_EVENT_INSTANT0( |
| 680 "cc", "EarlyOut_OutputSurfaceLost", TRACE_EVENT_SCOPE_THREAD); | 682 "cc", "EarlyOut_OutputSurfaceLost", TRACE_EVENT_SCOPE_THREAD); |
| 681 BeginMainFrameAbortedOnImplThread(); | 683 BeginMainFrameAbortedOnImplThread( |
| 684 CommitEarlyOutReason::ABORTED_OUTPUT_SURFACE_LOST); |
| 682 return; | 685 return; |
| 683 } | 686 } |
| 684 | 687 |
| 685 const BeginFrameArgs& begin_frame_args = | 688 const BeginFrameArgs& begin_frame_args = |
| 686 layer_tree_host_impl_->CurrentBeginFrameArgs(); | 689 layer_tree_host_impl_->CurrentBeginFrameArgs(); |
| 687 DoBeginMainFrame(begin_frame_args); | 690 DoBeginMainFrame(begin_frame_args); |
| 688 } | 691 } |
| 689 | 692 |
| 690 void SingleThreadProxy::DoBeginMainFrame( | 693 void SingleThreadProxy::DoBeginMainFrame( |
| 691 const BeginFrameArgs& begin_frame_args) { | 694 const BeginFrameArgs& begin_frame_args) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 703 layer_tree_host_impl_->memory_allocation_priority_cutoff()); | 706 layer_tree_host_impl_->memory_allocation_priority_cutoff()); |
| 704 } | 707 } |
| 705 | 708 |
| 706 DCHECK(!queue_for_commit_); | 709 DCHECK(!queue_for_commit_); |
| 707 queue_for_commit_ = make_scoped_ptr(new ResourceUpdateQueue); | 710 queue_for_commit_ = make_scoped_ptr(new ResourceUpdateQueue); |
| 708 | 711 |
| 709 layer_tree_host_->UpdateLayers(queue_for_commit_.get()); | 712 layer_tree_host_->UpdateLayers(queue_for_commit_.get()); |
| 710 | 713 |
| 711 timing_history_.DidBeginMainFrame(); | 714 timing_history_.DidBeginMainFrame(); |
| 712 | 715 |
| 716 // TODO(enne): SingleThreadProxy does not support cancelling commits yet, |
| 717 // search for CommitEarlyOutReason::FINISHED_NO_UPDATES inside |
| 718 // thread_proxy.cc |
| 713 if (scheduler_on_impl_thread_) { | 719 if (scheduler_on_impl_thread_) { |
| 714 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted(); | 720 scheduler_on_impl_thread_->NotifyBeginMainFrameStarted(); |
| 715 scheduler_on_impl_thread_->NotifyReadyToCommit(); | 721 scheduler_on_impl_thread_->NotifyReadyToCommit(); |
| 716 } | 722 } |
| 717 } | 723 } |
| 718 | 724 |
| 719 void SingleThreadProxy::BeginMainFrameAbortedOnImplThread() { | 725 void SingleThreadProxy::BeginMainFrameAbortedOnImplThread( |
| 726 CommitEarlyOutReason reason) { |
| 720 DebugScopedSetImplThread impl(this); | 727 DebugScopedSetImplThread impl(this); |
| 721 DCHECK(scheduler_on_impl_thread_->CommitPending()); | 728 DCHECK(scheduler_on_impl_thread_->CommitPending()); |
| 722 DCHECK(!layer_tree_host_impl_->pending_tree()); | 729 DCHECK(!layer_tree_host_impl_->pending_tree()); |
| 723 | 730 |
| 724 // TODO(enne): SingleThreadProxy does not support cancelling commits yet so | 731 layer_tree_host_impl_->BeginMainFrameAborted(reason); |
| 725 // did_handle is always false. | 732 scheduler_on_impl_thread_->BeginMainFrameAborted(reason); |
| 726 bool did_handle = false; | |
| 727 layer_tree_host_impl_->BeginMainFrameAborted(did_handle); | |
| 728 scheduler_on_impl_thread_->BeginMainFrameAborted(did_handle); | |
| 729 } | 733 } |
| 730 | 734 |
| 731 DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapIfPossible() { | 735 DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapIfPossible() { |
| 732 DebugScopedSetImplThread impl(this); | 736 DebugScopedSetImplThread impl(this); |
| 733 LayerTreeHostImpl::FrameData frame; | 737 LayerTreeHostImpl::FrameData frame; |
| 734 return DoComposite(layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time, | 738 return DoComposite(layer_tree_host_impl_->CurrentBeginFrameArgs().frame_time, |
| 735 &frame); | 739 &frame); |
| 736 } | 740 } |
| 737 | 741 |
| 738 DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapForced() { | 742 DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapForced() { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 | 798 |
| 795 void SingleThreadProxy::DidBeginImplFrameDeadline() { | 799 void SingleThreadProxy::DidBeginImplFrameDeadline() { |
| 796 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame(); | 800 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame(); |
| 797 } | 801 } |
| 798 | 802 |
| 799 void SingleThreadProxy::SendBeginFramesToChildren(const BeginFrameArgs& args) { | 803 void SingleThreadProxy::SendBeginFramesToChildren(const BeginFrameArgs& args) { |
| 800 layer_tree_host_->SendBeginFramesToChildren(args); | 804 layer_tree_host_->SendBeginFramesToChildren(args); |
| 801 } | 805 } |
| 802 | 806 |
| 803 } // namespace cc | 807 } // namespace cc |
| OLD | NEW |