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 layerIndex = 0; layerIndex < layer_list.size(); |
danakj
2013/03/14 02:14:38
layer_index
the script's bad with for loops :(
danakj
2013/03/14 02:14:38
1 statement per line?
enne (OOO)
2013/03/14 02:47:14
Done.
| |
86 ++layerIndex) { | |
87 LayerImpl* layer = layer_list[layerIndex]; | |
35 | 88 |
36 if (debugState.showPropertyChangedRects) | 89 if (LayerTreeHostCommon::renderSurfaceContributesToTarget<LayerImpl>( |
37 savePropertyChangedRects(renderSurfaceLayerList); | 90 layer, render_surface_layer->id())) |
91 continue; | |
38 | 92 |
39 if (debugState.showSurfaceDamageRects) | 93 if (layer->LayerIsAlwaysDamaged()) |
40 saveSurfaceDamageRects(renderSurfaceLayerList); | 94 continue; |
41 | 95 |
42 if (debugState.showScreenSpaceRects) | 96 if (layer->LayerPropertyChanged() || layer->LayerSurfacePropertyChanged()) |
43 saveScreenSpaceRects(renderSurfaceLayerList); | 97 debug_rects_.push_back( |
danakj
2013/03/14 02:14:38
{}
enne (OOO)
2013/03/14 02:47:14
Done.
| |
44 | 98 DebugRect(PROPERTY_CHANGED_RECT_TYPE, |
45 if (debugState.showOccludingRects) | 99 MathUtil::mapClippedRect( |
46 saveOccludingRects(occludingScreenSpaceRects); | 100 layer->screen_space_transform(), |
47 | 101 gfx::RectF(gfx::PointF(), layer->content_bounds())))); |
48 if (debugState.showNonOccludingRects) | 102 } |
49 saveNonOccludingRects(nonOccludingScreenSpaceRects); | 103 } |
50 } | 104 } |
51 | 105 |
106 void DebugRectHistory::SaveSurfaceDamageRects( | |
107 const std::vector<LayerImpl*>& render_surface_layer_list) { | |
108 for (int surface_index = render_surface_layer_list.size() - 1; | |
109 surface_index >= 0; | |
110 --surface_index) { | |
111 LayerImpl* render_surface_layer = render_surface_layer_list[surface_index]; | |
112 RenderSurfaceImpl* render_surface = render_surface_layer->render_surface(); | |
113 DCHECK(render_surface); | |
52 | 114 |
53 void DebugRectHistory::savePaintRects(LayerImpl* layer) | 115 debug_rects_.push_back(DebugRect( |
54 { | 116 SURFACE_DAMAGE_RECT_TYPE, |
55 // We would like to visualize where any layer's paint rect (update rect) has changed, | 117 MathUtil::mapClippedRect( |
56 // regardless of whether this layer is skipped for actual drawing or not. Th erefore | 118 render_surface->screen_space_transform(), |
57 // we traverse recursively over all layers, not just the render surface list . | 119 render_surface->damage_tracker()->current_damage_rect()))); |
58 | 120 } |
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 } | 121 } |
69 | 122 |
70 void DebugRectHistory::savePropertyChangedRects(const std::vector<LayerImpl*>& r enderSurfaceLayerList) | 123 void DebugRectHistory::SaveScreenSpaceRects( |
71 { | 124 const std::vector<LayerImpl*>& render_surface_layer_list) { |
72 for (int surfaceIndex = renderSurfaceLayerList.size() - 1; surfaceIndex >= 0 ; --surfaceIndex) { | 125 for (int surface_index = render_surface_layer_list.size() - 1; |
73 LayerImpl* renderSurfaceLayer = renderSurfaceLayerList[surfaceIndex]; | 126 surface_index >= 0; |
74 RenderSurfaceImpl* renderSurface = renderSurfaceLayer->render_surface(); | 127 --surface_index) { |
75 DCHECK(renderSurface); | 128 LayerImpl* render_surface_layer = render_surface_layer_list[surface_index]; |
129 RenderSurfaceImpl* render_surface = render_surface_layer->render_surface(); | |
130 DCHECK(render_surface); | |
76 | 131 |
77 const std::vector<LayerImpl*>& layerList = renderSurface->layer_list(); | 132 debug_rects_.push_back(DebugRect( |
78 for (unsigned layerIndex = 0; layerIndex < layerList.size(); ++layerInde x) { | 133 SCREEN_SPACE_RECT_TYPE, |
79 LayerImpl* layer = layerList[layerIndex]; | 134 MathUtil::mapClippedRect(render_surface->screen_space_transform(), |
135 render_surface->content_rect()))); | |
80 | 136 |
81 if (LayerTreeHostCommon::renderSurfaceContributesToTarget<LayerImpl> (layer, renderSurfaceLayer->id())) | 137 if (render_surface_layer->replica_layer()) |
danakj
2013/03/14 02:14:38
{}
enne (OOO)
2013/03/14 02:47:14
Done.
| |
82 continue; | 138 debug_rects_.push_back( |
83 | 139 DebugRect(REPLICA_SCREEN_SPACE_RECT_TYPE, |
84 if (layer->LayerIsAlwaysDamaged()) | 140 MathUtil::mapClippedRect( |
85 continue; | 141 render_surface->replica_screen_space_transform(), |
86 | 142 render_surface->content_rect()))); |
87 if (layer->LayerPropertyChanged() || layer->LayerSurfacePropertyChan ged()) | 143 } |
88 m_debugRects.push_back(DebugRect(PropertyChangedRectType, MathUt il::mapClippedRect(layer->screen_space_transform(), gfx::RectF(gfx::PointF(), la yer->content_bounds())))); | |
89 } | |
90 } | |
91 } | 144 } |
92 | 145 |
93 void DebugRectHistory::saveSurfaceDamageRects(const std::vector<LayerImpl* >& re nderSurfaceLayerList) | 146 void DebugRectHistory::SaveOccludingRects( |
94 { | 147 const std::vector<gfx::Rect>& occluding_rects) { |
95 for (int surfaceIndex = renderSurfaceLayerList.size() - 1; surfaceIndex >= 0 ; --surfaceIndex) { | 148 for (size_t i = 0; i < occluding_rects.size(); ++i) { |
danakj
2013/03/14 02:14:38
no {}
enne (OOO)
2013/03/14 02:47:14
"In general, curly braces are not required for sin
| |
96 LayerImpl* renderSurfaceLayer = renderSurfaceLayerList[surfaceIndex]; | 149 debug_rects_.push_back(DebugRect(OCCLUDING_RECT_TYPE, occluding_rects[i])); |
97 RenderSurfaceImpl* renderSurface = renderSurfaceLayer->render_surface(); | 150 } |
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 } | 151 } |
103 | 152 |
104 void DebugRectHistory::saveScreenSpaceRects(const std::vector<LayerImpl* >& rend erSurfaceLayerList) | 153 void DebugRectHistory::SaveNonOccludingRects( |
105 { | 154 const std::vector<gfx::Rect>& non_occluding_rects) { |
106 for (int surfaceIndex = renderSurfaceLayerList.size() - 1; surfaceIndex >= 0 ; --surfaceIndex) { | 155 for (size_t i = 0; i < non_occluding_rects.size(); ++i) { |
107 LayerImpl* renderSurfaceLayer = renderSurfaceLayerList[surfaceIndex]; | 156 debug_rects_.push_back( |
108 RenderSurfaceImpl* renderSurface = renderSurfaceLayer->render_surface(); | 157 DebugRect(NONOCCLUDING_RECT_TYPE, non_occluding_rects[i])); |
109 DCHECK(renderSurface); | 158 } |
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 } | 159 } |
129 | 160 |
130 } // namespace cc | 161 } // namespace cc |
OLD | NEW |