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

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

Issue 12662021: cc: Don't draw and swap if the frame will not change. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « cc/trees/layer_tree_host_impl.h ('k') | cc/trees/layer_tree_host_impl_unittest.cc » ('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_impl.h" 5 #include "cc/trees/layer_tree_host_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 time_source_->SetClient(this); 132 time_source_->SetClient(this);
133 } 133 }
134 134
135 LayerTreeHostImpl* layer_tree_host_impl_; 135 LayerTreeHostImpl* layer_tree_host_impl_;
136 scoped_refptr<DelayBasedTimeSource> time_source_; 136 scoped_refptr<DelayBasedTimeSource> time_source_;
137 137
138 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImplTimeSourceAdapter); 138 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImplTimeSourceAdapter);
139 }; 139 };
140 140
141 LayerTreeHostImpl::FrameData::FrameData() 141 LayerTreeHostImpl::FrameData::FrameData()
142 : contains_incomplete_tile(false) {} 142 : contains_incomplete_tile(false), has_no_damage(false) {}
143 143
144 LayerTreeHostImpl::FrameData::~FrameData() {} 144 LayerTreeHostImpl::FrameData::~FrameData() {}
145 145
146 scoped_ptr<LayerTreeHostImpl> LayerTreeHostImpl::Create( 146 scoped_ptr<LayerTreeHostImpl> LayerTreeHostImpl::Create(
147 const LayerTreeSettings& settings, 147 const LayerTreeSettings& settings,
148 LayerTreeHostImplClient* client, 148 LayerTreeHostImplClient* client,
149 Proxy* proxy, 149 Proxy* proxy,
150 RenderingStatsInstrumentation* rendering_stats_instrumentation) { 150 RenderingStatsInstrumentation* rendering_stats_instrumentation) {
151 return make_scoped_ptr( 151 return make_scoped_ptr(
152 new LayerTreeHostImpl(settings, 152 new LayerTreeHostImpl(settings,
(...skipping 23 matching lines...) Expand all
176 ManagedMemoryPolicy::CUTOFF_ALLOW_NOTHING), 176 ManagedMemoryPolicy::CUTOFF_ALLOW_NOTHING),
177 pinch_gesture_active_(false), 177 pinch_gesture_active_(false),
178 fps_counter_(FrameRateCounter::Create(proxy_->HasImplThread())), 178 fps_counter_(FrameRateCounter::Create(proxy_->HasImplThread())),
179 paint_time_counter_(PaintTimeCounter::Create()), 179 paint_time_counter_(PaintTimeCounter::Create()),
180 memory_history_(MemoryHistory::Create()), 180 memory_history_(MemoryHistory::Create()),
181 debug_rect_history_(DebugRectHistory::Create()), 181 debug_rect_history_(DebugRectHistory::Create()),
182 max_memory_needed_bytes_(0), 182 max_memory_needed_bytes_(0),
183 last_sent_memory_visible_bytes_(0), 183 last_sent_memory_visible_bytes_(0),
184 last_sent_memory_visible_and_nearby_bytes_(0), 184 last_sent_memory_visible_and_nearby_bytes_(0),
185 last_sent_memory_use_bytes_(0), 185 last_sent_memory_use_bytes_(0),
186 next_frame_damages_full_device_viewport_(false),
186 animation_registrar_(AnimationRegistrar::Create()), 187 animation_registrar_(AnimationRegistrar::Create()),
187 rendering_stats_instrumentation_(rendering_stats_instrumentation) { 188 rendering_stats_instrumentation_(rendering_stats_instrumentation) {
188 DCHECK(proxy_->IsImplThread()); 189 DCHECK(proxy_->IsImplThread());
189 DidVisibilityChange(this, visible_); 190 DidVisibilityChange(this, visible_);
190 191
191 SetDebugState(settings.initial_debug_state); 192 SetDebugState(settings.initial_debug_state);
192 193
193 if (settings.calculate_top_controls_position) { 194 if (settings.calculate_top_controls_position) {
194 top_controls_manager_ = 195 top_controls_manager_ =
195 TopControlsManager::Create(this, 196 TopControlsManager::Create(this,
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 502
502 bool LayerTreeHostImpl::CalculateRenderPasses(FrameData* frame) { 503 bool LayerTreeHostImpl::CalculateRenderPasses(FrameData* frame) {
503 DCHECK(frame->render_passes.empty()); 504 DCHECK(frame->render_passes.empty());
504 505
505 if (!CanDraw() || !active_tree_->root_layer()) 506 if (!CanDraw() || !active_tree_->root_layer())
506 return false; 507 return false;
507 508
508 TrackDamageForAllSurfaces(active_tree_->root_layer(), 509 TrackDamageForAllSurfaces(active_tree_->root_layer(),
509 *frame->render_surface_layer_list); 510 *frame->render_surface_layer_list);
510 511
512 // If the root render surface has no visible damage, then don't generate a
513 // frame at all.
514 RenderSurfaceImpl* root_surface =
515 active_tree_->root_layer()->render_surface();
516 bool root_surface_has_no_visible_damage =
517 !root_surface->damage_tracker()->current_damage_rect().Intersects(
518 root_surface->content_rect());
519 bool root_surface_has_contributing_layers =
520 !root_surface->layer_list().empty();
521 if (root_surface_has_contributing_layers &&
522 root_surface_has_no_visible_damage) {
523 TRACE_EVENT0("cc",
524 "LayerTreeHostImpl::CalculateRenderPasses::EmptyDamageRect");
525 frame->has_no_damage = true;
526 return true;
527 }
528
511 TRACE_EVENT1("cc", 529 TRACE_EVENT1("cc",
512 "LayerTreeHostImpl::CalculateRenderPasses", 530 "LayerTreeHostImpl::CalculateRenderPasses",
513 "render_surface_layer_list.size()", 531 "render_surface_layer_list.size()",
514 static_cast<uint64>(frame->render_surface_layer_list->size())); 532 static_cast<uint64>(frame->render_surface_layer_list->size()));
515 533
516 // Create the render passes in dependency order. 534 // Create the render passes in dependency order.
517 for (int surface_index = frame->render_surface_layer_list->size() - 1; 535 for (int surface_index = frame->render_surface_layer_list->size() - 1;
518 surface_index >= 0; 536 surface_index >= 0;
519 --surface_index) { 537 --surface_index) {
520 LayerImpl* render_surface_layer = 538 LayerImpl* render_surface_layer =
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 } 686 }
669 687
670 if (draw_frame) 688 if (draw_frame)
671 occlusion_tracker.overdraw_metrics()->RecordMetrics(this); 689 occlusion_tracker.overdraw_metrics()->RecordMetrics(this);
672 690
673 RemoveRenderPasses(CullRenderPassesWithNoQuads(), frame); 691 RemoveRenderPasses(CullRenderPassesWithNoQuads(), frame);
674 renderer_->DecideRenderPassAllocationsForFrame(frame->render_passes); 692 renderer_->DecideRenderPassAllocationsForFrame(frame->render_passes);
675 RemoveRenderPasses(CullRenderPassesWithCachedTextures(renderer_.get()), 693 RemoveRenderPasses(CullRenderPassesWithCachedTextures(renderer_.get()),
676 frame); 694 frame);
677 695
696 // If we're making a frame to draw, it better have at least one render pass.
697 DCHECK(!frame->render_passes.empty());
678 return draw_frame; 698 return draw_frame;
679 } 699 }
680 700
681 void LayerTreeHostImpl::UpdateBackgroundAnimateTicking( 701 void LayerTreeHostImpl::UpdateBackgroundAnimateTicking(
682 bool should_background_tick) { 702 bool should_background_tick) {
683 bool enabled = should_background_tick && 703 bool enabled = should_background_tick &&
684 !animation_registrar_->active_animation_controllers().empty(); 704 !animation_registrar_->active_animation_controllers().empty();
685 705
686 // Lazily create the time_source adapter so that we can vary the interval for 706 // Lazily create the time_source adapter so that we can vary the interval for
687 // testing. 707 // testing.
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 // change. So, capture the iterator position from the end of the 840 // change. So, capture the iterator position from the end of the
821 // list, and restore it after the change. 841 // list, and restore it after the change.
822 size_t position_from_end = frame->render_passes.size() - it; 842 size_t position_from_end = frame->render_passes.size() - it;
823 RemoveRenderPassesRecursive(render_pass_quad->render_pass_id, frame); 843 RemoveRenderPassesRecursive(render_pass_quad->render_pass_id, frame);
824 it = frame->render_passes.size() - position_from_end; 844 it = frame->render_passes.size() - position_from_end;
825 DCHECK_GE(frame->render_passes.size(), position_from_end); 845 DCHECK_GE(frame->render_passes.size(), position_from_end);
826 } 846 }
827 } 847 }
828 } 848 }
829 849
830 bool LayerTreeHostImpl::PrepareToDraw(FrameData* frame) { 850 bool LayerTreeHostImpl::PrepareToDraw(FrameData* frame,
851 gfx::Rect device_viewport_damage_rect) {
831 TRACE_EVENT0("cc", "LayerTreeHostImpl::PrepareToDraw"); 852 TRACE_EVENT0("cc", "LayerTreeHostImpl::PrepareToDraw");
832 853
833 active_tree_->UpdateDrawProperties( 854 active_tree_->UpdateDrawProperties(
834 LayerTreeImpl::UPDATE_ACTIVE_TREE_FOR_DRAW); 855 LayerTreeImpl::UPDATE_ACTIVE_TREE_FOR_DRAW);
835 856
836 frame->render_surface_layer_list = &active_tree_->RenderSurfaceLayerList(); 857 frame->render_surface_layer_list = &active_tree_->RenderSurfaceLayerList();
837 frame->render_passes.clear(); 858 frame->render_passes.clear();
838 frame->render_passes_by_id.clear(); 859 frame->render_passes_by_id.clear();
839 frame->will_draw_layers.clear(); 860 frame->will_draw_layers.clear();
861 frame->contains_incomplete_tile = false;
862 frame->has_no_damage = false;
863
864 if (active_tree_->root_layer()) {
865 if (next_frame_damages_full_device_viewport_)
866 device_viewport_damage_rect.Union(gfx::Rect(device_viewport_size_));
867
868 active_tree_->root_layer()->render_surface()->damage_tracker()->
869 AddDamageNextUpdate(device_viewport_damage_rect);
870 }
871 next_frame_damages_full_device_viewport_ = false;
840 872
841 if (!CalculateRenderPasses(frame)) 873 if (!CalculateRenderPasses(frame))
842 return false; 874 return false;
843 875
844 // If we return true, then we expect DrawLayers() to be called before this 876 // If we return true, then we expect DrawLayers() to be called before this
845 // function is called again. 877 // function is called again.
846 return true; 878 return true;
847 } 879 }
848 880
849 void LayerTreeHostImpl::EnforceManagedMemoryPolicy( 881 void LayerTreeHostImpl::EnforceManagedMemoryPolicy(
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 // We don't track damage on the HUD layer (it interacts with damage tracking 1022 // We don't track damage on the HUD layer (it interacts with damage tracking
991 // visualizations), so disable partial swaps to make the HUD layer display 1023 // visualizations), so disable partial swaps to make the HUD layer display
992 // properly. 1024 // properly.
993 return !debug_state_.ShowHudRects(); 1025 return !debug_state_.ShowHudRects();
994 } 1026 }
995 1027
996 void LayerTreeHostImpl::DrawLayers(FrameData* frame, 1028 void LayerTreeHostImpl::DrawLayers(FrameData* frame,
997 base::TimeTicks frame_begin_time) { 1029 base::TimeTicks frame_begin_time) {
998 TRACE_EVENT0("cc", "LayerTreeHostImpl::DrawLayers"); 1030 TRACE_EVENT0("cc", "LayerTreeHostImpl::DrawLayers");
999 DCHECK(CanDraw()); 1031 DCHECK(CanDraw());
1032
1033 if (frame->has_no_damage)
1034 return;
1035
1000 DCHECK(!frame->render_passes.empty()); 1036 DCHECK(!frame->render_passes.empty());
1001 1037
1002 fps_counter_->SaveTimeStamp(frame_begin_time); 1038 fps_counter_->SaveTimeStamp(frame_begin_time);
1003 1039
1004 rendering_stats_instrumentation_->SetScreenFrameCount( 1040 rendering_stats_instrumentation_->SetScreenFrameCount(
1005 fps_counter_->current_frame_number()); 1041 fps_counter_->current_frame_number());
1006 rendering_stats_instrumentation_->SetDroppedFrameCount( 1042 rendering_stats_instrumentation_->SetDroppedFrameCount(
1007 fps_counter_->dropped_frame_count()); 1043 fps_counter_->dropped_frame_count());
1008 1044
1009 if (tile_manager_) { 1045 if (tile_manager_) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 1103
1068 bool LayerTreeHostImpl::IsContextLost() { 1104 bool LayerTreeHostImpl::IsContextLost() {
1069 DCHECK(proxy_->IsImplThread()); 1105 DCHECK(proxy_->IsImplThread());
1070 return renderer_ && renderer_->IsContextLost(); 1106 return renderer_ && renderer_->IsContextLost();
1071 } 1107 }
1072 1108
1073 const RendererCapabilities& LayerTreeHostImpl::GetRendererCapabilities() const { 1109 const RendererCapabilities& LayerTreeHostImpl::GetRendererCapabilities() const {
1074 return renderer_->Capabilities(); 1110 return renderer_->Capabilities();
1075 } 1111 }
1076 1112
1077 bool LayerTreeHostImpl::SwapBuffers() { 1113 bool LayerTreeHostImpl::SwapBuffers(const LayerTreeHostImpl::FrameData& frame) {
1114 if (frame.has_no_damage)
1115 return false;
1078 return renderer_->SwapBuffers(); 1116 return renderer_->SwapBuffers();
1079 } 1117 }
1080 1118
1081 void LayerTreeHostImpl::EnableVSyncNotification(bool enable) { 1119 void LayerTreeHostImpl::EnableVSyncNotification(bool enable) {
1082 if (output_surface_) 1120 if (output_surface_)
1083 output_surface_->EnableVSyncNotification(enable); 1121 output_surface_->EnableVSyncNotification(enable);
1084 } 1122 }
1085 1123
1086 gfx::Size LayerTreeHostImpl::DeviceViewportSize() const { 1124 gfx::Size LayerTreeHostImpl::DeviceViewportSize() const {
1087 return device_viewport_size(); 1125 return device_viewport_size();
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
1756 scoped_ptr<ScrollAndScaleSet> scroll_info(new ScrollAndScaleSet()); 1794 scoped_ptr<ScrollAndScaleSet> scroll_info(new ScrollAndScaleSet());
1757 1795
1758 CollectScrollDeltas(scroll_info.get(), active_tree_->root_layer()); 1796 CollectScrollDeltas(scroll_info.get(), active_tree_->root_layer());
1759 scroll_info->page_scale_delta = active_tree_->page_scale_delta(); 1797 scroll_info->page_scale_delta = active_tree_->page_scale_delta();
1760 active_tree_->set_sent_page_scale_delta(scroll_info->page_scale_delta); 1798 active_tree_->set_sent_page_scale_delta(scroll_info->page_scale_delta);
1761 1799
1762 return scroll_info.Pass(); 1800 return scroll_info.Pass();
1763 } 1801 }
1764 1802
1765 void LayerTreeHostImpl::SetFullRootLayerDamage() { 1803 void LayerTreeHostImpl::SetFullRootLayerDamage() {
1766 if (active_tree_->root_layer()) { 1804 next_frame_damages_full_device_viewport_ = true;
1767 RenderSurfaceImpl* render_surface =
1768 active_tree_->root_layer()->render_surface();
1769 if (render_surface)
1770 render_surface->damage_tracker()->ForceFullDamageNextUpdate();
1771 }
1772 } 1805 }
1773 1806
1774 void LayerTreeHostImpl::AnimatePageScale(base::TimeTicks time) { 1807 void LayerTreeHostImpl::AnimatePageScale(base::TimeTicks time) {
1775 if (!page_scale_animation_ || !RootScrollLayer()) 1808 if (!page_scale_animation_ || !RootScrollLayer())
1776 return; 1809 return;
1777 1810
1778 double monotonic_time = (time - base::TimeTicks()).InSecondsF(); 1811 double monotonic_time = (time - base::TimeTicks()).InSecondsF();
1779 gfx::Vector2dF scroll_total = RootScrollLayer()->scroll_offset() + 1812 gfx::Vector2dF scroll_total = RootScrollLayer()->scroll_offset() +
1780 RootScrollLayer()->scroll_delta(); 1813 RootScrollLayer()->scroll_delta();
1781 1814
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
2054 } 2087 }
2055 2088
2056 void LayerTreeHostImpl::SetDebugState(const LayerTreeDebugState& debug_state) { 2089 void LayerTreeHostImpl::SetDebugState(const LayerTreeDebugState& debug_state) {
2057 if (debug_state_.continuous_painting != debug_state.continuous_painting) 2090 if (debug_state_.continuous_painting != debug_state.continuous_painting)
2058 paint_time_counter_->ClearHistory(); 2091 paint_time_counter_->ClearHistory();
2059 2092
2060 debug_state_ = debug_state; 2093 debug_state_ = debug_state;
2061 } 2094 }
2062 2095
2063 } // namespace cc 2096 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.h ('k') | cc/trees/layer_tree_host_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698