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_PICTURE_LAYER_TILING_H_
6 #define CC_PICTURE_LAYER_TILING_H_
8 #include "base/basictypes.h"
9 #include "base/hash_tables.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "cc/cc_export.h"
12 #include "cc/hash_pair.h"
13 #include "cc/region.h"
15 #include "cc/tiling_data.h"
16 #include "ui/gfx/rect.h"
20 class PictureLayerTiling
;
22 class PictureLayerTilingClient
{
24 virtual scoped_refptr
<Tile
> CreateTile(PictureLayerTiling
*, gfx::Rect
) = 0;
27 class CC_EXPORT PictureLayerTiling
{
29 ~PictureLayerTiling();
31 static scoped_ptr
<PictureLayerTiling
> Create(float contents_scale
,
33 scoped_ptr
<PictureLayerTiling
> Clone() const;
35 const PictureLayerTiling
& operator=(const PictureLayerTiling
&);
37 void SetLayerBounds(gfx::Size layer_bounds
);
38 void Invalidate(const Region
& layer_invalidation
);
40 void SetClient(PictureLayerTilingClient
* client
);
42 gfx::Rect
ContentRect() const;
43 float contents_scale() const { return contents_scale_
; }
45 // Iterate over all tiles to fill content_rect. Even if tiles are invalid
46 // (i.e. no valid resource) this tiling should still iterate over them.
47 // The union of all geometry_rect calls for each element iterated over should
48 // exactly equal content_rect and no two geometry_rects should intersect.
49 class CC_EXPORT Iterator
{
52 Iterator(PictureLayerTiling
* tiling
, float dest_scale
, gfx::Rect rect
);
55 // Visible rect (no borders), always in the space of content_rect,
56 // regardless of the contents scale of the tiling.
57 gfx::Rect
geometry_rect() const;
58 // Texture rect (in texels) for geometry_rect
59 gfx::RectF
texture_rect() const;
60 gfx::Size
texture_size() const;
62 Tile
* operator->() const { return current_tile_
; }
63 Tile
* operator*() const { return current_tile_
; }
65 Iterator
& operator++();
66 operator bool() const { return tile_j_
<= bottom_
; }
69 PictureLayerTiling
* tiling_
;
71 float dest_to_content_scale_
;
74 gfx::Rect current_geometry_rect_
;
82 friend class PictureLayerTiling
;
85 Region
OpaqueRegionInContentRect(const gfx::Rect
&) const;
87 void Reset() { return tiles_
.clear(); }
89 void UpdateTilePriorities(
91 const gfx::Size
& device_viewport
,
92 float layer_content_scale_x
,
93 float layer_content_scale_y
,
94 const gfx::Transform
& last_screen_transform
,
95 const gfx::Transform
& current_screen_transform
,
99 typedef std::pair
<int, int> TileMapKey
;
100 typedef base::hash_map
<TileMapKey
, scoped_refptr
<Tile
> > TileMap
;
102 PictureLayerTiling(float contents_scale
, gfx::Size tileSize
);
103 Tile
* TileAt(int, int) const;
104 void CreateTile(int i
, int j
);
106 PictureLayerTilingClient
* client_
;
107 float contents_scale_
;
108 gfx::Size layer_bounds_
;
110 TilingData tiling_data_
;
112 friend class Iterator
;
117 #endif // CC_PICTURE_LAYER_TILING_H_