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/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 PictureLayerTilingSet(PictureLayerTilingClient
* client
,
38 const gfx::Size
& layer_bounds
);
39 ~PictureLayerTilingSet();
41 void SetClient(PictureLayerTilingClient
* client
);
42 const PictureLayerTilingClient
* client() const { return client_
; }
44 void RemoveTilesInRegion(const Region
& region
);
46 // Make this set of tilings match the same set of content scales from |other|.
47 // Delete any tilings that don't meet |minimum_contents_scale|. Recreate
48 // any tiles that intersect |layer_invalidation|. Update the size of all
49 // tilings to |new_layer_bounds|.
50 // Returns true if we had at least one high res tiling synced.
51 bool SyncTilings(const PictureLayerTilingSet
& other
,
52 const gfx::Size
& new_layer_bounds
,
53 const Region
& layer_invalidation
,
54 float minimum_contents_scale
);
56 gfx::Size
layer_bounds() const { return layer_bounds_
; }
58 PictureLayerTiling
* AddTiling(float contents_scale
);
59 size_t num_tilings() const { return tilings_
.size(); }
60 int NumHighResTilings() const;
61 PictureLayerTiling
* tiling_at(size_t idx
) { return tilings_
[idx
]; }
62 const PictureLayerTiling
* tiling_at(size_t idx
) const {
66 PictureLayerTiling
* TilingAtScale(float scale
) const;
68 // Remove all tilings.
69 void RemoveAllTilings();
72 void Remove(PictureLayerTiling
* tiling
);
74 // Remove all tiles; keep all tilings.
75 void RemoveAllTiles();
77 void DidBecomeActive();
78 void DidBecomeRecycled();
80 // For a given rect, iterates through tiles that can fill it. If no
81 // set of tiles with resources can fill the rect, then it will iterate
82 // through null tiles with valid geometry_rect() until the rect is full.
83 // If all tiles have resources, the union of all geometry_rects will
84 // exactly fill rect with no overlap.
85 class CC_EXPORT CoverageIterator
{
87 CoverageIterator(const PictureLayerTilingSet
* set
,
89 const gfx::Rect
& content_rect
,
90 float ideal_contents_scale
);
93 // Visible rect (no borders), always in the space of rect,
94 // regardless of the relative contents scale of the tiling.
95 gfx::Rect
geometry_rect() const;
96 // Texture rect (in texels) for geometry_rect
97 gfx::RectF
texture_rect() const;
98 // Texture size in texels
99 gfx::Size
texture_size() const;
101 Tile
* operator->() const;
102 Tile
* operator*() const;
104 CoverageIterator
& operator++();
105 operator bool() const;
107 PictureLayerTiling
* CurrentTiling();
110 int NextTiling() const;
112 const PictureLayerTilingSet
* set_
;
113 float contents_scale_
;
114 float ideal_contents_scale_
;
115 PictureLayerTiling::CoverageIterator tiling_iter_
;
119 Region current_region_
;
120 Region missing_region_
;
121 Region::Iterator region_iter_
;
124 void AsValueInto(base::debug::TracedValue
* array
) const;
125 size_t GPUMemoryUsageInBytes() const;
127 TilingRange
GetTilingRange(TilingRangeType type
) const;
130 PictureLayerTilingClient
* client_
;
131 gfx::Size layer_bounds_
;
132 ScopedPtrVector
<PictureLayerTiling
> tilings_
;
134 friend class Iterator
;
135 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingSet
);
140 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_SET_H_