| 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/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/profiler/scoped_tracker.h" | 9 #include "base/profiler/scoped_tracker.h" |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 next_frame_is_newly_committed_frame_(false), | 43 next_frame_is_newly_committed_frame_(false), |
| 44 #if DCHECK_IS_ON() | 44 #if DCHECK_IS_ON() |
| 45 inside_impl_frame_(false), | 45 inside_impl_frame_(false), |
| 46 #endif | 46 #endif |
| 47 inside_draw_(false), | 47 inside_draw_(false), |
| 48 defer_commits_(false), | 48 defer_commits_(false), |
| 49 animate_requested_(false), | 49 animate_requested_(false), |
| 50 commit_requested_(false), | 50 commit_requested_(false), |
| 51 inside_synchronous_composite_(false), | 51 inside_synchronous_composite_(false), |
| 52 output_surface_creation_requested_(false), | 52 output_surface_creation_requested_(false), |
| 53 output_surface_lost_(true), |
| 53 weak_factory_(this) { | 54 weak_factory_(this) { |
| 54 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); | 55 TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); |
| 55 DCHECK(task_runner_provider_); | 56 DCHECK(task_runner_provider_); |
| 56 DCHECK(task_runner_provider_->IsMainThread()); | 57 DCHECK(task_runner_provider_->IsMainThread()); |
| 57 DCHECK(layer_tree_host); | 58 DCHECK(layer_tree_host); |
| 58 } | 59 } |
| 59 | 60 |
| 60 void SingleThreadProxy::Start( | 61 void SingleThreadProxy::Start( |
| 61 std::unique_ptr<BeginFrameSource> external_begin_frame_source) { | 62 std::unique_ptr<BeginFrameSource> external_begin_frame_source) { |
| 62 DebugScopedSetImplThread impl(task_runner_provider_); | 63 DebugScopedSetImplThread impl(task_runner_provider_); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 DebugScopedSetImplThread impl(task_runner_provider_); | 125 DebugScopedSetImplThread impl(task_runner_provider_); |
| 125 | 126 |
| 126 layer_tree_host_impl_->SetVisible(visible); | 127 layer_tree_host_impl_->SetVisible(visible); |
| 127 | 128 |
| 128 if (scheduler_on_impl_thread_) | 129 if (scheduler_on_impl_thread_) |
| 129 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); | 130 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); |
| 130 } | 131 } |
| 131 | 132 |
| 132 void SingleThreadProxy::RequestNewOutputSurface() { | 133 void SingleThreadProxy::RequestNewOutputSurface() { |
| 133 DCHECK(task_runner_provider_->IsMainThread()); | 134 DCHECK(task_runner_provider_->IsMainThread()); |
| 134 DCHECK(layer_tree_host_->output_surface_lost()); | |
| 135 output_surface_creation_callback_.Cancel(); | 135 output_surface_creation_callback_.Cancel(); |
| 136 if (output_surface_creation_requested_) | 136 if (output_surface_creation_requested_) |
| 137 return; | 137 return; |
| 138 output_surface_creation_requested_ = true; | 138 output_surface_creation_requested_ = true; |
| 139 layer_tree_host_->RequestNewOutputSurface(); | 139 layer_tree_host_->RequestNewOutputSurface(); |
| 140 } | 140 } |
| 141 | 141 |
| 142 void SingleThreadProxy::ReleaseOutputSurface() { | 142 void SingleThreadProxy::ReleaseOutputSurface() { |
| 143 // |layer_tree_host_| should already be aware of this. | |
| 144 DCHECK(layer_tree_host_->output_surface_lost()); | |
| 145 | |
| 146 if (scheduler_on_impl_thread_) | 143 if (scheduler_on_impl_thread_) |
| 147 scheduler_on_impl_thread_->DidLoseOutputSurface(); | 144 scheduler_on_impl_thread_->DidLoseOutputSurface(); |
| 148 return layer_tree_host_impl_->ReleaseOutputSurface(); | 145 return layer_tree_host_impl_->ReleaseOutputSurface(); |
| 149 } | 146 } |
| 150 | 147 |
| 151 void SingleThreadProxy::SetOutputSurface(OutputSurface* output_surface) { | 148 void SingleThreadProxy::SetOutputSurface(OutputSurface* output_surface) { |
| 152 DCHECK(task_runner_provider_->IsMainThread()); | 149 DCHECK(task_runner_provider_->IsMainThread()); |
| 153 DCHECK(layer_tree_host_->output_surface_lost()); | |
| 154 DCHECK(output_surface_creation_requested_); | 150 DCHECK(output_surface_creation_requested_); |
| 155 | 151 |
| 156 bool success; | 152 bool success; |
| 157 { | 153 { |
| 158 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); | 154 DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); |
| 159 DebugScopedSetImplThread impl(task_runner_provider_); | 155 DebugScopedSetImplThread impl(task_runner_provider_); |
| 160 success = layer_tree_host_impl_->InitializeRenderer(output_surface); | 156 success = layer_tree_host_impl_->InitializeRenderer(output_surface); |
| 161 } | 157 } |
| 162 | 158 |
| 163 if (success) { | 159 if (success) { |
| 164 layer_tree_host_->DidInitializeOutputSurface(); | 160 layer_tree_host_->DidInitializeOutputSurface(); |
| 165 if (scheduler_on_impl_thread_) | 161 if (scheduler_on_impl_thread_) |
| 166 scheduler_on_impl_thread_->DidCreateAndInitializeOutputSurface(); | 162 scheduler_on_impl_thread_->DidCreateAndInitializeOutputSurface(); |
| 167 else if (!inside_synchronous_composite_) | 163 else if (!inside_synchronous_composite_) |
| 168 SetNeedsCommit(); | 164 SetNeedsCommit(); |
| 169 output_surface_creation_requested_ = false; | 165 output_surface_creation_requested_ = false; |
| 166 output_surface_lost_ = false; |
| 170 } else { | 167 } else { |
| 171 // DidFailToInitializeOutputSurface is treated as a RequestNewOutputSurface, | 168 // DidFailToInitializeOutputSurface is treated as a RequestNewOutputSurface, |
| 172 // and so output_surface_creation_requested remains true. | 169 // and so output_surface_creation_requested remains true. |
| 173 layer_tree_host_->DidFailToInitializeOutputSurface(); | 170 layer_tree_host_->DidFailToInitializeOutputSurface(); |
| 174 } | 171 } |
| 175 } | 172 } |
| 176 | 173 |
| 177 void SingleThreadProxy::SetNeedsAnimate() { | 174 void SingleThreadProxy::SetNeedsAnimate() { |
| 178 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsAnimate"); | 175 TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsAnimate"); |
| 179 DCHECK(task_runner_provider_->IsMainThread()); | 176 DCHECK(task_runner_provider_->IsMainThread()); |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread"); | 451 TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread"); |
| 455 { | 452 { |
| 456 DebugScopedSetMainThread main(task_runner_provider_); | 453 DebugScopedSetMainThread main(task_runner_provider_); |
| 457 // This must happen before we notify the scheduler as it may try to recreate | 454 // 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. | 455 // the output surface if already in BEGIN_IMPL_FRAME_STATE_IDLE. |
| 459 layer_tree_host_->DidLoseOutputSurface(); | 456 layer_tree_host_->DidLoseOutputSurface(); |
| 460 } | 457 } |
| 461 client_->DidAbortSwapBuffers(); | 458 client_->DidAbortSwapBuffers(); |
| 462 if (scheduler_on_impl_thread_) | 459 if (scheduler_on_impl_thread_) |
| 463 scheduler_on_impl_thread_->DidLoseOutputSurface(); | 460 scheduler_on_impl_thread_->DidLoseOutputSurface(); |
| 461 output_surface_lost_ = true; |
| 464 } | 462 } |
| 465 | 463 |
| 466 void SingleThreadProxy::CommitVSyncParameters(base::TimeTicks timebase, | 464 void SingleThreadProxy::CommitVSyncParameters(base::TimeTicks timebase, |
| 467 base::TimeDelta interval) { | 465 base::TimeDelta interval) { |
| 468 if (synthetic_begin_frame_source_) | 466 if (synthetic_begin_frame_source_) |
| 469 synthetic_begin_frame_source_->OnUpdateVSyncParameters(timebase, interval); | 467 synthetic_begin_frame_source_->OnUpdateVSyncParameters(timebase, interval); |
| 470 } | 468 } |
| 471 | 469 |
| 472 void SingleThreadProxy::SetBeginFrameSource(BeginFrameSource* source) { | 470 void SingleThreadProxy::SetBeginFrameSource(BeginFrameSource* source) { |
| 473 DCHECK(layer_tree_host_->settings().single_thread_proxy_scheduler); | 471 DCHECK(layer_tree_host_->settings().single_thread_proxy_scheduler); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 498 } | 496 } |
| 499 | 497 |
| 500 void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { | 498 void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { |
| 501 TRACE_EVENT0("cc,benchmark", "SingleThreadProxy::CompositeImmediately"); | 499 TRACE_EVENT0("cc,benchmark", "SingleThreadProxy::CompositeImmediately"); |
| 502 DCHECK(task_runner_provider_->IsMainThread()); | 500 DCHECK(task_runner_provider_->IsMainThread()); |
| 503 #if DCHECK_IS_ON() | 501 #if DCHECK_IS_ON() |
| 504 DCHECK(!inside_impl_frame_); | 502 DCHECK(!inside_impl_frame_); |
| 505 #endif | 503 #endif |
| 506 base::AutoReset<bool> inside_composite(&inside_synchronous_composite_, true); | 504 base::AutoReset<bool> inside_composite(&inside_synchronous_composite_, true); |
| 507 | 505 |
| 508 if (layer_tree_host_->output_surface_lost()) { | 506 if (output_surface_lost_) { |
| 509 RequestNewOutputSurface(); | 507 RequestNewOutputSurface(); |
| 510 // RequestNewOutputSurface could have synchronously created an output | 508 // RequestNewOutputSurface could have synchronously created an output |
| 511 // surface, so check again before returning. | 509 // surface, so check again before returning. |
| 512 if (layer_tree_host_->output_surface_lost()) | 510 if (output_surface_lost_) |
| 513 return; | 511 return; |
| 514 } | 512 } |
| 515 | 513 |
| 516 BeginFrameArgs begin_frame_args(BeginFrameArgs::Create( | 514 BeginFrameArgs begin_frame_args(BeginFrameArgs::Create( |
| 517 BEGINFRAME_FROM_HERE, frame_begin_time, base::TimeTicks(), | 515 BEGINFRAME_FROM_HERE, frame_begin_time, base::TimeTicks(), |
| 518 BeginFrameArgs::DefaultInterval(), BeginFrameArgs::NORMAL)); | 516 BeginFrameArgs::DefaultInterval(), BeginFrameArgs::NORMAL)); |
| 519 | 517 |
| 520 // Start the impl frame. | 518 // Start the impl frame. |
| 521 { | 519 { |
| 522 DebugScopedSetImplThread impl(task_runner_provider_); | 520 DebugScopedSetImplThread impl(task_runner_provider_); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 output_surface_creation_callback_.Reset( | 572 output_surface_creation_callback_.Reset( |
| 575 base::Bind(&SingleThreadProxy::RequestNewOutputSurface, | 573 base::Bind(&SingleThreadProxy::RequestNewOutputSurface, |
| 576 weak_factory_.GetWeakPtr())); | 574 weak_factory_.GetWeakPtr())); |
| 577 task_runner_provider_->MainThreadTaskRunner()->PostTask( | 575 task_runner_provider_->MainThreadTaskRunner()->PostTask( |
| 578 FROM_HERE, output_surface_creation_callback_.callback()); | 576 FROM_HERE, output_surface_creation_callback_.callback()); |
| 579 } | 577 } |
| 580 } | 578 } |
| 581 | 579 |
| 582 DrawResult SingleThreadProxy::DoComposite(LayerTreeHostImpl::FrameData* frame) { | 580 DrawResult SingleThreadProxy::DoComposite(LayerTreeHostImpl::FrameData* frame) { |
| 583 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite"); | 581 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite"); |
| 584 DCHECK(!layer_tree_host_->output_surface_lost()); | |
| 585 | 582 |
| 586 DrawResult draw_result; | 583 DrawResult draw_result; |
| 587 bool draw_frame; | 584 bool draw_frame; |
| 588 { | 585 { |
| 589 DebugScopedSetImplThread impl(task_runner_provider_); | 586 DebugScopedSetImplThread impl(task_runner_provider_); |
| 590 base::AutoReset<bool> mark_inside(&inside_draw_, true); | 587 base::AutoReset<bool> mark_inside(&inside_draw_, true); |
| 591 | 588 |
| 592 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 | 589 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 593 // is fixed. | 590 // is fixed. |
| 594 tracked_objects::ScopedTracker tracking_profile1( | 591 tracked_objects::ScopedTracker tracking_profile1( |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 | 675 |
| 679 void SingleThreadProxy::DidCommitAndDrawFrame() { | 676 void SingleThreadProxy::DidCommitAndDrawFrame() { |
| 680 if (next_frame_is_newly_committed_frame_) { | 677 if (next_frame_is_newly_committed_frame_) { |
| 681 DebugScopedSetMainThread main(task_runner_provider_); | 678 DebugScopedSetMainThread main(task_runner_provider_); |
| 682 next_frame_is_newly_committed_frame_ = false; | 679 next_frame_is_newly_committed_frame_ = false; |
| 683 layer_tree_host_->DidCommitAndDrawFrame(); | 680 layer_tree_host_->DidCommitAndDrawFrame(); |
| 684 } | 681 } |
| 685 } | 682 } |
| 686 | 683 |
| 687 bool SingleThreadProxy::MainFrameWillHappenForTesting() { | 684 bool SingleThreadProxy::MainFrameWillHappenForTesting() { |
| 688 if (layer_tree_host_->output_surface_lost()) | |
| 689 return false; | |
| 690 if (!scheduler_on_impl_thread_) | 685 if (!scheduler_on_impl_thread_) |
| 691 return false; | 686 return false; |
| 692 return scheduler_on_impl_thread_->MainFrameForTestingWillHappen(); | 687 return scheduler_on_impl_thread_->MainFrameForTestingWillHappen(); |
| 693 } | 688 } |
| 694 | 689 |
| 695 void SingleThreadProxy::WillBeginImplFrame(const BeginFrameArgs& args) { | 690 void SingleThreadProxy::WillBeginImplFrame(const BeginFrameArgs& args) { |
| 696 DebugScopedSetImplThread impl(task_runner_provider_); | 691 DebugScopedSetImplThread impl(task_runner_provider_); |
| 697 #if DCHECK_IS_ON() | 692 #if DCHECK_IS_ON() |
| 698 DCHECK(!inside_impl_frame_) | 693 DCHECK(!inside_impl_frame_) |
| 699 << "WillBeginImplFrame called while already inside an impl frame!"; | 694 << "WillBeginImplFrame called while already inside an impl frame!"; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 // commit. | 742 // commit. |
| 748 ScopedAbortRemainingSwapPromises swap_promise_checker(layer_tree_host_); | 743 ScopedAbortRemainingSwapPromises swap_promise_checker(layer_tree_host_); |
| 749 | 744 |
| 750 if (!layer_tree_host_->visible()) { | 745 if (!layer_tree_host_->visible()) { |
| 751 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD); | 746 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NotVisible", TRACE_EVENT_SCOPE_THREAD); |
| 752 BeginMainFrameAbortedOnImplThread( | 747 BeginMainFrameAbortedOnImplThread( |
| 753 CommitEarlyOutReason::ABORTED_NOT_VISIBLE); | 748 CommitEarlyOutReason::ABORTED_NOT_VISIBLE); |
| 754 return; | 749 return; |
| 755 } | 750 } |
| 756 | 751 |
| 757 if (layer_tree_host_->output_surface_lost()) { | |
| 758 TRACE_EVENT_INSTANT0("cc", "EarlyOut_OutputSurfaceLost", | |
| 759 TRACE_EVENT_SCOPE_THREAD); | |
| 760 BeginMainFrameAbortedOnImplThread( | |
| 761 CommitEarlyOutReason::ABORTED_OUTPUT_SURFACE_LOST); | |
| 762 return; | |
| 763 } | |
| 764 | |
| 765 // Prevent new commits from being requested inside DoBeginMainFrame. | 752 // Prevent new commits from being requested inside DoBeginMainFrame. |
| 766 // Note: We do not want to prevent SetNeedsAnimate from requesting | 753 // Note: We do not want to prevent SetNeedsAnimate from requesting |
| 767 // a commit here. | 754 // a commit here. |
| 768 commit_requested_ = true; | 755 commit_requested_ = true; |
| 769 | 756 |
| 770 DoBeginMainFrame(begin_frame_args); | 757 DoBeginMainFrame(begin_frame_args); |
| 771 } | 758 } |
| 772 | 759 |
| 773 void SingleThreadProxy::DoBeginMainFrame( | 760 void SingleThreadProxy::DoBeginMainFrame( |
| 774 const BeginFrameArgs& begin_frame_args) { | 761 const BeginFrameArgs& begin_frame_args) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 void SingleThreadProxy::DidFinishImplFrame() { | 850 void SingleThreadProxy::DidFinishImplFrame() { |
| 864 layer_tree_host_impl_->DidFinishImplFrame(); | 851 layer_tree_host_impl_->DidFinishImplFrame(); |
| 865 #if DCHECK_IS_ON() | 852 #if DCHECK_IS_ON() |
| 866 DCHECK(inside_impl_frame_) | 853 DCHECK(inside_impl_frame_) |
| 867 << "DidFinishImplFrame called while not inside an impl frame!"; | 854 << "DidFinishImplFrame called while not inside an impl frame!"; |
| 868 inside_impl_frame_ = false; | 855 inside_impl_frame_ = false; |
| 869 #endif | 856 #endif |
| 870 } | 857 } |
| 871 | 858 |
| 872 } // namespace cc | 859 } // namespace cc |
| OLD | NEW |