• 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.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::Rect(); }
AddDamageNextUpdate(const gfx::Rect & dmg)35   void AddDamageNextUpdate(const gfx::Rect& dmg) {
36     current_damage_rect_.Union(dmg);
37   }
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);
45 
current_damage_rect()46   gfx::Rect current_damage_rect() { return current_damage_rect_; }
47 
48  private:
49   DamageTracker();
50 
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();
55 
56   void PrepareRectHistoryForUpdate();
57 
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);
62 
63   struct RectMapData {
RectMapDataRectMapData64     RectMapData() : layer_id_(0), mailboxId_(0) {}
RectMapDataRectMapData65     explicit RectMapData(int layer_id) : layer_id_(layer_id), mailboxId_(0) {}
UpdateRectMapData66     void Update(const gfx::Rect& rect, unsigned int mailboxId) {
67       mailboxId_ = mailboxId;
68       rect_ = rect;
69     }
70 
71     bool operator < (const RectMapData& other) const {
72       return layer_id_ < other.layer_id_;
73     }
74 
75     int layer_id_;
76     unsigned int mailboxId_;
77     gfx::Rect rect_;
78   };
79   typedef std::vector<RectMapData> SortedRectMap;
80 
81   RectMapData& RectDataForLayer(int layer_id, bool* layer_is_new);
82 
83   SortedRectMap rect_history_;
84 
85   unsigned int mailboxId_;
86   gfx::Rect current_damage_rect_;
87 
88   DISALLOW_COPY_AND_ASSIGN(DamageTracker);
89 };
90 
91 }  // namespace cc
92 
93 #endif  // CC_TREES_DAMAGE_TRACKER_H_
94