| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/debug_rect_history.h" | 5 #include "cc/debug_rect_history.h" |
| 6 | 6 |
| 7 #include "cc/damage_tracker.h" | 7 #include "cc/damage_tracker.h" |
| 8 #include "cc/layer_impl.h" | 8 #include "cc/layer_impl.h" |
| 9 #include "cc/layer_tree_host.h" | 9 #include "cc/layer_tree_host.h" |
| 10 #include "cc/math_util.h" | 10 #include "cc/math_util.h" |
| 11 | 11 |
| 12 namespace cc { | 12 namespace cc { |
| 13 | 13 |
| 14 // static | 14 // static |
| 15 scoped_ptr<DebugRectHistory> DebugRectHistory::create() { | 15 scoped_ptr<DebugRectHistory> DebugRectHistory::Create() { |
| 16 return make_scoped_ptr(new DebugRectHistory()); | 16 return make_scoped_ptr(new DebugRectHistory()); |
| 17 } | 17 } |
| 18 | 18 |
| 19 DebugRectHistory::DebugRectHistory() | 19 DebugRectHistory::DebugRectHistory() {} |
| 20 { | 20 |
| 21 DebugRectHistory::~DebugRectHistory() {} |
| 22 |
| 23 void DebugRectHistory::SaveDebugRectsForCurrentFrame( |
| 24 LayerImpl* root_layer, |
| 25 const std::vector<LayerImpl*>& render_surface_layer_list, |
| 26 const std::vector<gfx::Rect>& occluding_screen_space_rects, |
| 27 const std::vector<gfx::Rect>& non_occluding_screen_space_rects, |
| 28 const LayerTreeDebugState& debug_state) { |
| 29 // For now, clear all rects from previous frames. In the future we may want to |
| 30 // store all debug rects for a history of many frames. |
| 31 debug_rects_.clear(); |
| 32 |
| 33 if (debug_state.showPaintRects) |
| 34 SavePaintRects(root_layer); |
| 35 |
| 36 if (debug_state.showPropertyChangedRects) |
| 37 SavePropertyChangedRects(render_surface_layer_list); |
| 38 |
| 39 if (debug_state.showSurfaceDamageRects) |
| 40 SaveSurfaceDamageRects(render_surface_layer_list); |
| 41 |
| 42 if (debug_state.showScreenSpaceRects) |
| 43 SaveScreenSpaceRects(render_surface_layer_list); |
| 44 |
| 45 if (debug_state.showOccludingRects) |
| 46 SaveOccludingRects(occluding_screen_space_rects); |
| 47 |
| 48 if (debug_state.showNonOccludingRects) |
| 49 SaveNonOccludingRects(non_occluding_screen_space_rects); |
| 21 } | 50 } |
| 22 | 51 |
| 23 DebugRectHistory::~DebugRectHistory() | 52 void DebugRectHistory::SavePaintRects(LayerImpl* layer) { |
| 24 { | 53 // We would like to visualize where any layer's paint rect (update rect) has |
| 54 // changed, regardless of whether this layer is skipped for actual drawing or |
| 55 // not. Therefore we traverse recursively over all layers, not just the render |
| 56 // surface list. |
| 57 |
| 58 if (!layer->update_rect().IsEmpty() && layer->DrawsContent()) { |
| 59 float width_scale = layer->content_bounds().width() / |
| 60 static_cast<float>(layer->bounds().width()); |
| 61 float height_scale = layer->content_bounds().height() / |
| 62 static_cast<float>(layer->bounds().height()); |
| 63 gfx::RectF update_content_rect = |
| 64 gfx::ScaleRect(layer->update_rect(), width_scale, height_scale); |
| 65 debug_rects_.push_back( |
| 66 DebugRect(PAINT_RECT_TYPE, |
| 67 MathUtil::mapClippedRect(layer->screen_space_transform(), |
| 68 update_content_rect))); |
| 69 } |
| 70 |
| 71 for (unsigned i = 0; i < layer->children().size(); ++i) |
| 72 SavePaintRects(layer->children()[i]); |
| 25 } | 73 } |
| 26 | 74 |
| 27 void DebugRectHistory::saveDebugRectsForCurrentFrame(LayerImpl* rootLayer, const
std::vector<LayerImpl*>& renderSurfaceLayerList, const std::vector<gfx::Rect>&
occludingScreenSpaceRects, const std::vector<gfx::Rect>& nonOccludingScreenSpace
Rects, const LayerTreeDebugState& debugState) | 75 void DebugRectHistory::SavePropertyChangedRects( |
| 28 { | 76 const std::vector<LayerImpl*>& render_surface_layer_list) { |
| 29 // For now, clear all rects from previous frames. In the future we may want
to store | 77 for (int surface_index = render_surface_layer_list.size() - 1; |
| 30 // all debug rects for a history of many frames. | 78 surface_index >= 0; |
| 31 m_debugRects.clear(); | 79 --surface_index) { |
| 80 LayerImpl* render_surface_layer = render_surface_layer_list[surface_index]; |
| 81 RenderSurfaceImpl* render_surface = render_surface_layer->render_surface(); |
| 82 DCHECK(render_surface); |
| 32 | 83 |
| 33 if (debugState.showPaintRects) | 84 const std::vector<LayerImpl*>& layer_list = render_surface->layer_list(); |
| 34 savePaintRects(rootLayer); | 85 for (unsigned layer_index = 0; |
| 86 layer_index < layer_list.size(); |
| 87 ++layer_index) { |
| 88 LayerImpl* layer = layer_list[layer_index]; |
| 35 | 89 |
| 36 if (debugState.showPropertyChangedRects) | 90 if (LayerTreeHostCommon::renderSurfaceContributesToTarget<LayerImpl>( |
| 37 savePropertyChangedRects(renderSurfaceLayerList); | 91 layer, render_surface_layer->id())) |
| 92 continue; |
| 38 | 93 |
| 39 if (debugState.showSurfaceDamageRects) | 94 if (layer->LayerIsAlwaysDamaged()) |
| 40 saveSurfaceDamageRects(renderSurfaceLayerList); | 95 continue; |
| 41 | 96 |
| 42 if (debugState.showScreenSpaceRects) | 97 if (layer->LayerPropertyChanged() || |
| 43 saveScreenSpaceRects(renderSurfaceLayerList); | 98 layer->LayerSurfacePropertyChanged()) { |
| 44 | 99 debug_rects_.push_back( |
| 45 if (debugState.showOccludingRects) | 100 DebugRect(PROPERTY_CHANGED_RECT_TYPE, |
| 46 saveOccludingRects(occludingScreenSpaceRects); | 101 MathUtil::mapClippedRect( |
| 47 | 102 layer->screen_space_transform(), |
| 48 if (debugState.showNonOccludingRects) | 103 gfx::RectF(gfx::PointF(), layer->content_bounds())))); |
| 49 saveNonOccludingRects(nonOccludingScreenSpaceRects); | 104 } |
| 105 } |
| 106 } |
| 50 } | 107 } |
| 51 | 108 |
| 109 void DebugRectHistory::SaveSurfaceDamageRects( |
| 110 const std::vector<LayerImpl*>& render_surface_layer_list) { |
| 111 for (int surface_index = render_surface_layer_list.size() - 1; |
| 112 surface_index >= 0; |
| 113 --surface_index) { |
| 114 LayerImpl* render_surface_layer = render_surface_layer_list[surface_index]; |
| 115 RenderSurfaceImpl* render_surface = render_surface_layer->render_surface(); |
| 116 DCHECK(render_surface); |
| 52 | 117 |
| 53 void DebugRectHistory::savePaintRects(LayerImpl* layer) | 118 debug_rects_.push_back(DebugRect( |
| 54 { | 119 SURFACE_DAMAGE_RECT_TYPE, |
| 55 // We would like to visualize where any layer's paint rect (update rect) has
changed, | 120 MathUtil::mapClippedRect( |
| 56 // regardless of whether this layer is skipped for actual drawing or not. Th
erefore | 121 render_surface->screen_space_transform(), |
| 57 // we traverse recursively over all layers, not just the render surface list
. | 122 render_surface->damage_tracker()->current_damage_rect()))); |
| 58 | 123 } |
| 59 if (!layer->update_rect().IsEmpty() && layer->DrawsContent()) { | |
| 60 float widthScale = layer->content_bounds().width() / static_cast<float>(
layer->bounds().width()); | |
| 61 float heightScale = layer->content_bounds().height() / static_cast<float
>(layer->bounds().height()); | |
| 62 gfx::RectF updateContentRect = gfx::ScaleRect(layer->update_rect(), widt
hScale, heightScale); | |
| 63 m_debugRects.push_back(DebugRect(PaintRectType, MathUtil::mapClippedRect
(layer->screen_space_transform(), updateContentRect))); | |
| 64 } | |
| 65 | |
| 66 for (unsigned i = 0; i < layer->children().size(); ++i) | |
| 67 savePaintRects(layer->children()[i]); | |
| 68 } | 124 } |
| 69 | 125 |
| 70 void DebugRectHistory::savePropertyChangedRects(const std::vector<LayerImpl*>& r
enderSurfaceLayerList) | 126 void DebugRectHistory::SaveScreenSpaceRects( |
| 71 { | 127 const std::vector<LayerImpl*>& render_surface_layer_list) { |
| 72 for (int surfaceIndex = renderSurfaceLayerList.size() - 1; surfaceIndex >= 0
; --surfaceIndex) { | 128 for (int surface_index = render_surface_layer_list.size() - 1; |
| 73 LayerImpl* renderSurfaceLayer = renderSurfaceLayerList[surfaceIndex]; | 129 surface_index >= 0; |
| 74 RenderSurfaceImpl* renderSurface = renderSurfaceLayer->render_surface(); | 130 --surface_index) { |
| 75 DCHECK(renderSurface); | 131 LayerImpl* render_surface_layer = render_surface_layer_list[surface_index]; |
| 132 RenderSurfaceImpl* render_surface = render_surface_layer->render_surface(); |
| 133 DCHECK(render_surface); |
| 76 | 134 |
| 77 const std::vector<LayerImpl*>& layerList = renderSurface->layer_list(); | 135 debug_rects_.push_back(DebugRect( |
| 78 for (unsigned layerIndex = 0; layerIndex < layerList.size(); ++layerInde
x) { | 136 SCREEN_SPACE_RECT_TYPE, |
| 79 LayerImpl* layer = layerList[layerIndex]; | 137 MathUtil::mapClippedRect(render_surface->screen_space_transform(), |
| 138 render_surface->content_rect()))); |
| 80 | 139 |
| 81 if (LayerTreeHostCommon::renderSurfaceContributesToTarget<LayerImpl>
(layer, renderSurfaceLayer->id())) | 140 if (render_surface_layer->replica_layer()) { |
| 82 continue; | 141 debug_rects_.push_back( |
| 83 | 142 DebugRect(REPLICA_SCREEN_SPACE_RECT_TYPE, |
| 84 if (layer->LayerIsAlwaysDamaged()) | 143 MathUtil::mapClippedRect( |
| 85 continue; | 144 render_surface->replica_screen_space_transform(), |
| 86 | 145 render_surface->content_rect()))); |
| 87 if (layer->LayerPropertyChanged() || layer->LayerSurfacePropertyChan
ged()) | |
| 88 m_debugRects.push_back(DebugRect(PropertyChangedRectType, MathUt
il::mapClippedRect(layer->screen_space_transform(), gfx::RectF(gfx::PointF(), la
yer->content_bounds())))); | |
| 89 } | |
| 90 } | 146 } |
| 147 } |
| 91 } | 148 } |
| 92 | 149 |
| 93 void DebugRectHistory::saveSurfaceDamageRects(const std::vector<LayerImpl* >& re
nderSurfaceLayerList) | 150 void DebugRectHistory::SaveOccludingRects( |
| 94 { | 151 const std::vector<gfx::Rect>& occluding_rects) { |
| 95 for (int surfaceIndex = renderSurfaceLayerList.size() - 1; surfaceIndex >= 0
; --surfaceIndex) { | 152 for (size_t i = 0; i < occluding_rects.size(); ++i) |
| 96 LayerImpl* renderSurfaceLayer = renderSurfaceLayerList[surfaceIndex]; | 153 debug_rects_.push_back(DebugRect(OCCLUDING_RECT_TYPE, occluding_rects[i])); |
| 97 RenderSurfaceImpl* renderSurface = renderSurfaceLayer->render_surface(); | |
| 98 DCHECK(renderSurface); | |
| 99 | |
| 100 m_debugRects.push_back(DebugRect(SurfaceDamageRectType, MathUtil::mapCli
ppedRect(renderSurface->screen_space_transform(), renderSurface->damage_tracker(
)->current_damage_rect()))); | |
| 101 } | |
| 102 } | 154 } |
| 103 | 155 |
| 104 void DebugRectHistory::saveScreenSpaceRects(const std::vector<LayerImpl* >& rend
erSurfaceLayerList) | 156 void DebugRectHistory::SaveNonOccludingRects( |
| 105 { | 157 const std::vector<gfx::Rect>& non_occluding_rects) { |
| 106 for (int surfaceIndex = renderSurfaceLayerList.size() - 1; surfaceIndex >= 0
; --surfaceIndex) { | 158 for (size_t i = 0; i < non_occluding_rects.size(); ++i) { |
| 107 LayerImpl* renderSurfaceLayer = renderSurfaceLayerList[surfaceIndex]; | 159 debug_rects_.push_back( |
| 108 RenderSurfaceImpl* renderSurface = renderSurfaceLayer->render_surface(); | 160 DebugRect(NONOCCLUDING_RECT_TYPE, non_occluding_rects[i])); |
| 109 DCHECK(renderSurface); | 161 } |
| 110 | |
| 111 m_debugRects.push_back(DebugRect(ScreenSpaceRectType, MathUtil::mapClipp
edRect(renderSurface->screen_space_transform(), renderSurface->content_rect())))
; | |
| 112 | |
| 113 if (renderSurfaceLayer->replica_layer()) | |
| 114 m_debugRects.push_back(DebugRect(ReplicaScreenSpaceRectType, MathUti
l::mapClippedRect(renderSurface->replica_screen_space_transform(), renderSurface
->content_rect()))); | |
| 115 } | |
| 116 } | |
| 117 | |
| 118 void DebugRectHistory::saveOccludingRects(const std::vector<gfx::Rect>& occludin
gRects) | |
| 119 { | |
| 120 for (size_t i = 0; i < occludingRects.size(); ++i) | |
| 121 m_debugRects.push_back(DebugRect(OccludingRectType, occludingRects[i])); | |
| 122 } | |
| 123 | |
| 124 void DebugRectHistory::saveNonOccludingRects(const std::vector<gfx::Rect>& nonOc
cludingRects) | |
| 125 { | |
| 126 for (size_t i = 0; i < nonOccludingRects.size(); ++i) | |
| 127 m_debugRects.push_back(DebugRect(NonOccludingRectType, nonOccludingRects
[i])); | |
| 128 } | 162 } |
| 129 | 163 |
| 130 } // namespace cc | 164 } // namespace cc |
| OLD | NEW |