blob: 7f3c2ea79b2a5765623e42d0a80b56a39f630e6e [file] [log] [blame]
[email protected]94f206c12012-08-25 00:09:141// 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.
4
5#include "config.h"
6
7#if USE(ACCELERATED_COMPOSITING)
8#include "CCDebugRectHistory.h"
9
10#include "CCDamageTracker.h"
11#include "CCLayerImpl.h"
12#include "CCLayerTreeHost.h"
13#include "CCMathUtil.h"
14
[email protected]9c88e562012-09-14 22:21:3015namespace cc {
[email protected]94f206c12012-08-25 00:09:1416
17CCDebugRectHistory::CCDebugRectHistory()
18{
19}
20
[email protected]76481592012-09-21 16:47:0621CCDebugRectHistory::~CCDebugRectHistory()
22{
23}
24
[email protected]d58499a2012-10-09 22:27:4725void CCDebugRectHistory::saveDebugRectsForCurrentFrame(CCLayerImpl* rootLayer, const std::vector<CCLayerImpl*>& renderSurfaceLayerList, const Vector<IntRect>& occludingScreenSpaceRects, const CCLayerTreeSettings& settings)
[email protected]94f206c12012-08-25 00:09:1426{
27 // For now, clear all rects from previous frames. In the future we may want to store
28 // all debug rects for a history of many frames.
29 m_debugRects.clear();
30
31 if (settings.showPaintRects)
32 savePaintRects(rootLayer);
33
34 if (settings.showPropertyChangedRects)
35 savePropertyChangedRects(renderSurfaceLayerList);
36
37 if (settings.showSurfaceDamageRects)
38 saveSurfaceDamageRects(renderSurfaceLayerList);
39
40 if (settings.showScreenSpaceRects)
41 saveScreenSpaceRects(renderSurfaceLayerList);
42
43 if (settings.showOccludingRects)
44 saveOccludingRects(occludingScreenSpaceRects);
45}
46
47
48void CCDebugRectHistory::savePaintRects(CCLayerImpl* layer)
49{
50 // We would like to visualize where any layer's paint rect (update rect) has changed,
51 // regardless of whether this layer is skipped for actual drawing or not. Therefore
52 // we traverse recursively over all layers, not just the render surface list.
53
54 if (!layer->updateRect().isEmpty() && layer->drawsContent()) {
55 FloatRect updateContentRect = layer->updateRect();
56 updateContentRect.scale(layer->contentBounds().width() / static_cast<float>(layer->bounds().width()), layer->contentBounds().height() / static_cast<float>(layer->bounds().height()));
57 m_debugRects.append(CCDebugRect(PaintRectType, CCMathUtil::mapClippedRect(layer->screenSpaceTransform(), updateContentRect)));
58 }
59
60 for (unsigned i = 0; i < layer->children().size(); ++i)
[email protected]0920e24f2012-09-20 03:34:0361 savePaintRects(layer->children()[i]);
[email protected]94f206c12012-08-25 00:09:1462}
63
[email protected]d58499a2012-10-09 22:27:4764void CCDebugRectHistory::savePropertyChangedRects(const std::vector<CCLayerImpl*>& renderSurfaceLayerList)
[email protected]94f206c12012-08-25 00:09:1465{
66 for (int surfaceIndex = renderSurfaceLayerList.size() - 1; surfaceIndex >= 0 ; --surfaceIndex) {
67 CCLayerImpl* renderSurfaceLayer = renderSurfaceLayerList[surfaceIndex];
68 CCRenderSurface* renderSurface = renderSurfaceLayer->renderSurface();
69 ASSERT(renderSurface);
70
[email protected]d58499a2012-10-09 22:27:4771 const std::vector<CCLayerImpl*>& layerList = renderSurface->layerList();
[email protected]94f206c12012-08-25 00:09:1472 for (unsigned layerIndex = 0; layerIndex < layerList.size(); ++layerIndex) {
73 CCLayerImpl* layer = layerList[layerIndex];
74
75 if (CCLayerTreeHostCommon::renderSurfaceContributesToTarget<CCLayerImpl>(layer, renderSurfaceLayer->id()))
76 continue;
77
78 if (layer->layerIsAlwaysDamaged())
79 continue;
80
81 if (layer->layerPropertyChanged() || layer->layerSurfacePropertyChanged())
82 m_debugRects.append(CCDebugRect(PropertyChangedRectType, CCMathUtil::mapClippedRect(layer->screenSpaceTransform(), FloatRect(FloatPoint::zero(), layer->contentBounds()))));
83 }
84 }
85}
86
[email protected]d58499a2012-10-09 22:27:4787void CCDebugRectHistory::saveSurfaceDamageRects(const std::vector<CCLayerImpl* >& renderSurfaceLayerList)
[email protected]94f206c12012-08-25 00:09:1488{
89 for (int surfaceIndex = renderSurfaceLayerList.size() - 1; surfaceIndex >= 0 ; --surfaceIndex) {
90 CCLayerImpl* renderSurfaceLayer = renderSurfaceLayerList[surfaceIndex];
91 CCRenderSurface* renderSurface = renderSurfaceLayer->renderSurface();
92 ASSERT(renderSurface);
93
94 m_debugRects.append(CCDebugRect(SurfaceDamageRectType, CCMathUtil::mapClippedRect(renderSurface->screenSpaceTransform(), renderSurface->damageTracker()->currentDamageRect())));
95 }
96}
97
[email protected]d58499a2012-10-09 22:27:4798void CCDebugRectHistory::saveScreenSpaceRects(const std::vector<CCLayerImpl* >& renderSurfaceLayerList)
[email protected]94f206c12012-08-25 00:09:1499{
100 for (int surfaceIndex = renderSurfaceLayerList.size() - 1; surfaceIndex >= 0 ; --surfaceIndex) {
101 CCLayerImpl* renderSurfaceLayer = renderSurfaceLayerList[surfaceIndex];
102 CCRenderSurface* renderSurface = renderSurfaceLayer->renderSurface();
103 ASSERT(renderSurface);
104
105 m_debugRects.append(CCDebugRect(ScreenSpaceRectType, CCMathUtil::mapClippedRect(renderSurface->screenSpaceTransform(), renderSurface->contentRect())));
106
107 if (renderSurfaceLayer->replicaLayer())
108 m_debugRects.append(CCDebugRect(ReplicaScreenSpaceRectType, CCMathUtil::mapClippedRect(renderSurface->replicaScreenSpaceTransform(), renderSurface->contentRect())));
109 }
110}
111
112void CCDebugRectHistory::saveOccludingRects(const Vector<IntRect>& occludingRects)
113{
114 for (size_t i = 0; i < occludingRects.size(); ++i)
115 m_debugRects.append(CCDebugRect(OccludingRectType, occludingRects[i]));
116}
117
[email protected]9c88e562012-09-14 22:21:30118} // namespace cc
[email protected]94f206c12012-08-25 00:09:14119
120#endif // USE(ACCELERATED_COMPOSITING)