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"
15 class CC_EXPORT PictureLayerTilingSet
{
17 PictureLayerTilingSet(PictureLayerTilingClient
* client
,
18 const gfx::Size
& layer_bounds
);
19 ~PictureLayerTilingSet();
21 void SetClient(PictureLayerTilingClient
* client
);
22 const PictureLayerTilingClient
* client() const { return client_
; }
24 void RemoveTilesInRegion(const Region
& region
);
26 // Make this set of tilings match the same set of content scales from |other|.
27 // Delete any tilings that don't meet |minimum_contents_scale|. Recreate
28 // any tiles that intersect |layer_invalidation|. Update the size of all
29 // tilings to |new_layer_bounds|.
30 // Returns true if we had at least one high res tiling synced.
31 bool SyncTilings(const PictureLayerTilingSet
& other
,
32 const gfx::Size
& new_layer_bounds
,
33 const Region
& layer_invalidation
,
34 float minimum_contents_scale
);
36 gfx::Size
layer_bounds() const { return layer_bounds_
; }
38 PictureLayerTiling
* AddTiling(float contents_scale
);
39 size_t num_tilings() const { return tilings_
.size(); }
40 int NumHighResTilings() const;
41 PictureLayerTiling
* tiling_at(size_t idx
) { return tilings_
[idx
]; }
42 const PictureLayerTiling
* tiling_at(size_t idx
) const {
46 PictureLayerTiling
* TilingAtScale(float scale
) const;
48 // Remove all tilings.
49 void RemoveAllTilings();
52 void Remove(PictureLayerTiling
* tiling
);
54 // Remove all tiles; keep all tilings.
55 void RemoveAllTiles();
57 void DidBecomeActive();
58 void DidBecomeRecycled();
60 // For a given rect, iterates through tiles that can fill it. If no
61 // set of tiles with resources can fill the rect, then it will iterate
62 // through null tiles with valid geometry_rect() until the rect is full.
63 // If all tiles have resources, the union of all geometry_rects will
64 // exactly fill rect with no overlap.
65 class CC_EXPORT CoverageIterator
{
67 CoverageIterator(const PictureLayerTilingSet
* set
,
69 const gfx::Rect
& content_rect
,
70 float ideal_contents_scale
);
73 // Visible rect (no borders), always in the space of rect,
74 // regardless of the relative contents scale of the tiling.
75 gfx::Rect
geometry_rect() const;
76 // Texture rect (in texels) for geometry_rect
77 gfx::RectF
texture_rect() const;
78 // Texture size in texels
79 gfx::Size
texture_size() const;
81 Tile
* operator->() const;
82 Tile
* operator*() const;
84 CoverageIterator
& operator++();
85 operator bool() const;
87 PictureLayerTiling
* CurrentTiling();
90 int NextTiling() const;
92 const PictureLayerTilingSet
* set_
;
93 float contents_scale_
;
94 float ideal_contents_scale_
;
95 PictureLayerTiling::CoverageIterator tiling_iter_
;
99 Region current_region_
;
100 Region missing_region_
;
101 Region::Iterator region_iter_
;
104 scoped_ptr
<base::Value
> AsValue() const;
105 size_t GPUMemoryUsageInBytes() const;
108 PictureLayerTilingClient
* client_
;
109 gfx::Size layer_bounds_
;
110 ScopedPtrVector
<PictureLayerTiling
> tilings_
;
112 friend class Iterator
;
113 DISALLOW_COPY_AND_ASSIGN(PictureLayerTilingSet
);
118 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_SET_H_