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/profiler/scoped_tracker.h" | 8 #include "base/profiler/scoped_tracker.h" |
9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
10 #include "cc/debug/benchmark_instrumentation.h" | 10 #include "cc/debug/benchmark_instrumentation.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 SingleThreadProxy::SingleThreadProxy( | 38 SingleThreadProxy::SingleThreadProxy( |
39 LayerTreeHost* layer_tree_host, | 39 LayerTreeHost* layer_tree_host, |
40 LayerTreeHostSingleThreadClient* client, | 40 LayerTreeHostSingleThreadClient* client, |
41 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 41 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
42 scoped_ptr<BeginFrameSource> external_begin_frame_source) | 42 scoped_ptr<BeginFrameSource> external_begin_frame_source) |
43 : Proxy(main_task_runner, NULL), | 43 : Proxy(main_task_runner, NULL), |
44 layer_tree_host_(layer_tree_host), | 44 layer_tree_host_(layer_tree_host), |
45 client_(client), | 45 client_(client), |
46 timing_history_(layer_tree_host->rendering_stats_instrumentation()), | 46 timing_history_(layer_tree_host->rendering_stats_instrumentation()), |
47 next_frame_is_newly_committed_frame_(false), | 47 next_frame_is_newly_committed_frame_(false), |
| 48 #if DCHECK_IS_ON() |
48 inside_impl_frame_(false), | 49 inside_impl_frame_(false), |
| 50 #endif |
49 inside_draw_(false), | 51 inside_draw_(false), |
50 defer_commits_(false), | 52 defer_commits_(false), |
51 animate_requested_(false), | 53 animate_requested_(false), |
52 commit_requested_(false), | 54 commit_requested_(false), |
53 inside_synchronous_composite_(false), | 55 inside_synchronous_composite_(false), |
54 output_surface_creation_requested_(false), | 56 output_surface_creation_requested_(false), |
55 weak_factory_(this) { | 57 weak_factory_(this) { |
56 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); | 58 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); |
57 DCHECK(Proxy::IsMainThread()); | 59 DCHECK(Proxy::IsMainThread()); |
58 DCHECK(layer_tree_host); | 60 DCHECK(layer_tree_host); |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 layer_tree_host_->DidCompleteSwapBuffers(); | 582 layer_tree_host_->DidCompleteSwapBuffers(); |
581 } | 583 } |
582 | 584 |
583 void SingleThreadProxy::OnDrawForOutputSurface() { | 585 void SingleThreadProxy::OnDrawForOutputSurface() { |
584 NOTREACHED() << "Implemented by ThreadProxy for synchronous compositor."; | 586 NOTREACHED() << "Implemented by ThreadProxy for synchronous compositor."; |
585 } | 587 } |
586 | 588 |
587 void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { | 589 void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { |
588 TRACE_EVENT0("cc,benchmark", "SingleThreadProxy::CompositeImmediately"); | 590 TRACE_EVENT0("cc,benchmark", "SingleThreadProxy::CompositeImmediately"); |
589 DCHECK(Proxy::IsMainThread()); | 591 DCHECK(Proxy::IsMainThread()); |
| 592 #if DCHECK_IS_ON() |
590 DCHECK(!inside_impl_frame_); | 593 DCHECK(!inside_impl_frame_); |
| 594 #endif |
591 base::AutoReset<bool> inside_composite(&inside_synchronous_composite_, true); | 595 base::AutoReset<bool> inside_composite(&inside_synchronous_composite_, true); |
592 | 596 |
593 if (layer_tree_host_->output_surface_lost()) { | 597 if (layer_tree_host_->output_surface_lost()) { |
594 RequestNewOutputSurface(); | 598 RequestNewOutputSurface(); |
595 // RequestNewOutputSurface could have synchronously created an output | 599 // RequestNewOutputSurface could have synchronously created an output |
596 // surface, so check again before returning. | 600 // surface, so check again before returning. |
597 if (layer_tree_host_->output_surface_lost()) | 601 if (layer_tree_host_->output_surface_lost()) |
598 return; | 602 return; |
599 } | 603 } |
600 | 604 |
601 BeginFrameArgs begin_frame_args(BeginFrameArgs::Create( | 605 BeginFrameArgs begin_frame_args(BeginFrameArgs::Create( |
602 BEGINFRAME_FROM_HERE, frame_begin_time, base::TimeTicks(), | 606 BEGINFRAME_FROM_HERE, frame_begin_time, base::TimeTicks(), |
603 BeginFrameArgs::DefaultInterval(), BeginFrameArgs::NORMAL)); | 607 BeginFrameArgs::DefaultInterval(), BeginFrameArgs::NORMAL)); |
604 | 608 |
605 // Start the impl frame. | 609 // Start the impl frame. |
606 { | 610 { |
607 DebugScopedSetImplThread impl(this); | 611 DebugScopedSetImplThread impl(this); |
608 WillBeginImplFrame(begin_frame_args); | 612 WillBeginImplFrame(begin_frame_args); |
609 } | 613 } |
610 | 614 |
611 // Run the "main thread" and get it to commit. | 615 // Run the "main thread" and get it to commit. |
612 { | 616 { |
| 617 #if DCHECK_IS_ON() |
613 DCHECK(inside_impl_frame_); | 618 DCHECK(inside_impl_frame_); |
| 619 #endif |
614 DoBeginMainFrame(begin_frame_args); | 620 DoBeginMainFrame(begin_frame_args); |
615 DoCommit(); | 621 DoCommit(); |
616 | 622 |
617 DCHECK_EQ(0u, layer_tree_host_->num_queued_swap_promises()) | 623 DCHECK_EQ(0u, layer_tree_host_->num_queued_swap_promises()) |
618 << "Commit should always succeed and transfer promises."; | 624 << "Commit should always succeed and transfer promises."; |
619 } | 625 } |
620 | 626 |
621 // Finish the impl frame. | 627 // Finish the impl frame. |
622 { | 628 { |
623 DebugScopedSetImplThread impl(this); | 629 DebugScopedSetImplThread impl(this); |
624 if (layer_tree_host_impl_->settings().impl_side_painting) { | 630 if (layer_tree_host_impl_->settings().impl_side_painting) { |
625 layer_tree_host_impl_->ActivateSyncTree(); | 631 layer_tree_host_impl_->ActivateSyncTree(); |
626 DCHECK(!layer_tree_host_impl_->active_tree() | 632 DCHECK(!layer_tree_host_impl_->active_tree() |
627 ->needs_update_draw_properties()); | 633 ->needs_update_draw_properties()); |
628 layer_tree_host_impl_->PrepareTiles(); | 634 layer_tree_host_impl_->PrepareTiles(); |
629 layer_tree_host_impl_->SynchronouslyInitializeAllTiles(); | 635 layer_tree_host_impl_->SynchronouslyInitializeAllTiles(); |
630 } | 636 } |
631 | 637 |
632 DoAnimate(); | 638 DoAnimate(); |
633 | 639 |
634 LayerTreeHostImpl::FrameData frame; | 640 LayerTreeHostImpl::FrameData frame; |
635 DoComposite(&frame); | 641 DoComposite(&frame); |
636 | 642 |
637 // DoComposite could abort, but because this is a synchronous composite | 643 // DoComposite could abort, but because this is a synchronous composite |
638 // another draw will never be scheduled, so break remaining promises. | 644 // another draw will never be scheduled, so break remaining promises. |
639 layer_tree_host_impl_->active_tree()->BreakSwapPromises( | 645 layer_tree_host_impl_->active_tree()->BreakSwapPromises( |
640 SwapPromise::SWAP_FAILS); | 646 SwapPromise::SWAP_FAILS); |
641 | 647 |
642 DidBeginImplFrameDeadline(); | 648 DidFinishImplFrame(); |
643 } | 649 } |
644 } | 650 } |
645 | 651 |
646 void SingleThreadProxy::ForceSerializeOnSwapBuffers() { | 652 void SingleThreadProxy::ForceSerializeOnSwapBuffers() { |
647 { | 653 { |
648 DebugScopedSetImplThread impl(this); | 654 DebugScopedSetImplThread impl(this); |
649 if (layer_tree_host_impl_->renderer()) { | 655 if (layer_tree_host_impl_->renderer()) { |
650 DCHECK(!layer_tree_host_->output_surface_lost()); | 656 DCHECK(!layer_tree_host_->output_surface_lost()); |
651 layer_tree_host_impl_->renderer()->DoNoOp(); | 657 layer_tree_host_impl_->renderer()->DoNoOp(); |
652 } | 658 } |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
791 scheduler_on_impl_thread_->SetChildrenNeedBeginFrames( | 797 scheduler_on_impl_thread_->SetChildrenNeedBeginFrames( |
792 children_need_begin_frames); | 798 children_need_begin_frames); |
793 } | 799 } |
794 | 800 |
795 void SingleThreadProxy::SetAuthoritativeVSyncInterval( | 801 void SingleThreadProxy::SetAuthoritativeVSyncInterval( |
796 const base::TimeDelta& interval) { | 802 const base::TimeDelta& interval) { |
797 scheduler_on_impl_thread_->SetAuthoritativeVSyncInterval(interval); | 803 scheduler_on_impl_thread_->SetAuthoritativeVSyncInterval(interval); |
798 } | 804 } |
799 | 805 |
800 void SingleThreadProxy::WillBeginImplFrame(const BeginFrameArgs& args) { | 806 void SingleThreadProxy::WillBeginImplFrame(const BeginFrameArgs& args) { |
| 807 #if DCHECK_IS_ON() |
801 DCHECK(!inside_impl_frame_) | 808 DCHECK(!inside_impl_frame_) |
802 << "WillBeginImplFrame called while already inside an impl frame!"; | 809 << "WillBeginImplFrame called while already inside an impl frame!"; |
803 inside_impl_frame_ = true; | 810 inside_impl_frame_ = true; |
| 811 #endif |
804 layer_tree_host_impl_->WillBeginImplFrame(args); | 812 layer_tree_host_impl_->WillBeginImplFrame(args); |
805 } | 813 } |
806 | 814 |
807 void SingleThreadProxy::ScheduledActionSendBeginMainFrame() { | 815 void SingleThreadProxy::ScheduledActionSendBeginMainFrame() { |
808 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionSendBeginMainFrame"); | 816 TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionSendBeginMainFrame"); |
809 // Although this proxy is single-threaded, it's problematic to synchronously | 817 // Although this proxy is single-threaded, it's problematic to synchronously |
810 // have BeginMainFrame happen after ScheduledActionSendBeginMainFrame. This | 818 // have BeginMainFrame happen after ScheduledActionSendBeginMainFrame. This |
811 // could cause a commit to occur in between a series of SetNeedsCommit calls | 819 // could cause a commit to occur in between a series of SetNeedsCommit calls |
812 // (i.e. property modifications) causing some to fall on one frame and some to | 820 // (i.e. property modifications) causing some to fall on one frame and some to |
813 // fall on the next. Doing it asynchronously instead matches the semantics of | 821 // fall on the next. Doing it asynchronously instead matches the semantics of |
814 // ThreadProxy::SetNeedsCommit where SetNeedsCommit will not cause a | 822 // ThreadProxy::SetNeedsCommit where SetNeedsCommit will not cause a |
815 // synchronous commit. | 823 // synchronous commit. |
| 824 #if DCHECK_IS_ON() |
816 DCHECK(inside_impl_frame_) | 825 DCHECK(inside_impl_frame_) |
817 << "BeginMainFrame should only be sent inside a BeginImplFrame"; | 826 << "BeginMainFrame should only be sent inside a BeginImplFrame"; |
| 827 #endif |
818 const BeginFrameArgs& begin_frame_args = | 828 const BeginFrameArgs& begin_frame_args = |
819 layer_tree_host_impl_->CurrentBeginFrameArgs(); | 829 layer_tree_host_impl_->CurrentBeginFrameArgs(); |
820 | 830 |
821 MainThreadTaskRunner()->PostTask( | 831 MainThreadTaskRunner()->PostTask( |
822 FROM_HERE, base::Bind(&SingleThreadProxy::BeginMainFrame, | 832 FROM_HERE, base::Bind(&SingleThreadProxy::BeginMainFrame, |
823 weak_factory_.GetWeakPtr(), begin_frame_args)); | 833 weak_factory_.GetWeakPtr(), begin_frame_args)); |
824 } | 834 } |
825 | 835 |
826 void SingleThreadProxy::SendBeginMainFrameNotExpectedSoon() { | 836 void SingleThreadProxy::SendBeginMainFrameNotExpectedSoon() { |
827 layer_tree_host_->BeginMainFrameNotExpectedSoon(); | 837 layer_tree_host_->BeginMainFrameNotExpectedSoon(); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 } | 981 } |
972 | 982 |
973 base::TimeDelta SingleThreadProxy::BeginMainFrameToCommitDurationEstimate() { | 983 base::TimeDelta SingleThreadProxy::BeginMainFrameToCommitDurationEstimate() { |
974 return timing_history_.BeginMainFrameToCommitDurationEstimate(); | 984 return timing_history_.BeginMainFrameToCommitDurationEstimate(); |
975 } | 985 } |
976 | 986 |
977 base::TimeDelta SingleThreadProxy::CommitToActivateDurationEstimate() { | 987 base::TimeDelta SingleThreadProxy::CommitToActivateDurationEstimate() { |
978 return timing_history_.CommitToActivateDurationEstimate(); | 988 return timing_history_.CommitToActivateDurationEstimate(); |
979 } | 989 } |
980 | 990 |
981 void SingleThreadProxy::DidBeginImplFrameDeadline() { | 991 void SingleThreadProxy::DidFinishImplFrame() { |
982 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame(); | 992 layer_tree_host_impl_->DidFinishImplFrame(); |
| 993 #if DCHECK_IS_ON() |
983 DCHECK(inside_impl_frame_) | 994 DCHECK(inside_impl_frame_) |
984 << "DidBeginImplFrameDeadline called while not inside an impl frame!"; | 995 << "DidFinishImplFrame called while not inside an impl frame!"; |
985 inside_impl_frame_ = false; | 996 inside_impl_frame_ = false; |
| 997 #endif |
986 } | 998 } |
987 | 999 |
988 void SingleThreadProxy::SendBeginFramesToChildren(const BeginFrameArgs& args) { | 1000 void SingleThreadProxy::SendBeginFramesToChildren(const BeginFrameArgs& args) { |
989 layer_tree_host_->SendBeginFramesToChildren(args); | 1001 layer_tree_host_->SendBeginFramesToChildren(args); |
990 } | 1002 } |
991 | 1003 |
992 } // namespace cc | 1004 } // namespace cc |
OLD | NEW |