| 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/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 9 #include "cc/debug/benchmark_instrumentation.h" | 10 #include "cc/debug/benchmark_instrumentation.h" |
| 10 #include "cc/debug/devtools_instrumentation.h" | 11 #include "cc/debug/devtools_instrumentation.h" |
| 11 #include "cc/output/context_provider.h" | 12 #include "cc/output/context_provider.h" |
| 12 #include "cc/output/output_surface.h" | 13 #include "cc/output/output_surface.h" |
| 13 #include "cc/quads/draw_quad.h" | 14 #include "cc/quads/draw_quad.h" |
| 14 #include "cc/resources/prioritized_resource_manager.h" | 15 #include "cc/resources/prioritized_resource_manager.h" |
| 15 #include "cc/resources/resource_update_controller.h" | 16 #include "cc/resources/resource_update_controller.h" |
| 16 #include "cc/scheduler/commit_earlyout_reason.h" | 17 #include "cc/scheduler/commit_earlyout_reason.h" |
| 17 #include "cc/trees/layer_tree_host.h" | 18 #include "cc/trees/layer_tree_host.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 } | 90 } |
| 90 | 91 |
| 91 void SingleThreadProxy::SetLayerTreeHostClientReady() { | 92 void SingleThreadProxy::SetLayerTreeHostClientReady() { |
| 92 TRACE_EVENT0("cc", "SingleThreadProxy::SetLayerTreeHostClientReady"); | 93 TRACE_EVENT0("cc", "SingleThreadProxy::SetLayerTreeHostClientReady"); |
| 93 // Scheduling is controlled by the embedder in the single thread case, so | 94 // Scheduling is controlled by the embedder in the single thread case, so |
| 94 // nothing to do. | 95 // nothing to do. |
| 95 DCHECK(Proxy::IsMainThread()); | 96 DCHECK(Proxy::IsMainThread()); |
| 96 DebugScopedSetImplThread impl(this); | 97 DebugScopedSetImplThread impl(this); |
| 97 if (layer_tree_host_->settings().single_thread_proxy_scheduler && | 98 if (layer_tree_host_->settings().single_thread_proxy_scheduler && |
| 98 !scheduler_on_impl_thread_) { | 99 !scheduler_on_impl_thread_) { |
| 99 SchedulerSettings scheduler_settings(layer_tree_host_->settings()); | 100 SchedulerSettings scheduler_settings( |
| 101 layer_tree_host_->settings().ToSchedulerSettings()); |
| 100 // SingleThreadProxy should run in main thread low latency mode. | 102 // SingleThreadProxy should run in main thread low latency mode. |
| 101 scheduler_settings.main_thread_should_always_be_low_latency = true; | 103 scheduler_settings.main_thread_should_always_be_low_latency = true; |
| 102 scheduler_on_impl_thread_ = | 104 scheduler_on_impl_thread_ = |
| 103 Scheduler::Create(this, | 105 Scheduler::Create(this, |
| 104 scheduler_settings, | 106 scheduler_settings, |
| 105 layer_tree_host_->id(), | 107 layer_tree_host_->id(), |
| 106 MainThreadTaskRunner(), | 108 MainThreadTaskRunner(), |
| 107 external_begin_frame_source_.Pass()); | 109 external_begin_frame_source_.Pass()); |
| 108 scheduler_on_impl_thread_->SetCanStart(); | 110 scheduler_on_impl_thread_->SetCanStart(); |
| 109 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); | 111 scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 // won't happen in DoComposite. | 203 // won't happen in DoComposite. |
| 202 if (!layer_tree_host_impl_->AnimationsAreVisible()) { | 204 if (!layer_tree_host_impl_->AnimationsAreVisible()) { |
| 203 layer_tree_host_impl_->UpdateAnimationState(true); | 205 layer_tree_host_impl_->UpdateAnimationState(true); |
| 204 } | 206 } |
| 205 } | 207 } |
| 206 | 208 |
| 207 void SingleThreadProxy::DoCommit() { | 209 void SingleThreadProxy::DoCommit() { |
| 208 TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit"); | 210 TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit"); |
| 209 DCHECK(Proxy::IsMainThread()); | 211 DCHECK(Proxy::IsMainThread()); |
| 210 | 212 |
| 213 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 is |
| 214 // fixed. |
| 215 tracked_objects::ScopedTracker tracking_profile1( |
| 216 FROM_HERE_WITH_EXPLICIT_FUNCTION("461509 SingleThreadProxy::DoCommit1")); |
| 211 commit_requested_ = false; | 217 commit_requested_ = false; |
| 212 layer_tree_host_->WillCommit(); | 218 layer_tree_host_->WillCommit(); |
| 213 devtools_instrumentation::ScopedCommitTrace commit_task( | 219 devtools_instrumentation::ScopedCommitTrace commit_task( |
| 214 layer_tree_host_->id()); | 220 layer_tree_host_->id()); |
| 215 | 221 |
| 216 // Commit immediately. | 222 // Commit immediately. |
| 217 { | 223 { |
| 224 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 225 // is fixed. |
| 226 tracked_objects::ScopedTracker tracking_profile2( |
| 227 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 228 "461509 SingleThreadProxy::DoCommit2")); |
| 218 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 229 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 219 DebugScopedSetImplThread impl(this); | 230 DebugScopedSetImplThread impl(this); |
| 220 | 231 |
| 221 // This CapturePostTasks should be destroyed before CommitComplete() is | 232 // This CapturePostTasks should be destroyed before CommitComplete() is |
| 222 // called since that goes out to the embedder, and we want the embedder | 233 // called since that goes out to the embedder, and we want the embedder |
| 223 // to receive its callbacks before that. | 234 // to receive its callbacks before that. |
| 224 commit_blocking_task_runner_.reset(new BlockingTaskRunner::CapturePostTasks( | 235 commit_blocking_task_runner_.reset(new BlockingTaskRunner::CapturePostTasks( |
| 225 blocking_main_thread_task_runner())); | 236 blocking_main_thread_task_runner())); |
| 226 | 237 |
| 227 layer_tree_host_impl_->BeginCommit(); | 238 layer_tree_host_impl_->BeginCommit(); |
| 228 | 239 |
| 229 if (PrioritizedResourceManager* contents_texture_manager = | 240 if (PrioritizedResourceManager* contents_texture_manager = |
| 230 layer_tree_host_->contents_texture_manager()) { | 241 layer_tree_host_->contents_texture_manager()) { |
| 242 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 243 // is fixed. |
| 244 tracked_objects::ScopedTracker tracking_profile3( |
| 245 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 246 "461509 SingleThreadProxy::DoCommit3")); |
| 231 contents_texture_manager->PushTexturePrioritiesToBackings(); | 247 contents_texture_manager->PushTexturePrioritiesToBackings(); |
| 232 } | 248 } |
| 233 layer_tree_host_->BeginCommitOnImplThread(layer_tree_host_impl_.get()); | 249 layer_tree_host_->BeginCommitOnImplThread(layer_tree_host_impl_.get()); |
| 234 | 250 |
| 251 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 252 // is fixed. |
| 253 tracked_objects::ScopedTracker tracking_profile4( |
| 254 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 255 "461509 SingleThreadProxy::DoCommit4")); |
| 235 scoped_ptr<ResourceUpdateController> update_controller = | 256 scoped_ptr<ResourceUpdateController> update_controller = |
| 236 ResourceUpdateController::Create( | 257 ResourceUpdateController::Create( |
| 237 NULL, | 258 NULL, |
| 238 MainThreadTaskRunner(), | 259 MainThreadTaskRunner(), |
| 239 queue_for_commit_.Pass(), | 260 queue_for_commit_.Pass(), |
| 240 layer_tree_host_impl_->resource_provider()); | 261 layer_tree_host_impl_->resource_provider()); |
| 262 |
| 263 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 264 // is fixed. |
| 265 tracked_objects::ScopedTracker tracking_profile5( |
| 266 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 267 "461509 SingleThreadProxy::DoCommit5")); |
| 241 update_controller->Finalize(); | 268 update_controller->Finalize(); |
| 242 | 269 |
| 270 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 271 // is fixed. |
| 272 tracked_objects::ScopedTracker tracking_profile6( |
| 273 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 274 "461509 SingleThreadProxy::DoCommit6")); |
| 243 if (layer_tree_host_impl_->EvictedUIResourcesExist()) | 275 if (layer_tree_host_impl_->EvictedUIResourcesExist()) |
| 244 layer_tree_host_->RecreateUIResources(); | 276 layer_tree_host_->RecreateUIResources(); |
| 245 | 277 |
| 278 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 279 // is fixed. |
| 280 tracked_objects::ScopedTracker tracking_profile7( |
| 281 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 282 "461509 SingleThreadProxy::DoCommit7")); |
| 246 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get()); | 283 layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get()); |
| 247 | 284 |
| 248 #if DCHECK_IS_ON() | 285 #if DCHECK_IS_ON() |
| 249 // In the single-threaded case, the scale and scroll deltas should never be | 286 // In the single-threaded case, the scale and scroll deltas should never be |
| 250 // touched on the impl layer tree. | 287 // touched on the impl layer tree. |
| 251 scoped_ptr<ScrollAndScaleSet> scroll_info = | 288 scoped_ptr<ScrollAndScaleSet> scroll_info = |
| 252 layer_tree_host_impl_->ProcessScrollDeltas(); | 289 layer_tree_host_impl_->ProcessScrollDeltas(); |
| 253 DCHECK(!scroll_info->scrolls.size()); | 290 DCHECK(!scroll_info->scrolls.size()); |
| 254 DCHECK_EQ(1.f, scroll_info->page_scale_delta); | 291 DCHECK_EQ(1.f, scroll_info->page_scale_delta); |
| 255 #endif | 292 #endif |
| 256 | 293 |
| 257 if (layer_tree_host_->settings().impl_side_painting) { | 294 if (layer_tree_host_->settings().impl_side_painting) { |
| 295 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 296 // is fixed. |
| 297 tracked_objects::ScopedTracker tracking_profile8( |
| 298 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 299 "461509 SingleThreadProxy::DoCommit8")); |
| 258 // Commit goes directly to the active tree, but we need to synchronously | 300 // Commit goes directly to the active tree, but we need to synchronously |
| 259 // "activate" the tree still during commit to satisfy any potential | 301 // "activate" the tree still during commit to satisfy any potential |
| 260 // SetNextCommitWaitsForActivation calls. Unfortunately, the tree | 302 // SetNextCommitWaitsForActivation calls. Unfortunately, the tree |
| 261 // might not be ready to draw, so DidActivateSyncTree must set | 303 // might not be ready to draw, so DidActivateSyncTree must set |
| 262 // the flag to force the tree to not draw until textures are ready. | 304 // the flag to force the tree to not draw until textures are ready. |
| 263 NotifyReadyToActivate(); | 305 NotifyReadyToActivate(); |
| 264 } else { | 306 } else { |
| 307 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 308 // is fixed. |
| 309 tracked_objects::ScopedTracker tracking_profile9( |
| 310 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 311 "461509 SingleThreadProxy::DoCommit9")); |
| 265 CommitComplete(); | 312 CommitComplete(); |
| 266 } | 313 } |
| 267 } | 314 } |
| 268 } | 315 } |
| 269 | 316 |
| 270 void SingleThreadProxy::CommitComplete() { | 317 void SingleThreadProxy::CommitComplete() { |
| 271 DCHECK(!layer_tree_host_impl_->pending_tree()) | 318 DCHECK(!layer_tree_host_impl_->pending_tree()) |
| 272 << "Activation is expected to have synchronously occurred by now."; | 319 << "Activation is expected to have synchronously occurred by now."; |
| 273 DCHECK(commit_blocking_task_runner_); | 320 DCHECK(commit_blocking_task_runner_); |
| 274 | 321 |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 LayerTreeHostImpl::FrameData* frame) { | 636 LayerTreeHostImpl::FrameData* frame) { |
| 590 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite"); | 637 TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite"); |
| 591 DCHECK(!layer_tree_host_->output_surface_lost()); | 638 DCHECK(!layer_tree_host_->output_surface_lost()); |
| 592 | 639 |
| 593 DrawResult draw_result; | 640 DrawResult draw_result; |
| 594 bool draw_frame; | 641 bool draw_frame; |
| 595 { | 642 { |
| 596 DebugScopedSetImplThread impl(this); | 643 DebugScopedSetImplThread impl(this); |
| 597 base::AutoReset<bool> mark_inside(&inside_draw_, true); | 644 base::AutoReset<bool> mark_inside(&inside_draw_, true); |
| 598 | 645 |
| 646 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 647 // is fixed. |
| 648 tracked_objects::ScopedTracker tracking_profile1( |
| 649 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 650 "461509 SingleThreadProxy::DoComposite1")); |
| 651 |
| 599 // We guard PrepareToDraw() with CanDraw() because it always returns a valid | 652 // We guard PrepareToDraw() with CanDraw() because it always returns a valid |
| 600 // frame, so can only be used when such a frame is possible. Since | 653 // frame, so can only be used when such a frame is possible. Since |
| 601 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on | 654 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on |
| 602 // CanDraw() as well. | 655 // CanDraw() as well. |
| 603 if (!ShouldComposite()) { | 656 if (!ShouldComposite()) { |
| 604 return DRAW_ABORTED_CANT_DRAW; | 657 return DRAW_ABORTED_CANT_DRAW; |
| 605 } | 658 } |
| 606 | 659 |
| 607 timing_history_.DidStartDrawing(); | 660 timing_history_.DidStartDrawing(); |
| 608 | 661 |
| 662 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 663 // is fixed. |
| 664 tracked_objects::ScopedTracker tracking_profile2( |
| 665 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 666 "461509 SingleThreadProxy::DoComposite2")); |
| 609 draw_result = layer_tree_host_impl_->PrepareToDraw(frame); | 667 draw_result = layer_tree_host_impl_->PrepareToDraw(frame); |
| 610 draw_frame = draw_result == DRAW_SUCCESS; | 668 draw_frame = draw_result == DRAW_SUCCESS; |
| 611 if (draw_frame) | 669 if (draw_frame) { |
| 670 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 671 // is fixed. |
| 672 tracked_objects::ScopedTracker tracking_profile3( |
| 673 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 674 "461509 SingleThreadProxy::DoComposite3")); |
| 612 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time); | 675 layer_tree_host_impl_->DrawLayers(frame, frame_begin_time); |
| 676 } |
| 677 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 678 // is fixed. |
| 679 tracked_objects::ScopedTracker tracking_profile4( |
| 680 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 681 "461509 SingleThreadProxy::DoComposite4")); |
| 613 layer_tree_host_impl_->DidDrawAllLayers(*frame); | 682 layer_tree_host_impl_->DidDrawAllLayers(*frame); |
| 614 | 683 |
| 615 bool start_ready_animations = draw_frame; | 684 bool start_ready_animations = draw_frame; |
| 685 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 686 // is fixed. |
| 687 tracked_objects::ScopedTracker tracking_profile5( |
| 688 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 689 "461509 SingleThreadProxy::DoComposite5")); |
| 616 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); | 690 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); |
| 691 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 692 // is fixed. |
| 693 tracked_objects::ScopedTracker tracking_profile6( |
| 694 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 695 "461509 SingleThreadProxy::DoComposite6")); |
| 617 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame(); | 696 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame(); |
| 618 | 697 |
| 698 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 699 // is fixed. |
| 700 tracked_objects::ScopedTracker tracking_profile7( |
| 701 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 702 "461509 SingleThreadProxy::DoComposite7")); |
| 619 timing_history_.DidFinishDrawing(); | 703 timing_history_.DidFinishDrawing(); |
| 620 } | 704 } |
| 621 | 705 |
| 622 if (draw_frame) { | 706 if (draw_frame) { |
| 623 DebugScopedSetImplThread impl(this); | 707 DebugScopedSetImplThread impl(this); |
| 624 | 708 |
| 625 // This CapturePostTasks should be destroyed before | 709 // This CapturePostTasks should be destroyed before |
| 626 // DidCommitAndDrawFrame() is called since that goes out to the | 710 // DidCommitAndDrawFrame() is called since that goes out to the |
| 627 // embedder, | 711 // embedder, |
| 628 // and we want the embedder to receive its callbacks before that. | 712 // and we want the embedder to receive its callbacks before that. |
| 629 // NOTE: This maintains consistent ordering with the ThreadProxy since | 713 // NOTE: This maintains consistent ordering with the ThreadProxy since |
| 630 // the DidCommitAndDrawFrame() must be post-tasked from the impl thread | 714 // the DidCommitAndDrawFrame() must be post-tasked from the impl thread |
| 631 // there as the main thread is not blocked, so any posted tasks inside | 715 // there as the main thread is not blocked, so any posted tasks inside |
| 632 // the swap buffers will execute first. | 716 // the swap buffers will execute first. |
| 633 DebugScopedSetMainThreadBlocked main_thread_blocked(this); | 717 DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
| 634 | 718 |
| 635 BlockingTaskRunner::CapturePostTasks blocked( | 719 BlockingTaskRunner::CapturePostTasks blocked( |
| 636 blocking_main_thread_task_runner()); | 720 blocking_main_thread_task_runner()); |
| 721 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 |
| 722 // is fixed. |
| 723 tracked_objects::ScopedTracker tracking_profile8( |
| 724 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 725 "461509 SingleThreadProxy::DoComposite8")); |
| 637 layer_tree_host_impl_->SwapBuffers(*frame); | 726 layer_tree_host_impl_->SwapBuffers(*frame); |
| 638 } | 727 } |
| 728 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/461509 is |
| 729 // fixed. |
| 730 tracked_objects::ScopedTracker tracking_profile9( |
| 731 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 732 "461509 SingleThreadProxy::DoComposite9")); |
| 639 DidCommitAndDrawFrame(); | 733 DidCommitAndDrawFrame(); |
| 640 | 734 |
| 641 return draw_result; | 735 return draw_result; |
| 642 } | 736 } |
| 643 | 737 |
| 644 void SingleThreadProxy::DidCommitAndDrawFrame() { | 738 void SingleThreadProxy::DidCommitAndDrawFrame() { |
| 645 if (next_frame_is_newly_committed_frame_) { | 739 if (next_frame_is_newly_committed_frame_) { |
| 646 DebugScopedSetMainThread main(this); | 740 DebugScopedSetMainThread main(this); |
| 647 next_frame_is_newly_committed_frame_ = false; | 741 next_frame_is_newly_committed_frame_ = false; |
| 648 layer_tree_host_->DidCommitAndDrawFrame(); | 742 layer_tree_host_->DidCommitAndDrawFrame(); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 | 917 |
| 824 void SingleThreadProxy::DidBeginImplFrameDeadline() { | 918 void SingleThreadProxy::DidBeginImplFrameDeadline() { |
| 825 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame(); | 919 layer_tree_host_impl_->ResetCurrentBeginFrameArgsForNextFrame(); |
| 826 } | 920 } |
| 827 | 921 |
| 828 void SingleThreadProxy::SendBeginFramesToChildren(const BeginFrameArgs& args) { | 922 void SingleThreadProxy::SendBeginFramesToChildren(const BeginFrameArgs& args) { |
| 829 layer_tree_host_->SendBeginFramesToChildren(args); | 923 layer_tree_host_->SendBeginFramesToChildren(args); |
| 830 } | 924 } |
| 831 | 925 |
| 832 } // namespace cc | 926 } // namespace cc |
| OLD | NEW |