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 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 EXPECT_EQ(gfx::Size(5, 5), data.max_texture_size()); | 766 EXPECT_EQ(gfx::Size(5, 5), data.max_texture_size()); |
767 EXPECT_EQ(5, data.num_tiles_x()); | 767 EXPECT_EQ(5, data.num_tiles_x()); |
768 EXPECT_EQ(10, data.num_tiles_y()); | 768 EXPECT_EQ(10, data.num_tiles_y()); |
769 | 769 |
770 data.SetMaxTextureSize(gfx::Size(8, 5)); | 770 data.SetMaxTextureSize(gfx::Size(8, 5)); |
771 EXPECT_EQ(gfx::Size(8, 5), data.max_texture_size()); | 771 EXPECT_EQ(gfx::Size(8, 5), data.max_texture_size()); |
772 EXPECT_EQ(3, data.num_tiles_x()); | 772 EXPECT_EQ(3, data.num_tiles_x()); |
773 EXPECT_EQ(10, data.num_tiles_y()); | 773 EXPECT_EQ(10, data.num_tiles_y()); |
774 } | 774 } |
775 | 775 |
776 TEST(TilingDataTest, ExpandRectIgnoringBordersToTileBoundsWithBordersEmpty) { | 776 TEST(TilingDataTest, ExpandRectIgnoringBordersToTileBoundsEmpty) { |
777 TilingData empty_total_size(gfx::Size(0, 0), gfx::Size(8, 8), true); | 777 TilingData empty_total_size(gfx::Size(0, 0), gfx::Size(8, 8), true); |
778 EXPECT_RECT_EQ( | 778 EXPECT_RECT_EQ( |
779 gfx::Rect(), | 779 gfx::Rect(), |
780 empty_total_size.ExpandRectIgnoringBordersToTileBoundsWithBorders( | 780 empty_total_size.ExpandRectIgnoringBordersToTileBounds(gfx::Rect())); |
781 gfx::Rect())); | 781 EXPECT_RECT_EQ(gfx::Rect(), |
782 EXPECT_RECT_EQ( | 782 empty_total_size.ExpandRectIgnoringBordersToTileBounds( |
783 gfx::Rect(), | 783 gfx::Rect(100, 100, 100, 100))); |
784 empty_total_size.ExpandRectIgnoringBordersToTileBoundsWithBorders( | 784 EXPECT_RECT_EQ(gfx::Rect(), |
785 gfx::Rect(100, 100, 100, 100))); | 785 empty_total_size.ExpandRectIgnoringBordersToTileBounds( |
786 EXPECT_RECT_EQ( | 786 gfx::Rect(100, 100))); |
787 gfx::Rect(), | |
788 empty_total_size.ExpandRectIgnoringBordersToTileBoundsWithBorders( | |
789 gfx::Rect(100, 100))); | |
790 | 787 |
791 TilingData empty_max_texture_size(gfx::Size(8, 8), gfx::Size(0, 0), true); | 788 TilingData empty_max_texture_size(gfx::Size(8, 8), gfx::Size(0, 0), true); |
792 EXPECT_RECT_EQ( | 789 EXPECT_RECT_EQ(gfx::Rect(), |
793 gfx::Rect(), | 790 empty_max_texture_size.ExpandRectIgnoringBordersToTileBounds( |
794 empty_max_texture_size.ExpandRectIgnoringBordersToTileBoundsWithBorders( | 791 gfx::Rect())); |
795 gfx::Rect())); | 792 EXPECT_RECT_EQ(gfx::Rect(), |
796 EXPECT_RECT_EQ( | 793 empty_max_texture_size.ExpandRectIgnoringBordersToTileBounds( |
797 gfx::Rect(), | 794 gfx::Rect(100, 100, 100, 100))); |
798 empty_max_texture_size.ExpandRectIgnoringBordersToTileBoundsWithBorders( | 795 EXPECT_RECT_EQ(gfx::Rect(), |
799 gfx::Rect(100, 100, 100, 100))); | 796 empty_max_texture_size.ExpandRectIgnoringBordersToTileBounds( |
800 EXPECT_RECT_EQ( | 797 gfx::Rect(100, 100))); |
801 gfx::Rect(), | |
802 empty_max_texture_size.ExpandRectIgnoringBordersToTileBoundsWithBorders( | |
803 gfx::Rect(100, 100))); | |
804 } | 798 } |
805 | 799 |
806 TEST(TilingDataTest, ExpandRectIgnoringBordersToTileBoundsWithBorders) { | 800 TEST(TilingDataTest, ExpandRectIgnoringBordersToTileBounds) { |
807 TilingData data(gfx::Size(4, 4), gfx::Size(16, 32), true); | 801 TilingData data(gfx::Size(4, 4), gfx::Size(16, 32), true); |
808 | 802 |
809 // Small rect at origin rounds up to tile 0, 0. | 803 // Small rect at origin rounds up to tile 0, 0. |
810 gfx::Rect at_origin_src(1, 1); | 804 gfx::Rect at_origin_src(1, 1); |
811 gfx::Rect at_origin_result(data.TileBoundsWithBorder(0, 0)); | 805 gfx::Rect at_origin_result(data.TileBounds(0, 0)); |
812 EXPECT_NE(at_origin_src, at_origin_result); | 806 EXPECT_NE(at_origin_src, at_origin_result); |
813 EXPECT_RECT_EQ( | 807 EXPECT_RECT_EQ(at_origin_result, |
814 at_origin_result, | 808 data.ExpandRectIgnoringBordersToTileBounds(at_origin_src)); |
815 data.ExpandRectIgnoringBordersToTileBoundsWithBorders(at_origin_src)); | |
816 | 809 |
817 // Arbitrary internal rect. | 810 // Arbitrary internal rect. |
818 gfx::Rect rect_src(6, 6, 1, 3); | 811 gfx::Rect rect_src(6, 6, 1, 3); |
819 // Tile 2, 2 => gfx::Rect(4, 4, 4, 4) | 812 // Tile 2, 2 => gfx::Rect(4, 4, 4, 4) |
820 // Tile 2, 3 => gfx::Rect(4, 6, 4, 4) | 813 // Tile 2, 3 => gfx::Rect(4, 6, 4, 4) |
821 gfx::Rect rect_result(gfx::UnionRects(data.TileBoundsWithBorder(2, 2), | 814 gfx::Rect rect_result( |
822 data.TileBoundsWithBorder(2, 3))); | 815 gfx::UnionRects(data.TileBounds(2, 2), data.TileBounds(2, 3))); |
823 EXPECT_NE(rect_src, rect_result); | 816 EXPECT_NE(rect_src, rect_result); |
824 EXPECT_RECT_EQ( | 817 EXPECT_RECT_EQ(rect_result, |
825 rect_result, | 818 data.ExpandRectIgnoringBordersToTileBounds(rect_src)); |
826 data.ExpandRectIgnoringBordersToTileBoundsWithBorders(rect_src)); | |
827 | 819 |
828 // On tile bounds does not round up to next tile (ignores the border). | 820 // On tile bounds does not round up to next tile (ignores the border). |
829 gfx::Rect border_rect_src( | 821 gfx::Rect border_rect_src( |
830 gfx::UnionRects(data.TileBounds(1, 2), data.TileBounds(3, 4))); | 822 gfx::UnionRects(data.TileBounds(1, 2), data.TileBounds(3, 4))); |
831 gfx::Rect border_rect_result(gfx::UnionRects( | 823 gfx::Rect border_rect_result( |
832 data.TileBoundsWithBorder(1, 2), data.TileBoundsWithBorder(3, 4))); | 824 gfx::UnionRects(data.TileBounds(1, 2), data.TileBounds(3, 4))); |
833 EXPECT_RECT_EQ( | 825 EXPECT_RECT_EQ(border_rect_result, |
834 border_rect_result, | 826 data.ExpandRectIgnoringBordersToTileBounds(border_rect_src)); |
835 data.ExpandRectIgnoringBordersToTileBoundsWithBorders(border_rect_src)); | |
836 | 827 |
837 // Equal to tiling rect. | 828 // Equal to tiling rect. |
838 EXPECT_RECT_EQ(gfx::Rect(data.tiling_size()), | 829 EXPECT_RECT_EQ(gfx::Rect(data.tiling_size()), |
839 data.ExpandRectIgnoringBordersToTileBoundsWithBorders( | 830 data.ExpandRectIgnoringBordersToTileBounds( |
840 gfx::Rect(data.tiling_size()))); | 831 gfx::Rect(data.tiling_size()))); |
841 | 832 |
842 // Containing, but larger than tiling rect. | 833 // Containing, but larger than tiling rect. |
843 EXPECT_RECT_EQ(gfx::Rect(data.tiling_size()), | 834 EXPECT_RECT_EQ( |
844 data.ExpandRectIgnoringBordersToTileBoundsWithBorders( | 835 gfx::Rect(data.tiling_size()), |
845 gfx::Rect(100, 100))); | 836 data.ExpandRectIgnoringBordersToTileBounds(gfx::Rect(100, 100))); |
846 | 837 |
847 // Non-intersecting with tiling rect. | 838 // Non-intersecting with tiling rect. |
848 gfx::Rect non_intersect(200, 200, 100, 100); | 839 gfx::Rect non_intersect(200, 200, 100, 100); |
849 EXPECT_FALSE(non_intersect.Intersects(gfx::Rect(data.tiling_size()))); | 840 EXPECT_FALSE(non_intersect.Intersects(gfx::Rect(data.tiling_size()))); |
850 EXPECT_RECT_EQ( | 841 EXPECT_RECT_EQ(gfx::Rect(), |
851 gfx::Rect(), | 842 data.ExpandRectIgnoringBordersToTileBounds(non_intersect)); |
852 data.ExpandRectIgnoringBordersToTileBoundsWithBorders(non_intersect)); | |
853 | 843 |
854 TilingData data2(gfx::Size(8, 8), gfx::Size(32, 64), true); | 844 TilingData data2(gfx::Size(8, 8), gfx::Size(32, 64), true); |
855 | 845 |
856 // Inside other tile border texels doesn't include other tiles. | 846 // Inside other tile border texels doesn't include other tiles. |
857 gfx::Rect inner_rect_src(data2.TileBounds(1, 1)); | 847 gfx::Rect inner_rect_src(data2.TileBounds(1, 1)); |
858 inner_rect_src.Inset(data2.border_texels(), data.border_texels()); | 848 inner_rect_src.Inset(data2.border_texels(), data.border_texels()); |
859 gfx::Rect inner_rect_result(data2.TileBoundsWithBorder(1, 1)); | 849 gfx::Rect inner_rect_result(data2.TileBounds(1, 1)); |
860 gfx::Rect expanded = | 850 gfx::Rect expanded = |
861 data2.ExpandRectIgnoringBordersToTileBoundsWithBorders(inner_rect_src); | 851 data2.ExpandRectIgnoringBordersToTileBounds(inner_rect_src); |
862 EXPECT_EQ(inner_rect_result.ToString(), expanded.ToString()); | 852 EXPECT_EQ(inner_rect_result.ToString(), expanded.ToString()); |
863 } | 853 } |
864 | 854 |
865 TEST(TilingDataTest, ExpandRectToTileBounds) { | 855 TEST(TilingDataTest, ExpandRectToTileBounds) { |
866 TilingData data(gfx::Size(4, 4), gfx::Size(16, 32), true); | 856 TilingData data(gfx::Size(4, 4), gfx::Size(16, 32), true); |
867 | 857 |
868 // Small rect at origin rounds up to tile 0, 0. | 858 // Small rect at origin rounds up to tile 0, 0. |
869 gfx::Rect at_origin_src(1, 1); | 859 gfx::Rect at_origin_src(1, 1); |
870 gfx::Rect at_origin_result(data.TileBounds(0, 0)); | 860 gfx::Rect at_origin_result(data.TileBounds(0, 0)); |
871 EXPECT_NE(at_origin_src, at_origin_result); | 861 EXPECT_NE(at_origin_src, at_origin_result); |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1079 found = true; | 1069 found = true; |
1080 break; | 1070 break; |
1081 } | 1071 } |
1082 } | 1072 } |
1083 EXPECT_TRUE(found); | 1073 EXPECT_TRUE(found); |
1084 } | 1074 } |
1085 EXPECT_EQ(0u, expected.size()); | 1075 EXPECT_EQ(0u, expected.size()); |
1086 } | 1076 } |
1087 | 1077 |
1088 // 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. |
1089 // The difference iterator always includes borders, so ignore it otherwise. | 1079 // The difference iterator never includes borders, so ignore it otherwise. |
1090 if (include_borders) { | 1080 if (!include_borders) { |
1091 std::vector<std::pair<int, int> > expected = original_expected; | 1081 std::vector<std::pair<int, int> > expected = original_expected; |
1092 for (TilingData::DifferenceIterator iter(&data, rect, gfx::Rect()); | 1082 for (TilingData::DifferenceIterator iter(&data, rect, gfx::Rect()); iter; |
1093 iter; ++iter) { | 1083 ++iter) { |
1094 bool found = false; | 1084 bool found = false; |
1095 for (size_t i = 0; i < expected.size(); ++i) { | 1085 for (size_t i = 0; i < expected.size(); ++i) { |
1096 if (expected[i] == iter.index()) { | 1086 if (expected[i] == iter.index()) { |
1097 expected[i] = expected.back(); | 1087 expected[i] = expected.back(); |
1098 expected.pop_back(); | 1088 expected.pop_back(); |
1099 found = true; | 1089 found = true; |
1100 break; | 1090 break; |
1101 } | 1091 } |
1102 } | 1092 } |
1103 EXPECT_TRUE(found); | 1093 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); | 1233 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); | 1234 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); | 1235 TestIterateAll(big_border, gfx::Rect(30, 40, 100, 100), 0, 0, -1, -1); |
1246 } | 1236 } |
1247 | 1237 |
1248 TEST(TilingDataTest, IteratorNoTiles) { | 1238 TEST(TilingDataTest, IteratorNoTiles) { |
1249 TilingData data(gfx::Size(100, 100), gfx::Size(), false); | 1239 TilingData data(gfx::Size(100, 100), gfx::Size(), false); |
1250 TestIterateAll(data, gfx::Rect(100, 100), 0, 0, -1, -1); | 1240 TestIterateAll(data, gfx::Rect(100, 100), 0, 0, -1, -1); |
1251 } | 1241 } |
1252 | 1242 |
1253 void TestDiff( | 1243 void TestDiff(const TilingData& data, |
1254 const TilingData& data, | 1244 gfx::Rect consider, |
1255 gfx::Rect consider, | 1245 gfx::Rect ignore, |
1256 gfx::Rect ignore, | 1246 size_t num_tiles) { |
1257 size_t num_tiles) { | |
1258 | |
1259 std::vector<std::pair<int, int> > expected; | 1247 std::vector<std::pair<int, int> > expected; |
1260 for (int y = 0; y < data.num_tiles_y(); ++y) { | 1248 for (int y = 0; y < data.num_tiles_y(); ++y) { |
1261 for (int x = 0; x < data.num_tiles_x(); ++x) { | 1249 for (int x = 0; x < data.num_tiles_x(); ++x) { |
1262 gfx::Rect bounds = data.TileBoundsWithBorder(x, y); | 1250 gfx::Rect bounds = data.TileBounds(x, y); |
1263 if (bounds.Intersects(consider) && !bounds.Intersects(ignore)) | 1251 if (bounds.Intersects(consider) && !bounds.Intersects(ignore)) |
1264 expected.push_back(std::make_pair(x, y)); | 1252 expected.push_back(std::make_pair(x, y)); |
1265 } | 1253 } |
1266 } | 1254 } |
1267 | 1255 |
1268 // Sanity check the test. | 1256 // Sanity check the test. |
1269 EXPECT_EQ(num_tiles, expected.size()); | 1257 EXPECT_EQ(num_tiles, expected.size()); |
1270 | 1258 |
1271 for (TilingData::DifferenceIterator iter(&data, consider, ignore); | 1259 for (TilingData::DifferenceIterator iter(&data, consider, ignore); iter; |
1272 iter; ++iter) { | 1260 ++iter) { |
1273 bool found = false; | 1261 bool found = false; |
1274 for (size_t i = 0; i < expected.size(); ++i) { | 1262 for (size_t i = 0; i < expected.size(); ++i) { |
1275 if (expected[i] == iter.index()) { | 1263 if (expected[i] == iter.index()) { |
1276 expected[i] = expected.back(); | 1264 expected[i] = expected.back(); |
1277 expected.pop_back(); | 1265 expected.pop_back(); |
1278 found = true; | 1266 found = true; |
1279 break; | 1267 break; |
1280 } | 1268 } |
1281 } | 1269 } |
1282 EXPECT_TRUE(found); | 1270 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. | 1320 // 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); | 1321 TestDiff(data, gfx::Rect(8, 0, 32, 25), gfx::Rect(0, 12, 5, 12), 10); |
1334 | 1322 |
1335 // Intersecting, but neither contains the other. 2x3 with one overlap. | 1323 // 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); | 1324 TestDiff(data, gfx::Rect(5, 2, 20, 10), gfx::Rect(25, 15, 5, 10), 5); |
1337 } | 1325 } |
1338 | 1326 |
1339 TEST(TilingDataTest, DifferenceIteratorManyBorderTexels) { | 1327 TEST(TilingDataTest, DifferenceIteratorManyBorderTexels) { |
1340 // X border index by src coord: [0-50), [10-60), [20-65) | 1328 // 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) | 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) |
1342 TilingData data(gfx::Size(50, 60), gfx::Size(65, 110), 20); | 1332 TilingData data(gfx::Size(50, 60), gfx::Size(65, 110), 20); |
1343 | 1333 |
1344 // Ignore one column, three rows | 1334 // 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); | 1335 TestDiff(data, gfx::Rect(10, 30, 55, 80), gfx::Rect(30, 59, 20, 2), 8); |
1346 | 1336 |
1347 // Knock out three columns, leaving only one. | 1337 // Knock out one row. |
1348 TestDiff(data, gfx::Rect(10, 30, 55, 80), gfx::Rect(30, 59, 20, 1), 3); | 1338 TestDiff(data, gfx::Rect(10, 30, 55, 80), gfx::Rect(29, 59, 20, 1), 9); |
1349 | 1339 |
1350 // Overlap all tiles with ignore rect. | 1340 // Overlap all tiles with ignore rect. |
1351 TestDiff(data, gfx::Rect(65, 110), gfx::Rect(30, 59, 1, 2), 0); | 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); |
1352 } | 1350 } |
1353 | 1351 |
1354 TEST(TilingDataTest, DifferenceIteratorOneTile) { | 1352 TEST(TilingDataTest, DifferenceIteratorOneTile) { |
1355 TilingData no_border(gfx::Size(1000, 1000), gfx::Size(30, 40), false); | 1353 TilingData no_border(gfx::Size(1000, 1000), gfx::Size(30, 40), false); |
1356 TestDiff(no_border, gfx::Rect(30, 40), gfx::Rect(), 1); | 1354 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); | 1355 TestDiff(no_border, gfx::Rect(5, 5, 100, 100), gfx::Rect(5, 5, 1, 1), 0); |
1358 | 1356 |
1359 TilingData one_border(gfx::Size(1000, 1000), gfx::Size(30, 40), true); | 1357 TilingData one_border(gfx::Size(1000, 1000), gfx::Size(30, 40), true); |
1360 TestDiff(one_border, gfx::Rect(30, 40), gfx::Rect(), 1); | 1358 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); | 1359 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)); | 1931 expected.push_back(std::make_pair(2, 2)); |
1934 expected.push_back(std::make_pair(2, 1)); | 1932 expected.push_back(std::make_pair(2, 1)); |
1935 expected.push_back(std::make_pair(2, 0)); | 1933 expected.push_back(std::make_pair(2, 0)); |
1936 | 1934 |
1937 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected); | 1935 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected); |
1938 } | 1936 } |
1939 | 1937 |
1940 } // namespace | 1938 } // namespace |
1941 | 1939 |
1942 } // namespace cc | 1940 } // namespace cc |
OLD | NEW |