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/memory/scoped_ptr.h"
10 #include "cc/base/cc_export.h"
11 #include "cc/layers/layer_lists.h"
12 #include "ui/gfx/rect.h"
22 class FilterOperations;
24 class RenderSurfaceImpl;
26 // Computes the region where pixels have actually changed on a
27 // RenderSurfaceImpl. This region is used to scissor what is actually drawn to
28 // the screen to save GPU computation and bandwidth.
29 class CC_EXPORT DamageTracker {
31 static scoped_ptr<DamageTracker> Create();
34 void DidDrawDamagedArea() { current_damage_rect_ = gfx::Rect(); }
35 void AddDamageNextUpdate(const gfx::Rect& dmg) {
36 current_damage_rect_.Union(dmg);
38 void UpdateDamageTrackingState(
39 const LayerImplList& layer_list,
40 int target_surface_layer_id,
41 bool target_surface_property_changed_only_from_descendant,
42 const gfx::Rect& target_surface_content_rect,
43 LayerImpl* target_surface_mask_layer,
44 const FilterOperations& filters);
46 gfx::Rect current_damage_rect() { return current_damage_rect_; }
51 gfx::Rect TrackDamageFromActiveLayers(const LayerImplList& layer_list,
52 int target_surface_layer_id);
53 gfx::Rect TrackDamageFromSurfaceMask(LayerImpl* target_surface_mask_layer);
54 gfx::Rect TrackDamageFromLeftoverRects();
56 void PrepareRectHistoryForUpdate();
58 // These helper functions are used only in TrackDamageFromActiveLayers().
59 void ExtendDamageForLayer(LayerImpl* layer, gfx::Rect* target_damage_rect);
60 void ExtendDamageForRenderSurface(LayerImpl* layer,
61 gfx::Rect* target_damage_rect);
64 RectMapData() : layer_id_(0), mailboxId_(0) {}
65 explicit RectMapData(int layer_id) : layer_id_(layer_id), mailboxId_(0) {}
66 void Update(const gfx::Rect& rect, unsigned int mailboxId) {
67 mailboxId_ = mailboxId;
71 bool operator < (const RectMapData& other) const {
72 return layer_id_ < other.layer_id_;
76 unsigned int mailboxId_;
79 typedef std::vector<RectMapData> SortedRectMap;
81 RectMapData& RectDataForLayer(int layer_id, bool* layer_is_new);
83 SortedRectMap rect_history_;
85 unsigned int mailboxId_;
86 gfx::Rect current_damage_rect_;
88 DISALLOW_COPY_AND_ASSIGN(DamageTracker);
93 #endif // CC_TREES_DAMAGE_TRACKER_H_