summaryrefslogtreecommitdiffstats
path: root/cc/trees/damage_tracker.h
blob: ce72fcc842cf7a57d63f58577c0fceee692d28e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CC_TREES_DAMAGE_TRACKER_H_
#define CC_TREES_DAMAGE_TRACKER_H_

#include <vector>
#include "base/containers/hash_tables.h"
#include "base/memory/scoped_ptr.h"
#include "cc/base/cc_export.h"
#include "cc/layers/layer_lists.h"
#include "ui/gfx/rect_f.h"

class SkImageFilter;

namespace gfx {
class Rect;
}

namespace cc {

class FilterOperations;
class LayerImpl;
class RenderSurfaceImpl;

// Computes the region where pixels have actually changed on a
// RenderSurfaceImpl. This region is used to scissor what is actually drawn to
// the screen to save GPU computation and bandwidth.
class CC_EXPORT DamageTracker {
 public:
  static scoped_ptr<DamageTracker> Create();
  ~DamageTracker();

  void DidDrawDamagedArea() { current_damage_rect_ = gfx::RectF(); }
  void AddDamageNextUpdate(gfx::RectF dmg) { current_damage_rect_.Union(dmg); }
  void UpdateDamageTrackingState(
      const LayerImplList& layer_list,
      int target_surface_layer_id,
      bool target_surface_property_changed_only_from_descendant,
      gfx::Rect target_surface_content_rect,
      LayerImpl* target_surface_mask_layer,
      const FilterOperations& filters,
      SkImageFilter* filter);

  gfx::RectF current_damage_rect() { return current_damage_rect_; }

 private:
  DamageTracker();

  gfx::RectF TrackDamageFromActiveLayers(
      const LayerImplList& layer_list,
      int target_surface_layer_id);
  gfx::RectF TrackDamageFromSurfaceMask(LayerImpl* target_surface_mask_layer);
  gfx::RectF TrackDamageFromLeftoverRects();

  gfx::RectF RemoveRectFromCurrentFrame(int layer_id, bool* layer_is_new);
  void SaveRectForNextFrame(int layer_id, const gfx::RectF& target_space_rect);

  // These helper functions are used only in TrackDamageFromActiveLayers().
  void ExtendDamageForLayer(LayerImpl* layer, gfx::RectF* target_damage_rect);
  void ExtendDamageForRenderSurface(LayerImpl* layer,
                                    gfx::RectF* target_damage_rect);

  // To correctly track exposed regions, two hashtables of rects are maintained.
  // The "current" map is used to compute exposed regions of the current frame,
  // while the "next" map is used to collect layer rects that are used in the
  // next frame.
  typedef base::hash_map<int, gfx::RectF> RectMap;
  scoped_ptr<RectMap> current_rect_history_;
  scoped_ptr<RectMap> next_rect_history_;

  gfx::RectF current_damage_rect_;

  DISALLOW_COPY_AND_ASSIGN(DamageTracker);
};

}  // namespace cc

#endif  // CC_TREES_DAMAGE_TRACKER_H_