Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / cc / debug / debug_rect_history.cc
blob9fa90a5bd363e3617c42db2885a9bf3922809355
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
3 // found in the LICENSE file.
5 #include "cc/debug/debug_rect_history.h"
7 #include "cc/base/math_util.h"
8 #include "cc/layers/layer_impl.h"
9 #include "cc/layers/layer_iterator.h"
10 #include "cc/layers/layer_utils.h"
11 #include "cc/layers/render_surface_impl.h"
12 #include "cc/trees/damage_tracker.h"
13 #include "cc/trees/layer_tree_host.h"
14 #include "cc/trees/layer_tree_host_common.h"
15 #include "ui/gfx/geometry/rect_conversions.h"
17 namespace cc {
19 // static
20 scoped_ptr<DebugRectHistory> DebugRectHistory::Create() {
21 return make_scoped_ptr(new DebugRectHistory());
24 DebugRectHistory::DebugRectHistory() {}
26 DebugRectHistory::~DebugRectHistory() {}
28 void DebugRectHistory::SaveDebugRectsForCurrentFrame(
29 LayerImpl* root_layer,
30 LayerImpl* hud_layer,
31 const LayerImplList& render_surface_layer_list,
32 const LayerTreeDebugState& debug_state) {
33 // For now, clear all rects from previous frames. In the future we may want to
34 // store all debug rects for a history of many frames.
35 debug_rects_.clear();
37 if (debug_state.show_touch_event_handler_rects)
38 SaveTouchEventHandlerRects(root_layer);
40 if (debug_state.show_wheel_event_handler_rects)
41 SaveWheelEventHandlerRects(root_layer);
43 if (debug_state.show_scroll_event_handler_rects)
44 SaveScrollEventHandlerRects(root_layer);
46 if (debug_state.show_non_fast_scrollable_rects)
47 SaveNonFastScrollableRects(root_layer);
49 if (debug_state.show_paint_rects)
50 SavePaintRects(root_layer);
52 if (debug_state.show_property_changed_rects)
53 SavePropertyChangedRects(render_surface_layer_list, hud_layer);
55 if (debug_state.show_surface_damage_rects)
56 SaveSurfaceDamageRects(render_surface_layer_list);
58 if (debug_state.show_screen_space_rects)
59 SaveScreenSpaceRects(render_surface_layer_list);
61 if (debug_state.show_layer_animation_bounds_rects)
62 SaveLayerAnimationBoundsRects(render_surface_layer_list);
65 void DebugRectHistory::SavePaintRects(LayerImpl* layer) {
66 // We would like to visualize where any layer's paint rect (update rect) has
67 // changed, regardless of whether this layer is skipped for actual drawing or
68 // not. Therefore we traverse recursively over all layers, not just the render
69 // surface list.
71 Region invalidation_region = layer->GetInvalidationRegion();
72 if (!invalidation_region.IsEmpty() && layer->DrawsContent()) {
73 for (Region::Iterator it(invalidation_region); it.has_rect(); it.next()) {
74 debug_rects_.push_back(DebugRect(
75 PAINT_RECT_TYPE, MathUtil::MapEnclosingClippedRect(
76 layer->screen_space_transform(), it.rect())));
80 for (unsigned i = 0; i < layer->children().size(); ++i)
81 SavePaintRects(layer->children()[i]);
84 void DebugRectHistory::SavePropertyChangedRects(
85 const LayerImplList& render_surface_layer_list,
86 LayerImpl* hud_layer) {
87 for (size_t i = 0; i < render_surface_layer_list.size(); ++i) {
88 size_t surface_index = render_surface_layer_list.size() - 1 - i;
89 LayerImpl* render_surface_layer = render_surface_layer_list[surface_index];
90 RenderSurfaceImpl* render_surface = render_surface_layer->render_surface();
91 DCHECK(render_surface);
93 const LayerImplList& layer_list = render_surface->layer_list();
94 for (unsigned layer_index = 0;
95 layer_index < layer_list.size();
96 ++layer_index) {
97 LayerImpl* layer = layer_list[layer_index];
99 if (LayerTreeHostCommon::RenderSurfaceContributesToTarget<LayerImpl>(
100 layer, render_surface_layer->id()))
101 continue;
103 if (layer == hud_layer)
104 continue;
106 if (!layer->LayerPropertyChanged())
107 continue;
109 debug_rects_.push_back(DebugRect(
110 PROPERTY_CHANGED_RECT_TYPE,
111 MathUtil::MapEnclosingClippedRect(layer->screen_space_transform(),
112 gfx::Rect(layer->bounds()))));
117 void DebugRectHistory::SaveSurfaceDamageRects(
118 const LayerImplList& render_surface_layer_list) {
119 for (size_t i = 0; i < render_surface_layer_list.size(); ++i) {
120 size_t surface_index = render_surface_layer_list.size() - 1 - i;
121 LayerImpl* render_surface_layer = render_surface_layer_list[surface_index];
122 RenderSurfaceImpl* render_surface = render_surface_layer->render_surface();
123 DCHECK(render_surface);
125 debug_rects_.push_back(DebugRect(
126 SURFACE_DAMAGE_RECT_TYPE,
127 MathUtil::MapEnclosingClippedRect(
128 render_surface->screen_space_transform(),
129 render_surface->damage_tracker()->current_damage_rect())));
133 void DebugRectHistory::SaveScreenSpaceRects(
134 const LayerImplList& render_surface_layer_list) {
135 for (size_t i = 0; i < render_surface_layer_list.size(); ++i) {
136 size_t surface_index = render_surface_layer_list.size() - 1 - i;
137 LayerImpl* render_surface_layer = render_surface_layer_list[surface_index];
138 RenderSurfaceImpl* render_surface = render_surface_layer->render_surface();
139 DCHECK(render_surface);
141 debug_rects_.push_back(
142 DebugRect(SCREEN_SPACE_RECT_TYPE,
143 MathUtil::MapEnclosingClippedRect(
144 render_surface->screen_space_transform(),
145 render_surface->content_rect())));
147 if (render_surface_layer->replica_layer()) {
148 debug_rects_.push_back(
149 DebugRect(REPLICA_SCREEN_SPACE_RECT_TYPE,
150 MathUtil::MapEnclosingClippedRect(
151 render_surface->replica_screen_space_transform(),
152 render_surface->content_rect())));
157 void DebugRectHistory::SaveTouchEventHandlerRects(LayerImpl* layer) {
158 LayerTreeHostCommon::CallFunctionForSubtree(layer, [this](LayerImpl* layer) {
159 SaveTouchEventHandlerRectsCallback(layer);
163 void DebugRectHistory::SaveTouchEventHandlerRectsCallback(LayerImpl* layer) {
164 for (Region::Iterator iter(layer->touch_event_handler_region());
165 iter.has_rect();
166 iter.next()) {
167 debug_rects_.push_back(
168 DebugRect(TOUCH_EVENT_HANDLER_RECT_TYPE,
169 MathUtil::MapEnclosingClippedRect(
170 layer->screen_space_transform(), iter.rect())));
174 void DebugRectHistory::SaveWheelEventHandlerRects(LayerImpl* layer) {
175 LayerTreeHostCommon::CallFunctionForSubtree(layer, [this](LayerImpl* layer) {
176 SaveWheelEventHandlerRectsCallback(layer);
180 void DebugRectHistory::SaveWheelEventHandlerRectsCallback(LayerImpl* layer) {
181 if (!layer->have_wheel_event_handlers())
182 return;
184 debug_rects_.push_back(DebugRect(
185 WHEEL_EVENT_HANDLER_RECT_TYPE,
186 MathUtil::MapEnclosingClippedRect(layer->screen_space_transform(),
187 gfx::Rect(layer->bounds()))));
190 void DebugRectHistory::SaveScrollEventHandlerRects(LayerImpl* layer) {
191 LayerTreeHostCommon::CallFunctionForSubtree(layer, [this](LayerImpl* layer) {
192 SaveScrollEventHandlerRectsCallback(layer);
196 void DebugRectHistory::SaveScrollEventHandlerRectsCallback(LayerImpl* layer) {
197 if (!layer->have_scroll_event_handlers())
198 return;
200 debug_rects_.push_back(DebugRect(
201 SCROLL_EVENT_HANDLER_RECT_TYPE,
202 MathUtil::MapEnclosingClippedRect(layer->screen_space_transform(),
203 gfx::Rect(layer->bounds()))));
206 void DebugRectHistory::SaveNonFastScrollableRects(LayerImpl* layer) {
207 LayerTreeHostCommon::CallFunctionForSubtree(layer, [this](LayerImpl* layer) {
208 SaveNonFastScrollableRectsCallback(layer);
212 void DebugRectHistory::SaveNonFastScrollableRectsCallback(LayerImpl* layer) {
213 for (Region::Iterator iter(layer->non_fast_scrollable_region());
214 iter.has_rect();
215 iter.next()) {
216 debug_rects_.push_back(
217 DebugRect(NON_FAST_SCROLLABLE_RECT_TYPE,
218 MathUtil::MapEnclosingClippedRect(
219 layer->screen_space_transform(), iter.rect())));
223 void DebugRectHistory::SaveLayerAnimationBoundsRects(
224 const LayerImplList& render_surface_layer_list) {
225 LayerIterator end = LayerIterator::End(&render_surface_layer_list);
226 for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list);
227 it != end; ++it) {
228 if (!it.represents_itself())
229 continue;
231 // TODO(avallee): Figure out if we should show something for a layer who's
232 // animating bounds but that we can't compute them.
233 gfx::BoxF inflated_bounds;
234 if (!LayerUtils::GetAnimationBounds(**it, &inflated_bounds))
235 continue;
237 debug_rects_.push_back(
238 DebugRect(ANIMATION_BOUNDS_RECT_TYPE,
239 gfx::ToEnclosingRect(gfx::RectF(inflated_bounds.x(),
240 inflated_bounds.y(),
241 inflated_bounds.width(),
242 inflated_bounds.height()))));
246 } // namespace cc