Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / cc / resources / picture_layer_tiling_set.h
1 // Copyright 2012 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_RESOURCES_PICTURE_LAYER_TILING_SET_H_
6 #define CC_RESOURCES_PICTURE_LAYER_TILING_SET_H_
7
8 #include "cc/base/region.h"
9 #include "cc/base/scoped_ptr_vector.h"
10 #include "cc/resources/picture_layer_tiling.h"
11 #include "ui/gfx/geometry/size.h"
12
13 namespace base {
14 namespace debug {
15 class TracedValue;
16 }
17 }
18
19 namespace cc {
20
21 class CC_EXPORT PictureLayerTilingSet {
22  public:
23   enum TilingRangeType {
24     HIGHER_THAN_HIGH_RES,
25     HIGH_RES,
26     BETWEEN_HIGH_AND_LOW_RES,
27     LOW_RES,
28     LOWER_THAN_LOW_RES
29   };
30   struct TilingRange {
31     TilingRange(size_t start, size_t end) : start(start), end(end) {}
32
33     size_t start;
34     size_t end;
35   };
36
37   explicit PictureLayerTilingSet(PictureLayerTilingClient* client);
38   ~PictureLayerTilingSet();
39
40   void SetClient(PictureLayerTilingClient* client);
41   const PictureLayerTilingClient* client() const { return client_; }
42
43   void RemoveTilesInRegion(const Region& region);
44
45   // Make this set of tilings match the same set of content scales from |other|.
46   // Delete any tilings that don't meet |minimum_contents_scale|.  Recreate
47   // any tiles that intersect |layer_invalidation|.  Update the size of all
48   // tilings to |new_layer_bounds|.
49   // Returns true if we had at least one high res tiling synced.
50   bool SyncTilings(const PictureLayerTilingSet& other,
51                    const gfx::Size& new_layer_bounds,
52                    const Region& layer_invalidation,
53                    float minimum_contents_scale);
54
55   PictureLayerTiling* AddTiling(float contents_scale,
56                                 const gfx::Size& layer_bounds);
57   size_t num_tilings() const { return tilings_.size(); }
58   int NumHighResTilings() const;
59   PictureLayerTiling* tiling_at(size_t idx) { return tilings_[idx]; }
60   const PictureLayerTiling* tiling_at(size_t idx) const {
61     return tilings_[idx];
62   }
63
64   PictureLayerTiling* TilingAtScale(float scale) const;
65
66   // Remove all tilings.
67   void RemoveAllTilings();
68
69   // Remove one tiling.
70   void Remove(PictureLayerTiling* tiling);
71
72   // Remove all tiles; keep all tilings.
73   void RemoveAllTiles();
74
75   // For a given rect, iterates through tiles that can fill it.  If no
76   // set of tiles with resources can fill the rect, then it will iterate
77   // through null tiles with valid geometry_rect() until the rect is full.
78   // If all tiles have resources, the union of all geometry_rects will
79   // exactly fill rect with no overlap.
80   class CC_EXPORT CoverageIterator {
81    public:
82     CoverageIterator(const PictureLayerTilingSet* set,
83       float contents_scale,
84       const gfx::Rect& content_rect,
85       float ideal_contents_scale);
86     ~CoverageIterator();
87
88     // Visible rect (no borders), always in the space of rect,
89     // regardless of the relative contents scale of the tiling.
90     gfx::Rect geometry_rect() const;
91     // Texture rect (in texels) for geometry_rect
92     gfx::RectF texture_rect() const;
93     // Texture size in texels
94     gfx::Size texture_size() const;
95
96     Tile* operator->() const;
97     Tile* operator*() const;
98
99     CoverageIterator& operator++();
100     operator bool() const;
101
102     TileResolution resolution() const;
103     PictureLayerTiling* CurrentTiling() const;
104
105    private:
106     int NextTiling() const;
107
108     const PictureLayerTilingSet* set_;
109     float contents_scale_;
110     float ideal_contents_scale_;
111     PictureLayerTiling::CoverageIterator tiling_iter_;
112     int current_tiling_;
113     int ideal_tiling_;
114
115     Region current_region_;
116     Region missing_region_;
117     Region::Iterator region_iter_;
118   };
119
120   void AsValueInto(base::debug::TracedValue* array) const;
121   size_t GPUMemoryUsageInBytes() const;
122
123   TilingRange GetTilingRange(TilingRangeType type) const;
124
125  private:
126   PictureLayerTilingClient* client_;
127   ScopedPtrVector<PictureLayerTiling> tilings_;
128
129   friend class Iterator;
130   DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingSet);
131 };
132
133 }  // namespace cc
134
135 #endif  // CC_RESOURCES_PICTURE_LAYER_TILING_SET_H_