[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 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. |
| 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] | 9c88e56 | 2012-09-14 22:21:30 | [diff] [blame] | 15 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 16 | |
| 17 | CCDebugRectHistory::CCDebugRectHistory() |
| 18 | { |
| 19 | } |
| 20 | |
[email protected] | 7648159 | 2012-09-21 16:47:06 | [diff] [blame] | 21 | CCDebugRectHistory::~CCDebugRectHistory() |
| 22 | { |
| 23 | } |
| 24 | |
[email protected] | d58499a | 2012-10-09 22:27:47 | [diff] [blame^] | 25 | void CCDebugRectHistory::saveDebugRectsForCurrentFrame(CCLayerImpl* rootLayer, const std::vector<CCLayerImpl*>& renderSurfaceLayerList, const Vector<IntRect>& occludingScreenSpaceRects, const CCLayerTreeSettings& settings) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 26 | { |
| 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 | |
| 48 | void 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] | 0920e24f | 2012-09-20 03:34:03 | [diff] [blame] | 61 | savePaintRects(layer->children()[i]); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 62 | } |
| 63 | |
[email protected] | d58499a | 2012-10-09 22:27:47 | [diff] [blame^] | 64 | void CCDebugRectHistory::savePropertyChangedRects(const std::vector<CCLayerImpl*>& renderSurfaceLayerList) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 65 | { |
| 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] | d58499a | 2012-10-09 22:27:47 | [diff] [blame^] | 71 | const std::vector<CCLayerImpl*>& layerList = renderSurface->layerList(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 72 | 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] | d58499a | 2012-10-09 22:27:47 | [diff] [blame^] | 87 | void CCDebugRectHistory::saveSurfaceDamageRects(const std::vector<CCLayerImpl* >& renderSurfaceLayerList) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 88 | { |
| 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] | d58499a | 2012-10-09 22:27:47 | [diff] [blame^] | 98 | void CCDebugRectHistory::saveScreenSpaceRects(const std::vector<CCLayerImpl* >& renderSurfaceLayerList) |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 99 | { |
| 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 | |
| 112 | void 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] | 9c88e56 | 2012-09-14 22:21:30 | [diff] [blame] | 118 | } // namespace cc |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 119 | |
| 120 | #endif // USE(ACCELERATED_COMPOSITING) |