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_rect_history.h"
7 #include "cc/damage_tracker.h"
8 #include "cc/layer_impl.h"
9 #include "cc/layer_tree_host.h"
10 #include "cc/math_util.h"
15 scoped_ptr
<DebugRectHistory
> DebugRectHistory::create() {
16 return make_scoped_ptr(new DebugRectHistory());
19 DebugRectHistory::DebugRectHistory()
23 DebugRectHistory::~DebugRectHistory()
27 void DebugRectHistory::saveDebugRectsForCurrentFrame(LayerImpl
* rootLayer
, const std::vector
<LayerImpl
*>& renderSurfaceLayerList
, const std::vector
<gfx::Rect
>& occludingScreenSpaceRects
, const std::vector
<gfx::Rect
>& nonOccludingScreenSpaceRects
, const LayerTreeDebugState
& debugState
)
29 // For now, clear all rects from previous frames. In the future we may want to store
30 // all debug rects for a history of many frames.
33 if (debugState
.showPaintRects
)
34 savePaintRects(rootLayer
);
36 if (debugState
.showPropertyChangedRects
)
37 savePropertyChangedRects(renderSurfaceLayerList
);
39 if (debugState
.showSurfaceDamageRects
)
40 saveSurfaceDamageRects(renderSurfaceLayerList
);
42 if (debugState
.showScreenSpaceRects
)
43 saveScreenSpaceRects(renderSurfaceLayerList
);
45 if (debugState
.showOccludingRects
)
46 saveOccludingRects(occludingScreenSpaceRects
);
48 if (debugState
.showNonOccludingRects
)
49 saveNonOccludingRects(nonOccludingScreenSpaceRects
);
53 void DebugRectHistory::savePaintRects(LayerImpl
* layer
)
55 // We would like to visualize where any layer's paint rect (update rect) has changed,
56 // regardless of whether this layer is skipped for actual drawing or not. Therefore
57 // we traverse recursively over all layers, not just the render surface list.
59 if (!layer
->updateRect().IsEmpty() && layer
->drawsContent()) {
60 float widthScale
= layer
->contentBounds().width() / static_cast<float>(layer
->bounds().width());
61 float heightScale
= layer
->contentBounds().height() / static_cast<float>(layer
->bounds().height());
62 gfx::RectF updateContentRect
= gfx::ScaleRect(layer
->updateRect(), widthScale
, heightScale
);
63 m_debugRects
.push_back(DebugRect(PaintRectType
, MathUtil::mapClippedRect(layer
->screenSpaceTransform(), updateContentRect
)));
66 for (unsigned i
= 0; i
< layer
->children().size(); ++i
)
67 savePaintRects(layer
->children()[i
]);
70 void DebugRectHistory::savePropertyChangedRects(const std::vector
<LayerImpl
*>& renderSurfaceLayerList
)
72 for (int surfaceIndex
= renderSurfaceLayerList
.size() - 1; surfaceIndex
>= 0 ; --surfaceIndex
) {
73 LayerImpl
* renderSurfaceLayer
= renderSurfaceLayerList
[surfaceIndex
];
74 RenderSurfaceImpl
* renderSurface
= renderSurfaceLayer
->renderSurface();
75 DCHECK(renderSurface
);
77 const std::vector
<LayerImpl
*>& layerList
= renderSurface
->layerList();
78 for (unsigned layerIndex
= 0; layerIndex
< layerList
.size(); ++layerIndex
) {
79 LayerImpl
* layer
= layerList
[layerIndex
];
81 if (LayerTreeHostCommon::renderSurfaceContributesToTarget
<LayerImpl
>(layer
, renderSurfaceLayer
->id()))
84 if (layer
->layerIsAlwaysDamaged())
87 if (layer
->layerPropertyChanged() || layer
->layerSurfacePropertyChanged())
88 m_debugRects
.push_back(DebugRect(PropertyChangedRectType
, MathUtil::mapClippedRect(layer
->screenSpaceTransform(), gfx::RectF(gfx::PointF(), layer
->contentBounds()))));
93 void DebugRectHistory::saveSurfaceDamageRects(const std::vector
<LayerImpl
* >& renderSurfaceLayerList
)
95 for (int surfaceIndex
= renderSurfaceLayerList
.size() - 1; surfaceIndex
>= 0 ; --surfaceIndex
) {
96 LayerImpl
* renderSurfaceLayer
= renderSurfaceLayerList
[surfaceIndex
];
97 RenderSurfaceImpl
* renderSurface
= renderSurfaceLayer
->renderSurface();
98 DCHECK(renderSurface
);
100 m_debugRects
.push_back(DebugRect(SurfaceDamageRectType
, MathUtil::mapClippedRect(renderSurface
->screenSpaceTransform(), renderSurface
->damageTracker()->currentDamageRect())));
104 void DebugRectHistory::saveScreenSpaceRects(const std::vector
<LayerImpl
* >& renderSurfaceLayerList
)
106 for (int surfaceIndex
= renderSurfaceLayerList
.size() - 1; surfaceIndex
>= 0 ; --surfaceIndex
) {
107 LayerImpl
* renderSurfaceLayer
= renderSurfaceLayerList
[surfaceIndex
];
108 RenderSurfaceImpl
* renderSurface
= renderSurfaceLayer
->renderSurface();
109 DCHECK(renderSurface
);
111 m_debugRects
.push_back(DebugRect(ScreenSpaceRectType
, MathUtil::mapClippedRect(renderSurface
->screenSpaceTransform(), renderSurface
->contentRect())));
113 if (renderSurfaceLayer
->replicaLayer())
114 m_debugRects
.push_back(DebugRect(ReplicaScreenSpaceRectType
, MathUtil::mapClippedRect(renderSurface
->replicaScreenSpaceTransform(), renderSurface
->contentRect())));
118 void DebugRectHistory::saveOccludingRects(const std::vector
<gfx::Rect
>& occludingRects
)
120 for (size_t i
= 0; i
< occludingRects
.size(); ++i
)
121 m_debugRects
.push_back(DebugRect(OccludingRectType
, occludingRects
[i
]));
124 void DebugRectHistory::saveNonOccludingRects(const std::vector
<gfx::Rect
>& nonOccludingRects
)
126 for (size_t i
= 0; i
< nonOccludingRects
.size(); ++i
)
127 m_debugRects
.push_back(DebugRect(NonOccludingRectType
, nonOccludingRects
[i
]));