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. 4 5 #ifndef CC_TREES_DAMAGE_TRACKER_H_ 6 #define CC_TREES_DAMAGE_TRACKER_H_ 7 8 #include <vector> 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" 14 15 class SkImageFilter; 16 17 namespace gfx { 18 class Rect; 19 } 20 21 namespace cc { 22 23 class FilterOperations; 24 class LayerImpl; 25 class RenderSurfaceImpl; 26 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 { 31 public: 32 static scoped_ptr<DamageTracker> Create(); 33 ~DamageTracker(); 34 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); 45 46 gfx::RectF current_damage_rect() { return current_damage_rect_; } 47 48 private: 49 DamageTracker(); 50 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(); 56 57 gfx::RectF RemoveRectFromCurrentFrame(int layer_id, bool* layer_is_new); 58 void SaveRectForNextFrame(int layer_id, const gfx::RectF& target_space_rect); 59 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); 64 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 68 // next frame. 69 typedef base::hash_map<int, gfx::RectF> RectMap; 70 scoped_ptr<RectMap> current_rect_history_; 71 scoped_ptr<RectMap> next_rect_history_; 72 73 gfx::RectF current_damage_rect_; 74 75 DISALLOW_COPY_AND_ASSIGN(DamageTracker); 76 }; 77 78 } // namespace cc 79 80 #endif // CC_TREES_DAMAGE_TRACKER_H_ 81