Fix a type mismatch on Windows caused by r201738.
[chromium-blink-merge.git] / cc / debug / debug_rect_history.cc
blob7eaf6ab630a2a773a51916fb3edf45a36ef0c645
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/render_surface_impl.h"
10 #include "cc/trees/damage_tracker.h"
11 #include "cc/trees/layer_tree_host.h"
13 namespace cc {
15 // static
16 scoped_ptr<DebugRectHistory> DebugRectHistory::Create() {
17 return make_scoped_ptr(new DebugRectHistory());
20 DebugRectHistory::DebugRectHistory() {}
22 DebugRectHistory::~DebugRectHistory() {}
24 void DebugRectHistory::SaveDebugRectsForCurrentFrame(
25 LayerImpl* root_layer,
26 const LayerImplList& render_surface_layer_list,
27 const std::vector<gfx::Rect>& occluding_screen_space_rects,
28 const std::vector<gfx::Rect>& non_occluding_screen_space_rects,
29 const LayerTreeDebugState& debug_state) {
30 // For now, clear all rects from previous frames. In the future we may want to
31 // store all debug rects for a history of many frames.
32 debug_rects_.clear();
34 if (debug_state.show_paint_rects)
35 SavePaintRects(root_layer);
37 if (debug_state.show_property_changed_rects)
38 SavePropertyChangedRects(render_surface_layer_list);
40 if (debug_state.show_surface_damage_rects)
41 SaveSurfaceDamageRects(render_surface_layer_list);
43 if (debug_state.show_screen_space_rects)
44 SaveScreenSpaceRects(render_surface_layer_list);
46 if (debug_state.show_occluding_rects)
47 SaveOccludingRects(occluding_screen_space_rects);
49 if (debug_state.show_non_occluding_rects)
50 SaveNonOccludingRects(non_occluding_screen_space_rects);
53 void DebugRectHistory::SavePaintRects(LayerImpl* layer) {
54 // We would like to visualize where any layer's paint rect (update rect) has
55 // changed, regardless of whether this layer is skipped for actual drawing or
56 // not. Therefore we traverse recursively over all layers, not just the render
57 // surface list.
59 if (!layer->update_rect().IsEmpty() && layer->DrawsContent()) {
60 float width_scale = layer->content_bounds().width() /
61 static_cast<float>(layer->bounds().width());
62 float height_scale = layer->content_bounds().height() /
63 static_cast<float>(layer->bounds().height());
64 gfx::RectF update_content_rect =
65 gfx::ScaleRect(layer->update_rect(), width_scale, height_scale);
66 debug_rects_.push_back(
67 DebugRect(PAINT_RECT_TYPE,
68 MathUtil::MapClippedRect(layer->screen_space_transform(),
69 update_content_rect)));
72 for (unsigned i = 0; i < layer->children().size(); ++i)
73 SavePaintRects(layer->children()[i]);
76 void DebugRectHistory::SavePropertyChangedRects(
77 const LayerImplList& render_surface_layer_list) {
78 for (int surface_index = render_surface_layer_list.size() - 1;
79 surface_index >= 0;
80 --surface_index) {
81 LayerImpl* render_surface_layer = render_surface_layer_list[surface_index];
82 RenderSurfaceImpl* render_surface = render_surface_layer->render_surface();
83 DCHECK(render_surface);
85 const LayerImplList& layer_list = render_surface->layer_list();
86 for (unsigned layer_index = 0;
87 layer_index < layer_list.size();
88 ++layer_index) {
89 LayerImpl* layer = layer_list[layer_index];
91 if (LayerTreeHostCommon::RenderSurfaceContributesToTarget<LayerImpl>(
92 layer, render_surface_layer->id()))
93 continue;
95 if (layer->LayerIsAlwaysDamaged())
96 continue;
98 if (layer->LayerPropertyChanged() ||
99 layer->LayerSurfacePropertyChanged()) {
100 debug_rects_.push_back(
101 DebugRect(PROPERTY_CHANGED_RECT_TYPE,
102 MathUtil::MapClippedRect(
103 layer->screen_space_transform(),
104 gfx::RectF(gfx::PointF(), layer->content_bounds()))));
110 void DebugRectHistory::SaveSurfaceDamageRects(
111 const LayerImplList& render_surface_layer_list) {
112 for (int surface_index = render_surface_layer_list.size() - 1;
113 surface_index >= 0;
114 --surface_index) {
115 LayerImpl* render_surface_layer = render_surface_layer_list[surface_index];
116 RenderSurfaceImpl* render_surface = render_surface_layer->render_surface();
117 DCHECK(render_surface);
119 debug_rects_.push_back(DebugRect(
120 SURFACE_DAMAGE_RECT_TYPE,
121 MathUtil::MapClippedRect(
122 render_surface->screen_space_transform(),
123 render_surface->damage_tracker()->current_damage_rect())));
127 void DebugRectHistory::SaveScreenSpaceRects(
128 const LayerImplList& render_surface_layer_list) {
129 for (int surface_index = render_surface_layer_list.size() - 1;
130 surface_index >= 0;
131 --surface_index) {
132 LayerImpl* render_surface_layer = render_surface_layer_list[surface_index];
133 RenderSurfaceImpl* render_surface = render_surface_layer->render_surface();
134 DCHECK(render_surface);
136 debug_rects_.push_back(DebugRect(
137 SCREEN_SPACE_RECT_TYPE,
138 MathUtil::MapClippedRect(render_surface->screen_space_transform(),
139 render_surface->content_rect())));
141 if (render_surface_layer->replica_layer()) {
142 debug_rects_.push_back(
143 DebugRect(REPLICA_SCREEN_SPACE_RECT_TYPE,
144 MathUtil::MapClippedRect(
145 render_surface->replica_screen_space_transform(),
146 render_surface->content_rect())));
151 void DebugRectHistory::SaveOccludingRects(
152 const std::vector<gfx::Rect>& occluding_rects) {
153 for (size_t i = 0; i < occluding_rects.size(); ++i)
154 debug_rects_.push_back(DebugRect(OCCLUDING_RECT_TYPE, occluding_rects[i]));
157 void DebugRectHistory::SaveNonOccludingRects(
158 const std::vector<gfx::Rect>& non_occluding_rects) {
159 for (size_t i = 0; i < non_occluding_rects.size(); ++i) {
160 debug_rects_.push_back(
161 DebugRect(NONOCCLUDING_RECT_TYPE, non_occluding_rects[i]));
165 } // namespace cc