forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug_rect_history.cc
165 lines (136 loc) · 5.91 KB
/
debug_rect_history.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/debug/debug_rect_history.h"
#include "cc/base/math_util.h"
#include "cc/layers/layer_impl.h"
#include "cc/layers/render_surface_impl.h"
#include "cc/trees/damage_tracker.h"
#include "cc/trees/layer_tree_host.h"
namespace cc {
// static
scoped_ptr<DebugRectHistory> DebugRectHistory::Create() {
return make_scoped_ptr(new DebugRectHistory());
}
DebugRectHistory::DebugRectHistory() {}
DebugRectHistory::~DebugRectHistory() {}
void DebugRectHistory::SaveDebugRectsForCurrentFrame(
LayerImpl* root_layer,
const LayerImplList& render_surface_layer_list,
const std::vector<gfx::Rect>& occluding_screen_space_rects,
const std::vector<gfx::Rect>& non_occluding_screen_space_rects,
const LayerTreeDebugState& debug_state) {
// For now, clear all rects from previous frames. In the future we may want to
// store all debug rects for a history of many frames.
debug_rects_.clear();
if (debug_state.show_paint_rects)
SavePaintRects(root_layer);
if (debug_state.show_property_changed_rects)
SavePropertyChangedRects(render_surface_layer_list);
if (debug_state.show_surface_damage_rects)
SaveSurfaceDamageRects(render_surface_layer_list);
if (debug_state.show_screen_space_rects)
SaveScreenSpaceRects(render_surface_layer_list);
if (debug_state.show_occluding_rects)
SaveOccludingRects(occluding_screen_space_rects);
if (debug_state.show_non_occluding_rects)
SaveNonOccludingRects(non_occluding_screen_space_rects);
}
void DebugRectHistory::SavePaintRects(LayerImpl* layer) {
// We would like to visualize where any layer's paint rect (update rect) has
// changed, regardless of whether this layer is skipped for actual drawing or
// not. Therefore we traverse recursively over all layers, not just the render
// surface list.
if (!layer->update_rect().IsEmpty() && layer->DrawsContent()) {
float width_scale = layer->content_bounds().width() /
static_cast<float>(layer->bounds().width());
float height_scale = layer->content_bounds().height() /
static_cast<float>(layer->bounds().height());
gfx::RectF update_content_rect =
gfx::ScaleRect(layer->update_rect(), width_scale, height_scale);
debug_rects_.push_back(
DebugRect(PAINT_RECT_TYPE,
MathUtil::MapClippedRect(layer->screen_space_transform(),
update_content_rect)));
}
for (unsigned i = 0; i < layer->children().size(); ++i)
SavePaintRects(layer->children()[i]);
}
void DebugRectHistory::SavePropertyChangedRects(
const LayerImplList& render_surface_layer_list) {
for (int surface_index = render_surface_layer_list.size() - 1;
surface_index >= 0;
--surface_index) {
LayerImpl* render_surface_layer = render_surface_layer_list[surface_index];
RenderSurfaceImpl* render_surface = render_surface_layer->render_surface();
DCHECK(render_surface);
const LayerImplList& layer_list = render_surface->layer_list();
for (unsigned layer_index = 0;
layer_index < layer_list.size();
++layer_index) {
LayerImpl* layer = layer_list[layer_index];
if (LayerTreeHostCommon::RenderSurfaceContributesToTarget<LayerImpl>(
layer, render_surface_layer->id()))
continue;
if (layer->LayerIsAlwaysDamaged())
continue;
if (layer->LayerPropertyChanged() ||
layer->LayerSurfacePropertyChanged()) {
debug_rects_.push_back(
DebugRect(PROPERTY_CHANGED_RECT_TYPE,
MathUtil::MapClippedRect(
layer->screen_space_transform(),
gfx::RectF(gfx::PointF(), layer->content_bounds()))));
}
}
}
}
void DebugRectHistory::SaveSurfaceDamageRects(
const LayerImplList& render_surface_layer_list) {
for (int surface_index = render_surface_layer_list.size() - 1;
surface_index >= 0;
--surface_index) {
LayerImpl* render_surface_layer = render_surface_layer_list[surface_index];
RenderSurfaceImpl* render_surface = render_surface_layer->render_surface();
DCHECK(render_surface);
debug_rects_.push_back(DebugRect(
SURFACE_DAMAGE_RECT_TYPE,
MathUtil::MapClippedRect(
render_surface->screen_space_transform(),
render_surface->damage_tracker()->current_damage_rect())));
}
}
void DebugRectHistory::SaveScreenSpaceRects(
const LayerImplList& render_surface_layer_list) {
for (int surface_index = render_surface_layer_list.size() - 1;
surface_index >= 0;
--surface_index) {
LayerImpl* render_surface_layer = render_surface_layer_list[surface_index];
RenderSurfaceImpl* render_surface = render_surface_layer->render_surface();
DCHECK(render_surface);
debug_rects_.push_back(DebugRect(
SCREEN_SPACE_RECT_TYPE,
MathUtil::MapClippedRect(render_surface->screen_space_transform(),
render_surface->content_rect())));
if (render_surface_layer->replica_layer()) {
debug_rects_.push_back(
DebugRect(REPLICA_SCREEN_SPACE_RECT_TYPE,
MathUtil::MapClippedRect(
render_surface->replica_screen_space_transform(),
render_surface->content_rect())));
}
}
}
void DebugRectHistory::SaveOccludingRects(
const std::vector<gfx::Rect>& occluding_rects) {
for (size_t i = 0; i < occluding_rects.size(); ++i)
debug_rects_.push_back(DebugRect(OCCLUDING_RECT_TYPE, occluding_rects[i]));
}
void DebugRectHistory::SaveNonOccludingRects(
const std::vector<gfx::Rect>& non_occluding_rects) {
for (size_t i = 0; i < non_occluding_rects.size(); ++i) {
debug_rects_.push_back(
DebugRect(NONOCCLUDING_RECT_TYPE, non_occluding_rects[i]));
}
}
} // namespace cc