OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_RESOURCES_LAYER_TILING_DATA_H_ | 5 #ifndef CC_RESOURCES_LAYER_TILING_DATA_H_ |
6 #define CC_RESOURCES_LAYER_TILING_DATA_H_ | 6 #define CC_RESOURCES_LAYER_TILING_DATA_H_ |
7 | 7 |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
12 #include "base/containers/scoped_ptr_hash_map.h" | 12 #include "base/containers/scoped_ptr_hash_map.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "cc/base/cc_export.h" | 14 #include "cc/base/cc_export.h" |
15 #include "cc/base/region.h" | 15 #include "cc/base/region.h" |
16 #include "cc/base/tiling_data.h" | 16 #include "cc/base/tiling_data.h" |
17 #include "ui/gfx/rect.h" | 17 #include "ui/gfx/rect.h" |
18 | 18 |
19 namespace cc { | 19 namespace cc { |
20 | 20 |
21 class CC_EXPORT LayerTilingData { | 21 class CC_EXPORT LayerTilingData { |
22 public: | 22 public: |
23 enum BorderTexelOption { | 23 enum BorderTexelOption { |
24 HAS_BORDER_TEXELS, | 24 HAS_BORDER_TEXELS, |
25 NO_BORDER_TEXELS | 25 NO_BORDER_TEXELS |
26 }; | 26 }; |
27 | 27 |
28 ~LayerTilingData(); | 28 ~LayerTilingData(); |
29 | 29 |
30 static scoped_ptr<LayerTilingData> Create(gfx::Size tile_size, | 30 static scoped_ptr<LayerTilingData> Create(const gfx::Size& tile_size, |
31 BorderTexelOption option); | 31 BorderTexelOption option); |
32 | 32 |
33 bool has_empty_bounds() const { return tiling_data_.has_empty_bounds(); } | 33 bool has_empty_bounds() const { return tiling_data_.has_empty_bounds(); } |
34 int num_tiles_x() const { return tiling_data_.num_tiles_x(); } | 34 int num_tiles_x() const { return tiling_data_.num_tiles_x(); } |
35 int num_tiles_y() const { return tiling_data_.num_tiles_y(); } | 35 int num_tiles_y() const { return tiling_data_.num_tiles_y(); } |
36 gfx::Rect tile_bounds(int i, int j) const { | 36 gfx::Rect tile_bounds(int i, int j) const { |
37 return tiling_data_.TileBounds(i, j); | 37 return tiling_data_.TileBounds(i, j); |
38 } | 38 } |
39 gfx::Vector2d texture_offset(int x_index, int y_index) const { | 39 gfx::Vector2d texture_offset(int x_index, int y_index) const { |
40 return tiling_data_.TextureOffset(x_index, y_index); | 40 return tiling_data_.TextureOffset(x_index, y_index); |
41 } | 41 } |
42 | 42 |
43 // Change the tile size. This may invalidate all the existing tiles. | 43 // Change the tile size. This may invalidate all the existing tiles. |
44 void SetTileSize(gfx::Size size); | 44 void SetTileSize(const gfx::Size& size); |
45 gfx::Size tile_size() const; | 45 gfx::Size tile_size() const; |
46 // Change the border texel setting. This may invalidate all existing tiles. | 46 // Change the border texel setting. This may invalidate all existing tiles. |
47 void SetBorderTexelOption(BorderTexelOption option); | 47 void SetBorderTexelOption(BorderTexelOption option); |
48 bool has_border_texels() const { return !!tiling_data_.border_texels(); } | 48 bool has_border_texels() const { return !!tiling_data_.border_texels(); } |
49 | 49 |
50 bool is_empty() const { return has_empty_bounds() || !tiles().size(); } | 50 bool is_empty() const { return has_empty_bounds() || !tiles().size(); } |
51 | 51 |
52 const LayerTilingData& operator=(const LayerTilingData&); | 52 const LayerTilingData& operator=(const LayerTilingData&); |
53 | 53 |
54 class Tile { | 54 class Tile { |
(...skipping 19 matching lines...) Expand all Loading... |
74 DISALLOW_COPY_AND_ASSIGN(Tile); | 74 DISALLOW_COPY_AND_ASSIGN(Tile); |
75 }; | 75 }; |
76 typedef std::pair<int, int> TileMapKey; | 76 typedef std::pair<int, int> TileMapKey; |
77 typedef base::ScopedPtrHashMap<TileMapKey, Tile> TileMap; | 77 typedef base::ScopedPtrHashMap<TileMapKey, Tile> TileMap; |
78 | 78 |
79 void AddTile(scoped_ptr<Tile> tile, int i, int j); | 79 void AddTile(scoped_ptr<Tile> tile, int i, int j); |
80 scoped_ptr<Tile> TakeTile(int i, int j); | 80 scoped_ptr<Tile> TakeTile(int i, int j); |
81 Tile* TileAt(int i, int j) const; | 81 Tile* TileAt(int i, int j) const; |
82 const TileMap& tiles() const { return tiles_; } | 82 const TileMap& tiles() const { return tiles_; } |
83 | 83 |
84 void SetBounds(gfx::Size size); | 84 void SetBounds(const gfx::Size& size); |
85 gfx::Size bounds() const { return tiling_data_.total_size(); } | 85 gfx::Size bounds() const { return tiling_data_.total_size(); } |
86 | 86 |
87 void ContentRectToTileIndices(const gfx::Rect& rect, | 87 void ContentRectToTileIndices(const gfx::Rect& rect, |
88 int* left, | 88 int* left, |
89 int* top, | 89 int* top, |
90 int* right, | 90 int* right, |
91 int* bottom) const; | 91 int* bottom) const; |
92 gfx::Rect TileRect(const Tile* tile) const; | 92 gfx::Rect TileRect(const Tile* tile) const; |
93 | 93 |
94 Region OpaqueRegionInContentRect(const gfx::Rect& rect) const; | 94 Region OpaqueRegionInContentRect(const gfx::Rect& rect) const; |
95 | 95 |
96 void reset() { tiles_.clear(); } | 96 void reset() { tiles_.clear(); } |
97 | 97 |
98 protected: | 98 protected: |
99 LayerTilingData(gfx::Size tile_size, BorderTexelOption option); | 99 LayerTilingData(const gfx::Size& tile_size, BorderTexelOption option); |
100 | 100 |
101 TileMap tiles_; | 101 TileMap tiles_; |
102 TilingData tiling_data_; | 102 TilingData tiling_data_; |
103 | 103 |
104 DISALLOW_COPY(LayerTilingData); | 104 DISALLOW_COPY(LayerTilingData); |
105 }; | 105 }; |
106 | 106 |
107 } // namespace cc | 107 } // namespace cc |
108 | 108 |
109 #endif // CC_RESOURCES_LAYER_TILING_DATA_H_ | 109 #endif // CC_RESOURCES_LAYER_TILING_DATA_H_ |
OLD | NEW |