1 // Copyright 2011 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 #include "cc/resources/layer_tiling_data.h"
9 #include "base/logging.h"
10 #include "cc/base/region.h"
11 #include "cc/base/simple_enclosed_region.h"
15 scoped_ptr
<LayerTilingData
> LayerTilingData::Create(const gfx::Size
& tile_size
,
16 BorderTexelOption border
) {
17 return make_scoped_ptr(new LayerTilingData(tile_size
, border
));
20 LayerTilingData::LayerTilingData(const gfx::Size
& tile_size
,
21 BorderTexelOption border
)
22 : tiling_data_(tile_size
, gfx::Size(), border
== HAS_BORDER_TEXELS
) {
23 SetTileSize(tile_size
);
26 LayerTilingData::~LayerTilingData() {}
28 void LayerTilingData::SetTileSize(const gfx::Size
& size
) {
29 if (tile_size() == size
)
34 tiling_data_
.SetMaxTextureSize(size
);
37 gfx::Size
LayerTilingData::tile_size() const {
38 return tiling_data_
.max_texture_size();
41 void LayerTilingData::SetBorderTexelOption(
42 BorderTexelOption border_texel_option
) {
43 bool border_texels
= border_texel_option
== HAS_BORDER_TEXELS
;
44 if (has_border_texels() == border_texels
)
48 tiling_data_
.SetHasBorderTexels(border_texels
);
51 const LayerTilingData
& LayerTilingData::operator=
52 (const LayerTilingData
& tiler
) {
53 tiling_data_
= tiler
.tiling_data_
;
58 void LayerTilingData::AddTile(scoped_ptr
<Tile
> tile
, int i
, int j
) {
59 DCHECK(!TileAt(i
, j
));
61 tiles_
.add(std::make_pair(i
, j
), tile
.Pass());
64 scoped_ptr
<LayerTilingData::Tile
> LayerTilingData::TakeTile(int i
, int j
) {
65 return tiles_
.take_and_erase(std::make_pair(i
, j
));
68 LayerTilingData::Tile
* LayerTilingData::TileAt(int i
, int j
) const {
69 return tiles_
.get(std::make_pair(i
, j
));
72 void LayerTilingData::ContentRectToTileIndices(const gfx::Rect
& content_rect
,
77 // An empty rect doesn't result in an empty set of tiles, so don't pass an
79 // TODO(enne): Possibly we should fill a vector of tiles instead, since the
80 // normal use of this function is to enumerate some tiles.
81 DCHECK(!content_rect
.IsEmpty());
83 *left
= tiling_data_
.TileXIndexFromSrcCoord(content_rect
.x());
84 *top
= tiling_data_
.TileYIndexFromSrcCoord(content_rect
.y());
85 *right
= tiling_data_
.TileXIndexFromSrcCoord(content_rect
.right() - 1);
86 *bottom
= tiling_data_
.TileYIndexFromSrcCoord(content_rect
.bottom() - 1);
89 gfx::Rect
LayerTilingData::TileRect(const Tile
* tile
) const {
90 gfx::Rect tile_rect
= tiling_data_
.TileBoundsWithBorder(tile
->i(), tile
->j());
91 tile_rect
.set_size(tile_size());
95 void LayerTilingData::SetTilingSize(const gfx::Size
& tiling_size
) {
96 tiling_data_
.SetTilingSize(tiling_size
);
97 if (tiling_size
.IsEmpty()) {
102 // Any tiles completely outside our new bounds are invalid and should be
104 int left
, top
, right
, bottom
;
105 ContentRectToTileIndices(
106 gfx::Rect(tiling_size
), &left
, &top
, &right
, &bottom
);
107 std::vector
<TileMapKey
> invalid_tile_keys
;
108 for (TileMap::const_iterator it
= tiles_
.begin(); it
!= tiles_
.end(); ++it
) {
109 if (it
->first
.first
> right
|| it
->first
.second
> bottom
)
110 invalid_tile_keys
.push_back(it
->first
);
112 for (size_t i
= 0; i
< invalid_tile_keys
.size(); ++i
)
113 tiles_
.erase(invalid_tile_keys
[i
]);