• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/memory/scoped_ptr.h"
10 #include "cc/base/cc_export.h"
11 #include "cc/layers/layer_lists.h"
12 #include "ui/gfx/rect_f.h"
13 
14 class SkImageFilter;
15 
16 namespace gfx {
17 class Rect;
18 }
19 
20 namespace cc {
21 
22 class FilterOperations;
23 class LayerImpl;
24 class RenderSurfaceImpl;
25 
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 {
30  public:
31   static scoped_ptr<DamageTracker> Create();
32   ~DamageTracker();
33 
DidDrawDamagedArea()34   void DidDrawDamagedArea() { current_damage_rect_ = gfx::RectF(); }
AddDamageNextUpdate(gfx::RectF dmg)35   void AddDamageNextUpdate(gfx::RectF dmg) { current_damage_rect_.Union(dmg); }
36   void UpdateDamageTrackingState(
37       const LayerImplList& layer_list,
38       int target_surface_layer_id,
39       bool target_surface_property_changed_only_from_descendant,
40       gfx::Rect target_surface_content_rect,
41       LayerImpl* target_surface_mask_layer,
42       const FilterOperations& filters);
43 
current_damage_rect()44   gfx::RectF current_damage_rect() { return current_damage_rect_; }
45 
46  private:
47   DamageTracker();
48 
49   gfx::RectF TrackDamageFromActiveLayers(
50       const LayerImplList& layer_list,
51       int target_surface_layer_id);
52   gfx::RectF TrackDamageFromSurfaceMask(LayerImpl* target_surface_mask_layer);
53   gfx::RectF TrackDamageFromLeftoverRects();
54 
55   void PrepareRectHistoryForUpdate();
56 
57   // These helper functions are used only in TrackDamageFromActiveLayers().
58   void ExtendDamageForLayer(LayerImpl* layer, gfx::RectF* target_damage_rect);
59   void ExtendDamageForRenderSurface(LayerImpl* layer,
60                                     gfx::RectF* target_damage_rect);
61 
62   struct RectMapData {
RectMapDataRectMapData63     RectMapData() : layer_id_(0), mailboxId_(0) {}
RectMapDataRectMapData64     explicit RectMapData(int layer_id) : layer_id_(layer_id), mailboxId_(0) {}
UpdateRectMapData65     void Update(const gfx::RectF& rect, unsigned int mailboxId) {
66       mailboxId_ = mailboxId;
67       rect_ = rect;
68     }
69 
70     bool operator < (const RectMapData& other) const {
71       return layer_id_ < other.layer_id_;
72     }
73 
74     int layer_id_;
75     unsigned int mailboxId_;
76     gfx::RectF rect_;
77   };
78   typedef std::vector<RectMapData> SortedRectMap;
79 
80   RectMapData& RectDataForLayer(int layer_id, bool* layer_is_new);
81 
82   SortedRectMap rect_history_;
83 
84   unsigned int mailboxId_;
85   gfx::RectF current_damage_rect_;
86 
87   DISALLOW_COPY_AND_ASSIGN(DamageTracker);
88 };
89 
90 }  // namespace cc
91 
92 #endif  // CC_TREES_DAMAGE_TRACKER_H_
93