1 // Copyright 2011 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_DAMAGE_TRACKER_H_
6 #define CC_DAMAGE_TRACKER_H_
8 #include "base/hash_tables.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "cc/cc_export.h"
11 #include "ui/gfx/rect_f.h"
21 class WebFilterOperations
;
27 class RenderSurfaceImpl
;
29 // Computes the region where pixels have actually changed on a RenderSurfaceImpl. This region is used
30 // to scissor what is actually drawn to the screen to save GPU computation and bandwidth.
31 class CC_EXPORT DamageTracker
{
33 static scoped_ptr
<DamageTracker
> create();
36 void didDrawDamagedArea() { m_currentDamageRect
= gfx::RectF(); }
37 void forceFullDamageNextUpdate() { m_forceFullDamageNextUpdate
= true; }
38 void updateDamageTrackingState(const std::vector
<LayerImpl
*>& layerList
, int targetSurfaceLayerID
, bool targetSurfacePropertyChangedOnlyFromDescendant
, const gfx::Rect
& targetSurfaceContentRect
, LayerImpl
* targetSurfaceMaskLayer
, const WebKit::WebFilterOperations
&, SkImageFilter
* filter
);
40 const gfx::RectF
& currentDamageRect() { return m_currentDamageRect
; }
45 gfx::RectF
trackDamageFromActiveLayers(const std::vector
<LayerImpl
*>& layerList
, int targetSurfaceLayerID
);
46 gfx::RectF
trackDamageFromSurfaceMask(LayerImpl
* targetSurfaceMaskLayer
);
47 gfx::RectF
trackDamageFromLeftoverRects();
49 gfx::RectF
removeRectFromCurrentFrame(int layerID
, bool& layerIsNew
);
50 void saveRectForNextFrame(int layerID
, const gfx::RectF
& targetSpaceRect
);
52 // These helper functions are used only in trackDamageFromActiveLayers().
53 void extendDamageForLayer(LayerImpl
*, gfx::RectF
& targetDamageRect
);
54 void extendDamageForRenderSurface(LayerImpl
*, gfx::RectF
& targetDamageRect
);
56 // To correctly track exposed regions, two hashtables of rects are maintained.
57 // The "current" map is used to compute exposed regions of the current frame, while
58 // the "next" map is used to collect layer rects that are used in the next frame.
59 typedef base::hash_map
<int, gfx::RectF
> RectMap
;
60 scoped_ptr
<RectMap
> m_currentRectHistory
;
61 scoped_ptr
<RectMap
> m_nextRectHistory
;
63 gfx::RectF m_currentDamageRect
;
64 bool m_forceFullDamageNextUpdate
;
66 DISALLOW_COPY_AND_ASSIGN(DamageTracker
);
71 #endif // CC_DAMAGE_TRACKER_H_