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_TREES_DAMAGE_TRACKER_H_
6 #define CC_TREES_DAMAGE_TRACKER_H_
9 #include "base/containers/hash_tables.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "cc/base/cc_export.h"
12 #include "cc/layers/layer_lists.h"
13 #include "ui/gfx/rect_f.h"
23 class FilterOperations
;
25 class RenderSurfaceImpl
;
27 // Computes the region where pixels have actually changed on a
28 // RenderSurfaceImpl. This region is used to scissor what is actually drawn to
29 // the screen to save GPU computation and bandwidth.
30 class CC_EXPORT DamageTracker
{
32 static scoped_ptr
<DamageTracker
> Create();
35 void DidDrawDamagedArea() { current_damage_rect_
= gfx::RectF(); }
36 void AddDamageNextUpdate(gfx::RectF dmg
) { current_damage_rect_
.Union(dmg
); }
37 void UpdateDamageTrackingState(
38 const LayerImplList
& layer_list
,
39 int target_surface_layer_id
,
40 bool target_surface_property_changed_only_from_descendant
,
41 gfx::Rect target_surface_content_rect
,
42 LayerImpl
* target_surface_mask_layer
,
43 const FilterOperations
& filters
,
44 SkImageFilter
* filter
);
46 gfx::RectF
current_damage_rect() { return current_damage_rect_
; }
51 gfx::RectF
TrackDamageFromActiveLayers(
52 const LayerImplList
& layer_list
,
53 int target_surface_layer_id
);
54 gfx::RectF
TrackDamageFromSurfaceMask(LayerImpl
* target_surface_mask_layer
);
55 gfx::RectF
TrackDamageFromLeftoverRects();
57 gfx::RectF
RemoveRectFromCurrentFrame(int layer_id
, bool* layer_is_new
);
58 void SaveRectForNextFrame(int layer_id
, const gfx::RectF
& target_space_rect
);
60 // These helper functions are used only in TrackDamageFromActiveLayers().
61 void ExtendDamageForLayer(LayerImpl
* layer
, gfx::RectF
* target_damage_rect
);
62 void ExtendDamageForRenderSurface(LayerImpl
* layer
,
63 gfx::RectF
* target_damage_rect
);
65 // To correctly track exposed regions, two hashtables of rects are maintained.
66 // The "current" map is used to compute exposed regions of the current frame,
67 // while the "next" map is used to collect layer rects that are used in the
69 typedef base::hash_map
<int, gfx::RectF
> RectMap
;
70 scoped_ptr
<RectMap
> current_rect_history_
;
71 scoped_ptr
<RectMap
> next_rect_history_
;
73 gfx::RectF current_damage_rect_
;
75 DISALLOW_COPY_AND_ASSIGN(DamageTracker
);
80 #endif // CC_TREES_DAMAGE_TRACKER_H_