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

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

Issue 196343005: cc: Replace recorded region with direct map lookup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Bugfixes 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 bool include_borders = true;
993 TestIterate(data,
994 rect,
995 expect_left,
996 expect_top,
997 expect_right,
998 expect_bottom,
999 include_borders);
1000 }
1001
1002 void TestIterateNoBorders(const TilingData& data,
1003 gfx::Rect rect,
1004 int expect_left,
1005 int expect_top,
1006 int expect_right,
1007 int expect_bottom) {
1008 bool include_borders = false;
1009 TestIterate(data,
1010 rect,
1011 expect_left,
1012 expect_top,
1013 expect_right,
1014 expect_bottom,
1015 include_borders);
1016 }
1017
1018 void TestIterateAll(const TilingData& data,
1019 gfx::Rect rect,
1020 int expect_left,
1021 int expect_top,
1022 int expect_right,
1023 int expect_bottom) {
1024 TestIterateBorders(
1025 data, rect, expect_left, expect_top, expect_right, expect_bottom);
1026 TestIterateNoBorders(
1027 data, rect, expect_left, expect_top, expect_right, expect_bottom);
1028 }
1029
981 TEST(TilingDataTest, IteratorNoBorderTexels) { 1030 TEST(TilingDataTest, IteratorNoBorderTexels) {
982 TilingData data(gfx::Size(10, 10), gfx::Size(40, 25), false); 1031 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) 1032 // 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) 1033 // 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); 1034 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); 1035 TestIterateAll(data, gfx::Rect(15, 15, 8, 8), 1, 1, 2, 2);
987 1036
988 // Oversized. 1037 // Oversized.
989 TestIterate(data, gfx::Rect(-100, -100, 1000, 1000), 0, 0, 3, 2); 1038 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); 1039 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); 1040 TestIterateAll(data, gfx::Rect(29, -100, 31, 1000), 2, 0, 3, 2);
992 // Nonintersecting. 1041 // Nonintersecting.
993 TestIterate(data, gfx::Rect(60, 80, 100, 100), 0, 0, -1, -1); 1042 TestIterateAll(data, gfx::Rect(60, 80, 100, 100), 0, 0, -1, -1);
994 } 1043 }
995 1044
996 TEST(TilingDataTest, IteratorOneBorderTexel) { 1045 TEST(TilingDataTest, BordersIteratorOneBorderTexel) {
997 TilingData data(gfx::Size(10, 20), gfx::Size(25, 45), true); 1046 TilingData data(gfx::Size(10, 20), gfx::Size(25, 45), true);
998 // X border index by src coord: [0-10), [8-18), [16-25) 1047 // 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) 1048 // 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); 1049 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); 1050 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); 1051 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); 1052 TestIterateBorders(data, gfx::Rect(9, 19, 8, 18), 0, 0, 2, 2);
1004
1005 // Oversized. 1053 // Oversized.
1006 TestIterate(data, gfx::Rect(-100, -100, 1000, 1000), 0, 0, 2, 2); 1054 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); 1055 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); 1056 TestIterateBorders(data, gfx::Rect(18, -100, 6, 1000), 2, 0, 2, 2);
1009 // Nonintersecting. 1057 // Nonintersecting.
1010 TestIterate(data, gfx::Rect(60, 80, 100, 100), 0, 0, -1, -1); 1058 TestIterateBorders(data, gfx::Rect(60, 80, 100, 100), 0, 0, -1, -1);
1011 } 1059 }
1012 1060
1013 TEST(TilingDataTest, IteratorManyBorderTexels) { 1061 TEST(TilingDataTest, NoBordersIteratorOneBorderTexel) {
vmpstr 2014/03/18 17:24:54 Maybe it's already here, but can you add a test fo
enne (OOO) 2014/03/18 17:52:16 The test on line 1068 does this. The right/bottom
1062 TilingData data(gfx::Size(10, 20), gfx::Size(25, 45), true);
1063 // X index by src coord: [0-9), [9-17), [17-25)
1064 // Y index by src coord: [0-19), [19-37), [37-45)
1065 TestIterateNoBorders(data, gfx::Rect(0, 0, 25, 45), 0, 0, 2, 2);
1066 TestIterateNoBorders(data, gfx::Rect(17, 19, 3, 18), 2, 1, 2, 1);
1067 TestIterateNoBorders(data, gfx::Rect(17, 19, 3, 19), 2, 1, 2, 2);
1068 TestIterateNoBorders(data, gfx::Rect(8, 18, 9, 19), 0, 0, 1, 1);
1069 TestIterateNoBorders(data, gfx::Rect(9, 19, 9, 19), 1, 1, 2, 2);
1070 // Oversized.
1071 TestIterateNoBorders(data, gfx::Rect(-100, -100, 1000, 1000), 0, 0, 2, 2);
1072 TestIterateNoBorders(data, gfx::Rect(-100, 20, 1000, 1), 0, 1, 2, 1);
1073 TestIterateNoBorders(data, gfx::Rect(18, -100, 6, 1000), 2, 0, 2, 2);
1074 // Nonintersecting.
1075 TestIterateNoBorders(data, gfx::Rect(60, 80, 100, 100), 0, 0, -1, -1);
1076 }
1077
1078 TEST(TilingDataTest, BordersIteratorManyBorderTexels) {
1014 TilingData data(gfx::Size(50, 60), gfx::Size(65, 110), 20); 1079 TilingData data(gfx::Size(50, 60), gfx::Size(65, 110), 20);
1015 // X border index by src coord: [0-50), [10-60), [20-65) 1080 // 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) 1081 // 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); 1082 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); 1083 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); 1084 TestIterateBorders(data, gfx::Rect(60, 30, 2, 10), 2, 0, 2, 1);
1085 // Oversized.
1086 TestIterateBorders(data, gfx::Rect(-100, -100, 1000, 1000), 0, 0, 2, 3);
1087 TestIterateBorders(data, gfx::Rect(-100, 10, 1000, 10), 0, 0, 2, 0);
1088 TestIterateBorders(data, gfx::Rect(10, -100, 10, 1000), 0, 0, 1, 3);
1089 // Nonintersecting.
1090 TestIterateBorders(data, gfx::Rect(65, 110, 100, 100), 0, 0, -1, -1);
1091 }
1020 1092
1093 TEST(TilingDataTest, NoBordersIteratorManyBorderTexels) {
1094 TilingData data(gfx::Size(50, 60), gfx::Size(65, 110), 20);
1095 // X index by src coord: [0-30), [30-40), [40, 65)
1096 // Y index by src coord: [0-40), [40-60), [60, 80), [80-110)
1097 TestIterateNoBorders(data, gfx::Rect(0, 0, 65, 110), 0, 0, 2, 3);
1098 TestIterateNoBorders(data, gfx::Rect(30, 40, 15, 65), 1, 1, 2, 3);
1099 TestIterateNoBorders(data, gfx::Rect(60, 20, 2, 21), 2, 0, 2, 1);
1021 // Oversized. 1100 // Oversized.
1022 TestIterate(data, gfx::Rect(-100, -100, 1000, 1000), 0, 0, 2, 3); 1101 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); 1102 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); 1103 TestIterateNoBorders(data, gfx::Rect(10, -100, 10, 1000), 0, 0, 0, 3);
1025 // Nonintersecting. 1104 // Nonintersecting.
1026 TestIterate(data, gfx::Rect(65, 110, 100, 100), 0, 0, -1, -1); 1105 TestIterateNoBorders(data, gfx::Rect(65, 110, 100, 100), 0, 0, -1, -1);
1027 } 1106 }
1028 1107
1029 TEST(TilingDataTest, IteratorOneTile) { 1108 TEST(TilingDataTest, IteratorOneTile) {
1030 TilingData no_border(gfx::Size(1000, 1000), gfx::Size(30, 40), false); 1109 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); 1110 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); 1111 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); 1112 TestIterateAll(no_border, gfx::Rect(30, 40, 100, 100), 0, 0, -1, -1);
1034 1113
1035 TilingData one_border(gfx::Size(1000, 1000), gfx::Size(30, 40), true); 1114 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); 1115 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); 1116 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); 1117 TestIterateAll(one_border, gfx::Rect(30, 40, 100, 100), 0, 0, -1, -1);
1039 1118
1040 TilingData big_border(gfx::Size(1000, 1000), gfx::Size(30, 40), 50); 1119 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); 1120 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); 1121 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); 1122 TestIterateAll(big_border, gfx::Rect(30, 40, 100, 100), 0, 0, -1, -1);
1044 } 1123 }
1045 1124
1046 TEST(TilingDataTest, IteratorNoTiles) { 1125 TEST(TilingDataTest, IteratorNoTiles) {
1047 TilingData data(gfx::Size(100, 100), gfx::Size(), false); 1126 TilingData data(gfx::Size(100, 100), gfx::Size(), false);
1048 TestIterate(data, gfx::Rect(0, 0, 100, 100), 0, 0, -1, -1); 1127 TestIterateAll(data, gfx::Rect(0, 0, 100, 100), 0, 0, -1, -1);
1049 } 1128 }
1050 1129
1051 void TestDiff( 1130 void TestDiff(
1052 const TilingData& data, 1131 const TilingData& data,
1053 gfx::Rect consider, 1132 gfx::Rect consider,
1054 gfx::Rect ignore, 1133 gfx::Rect ignore,
1055 size_t num_tiles) { 1134 size_t num_tiles) {
1056 1135
1057 std::vector<std::pair<int, int> > expected; 1136 std::vector<std::pair<int, int> > expected;
1058 for (int y = 0; y < data.num_tiles_y(); ++y) { 1137 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)); 1809 expected.push_back(std::make_pair(1, 0));
1731 expected.push_back(std::make_pair(2, 2)); 1810 expected.push_back(std::make_pair(2, 2));
1732 expected.push_back(std::make_pair(2, 1)); 1811 expected.push_back(std::make_pair(2, 1));
1733 expected.push_back(std::make_pair(2, 0)); 1812 expected.push_back(std::make_pair(2, 0));
1734 1813
1735 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected); 1814 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
1736 } 1815 }
1737 } // namespace 1816 } // namespace
1738 1817
1739 } // namespace cc 1818 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698