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