Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: cc/trees/layer_tree_host.cc

Issue 12519006: cc:: Add RenderingStatsInstrumentation to manage collection of RenderingStats (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Updated all tests Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/trees/layer_tree_host.h ('k') | cc/trees/layer_tree_host_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/layer_tree_host.h" 5 #include "cc/trees/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/animation_registrar.h" 13 #include "cc/animation/animation_registrar.h"
14 #include "cc/animation/layer_animation_controller.h" 14 #include "cc/animation/layer_animation_controller.h"
15 #include "cc/base/math_util.h" 15 #include "cc/base/math_util.h"
16 #include "cc/base/thread.h" 16 #include "cc/base/thread.h"
17 #include "cc/debug/overdraw_metrics.h" 17 #include "cc/debug/overdraw_metrics.h"
18 #include "cc/debug/rendering_stats_instrumentation.h"
18 #include "cc/input/pinch_zoom_scrollbar.h" 19 #include "cc/input/pinch_zoom_scrollbar.h"
19 #include "cc/input/pinch_zoom_scrollbar_geometry.h" 20 #include "cc/input/pinch_zoom_scrollbar_geometry.h"
20 #include "cc/input/pinch_zoom_scrollbar_painter.h" 21 #include "cc/input/pinch_zoom_scrollbar_painter.h"
21 #include "cc/input/top_controls_manager.h" 22 #include "cc/input/top_controls_manager.h"
22 #include "cc/layers/heads_up_display_layer.h" 23 #include "cc/layers/heads_up_display_layer.h"
23 #include "cc/layers/heads_up_display_layer_impl.h" 24 #include "cc/layers/heads_up_display_layer_impl.h"
24 #include "cc/layers/layer.h" 25 #include "cc/layers/layer.h"
25 #include "cc/layers/layer_iterator.h" 26 #include "cc/layers/layer_iterator.h"
26 #include "cc/layers/scrollbar_layer.h" 27 #include "cc/layers/scrollbar_layer.h"
27 #include "cc/resources/prioritized_resource_manager.h" 28 #include "cc/resources/prioritized_resource_manager.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 return layer_tree_host.Pass(); 71 return layer_tree_host.Pass();
71 } 72 }
72 73
73 LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, 74 LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client,
74 const LayerTreeSettings& settings) 75 const LayerTreeSettings& settings)
75 : animating_(false), 76 : animating_(false),
76 needs_full_tree_sync_(true), 77 needs_full_tree_sync_(true),
77 needs_filter_context_(false), 78 needs_filter_context_(false),
78 client_(client), 79 client_(client),
79 commit_number_(0), 80 commit_number_(0),
80 rendering_stats_(), 81 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()),
81 renderer_initialized_(false), 82 renderer_initialized_(false),
82 output_surface_lost_(false), 83 output_surface_lost_(false),
83 num_failed_recreate_attempts_(0), 84 num_failed_recreate_attempts_(0),
84 settings_(settings), 85 settings_(settings),
85 debug_state_(settings.initial_debug_state), 86 debug_state_(settings.initial_debug_state),
86 device_scale_factor_(1.f), 87 device_scale_factor_(1.f),
87 visible_(true), 88 visible_(true),
88 page_scale_factor_(1.f), 89 page_scale_factor_(1.f),
89 min_page_scale_factor_(1.f), 90 min_page_scale_factor_(1.f),
90 max_page_scale_factor_(1.f), 91 max_page_scale_factor_(1.f),
91 trigger_idle_updates_(true), 92 trigger_idle_updates_(true),
92 background_color_(SK_ColorWHITE), 93 background_color_(SK_ColorWHITE),
93 has_transparent_background_(false), 94 has_transparent_background_(false),
94 partial_texture_update_requests_(0) { 95 partial_texture_update_requests_(0) {
95 if (settings_.accelerated_animation_enabled) 96 if (settings_.accelerated_animation_enabled)
96 animation_registrar_ = AnimationRegistrar::Create(); 97 animation_registrar_ = AnimationRegistrar::Create();
97 s_num_layer_tree_instances++; 98 s_num_layer_tree_instances++;
99
100 rendering_stats_instrumentation_->set_record_rendering_stats(
101 debug_state_.RecordRenderingStats());
98 } 102 }
99 103
100 bool LayerTreeHost::Initialize(scoped_ptr<Thread> impl_thread) { 104 bool LayerTreeHost::Initialize(scoped_ptr<Thread> impl_thread) {
101 if (impl_thread) 105 if (impl_thread)
102 return InitializeProxy(ThreadProxy::Create(this, impl_thread.Pass())); 106 return InitializeProxy(ThreadProxy::Create(this, impl_thread.Pass()));
103 else 107 else
104 return InitializeProxy(SingleThreadProxy::Create(this)); 108 return InitializeProxy(SingleThreadProxy::Create(this));
105 } 109 }
106 110
107 bool LayerTreeHost::InitializeForTesting(scoped_ptr<Proxy> proxy_for_testing) { 111 bool LayerTreeHost::InitializeForTesting(scoped_ptr<Proxy> proxy_for_testing) {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 void LayerTreeHost::DidBeginFrame() { 227 void LayerTreeHost::DidBeginFrame() {
224 client_->DidBeginFrame(); 228 client_->DidBeginFrame();
225 } 229 }
226 230
227 void LayerTreeHost::UpdateAnimations(base::TimeTicks frame_begin_time) { 231 void LayerTreeHost::UpdateAnimations(base::TimeTicks frame_begin_time) {
228 animating_ = true; 232 animating_ = true;
229 client_->Animate((frame_begin_time - base::TimeTicks()).InSecondsF()); 233 client_->Animate((frame_begin_time - base::TimeTicks()).InSecondsF());
230 AnimateLayers(frame_begin_time); 234 AnimateLayers(frame_begin_time);
231 animating_ = false; 235 animating_ = false;
232 236
233 rendering_stats_.numAnimationFrames++; 237 rendering_stats_instrumentation_->IncrementAnimationFrameCount();
234 } 238 }
235 239
236 void LayerTreeHost::DidStopFlinging() { 240 void LayerTreeHost::DidStopFlinging() {
237 proxy_->MainThreadHasStoppedFlinging(); 241 proxy_->MainThreadHasStoppedFlinging();
238 } 242 }
239 243
240 void LayerTreeHost::Layout() { 244 void LayerTreeHost::Layout() {
241 client_->Layout(); 245 client_->Layout();
242 } 246 }
243 247
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 sync_tree->SetPinchZoomVerticalLayerId( 342 sync_tree->SetPinchZoomVerticalLayerId(
339 pinch_zoom_scrollbar_vertical_ ? 343 pinch_zoom_scrollbar_vertical_ ?
340 pinch_zoom_scrollbar_vertical_->id() : Layer::INVALID_ID); 344 pinch_zoom_scrollbar_vertical_->id() : Layer::INVALID_ID);
341 345
342 if (!settings_.impl_side_painting) { 346 if (!settings_.impl_side_painting) {
343 // If we're not in impl-side painting, the tree is immediately 347 // If we're not in impl-side painting, the tree is immediately
344 // considered active. 348 // considered active.
345 sync_tree->DidBecomeActive(); 349 sync_tree->DidBecomeActive();
346 } 350 }
347 351
348 if (debug_state_.continuous_painting) 352 if (debug_state_.continuous_painting) {
349 host_impl->SavePaintTime(rendering_stats_.totalPaintTime, commit_number()); 353 host_impl->SavePaintTime(
354 rendering_stats_instrumentation_->GetRenderingStats().totalPaintTime,
355 commit_number()
356 );
357 }
350 358
351 commit_number_++; 359 commit_number_++;
352 } 360 }
353 361
354 void LayerTreeHost::SetPinchZoomScrollbarsBoundsAndPosition() { 362 void LayerTreeHost::SetPinchZoomScrollbarsBoundsAndPosition() {
355 if (!pinch_zoom_scrollbar_horizontal_ || !pinch_zoom_scrollbar_vertical_) 363 if (!pinch_zoom_scrollbar_horizontal_ || !pinch_zoom_scrollbar_vertical_)
356 return; 364 return;
357 365
358 gfx::Size size = layout_viewport_size(); 366 gfx::Size size = layout_viewport_size();
359 int track_width = PinchZoomScrollbarGeometry::kTrackWidth; 367 int track_width = PinchZoomScrollbarGeometry::kTrackWidth;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 } 444 }
437 445
438 scoped_ptr<InputHandler> LayerTreeHost::CreateInputHandler() { 446 scoped_ptr<InputHandler> LayerTreeHost::CreateInputHandler() {
439 return client_->CreateInputHandler(); 447 return client_->CreateInputHandler();
440 } 448 }
441 449
442 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl( 450 scoped_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl(
443 LayerTreeHostImplClient* client) { 451 LayerTreeHostImplClient* client) {
444 DCHECK(proxy_->IsImplThread()); 452 DCHECK(proxy_->IsImplThread());
445 scoped_ptr<LayerTreeHostImpl> host_impl = 453 scoped_ptr<LayerTreeHostImpl> host_impl =
446 LayerTreeHostImpl::Create(settings_, client, proxy_.get()); 454 LayerTreeHostImpl::Create(settings_,
455 client,
456 proxy_.get(),
457 rendering_stats_instrumentation_.get());
447 if (settings_.calculate_top_controls_position && 458 if (settings_.calculate_top_controls_position &&
448 host_impl->top_controls_manager()) { 459 host_impl->top_controls_manager()) {
449 top_controls_manager_weak_ptr_ = 460 top_controls_manager_weak_ptr_ =
450 host_impl->top_controls_manager()->AsWeakPtr(); 461 host_impl->top_controls_manager()->AsWeakPtr();
451 } 462 }
452 return host_impl.Pass(); 463 return host_impl.Pass();
453 } 464 }
454 465
455 void LayerTreeHost::DidLoseOutputSurface() { 466 void LayerTreeHost::DidLoseOutputSurface() {
456 TRACE_EVENT0("cc", "LayerTreeHost::DidLoseOutputSurface"); 467 TRACE_EVENT0("cc", "LayerTreeHost::DidLoseOutputSurface");
(...skipping 18 matching lines...) Expand all
475 } 486 }
476 487
477 void LayerTreeHost::SetDeferCommits(bool defer_commits) { 488 void LayerTreeHost::SetDeferCommits(bool defer_commits) {
478 proxy_->SetDeferCommits(defer_commits); 489 proxy_->SetDeferCommits(defer_commits);
479 } 490 }
480 491
481 void LayerTreeHost::DidDeferCommit() {} 492 void LayerTreeHost::DidDeferCommit() {}
482 493
483 void LayerTreeHost::CollectRenderingStats(RenderingStats* stats) const { 494 void LayerTreeHost::CollectRenderingStats(RenderingStats* stats) const {
484 CHECK(debug_state_.RecordRenderingStats()); 495 CHECK(debug_state_.RecordRenderingStats());
485 *stats = rendering_stats_; 496 *stats = rendering_stats_instrumentation_->GetRenderingStats();
486 proxy_->CollectRenderingStats(stats);
487 } 497 }
488 498
489 const RendererCapabilities& LayerTreeHost::GetRendererCapabilities() const { 499 const RendererCapabilities& LayerTreeHost::GetRendererCapabilities() const {
490 return proxy_->GetRendererCapabilities(); 500 return proxy_->GetRendererCapabilities();
491 } 501 }
492 502
493 void LayerTreeHost::SetNeedsAnimate() { 503 void LayerTreeHost::SetNeedsAnimate() {
494 DCHECK(proxy_->HasImplThread()); 504 DCHECK(proxy_->HasImplThread());
495 proxy_->SetNeedsAnimate(); 505 proxy_->SetNeedsAnimate();
496 } 506 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 } 560 }
551 561
552 void LayerTreeHost::SetDebugState(const LayerTreeDebugState& debug_state) { 562 void LayerTreeHost::SetDebugState(const LayerTreeDebugState& debug_state) {
553 LayerTreeDebugState new_debug_state = 563 LayerTreeDebugState new_debug_state =
554 LayerTreeDebugState::Unite(settings_.initial_debug_state, debug_state); 564 LayerTreeDebugState::Unite(settings_.initial_debug_state, debug_state);
555 565
556 if (LayerTreeDebugState::Equal(debug_state_, new_debug_state)) 566 if (LayerTreeDebugState::Equal(debug_state_, new_debug_state))
557 return; 567 return;
558 568
559 debug_state_ = new_debug_state; 569 debug_state_ = new_debug_state;
570
571 rendering_stats_instrumentation_->set_record_rendering_stats(
572 debug_state_.RecordRenderingStats());
573
560 SetNeedsCommit(); 574 SetNeedsCommit();
561 } 575 }
562 576
563 void LayerTreeHost::SetViewportSize(gfx::Size layout_viewport_size, 577 void LayerTreeHost::SetViewportSize(gfx::Size layout_viewport_size,
564 gfx::Size device_viewport_size) { 578 gfx::Size device_viewport_size) {
565 if (layout_viewport_size == layout_viewport_size_ && 579 if (layout_viewport_size == layout_viewport_size_ &&
566 device_viewport_size == device_viewport_size_) 580 device_viewport_size == device_viewport_size_)
567 return; 581 return;
568 582
569 layout_viewport_size_ = layout_viewport_size; 583 layout_viewport_size_ = layout_viewport_size;
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 max_background_texture_bytes = bytes; 803 max_background_texture_bytes = bytes;
790 if (!readback_bytes) { 804 if (!readback_bytes) {
791 readback_bytes = Resource::MemorySizeBytes(device_viewport_size_, 805 readback_bytes = Resource::MemorySizeBytes(device_viewport_size_,
792 GL_RGBA); 806 GL_RGBA);
793 } 807 }
794 } 808 }
795 return readback_bytes + max_background_texture_bytes + contents_texture_bytes; 809 return readback_bytes + max_background_texture_bytes + contents_texture_bytes;
796 } 810 }
797 811
798 bool LayerTreeHost::PaintMasksForRenderSurface(Layer* render_surface_layer, 812 bool LayerTreeHost::PaintMasksForRenderSurface(Layer* render_surface_layer,
799 ResourceUpdateQueue* queue) { 813 ResourceUpdateQueue* queue,
814 RenderingStats* stats) {
800 // Note: Masks and replicas only exist for layers that own render surfaces. If 815 // Note: Masks and replicas only exist for layers that own render surfaces. If
801 // we reach this point in code, we already know that at least something will 816 // we reach this point in code, we already know that at least something will
802 // be drawn into this render surface, so the mask and replica should be 817 // be drawn into this render surface, so the mask and replica should be
803 // painted. 818 // painted.
804 819
805 RenderingStats* stats =
806 debug_state_.RecordRenderingStats() ? &rendering_stats_ : NULL;
807
808 bool need_more_updates = false; 820 bool need_more_updates = false;
809 Layer* mask_layer = render_surface_layer->mask_layer(); 821 Layer* mask_layer = render_surface_layer->mask_layer();
810 if (mask_layer) { 822 if (mask_layer) {
811 mask_layer->Update(queue, NULL, stats); 823 mask_layer->Update(queue, NULL, stats);
812 need_more_updates |= mask_layer->NeedMoreUpdates(); 824 need_more_updates |= mask_layer->NeedMoreUpdates();
813 } 825 }
814 826
815 Layer* replica_mask_layer = 827 Layer* replica_mask_layer =
816 render_surface_layer->replica_layer() ? 828 render_surface_layer->replica_layer() ?
817 render_surface_layer->replica_layer()->mask_layer() : NULL; 829 render_surface_layer->replica_layer()->mask_layer() : NULL;
(...skipping 19 matching lines...) Expand all
837 base::debug::TraceLog::GetInstance() && 849 base::debug::TraceLog::GetInstance() &&
838 base::debug::TraceLog::GetInstance()->IsEnabled(); 850 base::debug::TraceLog::GetInstance()->IsEnabled();
839 OcclusionTracker occlusion_tracker( 851 OcclusionTracker occlusion_tracker(
840 root_layer_->render_surface()->content_rect(), record_metrics_for_frame); 852 root_layer_->render_surface()->content_rect(), record_metrics_for_frame);
841 occlusion_tracker.set_minimum_tracking_size( 853 occlusion_tracker.set_minimum_tracking_size(
842 settings_.minimum_occlusion_tracking_size); 854 settings_.minimum_occlusion_tracking_size);
843 855
844 PrioritizeTextures(render_surface_layer_list, 856 PrioritizeTextures(render_surface_layer_list,
845 occlusion_tracker.overdraw_metrics()); 857 occlusion_tracker.overdraw_metrics());
846 858
847 RenderingStats* stats = debug_state_.RecordRenderingStats() ? 859 // TODO(egraether): Use RenderingStatsInstrumentation in Layer::update()
848 &rendering_stats_ : NULL; 860 RenderingStats stats;
861 RenderingStats* stats_ptr =
862 debug_state_.RecordRenderingStats() ? &stats : NULL;
849 863
850 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list); 864 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list);
851 for (LayerIteratorType it = 865 for (LayerIteratorType it =
852 LayerIteratorType::Begin(&render_surface_layer_list); 866 LayerIteratorType::Begin(&render_surface_layer_list);
853 it != end; 867 it != end;
854 ++it) { 868 ++it) {
855 occlusion_tracker.EnterLayer(it); 869 occlusion_tracker.EnterLayer(it);
856 870
857 if (it.represents_target_render_surface()) { 871 if (it.represents_target_render_surface()) {
858 DCHECK(it->render_surface()->draw_opacity() || 872 DCHECK(it->render_surface()->draw_opacity() ||
859 it->render_surface()->draw_opacity_is_animating()); 873 it->render_surface()->draw_opacity_is_animating());
860 need_more_updates |= PaintMasksForRenderSurface(*it, queue); 874 need_more_updates |= PaintMasksForRenderSurface(*it, queue, stats_ptr);
861 } else if (it.represents_itself()) { 875 } else if (it.represents_itself()) {
862 DCHECK(!it->bounds().IsEmpty()); 876 DCHECK(!it->bounds().IsEmpty());
863 it->Update(queue, &occlusion_tracker, stats); 877 it->Update(queue, &occlusion_tracker, stats_ptr);
864 need_more_updates |= it->NeedMoreUpdates(); 878 need_more_updates |= it->NeedMoreUpdates();
865 } 879 }
866 880
867 occlusion_tracker.LeaveLayer(it); 881 occlusion_tracker.LeaveLayer(it);
868 } 882 }
869 883
884 rendering_stats_instrumentation_->AddStats(stats);
885
870 occlusion_tracker.overdraw_metrics()->RecordMetrics(this); 886 occlusion_tracker.overdraw_metrics()->RecordMetrics(this);
871 887
872 return need_more_updates; 888 return need_more_updates;
873 } 889 }
874 890
875 void LayerTreeHost::ApplyScrollAndScale(const ScrollAndScaleSet& info) { 891 void LayerTreeHost::ApplyScrollAndScale(const ScrollAndScaleSet& info) {
876 if (!root_layer_) 892 if (!root_layer_)
877 return; 893 return;
878 894
879 Layer* root_scroll_layer = FindFirstScrollableLayer(root_layer_.get()); 895 Layer* root_scroll_layer = FindFirstScrollableLayer(root_layer_.get());
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 SetAnimationEventsRecursive(events, 1037 SetAnimationEventsRecursive(events,
1022 layer->children()[child_index].get(), 1038 layer->children()[child_index].get(),
1023 wall_clock_time); 1039 wall_clock_time);
1024 } 1040 }
1025 1041
1026 skia::RefPtr<SkPicture> LayerTreeHost::CapturePicture() { 1042 skia::RefPtr<SkPicture> LayerTreeHost::CapturePicture() {
1027 return proxy_->CapturePicture(); 1043 return proxy_->CapturePicture();
1028 } 1044 }
1029 1045
1030 } // namespace cc 1046 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host.h ('k') | cc/trees/layer_tree_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698