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.
5 #ifndef CC_RESOURCES_PICTURE_LAYER_TILING_SET_H_
6 #define CC_RESOURCES_PICTURE_LAYER_TILING_SET_H_
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"
21 class CC_EXPORT PictureLayerTilingSet {
23 enum TilingRangeType {
26 BETWEEN_HIGH_AND_LOW_RES,
31 TilingRange(size_t start, size_t end) : start(start), end(end) {}
37 explicit PictureLayerTilingSet(PictureLayerTilingClient* client);
38 ~PictureLayerTilingSet();
40 void SetClient(PictureLayerTilingClient* client);
41 const PictureLayerTilingClient* client() const { return client_; }
43 void RemoveTilesInRegion(const Region& region);
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);
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 {
64 PictureLayerTiling* TilingAtScale(float scale) const;
66 // Remove all tilings.
67 void RemoveAllTilings();
70 void Remove(PictureLayerTiling* tiling);
72 // Remove all tiles; keep all tilings.
73 void RemoveAllTiles();
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 {
82 CoverageIterator(const PictureLayerTilingSet* set,
84 const gfx::Rect& content_rect,
85 float ideal_contents_scale);
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;
96 Tile* operator->() const;
97 Tile* operator*() const;
99 CoverageIterator& operator++();
100 operator bool() const;
102 TileResolution resolution() const;
103 PictureLayerTiling* CurrentTiling() const;
106 int NextTiling() const;
108 const PictureLayerTilingSet* set_;
109 float contents_scale_;
110 float ideal_contents_scale_;
111 PictureLayerTiling::CoverageIterator tiling_iter_;
115 Region current_region_;
116 Region missing_region_;
117 Region::Iterator region_iter_;
120 void AsValueInto(base::debug::TracedValue* array) const;
121 size_t GPUMemoryUsageInBytes() const;
123 TilingRange GetTilingRange(TilingRangeType type) const;
126 PictureLayerTilingClient* client_;
127 ScopedPtrVector<PictureLayerTiling> tilings_;
129 friend class Iterator;
130 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingSet);
135 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_SET_H_