[Android] Implement 3-way sensor fallback for Device Orientation.
[chromium-blink-merge.git] / cc / trees / damage_tracker.h
blobaafbd033bcd0d0823a487e0390427920c7b7b4ce
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_
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/geometry/rect.h"
14 class SkImageFilter;
16 namespace gfx {
17 class Rect;
20 namespace cc {
22 class FilterOperations;
23 class LayerImpl;
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 {
30 public:
31 static scoped_ptr<DamageTracker> Create();
32 ~DamageTracker();
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_; }
48 private:
49 DamageTracker();
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);
63 struct RectMapData {
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;
68 rect_ = rect;
71 bool operator < (const RectMapData& other) const {
72 return layer_id_ < other.layer_id_;
75 int layer_id_;
76 unsigned int mailboxId_;
77 gfx::Rect rect_;
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);
91 } // namespace cc
93 #endif // CC_TREES_DAMAGE_TRACKER_H_