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.
4
5#include "cc/base/tiling_data.h"
6
7#include <algorithm>
8#include <vector>
9
10#include "cc/test/geometry_test_utils.h"
11#include "testing/gtest/include/gtest/gtest.h"
12
13namespace cc {
14namespace {
15
16int NumTiles(const gfx::Size& max_texture_size,
17             const gfx::Size& tiling_size,
18             bool has_border_texels) {
19  TilingData tiling(max_texture_size, tiling_size, has_border_texels);
20  int num_tiles = tiling.num_tiles_x() * tiling.num_tiles_y();
21
22  // Assert no overflow.
23  EXPECT_GE(num_tiles, 0);
24  if (num_tiles > 0)
25    EXPECT_EQ(num_tiles / tiling.num_tiles_x(), tiling.num_tiles_y());
26
27  return num_tiles;
28}
29
30int XIndex(const gfx::Size& max_texture_size,
31           const gfx::Size& tiling_size,
32           bool has_border_texels,
33           int x_coord) {
34  TilingData tiling(max_texture_size, tiling_size, has_border_texels);
35  return tiling.TileXIndexFromSrcCoord(x_coord);
36}
37
38int YIndex(const gfx::Size& max_texture_size,
39           const gfx::Size& tiling_size,
40           bool has_border_texels,
41           int y_coord) {
42  TilingData tiling(max_texture_size, tiling_size, has_border_texels);
43  return tiling.TileYIndexFromSrcCoord(y_coord);
44}
45
46int MinBorderXIndex(const gfx::Size& max_texture_size,
47                    const gfx::Size& tiling_size,
48                    bool has_border_texels,
49                    int x_coord) {
50  TilingData tiling(max_texture_size, tiling_size, has_border_texels);
51  return tiling.FirstBorderTileXIndexFromSrcCoord(x_coord);
52}
53
54int MinBorderYIndex(const gfx::Size& max_texture_size,
55                    const gfx::Size& tiling_size,
56                    bool has_border_texels,
57                    int y_coord) {
58  TilingData tiling(max_texture_size, tiling_size, has_border_texels);
59  return tiling.FirstBorderTileYIndexFromSrcCoord(y_coord);
60}
61
62int MaxBorderXIndex(const gfx::Size& max_texture_size,
63                    const gfx::Size& tiling_size,
64                    bool has_border_texels,
65                    int x_coord) {
66  TilingData tiling(max_texture_size, tiling_size, has_border_texels);
67  return tiling.LastBorderTileXIndexFromSrcCoord(x_coord);
68}
69
70int MaxBorderYIndex(const gfx::Size& max_texture_size,
71                    const gfx::Size& tiling_size,
72                    bool has_border_texels,
73                    int y_coord) {
74  TilingData tiling(max_texture_size, tiling_size, has_border_texels);
75  return tiling.LastBorderTileYIndexFromSrcCoord(y_coord);
76}
77
78int PosX(const gfx::Size& max_texture_size,
79         const gfx::Size& tiling_size,
80         bool has_border_texels,
81         int x_index) {
82  TilingData tiling(max_texture_size, tiling_size, has_border_texels);
83  return tiling.TilePositionX(x_index);
84}
85
86int PosY(const gfx::Size& max_texture_size,
87         const gfx::Size& tiling_size,
88         bool has_border_texels,
89         int y_index) {
90  TilingData tiling(max_texture_size, tiling_size, has_border_texels);
91  return tiling.TilePositionY(y_index);
92}
93
94int SizeX(const gfx::Size& max_texture_size,
95          const gfx::Size& tiling_size,
96          bool has_border_texels,
97          int x_index) {
98  TilingData tiling(max_texture_size, tiling_size, has_border_texels);
99  return tiling.TileSizeX(x_index);
100}
101
102int SizeY(const gfx::Size& max_texture_size,
103          const gfx::Size& tiling_size,
104          bool has_border_texels,
105          int y_index) {
106  TilingData tiling(max_texture_size, tiling_size, has_border_texels);
107  return tiling.TileSizeY(y_index);
108}
109
110class TilingDataTest : public ::testing::TestWithParam<gfx::Point> {};
111
112TEST(TilingDataTest, NumTiles_NoTiling) {
113  EXPECT_EQ(1, NumTiles(gfx::Size(16, 16), gfx::Size(16, 16), false));
114  EXPECT_EQ(1, NumTiles(gfx::Size(16, 16), gfx::Size(15, 15), true));
115  EXPECT_EQ(1, NumTiles(gfx::Size(16, 16), gfx::Size(16, 16), true));
116  EXPECT_EQ(1, NumTiles(gfx::Size(16, 16), gfx::Size(1, 16), false));
117  EXPECT_EQ(1, NumTiles(gfx::Size(15, 15), gfx::Size(15, 15), true));
118  EXPECT_EQ(1, NumTiles(gfx::Size(32, 16), gfx::Size(32, 16), false));
119  EXPECT_EQ(1, NumTiles(gfx::Size(32, 16), gfx::Size(32, 16), true));
120}
121
122TEST(TilingDataTest, NumTiles_TilingNoBorders) {
123  EXPECT_EQ(0, NumTiles(gfx::Size(0, 0), gfx::Size(0, 0), false));
124  EXPECT_EQ(0, NumTiles(gfx::Size(0, 0), gfx::Size(4, 0), false));
125  EXPECT_EQ(0, NumTiles(gfx::Size(0, 0), gfx::Size(0, 4), false));
126  EXPECT_EQ(0, NumTiles(gfx::Size(4, 4), gfx::Size(4, 0), false));
127  EXPECT_EQ(0, NumTiles(gfx::Size(4, 4), gfx::Size(0, 4), false));
128  EXPECT_EQ(0, NumTiles(gfx::Size(0, 0), gfx::Size(1, 1), false));
129
130  EXPECT_EQ(1, NumTiles(gfx::Size(1, 1), gfx::Size(1, 1), false));
131  EXPECT_EQ(2, NumTiles(gfx::Size(1, 1), gfx::Size(1, 2), false));
132  EXPECT_EQ(2, NumTiles(gfx::Size(1, 1), gfx::Size(2, 1), false));
133  EXPECT_EQ(1, NumTiles(gfx::Size(2, 2), gfx::Size(1, 1), false));
134  EXPECT_EQ(1, NumTiles(gfx::Size(2, 2), gfx::Size(1, 2), false));
135  EXPECT_EQ(1, NumTiles(gfx::Size(2, 2), gfx::Size(2, 1), false));
136  EXPECT_EQ(1, NumTiles(gfx::Size(2, 2), gfx::Size(2, 2), false));
137  EXPECT_EQ(1, NumTiles(gfx::Size(3, 3), gfx::Size(3, 3), false));
138
139  EXPECT_EQ(1, NumTiles(gfx::Size(4, 4), gfx::Size(1, 4), false));
140  EXPECT_EQ(1, NumTiles(gfx::Size(4, 4), gfx::Size(2, 4), false));
141  EXPECT_EQ(1, NumTiles(gfx::Size(4, 4), gfx::Size(3, 4), false));
142  EXPECT_EQ(1, NumTiles(gfx::Size(4, 4), gfx::Size(4, 4), false));
143  EXPECT_EQ(2, NumTiles(gfx::Size(4, 4), gfx::Size(5, 4), false));
144  EXPECT_EQ(2, NumTiles(gfx::Size(4, 4), gfx::Size(6, 4), false));
145  EXPECT_EQ(2, NumTiles(gfx::Size(4, 4), gfx::Size(7, 4), false));
146  EXPECT_EQ(2, NumTiles(gfx::Size(4, 4), gfx::Size(8, 4), false));
147  EXPECT_EQ(3, NumTiles(gfx::Size(4, 4), gfx::Size(9, 4), false));
148  EXPECT_EQ(3, NumTiles(gfx::Size(4, 4), gfx::Size(10, 4), false));
149  EXPECT_EQ(3, NumTiles(gfx::Size(4, 4), gfx::Size(11, 4), false));
150
151  EXPECT_EQ(1, NumTiles(gfx::Size(5, 5), gfx::Size(1, 5), false));
152  EXPECT_EQ(1, NumTiles(gfx::Size(5, 5), gfx::Size(2, 5), false));
153  EXPECT_EQ(1, NumTiles(gfx::Size(5, 5), gfx::Size(3, 5), false));
154  EXPECT_EQ(1, NumTiles(gfx::Size(5, 5), gfx::Size(4, 5), false));
155  EXPECT_EQ(1, NumTiles(gfx::Size(5, 5), gfx::Size(5, 5), false));
156  EXPECT_EQ(2, NumTiles(gfx::Size(5, 5), gfx::Size(6, 5), false));
157  EXPECT_EQ(2, NumTiles(gfx::Size(5, 5), gfx::Size(7, 5), false));
158  EXPECT_EQ(2, NumTiles(gfx::Size(5, 5), gfx::Size(8, 5), false));
159  EXPECT_EQ(2, NumTiles(gfx::Size(5, 5), gfx::Size(9, 5), false));
160  EXPECT_EQ(2, NumTiles(gfx::Size(5, 5), gfx::Size(10, 5), false));
161  EXPECT_EQ(3, NumTiles(gfx::Size(5, 5), gfx::Size(11, 5), false));
162
163  EXPECT_EQ(1, NumTiles(gfx::Size(16, 16), gfx::Size(16, 16), false));
164  EXPECT_EQ(1, NumTiles(gfx::Size(17, 17), gfx::Size(16, 16), false));
165  EXPECT_EQ(4, NumTiles(gfx::Size(15, 15), gfx::Size(16, 16), false));
166  EXPECT_EQ(4, NumTiles(gfx::Size(8, 8), gfx::Size(16, 16), false));
167  EXPECT_EQ(6, NumTiles(gfx::Size(8, 8), gfx::Size(17, 16), false));
168
169  EXPECT_EQ(8, NumTiles(gfx::Size(5, 8), gfx::Size(17, 16), false));
170}
171
172TEST(TilingDataTest, NumTiles_TilingWithBorders) {
173  EXPECT_EQ(0, NumTiles(gfx::Size(0, 0), gfx::Size(0, 0), true));
174  EXPECT_EQ(0, NumTiles(gfx::Size(0, 0), gfx::Size(4, 0), true));
175  EXPECT_EQ(0, NumTiles(gfx::Size(0, 0), gfx::Size(0, 4), true));
176  EXPECT_EQ(0, NumTiles(gfx::Size(4, 4), gfx::Size(4, 0), true));
177  EXPECT_EQ(0, NumTiles(gfx::Size(4, 4), gfx::Size(0, 4), true));
178  EXPECT_EQ(0, NumTiles(gfx::Size(0, 0), gfx::Size(1, 1), true));
179
180  EXPECT_EQ(1, NumTiles(gfx::Size(1, 1), gfx::Size(1, 1), true));
181  EXPECT_EQ(0, NumTiles(gfx::Size(1, 1), gfx::Size(1, 2), true));
182  EXPECT_EQ(0, NumTiles(gfx::Size(1, 1), gfx::Size(2, 1), true));
183  EXPECT_EQ(1, NumTiles(gfx::Size(2, 2), gfx::Size(1, 1), true));
184  EXPECT_EQ(1, NumTiles(gfx::Size(2, 2), gfx::Size(1, 2), true));
185  EXPECT_EQ(1, NumTiles(gfx::Size(2, 2), gfx::Size(2, 1), true));
186  EXPECT_EQ(1, NumTiles(gfx::Size(2, 2), gfx::Size(2, 2), true));
187
188  EXPECT_EQ(1, NumTiles(gfx::Size(3, 3), gfx::Size(1, 3), true));
189  EXPECT_EQ(1, NumTiles(gfx::Size(3, 3), gfx::Size(2, 3), true));
190  EXPECT_EQ(1, NumTiles(gfx::Size(3, 3), gfx::Size(3, 3), true));
191  EXPECT_EQ(2, NumTiles(gfx::Size(3, 3), gfx::Size(4, 3), true));
192  EXPECT_EQ(3, NumTiles(gfx::Size(3, 3), gfx::Size(5, 3), true));
193  EXPECT_EQ(4, NumTiles(gfx::Size(3, 3), gfx::Size(6, 3), true));
194  EXPECT_EQ(5, NumTiles(gfx::Size(3, 3), gfx::Size(7, 3), true));
195
196  EXPECT_EQ(1, NumTiles(gfx::Size(4, 4), gfx::Size(1, 4), true));
197  EXPECT_EQ(1, NumTiles(gfx::Size(4, 4), gfx::Size(2, 4), true));
198  EXPECT_EQ(1, NumTiles(gfx::Size(4, 4), gfx::Size(3, 4), true));
199  EXPECT_EQ(1, NumTiles(gfx::Size(4, 4), gfx::Size(4, 4), true));
200  EXPECT_EQ(2, NumTiles(gfx::Size(4, 4), gfx::Size(5, 4), true));
201  EXPECT_EQ(2, NumTiles(gfx::Size(4, 4), gfx::Size(6, 4), true));
202  EXPECT_EQ(3, NumTiles(gfx::Size(4, 4), gfx::Size(7, 4), true));
203  EXPECT_EQ(3, NumTiles(gfx::Size(4, 4), gfx::Size(8, 4), true));
204  EXPECT_EQ(4, NumTiles(gfx::Size(4, 4), gfx::Size(9, 4), true));
205  EXPECT_EQ(4, NumTiles(gfx::Size(4, 4), gfx::Size(10, 4), true));
206  EXPECT_EQ(5, NumTiles(gfx::Size(4, 4), gfx::Size(11, 4), true));
207
208  EXPECT_EQ(1, NumTiles(gfx::Size(5, 5), gfx::Size(1, 5), true));
209  EXPECT_EQ(1, NumTiles(gfx::Size(5, 5), gfx::Size(2, 5), true));
210  EXPECT_EQ(1, NumTiles(gfx::Size(5, 5), gfx::Size(3, 5), true));
211  EXPECT_EQ(1, NumTiles(gfx::Size(5, 5), gfx::Size(4, 5), true));
212  EXPECT_EQ(1, NumTiles(gfx::Size(5, 5), gfx::Size(5, 5), true));
213  EXPECT_EQ(2, NumTiles(gfx::Size(5, 5), gfx::Size(6, 5), true));
214  EXPECT_EQ(2, NumTiles(gfx::Size(5, 5), gfx::Size(7, 5), true));
215  EXPECT_EQ(2, NumTiles(gfx::Size(5, 5), gfx::Size(8, 5), true));
216  EXPECT_EQ(3, NumTiles(gfx::Size(5, 5), gfx::Size(9, 5), true));
217  EXPECT_EQ(3, NumTiles(gfx::Size(5, 5), gfx::Size(10, 5), true));
218  EXPECT_EQ(3, NumTiles(gfx::Size(5, 5), gfx::Size(11, 5), true));
219
220  EXPECT_EQ(30, NumTiles(gfx::Size(8, 5), gfx::Size(16, 32), true));
221}
222
223TEST(TilingDataTest, TileXIndexFromSrcCoord) {
224  EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 0));
225  EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 1));
226  EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 2));
227  EXPECT_EQ(1, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 3));
228  EXPECT_EQ(1, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 4));
229  EXPECT_EQ(1, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 5));
230  EXPECT_EQ(2, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 6));
231  EXPECT_EQ(2, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 7));
232  EXPECT_EQ(2, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 8));
233  EXPECT_EQ(3, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 9));
234  EXPECT_EQ(3, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 10));
235  EXPECT_EQ(3, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 11));
236
237  EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 0));
238  EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 1));
239  EXPECT_EQ(1, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 2));
240  EXPECT_EQ(2, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 3));
241  EXPECT_EQ(3, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 4));
242  EXPECT_EQ(4, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 5));
243  EXPECT_EQ(5, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 6));
244  EXPECT_EQ(6, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 7));
245  EXPECT_EQ(7, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 8));
246  EXPECT_EQ(7, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 9));
247  EXPECT_EQ(7, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 10));
248  EXPECT_EQ(7, XIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 11));
249
250  EXPECT_EQ(0, XIndex(gfx::Size(1, 1), gfx::Size(1, 1), false, 0));
251  EXPECT_EQ(0, XIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 0));
252  EXPECT_EQ(0, XIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 1));
253  EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 0));
254  EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 1));
255  EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 2));
256
257  EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 0));
258  EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 1));
259  EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 2));
260  EXPECT_EQ(1, XIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 3));
261
262  EXPECT_EQ(0, XIndex(gfx::Size(1, 1), gfx::Size(1, 1), true, 0));
263  EXPECT_EQ(0, XIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 0));
264  EXPECT_EQ(0, XIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 1));
265  EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 0));
266  EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 1));
267  EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 2));
268
269  EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 0));
270  EXPECT_EQ(0, XIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 1));
271  EXPECT_EQ(1, XIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 2));
272  EXPECT_EQ(1, XIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 3));
273}
274
275TEST(TilingDataTest, FirstBorderTileXIndexFromSrcCoord) {
276  EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 0));
277  EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 1));
278  EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 2));
279  EXPECT_EQ(1, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 3));
280  EXPECT_EQ(1, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 4));
281  EXPECT_EQ(1, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 5));
282  EXPECT_EQ(2, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 6));
283  EXPECT_EQ(2, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 7));
284  EXPECT_EQ(2, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 8));
285  EXPECT_EQ(3, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 9));
286  EXPECT_EQ(3, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 10));
287  EXPECT_EQ(3, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 11));
288
289  EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 0));
290  EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 1));
291  EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 2));
292  EXPECT_EQ(1, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 3));
293  EXPECT_EQ(2, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 4));
294  EXPECT_EQ(3, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 5));
295  EXPECT_EQ(4, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 6));
296  EXPECT_EQ(5, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 7));
297  EXPECT_EQ(6, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 8));
298  EXPECT_EQ(7, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 9));
299  EXPECT_EQ(7, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 10));
300  EXPECT_EQ(7, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 11));
301
302  EXPECT_EQ(0, MinBorderXIndex(gfx::Size(1, 1), gfx::Size(1, 1), false, 0));
303  EXPECT_EQ(0, MinBorderXIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 0));
304  EXPECT_EQ(0, MinBorderXIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 1));
305  EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 0));
306  EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 1));
307  EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 2));
308
309  EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 0));
310  EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 1));
311  EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 2));
312  EXPECT_EQ(1, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 3));
313
314  EXPECT_EQ(0, MinBorderXIndex(gfx::Size(1, 1), gfx::Size(1, 1), true, 0));
315  EXPECT_EQ(0, MinBorderXIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 0));
316  EXPECT_EQ(0, MinBorderXIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 1));
317  EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 0));
318  EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 1));
319  EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 2));
320
321  EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 0));
322  EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 1));
323  EXPECT_EQ(0, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 2));
324  EXPECT_EQ(1, MinBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 3));
325}
326
327TEST(TilingDataTest, LastBorderTileXIndexFromSrcCoord) {
328  EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 0));
329  EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 1));
330  EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 2));
331  EXPECT_EQ(1, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 3));
332  EXPECT_EQ(1, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 4));
333  EXPECT_EQ(1, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 5));
334  EXPECT_EQ(2, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 6));
335  EXPECT_EQ(2, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 7));
336  EXPECT_EQ(2, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 8));
337  EXPECT_EQ(3, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 9));
338  EXPECT_EQ(3, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 10));
339  EXPECT_EQ(3, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 11));
340
341  EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 0));
342  EXPECT_EQ(1, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 1));
343  EXPECT_EQ(2, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 2));
344  EXPECT_EQ(3, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 3));
345  EXPECT_EQ(4, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 4));
346  EXPECT_EQ(5, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 5));
347  EXPECT_EQ(6, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 6));
348  EXPECT_EQ(7, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 7));
349  EXPECT_EQ(7, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 8));
350  EXPECT_EQ(7, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 9));
351  EXPECT_EQ(7, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 10));
352  EXPECT_EQ(7, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 11));
353
354  EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(1, 1), gfx::Size(1, 1), false, 0));
355  EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 0));
356  EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 1));
357  EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 0));
358  EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 1));
359  EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 2));
360
361  EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 0));
362  EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 1));
363  EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 2));
364  EXPECT_EQ(1, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), false, 3));
365
366  EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(1, 1), gfx::Size(1, 1), true, 0));
367  EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 0));
368  EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 1));
369  EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 0));
370  EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 1));
371  EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 2));
372
373  EXPECT_EQ(0, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 0));
374  EXPECT_EQ(1, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 1));
375  EXPECT_EQ(1, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 2));
376  EXPECT_EQ(1, MaxBorderXIndex(gfx::Size(3, 3), gfx::Size(4, 3), true, 3));
377}
378
379TEST(TilingDataTest, TileYIndexFromSrcCoord) {
380  EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 0));
381  EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 1));
382  EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 2));
383  EXPECT_EQ(1, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 3));
384  EXPECT_EQ(1, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 4));
385  EXPECT_EQ(1, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 5));
386  EXPECT_EQ(2, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 6));
387  EXPECT_EQ(2, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 7));
388  EXPECT_EQ(2, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 8));
389  EXPECT_EQ(3, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 9));
390  EXPECT_EQ(3, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 10));
391  EXPECT_EQ(3, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 11));
392
393  EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 0));
394  EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 1));
395  EXPECT_EQ(1, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 2));
396  EXPECT_EQ(2, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 3));
397  EXPECT_EQ(3, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 4));
398  EXPECT_EQ(4, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 5));
399  EXPECT_EQ(5, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 6));
400  EXPECT_EQ(6, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 7));
401  EXPECT_EQ(7, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 8));
402  EXPECT_EQ(7, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 9));
403  EXPECT_EQ(7, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 10));
404  EXPECT_EQ(7, YIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 11));
405
406  EXPECT_EQ(0, YIndex(gfx::Size(1, 1), gfx::Size(1, 1), false, 0));
407  EXPECT_EQ(0, YIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 0));
408  EXPECT_EQ(0, YIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 1));
409  EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 0));
410  EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 1));
411  EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 2));
412
413  EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 0));
414  EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 1));
415  EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 2));
416  EXPECT_EQ(1, YIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 3));
417
418  EXPECT_EQ(0, YIndex(gfx::Size(1, 1), gfx::Size(1, 1), true, 0));
419  EXPECT_EQ(0, YIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 0));
420  EXPECT_EQ(0, YIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 1));
421  EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 0));
422  EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 1));
423  EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 2));
424
425  EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 0));
426  EXPECT_EQ(0, YIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 1));
427  EXPECT_EQ(1, YIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 2));
428  EXPECT_EQ(1, YIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 3));
429}
430
431TEST(TilingDataTest, FirstBorderTileYIndexFromSrcCoord) {
432  EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 0));
433  EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 1));
434  EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 2));
435  EXPECT_EQ(1, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 3));
436  EXPECT_EQ(1, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 4));
437  EXPECT_EQ(1, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 5));
438  EXPECT_EQ(2, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 6));
439  EXPECT_EQ(2, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 7));
440  EXPECT_EQ(2, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 8));
441  EXPECT_EQ(3, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 9));
442  EXPECT_EQ(3, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 10));
443  EXPECT_EQ(3, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 11));
444
445  EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 0));
446  EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 1));
447  EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 2));
448  EXPECT_EQ(1, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 3));
449  EXPECT_EQ(2, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 4));
450  EXPECT_EQ(3, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 5));
451  EXPECT_EQ(4, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 6));
452  EXPECT_EQ(5, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 7));
453  EXPECT_EQ(6, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 8));
454  EXPECT_EQ(7, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 9));
455  EXPECT_EQ(7, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 10));
456  EXPECT_EQ(7, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 11));
457
458  EXPECT_EQ(0, MinBorderYIndex(gfx::Size(1, 1), gfx::Size(1, 1), false, 0));
459  EXPECT_EQ(0, MinBorderYIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 0));
460  EXPECT_EQ(0, MinBorderYIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 1));
461  EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 0));
462  EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 1));
463  EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 2));
464
465  EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 0));
466  EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 1));
467  EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 2));
468  EXPECT_EQ(1, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 3));
469
470  EXPECT_EQ(0, MinBorderYIndex(gfx::Size(1, 1), gfx::Size(1, 1), true, 0));
471  EXPECT_EQ(0, MinBorderYIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 0));
472  EXPECT_EQ(0, MinBorderYIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 1));
473  EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 0));
474  EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 1));
475  EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 2));
476
477  EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 0));
478  EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 1));
479  EXPECT_EQ(0, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 2));
480  EXPECT_EQ(1, MinBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 3));
481}
482
483TEST(TilingDataTest, LastBorderTileYIndexFromSrcCoord) {
484  EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 0));
485  EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 1));
486  EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 2));
487  EXPECT_EQ(1, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 3));
488  EXPECT_EQ(1, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 4));
489  EXPECT_EQ(1, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 5));
490  EXPECT_EQ(2, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 6));
491  EXPECT_EQ(2, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 7));
492  EXPECT_EQ(2, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 8));
493  EXPECT_EQ(3, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 9));
494  EXPECT_EQ(3, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 10));
495  EXPECT_EQ(3, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), false, 11));
496
497  EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 0));
498  EXPECT_EQ(1, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 1));
499  EXPECT_EQ(2, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 2));
500  EXPECT_EQ(3, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 3));
501  EXPECT_EQ(4, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 4));
502  EXPECT_EQ(5, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 5));
503  EXPECT_EQ(6, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 6));
504  EXPECT_EQ(7, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 7));
505  EXPECT_EQ(7, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 8));
506  EXPECT_EQ(7, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 9));
507  EXPECT_EQ(7, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 10));
508  EXPECT_EQ(7, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(10, 10), true, 11));
509
510  EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(1, 1), gfx::Size(1, 1), false, 0));
511  EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 0));
512  EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(2, 2), gfx::Size(2, 2), false, 1));
513  EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 0));
514  EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 1));
515  EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), false, 2));
516
517  EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 0));
518  EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 1));
519  EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 2));
520  EXPECT_EQ(1, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), false, 3));
521
522  EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(1, 1), gfx::Size(1, 1), true, 0));
523  EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 0));
524  EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(2, 2), gfx::Size(2, 2), true, 1));
525  EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 0));
526  EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 1));
527  EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 3), true, 2));
528
529  EXPECT_EQ(0, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 0));
530  EXPECT_EQ(1, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 1));
531  EXPECT_EQ(1, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 2));
532  EXPECT_EQ(1, MaxBorderYIndex(gfx::Size(3, 3), gfx::Size(3, 4), true, 3));
533}
534
535TEST(TilingDataTest, TileSizeX) {
536  EXPECT_EQ(5, SizeX(gfx::Size(5, 5), gfx::Size(5, 5), false, 0));
537  EXPECT_EQ(5, SizeX(gfx::Size(5, 5), gfx::Size(5, 5), true, 0));
538
539  EXPECT_EQ(5, SizeX(gfx::Size(5, 5), gfx::Size(6, 6), false, 0));
540  EXPECT_EQ(1, SizeX(gfx::Size(5, 5), gfx::Size(6, 6), false, 1));
541  EXPECT_EQ(4, SizeX(gfx::Size(5, 5), gfx::Size(6, 6), true, 0));
542  EXPECT_EQ(2, SizeX(gfx::Size(5, 5), gfx::Size(6, 6), true, 1));
543
544  EXPECT_EQ(5, SizeX(gfx::Size(5, 5), gfx::Size(8, 8), false, 0));
545  EXPECT_EQ(3, SizeX(gfx::Size(5, 5), gfx::Size(8, 8), false, 1));
546  EXPECT_EQ(4, SizeX(gfx::Size(5, 5), gfx::Size(8, 8), true, 0));
547  EXPECT_EQ(4, SizeX(gfx::Size(5, 5), gfx::Size(8, 8), true, 1));
548
549  EXPECT_EQ(5, SizeX(gfx::Size(5, 5), gfx::Size(10, 10), false, 0));
550  EXPECT_EQ(5, SizeX(gfx::Size(5, 5), gfx::Size(10, 10), false, 1));
551  EXPECT_EQ(4, SizeX(gfx::Size(5, 5), gfx::Size(10, 10), true, 0));
552  EXPECT_EQ(3, SizeX(gfx::Size(5, 5), gfx::Size(10, 10), true, 1));
553  EXPECT_EQ(3, SizeX(gfx::Size(5, 5), gfx::Size(10, 10), true, 2));
554
555  EXPECT_EQ(4, SizeX(gfx::Size(5, 5), gfx::Size(11, 11), true, 2));
556  EXPECT_EQ(3, SizeX(gfx::Size(5, 5), gfx::Size(12, 12), true, 2));
557
558  EXPECT_EQ(3, SizeX(gfx::Size(5, 9), gfx::Size(12, 17), true, 2));
559}
560
561TEST(TilingDataTest, TileSizeY) {
562  EXPECT_EQ(5, SizeY(gfx::Size(5, 5), gfx::Size(5, 5), false, 0));
563  EXPECT_EQ(5, SizeY(gfx::Size(5, 5), gfx::Size(5, 5), true, 0));
564
565  EXPECT_EQ(5, SizeY(gfx::Size(5, 5), gfx::Size(6, 6), false, 0));
566  EXPECT_EQ(1, SizeY(gfx::Size(5, 5), gfx::Size(6, 6), false, 1));
567  EXPECT_EQ(4, SizeY(gfx::Size(5, 5), gfx::Size(6, 6), true, 0));
568  EXPECT_EQ(2, SizeY(gfx::Size(5, 5), gfx::Size(6, 6), true, 1));
569
570  EXPECT_EQ(5, SizeY(gfx::Size(5, 5), gfx::Size(8, 8), false, 0));
571  EXPECT_EQ(3, SizeY(gfx::Size(5, 5), gfx::Size(8, 8), false, 1));
572  EXPECT_EQ(4, SizeY(gfx::Size(5, 5), gfx::Size(8, 8), true, 0));
573  EXPECT_EQ(4, SizeY(gfx::Size(5, 5), gfx::Size(8, 8), true, 1));
574
575  EXPECT_EQ(5, SizeY(gfx::Size(5, 5), gfx::Size(10, 10), false, 0));
576  EXPECT_EQ(5, SizeY(gfx::Size(5, 5), gfx::Size(10, 10), false, 1));
577  EXPECT_EQ(4, SizeY(gfx::Size(5, 5), gfx::Size(10, 10), true, 0));
578  EXPECT_EQ(3, SizeY(gfx::Size(5, 5), gfx::Size(10, 10), true, 1));
579  EXPECT_EQ(3, SizeY(gfx::Size(5, 5), gfx::Size(10, 10), true, 2));
580
581  EXPECT_EQ(4, SizeY(gfx::Size(5, 5), gfx::Size(11, 11), true, 2));
582  EXPECT_EQ(3, SizeY(gfx::Size(5, 5), gfx::Size(12, 12), true, 2));
583
584  EXPECT_EQ(3, SizeY(gfx::Size(9, 5), gfx::Size(17, 12), true, 2));
585}
586
587TEST(TilingDataTest, TileSizeX_and_TilePositionX) {
588  // Single tile cases:
589  EXPECT_EQ(1, SizeX(gfx::Size(3, 3), gfx::Size(1, 1), false, 0));
590  EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(1, 1), false, 0));
591  EXPECT_EQ(1, SizeX(gfx::Size(3, 3), gfx::Size(1, 100), false, 0));
592  EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(1, 100), false, 0));
593  EXPECT_EQ(3, SizeX(gfx::Size(3, 3), gfx::Size(3, 1), false, 0));
594  EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(3, 1), false, 0));
595  EXPECT_EQ(3, SizeX(gfx::Size(3, 3), gfx::Size(3, 100), false, 0));
596  EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(3, 100), false, 0));
597  EXPECT_EQ(1, SizeX(gfx::Size(3, 3), gfx::Size(1, 1), true, 0));
598  EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(1, 1), true, 0));
599  EXPECT_EQ(1, SizeX(gfx::Size(3, 3), gfx::Size(1, 100), true, 0));
600  EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(1, 100), true, 0));
601  EXPECT_EQ(3, SizeX(gfx::Size(3, 3), gfx::Size(3, 1), true, 0));
602  EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(3, 1), true, 0));
603  EXPECT_EQ(3, SizeX(gfx::Size(3, 3), gfx::Size(3, 100), true, 0));
604  EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(3, 100), true, 0));
605
606  // Multiple tiles:
607  // no border
608  // positions 0, 3
609  EXPECT_EQ(2, NumTiles(gfx::Size(3, 3), gfx::Size(6, 1), false));
610  EXPECT_EQ(3, SizeX(gfx::Size(3, 3), gfx::Size(6, 1), false, 0));
611  EXPECT_EQ(3, SizeX(gfx::Size(3, 3), gfx::Size(6, 1), false, 1));
612  EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(6, 1), false, 0));
613  EXPECT_EQ(3, PosX(gfx::Size(3, 3), gfx::Size(6, 1), false, 1));
614  EXPECT_EQ(3, SizeX(gfx::Size(3, 3), gfx::Size(6, 100), false, 0));
615  EXPECT_EQ(3, SizeX(gfx::Size(3, 3), gfx::Size(6, 100), false, 1));
616  EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(6, 100), false, 0));
617  EXPECT_EQ(3, PosX(gfx::Size(3, 3), gfx::Size(6, 100), false, 1));
618
619  // Multiple tiles:
620  // with border
621  // positions 0, 2, 3, 4
622  EXPECT_EQ(4, NumTiles(gfx::Size(3, 3), gfx::Size(6, 1), true));
623  EXPECT_EQ(2, SizeX(gfx::Size(3, 3), gfx::Size(6, 1), true, 0));
624  EXPECT_EQ(1, SizeX(gfx::Size(3, 3), gfx::Size(6, 1), true, 1));
625  EXPECT_EQ(1, SizeX(gfx::Size(3, 3), gfx::Size(6, 1), true, 2));
626  EXPECT_EQ(2, SizeX(gfx::Size(3, 3), gfx::Size(6, 1), true, 3));
627  EXPECT_EQ(0, PosX(gfx::Size(3, 3), gfx::Size(6, 1), true, 0));
628  EXPECT_EQ(2, PosX(gfx::Size(3, 3), gfx::Size(6, 1), true, 1));
629  EXPECT_EQ(3, PosX(gfx::Size(3, 3), gfx::Size(6, 1), true, 2));
630  EXPECT_EQ(4, PosX(gfx::Size(3, 3), gfx::Size(6, 1), true, 3));
631  EXPECT_EQ(2, SizeX(gfx::Size(3, 7), gfx::Size(6, 100), true, 0));
632  EXPECT_EQ(1, SizeX(gfx::Size(3, 7), gfx::Size(6, 100), true, 1));
633  EXPECT_EQ(1, SizeX(gfx::Size(3, 7), gfx::Size(6, 100), true, 2));
634  EXPECT_EQ(2, SizeX(gfx::Size(3, 7), gfx::Size(6, 100), true, 3));
635  EXPECT_EQ(0, PosX(gfx::Size(3, 7), gfx::Size(6, 100), true, 0));
636  EXPECT_EQ(2, PosX(gfx::Size(3, 7), gfx::Size(6, 100), true, 1));
637  EXPECT_EQ(3, PosX(gfx::Size(3, 7), gfx::Size(6, 100), true, 2));
638  EXPECT_EQ(4, PosX(gfx::Size(3, 7), gfx::Size(6, 100), true, 3));
639}
640
641TEST(TilingDataTest, TileSizeY_and_TilePositionY) {
642  // Single tile cases:
643  EXPECT_EQ(1, SizeY(gfx::Size(3, 3), gfx::Size(1, 1), false, 0));
644  EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(1, 1), false, 0));
645  EXPECT_EQ(1, SizeY(gfx::Size(3, 3), gfx::Size(100, 1), false, 0));
646  EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(100, 1), false, 0));
647  EXPECT_EQ(3, SizeY(gfx::Size(3, 3), gfx::Size(1, 3), false, 0));
648  EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(1, 3), false, 0));
649  EXPECT_EQ(3, SizeY(gfx::Size(3, 3), gfx::Size(100, 3), false, 0));
650  EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(100, 3), false, 0));
651  EXPECT_EQ(1, SizeY(gfx::Size(3, 3), gfx::Size(1, 1), true, 0));
652  EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(1, 1), true, 0));
653  EXPECT_EQ(1, SizeY(gfx::Size(3, 3), gfx::Size(100, 1), true, 0));
654  EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(100, 1), true, 0));
655  EXPECT_EQ(3, SizeY(gfx::Size(3, 3), gfx::Size(1, 3), true, 0));
656  EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(1, 3), true, 0));
657  EXPECT_EQ(3, SizeY(gfx::Size(3, 3), gfx::Size(100, 3), true, 0));
658  EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(100, 3), true, 0));
659
660  // Multiple tiles:
661  // no border
662  // positions 0, 3
663  EXPECT_EQ(2, NumTiles(gfx::Size(3, 3), gfx::Size(1, 6), false));
664  EXPECT_EQ(3, SizeY(gfx::Size(3, 3), gfx::Size(1, 6), false, 0));
665  EXPECT_EQ(3, SizeY(gfx::Size(3, 3), gfx::Size(1, 6), false, 1));
666  EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(1, 6), false, 0));
667  EXPECT_EQ(3, PosY(gfx::Size(3, 3), gfx::Size(1, 6), false, 1));
668  EXPECT_EQ(3, SizeY(gfx::Size(3, 3), gfx::Size(100, 6), false, 0));
669  EXPECT_EQ(3, SizeY(gfx::Size(3, 3), gfx::Size(100, 6), false, 1));
670  EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(100, 6), false, 0));
671  EXPECT_EQ(3, PosY(gfx::Size(3, 3), gfx::Size(100, 6), false, 1));
672
673  // Multiple tiles:
674  // with border
675  // positions 0, 2, 3, 4
676  EXPECT_EQ(4, NumTiles(gfx::Size(3, 3), gfx::Size(1, 6), true));
677  EXPECT_EQ(2, SizeY(gfx::Size(3, 3), gfx::Size(1, 6), true, 0));
678  EXPECT_EQ(1, SizeY(gfx::Size(3, 3), gfx::Size(1, 6), true, 1));
679  EXPECT_EQ(1, SizeY(gfx::Size(3, 3), gfx::Size(1, 6), true, 2));
680  EXPECT_EQ(2, SizeY(gfx::Size(3, 3), gfx::Size(1, 6), true, 3));
681  EXPECT_EQ(0, PosY(gfx::Size(3, 3), gfx::Size(1, 6), true, 0));
682  EXPECT_EQ(2, PosY(gfx::Size(3, 3), gfx::Size(1, 6), true, 1));
683  EXPECT_EQ(3, PosY(gfx::Size(3, 3), gfx::Size(1, 6), true, 2));
684  EXPECT_EQ(4, PosY(gfx::Size(3, 3), gfx::Size(1, 6), true, 3));
685  EXPECT_EQ(2, SizeY(gfx::Size(7, 3), gfx::Size(100, 6), true, 0));
686  EXPECT_EQ(1, SizeY(gfx::Size(7, 3), gfx::Size(100, 6), true, 1));
687  EXPECT_EQ(1, SizeY(gfx::Size(7, 3), gfx::Size(100, 6), true, 2));
688  EXPECT_EQ(2, SizeY(gfx::Size(7, 3), gfx::Size(100, 6), true, 3));
689  EXPECT_EQ(0, PosY(gfx::Size(7, 3), gfx::Size(100, 6), true, 0));
690  EXPECT_EQ(2, PosY(gfx::Size(7, 3), gfx::Size(100, 6), true, 1));
691  EXPECT_EQ(3, PosY(gfx::Size(7, 3), gfx::Size(100, 6), true, 2));
692  EXPECT_EQ(4, PosY(gfx::Size(7, 3), gfx::Size(100, 6), true, 3));
693}
694
695TEST(TilingDataTest, SetTotalSize) {
696  TilingData data(gfx::Size(5, 5), gfx::Size(5, 5), false);
697  EXPECT_EQ(5, data.tiling_size().width());
698  EXPECT_EQ(5, data.tiling_size().height());
699  EXPECT_EQ(1, data.num_tiles_x());
700  EXPECT_EQ(5, data.TileSizeX(0));
701  EXPECT_EQ(1, data.num_tiles_y());
702  EXPECT_EQ(5, data.TileSizeY(0));
703
704  data.SetTilingSize(gfx::Size(6, 5));
705  EXPECT_EQ(6, data.tiling_size().width());
706  EXPECT_EQ(5, data.tiling_size().height());
707  EXPECT_EQ(2, data.num_tiles_x());
708  EXPECT_EQ(5, data.TileSizeX(0));
709  EXPECT_EQ(1, data.TileSizeX(1));
710  EXPECT_EQ(1, data.num_tiles_y());
711  EXPECT_EQ(5, data.TileSizeY(0));
712
713  data.SetTilingSize(gfx::Size(5, 12));
714  EXPECT_EQ(5, data.tiling_size().width());
715  EXPECT_EQ(12, data.tiling_size().height());
716  EXPECT_EQ(1, data.num_tiles_x());
717  EXPECT_EQ(5, data.TileSizeX(0));
718  EXPECT_EQ(3, data.num_tiles_y());
719  EXPECT_EQ(5, data.TileSizeY(0));
720  EXPECT_EQ(5, data.TileSizeY(1));
721  EXPECT_EQ(2, data.TileSizeY(2));
722}
723
724TEST(TilingDataTest, SetMaxTextureSizeNoBorders) {
725  TilingData data(gfx::Size(8, 8), gfx::Size(16, 32), false);
726  EXPECT_EQ(2, data.num_tiles_x());
727  EXPECT_EQ(4, data.num_tiles_y());
728
729  data.SetMaxTextureSize(gfx::Size(32, 32));
730  EXPECT_EQ(gfx::Size(32, 32), data.max_texture_size());
731  EXPECT_EQ(1, data.num_tiles_x());
732  EXPECT_EQ(1, data.num_tiles_y());
733
734  data.SetMaxTextureSize(gfx::Size(2, 2));
735  EXPECT_EQ(gfx::Size(2, 2), data.max_texture_size());
736  EXPECT_EQ(8, data.num_tiles_x());
737  EXPECT_EQ(16, data.num_tiles_y());
738
739  data.SetMaxTextureSize(gfx::Size(5, 5));
740  EXPECT_EQ(gfx::Size(5, 5), data.max_texture_size());
741  EXPECT_EQ(4, data.num_tiles_x());
742  EXPECT_EQ(7, data.num_tiles_y());
743
744  data.SetMaxTextureSize(gfx::Size(8, 5));
745  EXPECT_EQ(gfx::Size(8, 5), data.max_texture_size());
746  EXPECT_EQ(2, data.num_tiles_x());
747  EXPECT_EQ(7, data.num_tiles_y());
748}
749
750TEST(TilingDataTest, SetMaxTextureSizeBorders) {
751  TilingData data(gfx::Size(8, 8), gfx::Size(16, 32), true);
752  EXPECT_EQ(3, data.num_tiles_x());
753  EXPECT_EQ(5, data.num_tiles_y());
754
755  data.SetMaxTextureSize(gfx::Size(32, 32));
756  EXPECT_EQ(gfx::Size(32, 32), data.max_texture_size());
757  EXPECT_EQ(1, data.num_tiles_x());
758  EXPECT_EQ(1, data.num_tiles_y());
759
760  data.SetMaxTextureSize(gfx::Size(2, 2));
761  EXPECT_EQ(gfx::Size(2, 2), data.max_texture_size());
762  EXPECT_EQ(0, data.num_tiles_x());
763  EXPECT_EQ(0, data.num_tiles_y());
764
765  data.SetMaxTextureSize(gfx::Size(5, 5));
766  EXPECT_EQ(gfx::Size(5, 5), data.max_texture_size());
767  EXPECT_EQ(5, data.num_tiles_x());
768  EXPECT_EQ(10, data.num_tiles_y());
769
770  data.SetMaxTextureSize(gfx::Size(8, 5));
771  EXPECT_EQ(gfx::Size(8, 5), data.max_texture_size());
772  EXPECT_EQ(3, data.num_tiles_x());
773  EXPECT_EQ(10, data.num_tiles_y());
774}
775
776TEST(TilingDataTest, ExpandRectIgnoringBordersToTileBoundsEmpty) {
777  TilingData empty_total_size(gfx::Size(0, 0), gfx::Size(8, 8), true);
778  EXPECT_RECT_EQ(
779      gfx::Rect(),
780      empty_total_size.ExpandRectIgnoringBordersToTileBounds(gfx::Rect()));
781  EXPECT_RECT_EQ(gfx::Rect(),
782                 empty_total_size.ExpandRectIgnoringBordersToTileBounds(
783                     gfx::Rect(100, 100, 100, 100)));
784  EXPECT_RECT_EQ(gfx::Rect(),
785                 empty_total_size.ExpandRectIgnoringBordersToTileBounds(
786                     gfx::Rect(100, 100)));
787
788  TilingData empty_max_texture_size(gfx::Size(8, 8), gfx::Size(0, 0), true);
789  EXPECT_RECT_EQ(gfx::Rect(),
790                 empty_max_texture_size.ExpandRectIgnoringBordersToTileBounds(
791                     gfx::Rect()));
792  EXPECT_RECT_EQ(gfx::Rect(),
793                 empty_max_texture_size.ExpandRectIgnoringBordersToTileBounds(
794                     gfx::Rect(100, 100, 100, 100)));
795  EXPECT_RECT_EQ(gfx::Rect(),
796                 empty_max_texture_size.ExpandRectIgnoringBordersToTileBounds(
797                     gfx::Rect(100, 100)));
798}
799
800TEST(TilingDataTest, ExpandRectIgnoringBordersToTileBounds) {
801  TilingData data(gfx::Size(4, 4), gfx::Size(16, 32), true);
802
803  // Small rect at origin rounds up to tile 0, 0.
804  gfx::Rect at_origin_src(1, 1);
805  gfx::Rect at_origin_result(data.TileBounds(0, 0));
806  EXPECT_NE(at_origin_src, at_origin_result);
807  EXPECT_RECT_EQ(at_origin_result,
808                 data.ExpandRectIgnoringBordersToTileBounds(at_origin_src));
809
810  // Arbitrary internal rect.
811  gfx::Rect rect_src(6, 6, 1, 3);
812  // Tile 2, 2 => gfx::Rect(4, 4, 4, 4)
813  // Tile 2, 3 => gfx::Rect(4, 6, 4, 4)
814  gfx::Rect rect_result(
815      gfx::UnionRects(data.TileBounds(2, 2), data.TileBounds(2, 3)));
816  EXPECT_NE(rect_src, rect_result);
817  EXPECT_RECT_EQ(rect_result,
818                 data.ExpandRectIgnoringBordersToTileBounds(rect_src));
819
820  // On tile bounds does not round up to next tile (ignores the border).
821  gfx::Rect border_rect_src(
822      gfx::UnionRects(data.TileBounds(1, 2), data.TileBounds(3, 4)));
823  gfx::Rect border_rect_result(
824      gfx::UnionRects(data.TileBounds(1, 2), data.TileBounds(3, 4)));
825  EXPECT_RECT_EQ(border_rect_result,
826                 data.ExpandRectIgnoringBordersToTileBounds(border_rect_src));
827
828  // Equal to tiling rect.
829  EXPECT_RECT_EQ(gfx::Rect(data.tiling_size()),
830                 data.ExpandRectIgnoringBordersToTileBounds(
831                     gfx::Rect(data.tiling_size())));
832
833  // Containing, but larger than tiling rect.
834  EXPECT_RECT_EQ(
835      gfx::Rect(data.tiling_size()),
836      data.ExpandRectIgnoringBordersToTileBounds(gfx::Rect(100, 100)));
837
838  // Non-intersecting with tiling rect.
839  gfx::Rect non_intersect(200, 200, 100, 100);
840  EXPECT_FALSE(non_intersect.Intersects(gfx::Rect(data.tiling_size())));
841  EXPECT_RECT_EQ(gfx::Rect(),
842                 data.ExpandRectIgnoringBordersToTileBounds(non_intersect));
843
844  TilingData data2(gfx::Size(8, 8), gfx::Size(32, 64), true);
845
846  // Inside other tile border texels doesn't include other tiles.
847  gfx::Rect inner_rect_src(data2.TileBounds(1, 1));
848  inner_rect_src.Inset(data2.border_texels(), data.border_texels());
849  gfx::Rect inner_rect_result(data2.TileBounds(1, 1));
850  gfx::Rect expanded =
851      data2.ExpandRectIgnoringBordersToTileBounds(inner_rect_src);
852  EXPECT_EQ(inner_rect_result.ToString(), expanded.ToString());
853}
854
855TEST(TilingDataTest, ExpandRectToTileBounds) {
856  TilingData data(gfx::Size(4, 4), gfx::Size(16, 32), true);
857
858  // Small rect at origin rounds up to tile 0, 0.
859  gfx::Rect at_origin_src(1, 1);
860  gfx::Rect at_origin_result(data.TileBounds(0, 0));
861  EXPECT_NE(at_origin_src, at_origin_result);
862  EXPECT_RECT_EQ(at_origin_result, data.ExpandRectToTileBounds(at_origin_src));
863
864  // Arbitrary internal rect.
865  gfx::Rect rect_src(6, 6, 1, 3);
866  // Tile 2, 2 => gfx::Rect(4, 4, 4, 4)
867  // Tile 3, 4 => gfx::Rect(6, 8, 4, 4)
868  gfx::Rect rect_result(
869      gfx::UnionRects(data.TileBounds(2, 2), data.TileBounds(3, 4)));
870  EXPECT_NE(rect_src, rect_result);
871  EXPECT_RECT_EQ(rect_result, data.ExpandRectToTileBounds(rect_src));
872
873  // On tile bounds rounds up to next tile (since border overlaps).
874  gfx::Rect border_rect_src(
875      gfx::UnionRects(data.TileBounds(1, 2), data.TileBounds(3, 4)));
876  gfx::Rect border_rect_result(
877      gfx::UnionRects(data.TileBounds(0, 1), data.TileBounds(4, 5)));
878  EXPECT_RECT_EQ(border_rect_result,
879                 data.ExpandRectToTileBounds(border_rect_src));
880
881  // Equal to tiling rect.
882  EXPECT_RECT_EQ(gfx::Rect(data.tiling_size()),
883                 data.ExpandRectToTileBounds(gfx::Rect(data.tiling_size())));
884
885  // Containing, but larger than tiling rect.
886  EXPECT_RECT_EQ(gfx::Rect(data.tiling_size()),
887                 data.ExpandRectToTileBounds(gfx::Rect(100, 100)));
888
889  // Non-intersecting with tiling rect.
890  gfx::Rect non_intersect(200, 200, 100, 100);
891  EXPECT_FALSE(non_intersect.Intersects(gfx::Rect(data.tiling_size())));
892  EXPECT_RECT_EQ(gfx::Rect(), data.ExpandRectToTileBounds(non_intersect));
893
894  TilingData data2(gfx::Size(8, 8), gfx::Size(32, 64), true);
895
896  // Inside other tile border texels doesn't include other tiles.
897  gfx::Rect inner_rect_src(data2.TileBounds(1, 1));
898  inner_rect_src.Inset(data2.border_texels(), data.border_texels());
899  gfx::Rect inner_rect_result(data2.TileBounds(1, 1));
900  gfx::Rect expanded = data2.ExpandRectToTileBounds(inner_rect_src);
901  EXPECT_EQ(inner_rect_result.ToString(), expanded.ToString());
902}
903
904TEST(TilingDataTest, Assignment) {
905  {
906    TilingData source(gfx::Size(8, 8), gfx::Size(16, 32), true);
907    TilingData dest = source;
908    EXPECT_EQ(source.border_texels(), dest.border_texels());
909    EXPECT_EQ(source.max_texture_size(), dest.max_texture_size());
910    EXPECT_EQ(source.num_tiles_x(), dest.num_tiles_x());
911    EXPECT_EQ(source.num_tiles_y(), dest.num_tiles_y());
912    EXPECT_EQ(source.tiling_size(), dest.tiling_size());
913  }
914  {
915    TilingData source(gfx::Size(7, 3), gfx::Size(6, 100), false);
916    TilingData dest(source);
917    EXPECT_EQ(source.border_texels(), dest.border_texels());
918    EXPECT_EQ(source.max_texture_size(), dest.max_texture_size());
919    EXPECT_EQ(source.num_tiles_x(), dest.num_tiles_x());
920    EXPECT_EQ(source.num_tiles_y(), dest.num_tiles_y());
921    EXPECT_EQ(source.tiling_size(), dest.tiling_size());
922  }
923}
924
925TEST(TilingDataTest, SetBorderTexels) {
926  TilingData data(gfx::Size(8, 8), gfx::Size(16, 32), false);
927  EXPECT_EQ(2, data.num_tiles_x());
928  EXPECT_EQ(4, data.num_tiles_y());
929
930  data.SetHasBorderTexels(true);
931  EXPECT_EQ(3, data.num_tiles_x());
932  EXPECT_EQ(5, data.num_tiles_y());
933
934  data.SetHasBorderTexels(false);
935  EXPECT_EQ(2, data.num_tiles_x());
936  EXPECT_EQ(4, data.num_tiles_y());
937}
938
939TEST(TilingDataTest, LargeBorders) {
940  TilingData data(gfx::Size(100, 80), gfx::Size(200, 145), 30);
941  EXPECT_EQ(30, data.border_texels());
942
943  EXPECT_EQ(70, data.TileSizeX(0));
944  EXPECT_EQ(40, data.TileSizeX(1));
945  EXPECT_EQ(40, data.TileSizeX(2));
946  EXPECT_EQ(50, data.TileSizeX(3));
947  EXPECT_EQ(4, data.num_tiles_x());
948
949  EXPECT_EQ(50, data.TileSizeY(0));
950  EXPECT_EQ(20, data.TileSizeY(1));
951  EXPECT_EQ(20, data.TileSizeY(2));
952  EXPECT_EQ(20, data.TileSizeY(3));
953  EXPECT_EQ(35, data.TileSizeY(4));
954  EXPECT_EQ(5, data.num_tiles_y());
955
956  EXPECT_RECT_EQ(gfx::Rect(70, 50), data.TileBounds(0, 0));
957  EXPECT_RECT_EQ(gfx::Rect(70, 50, 40, 20), data.TileBounds(1, 1));
958  EXPECT_RECT_EQ(gfx::Rect(110, 110, 40, 35), data.TileBounds(2, 4));
959  EXPECT_RECT_EQ(gfx::Rect(150, 70, 50, 20), data.TileBounds(3, 2));
960  EXPECT_RECT_EQ(gfx::Rect(150, 110, 50, 35), data.TileBounds(3, 4));
961
962  EXPECT_RECT_EQ(gfx::Rect(100, 80), data.TileBoundsWithBorder(0, 0));
963  EXPECT_RECT_EQ(gfx::Rect(40, 20, 100, 80), data.TileBoundsWithBorder(1, 1));
964  EXPECT_RECT_EQ(gfx::Rect(80, 80, 100, 65), data.TileBoundsWithBorder(2, 4));
965  EXPECT_RECT_EQ(gfx::Rect(120, 40, 80, 80), data.TileBoundsWithBorder(3, 2));
966  EXPECT_RECT_EQ(gfx::Rect(120, 80, 80, 65), data.TileBoundsWithBorder(3, 4));
967
968  EXPECT_EQ(0, data.TileXIndexFromSrcCoord(0));
969  EXPECT_EQ(0, data.TileXIndexFromSrcCoord(69));
970  EXPECT_EQ(1, data.TileXIndexFromSrcCoord(70));
971  EXPECT_EQ(1, data.TileXIndexFromSrcCoord(109));
972  EXPECT_EQ(2, data.TileXIndexFromSrcCoord(110));
973  EXPECT_EQ(2, data.TileXIndexFromSrcCoord(149));
974  EXPECT_EQ(3, data.TileXIndexFromSrcCoord(150));
975  EXPECT_EQ(3, data.TileXIndexFromSrcCoord(199));
976
977  EXPECT_EQ(0, data.TileYIndexFromSrcCoord(0));
978  EXPECT_EQ(0, data.TileYIndexFromSrcCoord(49));
979  EXPECT_EQ(1, data.TileYIndexFromSrcCoord(50));
980  EXPECT_EQ(1, data.TileYIndexFromSrcCoord(69));
981  EXPECT_EQ(2, data.TileYIndexFromSrcCoord(70));
982  EXPECT_EQ(2, data.TileYIndexFromSrcCoord(89));
983  EXPECT_EQ(3, data.TileYIndexFromSrcCoord(90));
984  EXPECT_EQ(3, data.TileYIndexFromSrcCoord(109));
985  EXPECT_EQ(4, data.TileYIndexFromSrcCoord(110));
986  EXPECT_EQ(4, data.TileYIndexFromSrcCoord(144));
987
988  EXPECT_EQ(0, data.FirstBorderTileXIndexFromSrcCoord(0));
989  EXPECT_EQ(0, data.FirstBorderTileXIndexFromSrcCoord(99));
990  EXPECT_EQ(1, data.FirstBorderTileXIndexFromSrcCoord(100));
991  EXPECT_EQ(1, data.FirstBorderTileXIndexFromSrcCoord(139));
992  EXPECT_EQ(2, data.FirstBorderTileXIndexFromSrcCoord(140));
993  EXPECT_EQ(2, data.FirstBorderTileXIndexFromSrcCoord(179));
994  EXPECT_EQ(3, data.FirstBorderTileXIndexFromSrcCoord(180));
995  EXPECT_EQ(3, data.FirstBorderTileXIndexFromSrcCoord(199));
996
997  EXPECT_EQ(0, data.FirstBorderTileYIndexFromSrcCoord(0));
998  EXPECT_EQ(0, data.FirstBorderTileYIndexFromSrcCoord(79));
999  EXPECT_EQ(1, data.FirstBorderTileYIndexFromSrcCoord(80));
1000  EXPECT_EQ(1, data.FirstBorderTileYIndexFromSrcCoord(99));
1001  EXPECT_EQ(2, data.FirstBorderTileYIndexFromSrcCoord(100));
1002  EXPECT_EQ(2, data.FirstBorderTileYIndexFromSrcCoord(119));
1003  EXPECT_EQ(3, data.FirstBorderTileYIndexFromSrcCoord(120));
1004  EXPECT_EQ(3, data.FirstBorderTileYIndexFromSrcCoord(139));
1005  EXPECT_EQ(4, data.FirstBorderTileYIndexFromSrcCoord(140));
1006  EXPECT_EQ(4, data.FirstBorderTileYIndexFromSrcCoord(144));
1007
1008  EXPECT_EQ(0, data.LastBorderTileXIndexFromSrcCoord(0));
1009  EXPECT_EQ(0, data.LastBorderTileXIndexFromSrcCoord(39));
1010  EXPECT_EQ(1, data.LastBorderTileXIndexFromSrcCoord(40));
1011  EXPECT_EQ(1, data.LastBorderTileXIndexFromSrcCoord(79));
1012  EXPECT_EQ(2, data.LastBorderTileXIndexFromSrcCoord(80));
1013  EXPECT_EQ(2, data.LastBorderTileXIndexFromSrcCoord(119));
1014  EXPECT_EQ(3, data.LastBorderTileXIndexFromSrcCoord(120));
1015  EXPECT_EQ(3, data.LastBorderTileXIndexFromSrcCoord(199));
1016
1017  EXPECT_EQ(0, data.LastBorderTileYIndexFromSrcCoord(0));
1018  EXPECT_EQ(0, data.LastBorderTileYIndexFromSrcCoord(19));
1019  EXPECT_EQ(1, data.LastBorderTileYIndexFromSrcCoord(20));
1020  EXPECT_EQ(1, data.LastBorderTileYIndexFromSrcCoord(39));
1021  EXPECT_EQ(2, data.LastBorderTileYIndexFromSrcCoord(40));
1022  EXPECT_EQ(2, data.LastBorderTileYIndexFromSrcCoord(59));
1023  EXPECT_EQ(3, data.LastBorderTileYIndexFromSrcCoord(60));
1024  EXPECT_EQ(3, data.LastBorderTileYIndexFromSrcCoord(79));
1025  EXPECT_EQ(4, data.LastBorderTileYIndexFromSrcCoord(80));
1026  EXPECT_EQ(4, data.LastBorderTileYIndexFromSrcCoord(144));
1027}
1028
1029void TestIterate(const TilingData& data,
1030                 gfx::Rect rect,
1031                 int expect_left,
1032                 int expect_top,
1033                 int expect_right,
1034                 int expect_bottom,
1035                 bool include_borders) {
1036  EXPECT_GE(expect_left, 0);
1037  EXPECT_GE(expect_top, 0);
1038  EXPECT_LT(expect_right, data.num_tiles_x());
1039  EXPECT_LT(expect_bottom, data.num_tiles_y());
1040
1041  std::vector<std::pair<int, int> > original_expected;
1042  for (int x = 0; x < data.num_tiles_x(); ++x) {
1043    for (int y = 0; y < data.num_tiles_y(); ++y) {
1044      gfx::Rect bounds;
1045      if (include_borders)
1046        bounds = data.TileBoundsWithBorder(x, y);
1047      else
1048        bounds = data.TileBounds(x, y);
1049      if (x >= expect_left && x <= expect_right &&
1050          y >= expect_top && y <= expect_bottom) {
1051        EXPECT_TRUE(bounds.Intersects(rect));
1052        original_expected.push_back(std::make_pair(x, y));
1053      } else {
1054        EXPECT_FALSE(bounds.Intersects(rect));
1055      }
1056    }
1057  }
1058
1059  // Verify with vanilla iterator.
1060  {
1061    std::vector<std::pair<int, int> > expected = original_expected;
1062    for (TilingData::Iterator iter(&data, rect, include_borders); iter;
1063         ++iter) {
1064      bool found = false;
1065      for (size_t i = 0; i < expected.size(); ++i) {
1066        if (expected[i] == iter.index()) {
1067          expected[i] = expected.back();
1068          expected.pop_back();
1069          found = true;
1070          break;
1071        }
1072      }
1073      EXPECT_TRUE(found);
1074    }
1075    EXPECT_EQ(0u, expected.size());
1076  }
1077
1078  // Make sure this also works with a difference iterator and an empty ignore.
1079  // The difference iterator never includes borders, so ignore it otherwise.
1080  if (!include_borders) {
1081    std::vector<std::pair<int, int> > expected = original_expected;
1082    for (TilingData::DifferenceIterator iter(&data, rect, gfx::Rect()); iter;
1083         ++iter) {
1084      bool found = false;
1085      for (size_t i = 0; i < expected.size(); ++i) {
1086        if (expected[i] == iter.index()) {
1087          expected[i] = expected.back();
1088          expected.pop_back();
1089          found = true;
1090          break;
1091        }
1092      }
1093      EXPECT_TRUE(found);
1094    }
1095    EXPECT_EQ(0u, expected.size());
1096  }
1097}
1098
1099void TestIterateBorders(const TilingData& data,
1100                        gfx::Rect rect,
1101                        int expect_left,
1102                        int expect_top,
1103                        int expect_right,
1104                        int expect_bottom) {
1105  bool include_borders = true;
1106  TestIterate(data,
1107              rect,
1108              expect_left,
1109              expect_top,
1110              expect_right,
1111              expect_bottom,
1112              include_borders);
1113}
1114
1115void TestIterateNoBorders(const TilingData& data,
1116                          gfx::Rect rect,
1117                          int expect_left,
1118                          int expect_top,
1119                          int expect_right,
1120                          int expect_bottom) {
1121  bool include_borders = false;
1122  TestIterate(data,
1123              rect,
1124              expect_left,
1125              expect_top,
1126              expect_right,
1127              expect_bottom,
1128              include_borders);
1129}
1130
1131void TestIterateAll(const TilingData& data,
1132                    gfx::Rect rect,
1133                    int expect_left,
1134                    int expect_top,
1135                    int expect_right,
1136                    int expect_bottom) {
1137  TestIterateBorders(
1138      data, rect, expect_left, expect_top, expect_right, expect_bottom);
1139  TestIterateNoBorders(
1140      data, rect, expect_left, expect_top, expect_right, expect_bottom);
1141}
1142
1143TEST(TilingDataTest, IteratorNoBorderTexels) {
1144  TilingData data(gfx::Size(10, 10), gfx::Size(40, 25), false);
1145  // X border index by src coord: [0-10), [10-20), [20, 30), [30, 40)
1146  // Y border index by src coord: [0-10), [10-20), [20, 25)
1147  TestIterateAll(data, gfx::Rect(40, 25), 0, 0, 3, 2);
1148  TestIterateAll(data, gfx::Rect(15, 15, 8, 8), 1, 1, 2, 2);
1149
1150  // Oversized.
1151  TestIterateAll(data, gfx::Rect(-100, -100, 1000, 1000), 0, 0, 3, 2);
1152  TestIterateAll(data, gfx::Rect(-100, 20, 1000, 1), 0, 2, 3, 2);
1153  TestIterateAll(data, gfx::Rect(29, -100, 31, 1000), 2, 0, 3, 2);
1154  // Nonintersecting.
1155  TestIterateAll(data, gfx::Rect(60, 80, 100, 100), 0, 0, -1, -1);
1156}
1157
1158TEST(TilingDataTest, BordersIteratorOneBorderTexel) {
1159  TilingData data(gfx::Size(10, 20), gfx::Size(25, 45), true);
1160  // X border index by src coord: [0-10), [8-18), [16-25)
1161  // Y border index by src coord: [0-20), [18-38), [36-45)
1162  TestIterateBorders(data, gfx::Rect(25, 45), 0, 0, 2, 2);
1163  TestIterateBorders(data, gfx::Rect(18, 19, 3, 17), 2, 0, 2, 1);
1164  TestIterateBorders(data, gfx::Rect(10, 20, 6, 16), 1, 1, 1, 1);
1165  TestIterateBorders(data, gfx::Rect(9, 19, 8, 18), 0, 0, 2, 2);
1166  // Oversized.
1167  TestIterateBorders(data, gfx::Rect(-100, -100, 1000, 1000), 0, 0, 2, 2);
1168  TestIterateBorders(data, gfx::Rect(-100, 20, 1000, 1), 0, 1, 2, 1);
1169  TestIterateBorders(data, gfx::Rect(18, -100, 6, 1000), 2, 0, 2, 2);
1170  // Nonintersecting.
1171  TestIterateBorders(data, gfx::Rect(60, 80, 100, 100), 0, 0, -1, -1);
1172}
1173
1174TEST(TilingDataTest, NoBordersIteratorOneBorderTexel) {
1175  TilingData data(gfx::Size(10, 20), gfx::Size(25, 45), true);
1176  // X index by src coord: [0-9), [9-17), [17-25)
1177  // Y index by src coord: [0-19), [19-37), [37-45)
1178  TestIterateNoBorders(data, gfx::Rect(25, 45), 0, 0, 2, 2);
1179  TestIterateNoBorders(data, gfx::Rect(17, 19, 3, 18), 2, 1, 2, 1);
1180  TestIterateNoBorders(data, gfx::Rect(17, 19, 3, 19), 2, 1, 2, 2);
1181  TestIterateNoBorders(data, gfx::Rect(8, 18, 9, 19), 0, 0, 1, 1);
1182  TestIterateNoBorders(data, gfx::Rect(9, 19, 9, 19), 1, 1, 2, 2);
1183  // Oversized.
1184  TestIterateNoBorders(data, gfx::Rect(-100, -100, 1000, 1000), 0, 0, 2, 2);
1185  TestIterateNoBorders(data, gfx::Rect(-100, 20, 1000, 1), 0, 1, 2, 1);
1186  TestIterateNoBorders(data, gfx::Rect(18, -100, 6, 1000), 2, 0, 2, 2);
1187  // Nonintersecting.
1188  TestIterateNoBorders(data, gfx::Rect(60, 80, 100, 100), 0, 0, -1, -1);
1189}
1190
1191TEST(TilingDataTest, BordersIteratorManyBorderTexels) {
1192  TilingData data(gfx::Size(50, 60), gfx::Size(65, 110), 20);
1193  // X border index by src coord: [0-50), [10-60), [20-65)
1194  // Y border index by src coord: [0-60), [20-80), [40-100), [60-110)
1195  TestIterateBorders(data, gfx::Rect(65, 110), 0, 0, 2, 3);
1196  TestIterateBorders(data, gfx::Rect(50, 60, 15, 65), 1, 1, 2, 3);
1197  TestIterateBorders(data, gfx::Rect(60, 30, 2, 10), 2, 0, 2, 1);
1198  // Oversized.
1199  TestIterateBorders(data, gfx::Rect(-100, -100, 1000, 1000), 0, 0, 2, 3);
1200  TestIterateBorders(data, gfx::Rect(-100, 10, 1000, 10), 0, 0, 2, 0);
1201  TestIterateBorders(data, gfx::Rect(10, -100, 10, 1000), 0, 0, 1, 3);
1202  // Nonintersecting.
1203  TestIterateBorders(data, gfx::Rect(65, 110, 100, 100), 0, 0, -1, -1);
1204}
1205
1206TEST(TilingDataTest, NoBordersIteratorManyBorderTexels) {
1207  TilingData data(gfx::Size(50, 60), gfx::Size(65, 110), 20);
1208  // X index by src coord: [0-30), [30-40), [40, 65)
1209  // Y index by src coord: [0-40), [40-60), [60, 80), [80-110)
1210  TestIterateNoBorders(data, gfx::Rect(65, 110), 0, 0, 2, 3);
1211  TestIterateNoBorders(data, gfx::Rect(30, 40, 15, 65), 1, 1, 2, 3);
1212  TestIterateNoBorders(data, gfx::Rect(60, 20, 2, 21), 2, 0, 2, 1);
1213  // Oversized.
1214  TestIterateNoBorders(data, gfx::Rect(-100, -100, 1000, 1000), 0, 0, 2, 3);
1215  TestIterateNoBorders(data, gfx::Rect(-100, 10, 1000, 10), 0, 0, 2, 0);
1216  TestIterateNoBorders(data, gfx::Rect(10, -100, 10, 1000), 0, 0, 0, 3);
1217  // Nonintersecting.
1218  TestIterateNoBorders(data, gfx::Rect(65, 110, 100, 100), 0, 0, -1, -1);
1219}
1220
1221TEST(TilingDataTest, IteratorOneTile) {
1222  TilingData no_border(gfx::Size(1000, 1000), gfx::Size(30, 40), false);
1223  TestIterateAll(no_border, gfx::Rect(30, 40), 0, 0, 0, 0);
1224  TestIterateAll(no_border, gfx::Rect(10, 10, 20, 20), 0, 0, 0, 0);
1225  TestIterateAll(no_border, gfx::Rect(30, 40, 100, 100), 0, 0, -1, -1);
1226
1227  TilingData one_border(gfx::Size(1000, 1000), gfx::Size(30, 40), true);
1228  TestIterateAll(one_border, gfx::Rect(30, 40), 0, 0, 0, 0);
1229  TestIterateAll(one_border, gfx::Rect(10, 10, 20, 20), 0, 0, 0, 0);
1230  TestIterateAll(one_border, gfx::Rect(30, 40, 100, 100), 0, 0, -1, -1);
1231
1232  TilingData big_border(gfx::Size(1000, 1000), gfx::Size(30, 40), 50);
1233  TestIterateAll(big_border, gfx::Rect(30, 40), 0, 0, 0, 0);
1234  TestIterateAll(big_border, gfx::Rect(10, 10, 20, 20), 0, 0, 0, 0);
1235  TestIterateAll(big_border, gfx::Rect(30, 40, 100, 100), 0, 0, -1, -1);
1236}
1237
1238TEST(TilingDataTest, IteratorNoTiles) {
1239  TilingData data(gfx::Size(100, 100), gfx::Size(), false);
1240  TestIterateAll(data, gfx::Rect(100, 100), 0, 0, -1, -1);
1241}
1242
1243void TestDiff(const TilingData& data,
1244              gfx::Rect consider,
1245              gfx::Rect ignore,
1246              size_t num_tiles) {
1247  std::vector<std::pair<int, int> > expected;
1248  for (int y = 0; y < data.num_tiles_y(); ++y) {
1249    for (int x = 0; x < data.num_tiles_x(); ++x) {
1250      gfx::Rect bounds = data.TileBounds(x, y);
1251      if (bounds.Intersects(consider) && !bounds.Intersects(ignore))
1252        expected.push_back(std::make_pair(x, y));
1253    }
1254  }
1255
1256  // Sanity check the test.
1257  EXPECT_EQ(num_tiles, expected.size());
1258
1259  for (TilingData::DifferenceIterator iter(&data, consider, ignore); iter;
1260       ++iter) {
1261    bool found = false;
1262    for (size_t i = 0; i < expected.size(); ++i) {
1263      if (expected[i] == iter.index()) {
1264        expected[i] = expected.back();
1265        expected.pop_back();
1266        found = true;
1267        break;
1268      }
1269    }
1270    EXPECT_TRUE(found);
1271  }
1272  EXPECT_EQ(0u, expected.size());
1273}
1274
1275TEST(TilingDataTest, DifferenceIteratorIgnoreGeometry) {
1276  // This test is checking that the iterator can handle different geometries of
1277  // ignore rects relative to the consider rect.  The consider rect indices
1278  // themselves are mostly tested by the non-difference iterator tests, so the
1279  // full rect is mostly used here for simplicity.
1280
1281  // X border index by src coord: [0-10), [10-20), [20, 30), [30, 40)
1282  // Y border index by src coord: [0-10), [10-20), [20, 25)
1283  TilingData data(gfx::Size(10, 10), gfx::Size(40, 25), false);
1284
1285  // Fully ignored
1286  TestDiff(data, gfx::Rect(40, 25), gfx::Rect(40, 25), 0);
1287  TestDiff(data, gfx::Rect(40, 25), gfx::Rect(-100, -100, 200, 200), 0);
1288  TestDiff(data, gfx::Rect(40, 25), gfx::Rect(9, 9, 30, 15), 0);
1289  TestDiff(data, gfx::Rect(15, 15, 8, 8), gfx::Rect(15, 15, 8, 8), 0);
1290
1291  // Fully un-ignored
1292  TestDiff(data, gfx::Rect(40, 25), gfx::Rect(-30, -20, 8, 8), 12);
1293  TestDiff(data, gfx::Rect(40, 25), gfx::Rect(), 12);
1294
1295  // Top left, remove 2x2 tiles
1296  TestDiff(data, gfx::Rect(40, 25), gfx::Rect(20, 19), 8);
1297  // Bottom right, remove 2x2 tiles
1298  TestDiff(data, gfx::Rect(40, 25), gfx::Rect(20, 15, 20, 6), 8);
1299  // Bottom left, remove 2x2 tiles
1300  TestDiff(data, gfx::Rect(40, 25), gfx::Rect(0, 15, 20, 6), 8);
1301  // Top right, remove 2x2 tiles
1302  TestDiff(data, gfx::Rect(40, 25), gfx::Rect(20, 0, 20, 19), 8);
1303  // Center, remove only one tile
1304  TestDiff(data, gfx::Rect(40, 25), gfx::Rect(10, 10, 5, 5), 11);
1305
1306  // Left column, flush left, removing two columns
1307  TestDiff(data, gfx::Rect(40, 25), gfx::Rect(11, 25), 6);
1308  // Middle column, removing two columns
1309  TestDiff(data, gfx::Rect(40, 25), gfx::Rect(11, 0, 11, 25), 6);
1310  // Right column, flush right, removing one column
1311  TestDiff(data, gfx::Rect(40, 25), gfx::Rect(30, 0, 2, 25), 9);
1312
1313  // Top row, flush top, removing one row
1314  TestDiff(data, gfx::Rect(40, 25), gfx::Rect(0, 5, 40, 5), 8);
1315  // Middle row, removing one row
1316  TestDiff(data, gfx::Rect(40, 25), gfx::Rect(0, 13, 40, 5), 8);
1317  // Bottom row, flush bottom, removing two rows
1318  TestDiff(data, gfx::Rect(40, 25), gfx::Rect(0, 13, 40, 12), 4);
1319
1320  // Non-intersecting, but still touching two of the same tiles.
1321  TestDiff(data, gfx::Rect(8, 0, 32, 25), gfx::Rect(0, 12, 5, 12), 10);
1322
1323  // Intersecting, but neither contains the other. 2x3 with one overlap.
1324  TestDiff(data, gfx::Rect(5, 2, 20, 10), gfx::Rect(25, 15, 5, 10), 5);
1325}
1326
1327TEST(TilingDataTest, DifferenceIteratorManyBorderTexels) {
1328  // X border index by src coord: [0-50), [10-60), [20-65)
1329  // Y border index by src coord: [0-60), [20-80), [40-100), [60-110)
1330  // X tile bounds by src coord: [0-30), [30-40), [40-65)
1331  // Y tile bounds by src coord: [0-40), [40-60), [60-80), [80-110)
1332  TilingData data(gfx::Size(50, 60), gfx::Size(65, 110), 20);
1333
1334  // Knock out two rows, but not the left column.
1335  TestDiff(data, gfx::Rect(10, 30, 55, 80), gfx::Rect(30, 59, 20, 2), 8);
1336
1337  // Knock out one row.
1338  TestDiff(data, gfx::Rect(10, 30, 55, 80), gfx::Rect(29, 59, 20, 1), 9);
1339
1340  // Overlap all tiles with ignore rect.
1341  TestDiff(data, gfx::Rect(65, 110), gfx::Rect(29, 39, 12, 42), 0);
1342
1343  gfx::Rect tile = data.TileBounds(1, 1);
1344
1345  // Ignore one tile.
1346  TestDiff(data, gfx::Rect(20, 30, 45, 80), tile, 11);
1347
1348  // Include one tile.
1349  TestDiff(data, tile, gfx::Rect(), 1);
1350}
1351
1352TEST(TilingDataTest, DifferenceIteratorOneTile) {
1353  TilingData no_border(gfx::Size(1000, 1000), gfx::Size(30, 40), false);
1354  TestDiff(no_border, gfx::Rect(30, 40), gfx::Rect(), 1);
1355  TestDiff(no_border, gfx::Rect(5, 5, 100, 100), gfx::Rect(5, 5, 1, 1), 0);
1356
1357  TilingData one_border(gfx::Size(1000, 1000), gfx::Size(30, 40), true);
1358  TestDiff(one_border, gfx::Rect(30, 40), gfx::Rect(), 1);
1359  TestDiff(one_border, gfx::Rect(5, 5, 100, 100), gfx::Rect(5, 5, 1, 1), 0);
1360
1361  TilingData big_border(gfx::Size(1000, 1000), gfx::Size(30, 40), 50);
1362  TestDiff(big_border, gfx::Rect(30, 40), gfx::Rect(), 1);
1363  TestDiff(big_border, gfx::Rect(5, 5, 100, 100), gfx::Rect(5, 5, 1, 1), 0);
1364}
1365
1366TEST(TilingDataTest, DifferenceIteratorNoTiles) {
1367  TilingData data(gfx::Size(100, 100), gfx::Size(), false);
1368  TestDiff(data, gfx::Rect(100, 100), gfx::Rect(5, 5), 0);
1369}
1370
1371void TestSpiralIterate(int source_line_number,
1372                       const TilingData& tiling_data,
1373                       const gfx::Rect& consider,
1374                       const gfx::Rect& ignore,
1375                       const gfx::Rect& center,
1376                       const std::vector<std::pair<int, int> >& expected) {
1377  std::vector<std::pair<int, int> > actual;
1378  for (TilingData::SpiralDifferenceIterator it(
1379           &tiling_data, consider, ignore, center);
1380       it;
1381       ++it) {
1382    actual.push_back(it.index());
1383  }
1384
1385  EXPECT_EQ(expected.size(), actual.size()) << "error from line "
1386                                            << source_line_number;
1387  for (size_t i = 0; i < std::min(expected.size(), actual.size()); ++i) {
1388    EXPECT_EQ(expected[i].first, actual[i].first)
1389        << "i: " << i << " error from line: " << source_line_number;
1390    EXPECT_EQ(expected[i].second, actual[i].second)
1391        << "i: " << i << " error from line: " << source_line_number;
1392  }
1393}
1394
1395TEST(TilingDataTest, SpiralDifferenceIteratorNoIgnoreFullConsider) {
1396  TilingData tiling_data(gfx::Size(10, 10), gfx::Size(30, 30), false);
1397  gfx::Rect consider(30, 30);
1398  gfx::Rect ignore;
1399  std::vector<std::pair<int, int> > expected;
1400
1401  // Center is in the center of the tiling.
1402  gfx::Rect center(15, 15, 1, 1);
1403
1404  // Layout of the tiling data, and expected return order:
1405  //   x 0 1 2
1406  //  y.------
1407  //  0| 4 3 2
1408  //  1| 5 * 1
1409  //  2| 6 7 8
1410  expected.push_back(std::make_pair(2, 1));
1411  expected.push_back(std::make_pair(2, 0));
1412  expected.push_back(std::make_pair(1, 0));
1413  expected.push_back(std::make_pair(0, 0));
1414  expected.push_back(std::make_pair(0, 1));
1415  expected.push_back(std::make_pair(0, 2));
1416  expected.push_back(std::make_pair(1, 2));
1417  expected.push_back(std::make_pair(2, 2));
1418
1419  TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
1420
1421  // Center is off to the right side of the tiling (and far away).
1422  center = gfx::Rect(100, 15, 1, 1);
1423
1424  // Layout of the tiling data, and expected return order:
1425  //   x 0 1 2
1426  //  y.------
1427  //  0| 7 4 1
1428  //  1| 8 5 2 *
1429  //  2| 9 6 3
1430  expected.clear();
1431  expected.push_back(std::make_pair(2, 0));
1432  expected.push_back(std::make_pair(2, 1));
1433  expected.push_back(std::make_pair(2, 2));
1434  expected.push_back(std::make_pair(1, 0));
1435  expected.push_back(std::make_pair(1, 1));
1436  expected.push_back(std::make_pair(1, 2));
1437  expected.push_back(std::make_pair(0, 0));
1438  expected.push_back(std::make_pair(0, 1));
1439  expected.push_back(std::make_pair(0, 2));
1440
1441  TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
1442
1443  // Center is the bottom right corner of the tiling.
1444  center = gfx::Rect(25, 25, 1, 1);
1445
1446  // Layout of the tiling data, and expected return order:
1447  //   x 0 1 2
1448  //  y.------
1449  //  0| 6 5 4
1450  //  1| 7 2 1
1451  //  2| 8 3 *
1452  expected.clear();
1453  expected.push_back(std::make_pair(2, 1));
1454  expected.push_back(std::make_pair(1, 1));
1455  expected.push_back(std::make_pair(1, 2));
1456  expected.push_back(std::make_pair(2, 0));
1457  expected.push_back(std::make_pair(1, 0));
1458  expected.push_back(std::make_pair(0, 0));
1459  expected.push_back(std::make_pair(0, 1));
1460  expected.push_back(std::make_pair(0, 2));
1461
1462  TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
1463
1464  // Center is off the top left side of the tiling.
1465  center = gfx::Rect(-60, -50, 1, 1);
1466
1467  // Layout of the tiling data, and expected return order:
1468  // * x 0 1 2
1469  //  y.------
1470  //  0| 1 2 6
1471  //  1| 3 4 5
1472  //  2| 7 8 9
1473  expected.clear();
1474  expected.push_back(std::make_pair(0, 0));
1475  expected.push_back(std::make_pair(1, 0));
1476  expected.push_back(std::make_pair(0, 1));
1477  expected.push_back(std::make_pair(1, 1));
1478  expected.push_back(std::make_pair(2, 1));
1479  expected.push_back(std::make_pair(2, 0));
1480  expected.push_back(std::make_pair(0, 2));
1481  expected.push_back(std::make_pair(1, 2));
1482  expected.push_back(std::make_pair(2, 2));
1483
1484  TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
1485
1486  // Two tile center.
1487  center = gfx::Rect(15, 15, 1, 10);
1488
1489  // Layout of the tiling data, and expected return order:
1490  //   x 0 1 2
1491  //  y.------
1492  //  0| 5 4 3
1493  //  1| 6 * 2
1494  //  2| 7 * 1
1495  expected.clear();
1496  expected.push_back(std::make_pair(2, 2));
1497  expected.push_back(std::make_pair(2, 1));
1498  expected.push_back(std::make_pair(2, 0));
1499  expected.push_back(std::make_pair(1, 0));
1500  expected.push_back(std::make_pair(0, 0));
1501  expected.push_back(std::make_pair(0, 1));
1502  expected.push_back(std::make_pair(0, 2));
1503
1504  TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
1505}
1506
1507TEST(TilingDataTest, SpiralDifferenceIteratorSmallConsider) {
1508  TilingData tiling_data(gfx::Size(10, 10), gfx::Size(50, 50), false);
1509  gfx::Rect ignore;
1510  std::vector<std::pair<int, int> > expected;
1511  gfx::Rect center(15, 15, 1, 1);
1512
1513  // Consider is one cell.
1514  gfx::Rect consider(1, 1);
1515
1516  // Layout of the tiling data, and expected return order:
1517  //   x 0 1 2 3 4
1518  //  y.----------
1519  //  0| 1
1520  //  1|   *
1521  //  2|
1522  //  3|
1523  //  4|
1524  expected.push_back(std::make_pair(0, 0));
1525
1526  TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
1527
1528  // Consider is bottom right corner.
1529  consider = gfx::Rect(25, 25, 10, 10);
1530
1531  // Layout of the tiling data, and expected return order:
1532  //   x 0 1 2 3 4
1533  //  y.----------
1534  //  0|
1535  //  1|   *
1536  //  2|     1 2
1537  //  3|     3 4
1538  //  4|
1539  expected.clear();
1540  expected.push_back(std::make_pair(2, 2));
1541  expected.push_back(std::make_pair(3, 2));
1542  expected.push_back(std::make_pair(2, 3));
1543  expected.push_back(std::make_pair(3, 3));
1544
1545  TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
1546
1547  // Consider is one column.
1548  consider = gfx::Rect(11, 0, 1, 100);
1549
1550  // Layout of the tiling data, and expected return order:
1551  //   x 0 1 2 3 4
1552  //  y.----------
1553  //  0|   2
1554  //  1|   *
1555  //  2|   3
1556  //  3|   4
1557  //  4|   5
1558  expected.clear();
1559  expected.push_back(std::make_pair(1, 0));
1560  expected.push_back(std::make_pair(1, 2));
1561  expected.push_back(std::make_pair(1, 3));
1562  expected.push_back(std::make_pair(1, 4));
1563
1564  TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
1565}
1566
1567TEST(TilingDataTest, SpiralDifferenceIteratorHasIgnore) {
1568  TilingData tiling_data(gfx::Size(10, 10), gfx::Size(50, 50), false);
1569  gfx::Rect consider(50, 50);
1570  std::vector<std::pair<int, int> > expected;
1571  gfx::Rect center(15, 15, 1, 1);
1572
1573  // Full ignore.
1574  gfx::Rect ignore(50, 50);
1575
1576  // Layout of the tiling data, and expected return order:
1577  //   x 0 1 2 3 4
1578  //  y.----------
1579  //  0| . . . . .
1580  //  1| . * . . .
1581  //  2| . . . . .
1582  //  3| . . . . .
1583  //  4| . . . . .
1584  expected.clear();
1585
1586  TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
1587
1588  // 3 column ignore.
1589  ignore = gfx::Rect(15, 0, 20, 100);
1590
1591  // Layout of the tiling data, and expected return order:
1592  //   x 0 1 2 3 4
1593  //  y.----------
1594  //  0| 1 . . . 8
1595  //  1| 2 * . . 7
1596  //  2| 3 . . . 6
1597  //  3| 4 . . . 5
1598  //  4| 9 . . . 10
1599  expected.clear();
1600
1601  expected.push_back(std::make_pair(0, 0));
1602  expected.push_back(std::make_pair(0, 1));
1603  expected.push_back(std::make_pair(0, 2));
1604  expected.push_back(std::make_pair(0, 3));
1605  expected.push_back(std::make_pair(4, 3));
1606  expected.push_back(std::make_pair(4, 2));
1607  expected.push_back(std::make_pair(4, 1));
1608  expected.push_back(std::make_pair(4, 0));
1609  expected.push_back(std::make_pair(0, 4));
1610  expected.push_back(std::make_pair(4, 4));
1611
1612  TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
1613
1614  // Ignore covers the top half.
1615  ignore = gfx::Rect(50, 25);
1616
1617  // Layout of the tiling data, and expected return order:
1618  //   x 0 1 2 3 4
1619  //  y.----------
1620  //  0| . . . . .
1621  //  1| . * . . .
1622  //  2| . . . . .
1623  //  3| 1 2 3 4 5
1624  //  4| 6 7 8 9 10
1625  expected.clear();
1626
1627  expected.push_back(std::make_pair(0, 3));
1628  expected.push_back(std::make_pair(1, 3));
1629  expected.push_back(std::make_pair(2, 3));
1630  expected.push_back(std::make_pair(3, 3));
1631  expected.push_back(std::make_pair(4, 3));
1632  expected.push_back(std::make_pair(0, 4));
1633  expected.push_back(std::make_pair(1, 4));
1634  expected.push_back(std::make_pair(2, 4));
1635  expected.push_back(std::make_pair(3, 4));
1636  expected.push_back(std::make_pair(4, 4));
1637
1638  TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
1639}
1640
1641TEST(TilingDataTest, SpiralDifferenceIteratorRectangleCenter) {
1642  TilingData tiling_data(gfx::Size(10, 10), gfx::Size(50, 50), false);
1643  gfx::Rect consider(50, 50);
1644  std::vector<std::pair<int, int> > expected;
1645  gfx::Rect ignore;
1646
1647  // Two cell center
1648  gfx::Rect center(25, 25, 1, 10);
1649
1650  // Layout of the tiling data, and expected return order:
1651  //   x 0 1 2 3 4
1652  //  y.----------
1653  //  0| J I H G F
1654  //  1| K 5 4 3 E
1655  //  2| L 6 * 2 D
1656  //  3| M 7 * 1 C
1657  //  4| N 8 9 A B
1658  expected.clear();
1659
1660  expected.push_back(std::make_pair(3, 3));
1661  expected.push_back(std::make_pair(3, 2));
1662  expected.push_back(std::make_pair(3, 1));
1663  expected.push_back(std::make_pair(2, 1));
1664  expected.push_back(std::make_pair(1, 1));
1665  expected.push_back(std::make_pair(1, 2));
1666  expected.push_back(std::make_pair(1, 3));
1667  expected.push_back(std::make_pair(1, 4));
1668  expected.push_back(std::make_pair(2, 4));
1669  expected.push_back(std::make_pair(3, 4));
1670  expected.push_back(std::make_pair(4, 4));
1671  expected.push_back(std::make_pair(4, 3));
1672  expected.push_back(std::make_pair(4, 2));
1673  expected.push_back(std::make_pair(4, 1));
1674  expected.push_back(std::make_pair(4, 0));
1675  expected.push_back(std::make_pair(3, 0));
1676  expected.push_back(std::make_pair(2, 0));
1677  expected.push_back(std::make_pair(1, 0));
1678  expected.push_back(std::make_pair(0, 0));
1679  expected.push_back(std::make_pair(0, 1));
1680  expected.push_back(std::make_pair(0, 2));
1681  expected.push_back(std::make_pair(0, 3));
1682  expected.push_back(std::make_pair(0, 4));
1683
1684  TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
1685
1686  // Three by two center.
1687  center = gfx::Rect(15, 25, 20, 10);
1688
1689  // Layout of the tiling data, and expected return order:
1690  //   x 0 1 2 3 4
1691  //  y.----------
1692  //  0| J I H G F
1693  //  1| 7 6 5 4 3
1694  //  2| 8 * * * 2
1695  //  3| 9 * * * 1
1696  //  4| A B C D E
1697  expected.clear();
1698
1699  expected.push_back(std::make_pair(4, 3));
1700  expected.push_back(std::make_pair(4, 2));
1701  expected.push_back(std::make_pair(4, 1));
1702  expected.push_back(std::make_pair(3, 1));
1703  expected.push_back(std::make_pair(2, 1));
1704  expected.push_back(std::make_pair(1, 1));
1705  expected.push_back(std::make_pair(0, 1));
1706  expected.push_back(std::make_pair(0, 2));
1707  expected.push_back(std::make_pair(0, 3));
1708  expected.push_back(std::make_pair(0, 4));
1709  expected.push_back(std::make_pair(1, 4));
1710  expected.push_back(std::make_pair(2, 4));
1711  expected.push_back(std::make_pair(3, 4));
1712  expected.push_back(std::make_pair(4, 4));
1713  expected.push_back(std::make_pair(4, 0));
1714  expected.push_back(std::make_pair(3, 0));
1715  expected.push_back(std::make_pair(2, 0));
1716  expected.push_back(std::make_pair(1, 0));
1717  expected.push_back(std::make_pair(0, 0));
1718
1719  TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
1720
1721  // Column center off the left side.
1722  center = gfx::Rect(-50, 0, 30, 50);
1723
1724  // Layout of the tiling data, and expected return order:
1725  //    x 0 1 2 3 4
1726  //   y.----------
1727  // * 0| 5 A F K P
1728  // * 1| 4 9 E J O
1729  // * 2| 3 8 D I N
1730  // * 3| 2 7 C H M
1731  // * 4| 1 6 B G L
1732  expected.clear();
1733
1734  expected.push_back(std::make_pair(0, 4));
1735  expected.push_back(std::make_pair(0, 3));
1736  expected.push_back(std::make_pair(0, 2));
1737  expected.push_back(std::make_pair(0, 1));
1738  expected.push_back(std::make_pair(0, 0));
1739  expected.push_back(std::make_pair(1, 4));
1740  expected.push_back(std::make_pair(1, 3));
1741  expected.push_back(std::make_pair(1, 2));
1742  expected.push_back(std::make_pair(1, 1));
1743  expected.push_back(std::make_pair(1, 0));
1744  expected.push_back(std::make_pair(2, 4));
1745  expected.push_back(std::make_pair(2, 3));
1746  expected.push_back(std::make_pair(2, 2));
1747  expected.push_back(std::make_pair(2, 1));
1748  expected.push_back(std::make_pair(2, 0));
1749  expected.push_back(std::make_pair(3, 4));
1750  expected.push_back(std::make_pair(3, 3));
1751  expected.push_back(std::make_pair(3, 2));
1752  expected.push_back(std::make_pair(3, 1));
1753  expected.push_back(std::make_pair(3, 0));
1754  expected.push_back(std::make_pair(4, 4));
1755  expected.push_back(std::make_pair(4, 3));
1756  expected.push_back(std::make_pair(4, 2));
1757  expected.push_back(std::make_pair(4, 1));
1758  expected.push_back(std::make_pair(4, 0));
1759
1760  TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
1761}
1762
1763TEST(TilingDataTest, SpiralDifferenceIteratorEdgeCases) {
1764  TilingData tiling_data(gfx::Size(10, 10), gfx::Size(30, 30), false);
1765  std::vector<std::pair<int, int> > expected;
1766  gfx::Rect center;
1767  gfx::Rect consider;
1768  gfx::Rect ignore;
1769
1770  // Ignore contains, but is not equal to, consider and center.
1771  ignore = gfx::Rect(15, 0, 20, 30);
1772  consider = gfx::Rect(20, 10, 10, 20);
1773  center = gfx::Rect(25, 0, 5, 5);
1774
1775  // Layout of the tiling data, and expected return order:
1776  //   x 0 1 2
1777  //  y.------
1778  //  0|   . *
1779  //  1|   . .
1780  //  2|   . .
1781  expected.clear();
1782
1783  TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
1784
1785  // Center intersects with consider.
1786  ignore = gfx::Rect();
1787  center = gfx::Rect(0, 15, 30, 15);
1788  consider = gfx::Rect(15, 30);
1789
1790  // Layout of the tiling data, and expected return order:
1791  //   x 0 1 2
1792  //  y.------
1793  //  0| 2 1
1794  //  1| * * *
1795  //  2| * * *
1796  expected.clear();
1797
1798  expected.push_back(std::make_pair(1, 0));
1799  expected.push_back(std::make_pair(0, 0));
1800
1801  TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
1802
1803  // Consider and ignore are non-intersecting.
1804  ignore = gfx::Rect(5, 30);
1805  consider = gfx::Rect(25, 0, 5, 30);
1806  center = gfx::Rect(15, 0, 1, 1);
1807
1808  // Layout of the tiling data, and expected return order:
1809  //   x 0 1 2
1810  //  y.------
1811  //  0| . * 1
1812  //  1| .   2
1813  //  2| .   3
1814  expected.clear();
1815
1816  expected.push_back(std::make_pair(2, 0));
1817  expected.push_back(std::make_pair(2, 1));
1818  expected.push_back(std::make_pair(2, 2));
1819
1820  TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
1821
1822  // Center intersects with ignore.
1823  consider = gfx::Rect(30, 30);
1824  center = gfx::Rect(15, 0, 1, 30);
1825  ignore = gfx::Rect(0, 15, 30, 1);
1826
1827  // Layout of the tiling data, and expected return order:
1828  //   x 0 1 2
1829  //  y.------
1830  //  0| 3 * 2
1831  //  1| . * .
1832  //  2| 4 * 1
1833  expected.clear();
1834
1835  expected.push_back(std::make_pair(2, 2));
1836  expected.push_back(std::make_pair(2, 0));
1837  expected.push_back(std::make_pair(0, 0));
1838  expected.push_back(std::make_pair(0, 2));
1839
1840  TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
1841
1842  // Center and ignore are the same.
1843  consider = gfx::Rect(30, 30);
1844  center = gfx::Rect(15, 0, 1, 30);
1845  ignore = center;
1846
1847  // Layout of the tiling data, and expected return order:
1848  //   x 0 1 2
1849  //  y.------
1850  //  0| 4 * 3
1851  //  1| 5 * 2
1852  //  2| 6 * 1
1853  expected.clear();
1854
1855  expected.push_back(std::make_pair(2, 2));
1856  expected.push_back(std::make_pair(2, 1));
1857  expected.push_back(std::make_pair(2, 0));
1858  expected.push_back(std::make_pair(0, 0));
1859  expected.push_back(std::make_pair(0, 1));
1860  expected.push_back(std::make_pair(0, 2));
1861
1862  TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
1863
1864  // Empty tiling data.
1865  TilingData empty_data(gfx::Size(0, 0), gfx::Size(0, 0), false);
1866
1867  expected.clear();
1868  TestSpiralIterate(__LINE__, empty_data, consider, ignore, center, expected);
1869
1870  // Empty consider.
1871  ignore = gfx::Rect();
1872  center = gfx::Rect(1, 1, 1, 1);
1873  consider = gfx::Rect();
1874
1875  expected.clear();
1876  TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
1877
1878  // Empty center. Note: This arbitrarily puts the center to be off the top-left
1879  // corner.
1880  consider = gfx::Rect(30, 30);
1881  ignore = gfx::Rect();
1882  center = gfx::Rect();
1883
1884  // Layout of the tiling data, and expected return order:
1885  // * x 0 1 2
1886  //  y.------
1887  //  0| 1 2 6
1888  //  1| 3 4 5
1889  //  2| 7 8 9
1890  expected.clear();
1891
1892  expected.push_back(std::make_pair(0, 0));
1893  expected.push_back(std::make_pair(1, 0));
1894  expected.push_back(std::make_pair(0, 1));
1895  expected.push_back(std::make_pair(1, 1));
1896  expected.push_back(std::make_pair(2, 1));
1897  expected.push_back(std::make_pair(2, 0));
1898  expected.push_back(std::make_pair(0, 2));
1899  expected.push_back(std::make_pair(1, 2));
1900  expected.push_back(std::make_pair(2, 2));
1901
1902  TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
1903
1904  // Every rect is empty.
1905  ignore = gfx::Rect();
1906  center = gfx::Rect();
1907  consider = gfx::Rect();
1908
1909  expected.clear();
1910  TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
1911
1912  // Center is just to the left of cover, and off of the tiling's left side.
1913  consider = gfx::Rect(30, 30);
1914  ignore = gfx::Rect();
1915  center = gfx::Rect(-20, 0, 19, 30);
1916
1917  // Layout of the tiling data, and expected return order:
1918  //   x 0 1 2
1919  //  y.------
1920  // *0| 3 6 9
1921  // *1| 2 5 8
1922  // *2| 1 4 7
1923  expected.clear();
1924
1925  expected.push_back(std::make_pair(0, 2));
1926  expected.push_back(std::make_pair(0, 1));
1927  expected.push_back(std::make_pair(0, 0));
1928  expected.push_back(std::make_pair(1, 2));
1929  expected.push_back(std::make_pair(1, 1));
1930  expected.push_back(std::make_pair(1, 0));
1931  expected.push_back(std::make_pair(2, 2));
1932  expected.push_back(std::make_pair(2, 1));
1933  expected.push_back(std::make_pair(2, 0));
1934
1935  TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
1936}
1937
1938}  // namespace
1939
1940}  // namespace cc
1941