Chromium Code Reviews| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "cc/test/geometry_test_utils.h" | 9 #include "cc/test/geometry_test_utils.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 947 for (size_t i = 0; i < expected.size(); ++i) { | 947 for (size_t i = 0; i < expected.size(); ++i) { |
| 948 if (expected[i] == iter.index()) { | 948 if (expected[i] == iter.index()) { |
| 949 expected[i] = expected.back(); | 949 expected[i] = expected.back(); |
| 950 expected.pop_back(); | 950 expected.pop_back(); |
| 951 found = true; | 951 found = true; |
| 952 break; | 952 break; |
| 953 } | 953 } |
| 954 } | 954 } |
| 955 EXPECT_TRUE(found); | 955 EXPECT_TRUE(found); |
| 956 } | 956 } |
| 957 EXPECT_EQ(0, expected.size()); | 957 EXPECT_TRUE(expected.empty()); |
| 958 } | 958 } |
| 959 | 959 |
| 960 // Make sure this also works with a difference iterator and an empty ignore. | 960 // Make sure this also works with a difference iterator and an empty ignore. |
| 961 { | 961 { |
| 962 std::vector<std::pair<int, int> > expected = original_expected; | 962 std::vector<std::pair<int, int> > expected = original_expected; |
| 963 for (TilingData::DifferenceIterator iter(&data, rect, gfx::Rect()); | 963 for (TilingData::DifferenceIterator iter(&data, rect, gfx::Rect()); |
| 964 iter; ++iter) { | 964 iter; ++iter) { |
| 965 bool found = false; | 965 bool found = false; |
| 966 for (size_t i = 0; i < expected.size(); ++i) { | 966 for (size_t i = 0; i < expected.size(); ++i) { |
| 967 if (expected[i] == iter.index()) { | 967 if (expected[i] == iter.index()) { |
| 968 expected[i] = expected.back(); | 968 expected[i] = expected.back(); |
| 969 expected.pop_back(); | 969 expected.pop_back(); |
| 970 found = true; | 970 found = true; |
| 971 break; | 971 break; |
| 972 } | 972 } |
| 973 } | 973 } |
| 974 EXPECT_TRUE(found); | 974 EXPECT_TRUE(found); |
| 975 } | 975 } |
| 976 EXPECT_EQ(0, expected.size()); | 976 EXPECT_TRUE(expected.empty()); |
| 977 } | 977 } |
| 978 } | 978 } |
| 979 | 979 |
| 980 TEST(TilingDataTest, IteratorNoBorderTexels) { | 980 TEST(TilingDataTest, IteratorNoBorderTexels) { |
| 981 TilingData data(gfx::Size(10, 10), gfx::Size(40, 25), false); | 981 TilingData data(gfx::Size(10, 10), gfx::Size(40, 25), false); |
| 982 // X border index by src coord: [0-10), [10-20), [20, 30), [30, 40) | 982 // X border index by src coord: [0-10), [10-20), [20, 30), [30, 40) |
| 983 // Y border index by src coord: [0-10), [10-20), [20, 25) | 983 // Y border index by src coord: [0-10), [10-20), [20, 25) |
| 984 TestIterate(data, gfx::Rect(0, 0, 40, 25), 0, 0, 3, 2); | 984 TestIterate(data, gfx::Rect(0, 0, 40, 25), 0, 0, 3, 2); |
| 985 TestIterate(data, gfx::Rect(15, 15, 8, 8), 1, 1, 2, 2); | 985 TestIterate(data, gfx::Rect(15, 15, 8, 8), 1, 1, 2, 2); |
| 986 | 986 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1056 std::vector<std::pair<int, int> > expected; | 1056 std::vector<std::pair<int, int> > expected; |
| 1057 for (int y = 0; y < data.num_tiles_y(); ++y) { | 1057 for (int y = 0; y < data.num_tiles_y(); ++y) { |
| 1058 for (int x = 0; x < data.num_tiles_x(); ++x) { | 1058 for (int x = 0; x < data.num_tiles_x(); ++x) { |
| 1059 gfx::Rect bounds = data.TileBoundsWithBorder(x, y); | 1059 gfx::Rect bounds = data.TileBoundsWithBorder(x, y); |
| 1060 if (bounds.Intersects(consider) && !bounds.Intersects(ignore)) | 1060 if (bounds.Intersects(consider) && !bounds.Intersects(ignore)) |
| 1061 expected.push_back(std::make_pair(x, y)); | 1061 expected.push_back(std::make_pair(x, y)); |
| 1062 } | 1062 } |
| 1063 } | 1063 } |
| 1064 | 1064 |
| 1065 // Sanity check the test. | 1065 // Sanity check the test. |
| 1066 EXPECT_EQ(num_tiles, expected.size()); | 1066 EXPECT_EQ(static_cast<size_t>(num_tiles), expected.size()); |
|
jamesr
2013/03/29 00:07:16
num_tiles is a size_t, according to the function s
danakj
2013/03/29 00:17:35
Oh.. hm.. it's not. removed.
| |
| 1067 | 1067 |
| 1068 for (TilingData::DifferenceIterator iter(&data, consider, ignore); | 1068 for (TilingData::DifferenceIterator iter(&data, consider, ignore); |
| 1069 iter; ++iter) { | 1069 iter; ++iter) { |
| 1070 bool found = false; | 1070 bool found = false; |
| 1071 for (size_t i = 0; i < expected.size(); ++i) { | 1071 for (size_t i = 0; i < expected.size(); ++i) { |
| 1072 if (expected[i] == iter.index()) { | 1072 if (expected[i] == iter.index()) { |
| 1073 expected[i] = expected.back(); | 1073 expected[i] = expected.back(); |
| 1074 expected.pop_back(); | 1074 expected.pop_back(); |
| 1075 found = true; | 1075 found = true; |
| 1076 break; | 1076 break; |
| 1077 } | 1077 } |
| 1078 } | 1078 } |
| 1079 EXPECT_TRUE(found); | 1079 EXPECT_TRUE(found); |
| 1080 } | 1080 } |
| 1081 EXPECT_EQ(0, expected.size()); | 1081 EXPECT_TRUE(expected.empty()); |
| 1082 } | 1082 } |
| 1083 | 1083 |
| 1084 TEST(TilingDataTest, DifferenceIteratorIgnoreGeometry) { | 1084 TEST(TilingDataTest, DifferenceIteratorIgnoreGeometry) { |
| 1085 // This test is checking that the iterator can handle different geometries of | 1085 // This test is checking that the iterator can handle different geometries of |
| 1086 // ignore rects relative to the consider rect. The consider rect indices | 1086 // ignore rects relative to the consider rect. The consider rect indices |
| 1087 // themselves are mostly tested by the non-difference iterator tests, so the | 1087 // themselves are mostly tested by the non-difference iterator tests, so the |
| 1088 // full rect is mostly used here for simplicity. | 1088 // full rect is mostly used here for simplicity. |
| 1089 | 1089 |
| 1090 // X border index by src coord: [0-10), [10-20), [20, 30), [30, 40) | 1090 // X border index by src coord: [0-10), [10-20), [20, 30), [30, 40) |
| 1091 // Y border index by src coord: [0-10), [10-20), [20, 25) | 1091 // Y border index by src coord: [0-10), [10-20), [20, 25) |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1162 TestDiff(big_border, gfx::Rect(5, 5, 100, 100), gfx::Rect(5, 5, 1, 1), 0); | 1162 TestDiff(big_border, gfx::Rect(5, 5, 100, 100), gfx::Rect(5, 5, 1, 1), 0); |
| 1163 } | 1163 } |
| 1164 | 1164 |
| 1165 TEST(TilingDataTest, DifferenceIteratorNoTiles) { | 1165 TEST(TilingDataTest, DifferenceIteratorNoTiles) { |
| 1166 TilingData data(gfx::Size(100, 100), gfx::Size(), false); | 1166 TilingData data(gfx::Size(100, 100), gfx::Size(), false); |
| 1167 TestDiff(data, gfx::Rect(0, 0, 100, 100), gfx::Rect(0, 0, 5, 5), 0); | 1167 TestDiff(data, gfx::Rect(0, 0, 100, 100), gfx::Rect(0, 0, 5, 5), 0); |
| 1168 } | 1168 } |
| 1169 | 1169 |
| 1170 } // namespace | 1170 } // namespace |
| 1171 } // namespace cc | 1171 } // namespace cc |
| OLD | NEW |