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
|
// 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 "config.h"
#if USE(ACCELERATED_COMPOSITING)
#include "CCDebugRectHistory.h"
#include "CCDamageTracker.h"
#include "CCLayerImpl.h"
#include "CCLayerTreeHost.h"
#include "CCMathUtil.h"
namespace cc {
// static
scoped_ptr<CCDebugRectHistory> CCDebugRectHistory::create() {
return make_scoped_ptr(new CCDebugRectHistory());
}
CCDebugRectHistory::CCDebugRectHistory()
{
}
CCDebugRectHistory::~CCDebugRectHistory()
{
}
void CCDebugRectHistory::saveDebugRectsForCurrentFrame(CCLayerImpl* rootLayer, const std::vector<CCLayerImpl*>& renderSurfaceLayerList, const Vector<IntRect>& occludingScreenSpaceRects, const CCLayerTreeSettings& settings)
{
// 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.
m_debugRects.clear();
if (settings.showPaintRects)
savePaintRects(rootLayer);
if (settings.showPropertyChangedRects)
savePropertyChangedRects(renderSurfaceLayerList);
if (settings.showSurfaceDamageRects)
saveSurfaceDamageRects(renderSurfaceLayerList);
if (settings.showScreenSpaceRects)
saveScreenSpaceRects(renderSurfaceLayerList);
if (settings.showOccludingRects)
saveOccludingRects(occludingScreenSpaceRects);
}
void CCDebugRectHistory::savePaintRects(CCLayerImpl* 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->updateRect().isEmpty() && layer->drawsContent()) {
FloatRect updateContentRect = layer->updateRect();
updateContentRect.scale(layer->contentBounds().width() / static_cast<float>(layer->bounds().width()), layer->contentBounds().height() / static_cast<float>(layer->bounds().height()));
m_debugRects.append(CCDebugRect(PaintRectType, CCMathUtil::mapClippedRect(layer->screenSpaceTransform(), updateContentRect)));
}
for (unsigned i = 0; i < layer->children().size(); ++i)
savePaintRects(layer->children()[i]);
}
void CCDebugRectHistory::savePropertyChangedRects(const std::vector<CCLayerImpl*>& renderSurfaceLayerList)
{
for (int surfaceIndex = renderSurfaceLayerList.size() - 1; surfaceIndex >= 0 ; --surfaceIndex) {
CCLayerImpl* renderSurfaceLayer = renderSurfaceLayerList[surfaceIndex];
CCRenderSurface* renderSurface = renderSurfaceLayer->renderSurface();
ASSERT(renderSurface);
const std::vector<CCLayerImpl*>& layerList = renderSurface->layerList();
for (unsigned layerIndex = 0; layerIndex < layerList.size(); ++layerIndex) {
CCLayerImpl* layer = layerList[layerIndex];
if (CCLayerTreeHostCommon::renderSurfaceContributesToTarget<CCLayerImpl>(layer, renderSurfaceLayer->id()))
continue;
if (layer->layerIsAlwaysDamaged())
continue;
if (layer->layerPropertyChanged() || layer->layerSurfacePropertyChanged())
m_debugRects.append(CCDebugRect(PropertyChangedRectType, CCMathUtil::mapClippedRect(layer->screenSpaceTransform(), FloatRect(FloatPoint::zero(), layer->contentBounds()))));
}
}
}
void CCDebugRectHistory::saveSurfaceDamageRects(const std::vector<CCLayerImpl* >& renderSurfaceLayerList)
{
for (int surfaceIndex = renderSurfaceLayerList.size() - 1; surfaceIndex >= 0 ; --surfaceIndex) {
CCLayerImpl* renderSurfaceLayer = renderSurfaceLayerList[surfaceIndex];
CCRenderSurface* renderSurface = renderSurfaceLayer->renderSurface();
ASSERT(renderSurface);
m_debugRects.append(CCDebugRect(SurfaceDamageRectType, CCMathUtil::mapClippedRect(renderSurface->screenSpaceTransform(), renderSurface->damageTracker()->currentDamageRect())));
}
}
void CCDebugRectHistory::saveScreenSpaceRects(const std::vector<CCLayerImpl* >& renderSurfaceLayerList)
{
for (int surfaceIndex = renderSurfaceLayerList.size() - 1; surfaceIndex >= 0 ; --surfaceIndex) {
CCLayerImpl* renderSurfaceLayer = renderSurfaceLayerList[surfaceIndex];
CCRenderSurface* renderSurface = renderSurfaceLayer->renderSurface();
ASSERT(renderSurface);
m_debugRects.append(CCDebugRect(ScreenSpaceRectType, CCMathUtil::mapClippedRect(renderSurface->screenSpaceTransform(), renderSurface->contentRect())));
if (renderSurfaceLayer->replicaLayer())
m_debugRects.append(CCDebugRect(ReplicaScreenSpaceRectType, CCMathUtil::mapClippedRect(renderSurface->replicaScreenSpaceTransform(), renderSurface->contentRect())));
}
}
void CCDebugRectHistory::saveOccludingRects(const Vector<IntRect>& occludingRects)
{
for (size_t i = 0; i < occludingRects.size(); ++i)
m_debugRects.append(CCDebugRect(OccludingRectType, occludingRects[i]));
}
} // namespace cc
#endif // USE(ACCELERATED_COMPOSITING)
|