OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CC_TILING_DATA_H_ | |
6 #define CC_TILING_DATA_H_ | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "base/logging.h" | |
10 #include "cc/cc_export.h" | |
11 #include "ui/gfx/rect.h" | |
12 #include "ui/gfx/size.h" | |
13 | |
14 namespace gfx { | |
15 class Vector2d; | |
16 } | |
17 | |
18 namespace cc { | |
19 | |
20 class CC_EXPORT TilingData { | |
21 public: | |
22 TilingData(); | |
23 TilingData( | |
24 gfx::Size max_texture_size, | |
25 gfx::Size total_size, | |
26 bool has_border_texels); | |
27 TilingData( | |
28 gfx::Size max_texture_size, | |
29 gfx::Size total_size, | |
30 int border_texels); | |
31 | |
32 gfx::Size total_size() const { return total_size_; } | |
33 void SetTotalSize(const gfx::Size total_size); | |
34 | |
35 gfx::Size max_texture_size() const { return max_texture_size_; } | |
36 void SetMaxTextureSize(gfx::Size max_texture_size); | |
37 | |
38 int border_texels() const { return border_texels_; } | |
39 void SetHasBorderTexels(bool has_border_texels); | |
40 void SetBorderTexels(int border_texels); | |
41 | |
42 bool has_empty_bounds() const { return !num_tiles_x_ || !num_tiles_y_; } | |
43 int num_tiles_x() const { return num_tiles_x_; } | |
44 int num_tiles_y() const { return num_tiles_y_; } | |
45 // Return the tile index whose non-border texels include src_position. | |
46 int TileXIndexFromSrcCoord(int src_position) const; | |
47 int TileYIndexFromSrcCoord(int src_position) const; | |
48 // Return the lowest tile index whose border texels include src_position. | |
49 int FirstBorderTileXIndexFromSrcCoord(int src_position) const; | |
50 int FirstBorderTileYIndexFromSrcCoord(int src_position) const; | |
51 // Return the highest tile index whose border texels include src_position. | |
52 int LastBorderTileXIndexFromSrcCoord(int src_position) const; | |
53 int LastBorderTileYIndexFromSrcCoord(int src_position) const; | |
54 | |
55 gfx::Rect TileBounds(int i, int j) const; | |
56 gfx::Rect TileBoundsWithBorder(int i, int j) const; | |
57 int TilePositionX(int x_index) const; | |
58 int TilePositionY(int y_index) const; | |
59 int TileSizeX(int x_index) const; | |
60 int TileSizeY(int y_index) const; | |
61 | |
62 // Difference between TileBound's and TileBoundWithBorder's origin(). | |
63 gfx::Vector2d TextureOffset(int x_index, int y_index) const; | |
64 | |
65 class CC_EXPORT BaseIterator { | |
66 public: | |
67 operator bool() const { return index_x_ != -1 && index_y_ != -1; } | |
68 | |
69 int index_x() const { return index_x_; } | |
70 int index_y() const { return index_y_; } | |
71 std::pair<int, int> index() const { | |
72 return std::make_pair(index_x_, index_y_); | |
73 } | |
74 | |
75 protected: | |
76 explicit BaseIterator(const TilingData* tiling_data); | |
77 void done() { index_x_ = -1; index_y_ = -1; } | |
78 | |
79 const TilingData* tiling_data_; | |
80 int index_x_; | |
81 int index_y_; | |
82 }; | |
83 | |
84 // Iterate through all indices whose bounds + border intersect with |rect|. | |
85 class CC_EXPORT Iterator : public BaseIterator { | |
86 public: | |
87 Iterator(const TilingData* tiling_data, gfx::Rect rect); | |
88 Iterator& operator++(); | |
89 | |
90 private: | |
91 int left_; | |
92 int right_; | |
93 int bottom_; | |
94 }; | |
95 | |
96 // Iterate through all indices whose bounds + border intersect with | |
97 // |consider| but which also do not intersect with |ignore|. | |
98 class CC_EXPORT DifferenceIterator : public BaseIterator { | |
99 public: | |
100 DifferenceIterator( | |
101 const TilingData* tiling_data, | |
102 gfx::Rect consider, | |
103 gfx::Rect ignore); | |
104 DifferenceIterator& operator++(); | |
105 | |
106 private: | |
107 bool in_ignore_rect() const { | |
108 return index_x_ >= ignore_left_ && index_x_ <= ignore_right_ && | |
109 index_y_ >= ignore_top_ && index_y_ <= ignore_bottom_; | |
110 } | |
111 | |
112 int consider_left_; | |
113 int consider_top_; | |
114 int consider_right_; | |
115 int consider_bottom_; | |
116 int ignore_left_; | |
117 int ignore_top_; | |
118 int ignore_right_; | |
119 int ignore_bottom_; | |
120 }; | |
121 | |
122 private: | |
123 void AssertTile(int i, int j) const { | |
124 DCHECK_GE(i, 0); | |
125 DCHECK_LT(i, num_tiles_x_); | |
126 DCHECK_GE(j, 0); | |
127 DCHECK_LT(j, num_tiles_y_); | |
128 } | |
129 | |
130 void RecomputeNumTiles(); | |
131 | |
132 gfx::Size max_texture_size_; | |
133 gfx::Size total_size_; | |
134 int border_texels_; | |
135 | |
136 // These are computed values. | |
137 int num_tiles_x_; | |
138 int num_tiles_y_; | |
139 }; | |
140 | |
141 } // namespace cc | |
142 | |
143 #endif // CC_TILING_DATA_H_ | |
OLD | NEW |