Chromium Code Reviews| 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/layer_tree_host.h" | 5 #include "cc/layer_tree_host.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 13 #include "cc/animation_registrar.h" | 13 #include "cc/animation_registrar.h" |
| 14 #include "cc/heads_up_display_layer.h" | 14 #include "cc/heads_up_display_layer.h" |
| 15 #include "cc/heads_up_display_layer_impl.h" | 15 #include "cc/heads_up_display_layer_impl.h" |
| 16 #include "cc/layer.h" | 16 #include "cc/layer.h" |
| 17 #include "cc/layer_animation_controller.h" | 17 #include "cc/layer_animation_controller.h" |
| 18 #include "cc/layer_iterator.h" | 18 #include "cc/layer_iterator.h" |
| 19 #include "cc/layer_tree_host_client.h" | 19 #include "cc/layer_tree_host_client.h" |
| 20 #include "cc/layer_tree_host_common.h" | 20 #include "cc/layer_tree_host_common.h" |
| 21 #include "cc/layer_tree_host_impl.h" | 21 #include "cc/layer_tree_host_impl.h" |
| 22 #include "cc/layer_tree_impl.h" | 22 #include "cc/layer_tree_impl.h" |
| 23 #include "cc/math_util.h" | 23 #include "cc/math_util.h" |
| 24 #include "cc/occlusion_tracker.h" | 24 #include "cc/occlusion_tracker.h" |
| 25 #include "cc/overdraw_metrics.h" | 25 #include "cc/overdraw_metrics.h" |
| 26 #include "cc/prioritized_resource_manager.h" | 26 #include "cc/prioritized_resource_manager.h" |
| 27 #include "cc/rendering_stats_instrumentation.h" | |
| 27 #include "cc/single_thread_proxy.h" | 28 #include "cc/single_thread_proxy.h" |
| 28 #include "cc/switches.h" | 29 #include "cc/switches.h" |
| 29 #include "cc/thread.h" | 30 #include "cc/thread.h" |
| 30 #include "cc/thread_proxy.h" | 31 #include "cc/thread_proxy.h" |
| 31 #include "cc/top_controls_manager.h" | 32 #include "cc/top_controls_manager.h" |
| 32 #include "cc/tree_synchronizer.h" | 33 #include "cc/tree_synchronizer.h" |
| 33 | 34 |
| 34 namespace { | 35 namespace { |
| 35 static int s_num_layer_tree_instances; | 36 static int s_num_layer_tree_instances; |
| 36 } | 37 } |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 67 return layer_tree_host.Pass(); | 68 return layer_tree_host.Pass(); |
| 68 } | 69 } |
| 69 | 70 |
| 70 LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, | 71 LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, |
| 71 const LayerTreeSettings& settings) | 72 const LayerTreeSettings& settings) |
| 72 : animating_(false), | 73 : animating_(false), |
| 73 needs_full_tree_sync_(true), | 74 needs_full_tree_sync_(true), |
| 74 needs_filter_context_(false), | 75 needs_filter_context_(false), |
| 75 client_(client), | 76 client_(client), |
| 76 commit_number_(0), | 77 commit_number_(0), |
| 77 rendering_stats_(), | 78 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()), |
| 78 renderer_initialized_(false), | 79 renderer_initialized_(false), |
| 79 output_surface_lost_(false), | 80 output_surface_lost_(false), |
| 80 num_failed_recreate_attempts_(0), | 81 num_failed_recreate_attempts_(0), |
| 81 settings_(settings), | 82 settings_(settings), |
| 82 debug_state_(settings.initialDebugState), | 83 debug_state_(settings.initialDebugState), |
| 83 device_scale_factor_(1.f), | 84 device_scale_factor_(1.f), |
| 84 visible_(true), | 85 visible_(true), |
| 85 page_scale_factor_(1.f), | 86 page_scale_factor_(1.f), |
| 86 min_page_scale_factor_(1.f), | 87 min_page_scale_factor_(1.f), |
| 87 max_page_scale_factor_(1.f), | 88 max_page_scale_factor_(1.f), |
| 88 trigger_idle_updates_(true), | 89 trigger_idle_updates_(true), |
| 89 background_color_(SK_ColorWHITE), | 90 background_color_(SK_ColorWHITE), |
| 90 has_transparent_background_(false), | 91 has_transparent_background_(false), |
| 91 partial_texture_update_requests_(0) { | 92 partial_texture_update_requests_(0) { |
| 92 if (settings_.acceleratedAnimationEnabled) | 93 if (settings_.acceleratedAnimationEnabled) |
| 93 animation_registrar_ = AnimationRegistrar::create(); | 94 animation_registrar_ = AnimationRegistrar::create(); |
| 94 s_num_layer_tree_instances++; | 95 s_num_layer_tree_instances++; |
| 96 | |
| 97 rendering_stats_instrumentation_->set_record_rendering_stats( | |
| 98 debug_state_.recordRenderingStats()); | |
| 95 } | 99 } |
| 96 | 100 |
| 97 bool LayerTreeHost::Initialize(scoped_ptr<Thread> impl_thread) { | 101 bool LayerTreeHost::Initialize(scoped_ptr<Thread> impl_thread) { |
| 98 if (impl_thread) | 102 if (impl_thread) |
| 99 return InitializeProxy(ThreadProxy::Create(this, impl_thread.Pass())); | 103 return InitializeProxy(ThreadProxy::Create(this, impl_thread.Pass())); |
| 100 else | 104 else |
| 101 return InitializeProxy(SingleThreadProxy::Create(this)); | 105 return InitializeProxy(SingleThreadProxy::Create(this)); |
| 102 } | 106 } |
| 103 | 107 |
| 104 bool LayerTreeHost::InitializeForTesting(scoped_ptr<Proxy> proxy_for_testing) { | 108 bool LayerTreeHost::InitializeForTesting(scoped_ptr<Proxy> proxy_for_testing) { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 void LayerTreeHost::DidBeginFrame() { | 224 void LayerTreeHost::DidBeginFrame() { |
| 221 client_->didBeginFrame(); | 225 client_->didBeginFrame(); |
| 222 } | 226 } |
| 223 | 227 |
| 224 void LayerTreeHost::UpdateAnimations(base::TimeTicks frame_begin_time) { | 228 void LayerTreeHost::UpdateAnimations(base::TimeTicks frame_begin_time) { |
| 225 animating_ = true; | 229 animating_ = true; |
| 226 client_->animate((frame_begin_time - base::TimeTicks()).InSecondsF()); | 230 client_->animate((frame_begin_time - base::TimeTicks()).InSecondsF()); |
| 227 AnimateLayers(frame_begin_time); | 231 AnimateLayers(frame_begin_time); |
| 228 animating_ = false; | 232 animating_ = false; |
| 229 | 233 |
| 230 rendering_stats_.numAnimationFrames++; | 234 rendering_stats_instrumentation_->IncrementAnimationFrameCount(); |
| 231 } | 235 } |
| 232 | 236 |
| 233 void LayerTreeHost::DidStopFlinging() { | 237 void LayerTreeHost::DidStopFlinging() { |
| 234 proxy_->MainThreadHasStoppedFlinging(); | 238 proxy_->MainThreadHasStoppedFlinging(); |
| 235 } | 239 } |
| 236 | 240 |
| 237 void LayerTreeHost::Layout() { | 241 void LayerTreeHost::Layout() { |
| 238 client_->layout(); | 242 client_->layout(); |
| 239 } | 243 } |
| 240 | 244 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 327 if (sync_tree->ContentsTexturesPurged()) | 331 if (sync_tree->ContentsTexturesPurged()) |
| 328 sync_tree->ResetContentsTexturesPurged(); | 332 sync_tree->ResetContentsTexturesPurged(); |
| 329 } | 333 } |
| 330 | 334 |
| 331 if (!settings_.implSidePainting) { | 335 if (!settings_.implSidePainting) { |
| 332 // If we're not in impl-side painting, the tree is immediately | 336 // If we're not in impl-side painting, the tree is immediately |
| 333 // considered active. | 337 // considered active. |
| 334 sync_tree->DidBecomeActive(); | 338 sync_tree->DidBecomeActive(); |
| 335 } | 339 } |
| 336 | 340 |
| 337 if (debug_state_.continuousPainting) | 341 if (debug_state_.continuousPainting) { |
| 338 host_impl->SavePaintTime(rendering_stats_.totalPaintTime, commit_number()); | 342 host_impl->SavePaintTime( |
| 343 rendering_stats_instrumentation_->GetRenderingStats().totalPaintTime, | |
| 344 commit_number()); | |
| 345 } | |
| 339 | 346 |
| 340 commit_number_++; | 347 commit_number_++; |
| 341 } | 348 } |
| 342 | 349 |
| 343 void LayerTreeHost::WillCommit() { | 350 void LayerTreeHost::WillCommit() { |
| 344 client_->willCommit(); | 351 client_->willCommit(); |
| 345 } | 352 } |
| 346 | 353 |
| 347 void LayerTreeHost::UpdateHudLayer() { | 354 void LayerTreeHost::UpdateHudLayer() { |
| 348 if (debug_state_.showHudInfo()) { | 355 if (debug_state_.showHudInfo()) { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 366 } | 373 } |
| 367 | 374 |
| 368 scoped_ptr<InputHandler> LayerTreeHost::CreateInputHandler() { | 375 scoped_ptr<InputHandler> LayerTreeHost::CreateInputHandler() { |
| 369 return client_->createInputHandler(); | 376 return client_->createInputHandler(); |
| 370 } | 377 } |
| 371 | 378 |
| 372 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl( | 379 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl( |
| 373 LayerTreeHostImplClient* client) { | 380 LayerTreeHostImplClient* client) { |
| 374 DCHECK(proxy_->IsImplThread()); | 381 DCHECK(proxy_->IsImplThread()); |
| 375 scoped_ptr<LayerTreeHostImpl> host_impl = | 382 scoped_ptr<LayerTreeHostImpl> host_impl = |
| 376 LayerTreeHostImpl::Create(settings_, client, proxy_.get()); | 383 LayerTreeHostImpl::Create(settings_, |
| 384 client, | |
| 385 proxy_.get(), | |
| 386 rendering_stats_instrumentation_.get()); | |
| 377 if (settings_.calculateTopControlsPosition && | 387 if (settings_.calculateTopControlsPosition && |
| 378 host_impl->top_controls_manager()) { | 388 host_impl->top_controls_manager()) { |
| 379 top_controls_manager_weak_ptr_ = | 389 top_controls_manager_weak_ptr_ = |
| 380 host_impl->top_controls_manager()->AsWeakPtr(); | 390 host_impl->top_controls_manager()->AsWeakPtr(); |
| 381 } | 391 } |
| 382 return host_impl.Pass(); | 392 return host_impl.Pass(); |
| 383 } | 393 } |
| 384 | 394 |
| 385 void LayerTreeHost::DidLoseOutputSurface() { | 395 void LayerTreeHost::DidLoseOutputSurface() { |
| 386 TRACE_EVENT0("cc", "LayerTreeHost::DidLoseOutputSurface"); | 396 TRACE_EVENT0("cc", "LayerTreeHost::DidLoseOutputSurface"); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 405 } | 415 } |
| 406 | 416 |
| 407 void LayerTreeHost::SetDeferCommits(bool defer_commits) { | 417 void LayerTreeHost::SetDeferCommits(bool defer_commits) { |
| 408 proxy_->SetDeferCommits(defer_commits); | 418 proxy_->SetDeferCommits(defer_commits); |
| 409 } | 419 } |
| 410 | 420 |
| 411 void LayerTreeHost::DidDeferCommit() {} | 421 void LayerTreeHost::DidDeferCommit() {} |
| 412 | 422 |
| 413 void LayerTreeHost::CollectRenderingStats(RenderingStats* stats) const { | 423 void LayerTreeHost::CollectRenderingStats(RenderingStats* stats) const { |
| 414 CHECK(debug_state_.recordRenderingStats()); | 424 CHECK(debug_state_.recordRenderingStats()); |
| 415 *stats = rendering_stats_; | 425 *stats = rendering_stats_instrumentation_->GetRenderingStats(); |
| 416 proxy_->CollectRenderingStats(stats); | |
| 417 } | 426 } |
| 418 | 427 |
| 419 const RendererCapabilities& LayerTreeHost::GetRendererCapabilities() const { | 428 const RendererCapabilities& LayerTreeHost::GetRendererCapabilities() const { |
| 420 return proxy_->GetRendererCapabilities(); | 429 return proxy_->GetRendererCapabilities(); |
| 421 } | 430 } |
| 422 | 431 |
| 423 void LayerTreeHost::SetNeedsAnimate() { | 432 void LayerTreeHost::SetNeedsAnimate() { |
| 424 DCHECK(proxy_->HasImplThread()); | 433 DCHECK(proxy_->HasImplThread()); |
| 425 proxy_->SetNeedsAnimate(); | 434 proxy_->SetNeedsAnimate(); |
| 426 } | 435 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 475 | 484 |
| 476 void LayerTreeHost::SetDebugState(const LayerTreeDebugState& debug_state) { | 485 void LayerTreeHost::SetDebugState(const LayerTreeDebugState& debug_state) { |
| 477 LayerTreeDebugState new_debug_state = | 486 LayerTreeDebugState new_debug_state = |
| 478 LayerTreeDebugState::unite(settings_.initialDebugState, debug_state); | 487 LayerTreeDebugState::unite(settings_.initialDebugState, debug_state); |
| 479 | 488 |
| 480 if (LayerTreeDebugState::equal(debug_state_, new_debug_state)) | 489 if (LayerTreeDebugState::equal(debug_state_, new_debug_state)) |
| 481 return; | 490 return; |
| 482 | 491 |
| 483 debug_state_ = new_debug_state; | 492 debug_state_ = new_debug_state; |
| 484 SetNeedsCommit(); | 493 SetNeedsCommit(); |
| 494 | |
| 495 rendering_stats_instrumentation_->set_record_rendering_stats( | |
|
danakj
2013/03/15 17:28:48
The general pattern is to change states, then call
egraether
2013/03/15 21:14:26
Done.
| |
| 496 debug_state_.recordRenderingStats()); | |
| 485 } | 497 } |
| 486 | 498 |
| 487 void LayerTreeHost::SetViewportSize(gfx::Size layout_viewport_size, | 499 void LayerTreeHost::SetViewportSize(gfx::Size layout_viewport_size, |
| 488 gfx::Size device_viewport_size) { | 500 gfx::Size device_viewport_size) { |
| 489 if (layout_viewport_size == layout_viewport_size_ && | 501 if (layout_viewport_size == layout_viewport_size_ && |
| 490 device_viewport_size == device_viewport_size_) | 502 device_viewport_size == device_viewport_size_) |
| 491 return; | 503 return; |
| 492 | 504 |
| 493 layout_viewport_size_ = layout_viewport_size; | 505 layout_viewport_size_ = layout_viewport_size; |
| 494 device_viewport_size_ = device_viewport_size; | 506 device_viewport_size_ = device_viewport_size; |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 707 max_background_texture_bytes = bytes; | 719 max_background_texture_bytes = bytes; |
| 708 if (!readback_bytes) { | 720 if (!readback_bytes) { |
| 709 readback_bytes = Resource::MemorySizeBytes(device_viewport_size_, | 721 readback_bytes = Resource::MemorySizeBytes(device_viewport_size_, |
| 710 GL_RGBA); | 722 GL_RGBA); |
| 711 } | 723 } |
| 712 } | 724 } |
| 713 return readback_bytes + max_background_texture_bytes + contents_texture_bytes; | 725 return readback_bytes + max_background_texture_bytes + contents_texture_bytes; |
| 714 } | 726 } |
| 715 | 727 |
| 716 bool LayerTreeHost::PaintMasksForRenderSurface(Layer* render_surface_layer, | 728 bool LayerTreeHost::PaintMasksForRenderSurface(Layer* render_surface_layer, |
| 717 ResourceUpdateQueue* queue) { | 729 ResourceUpdateQueue* queue, |
| 730 RenderingStats* stats) { | |
| 718 // Note: Masks and replicas only exist for layers that own render surfaces. If | 731 // Note: Masks and replicas only exist for layers that own render surfaces. If |
| 719 // we reach this point in code, we already know that at least something will | 732 // we reach this point in code, we already know that at least something will |
| 720 // be drawn into this render surface, so the mask and replica should be | 733 // be drawn into this render surface, so the mask and replica should be |
| 721 // painted. | 734 // painted. |
| 722 | 735 |
| 723 RenderingStats* stats = | |
| 724 debug_state_.recordRenderingStats() ? &rendering_stats_ : NULL; | |
| 725 | |
| 726 bool need_more_updates = false; | 736 bool need_more_updates = false; |
| 727 Layer* mask_layer = render_surface_layer->mask_layer(); | 737 Layer* mask_layer = render_surface_layer->mask_layer(); |
| 728 if (mask_layer) { | 738 if (mask_layer) { |
| 729 mask_layer->Update(queue, NULL, stats); | 739 mask_layer->Update(queue, NULL, stats); |
| 730 need_more_updates |= mask_layer->NeedMoreUpdates(); | 740 need_more_updates |= mask_layer->NeedMoreUpdates(); |
| 731 } | 741 } |
| 732 | 742 |
| 733 Layer* replica_mask_layer = | 743 Layer* replica_mask_layer = |
| 734 render_surface_layer->replica_layer() ? | 744 render_surface_layer->replica_layer() ? |
| 735 render_surface_layer->replica_layer()->mask_layer() : NULL; | 745 render_surface_layer->replica_layer()->mask_layer() : NULL; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 755 base::debug::TraceLog::GetInstance() && | 765 base::debug::TraceLog::GetInstance() && |
| 756 base::debug::TraceLog::GetInstance()->IsEnabled(); | 766 base::debug::TraceLog::GetInstance()->IsEnabled(); |
| 757 OcclusionTracker occlusion_tracker( | 767 OcclusionTracker occlusion_tracker( |
| 758 root_layer_->render_surface()->content_rect(), record_metrics_for_frame); | 768 root_layer_->render_surface()->content_rect(), record_metrics_for_frame); |
| 759 occlusion_tracker.set_minimum_tracking_size( | 769 occlusion_tracker.set_minimum_tracking_size( |
| 760 settings_.minimumOcclusionTrackingSize); | 770 settings_.minimumOcclusionTrackingSize); |
| 761 | 771 |
| 762 PrioritizeTextures(render_surface_layer_list, | 772 PrioritizeTextures(render_surface_layer_list, |
| 763 occlusion_tracker.overdraw_metrics()); | 773 occlusion_tracker.overdraw_metrics()); |
| 764 | 774 |
| 765 RenderingStats* stats = debug_state_.recordRenderingStats() ? | 775 // TODO(egraether): Use RenderingStatsInstrumentation in Layer::update() |
| 766 &rendering_stats_ : NULL; | 776 RenderingStats stats; |
| 777 RenderingStats* stats_ptr = | |
| 778 debug_state_.recordRenderingStats() ? &stats : NULL; | |
| 767 | 779 |
| 768 LayerIteratorType end = LayerIteratorType::end(&render_surface_layer_list); | 780 LayerIteratorType end = LayerIteratorType::end(&render_surface_layer_list); |
| 769 for (LayerIteratorType it = | 781 for (LayerIteratorType it = |
| 770 LayerIteratorType::begin(&render_surface_layer_list); | 782 LayerIteratorType::begin(&render_surface_layer_list); |
| 771 it != end; | 783 it != end; |
| 772 ++it) { | 784 ++it) { |
| 773 occlusion_tracker.EnterLayer(it); | 785 occlusion_tracker.EnterLayer(it); |
| 774 | 786 |
| 775 if (it.representsTargetRenderSurface()) { | 787 if (it.representsTargetRenderSurface()) { |
| 776 DCHECK(it->render_surface()->draw_opacity() || | 788 DCHECK(it->render_surface()->draw_opacity() || |
| 777 it->render_surface()->draw_opacity_is_animating()); | 789 it->render_surface()->draw_opacity_is_animating()); |
| 778 need_more_updates |= PaintMasksForRenderSurface(*it, queue); | 790 need_more_updates |= PaintMasksForRenderSurface(*it, queue, stats_ptr); |
| 779 } else if (it.representsItself()) { | 791 } else if (it.representsItself()) { |
| 780 DCHECK(!it->bounds().IsEmpty()); | 792 DCHECK(!it->bounds().IsEmpty()); |
| 781 it->Update(queue, &occlusion_tracker, stats); | 793 it->Update(queue, &occlusion_tracker, stats_ptr); |
| 782 need_more_updates |= it->NeedMoreUpdates(); | 794 need_more_updates |= it->NeedMoreUpdates(); |
| 783 } | 795 } |
| 784 | 796 |
| 785 occlusion_tracker.LeaveLayer(it); | 797 occlusion_tracker.LeaveLayer(it); |
| 786 } | 798 } |
| 787 | 799 |
| 800 rendering_stats_instrumentation_->AddStats(stats); | |
| 801 | |
| 788 occlusion_tracker.overdraw_metrics()->RecordMetrics(this); | 802 occlusion_tracker.overdraw_metrics()->RecordMetrics(this); |
| 789 | 803 |
| 790 return need_more_updates; | 804 return need_more_updates; |
| 791 } | 805 } |
| 792 | 806 |
| 793 void LayerTreeHost::ApplyScrollAndScale(const ScrollAndScaleSet& info) { | 807 void LayerTreeHost::ApplyScrollAndScale(const ScrollAndScaleSet& info) { |
| 794 if (!root_layer_) | 808 if (!root_layer_) |
| 795 return; | 809 return; |
| 796 | 810 |
| 797 Layer* root_scroll_layer = FindFirstScrollableLayer(root_layer_.get()); | 811 Layer* root_scroll_layer = FindFirstScrollableLayer(root_layer_.get()); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 939 SetAnimationEventsRecursive(events, | 953 SetAnimationEventsRecursive(events, |
| 940 layer->children()[child_index].get(), | 954 layer->children()[child_index].get(), |
| 941 wall_clock_time); | 955 wall_clock_time); |
| 942 } | 956 } |
| 943 | 957 |
| 944 skia::RefPtr<SkPicture> LayerTreeHost::CapturePicture() { | 958 skia::RefPtr<SkPicture> LayerTreeHost::CapturePicture() { |
| 945 return proxy_->CapturePicture(); | 959 return proxy_->CapturePicture(); |
| 946 } | 960 } |
| 947 | 961 |
| 948 } // namespace cc | 962 } // namespace cc |
| OLD | NEW |