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 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 int expect_left, | 1031 int expect_left, |
1032 int expect_top, | 1032 int expect_top, |
1033 int expect_right, | 1033 int expect_right, |
1034 int expect_bottom, | 1034 int expect_bottom, |
1035 bool include_borders) { | 1035 bool include_borders) { |
1036 EXPECT_GE(expect_left, 0); | 1036 EXPECT_GE(expect_left, 0); |
1037 EXPECT_GE(expect_top, 0); | 1037 EXPECT_GE(expect_top, 0); |
1038 EXPECT_LT(expect_right, data.num_tiles_x()); | 1038 EXPECT_LT(expect_right, data.num_tiles_x()); |
1039 EXPECT_LT(expect_bottom, data.num_tiles_y()); | 1039 EXPECT_LT(expect_bottom, data.num_tiles_y()); |
1040 | 1040 |
1041 std::vector<std::pair<int, int> > original_expected; | 1041 std::vector<std::pair<int, int>> original_expected; |
1042 for (int x = 0; x < data.num_tiles_x(); ++x) { | 1042 for (int x = 0; x < data.num_tiles_x(); ++x) { |
1043 for (int y = 0; y < data.num_tiles_y(); ++y) { | 1043 for (int y = 0; y < data.num_tiles_y(); ++y) { |
1044 gfx::Rect bounds; | 1044 gfx::Rect bounds; |
1045 if (include_borders) | 1045 if (include_borders) |
1046 bounds = data.TileBoundsWithBorder(x, y); | 1046 bounds = data.TileBoundsWithBorder(x, y); |
1047 else | 1047 else |
1048 bounds = data.TileBounds(x, y); | 1048 bounds = data.TileBounds(x, y); |
1049 if (x >= expect_left && x <= expect_right && | 1049 if (x >= expect_left && x <= expect_right && |
1050 y >= expect_top && y <= expect_bottom) { | 1050 y >= expect_top && y <= expect_bottom) { |
1051 EXPECT_TRUE(bounds.Intersects(rect)); | 1051 EXPECT_TRUE(bounds.Intersects(rect)); |
1052 original_expected.push_back(std::make_pair(x, y)); | 1052 original_expected.push_back(std::make_pair(x, y)); |
1053 } else { | 1053 } else { |
1054 EXPECT_FALSE(bounds.Intersects(rect)); | 1054 EXPECT_FALSE(bounds.Intersects(rect)); |
1055 } | 1055 } |
1056 } | 1056 } |
1057 } | 1057 } |
1058 | 1058 |
1059 // Verify with vanilla iterator. | 1059 // Verify with vanilla iterator. |
1060 { | 1060 { |
1061 std::vector<std::pair<int, int> > expected = original_expected; | 1061 std::vector<std::pair<int, int>> expected = original_expected; |
1062 for (TilingData::Iterator iter(&data, rect, include_borders); iter; | 1062 for (TilingData::Iterator iter(&data, rect, include_borders); iter; |
1063 ++iter) { | 1063 ++iter) { |
1064 bool found = false; | 1064 bool found = false; |
1065 for (size_t i = 0; i < expected.size(); ++i) { | 1065 for (size_t i = 0; i < expected.size(); ++i) { |
1066 if (expected[i] == iter.index()) { | 1066 if (expected[i] == iter.index()) { |
1067 expected[i] = expected.back(); | 1067 expected[i] = expected.back(); |
1068 expected.pop_back(); | 1068 expected.pop_back(); |
1069 found = true; | 1069 found = true; |
1070 break; | 1070 break; |
1071 } | 1071 } |
1072 } | 1072 } |
1073 EXPECT_TRUE(found); | 1073 EXPECT_TRUE(found); |
1074 } | 1074 } |
1075 EXPECT_EQ(0u, expected.size()); | 1075 EXPECT_EQ(0u, expected.size()); |
1076 } | 1076 } |
1077 | 1077 |
1078 // Make sure this also works with a difference iterator and an empty ignore. | 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. | 1079 // The difference iterator never includes borders, so ignore it otherwise. |
1080 if (!include_borders) { | 1080 if (!include_borders) { |
1081 std::vector<std::pair<int, int> > expected = original_expected; | 1081 std::vector<std::pair<int, int>> expected = original_expected; |
1082 for (TilingData::DifferenceIterator iter(&data, rect, gfx::Rect()); iter; | 1082 for (TilingData::DifferenceIterator iter(&data, rect, gfx::Rect()); iter; |
1083 ++iter) { | 1083 ++iter) { |
1084 bool found = false; | 1084 bool found = false; |
1085 for (size_t i = 0; i < expected.size(); ++i) { | 1085 for (size_t i = 0; i < expected.size(); ++i) { |
1086 if (expected[i] == iter.index()) { | 1086 if (expected[i] == iter.index()) { |
1087 expected[i] = expected.back(); | 1087 expected[i] = expected.back(); |
1088 expected.pop_back(); | 1088 expected.pop_back(); |
1089 found = true; | 1089 found = true; |
1090 break; | 1090 break; |
1091 } | 1091 } |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1237 | 1237 |
1238 TEST(TilingDataTest, IteratorNoTiles) { | 1238 TEST(TilingDataTest, IteratorNoTiles) { |
1239 TilingData data(gfx::Size(100, 100), gfx::Size(), false); | 1239 TilingData data(gfx::Size(100, 100), gfx::Size(), false); |
1240 TestIterateAll(data, gfx::Rect(100, 100), 0, 0, -1, -1); | 1240 TestIterateAll(data, gfx::Rect(100, 100), 0, 0, -1, -1); |
1241 } | 1241 } |
1242 | 1242 |
1243 void TestDiff(const TilingData& data, | 1243 void TestDiff(const TilingData& data, |
1244 gfx::Rect consider, | 1244 gfx::Rect consider, |
1245 gfx::Rect ignore, | 1245 gfx::Rect ignore, |
1246 size_t num_tiles) { | 1246 size_t num_tiles) { |
1247 std::vector<std::pair<int, int> > expected; | 1247 std::vector<std::pair<int, int>> expected; |
1248 for (int y = 0; y < data.num_tiles_y(); ++y) { | 1248 for (int y = 0; y < data.num_tiles_y(); ++y) { |
1249 for (int x = 0; x < data.num_tiles_x(); ++x) { | 1249 for (int x = 0; x < data.num_tiles_x(); ++x) { |
1250 gfx::Rect bounds = data.TileBounds(x, y); | 1250 gfx::Rect bounds = data.TileBounds(x, y); |
1251 if (bounds.Intersects(consider) && !bounds.Intersects(ignore)) | 1251 if (bounds.Intersects(consider) && !bounds.Intersects(ignore)) |
1252 expected.push_back(std::make_pair(x, y)); | 1252 expected.push_back(std::make_pair(x, y)); |
1253 } | 1253 } |
1254 } | 1254 } |
1255 | 1255 |
1256 // Sanity check the test. | 1256 // Sanity check the test. |
1257 EXPECT_EQ(num_tiles, expected.size()); | 1257 EXPECT_EQ(num_tiles, expected.size()); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1366 TEST(TilingDataTest, DifferenceIteratorNoTiles) { | 1366 TEST(TilingDataTest, DifferenceIteratorNoTiles) { |
1367 TilingData data(gfx::Size(100, 100), gfx::Size(), false); | 1367 TilingData data(gfx::Size(100, 100), gfx::Size(), false); |
1368 TestDiff(data, gfx::Rect(100, 100), gfx::Rect(5, 5), 0); | 1368 TestDiff(data, gfx::Rect(100, 100), gfx::Rect(5, 5), 0); |
1369 } | 1369 } |
1370 | 1370 |
1371 void TestSpiralIterate(int source_line_number, | 1371 void TestSpiralIterate(int source_line_number, |
1372 const TilingData& tiling_data, | 1372 const TilingData& tiling_data, |
1373 const gfx::Rect& consider, | 1373 const gfx::Rect& consider, |
1374 const gfx::Rect& ignore, | 1374 const gfx::Rect& ignore, |
1375 const gfx::Rect& center, | 1375 const gfx::Rect& center, |
1376 const std::vector<std::pair<int, int> >& expected) { | 1376 const std::vector<std::pair<int, int>>& expected) { |
1377 std::vector<std::pair<int, int> > actual; | 1377 std::vector<std::pair<int, int>> actual; |
1378 for (TilingData::SpiralDifferenceIterator it( | 1378 for (TilingData::SpiralDifferenceIterator it( |
1379 &tiling_data, consider, ignore, center); | 1379 &tiling_data, consider, ignore, center); |
1380 it; | 1380 it; |
1381 ++it) { | 1381 ++it) { |
1382 actual.push_back(it.index()); | 1382 actual.push_back(it.index()); |
1383 } | 1383 } |
1384 | 1384 |
1385 EXPECT_EQ(expected.size(), actual.size()) << "error from line " | 1385 EXPECT_EQ(expected.size(), actual.size()) << "error from line " |
1386 << source_line_number; | 1386 << source_line_number; |
1387 for (size_t i = 0; i < std::min(expected.size(), actual.size()); ++i) { | 1387 for (size_t i = 0; i < std::min(expected.size(), actual.size()); ++i) { |
1388 EXPECT_EQ(expected[i].first, actual[i].first) | 1388 EXPECT_EQ(expected[i].first, actual[i].first) |
1389 << "i: " << i << " error from line: " << source_line_number; | 1389 << "i: " << i << " error from line: " << source_line_number; |
1390 EXPECT_EQ(expected[i].second, actual[i].second) | 1390 EXPECT_EQ(expected[i].second, actual[i].second) |
1391 << "i: " << i << " error from line: " << source_line_number; | 1391 << "i: " << i << " error from line: " << source_line_number; |
1392 } | 1392 } |
1393 } | 1393 } |
1394 | 1394 |
1395 TEST(TilingDataTest, SpiralDifferenceIteratorNoIgnoreFullConsider) { | 1395 TEST(TilingDataTest, SpiralDifferenceIteratorNoIgnoreFullConsider) { |
1396 TilingData tiling_data(gfx::Size(10, 10), gfx::Size(30, 30), false); | 1396 TilingData tiling_data(gfx::Size(10, 10), gfx::Size(30, 30), false); |
1397 gfx::Rect consider(30, 30); | 1397 gfx::Rect consider(30, 30); |
1398 gfx::Rect ignore; | 1398 gfx::Rect ignore; |
1399 std::vector<std::pair<int, int> > expected; | 1399 std::vector<std::pair<int, int>> expected; |
1400 | 1400 |
1401 // Center is in the center of the tiling. | 1401 // Center is in the center of the tiling. |
1402 gfx::Rect center(15, 15, 1, 1); | 1402 gfx::Rect center(15, 15, 1, 1); |
1403 | 1403 |
1404 // Layout of the tiling data, and expected return order: | 1404 // Layout of the tiling data, and expected return order: |
1405 // x 0 1 2 | 1405 // x 0 1 2 |
1406 // y.------ | 1406 // y.------ |
1407 // 0| 4 3 2 | 1407 // 0| 4 3 2 |
1408 // 1| 5 * 1 | 1408 // 1| 5 * 1 |
1409 // 2| 6 7 8 | 1409 // 2| 6 7 8 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1500 expected.push_back(std::make_pair(0, 0)); | 1500 expected.push_back(std::make_pair(0, 0)); |
1501 expected.push_back(std::make_pair(0, 1)); | 1501 expected.push_back(std::make_pair(0, 1)); |
1502 expected.push_back(std::make_pair(0, 2)); | 1502 expected.push_back(std::make_pair(0, 2)); |
1503 | 1503 |
1504 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected); | 1504 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected); |
1505 } | 1505 } |
1506 | 1506 |
1507 TEST(TilingDataTest, SpiralDifferenceIteratorSmallConsider) { | 1507 TEST(TilingDataTest, SpiralDifferenceIteratorSmallConsider) { |
1508 TilingData tiling_data(gfx::Size(10, 10), gfx::Size(50, 50), false); | 1508 TilingData tiling_data(gfx::Size(10, 10), gfx::Size(50, 50), false); |
1509 gfx::Rect ignore; | 1509 gfx::Rect ignore; |
1510 std::vector<std::pair<int, int> > expected; | 1510 std::vector<std::pair<int, int>> expected; |
1511 gfx::Rect center(15, 15, 1, 1); | 1511 gfx::Rect center(15, 15, 1, 1); |
1512 | 1512 |
1513 // Consider is one cell. | 1513 // Consider is one cell. |
1514 gfx::Rect consider(1, 1); | 1514 gfx::Rect consider(1, 1); |
1515 | 1515 |
1516 // Layout of the tiling data, and expected return order: | 1516 // Layout of the tiling data, and expected return order: |
1517 // x 0 1 2 3 4 | 1517 // x 0 1 2 3 4 |
1518 // y.---------- | 1518 // y.---------- |
1519 // 0| 1 | 1519 // 0| 1 |
1520 // 1| * | 1520 // 1| * |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1560 expected.push_back(std::make_pair(1, 2)); | 1560 expected.push_back(std::make_pair(1, 2)); |
1561 expected.push_back(std::make_pair(1, 3)); | 1561 expected.push_back(std::make_pair(1, 3)); |
1562 expected.push_back(std::make_pair(1, 4)); | 1562 expected.push_back(std::make_pair(1, 4)); |
1563 | 1563 |
1564 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected); | 1564 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected); |
1565 } | 1565 } |
1566 | 1566 |
1567 TEST(TilingDataTest, SpiralDifferenceIteratorHasIgnore) { | 1567 TEST(TilingDataTest, SpiralDifferenceIteratorHasIgnore) { |
1568 TilingData tiling_data(gfx::Size(10, 10), gfx::Size(50, 50), false); | 1568 TilingData tiling_data(gfx::Size(10, 10), gfx::Size(50, 50), false); |
1569 gfx::Rect consider(50, 50); | 1569 gfx::Rect consider(50, 50); |
1570 std::vector<std::pair<int, int> > expected; | 1570 std::vector<std::pair<int, int>> expected; |
1571 gfx::Rect center(15, 15, 1, 1); | 1571 gfx::Rect center(15, 15, 1, 1); |
1572 | 1572 |
1573 // Full ignore. | 1573 // Full ignore. |
1574 gfx::Rect ignore(50, 50); | 1574 gfx::Rect ignore(50, 50); |
1575 | 1575 |
1576 // Layout of the tiling data, and expected return order: | 1576 // Layout of the tiling data, and expected return order: |
1577 // x 0 1 2 3 4 | 1577 // x 0 1 2 3 4 |
1578 // y.---------- | 1578 // y.---------- |
1579 // 0| . . . . . | 1579 // 0| . . . . . |
1580 // 1| . * . . . | 1580 // 1| . * . . . |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1634 expected.push_back(std::make_pair(2, 4)); | 1634 expected.push_back(std::make_pair(2, 4)); |
1635 expected.push_back(std::make_pair(3, 4)); | 1635 expected.push_back(std::make_pair(3, 4)); |
1636 expected.push_back(std::make_pair(4, 4)); | 1636 expected.push_back(std::make_pair(4, 4)); |
1637 | 1637 |
1638 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected); | 1638 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected); |
1639 } | 1639 } |
1640 | 1640 |
1641 TEST(TilingDataTest, SpiralDifferenceIteratorRectangleCenter) { | 1641 TEST(TilingDataTest, SpiralDifferenceIteratorRectangleCenter) { |
1642 TilingData tiling_data(gfx::Size(10, 10), gfx::Size(50, 50), false); | 1642 TilingData tiling_data(gfx::Size(10, 10), gfx::Size(50, 50), false); |
1643 gfx::Rect consider(50, 50); | 1643 gfx::Rect consider(50, 50); |
1644 std::vector<std::pair<int, int> > expected; | 1644 std::vector<std::pair<int, int>> expected; |
1645 gfx::Rect ignore; | 1645 gfx::Rect ignore; |
1646 | 1646 |
1647 // Two cell center | 1647 // Two cell center |
1648 gfx::Rect center(25, 25, 1, 10); | 1648 gfx::Rect center(25, 25, 1, 10); |
1649 | 1649 |
1650 // Layout of the tiling data, and expected return order: | 1650 // Layout of the tiling data, and expected return order: |
1651 // x 0 1 2 3 4 | 1651 // x 0 1 2 3 4 |
1652 // y.---------- | 1652 // y.---------- |
1653 // 0| J I H G F | 1653 // 0| J I H G F |
1654 // 1| K 5 4 3 E | 1654 // 1| K 5 4 3 E |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1755 expected.push_back(std::make_pair(4, 3)); | 1755 expected.push_back(std::make_pair(4, 3)); |
1756 expected.push_back(std::make_pair(4, 2)); | 1756 expected.push_back(std::make_pair(4, 2)); |
1757 expected.push_back(std::make_pair(4, 1)); | 1757 expected.push_back(std::make_pair(4, 1)); |
1758 expected.push_back(std::make_pair(4, 0)); | 1758 expected.push_back(std::make_pair(4, 0)); |
1759 | 1759 |
1760 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected); | 1760 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected); |
1761 } | 1761 } |
1762 | 1762 |
1763 TEST(TilingDataTest, SpiralDifferenceIteratorEdgeCases) { | 1763 TEST(TilingDataTest, SpiralDifferenceIteratorEdgeCases) { |
1764 TilingData tiling_data(gfx::Size(10, 10), gfx::Size(30, 30), false); | 1764 TilingData tiling_data(gfx::Size(10, 10), gfx::Size(30, 30), false); |
1765 std::vector<std::pair<int, int> > expected; | 1765 std::vector<std::pair<int, int>> expected; |
1766 gfx::Rect center; | 1766 gfx::Rect center; |
1767 gfx::Rect consider; | 1767 gfx::Rect consider; |
1768 gfx::Rect ignore; | 1768 gfx::Rect ignore; |
1769 | 1769 |
1770 // Ignore contains, but is not equal to, consider and center. | 1770 // Ignore contains, but is not equal to, consider and center. |
1771 ignore = gfx::Rect(15, 0, 20, 30); | 1771 ignore = gfx::Rect(15, 0, 20, 30); |
1772 consider = gfx::Rect(20, 10, 10, 20); | 1772 consider = gfx::Rect(20, 10, 10, 20); |
1773 center = gfx::Rect(25, 0, 5, 5); | 1773 center = gfx::Rect(25, 0, 5, 5); |
1774 | 1774 |
1775 // Layout of the tiling data, and expected return order: | 1775 // Layout of the tiling data, and expected return order: |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1931 expected.push_back(std::make_pair(2, 2)); | 1931 expected.push_back(std::make_pair(2, 2)); |
1932 expected.push_back(std::make_pair(2, 1)); | 1932 expected.push_back(std::make_pair(2, 1)); |
1933 expected.push_back(std::make_pair(2, 0)); | 1933 expected.push_back(std::make_pair(2, 0)); |
1934 | 1934 |
1935 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected); | 1935 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected); |
1936 } | 1936 } |
1937 | 1937 |
1938 } // namespace | 1938 } // namespace |
1939 | 1939 |
1940 } // namespace cc | 1940 } // namespace cc |
OLD | NEW |