Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1017)

Side by Side Diff: cc/base/tiling_data_unittest.cc

Issue 202753002: cc: Add a tiling iterator that doesn't include borders (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove fprintf *innocent whistle* Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 895 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 EXPECT_EQ(1, data.LastBorderTileYIndexFromSrcCoord(20)); 906 EXPECT_EQ(1, data.LastBorderTileYIndexFromSrcCoord(20));
907 EXPECT_EQ(1, data.LastBorderTileYIndexFromSrcCoord(39)); 907 EXPECT_EQ(1, data.LastBorderTileYIndexFromSrcCoord(39));
908 EXPECT_EQ(2, data.LastBorderTileYIndexFromSrcCoord(40)); 908 EXPECT_EQ(2, data.LastBorderTileYIndexFromSrcCoord(40));
909 EXPECT_EQ(2, data.LastBorderTileYIndexFromSrcCoord(59)); 909 EXPECT_EQ(2, data.LastBorderTileYIndexFromSrcCoord(59));
910 EXPECT_EQ(3, data.LastBorderTileYIndexFromSrcCoord(60)); 910 EXPECT_EQ(3, data.LastBorderTileYIndexFromSrcCoord(60));
911 EXPECT_EQ(3, data.LastBorderTileYIndexFromSrcCoord(79)); 911 EXPECT_EQ(3, data.LastBorderTileYIndexFromSrcCoord(79));
912 EXPECT_EQ(4, data.LastBorderTileYIndexFromSrcCoord(80)); 912 EXPECT_EQ(4, data.LastBorderTileYIndexFromSrcCoord(80));
913 EXPECT_EQ(4, data.LastBorderTileYIndexFromSrcCoord(144)); 913 EXPECT_EQ(4, data.LastBorderTileYIndexFromSrcCoord(144));
914 } 914 }
915 915
916 void TestIterate( 916 void TestIterate(const TilingData& data,
917 const TilingData& data, 917 gfx::Rect rect,
918 gfx::Rect rect, 918 int expect_left,
919 int expect_left, 919 int expect_top,
920 int expect_top, 920 int expect_right,
921 int expect_right, 921 int expect_bottom,
922 int expect_bottom) { 922 bool include_borders) {
923
924 EXPECT_GE(expect_left, 0); 923 EXPECT_GE(expect_left, 0);
925 EXPECT_GE(expect_top, 0); 924 EXPECT_GE(expect_top, 0);
926 EXPECT_LT(expect_right, data.num_tiles_x()); 925 EXPECT_LT(expect_right, data.num_tiles_x());
927 EXPECT_LT(expect_bottom, data.num_tiles_y()); 926 EXPECT_LT(expect_bottom, data.num_tiles_y());
928 927
929 std::vector<std::pair<int, int> > original_expected; 928 std::vector<std::pair<int, int> > original_expected;
930 for (int x = 0; x < data.num_tiles_x(); ++x) { 929 for (int x = 0; x < data.num_tiles_x(); ++x) {
931 for (int y = 0; y < data.num_tiles_y(); ++y) { 930 for (int y = 0; y < data.num_tiles_y(); ++y) {
932 gfx::Rect bounds = data.TileBoundsWithBorder(x, y); 931 gfx::Rect bounds;
932 if (include_borders)
933 bounds = data.TileBoundsWithBorder(x, y);
934 else
935 bounds = data.TileBounds(x, y);
933 if (x >= expect_left && x <= expect_right && 936 if (x >= expect_left && x <= expect_right &&
934 y >= expect_top && y <= expect_bottom) { 937 y >= expect_top && y <= expect_bottom) {
935 EXPECT_TRUE(bounds.Intersects(rect)); 938 EXPECT_TRUE(bounds.Intersects(rect));
936 original_expected.push_back(std::make_pair(x, y)); 939 original_expected.push_back(std::make_pair(x, y));
937 } else { 940 } else {
938 EXPECT_FALSE(bounds.Intersects(rect)); 941 EXPECT_FALSE(bounds.Intersects(rect));
939 } 942 }
940 } 943 }
941 } 944 }
942 945
943 // Verify with vanilla iterator. 946 // Verify with vanilla iterator.
944 { 947 {
945 std::vector<std::pair<int, int> > expected = original_expected; 948 std::vector<std::pair<int, int> > expected = original_expected;
946 for (TilingData::Iterator iter(&data, rect); iter; ++iter) { 949 for (TilingData::Iterator iter(&data, rect, include_borders); iter;
950 ++iter) {
947 bool found = false; 951 bool found = false;
948 for (size_t i = 0; i < expected.size(); ++i) { 952 for (size_t i = 0; i < expected.size(); ++i) {
949 if (expected[i] == iter.index()) { 953 if (expected[i] == iter.index()) {
950 expected[i] = expected.back(); 954 expected[i] = expected.back();
951 expected.pop_back(); 955 expected.pop_back();
952 found = true; 956 found = true;
953 break; 957 break;
954 } 958 }
955 } 959 }
956 EXPECT_TRUE(found); 960 EXPECT_TRUE(found);
957 } 961 }
958 EXPECT_EQ(0u, expected.size()); 962 EXPECT_EQ(0u, expected.size());
959 } 963 }
960 964
961 // Make sure this also works with a difference iterator and an empty ignore. 965 // Make sure this also works with a difference iterator and an empty ignore.
962 { 966 // The difference iterator always includes borders, so ignore it otherwise.
967 if (include_borders) {
963 std::vector<std::pair<int, int> > expected = original_expected; 968 std::vector<std::pair<int, int> > expected = original_expected;
964 for (TilingData::DifferenceIterator iter(&data, rect, gfx::Rect()); 969 for (TilingData::DifferenceIterator iter(&data, rect, gfx::Rect());
965 iter; ++iter) { 970 iter; ++iter) {
966 bool found = false; 971 bool found = false;
967 for (size_t i = 0; i < expected.size(); ++i) { 972 for (size_t i = 0; i < expected.size(); ++i) {
968 if (expected[i] == iter.index()) { 973 if (expected[i] == iter.index()) {
969 expected[i] = expected.back(); 974 expected[i] = expected.back();
970 expected.pop_back(); 975 expected.pop_back();
971 found = true; 976 found = true;
972 break; 977 break;
973 } 978 }
974 } 979 }
975 EXPECT_TRUE(found); 980 EXPECT_TRUE(found);
976 } 981 }
977 EXPECT_EQ(0u, expected.size()); 982 EXPECT_EQ(0u, expected.size());
978 } 983 }
979 } 984 }
980 985
986 void TestIterateBorders(const TilingData& data,
987 gfx::Rect rect,
988 int expect_left,
989 int expect_top,
990 int expect_right,
991 int expect_bottom) {
992 TestIterate(
993 data, rect, expect_left, expect_top, expect_right, expect_bottom, true);
danakj 2014/03/17 23:46:07 nit: can you pass include_borders as a temp boolea
enne (OOO) 2014/03/17 23:53:09 Ok sure. I thought it was clear with both functio
994 }
995
996 void TestIterateNoBorders(const TilingData& data,
997 gfx::Rect rect,
998 int expect_left,
999 int expect_top,
1000 int expect_right,
1001 int expect_bottom) {
1002 TestIterate(
1003 data, rect, expect_left, expect_top, expect_right, expect_bottom, false);
1004 }
1005
1006 void TestIterateAll(const TilingData& data,
1007 gfx::Rect rect,
1008 int expect_left,
1009 int expect_top,
1010 int expect_right,
1011 int expect_bottom) {
1012 TestIterateBorders(
1013 data, rect, expect_left, expect_top, expect_right, expect_bottom);
1014 TestIterateNoBorders(
1015 data, rect, expect_left, expect_top, expect_right, expect_bottom);
1016 }
1017
981 TEST(TilingDataTest, IteratorNoBorderTexels) { 1018 TEST(TilingDataTest, IteratorNoBorderTexels) {
982 TilingData data(gfx::Size(10, 10), gfx::Size(40, 25), false); 1019 TilingData data(gfx::Size(10, 10), gfx::Size(40, 25), false);
983 // X border index by src coord: [0-10), [10-20), [20, 30), [30, 40) 1020 // X border index by src coord: [0-10), [10-20), [20, 30), [30, 40)
984 // Y border index by src coord: [0-10), [10-20), [20, 25) 1021 // Y border index by src coord: [0-10), [10-20), [20, 25)
985 TestIterate(data, gfx::Rect(0, 0, 40, 25), 0, 0, 3, 2); 1022 TestIterateAll(data, gfx::Rect(0, 0, 40, 25), 0, 0, 3, 2);
986 TestIterate(data, gfx::Rect(15, 15, 8, 8), 1, 1, 2, 2); 1023 TestIterateAll(data, gfx::Rect(15, 15, 8, 8), 1, 1, 2, 2);
987 1024
988 // Oversized. 1025 // Oversized.
989 TestIterate(data, gfx::Rect(-100, -100, 1000, 1000), 0, 0, 3, 2); 1026 TestIterateAll(data, gfx::Rect(-100, -100, 1000, 1000), 0, 0, 3, 2);
990 TestIterate(data, gfx::Rect(-100, 20, 1000, 1), 0, 2, 3, 2); 1027 TestIterateAll(data, gfx::Rect(-100, 20, 1000, 1), 0, 2, 3, 2);
991 TestIterate(data, gfx::Rect(29, -100, 31, 1000), 2, 0, 3, 2); 1028 TestIterateAll(data, gfx::Rect(29, -100, 31, 1000), 2, 0, 3, 2);
992 // Nonintersecting. 1029 // Nonintersecting.
993 TestIterate(data, gfx::Rect(60, 80, 100, 100), 0, 0, -1, -1); 1030 TestIterateAll(data, gfx::Rect(60, 80, 100, 100), 0, 0, -1, -1);
994 } 1031 }
995 1032
996 TEST(TilingDataTest, IteratorOneBorderTexel) { 1033 TEST(TilingDataTest, BordersIteratorOneBorderTexel) {
997 TilingData data(gfx::Size(10, 20), gfx::Size(25, 45), true); 1034 TilingData data(gfx::Size(10, 20), gfx::Size(25, 45), true);
998 // X border index by src coord: [0-10), [8-18), [16-25) 1035 // X border index by src coord: [0-10), [8-18), [16-25)
999 // Y border index by src coord: [0-20), [18-38), [36-45) 1036 // Y border index by src coord: [0-20), [18-38), [36-45)
1000 TestIterate(data, gfx::Rect(0, 0, 25, 45), 0, 0, 2, 2); 1037 TestIterateBorders(data, gfx::Rect(0, 0, 25, 45), 0, 0, 2, 2);
1001 TestIterate(data, gfx::Rect(18, 19, 3, 17), 2, 0, 2, 1); 1038 TestIterateBorders(data, gfx::Rect(18, 19, 3, 17), 2, 0, 2, 1);
1002 TestIterate(data, gfx::Rect(10, 20, 6, 16), 1, 1, 1, 1); 1039 TestIterateBorders(data, gfx::Rect(10, 20, 6, 16), 1, 1, 1, 1);
1003 TestIterate(data, gfx::Rect(9, 19, 8, 18), 0, 0, 2, 2); 1040 TestIterateBorders(data, gfx::Rect(9, 19, 8, 18), 0, 0, 2, 2);
1004
1005 // Oversized. 1041 // Oversized.
1006 TestIterate(data, gfx::Rect(-100, -100, 1000, 1000), 0, 0, 2, 2); 1042 TestIterateBorders(data, gfx::Rect(-100, -100, 1000, 1000), 0, 0, 2, 2);
1007 TestIterate(data, gfx::Rect(-100, 20, 1000, 1), 0, 1, 2, 1); 1043 TestIterateBorders(data, gfx::Rect(-100, 20, 1000, 1), 0, 1, 2, 1);
1008 TestIterate(data, gfx::Rect(18, -100, 6, 1000), 2, 0, 2, 2); 1044 TestIterateBorders(data, gfx::Rect(18, -100, 6, 1000), 2, 0, 2, 2);
1009 // Nonintersecting. 1045 // Nonintersecting.
1010 TestIterate(data, gfx::Rect(60, 80, 100, 100), 0, 0, -1, -1); 1046 TestIterateBorders(data, gfx::Rect(60, 80, 100, 100), 0, 0, -1, -1);
1011 } 1047 }
1012 1048
1013 TEST(TilingDataTest, IteratorManyBorderTexels) { 1049 TEST(TilingDataTest, NoBordersIteratorOneBorderTexel) {
1050 TilingData data(gfx::Size(10, 20), gfx::Size(25, 45), true);
1051 // X index by src coord: [0-9), [9-17), [17-25)
1052 // Y index by src coord: [0-19), [19-37), [37-45)
1053 TestIterateNoBorders(data, gfx::Rect(0, 0, 25, 45), 0, 0, 2, 2);
1054 TestIterateNoBorders(data, gfx::Rect(17, 19, 3, 18), 2, 1, 2, 1);
1055 TestIterateNoBorders(data, gfx::Rect(17, 19, 3, 19), 2, 1, 2, 2);
1056 TestIterateNoBorders(data, gfx::Rect(8, 18, 9, 19), 0, 0, 1, 1);
1057 TestIterateNoBorders(data, gfx::Rect(9, 19, 9, 19), 1, 1, 2, 2);
1058 // Oversized.
1059 TestIterateNoBorders(data, gfx::Rect(-100, -100, 1000, 1000), 0, 0, 2, 2);
1060 TestIterateNoBorders(data, gfx::Rect(-100, 20, 1000, 1), 0, 1, 2, 1);
1061 TestIterateNoBorders(data, gfx::Rect(18, -100, 6, 1000), 2, 0, 2, 2);
1062 // Nonintersecting.
1063 TestIterateNoBorders(data, gfx::Rect(60, 80, 100, 100), 0, 0, -1, -1);
1064 }
1065
1066 TEST(TilingDataTest, BordersIteratorManyBorderTexels) {
1014 TilingData data(gfx::Size(50, 60), gfx::Size(65, 110), 20); 1067 TilingData data(gfx::Size(50, 60), gfx::Size(65, 110), 20);
1015 // X border index by src coord: [0-50), [10-60), [20-65) 1068 // X border index by src coord: [0-50), [10-60), [20-65)
1016 // Y border index by src coord: [0-60), [20-80), [40-100), [60-110) 1069 // Y border index by src coord: [0-60), [20-80), [40-100), [60-110)
1017 TestIterate(data, gfx::Rect(0, 0, 65, 110), 0, 0, 2, 3); 1070 TestIterateBorders(data, gfx::Rect(0, 0, 65, 110), 0, 0, 2, 3);
1018 TestIterate(data, gfx::Rect(50, 60, 15, 65), 1, 1, 2, 3); 1071 TestIterateBorders(data, gfx::Rect(50, 60, 15, 65), 1, 1, 2, 3);
1019 TestIterate(data, gfx::Rect(60, 30, 2, 10), 2, 0, 2, 1); 1072 TestIterateBorders(data, gfx::Rect(60, 30, 2, 10), 2, 0, 2, 1);
1073 // Oversized.
1074 TestIterateBorders(data, gfx::Rect(-100, -100, 1000, 1000), 0, 0, 2, 3);
1075 TestIterateBorders(data, gfx::Rect(-100, 10, 1000, 10), 0, 0, 2, 0);
1076 TestIterateBorders(data, gfx::Rect(10, -100, 10, 1000), 0, 0, 1, 3);
1077 // Nonintersecting.
1078 TestIterateBorders(data, gfx::Rect(65, 110, 100, 100), 0, 0, -1, -1);
1079 }
1020 1080
1081 TEST(TilingDataTest, NoBordersIteratorManyBorderTexels) {
1082 TilingData data(gfx::Size(50, 60), gfx::Size(65, 110), 20);
1083 // X index by src coord: [0-30), [30-40), [40, 65)
1084 // Y index by src coord: [0-40), [40-60), [60, 80), [80-110)
1085 TestIterateNoBorders(data, gfx::Rect(0, 0, 65, 110), 0, 0, 2, 3);
1086 TestIterateNoBorders(data, gfx::Rect(30, 40, 15, 65), 1, 1, 2, 3);
1087 TestIterateNoBorders(data, gfx::Rect(60, 20, 2, 21), 2, 0, 2, 1);
1021 // Oversized. 1088 // Oversized.
1022 TestIterate(data, gfx::Rect(-100, -100, 1000, 1000), 0, 0, 2, 3); 1089 TestIterateNoBorders(data, gfx::Rect(-100, -100, 1000, 1000), 0, 0, 2, 3);
1023 TestIterate(data, gfx::Rect(-100, 10, 1000, 10), 0, 0, 2, 0); 1090 TestIterateNoBorders(data, gfx::Rect(-100, 10, 1000, 10), 0, 0, 2, 0);
1024 TestIterate(data, gfx::Rect(10, -100, 10, 1000), 0, 0, 1, 3); 1091 TestIterateNoBorders(data, gfx::Rect(10, -100, 10, 1000), 0, 0, 0, 3);
1025 // Nonintersecting. 1092 // Nonintersecting.
1026 TestIterate(data, gfx::Rect(65, 110, 100, 100), 0, 0, -1, -1); 1093 TestIterateNoBorders(data, gfx::Rect(65, 110, 100, 100), 0, 0, -1, -1);
1027 } 1094 }
1028 1095
1029 TEST(TilingDataTest, IteratorOneTile) { 1096 TEST(TilingDataTest, IteratorOneTile) {
1030 TilingData no_border(gfx::Size(1000, 1000), gfx::Size(30, 40), false); 1097 TilingData no_border(gfx::Size(1000, 1000), gfx::Size(30, 40), false);
1031 TestIterate(no_border, gfx::Rect(0, 0, 30, 40), 0, 0, 0, 0); 1098 TestIterateAll(no_border, gfx::Rect(0, 0, 30, 40), 0, 0, 0, 0);
1032 TestIterate(no_border, gfx::Rect(10, 10, 20, 20), 0, 0, 0, 0); 1099 TestIterateAll(no_border, gfx::Rect(10, 10, 20, 20), 0, 0, 0, 0);
1033 TestIterate(no_border, gfx::Rect(30, 40, 100, 100), 0, 0, -1, -1); 1100 TestIterateAll(no_border, gfx::Rect(30, 40, 100, 100), 0, 0, -1, -1);
1034 1101
1035 TilingData one_border(gfx::Size(1000, 1000), gfx::Size(30, 40), true); 1102 TilingData one_border(gfx::Size(1000, 1000), gfx::Size(30, 40), true);
1036 TestIterate(one_border, gfx::Rect(0, 0, 30, 40), 0, 0, 0, 0); 1103 TestIterateAll(one_border, gfx::Rect(0, 0, 30, 40), 0, 0, 0, 0);
1037 TestIterate(one_border, gfx::Rect(10, 10, 20, 20), 0, 0, 0, 0); 1104 TestIterateAll(one_border, gfx::Rect(10, 10, 20, 20), 0, 0, 0, 0);
1038 TestIterate(one_border, gfx::Rect(30, 40, 100, 100), 0, 0, -1, -1); 1105 TestIterateAll(one_border, gfx::Rect(30, 40, 100, 100), 0, 0, -1, -1);
1039 1106
1040 TilingData big_border(gfx::Size(1000, 1000), gfx::Size(30, 40), 50); 1107 TilingData big_border(gfx::Size(1000, 1000), gfx::Size(30, 40), 50);
1041 TestIterate(big_border, gfx::Rect(0, 0, 30, 40), 0, 0, 0, 0); 1108 TestIterateAll(big_border, gfx::Rect(0, 0, 30, 40), 0, 0, 0, 0);
1042 TestIterate(big_border, gfx::Rect(10, 10, 20, 20), 0, 0, 0, 0); 1109 TestIterateAll(big_border, gfx::Rect(10, 10, 20, 20), 0, 0, 0, 0);
1043 TestIterate(big_border, gfx::Rect(30, 40, 100, 100), 0, 0, -1, -1); 1110 TestIterateAll(big_border, gfx::Rect(30, 40, 100, 100), 0, 0, -1, -1);
1044 } 1111 }
1045 1112
1046 TEST(TilingDataTest, IteratorNoTiles) { 1113 TEST(TilingDataTest, IteratorNoTiles) {
1047 TilingData data(gfx::Size(100, 100), gfx::Size(), false); 1114 TilingData data(gfx::Size(100, 100), gfx::Size(), false);
1048 TestIterate(data, gfx::Rect(0, 0, 100, 100), 0, 0, -1, -1); 1115 TestIterateAll(data, gfx::Rect(0, 0, 100, 100), 0, 0, -1, -1);
1049 } 1116 }
1050 1117
1051 void TestDiff( 1118 void TestDiff(
1052 const TilingData& data, 1119 const TilingData& data,
1053 gfx::Rect consider, 1120 gfx::Rect consider,
1054 gfx::Rect ignore, 1121 gfx::Rect ignore,
1055 size_t num_tiles) { 1122 size_t num_tiles) {
1056 1123
1057 std::vector<std::pair<int, int> > expected; 1124 std::vector<std::pair<int, int> > expected;
1058 for (int y = 0; y < data.num_tiles_y(); ++y) { 1125 for (int y = 0; y < data.num_tiles_y(); ++y) {
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
1730 expected.push_back(std::make_pair(1, 0)); 1797 expected.push_back(std::make_pair(1, 0));
1731 expected.push_back(std::make_pair(2, 2)); 1798 expected.push_back(std::make_pair(2, 2));
1732 expected.push_back(std::make_pair(2, 1)); 1799 expected.push_back(std::make_pair(2, 1));
1733 expected.push_back(std::make_pair(2, 0)); 1800 expected.push_back(std::make_pair(2, 0));
1734 1801
1735 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected); 1802 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
1736 } 1803 }
1737 } // namespace 1804 } // namespace
1738 1805
1739 } // namespace cc 1806 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698