OLD | NEW |
---|---|
1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 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_TILING_DATA_H_ | 5 #ifndef CC_TILING_DATA_H_ |
6 #define CC_TILING_DATA_H_ | 6 #define CC_TILING_DATA_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "cc/cc_export.h" | 10 #include "cc/cc_export.h" |
11 #include "ui/gfx/rect.h" | |
11 #include "ui/gfx/size.h" | 12 #include "ui/gfx/size.h" |
12 | 13 |
13 namespace gfx { | 14 namespace gfx { |
14 class Rect; | |
15 class Vector2d; | 15 class Vector2d; |
16 } | 16 } |
17 | 17 |
18 namespace cc { | 18 namespace cc { |
19 | 19 |
20 class CC_EXPORT TilingData { | 20 class CC_EXPORT TilingData { |
21 public: | 21 public: |
22 TilingData(gfx::Size max_texture_size, gfx::Size total_size, bool has_border_t exels); | 22 TilingData( |
23 ~TilingData(); | 23 gfx::Size max_texture_size, |
24 gfx::Size total_size, | |
25 bool has_border_texels); | |
26 TilingData( | |
27 gfx::Size max_texture_size, | |
28 gfx::Size total_size, | |
29 int border_texels); | |
danakj
2013/01/15 23:09:05
can the compiler really tell apart bool/int and kn
enne (OOO)
2013/01/15 23:31:40
Yes it can. If bool doesn't exist, bool values wi
| |
24 | 30 |
25 gfx::Size total_size() const { return total_size_; } | 31 gfx::Size total_size() const { return total_size_; } |
26 void SetTotalSize(const gfx::Size total_size); | 32 void SetTotalSize(const gfx::Size total_size); |
27 | 33 |
28 gfx::Size max_texture_size() const { return max_texture_size_; } | 34 gfx::Size max_texture_size() const { return max_texture_size_; } |
29 void SetMaxTextureSize(gfx::Size max_texture_size); | 35 void SetMaxTextureSize(gfx::Size max_texture_size); |
30 | 36 |
31 int border_texels() const { return border_texels_; } | 37 int border_texels() const { return border_texels_; } |
32 void SetHasBorderTexels(bool has_border_texels); | 38 void SetHasBorderTexels(bool has_border_texels); |
39 void SetBorderTexels(int border_texels); | |
33 | 40 |
34 bool has_empty_bounds() const { return !num_tiles_x_ || !num_tiles_y_; } | 41 bool has_empty_bounds() const { return !num_tiles_x_ || !num_tiles_y_; } |
35 int num_tiles_x() const { return num_tiles_x_; } | 42 int num_tiles_x() const { return num_tiles_x_; } |
36 int num_tiles_y() const { return num_tiles_y_; } | 43 int num_tiles_y() const { return num_tiles_y_; } |
44 // Return the tile coordinate whose non-border texels include src_position | |
danakj
2013/01/15 23:09:05
nit: comments end with period (sorry 80 cols :( )
enne (OOO)
2013/01/15 23:31:40
Done. Exactly 80. \o/
| |
37 int TileXIndexFromSrcCoord(int src_position) const; | 45 int TileXIndexFromSrcCoord(int src_position) const; |
38 int TileYIndexFromSrcCoord(int src_position) const; | 46 int TileYIndexFromSrcCoord(int src_position) const; |
47 // Return the lowest tile coordinate whose border texels include src_position | |
48 int BorderTileXIndexFromSrcCoord(int src_position) const; | |
49 int BorderTileYIndexFromSrcCoord(int src_position) const; | |
39 | 50 |
40 gfx::Rect TileBounds(int i, int j) const; | 51 gfx::Rect TileBounds(int i, int j) const; |
41 gfx::Rect TileBoundsWithBorder(int i, int j) const; | 52 gfx::Rect TileBoundsWithBorder(int i, int j) const; |
42 int TilePositionX(int x_index) const; | 53 int TilePositionX(int x_index) const; |
43 int TilePositionY(int y_index) const; | 54 int TilePositionY(int y_index) const; |
44 int TileSizeX(int x_index) const; | 55 int TileSizeX(int x_index) const; |
45 int TileSizeY(int y_index) const; | 56 int TileSizeY(int y_index) const; |
46 | 57 |
47 // Difference between TileBound's and TileBoundWithBorder's origin(). | 58 // Difference between TileBound's and TileBoundWithBorder's origin(). |
48 gfx::Vector2d TextureOffset(int x_index, int y_index) const; | 59 gfx::Vector2d TextureOffset(int x_index, int y_index) const; |
49 | 60 |
61 // Iterate through all indices whose bounds + border intersect with this rect | |
62 class Iterator { | |
danakj
2013/01/15 23:09:05
WDYT of IntersectionIterator?
enne (OOO)
2013/01/15 23:31:40
Only when somebody adds NonIntersectionIterator an
| |
63 public: | |
64 Iterator(const TilingData* tiling_data, gfx::Rect rect); | |
65 Iterator& operator++(); | |
66 operator bool() const; | |
67 | |
68 int index_x() const { return index_x_; } | |
69 int index_y() const { return index_y_; } | |
70 | |
71 private: | |
72 void done(); | |
73 | |
74 const TilingData* tiling_data_; | |
75 gfx::Rect rect_; | |
76 int index_x_; | |
77 int index_y_; | |
78 }; | |
79 | |
50 private: | 80 private: |
51 void AssertTile(int i, int j) const { | 81 void AssertTile(int i, int j) const { |
52 DCHECK_GE(i, 0); | 82 DCHECK_GE(i, 0); |
53 DCHECK_LT(i, num_tiles_x_); | 83 DCHECK_LT(i, num_tiles_x_); |
54 DCHECK_GE(j, 0); | 84 DCHECK_GE(j, 0); |
55 DCHECK_LT(j, num_tiles_y_); | 85 DCHECK_LT(j, num_tiles_y_); |
56 } | 86 } |
57 | 87 |
58 void RecomputeNumTiles(); | 88 void RecomputeNumTiles(); |
59 | 89 |
60 gfx::Size max_texture_size_; | 90 gfx::Size max_texture_size_; |
61 gfx::Size total_size_; | 91 gfx::Size total_size_; |
62 // This value is always 0 or 1. | |
63 int border_texels_; | 92 int border_texels_; |
64 | 93 |
65 // These are computed values. | 94 // These are computed values. |
66 int num_tiles_x_; | 95 int num_tiles_x_; |
67 int num_tiles_y_; | 96 int num_tiles_y_; |
68 }; | 97 }; |
69 | 98 |
70 } // namespace cc | 99 } // namespace cc |
71 | 100 |
72 #endif // CC_TILING_DATA_H_ | 101 #endif // CC_TILING_DATA_H_ |
OLD | NEW |