WebKit Roll 139512:139548
[chromium-blink-merge.git] / cc / debug_rect_history.h
blobd4b19799f8ac77ff315d7c0dac11953d4c95f4d6
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 #ifndef CC_DEBUG_RECT_HISTORY_H_
6 #define CC_DEBUG_RECT_HISTORY_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "ui/gfx/rect.h"
11 #include "ui/gfx/rect_f.h"
12 #include <vector>
14 namespace cc {
16 class LayerImpl;
17 class LayerTreeDebugState;
19 // There are currently six types of debug rects:
21 // - Paint rects (update rects): regions of a layer that needed to be re-uploaded to the
22 // texture resource; in most cases implying that they had to be repainted, too.
24 // - Property-changed rects: enclosing bounds of layers that cause changes to the screen
25 // even if the layer did not change internally. (For example, if the layer's opacity or
26 // position changes.)
28 // - Surface damage rects: the aggregate damage on a target surface that is caused by all
29 // layers and surfaces that contribute to it. This includes (1) paint rects, (2) property-
30 // changed rects, and (3) newly exposed areas.
32 // - Screen space rects: this is the region the contents occupy in screen space.
34 // - Replica screen space rects: this is the region the replica's contents occupy in screen space.
36 // - Occluding rects: these are the regions that contribute to the occluded region.
38 // - Non-Occluding rects: these are the regions of composited layers that do not
39 // contribute to the occluded region.
41 enum DebugRectType { PaintRectType, PropertyChangedRectType, SurfaceDamageRectType, ScreenSpaceRectType, ReplicaScreenSpaceRectType, OccludingRectType, NonOccludingRectType };
43 struct DebugRect {
44 DebugRect(DebugRectType newType, gfx::RectF newRect)
45 : type(newType)
46 , rect(newRect) { }
48 DebugRectType type;
49 gfx::RectF rect;
52 // This class maintains a history of rects of various types that can be used
53 // for debugging purposes. The overhead of collecting rects is performed only if
54 // the appropriate LayerTreeSettings are enabled.
55 class DebugRectHistory {
56 public:
57 static scoped_ptr<DebugRectHistory> create();
59 ~DebugRectHistory();
61 // Note: Saving debug rects must happen before layers' change tracking is reset.
62 void saveDebugRectsForCurrentFrame(LayerImpl* rootLayer, const std::vector<LayerImpl*>& renderSurfaceLayerList, const std::vector<gfx::Rect>& occludingScreenSpaceRects, const std::vector<gfx::Rect>& nonOccludingScreenSpaceRects, const LayerTreeDebugState& debugState);
64 const std::vector<DebugRect>& debugRects() { return m_debugRects; }
66 private:
67 DebugRectHistory();
69 void savePaintRects(LayerImpl*);
70 void savePropertyChangedRects(const std::vector<LayerImpl*>& renderSurfaceLayerList);
71 void saveSurfaceDamageRects(const std::vector<LayerImpl* >& renderSurfaceLayerList);
72 void saveScreenSpaceRects(const std::vector<LayerImpl* >& renderSurfaceLayerList);
73 void saveOccludingRects(const std::vector<gfx::Rect>& occludingScreenSpaceRects);
74 void saveNonOccludingRects(const std::vector<gfx::Rect>& nonOccludingScreenSpaceRects);
76 std::vector<DebugRect> m_debugRects;
78 DISALLOW_COPY_AND_ASSIGN(DebugRectHistory);
81 } // namespace cc
83 #endif // CC_DEBUG_RECT_HISTORY_H_