1 // Copyright 2013 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/base/tiling_data.h"
9 #include "cc/test/geometry_test_utils.h"
10 #include "testing/gtest/include/gtest/gtest.h"
16 gfx::Size max_texture_size
,
18 bool has_border_texels
) {
19 TilingData
tiling(max_texture_size
, total_size
, has_border_texels
);
20 int num_tiles
= tiling
.num_tiles_x() * tiling
.num_tiles_y();
22 // Assert no overflow.
23 EXPECT_GE(num_tiles
, 0);
25 EXPECT_EQ(num_tiles
/ tiling
.num_tiles_x(), tiling
.num_tiles_y());
31 gfx::Size max_texture_size
,
33 bool has_border_texels
,
35 TilingData
tiling(max_texture_size
, total_size
, has_border_texels
);
36 return tiling
.TileXIndexFromSrcCoord(x_coord
);
40 gfx::Size max_texture_size
,
42 bool has_border_texels
,
44 TilingData
tiling(max_texture_size
, total_size
, has_border_texels
);
45 return tiling
.TileYIndexFromSrcCoord(y_coord
);
49 gfx::Size max_texture_size
,
51 bool has_border_texels
,
53 TilingData
tiling(max_texture_size
, total_size
, has_border_texels
);
54 return tiling
.FirstBorderTileXIndexFromSrcCoord(x_coord
);
58 gfx::Size max_texture_size
,
60 bool has_border_texels
,
62 TilingData
tiling(max_texture_size
, total_size
, has_border_texels
);
63 return tiling
.FirstBorderTileYIndexFromSrcCoord(y_coord
);
67 gfx::Size max_texture_size
,
69 bool has_border_texels
,
71 TilingData
tiling(max_texture_size
, total_size
, has_border_texels
);
72 return tiling
.LastBorderTileXIndexFromSrcCoord(x_coord
);
76 gfx::Size max_texture_size
,
78 bool has_border_texels
,
80 TilingData
tiling(max_texture_size
, total_size
, has_border_texels
);
81 return tiling
.LastBorderTileYIndexFromSrcCoord(y_coord
);
85 gfx::Size max_texture_size
,
87 bool has_border_texels
,
89 TilingData
tiling(max_texture_size
, total_size
, has_border_texels
);
90 return tiling
.TilePositionX(x_index
);
94 gfx::Size max_texture_size
,
96 bool has_border_texels
,
98 TilingData
tiling(max_texture_size
, total_size
, has_border_texels
);
99 return tiling
.TilePositionY(y_index
);
103 gfx::Size max_texture_size
,
104 gfx::Size total_size
,
105 bool has_border_texels
,
107 TilingData
tiling(max_texture_size
, total_size
, has_border_texels
);
108 return tiling
.TileSizeX(x_index
);
112 gfx::Size max_texture_size
,
113 gfx::Size total_size
,
114 bool has_border_texels
,
116 TilingData
tiling(max_texture_size
, total_size
, has_border_texels
);
117 return tiling
.TileSizeY(y_index
);
120 TEST(TilingDataTest
, NumTiles_NoTiling
) {
121 EXPECT_EQ(1, NumTiles(gfx::Size(16, 16), gfx::Size(16, 16), false));
122 EXPECT_EQ(1, NumTiles(gfx::Size(16, 16), gfx::Size(15, 15), true));
123 EXPECT_EQ(1, NumTiles(gfx::Size(16, 16), gfx::Size(16, 16), true));
124 EXPECT_EQ(1, NumTiles(gfx::Size(16, 16), gfx::Size(1, 16), false));
125 EXPECT_EQ(1, NumTiles(gfx::Size(15, 15), gfx::Size(15, 15), true));
126 EXPECT_EQ(1, NumTiles(gfx::Size(32, 16), gfx::Size(32, 16), false));
127 EXPECT_EQ(1, NumTiles(gfx::Size(32, 16), gfx::Size(32, 16), true));
130 TEST(TilingDataTest
, NumTiles_TilingNoBorders
) {
131 EXPECT_EQ(0, NumTiles(gfx::Size(0, 0), gfx::Size(0, 0), false));
132 EXPECT_EQ(0, NumTiles(gfx::Size(0, 0), gfx::Size(4, 0), false));
133 EXPECT_EQ(0, NumTiles(gfx::Size(0, 0), gfx::Size(0, 4), false));
134 EXPECT_EQ(0, NumTiles(gfx::Size(4, 4), gfx::Size(4, 0), false));
135 EXPECT_EQ(0, NumTiles(gfx::Size(4, 4), gfx::Size(0, 4), false));
136 EXPECT_EQ(0, NumTiles(gfx::Size(0, 0), gfx::Size(1, 1), false));
138 EXPECT_EQ(1, NumTiles(gfx::Size(1, 1), gfx::Size(1, 1), false));
139 EXPECT_EQ(2, NumTiles(gfx::Size(1, 1), gfx::Size(1, 2), false));
140 EXPECT_EQ(2, NumTiles(gfx::Size(1, 1), gfx::Size(2, 1), false));
141 EXPECT_EQ(1, NumTiles(gfx::Size(2, 2), gfx::Size(1, 1), false));
142 EXPECT_EQ(1, NumTiles(gfx::Size(2, 2), gfx::Size(1, 2), false));
143 EXPECT_EQ(1, NumTiles(gfx::Size(2, 2), gfx::Size(2, 1), false));
144 EXPECT_EQ(1, NumTiles(gfx::Size(2, 2), gfx::Size(2, 2), false));
145 EXPECT_EQ(1, NumTiles(gfx::Size(3, 3), gfx::Size(3, 3), false));
147 EXPECT_EQ(1, NumTiles(gfx::Size(4, 4), gfx::Size(1, 4), false));
148 EXPECT_EQ(1, NumTiles(gfx::Size(4, 4), gfx::Size(2, 4), false));
149 EXPECT_EQ(1, NumTiles(gfx::Size(4, 4), gfx::Size(3, 4), false));
150 EXPECT_EQ(1, NumTiles(gfx::Size(4, 4), gfx::Size(4, 4), false));
151 EXPECT_EQ(2, NumTiles(gfx::Size(4, 4), gfx::Size(5, 4), false));
152 EXPECT_EQ(2, NumTiles(gfx::Size(4, 4), gfx::Size(6, 4), false));
153 EXPECT_EQ(2, NumTiles(gfx::Size(4, 4), gfx::Size(7, 4), false));
154 EXPECT_EQ(2, NumTiles(gfx::Size(4, 4), gfx::Size(8, 4), false));
155 EXPECT_EQ(3, NumTiles(gfx::Size(4, 4), gfx::Size(9, 4), false));
156 EXPECT_EQ(3, NumTiles(gfx::Size(4, 4), gfx::Size(10, 4), false));
157 EXPECT_EQ(3, NumTiles(gfx::Size(4, 4), gfx::Size(11, 4), false));
159 EXPECT_EQ(1, NumTiles(gfx::Size(5, 5), gfx::Size(1, 5), false));
160 EXPECT_EQ(1, NumTiles(gfx::Size(5, 5), gfx::Size(2, 5), false));
161 EXPECT_EQ(1, NumTiles(gfx::Size(5, 5), gfx::Size(3, 5), false));
162 EXPECT_EQ(1, NumTiles(gfx::Size(5, 5), gfx::Size(4, 5), false));
163 EXPECT_EQ(1, NumTiles(gfx::Size(5, 5), gfx::Size(5, 5), false));
164 EXPECT_EQ(2, NumTiles(gfx::Size(5, 5), gfx::Size(6, 5), false));
165 EXPECT_EQ(2, NumTiles(gfx::Size(5, 5), gfx::Size(7, 5), false));
166 EXPECT_EQ(2, NumTiles(gfx::Size(5, 5), gfx::Size(8, 5), false));
167 EXPECT_EQ(2, NumTiles(gfx::Size(5, 5), gfx::Size(9, 5), false));
168 EXPECT_EQ(2, NumTiles(gfx::Size(5, 5), gfx::Size(10, 5), false));
169 EXPECT_EQ(3, NumTiles(gfx::Size(5, 5), gfx::Size(11, 5), false));
171 EXPECT_EQ(1, NumTiles(gfx::Size(16, 16), gfx::Size(16, 16), false));
172 EXPECT_EQ(1, NumTiles(gfx::Size(17, 17), gfx::Size(16, 16), false));
173 EXPECT_EQ(4, NumTiles(gfx::Size(15, 15), gfx::Size(16, 16), false));
174 EXPECT_EQ(4, NumTiles(gfx::Size(8, 8), gfx::Size(16, 16), false));
175 EXPECT_EQ(6, NumTiles(gfx::Size(8, 8), gfx::Size(17, 16), false));
177 EXPECT_EQ(8, NumTiles(gfx::Size(5, 8), gfx::Size(17, 16), false));
180 TEST(TilingDataTest
, NumTiles_TilingWithBorders
) {
181 EXPECT_EQ(0, NumTiles(gfx::Size(0, 0), gfx::Size(0, 0), true));
182 EXPECT_EQ(0, NumTiles(gfx::Size(0, 0), gfx::Size(4, 0), true));
183 EXPECT_EQ(0, NumTiles(gfx::Size(0, 0), gfx::Size(0, 4), true));
184 EXPECT_EQ(0, NumTiles(gfx::Size(4, 4), gfx::Size(4, 0), true));
185 EXPECT_EQ(0, NumTiles(gfx::Size(4, 4), gfx::Size(0, 4), true));
186 EXPECT_EQ(0, NumTiles(gfx::Size(0, 0), gfx::Size(1, 1), true));
188 EXPECT_EQ(1, NumTiles(gfx::Size(1, 1), gfx::Size(1, 1), true));
189 EXPECT_EQ(0, NumTiles(gfx::Size(1, 1), gfx::Size(1, 2), true));
190 EXPECT_EQ(0, NumTiles(gfx::Size(1, 1), gfx::Size(2, 1), true));
191 EXPECT_EQ(1, NumTiles(gfx::Size(2, 2), gfx::Size(1, 1), true));
192 EXPECT_EQ(1, NumTiles(gfx::Size(2, 2), gfx::Size(1, 2), true));
193 EXPECT_EQ(1, NumTiles(gfx::Size(2, 2), gfx::Size(2, 1), true));
194 EXPECT_EQ(1, NumTiles(gfx::Size(2, 2), gfx::Size(2, 2), true));
196 EXPECT_EQ(1, NumTiles(gfx::Size(3, 3), gfx::Size(1, 3), true));
197 EXPECT_EQ(1, NumTiles(gfx::Size(3, 3), gfx::Size(2, 3), true));
198 EXPECT_EQ(1, NumTiles(gfx::Size(3, 3), gfx::Size(3, 3), true));
199 EXPECT_EQ(2, NumTiles(gfx::Size(3, 3), gfx::Size(4, 3), true));
200 EXPECT_EQ(3, NumTiles(gfx::Size(3, 3), gfx::Size(5, 3), true));
201 EXPECT_EQ(4, NumTiles(gfx::Size(3, 3), gfx::Size(6, 3), true));
202 EXPECT_EQ(5, NumTiles(gfx::Size(3, 3), gfx::Size(7, 3), true));
204 EXPECT_EQ(1, NumTiles(gfx::Size(4, 4), gfx::Size(1, 4), true));
205 EXPECT_EQ(1, NumTiles(gfx::Size(4, 4), gfx::Size(2, 4), true));
206 EXPECT_EQ(1, NumTiles(gfx::Size(4, 4), gfx::Size(3, 4), true));
207 EXPECT_EQ(1, NumTiles(gfx::Size(4, 4), gfx::Size(4, 4), true));
208 EXPECT_EQ(2, NumTiles(gfx::Size(4, 4), gfx::Size(5, 4), true));
209 EXPECT_EQ(2, NumTiles(gfx::Size(4, 4), gfx::Size(6, 4), true));
210 EXPECT_EQ(3, NumTiles(gfx::Size(4, 4), gfx::Size(7, 4), true));
211 EXPECT_EQ(3, NumTiles(gfx::Size(4, 4), gfx::Size(8, 4), true));
212 EXPECT_EQ(4, NumTiles(gfx::Size(4, 4), gfx::Size(9, 4), true));
213 EXPECT_EQ(4, NumTiles(gfx::Size(4, 4), gfx::Size(10, 4), true));
214 EXPECT_EQ(5, NumTiles(gfx::Size(4, 4), gfx::Size(11, 4), true));
216 EXPECT_EQ(1, NumTiles(gfx::Size(5, 5), gfx::Size(1, 5), true));
217 EXPECT_EQ(1, NumTiles(gfx::Size(5, 5), gfx::Size(2, 5), true));
218 EXPECT_EQ(1, NumTiles(gfx::Size(5, 5), gfx::Size(3, 5), true));
219 EXPECT_EQ(1, NumTiles(gfx::Size(5, 5), gfx::Size(4, 5), true));
220 EXPECT_EQ(1, NumTiles(gfx::Size(5, 5), gfx::Size(5, 5), true));
221 EXPECT_EQ(2, NumTiles(gfx::Size(5, 5), gfx::Size(6, 5), true));
222 EXPECT_EQ(2, NumTiles(gfx::Size(5, 5), gfx::Size(7, 5), true));
223 EXPECT_EQ(2, NumTiles(gfx::Size(5, 5), gfx::Size(8, 5), true));
224 EXPECT_EQ(3, NumTiles(gfx::Size(5, 5), gfx::Size(9, 5), true));
225 EXPECT_EQ(3, NumTiles(gfx::Size(5, 5), gfx::Size(10, 5), true));
226 EXPECT_EQ(3, NumTiles(gfx::Size(5, 5), gfx::Size(11, 5), true));
228 EXPECT_EQ(30, NumTiles(gfx::Size(8, 5), gfx::Size(16, 32), true));
231 TEST(TilingDataTest
, TileXIndexFromSrcCoord
) {
232 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 0));
233 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 1));
234 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 2));
235 EXPECT_EQ(1, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 3));
236 EXPECT_EQ(1, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 4));
237 EXPECT_EQ(1, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 5));
238 EXPECT_EQ(2, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 6));
239 EXPECT_EQ(2, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 7));
240 EXPECT_EQ(2, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 8));
241 EXPECT_EQ(3, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 9));
242 EXPECT_EQ(3, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 10));
243 EXPECT_EQ(3, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 11));
245 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 0));
246 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 1));
247 EXPECT_EQ(1, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 2));
248 EXPECT_EQ(2, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 3));
249 EXPECT_EQ(3, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 4));
250 EXPECT_EQ(4, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 5));
251 EXPECT_EQ(5, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 6));
252 EXPECT_EQ(6, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 7));
253 EXPECT_EQ(7, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 8));
254 EXPECT_EQ(7, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 9));
255 EXPECT_EQ(7, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 10));
256 EXPECT_EQ(7, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 11));
258 EXPECT_EQ(0, XIndex(gfx::Size(1, 1), gfx::Size(1, 1), false, 0));
259 EXPECT_EQ(0, XIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 0));
260 EXPECT_EQ(0, XIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 1));
261 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 0));
262 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 1));
263 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 2));
265 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 0));
266 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 1));
267 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 2));
268 EXPECT_EQ(1, XIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 3));
270 EXPECT_EQ(0, XIndex(gfx::Size(1, 1), gfx::Size(1, 1), true, 0));
271 EXPECT_EQ(0, XIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 0));
272 EXPECT_EQ(0, XIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 1));
273 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 0));
274 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 1));
275 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 2));
277 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 0));
278 EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 1));
279 EXPECT_EQ(1, XIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 2));
280 EXPECT_EQ(1, XIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 3));
283 TEST(TilingDataTest
, FirstBorderTileXIndexFromSrcCoord
) {
284 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 0));
285 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 1));
286 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 2));
287 EXPECT_EQ(1, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 3));
288 EXPECT_EQ(1, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 4));
289 EXPECT_EQ(1, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 5));
290 EXPECT_EQ(2, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 6));
291 EXPECT_EQ(2, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 7));
292 EXPECT_EQ(2, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 8));
293 EXPECT_EQ(3, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 9));
294 EXPECT_EQ(3, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 10));
295 EXPECT_EQ(3, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 11));
297 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 0));
298 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 1));
299 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 2));
300 EXPECT_EQ(1, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 3));
301 EXPECT_EQ(2, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 4));
302 EXPECT_EQ(3, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 5));
303 EXPECT_EQ(4, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 6));
304 EXPECT_EQ(5, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 7));
305 EXPECT_EQ(6, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 8));
306 EXPECT_EQ(7, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 9));
307 EXPECT_EQ(7, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 10));
308 EXPECT_EQ(7, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 11));
310 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(1, 1), gfx::Size(1, 1), false, 0));
311 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 0));
312 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 1));
313 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 0));
314 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 1));
315 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 2));
317 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 0));
318 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 1));
319 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 2));
320 EXPECT_EQ(1, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 3));
322 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(1, 1), gfx::Size(1, 1), true, 0));
323 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 0));
324 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 1));
325 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 0));
326 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 1));
327 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 2));
329 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 0));
330 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 1));
331 EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 2));
332 EXPECT_EQ(1, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 3));
335 TEST(TilingDataTest
, LastBorderTileXIndexFromSrcCoord
) {
336 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 0));
337 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 1));
338 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 2));
339 EXPECT_EQ(1, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 3));
340 EXPECT_EQ(1, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 4));
341 EXPECT_EQ(1, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 5));
342 EXPECT_EQ(2, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 6));
343 EXPECT_EQ(2, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 7));
344 EXPECT_EQ(2, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 8));
345 EXPECT_EQ(3, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 9));
346 EXPECT_EQ(3, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 10));
347 EXPECT_EQ(3, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 11));
349 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 0));
350 EXPECT_EQ(1, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 1));
351 EXPECT_EQ(2, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 2));
352 EXPECT_EQ(3, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 3));
353 EXPECT_EQ(4, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 4));
354 EXPECT_EQ(5, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 5));
355 EXPECT_EQ(6, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 6));
356 EXPECT_EQ(7, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 7));
357 EXPECT_EQ(7, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 8));
358 EXPECT_EQ(7, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 9));
359 EXPECT_EQ(7, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 10));
360 EXPECT_EQ(7, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 11));
362 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(1, 1), gfx::Size(1, 1), false, 0));
363 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 0));
364 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 1));
365 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 0));
366 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 1));
367 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 2));
369 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 0));
370 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 1));
371 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 2));
372 EXPECT_EQ(1, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 3));
374 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(1, 1), gfx::Size(1, 1), true, 0));
375 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 0));
376 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 1));
377 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 0));
378 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 1));
379 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 2));
381 EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 0));
382 EXPECT_EQ(1, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 1));
383 EXPECT_EQ(1, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 2));
384 EXPECT_EQ(1, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 3));
387 TEST(TilingDataTest
, TileYIndexFromSrcCoord
) {
388 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 0));
389 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 1));
390 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 2));
391 EXPECT_EQ(1, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 3));
392 EXPECT_EQ(1, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 4));
393 EXPECT_EQ(1, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 5));
394 EXPECT_EQ(2, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 6));
395 EXPECT_EQ(2, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 7));
396 EXPECT_EQ(2, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 8));
397 EXPECT_EQ(3, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 9));
398 EXPECT_EQ(3, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 10));
399 EXPECT_EQ(3, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 11));
401 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 0));
402 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 1));
403 EXPECT_EQ(1, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 2));
404 EXPECT_EQ(2, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 3));
405 EXPECT_EQ(3, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 4));
406 EXPECT_EQ(4, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 5));
407 EXPECT_EQ(5, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 6));
408 EXPECT_EQ(6, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 7));
409 EXPECT_EQ(7, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 8));
410 EXPECT_EQ(7, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 9));
411 EXPECT_EQ(7, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 10));
412 EXPECT_EQ(7, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 11));
414 EXPECT_EQ(0, YIndex(gfx::Size(1, 1), gfx::Size(1, 1), false, 0));
415 EXPECT_EQ(0, YIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 0));
416 EXPECT_EQ(0, YIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 1));
417 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 0));
418 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 1));
419 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 2));
421 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 0));
422 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 1));
423 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 2));
424 EXPECT_EQ(1, YIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 3));
426 EXPECT_EQ(0, YIndex(gfx::Size(1, 1), gfx::Size(1, 1), true, 0));
427 EXPECT_EQ(0, YIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 0));
428 EXPECT_EQ(0, YIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 1));
429 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 0));
430 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 1));
431 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 2));
433 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 0));
434 EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 1));
435 EXPECT_EQ(1, YIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 2));
436 EXPECT_EQ(1, YIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 3));
439 TEST(TilingDataTest
, FirstBorderTileYIndexFromSrcCoord
) {
440 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 0));
441 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 1));
442 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 2));
443 EXPECT_EQ(1, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 3));
444 EXPECT_EQ(1, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 4));
445 EXPECT_EQ(1, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 5));
446 EXPECT_EQ(2, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 6));
447 EXPECT_EQ(2, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 7));
448 EXPECT_EQ(2, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 8));
449 EXPECT_EQ(3, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 9));
450 EXPECT_EQ(3, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 10));
451 EXPECT_EQ(3, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 11));
453 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 0));
454 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 1));
455 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 2));
456 EXPECT_EQ(1, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 3));
457 EXPECT_EQ(2, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 4));
458 EXPECT_EQ(3, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 5));
459 EXPECT_EQ(4, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 6));
460 EXPECT_EQ(5, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 7));
461 EXPECT_EQ(6, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 8));
462 EXPECT_EQ(7, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 9));
463 EXPECT_EQ(7, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 10));
464 EXPECT_EQ(7, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 11));
466 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(1, 1), gfx::Size(1, 1), false, 0));
467 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 0));
468 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 1));
469 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 0));
470 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 1));
471 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 2));
473 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 0));
474 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 1));
475 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 2));
476 EXPECT_EQ(1, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 3));
478 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(1, 1), gfx::Size(1, 1), true, 0));
479 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 0));
480 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 1));
481 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 0));
482 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 1));
483 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 2));
485 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 0));
486 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 1));
487 EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 2));
488 EXPECT_EQ(1, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 3));
491 TEST(TilingDataTest
, LastBorderTileYIndexFromSrcCoord
) {
492 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 0));
493 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 1));
494 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 2));
495 EXPECT_EQ(1, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 3));
496 EXPECT_EQ(1, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 4));
497 EXPECT_EQ(1, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 5));
498 EXPECT_EQ(2, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 6));
499 EXPECT_EQ(2, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 7));
500 EXPECT_EQ(2, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 8));
501 EXPECT_EQ(3, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 9));
502 EXPECT_EQ(3, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 10));
503 EXPECT_EQ(3, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 11));
505 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 0));
506 EXPECT_EQ(1, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 1));
507 EXPECT_EQ(2, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 2));
508 EXPECT_EQ(3, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 3));
509 EXPECT_EQ(4, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 4));
510 EXPECT_EQ(5, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 5));
511 EXPECT_EQ(6, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 6));
512 EXPECT_EQ(7, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 7));
513 EXPECT_EQ(7, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 8));
514 EXPECT_EQ(7, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 9));
515 EXPECT_EQ(7, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 10));
516 EXPECT_EQ(7, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 11));
518 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(1, 1), gfx::Size(1, 1), false, 0));
519 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 0));
520 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 1));
521 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 0));
522 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 1));
523 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 2));
525 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 0));
526 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 1));
527 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 2));
528 EXPECT_EQ(1, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 3));
530 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(1, 1), gfx::Size(1, 1), true, 0));
531 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 0));
532 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 1));
533 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 0));
534 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 1));
535 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 2));
537 EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 0));
538 EXPECT_EQ(1, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 1));
539 EXPECT_EQ(1, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 2));
540 EXPECT_EQ(1, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 3));
543 TEST(TilingDataTest
, TileSizeX
) {
544 EXPECT_EQ(5, SizeX(gfx::Size(5, 5), gfx::Size(5, 5), false, 0));
545 EXPECT_EQ(5, SizeX(gfx::Size(5, 5), gfx::Size(5, 5), true, 0));
547 EXPECT_EQ(5, SizeX(gfx::Size(5, 5), gfx::Size(6, 6), false, 0));
548 EXPECT_EQ(1, SizeX(gfx::Size(5, 5), gfx::Size(6, 6), false, 1));
549 EXPECT_EQ(4, SizeX(gfx::Size(5, 5), gfx::Size(6, 6), true, 0));
550 EXPECT_EQ(2, SizeX(gfx::Size(5, 5), gfx::Size(6, 6), true, 1));
552 EXPECT_EQ(5, SizeX(gfx::Size(5, 5), gfx::Size(8, 8), false, 0));
553 EXPECT_EQ(3, SizeX(gfx::Size(5, 5), gfx::Size(8, 8), false, 1));
554 EXPECT_EQ(4, SizeX(gfx::Size(5, 5), gfx::Size(8, 8), true, 0));
555 EXPECT_EQ(4, SizeX(gfx::Size(5, 5), gfx::Size(8, 8), true, 1));
557 EXPECT_EQ(5, SizeX(gfx::Size(5, 5), gfx::Size(10, 10), false, 0));
558 EXPECT_EQ(5, SizeX(gfx::Size(5, 5), gfx::Size(10, 10), false, 1));
559 EXPECT_EQ(4, SizeX(gfx::Size(5, 5), gfx::Size(10, 10), true, 0));
560 EXPECT_EQ(3, SizeX(gfx::Size(5, 5), gfx::Size(10, 10), true, 1));
561 EXPECT_EQ(3, SizeX(gfx::Size(5, 5), gfx::Size(10, 10), true, 2));
563 EXPECT_EQ(4, SizeX(gfx::Size(5, 5), gfx::Size(11, 11), true, 2));
564 EXPECT_EQ(3, SizeX(gfx::Size(5, 5), gfx::Size(12, 12), true, 2));
566 EXPECT_EQ(3, SizeX(gfx::Size(5, 9), gfx::Size(12, 17), true, 2));
569 TEST(TilingDataTest
, TileSizeY
) {
570 EXPECT_EQ(5, SizeY(gfx::Size(5, 5), gfx::Size(5, 5), false, 0));
571 EXPECT_EQ(5, SizeY(gfx::Size(5, 5), gfx::Size(5, 5), true, 0));
573 EXPECT_EQ(5, SizeY(gfx::Size(5, 5), gfx::Size(6, 6), false, 0));
574 EXPECT_EQ(1, SizeY(gfx::Size(5, 5), gfx::Size(6, 6), false, 1));
575 EXPECT_EQ(4, SizeY(gfx::Size(5, 5), gfx::Size(6, 6), true, 0));
576 EXPECT_EQ(2, SizeY(gfx::Size(5, 5), gfx::Size(6, 6), true, 1));
578 EXPECT_EQ(5, SizeY(gfx::Size(5, 5), gfx::Size(8, 8), false, 0));
579 EXPECT_EQ(3, SizeY(gfx::Size(5, 5), gfx::Size(8, 8), false, 1));
580 EXPECT_EQ(4, SizeY(gfx::Size(5, 5), gfx::Size(8, 8), true, 0));
581 EXPECT_EQ(4, SizeY(gfx::Size(5, 5), gfx::Size(8, 8), true, 1));
583 EXPECT_EQ(5, SizeY(gfx::Size(5, 5), gfx::Size(10, 10), false, 0));
584 EXPECT_EQ(5, SizeY(gfx::Size(5, 5), gfx::Size(10, 10), false, 1));
585 EXPECT_EQ(4, SizeY(gfx::Size(5, 5), gfx::Size(10, 10), true, 0));
586 EXPECT_EQ(3, SizeY(gfx::Size(5, 5), gfx::Size(10, 10), true, 1));
587 EXPECT_EQ(3, SizeY(gfx::Size(5, 5), gfx::Size(10, 10), true, 2));
589 EXPECT_EQ(4, SizeY(gfx::Size(5, 5), gfx::Size(11, 11), true, 2));
590 EXPECT_EQ(3, SizeY(gfx::Size(5, 5), gfx::Size(12, 12), true, 2));
592 EXPECT_EQ(3, SizeY(gfx::Size(9, 5), gfx::Size(17, 12), true, 2));
595 TEST(TilingDataTest
, TileSizeX_and_TilePositionX
) {
596 // Single tile cases:
597 EXPECT_EQ(1, SizeX(gfx::Size(3, 3), gfx::Size(1, 1), false, 0));
598 EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(1, 1), false, 0));
599 EXPECT_EQ(1, SizeX(gfx::Size(3, 3), gfx::Size(1, 100), false, 0));
600 EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(1, 100), false, 0));
601 EXPECT_EQ(3, SizeX(gfx::Size(3, 3), gfx::Size(3, 1), false, 0));
602 EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(3, 1), false, 0));
603 EXPECT_EQ(3, SizeX(gfx::Size(3, 3), gfx::Size(3, 100), false, 0));
604 EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(3, 100), false, 0));
605 EXPECT_EQ(1, SizeX(gfx::Size(3, 3), gfx::Size(1, 1), true, 0));
606 EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(1, 1), true, 0));
607 EXPECT_EQ(1, SizeX(gfx::Size(3, 3), gfx::Size(1, 100), true, 0));
608 EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(1, 100), true, 0));
609 EXPECT_EQ(3, SizeX(gfx::Size(3, 3), gfx::Size(3, 1), true, 0));
610 EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(3, 1), true, 0));
611 EXPECT_EQ(3, SizeX(gfx::Size(3, 3), gfx::Size(3, 100), true, 0));
612 EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(3, 100), true, 0));
617 EXPECT_EQ(2, NumTiles(gfx::Size(3, 3), gfx::Size(6, 1), false));
618 EXPECT_EQ(3, SizeX(gfx::Size(3, 3), gfx::Size(6, 1), false, 0));
619 EXPECT_EQ(3, SizeX(gfx::Size(3, 3), gfx::Size(6, 1), false, 1));
620 EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(6, 1), false, 0));
621 EXPECT_EQ(3, PosX(gfx::Size(3, 3), gfx::Size(6, 1), false, 1));
622 EXPECT_EQ(3, SizeX(gfx::Size(3, 3), gfx::Size(6, 100), false, 0));
623 EXPECT_EQ(3, SizeX(gfx::Size(3, 3), gfx::Size(6, 100), false, 1));
624 EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(6, 100), false, 0));
625 EXPECT_EQ(3, PosX(gfx::Size(3, 3), gfx::Size(6, 100), false, 1));
629 // positions 0, 2, 3, 4
630 EXPECT_EQ(4, NumTiles(gfx::Size(3, 3), gfx::Size(6, 1), true));
631 EXPECT_EQ(2, SizeX(gfx::Size(3, 3), gfx::Size(6, 1), true, 0));
632 EXPECT_EQ(1, SizeX(gfx::Size(3, 3), gfx::Size(6, 1), true, 1));
633 EXPECT_EQ(1, SizeX(gfx::Size(3, 3), gfx::Size(6, 1), true, 2));
634 EXPECT_EQ(2, SizeX(gfx::Size(3, 3), gfx::Size(6, 1), true, 3));
635 EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(6, 1), true, 0));
636 EXPECT_EQ(2, PosX(gfx::Size(3, 3), gfx::Size(6, 1), true, 1));
637 EXPECT_EQ(3, PosX(gfx::Size(3, 3), gfx::Size(6, 1), true, 2));
638 EXPECT_EQ(4, PosX(gfx::Size(3, 3), gfx::Size(6, 1), true, 3));
639 EXPECT_EQ(2, SizeX(gfx::Size(3, 7), gfx::Size(6, 100), true, 0));
640 EXPECT_EQ(1, SizeX(gfx::Size(3, 7), gfx::Size(6, 100), true, 1));
641 EXPECT_EQ(1, SizeX(gfx::Size(3, 7), gfx::Size(6, 100), true, 2));
642 EXPECT_EQ(2, SizeX(gfx::Size(3, 7), gfx::Size(6, 100), true, 3));
643 EXPECT_EQ(0, PosX(gfx::Size(3, 7), gfx::Size(6, 100), true, 0));
644 EXPECT_EQ(2, PosX(gfx::Size(3, 7), gfx::Size(6, 100), true, 1));
645 EXPECT_EQ(3, PosX(gfx::Size(3, 7), gfx::Size(6, 100), true, 2));
646 EXPECT_EQ(4, PosX(gfx::Size(3, 7), gfx::Size(6, 100), true, 3));
649 TEST(TilingDataTest
, TileSizeY_and_TilePositionY
) {
650 // Single tile cases:
651 EXPECT_EQ(1, SizeY(gfx::Size(3, 3), gfx::Size(1, 1), false, 0));
652 EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(1, 1), false, 0));
653 EXPECT_EQ(1, SizeY(gfx::Size(3, 3), gfx::Size(100, 1), false, 0));
654 EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(100, 1), false, 0));
655 EXPECT_EQ(3, SizeY(gfx::Size(3, 3), gfx::Size(1, 3), false, 0));
656 EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(1, 3), false, 0));
657 EXPECT_EQ(3, SizeY(gfx::Size(3, 3), gfx::Size(100, 3), false, 0));
658 EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(100, 3), false, 0));
659 EXPECT_EQ(1, SizeY(gfx::Size(3, 3), gfx::Size(1, 1), true, 0));
660 EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(1, 1), true, 0));
661 EXPECT_EQ(1, SizeY(gfx::Size(3, 3), gfx::Size(100, 1), true, 0));
662 EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(100, 1), true, 0));
663 EXPECT_EQ(3, SizeY(gfx::Size(3, 3), gfx::Size(1, 3), true, 0));
664 EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(1, 3), true, 0));
665 EXPECT_EQ(3, SizeY(gfx::Size(3, 3), gfx::Size(100, 3), true, 0));
666 EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(100, 3), true, 0));
671 EXPECT_EQ(2, NumTiles(gfx::Size(3, 3), gfx::Size(1, 6), false));
672 EXPECT_EQ(3, SizeY(gfx::Size(3, 3), gfx::Size(1, 6), false, 0));
673 EXPECT_EQ(3, SizeY(gfx::Size(3, 3), gfx::Size(1, 6), false, 1));
674 EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(1, 6), false, 0));
675 EXPECT_EQ(3, PosY(gfx::Size(3, 3), gfx::Size(1, 6), false, 1));
676 EXPECT_EQ(3, SizeY(gfx::Size(3, 3), gfx::Size(100, 6), false, 0));
677 EXPECT_EQ(3, SizeY(gfx::Size(3, 3), gfx::Size(100, 6), false, 1));
678 EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(100, 6), false, 0));
679 EXPECT_EQ(3, PosY(gfx::Size(3, 3), gfx::Size(100, 6), false, 1));
683 // positions 0, 2, 3, 4
684 EXPECT_EQ(4, NumTiles(gfx::Size(3, 3), gfx::Size(1, 6), true));
685 EXPECT_EQ(2, SizeY(gfx::Size(3, 3), gfx::Size(1, 6), true, 0));
686 EXPECT_EQ(1, SizeY(gfx::Size(3, 3), gfx::Size(1, 6), true, 1));
687 EXPECT_EQ(1, SizeY(gfx::Size(3, 3), gfx::Size(1, 6), true, 2));
688 EXPECT_EQ(2, SizeY(gfx::Size(3, 3), gfx::Size(1, 6), true, 3));
689 EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(1, 6), true, 0));
690 EXPECT_EQ(2, PosY(gfx::Size(3, 3), gfx::Size(1, 6), true, 1));
691 EXPECT_EQ(3, PosY(gfx::Size(3, 3), gfx::Size(1, 6), true, 2));
692 EXPECT_EQ(4, PosY(gfx::Size(3, 3), gfx::Size(1, 6), true, 3));
693 EXPECT_EQ(2, SizeY(gfx::Size(7, 3), gfx::Size(100, 6), true, 0));
694 EXPECT_EQ(1, SizeY(gfx::Size(7, 3), gfx::Size(100, 6), true, 1));
695 EXPECT_EQ(1, SizeY(gfx::Size(7, 3), gfx::Size(100, 6), true, 2));
696 EXPECT_EQ(2, SizeY(gfx::Size(7, 3), gfx::Size(100, 6), true, 3));
697 EXPECT_EQ(0, PosY(gfx::Size(7, 3), gfx::Size(100, 6), true, 0));
698 EXPECT_EQ(2, PosY(gfx::Size(7, 3), gfx::Size(100, 6), true, 1));
699 EXPECT_EQ(3, PosY(gfx::Size(7, 3), gfx::Size(100, 6), true, 2));
700 EXPECT_EQ(4, PosY(gfx::Size(7, 3), gfx::Size(100, 6), true, 3));
703 TEST(TilingDataTest
, SetTotalSize
) {
704 TilingData
data(gfx::Size(5, 5), gfx::Size(5, 5), false);
705 EXPECT_EQ(5, data
.total_size().width());
706 EXPECT_EQ(5, data
.total_size().height());
707 EXPECT_EQ(1, data
.num_tiles_x());
708 EXPECT_EQ(5, data
.TileSizeX(0));
709 EXPECT_EQ(1, data
.num_tiles_y());
710 EXPECT_EQ(5, data
.TileSizeY(0));
712 data
.SetTotalSize(gfx::Size(6, 5));
713 EXPECT_EQ(6, data
.total_size().width());
714 EXPECT_EQ(5, data
.total_size().height());
715 EXPECT_EQ(2, data
.num_tiles_x());
716 EXPECT_EQ(5, data
.TileSizeX(0));
717 EXPECT_EQ(1, data
.TileSizeX(1));
718 EXPECT_EQ(1, data
.num_tiles_y());
719 EXPECT_EQ(5, data
.TileSizeY(0));
721 data
.SetTotalSize(gfx::Size(5, 12));
722 EXPECT_EQ(5, data
.total_size().width());
723 EXPECT_EQ(12, data
.total_size().height());
724 EXPECT_EQ(1, data
.num_tiles_x());
725 EXPECT_EQ(5, data
.TileSizeX(0));
726 EXPECT_EQ(3, data
.num_tiles_y());
727 EXPECT_EQ(5, data
.TileSizeY(0));
728 EXPECT_EQ(5, data
.TileSizeY(1));
729 EXPECT_EQ(2, data
.TileSizeY(2));
732 TEST(TilingDataTest
, SetMaxTextureSizeNoBorders
) {
733 TilingData
data(gfx::Size(8, 8), gfx::Size(16, 32), false);
734 EXPECT_EQ(2, data
.num_tiles_x());
735 EXPECT_EQ(4, data
.num_tiles_y());
737 data
.SetMaxTextureSize(gfx::Size(32, 32));
738 EXPECT_EQ(gfx::Size(32, 32), data
.max_texture_size());
739 EXPECT_EQ(1, data
.num_tiles_x());
740 EXPECT_EQ(1, data
.num_tiles_y());
742 data
.SetMaxTextureSize(gfx::Size(2, 2));
743 EXPECT_EQ(gfx::Size(2, 2), data
.max_texture_size());
744 EXPECT_EQ(8, data
.num_tiles_x());
745 EXPECT_EQ(16, data
.num_tiles_y());
747 data
.SetMaxTextureSize(gfx::Size(5, 5));
748 EXPECT_EQ(gfx::Size(5, 5), data
.max_texture_size());
749 EXPECT_EQ(4, data
.num_tiles_x());
750 EXPECT_EQ(7, data
.num_tiles_y());
752 data
.SetMaxTextureSize(gfx::Size(8, 5));
753 EXPECT_EQ(gfx::Size(8, 5), data
.max_texture_size());
754 EXPECT_EQ(2, data
.num_tiles_x());
755 EXPECT_EQ(7, data
.num_tiles_y());
758 TEST(TilingDataTest
, SetMaxTextureSizeBorders
) {
759 TilingData
data(gfx::Size(8, 8), gfx::Size(16, 32), true);
760 EXPECT_EQ(3, data
.num_tiles_x());
761 EXPECT_EQ(5, data
.num_tiles_y());
763 data
.SetMaxTextureSize(gfx::Size(32, 32));
764 EXPECT_EQ(gfx::Size(32, 32), data
.max_texture_size());
765 EXPECT_EQ(1, data
.num_tiles_x());
766 EXPECT_EQ(1, data
.num_tiles_y());
768 data
.SetMaxTextureSize(gfx::Size(2, 2));
769 EXPECT_EQ(gfx::Size(2, 2), data
.max_texture_size());
770 EXPECT_EQ(0, data
.num_tiles_x());
771 EXPECT_EQ(0, data
.num_tiles_y());
773 data
.SetMaxTextureSize(gfx::Size(5, 5));
774 EXPECT_EQ(gfx::Size(5, 5), data
.max_texture_size());
775 EXPECT_EQ(5, data
.num_tiles_x());
776 EXPECT_EQ(10, data
.num_tiles_y());
778 data
.SetMaxTextureSize(gfx::Size(8, 5));
779 EXPECT_EQ(gfx::Size(8, 5), data
.max_texture_size());
780 EXPECT_EQ(3, data
.num_tiles_x());
781 EXPECT_EQ(10, data
.num_tiles_y());
784 TEST(TilingDataTest
, Assignment
) {
786 TilingData
source(gfx::Size(8, 8), gfx::Size(16, 32), true);
787 TilingData dest
= source
;
788 EXPECT_EQ(source
.border_texels(), dest
.border_texels());
789 EXPECT_EQ(source
.max_texture_size(), dest
.max_texture_size());
790 EXPECT_EQ(source
.num_tiles_x(), dest
.num_tiles_x());
791 EXPECT_EQ(source
.num_tiles_y(), dest
.num_tiles_y());
792 EXPECT_EQ(source
.total_size().width(), dest
.total_size().width());
793 EXPECT_EQ(source
.total_size().height(), dest
.total_size().height());
796 TilingData
source(gfx::Size(7, 3), gfx::Size(6, 100), false);
797 TilingData
dest(source
);
798 EXPECT_EQ(source
.border_texels(), dest
.border_texels());
799 EXPECT_EQ(source
.max_texture_size(), dest
.max_texture_size());
800 EXPECT_EQ(source
.num_tiles_x(), dest
.num_tiles_x());
801 EXPECT_EQ(source
.num_tiles_y(), dest
.num_tiles_y());
802 EXPECT_EQ(source
.total_size().width(), dest
.total_size().width());
803 EXPECT_EQ(source
.total_size().height(), dest
.total_size().height());
807 TEST(TilingDataTest
, SetBorderTexels
) {
808 TilingData
data(gfx::Size(8, 8), gfx::Size(16, 32), false);
809 EXPECT_EQ(2, data
.num_tiles_x());
810 EXPECT_EQ(4, data
.num_tiles_y());
812 data
.SetHasBorderTexels(true);
813 EXPECT_EQ(3, data
.num_tiles_x());
814 EXPECT_EQ(5, data
.num_tiles_y());
816 data
.SetHasBorderTexels(true);
817 EXPECT_EQ(3, data
.num_tiles_x());
818 EXPECT_EQ(5, data
.num_tiles_y());
820 data
.SetHasBorderTexels(false);
821 EXPECT_EQ(2, data
.num_tiles_x());
822 EXPECT_EQ(4, data
.num_tiles_y());
825 TEST(TilingDataTest
, LargeBorders
) {
826 TilingData
data(gfx::Size(100, 80), gfx::Size(200, 145), 30);
827 EXPECT_EQ(30, data
.border_texels());
829 EXPECT_EQ(70, data
.TileSizeX(0));
830 EXPECT_EQ(40, data
.TileSizeX(1));
831 EXPECT_EQ(40, data
.TileSizeX(2));
832 EXPECT_EQ(50, data
.TileSizeX(3));
833 EXPECT_EQ(4, data
.num_tiles_x());
835 EXPECT_EQ(50, data
.TileSizeY(0));
836 EXPECT_EQ(20, data
.TileSizeY(1));
837 EXPECT_EQ(20, data
.TileSizeY(2));
838 EXPECT_EQ(20, data
.TileSizeY(3));
839 EXPECT_EQ(35, data
.TileSizeY(4));
840 EXPECT_EQ(5, data
.num_tiles_y());
842 EXPECT_RECT_EQ(gfx::Rect(0, 0, 70, 50), data
.TileBounds(0, 0));
843 EXPECT_RECT_EQ(gfx::Rect(70, 50, 40, 20), data
.TileBounds(1, 1));
844 EXPECT_RECT_EQ(gfx::Rect(110, 110, 40, 35), data
.TileBounds(2, 4));
845 EXPECT_RECT_EQ(gfx::Rect(150, 70, 50, 20), data
.TileBounds(3, 2));
846 EXPECT_RECT_EQ(gfx::Rect(150, 110, 50, 35), data
.TileBounds(3, 4));
848 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 80), data
.TileBoundsWithBorder(0, 0));
849 EXPECT_RECT_EQ(gfx::Rect(40, 20, 100, 80), data
.TileBoundsWithBorder(1, 1));
850 EXPECT_RECT_EQ(gfx::Rect(80, 80, 100, 65), data
.TileBoundsWithBorder(2, 4));
851 EXPECT_RECT_EQ(gfx::Rect(120, 40, 80, 80), data
.TileBoundsWithBorder(3, 2));
852 EXPECT_RECT_EQ(gfx::Rect(120, 80, 80, 65), data
.TileBoundsWithBorder(3, 4));
854 EXPECT_EQ(0, data
.TileXIndexFromSrcCoord(0));
855 EXPECT_EQ(0, data
.TileXIndexFromSrcCoord(69));
856 EXPECT_EQ(1, data
.TileXIndexFromSrcCoord(70));
857 EXPECT_EQ(1, data
.TileXIndexFromSrcCoord(109));
858 EXPECT_EQ(2, data
.TileXIndexFromSrcCoord(110));
859 EXPECT_EQ(2, data
.TileXIndexFromSrcCoord(149));
860 EXPECT_EQ(3, data
.TileXIndexFromSrcCoord(150));
861 EXPECT_EQ(3, data
.TileXIndexFromSrcCoord(199));
863 EXPECT_EQ(0, data
.TileYIndexFromSrcCoord(0));
864 EXPECT_EQ(0, data
.TileYIndexFromSrcCoord(49));
865 EXPECT_EQ(1, data
.TileYIndexFromSrcCoord(50));
866 EXPECT_EQ(1, data
.TileYIndexFromSrcCoord(69));
867 EXPECT_EQ(2, data
.TileYIndexFromSrcCoord(70));
868 EXPECT_EQ(2, data
.TileYIndexFromSrcCoord(89));
869 EXPECT_EQ(3, data
.TileYIndexFromSrcCoord(90));
870 EXPECT_EQ(3, data
.TileYIndexFromSrcCoord(109));
871 EXPECT_EQ(4, data
.TileYIndexFromSrcCoord(110));
872 EXPECT_EQ(4, data
.TileYIndexFromSrcCoord(144));
874 EXPECT_EQ(0, data
.FirstBorderTileXIndexFromSrcCoord(0));
875 EXPECT_EQ(0, data
.FirstBorderTileXIndexFromSrcCoord(99));
876 EXPECT_EQ(1, data
.FirstBorderTileXIndexFromSrcCoord(100));
877 EXPECT_EQ(1, data
.FirstBorderTileXIndexFromSrcCoord(139));
878 EXPECT_EQ(2, data
.FirstBorderTileXIndexFromSrcCoord(140));
879 EXPECT_EQ(2, data
.FirstBorderTileXIndexFromSrcCoord(179));
880 EXPECT_EQ(3, data
.FirstBorderTileXIndexFromSrcCoord(180));
881 EXPECT_EQ(3, data
.FirstBorderTileXIndexFromSrcCoord(199));
883 EXPECT_EQ(0, data
.FirstBorderTileYIndexFromSrcCoord(0));
884 EXPECT_EQ(0, data
.FirstBorderTileYIndexFromSrcCoord(79));
885 EXPECT_EQ(1, data
.FirstBorderTileYIndexFromSrcCoord(80));
886 EXPECT_EQ(1, data
.FirstBorderTileYIndexFromSrcCoord(99));
887 EXPECT_EQ(2, data
.FirstBorderTileYIndexFromSrcCoord(100));
888 EXPECT_EQ(2, data
.FirstBorderTileYIndexFromSrcCoord(119));
889 EXPECT_EQ(3, data
.FirstBorderTileYIndexFromSrcCoord(120));
890 EXPECT_EQ(3, data
.FirstBorderTileYIndexFromSrcCoord(139));
891 EXPECT_EQ(4, data
.FirstBorderTileYIndexFromSrcCoord(140));
892 EXPECT_EQ(4, data
.FirstBorderTileYIndexFromSrcCoord(144));
894 EXPECT_EQ(0, data
.LastBorderTileXIndexFromSrcCoord(0));
895 EXPECT_EQ(0, data
.LastBorderTileXIndexFromSrcCoord(39));
896 EXPECT_EQ(1, data
.LastBorderTileXIndexFromSrcCoord(40));
897 EXPECT_EQ(1, data
.LastBorderTileXIndexFromSrcCoord(79));
898 EXPECT_EQ(2, data
.LastBorderTileXIndexFromSrcCoord(80));
899 EXPECT_EQ(2, data
.LastBorderTileXIndexFromSrcCoord(119));
900 EXPECT_EQ(3, data
.LastBorderTileXIndexFromSrcCoord(120));
901 EXPECT_EQ(3, data
.LastBorderTileXIndexFromSrcCoord(199));
903 EXPECT_EQ(0, data
.LastBorderTileYIndexFromSrcCoord(0));
904 EXPECT_EQ(0, data
.LastBorderTileYIndexFromSrcCoord(19));
905 EXPECT_EQ(1, data
.LastBorderTileYIndexFromSrcCoord(20));
906 EXPECT_EQ(1, data
.LastBorderTileYIndexFromSrcCoord(39));
907 EXPECT_EQ(2, data
.LastBorderTileYIndexFromSrcCoord(40));
908 EXPECT_EQ(2, data
.LastBorderTileYIndexFromSrcCoord(59));
909 EXPECT_EQ(3, data
.LastBorderTileYIndexFromSrcCoord(60));
910 EXPECT_EQ(3, data
.LastBorderTileYIndexFromSrcCoord(79));
911 EXPECT_EQ(4, data
.LastBorderTileYIndexFromSrcCoord(80));
912 EXPECT_EQ(4, data
.LastBorderTileYIndexFromSrcCoord(144));
916 const TilingData
& data
,
923 EXPECT_GE(expect_left
, 0);
924 EXPECT_GE(expect_top
, 0);
925 EXPECT_LT(expect_right
, data
.num_tiles_x());
926 EXPECT_LT(expect_bottom
, data
.num_tiles_y());
928 std::vector
<std::pair
<int, int> > original_expected
;
929 for (int x
= 0; x
< data
.num_tiles_x(); ++x
) {
930 for (int y
= 0; y
< data
.num_tiles_y(); ++y
) {
931 gfx::Rect bounds
= data
.TileBoundsWithBorder(x
, y
);
932 if (x
>= expect_left
&& x
<= expect_right
&&
933 y
>= expect_top
&& y
<= expect_bottom
) {
934 EXPECT_TRUE(bounds
.Intersects(rect
));
935 original_expected
.push_back(std::make_pair(x
, y
));
937 EXPECT_FALSE(bounds
.Intersects(rect
));
942 // Verify with vanilla iterator.
944 std::vector
<std::pair
<int, int> > expected
= original_expected
;
945 for (TilingData::Iterator
iter(&data
, rect
); iter
; ++iter
) {
947 for (size_t i
= 0; i
< expected
.size(); ++i
) {
948 if (expected
[i
] == iter
.index()) {
949 expected
[i
] = expected
.back();
957 EXPECT_EQ(0u, expected
.size());
960 // Make sure this also works with a difference iterator and an empty ignore.
962 std::vector
<std::pair
<int, int> > expected
= original_expected
;
963 for (TilingData::DifferenceIterator
iter(&data
, rect
, gfx::Rect());
966 for (size_t i
= 0; i
< expected
.size(); ++i
) {
967 if (expected
[i
] == iter
.index()) {
968 expected
[i
] = expected
.back();
976 EXPECT_EQ(0u, expected
.size());
980 TEST(TilingDataTest
, IteratorNoBorderTexels
) {
981 TilingData
data(gfx::Size(10, 10), gfx::Size(40, 25), false);
982 // X border index by src coord: [0-10), [10-20), [20, 30), [30, 40)
983 // Y border index by src coord: [0-10), [10-20), [20, 25)
984 TestIterate(data
, gfx::Rect(0, 0, 40, 25), 0, 0, 3, 2);
985 TestIterate(data
, gfx::Rect(15, 15, 8, 8), 1, 1, 2, 2);
988 TestIterate(data
, gfx::Rect(-100, -100, 1000, 1000), 0, 0, 3, 2);
989 TestIterate(data
, gfx::Rect(-100, 20, 1000, 1), 0, 2, 3, 2);
990 TestIterate(data
, gfx::Rect(29, -100, 31, 1000), 2, 0, 3, 2);
992 TestIterate(data
, gfx::Rect(60, 80, 100, 100), 0, 0, -1, -1);
995 TEST(TilingDataTest
, IteratorOneBorderTexel
) {
996 TilingData
data(gfx::Size(10, 20), gfx::Size(25, 45), true);
997 // X border index by src coord: [0-10), [8-18), [16-25)
998 // Y border index by src coord: [0-20), [18-38), [36-45)
999 TestIterate(data
, gfx::Rect(0, 0, 25, 45), 0, 0, 2, 2);
1000 TestIterate(data
, gfx::Rect(18, 19, 3, 17), 2, 0, 2, 1);
1001 TestIterate(data
, gfx::Rect(10, 20, 6, 16), 1, 1, 1, 1);
1002 TestIterate(data
, gfx::Rect(9, 19, 8, 18), 0, 0, 2, 2);
1005 TestIterate(data
, gfx::Rect(-100, -100, 1000, 1000), 0, 0, 2, 2);
1006 TestIterate(data
, gfx::Rect(-100, 20, 1000, 1), 0, 1, 2, 1);
1007 TestIterate(data
, gfx::Rect(18, -100, 6, 1000), 2, 0, 2, 2);
1009 TestIterate(data
, gfx::Rect(60, 80, 100, 100), 0, 0, -1, -1);
1012 TEST(TilingDataTest
, IteratorManyBorderTexels
) {
1013 TilingData
data(gfx::Size(50, 60), gfx::Size(65, 110), 20);
1014 // X border index by src coord: [0-50), [10-60), [20-65)
1015 // Y border index by src coord: [0-60), [20-80), [40-100), [60-110)
1016 TestIterate(data
, gfx::Rect(0, 0, 65, 110), 0, 0, 2, 3);
1017 TestIterate(data
, gfx::Rect(50, 60, 15, 65), 1, 1, 2, 3);
1018 TestIterate(data
, gfx::Rect(60, 30, 2, 10), 2, 0, 2, 1);
1021 TestIterate(data
, gfx::Rect(-100, -100, 1000, 1000), 0, 0, 2, 3);
1022 TestIterate(data
, gfx::Rect(-100, 10, 1000, 10), 0, 0, 2, 0);
1023 TestIterate(data
, gfx::Rect(10, -100, 10, 1000), 0, 0, 1, 3);
1025 TestIterate(data
, gfx::Rect(65, 110, 100, 100), 0, 0, -1, -1);
1028 TEST(TilingDataTest
, IteratorOneTile
) {
1029 TilingData
no_border(gfx::Size(1000, 1000), gfx::Size(30, 40), false);
1030 TestIterate(no_border
, gfx::Rect(0, 0, 30, 40), 0, 0, 0, 0);
1031 TestIterate(no_border
, gfx::Rect(10, 10, 20, 20), 0, 0, 0, 0);
1032 TestIterate(no_border
, gfx::Rect(30, 40, 100, 100), 0, 0, -1, -1);
1034 TilingData
one_border(gfx::Size(1000, 1000), gfx::Size(30, 40), true);
1035 TestIterate(one_border
, gfx::Rect(0, 0, 30, 40), 0, 0, 0, 0);
1036 TestIterate(one_border
, gfx::Rect(10, 10, 20, 20), 0, 0, 0, 0);
1037 TestIterate(one_border
, gfx::Rect(30, 40, 100, 100), 0, 0, -1, -1);
1039 TilingData
big_border(gfx::Size(1000, 1000), gfx::Size(30, 40), 50);
1040 TestIterate(big_border
, gfx::Rect(0, 0, 30, 40), 0, 0, 0, 0);
1041 TestIterate(big_border
, gfx::Rect(10, 10, 20, 20), 0, 0, 0, 0);
1042 TestIterate(big_border
, gfx::Rect(30, 40, 100, 100), 0, 0, -1, -1);
1045 TEST(TilingDataTest
, IteratorNoTiles
) {
1046 TilingData
data(gfx::Size(100, 100), gfx::Size(), false);
1047 TestIterate(data
, gfx::Rect(0, 0, 100, 100), 0, 0, -1, -1);
1051 const TilingData
& data
,
1056 std::vector
<std::pair
<int, int> > expected
;
1057 for (int y
= 0; y
< data
.num_tiles_y(); ++y
) {
1058 for (int x
= 0; x
< data
.num_tiles_x(); ++x
) {
1059 gfx::Rect bounds
= data
.TileBoundsWithBorder(x
, y
);
1060 if (bounds
.Intersects(consider
) && !bounds
.Intersects(ignore
))
1061 expected
.push_back(std::make_pair(x
, y
));
1065 // Sanity check the test.
1066 EXPECT_EQ(num_tiles
, expected
.size());
1068 for (TilingData::DifferenceIterator
iter(&data
, consider
, ignore
);
1071 for (size_t i
= 0; i
< expected
.size(); ++i
) {
1072 if (expected
[i
] == iter
.index()) {
1073 expected
[i
] = expected
.back();
1074 expected
.pop_back();
1081 EXPECT_EQ(0u, expected
.size());
1084 TEST(TilingDataTest
, DifferenceIteratorIgnoreGeometry
) {
1085 // This test is checking that the iterator can handle different geometries of
1086 // ignore rects relative to the consider rect. The consider rect indices
1087 // themselves are mostly tested by the non-difference iterator tests, so the
1088 // full rect is mostly used here for simplicity.
1090 // X border index by src coord: [0-10), [10-20), [20, 30), [30, 40)
1091 // Y border index by src coord: [0-10), [10-20), [20, 25)
1092 TilingData
data(gfx::Size(10, 10), gfx::Size(40, 25), false);
1095 TestDiff(data
, gfx::Rect(0, 0, 40, 25), gfx::Rect(0, 0, 40, 25), 0);
1096 TestDiff(data
, gfx::Rect(0, 0, 40, 25), gfx::Rect(-100, -100, 200, 200), 0);
1097 TestDiff(data
, gfx::Rect(0, 0, 40, 25), gfx::Rect(9, 9, 30, 15), 0);
1098 TestDiff(data
, gfx::Rect(15, 15, 8, 8), gfx::Rect(15, 15, 8, 8), 0);
1101 TestDiff(data
, gfx::Rect(0, 0, 40, 25), gfx::Rect(-30, -20, 8, 8), 12);
1102 TestDiff(data
, gfx::Rect(0, 0, 40, 25), gfx::Rect(), 12);
1104 // Top left, remove 2x2 tiles
1105 TestDiff(data
, gfx::Rect(0, 0, 40, 25), gfx::Rect(0, 0, 20, 19), 8);
1106 // Bottom right, remove 2x2 tiles
1107 TestDiff(data
, gfx::Rect(0, 0, 40, 25), gfx::Rect(20, 15, 20, 6), 8);
1108 // Bottom left, remove 2x2 tiles
1109 TestDiff(data
, gfx::Rect(0, 0, 40, 25), gfx::Rect(0, 15, 20, 6), 8);
1110 // Top right, remove 2x2 tiles
1111 TestDiff(data
, gfx::Rect(0, 0, 40, 25), gfx::Rect(20, 0, 20, 19), 8);
1112 // Center, remove only one tile
1113 TestDiff(data
, gfx::Rect(0, 0, 40, 25), gfx::Rect(10, 10, 5, 5), 11);
1115 // Left column, flush left, removing two columns
1116 TestDiff(data
, gfx::Rect(0, 0, 40, 25), gfx::Rect(0, 0, 11, 25), 6);
1117 // Middle column, removing two columns
1118 TestDiff(data
, gfx::Rect(0, 0, 40, 25), gfx::Rect(11, 0, 11, 25), 6);
1119 // Right column, flush right, removing one column
1120 TestDiff(data
, gfx::Rect(0, 0, 40, 25), gfx::Rect(30, 0, 2, 25), 9);
1122 // Top row, flush top, removing one row
1123 TestDiff(data
, gfx::Rect(0, 0, 40, 25), gfx::Rect(0, 5, 40, 5), 8);
1124 // Middle row, removing one row
1125 TestDiff(data
, gfx::Rect(0, 0, 40, 25), gfx::Rect(0, 13, 40, 5), 8);
1126 // Bottom row, flush bottom, removing two rows
1127 TestDiff(data
, gfx::Rect(0, 0, 40, 25), gfx::Rect(0, 13, 40, 12), 4);
1129 // Non-intersecting, but still touching two of the same tiles.
1130 TestDiff(data
, gfx::Rect(8, 0, 32, 25), gfx::Rect(0, 12, 5, 12), 10);
1132 // Intersecting, but neither contains the other. 2x3 with one overlap.
1133 TestDiff(data
, gfx::Rect(5, 2, 20, 10), gfx::Rect(25, 15, 5, 10), 5);
1136 TEST(TilingDataTest
, DifferenceIteratorManyBorderTexels
) {
1137 // X border index by src coord: [0-50), [10-60), [20-65)
1138 // Y border index by src coord: [0-60), [20-80), [40-100), [60-110)
1139 TilingData
data(gfx::Size(50, 60), gfx::Size(65, 110), 20);
1141 // Ignore one column, three rows
1142 TestDiff(data
, gfx::Rect(0, 30, 55, 80), gfx::Rect(5, 30, 5, 15), 9);
1144 // Knock out three columns, leaving only one.
1145 TestDiff(data
, gfx::Rect(10, 30, 55, 80), gfx::Rect(30, 59, 20, 1), 3);
1147 // Overlap all tiles with ignore rect.
1148 TestDiff(data
, gfx::Rect(0, 0, 65, 110), gfx::Rect(30, 59, 1, 2), 0);
1151 TEST(TilingDataTest
, DifferenceIteratorOneTile
) {
1152 TilingData
no_border(gfx::Size(1000, 1000), gfx::Size(30, 40), false);
1153 TestDiff(no_border
, gfx::Rect(0, 0, 30, 40), gfx::Rect(), 1);
1154 TestDiff(no_border
, gfx::Rect(5, 5, 100, 100), gfx::Rect(5, 5, 1, 1), 0);
1156 TilingData
one_border(gfx::Size(1000, 1000), gfx::Size(30, 40), true);
1157 TestDiff(one_border
, gfx::Rect(0, 0, 30, 40), gfx::Rect(), 1);
1158 TestDiff(one_border
, gfx::Rect(5, 5, 100, 100), gfx::Rect(5, 5, 1, 1), 0);
1160 TilingData
big_border(gfx::Size(1000, 1000), gfx::Size(30, 40), 50);
1161 TestDiff(big_border
, gfx::Rect(0, 0, 30, 40), gfx::Rect(), 1);
1162 TestDiff(big_border
, gfx::Rect(5, 5, 100, 100), gfx::Rect(5, 5, 1, 1), 0);
1165 TEST(TilingDataTest
, DifferenceIteratorNoTiles
) {
1166 TilingData
data(gfx::Size(100, 100), gfx::Size(), false);
1167 TestDiff(data
, gfx::Rect(0, 0, 100, 100), gfx::Rect(0, 0, 5, 5), 0);