OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/base/tiling_data.h" | 5 #include "cc/base/tiling_data.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "cc/test/geometry_test_utils.h" | 10 #include "cc/test/geometry_test_utils.h" |
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1079 found = true; | 1079 found = true; |
1080 break; | 1080 break; |
1081 } | 1081 } |
1082 } | 1082 } |
1083 EXPECT_TRUE(found); | 1083 EXPECT_TRUE(found); |
1084 } | 1084 } |
1085 EXPECT_EQ(0u, expected.size()); | 1085 EXPECT_EQ(0u, expected.size()); |
1086 } | 1086 } |
1087 | 1087 |
1088 // Make sure this also works with a difference iterator and an empty ignore. | 1088 // Make sure this also works with a difference iterator and an empty ignore. |
1089 // The difference iterator always includes borders, so ignore it otherwise. | 1089 // The difference iterator never includes borders, so ignore it otherwise. |
1090 if (include_borders) { | 1090 if (!include_borders) { |
1091 std::vector<std::pair<int, int> > expected = original_expected; | 1091 std::vector<std::pair<int, int> > expected = original_expected; |
1092 for (TilingData::DifferenceIterator iter(&data, rect, gfx::Rect()); | 1092 for (TilingData::DifferenceIterator iter(&data, rect, gfx::Rect()); iter; |
1093 iter; ++iter) { | 1093 ++iter) { |
1094 bool found = false; | 1094 bool found = false; |
1095 for (size_t i = 0; i < expected.size(); ++i) { | 1095 for (size_t i = 0; i < expected.size(); ++i) { |
1096 if (expected[i] == iter.index()) { | 1096 if (expected[i] == iter.index()) { |
1097 expected[i] = expected.back(); | 1097 expected[i] = expected.back(); |
1098 expected.pop_back(); | 1098 expected.pop_back(); |
1099 found = true; | 1099 found = true; |
1100 break; | 1100 break; |
1101 } | 1101 } |
1102 } | 1102 } |
1103 EXPECT_TRUE(found); | 1103 EXPECT_TRUE(found); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1243 TestIterateAll(big_border, gfx::Rect(30, 40), 0, 0, 0, 0); | 1243 TestIterateAll(big_border, gfx::Rect(30, 40), 0, 0, 0, 0); |
1244 TestIterateAll(big_border, gfx::Rect(10, 10, 20, 20), 0, 0, 0, 0); | 1244 TestIterateAll(big_border, gfx::Rect(10, 10, 20, 20), 0, 0, 0, 0); |
1245 TestIterateAll(big_border, gfx::Rect(30, 40, 100, 100), 0, 0, -1, -1); | 1245 TestIterateAll(big_border, gfx::Rect(30, 40, 100, 100), 0, 0, -1, -1); |
1246 } | 1246 } |
1247 | 1247 |
1248 TEST(TilingDataTest, IteratorNoTiles) { | 1248 TEST(TilingDataTest, IteratorNoTiles) { |
1249 TilingData data(gfx::Size(100, 100), gfx::Size(), false); | 1249 TilingData data(gfx::Size(100, 100), gfx::Size(), false); |
1250 TestIterateAll(data, gfx::Rect(100, 100), 0, 0, -1, -1); | 1250 TestIterateAll(data, gfx::Rect(100, 100), 0, 0, -1, -1); |
1251 } | 1251 } |
1252 | 1252 |
1253 void TestDiff( | 1253 void TestDiff(const TilingData& data, |
1254 const TilingData& data, | 1254 gfx::Rect consider, |
1255 gfx::Rect consider, | 1255 gfx::Rect ignore, |
1256 gfx::Rect ignore, | 1256 size_t num_tiles) { |
1257 size_t num_tiles) { | |
1258 | |
1259 std::vector<std::pair<int, int> > expected; | 1257 std::vector<std::pair<int, int> > expected; |
1260 for (int y = 0; y < data.num_tiles_y(); ++y) { | 1258 for (int y = 0; y < data.num_tiles_y(); ++y) { |
1261 for (int x = 0; x < data.num_tiles_x(); ++x) { | 1259 for (int x = 0; x < data.num_tiles_x(); ++x) { |
1262 gfx::Rect bounds = data.TileBoundsWithBorder(x, y); | 1260 gfx::Rect bounds = data.TileBounds(x, y); |
1263 if (bounds.Intersects(consider) && !bounds.Intersects(ignore)) | 1261 if (bounds.Intersects(consider) && !bounds.Intersects(ignore)) |
1264 expected.push_back(std::make_pair(x, y)); | 1262 expected.push_back(std::make_pair(x, y)); |
1265 } | 1263 } |
1266 } | 1264 } |
1267 | 1265 |
1268 // Sanity check the test. | 1266 // Sanity check the test. |
1269 EXPECT_EQ(num_tiles, expected.size()); | 1267 EXPECT_EQ(num_tiles, expected.size()); |
1270 | 1268 |
1271 for (TilingData::DifferenceIterator iter(&data, consider, ignore); | 1269 for (TilingData::DifferenceIterator iter(&data, consider, ignore); iter; |
1272 iter; ++iter) { | 1270 ++iter) { |
1273 bool found = false; | 1271 bool found = false; |
1274 for (size_t i = 0; i < expected.size(); ++i) { | 1272 for (size_t i = 0; i < expected.size(); ++i) { |
1275 if (expected[i] == iter.index()) { | 1273 if (expected[i] == iter.index()) { |
1276 expected[i] = expected.back(); | 1274 expected[i] = expected.back(); |
1277 expected.pop_back(); | 1275 expected.pop_back(); |
1278 found = true; | 1276 found = true; |
1279 break; | 1277 break; |
1280 } | 1278 } |
1281 } | 1279 } |
1282 EXPECT_TRUE(found); | 1280 EXPECT_TRUE(found); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1332 // Non-intersecting, but still touching two of the same tiles. | 1330 // Non-intersecting, but still touching two of the same tiles. |
1333 TestDiff(data, gfx::Rect(8, 0, 32, 25), gfx::Rect(0, 12, 5, 12), 10); | 1331 TestDiff(data, gfx::Rect(8, 0, 32, 25), gfx::Rect(0, 12, 5, 12), 10); |
1334 | 1332 |
1335 // Intersecting, but neither contains the other. 2x3 with one overlap. | 1333 // Intersecting, but neither contains the other. 2x3 with one overlap. |
1336 TestDiff(data, gfx::Rect(5, 2, 20, 10), gfx::Rect(25, 15, 5, 10), 5); | 1334 TestDiff(data, gfx::Rect(5, 2, 20, 10), gfx::Rect(25, 15, 5, 10), 5); |
1337 } | 1335 } |
1338 | 1336 |
1339 TEST(TilingDataTest, DifferenceIteratorManyBorderTexels) { | 1337 TEST(TilingDataTest, DifferenceIteratorManyBorderTexels) { |
1340 // X border index by src coord: [0-50), [10-60), [20-65) | 1338 // X border index by src coord: [0-50), [10-60), [20-65) |
1341 // Y border index by src coord: [0-60), [20-80), [40-100), [60-110) | 1339 // Y border index by src coord: [0-60), [20-80), [40-100), [60-110) |
| 1340 // X tile bounds by src coord: [0-30), [30-40), [40-65) |
| 1341 // Y tile bounds by src coord: [0-40), [40-60), [60-80), [80-110) |
1342 TilingData data(gfx::Size(50, 60), gfx::Size(65, 110), 20); | 1342 TilingData data(gfx::Size(50, 60), gfx::Size(65, 110), 20); |
1343 | 1343 |
1344 // Ignore one column, three rows | 1344 // Knock out two rows, but not the left column. |
1345 TestDiff(data, gfx::Rect(0, 30, 55, 80), gfx::Rect(5, 30, 5, 15), 9); | 1345 TestDiff(data, gfx::Rect(10, 30, 55, 80), gfx::Rect(30, 59, 20, 2), 8); |
1346 | 1346 |
1347 // Knock out three columns, leaving only one. | 1347 // Knock out one row. |
1348 TestDiff(data, gfx::Rect(10, 30, 55, 80), gfx::Rect(30, 59, 20, 1), 3); | 1348 TestDiff(data, gfx::Rect(10, 30, 55, 80), gfx::Rect(29, 59, 20, 1), 9); |
1349 | 1349 |
1350 // Overlap all tiles with ignore rect. | 1350 // Overlap all tiles with ignore rect. |
1351 TestDiff(data, gfx::Rect(65, 110), gfx::Rect(30, 59, 1, 2), 0); | 1351 TestDiff(data, gfx::Rect(65, 110), gfx::Rect(29, 39, 12, 42), 0); |
| 1352 |
| 1353 gfx::Rect tile = data.TileBounds(1, 1); |
| 1354 |
| 1355 // Ignore one tile. |
| 1356 TestDiff(data, gfx::Rect(20, 30, 45, 80), tile, 11); |
| 1357 |
| 1358 // Include one tile. |
| 1359 TestDiff(data, tile, gfx::Rect(), 1); |
1352 } | 1360 } |
1353 | 1361 |
1354 TEST(TilingDataTest, DifferenceIteratorOneTile) { | 1362 TEST(TilingDataTest, DifferenceIteratorOneTile) { |
1355 TilingData no_border(gfx::Size(1000, 1000), gfx::Size(30, 40), false); | 1363 TilingData no_border(gfx::Size(1000, 1000), gfx::Size(30, 40), false); |
1356 TestDiff(no_border, gfx::Rect(30, 40), gfx::Rect(), 1); | 1364 TestDiff(no_border, gfx::Rect(30, 40), gfx::Rect(), 1); |
1357 TestDiff(no_border, gfx::Rect(5, 5, 100, 100), gfx::Rect(5, 5, 1, 1), 0); | 1365 TestDiff(no_border, gfx::Rect(5, 5, 100, 100), gfx::Rect(5, 5, 1, 1), 0); |
1358 | 1366 |
1359 TilingData one_border(gfx::Size(1000, 1000), gfx::Size(30, 40), true); | 1367 TilingData one_border(gfx::Size(1000, 1000), gfx::Size(30, 40), true); |
1360 TestDiff(one_border, gfx::Rect(30, 40), gfx::Rect(), 1); | 1368 TestDiff(one_border, gfx::Rect(30, 40), gfx::Rect(), 1); |
1361 TestDiff(one_border, gfx::Rect(5, 5, 100, 100), gfx::Rect(5, 5, 1, 1), 0); | 1369 TestDiff(one_border, gfx::Rect(5, 5, 100, 100), gfx::Rect(5, 5, 1, 1), 0); |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1933 expected.push_back(std::make_pair(2, 2)); | 1941 expected.push_back(std::make_pair(2, 2)); |
1934 expected.push_back(std::make_pair(2, 1)); | 1942 expected.push_back(std::make_pair(2, 1)); |
1935 expected.push_back(std::make_pair(2, 0)); | 1943 expected.push_back(std::make_pair(2, 0)); |
1936 | 1944 |
1937 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected); | 1945 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected); |
1938 } | 1946 } |
1939 | 1947 |
1940 } // namespace | 1948 } // namespace |
1941 | 1949 |
1942 } // namespace cc | 1950 } // namespace cc |
OLD | NEW |