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

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

Issue 505913003: cc: Remove and Create the correct tiles when resizing live tiles rect (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: livetiles: . Created 6 years, 4 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
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 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 found = true; 1079 found = true;
1080 break; 1080 break;
1081 } 1081 }
1082 } 1082 }
1083 EXPECT_TRUE(found); 1083 EXPECT_TRUE(found);
1084 } 1084 }
1085 EXPECT_EQ(0u, expected.size()); 1085 EXPECT_EQ(0u, expected.size());
1086 } 1086 }
1087 1087
1088 // Make sure this also works with a difference iterator and an empty ignore. 1088 // Make sure this also works with a difference iterator and an empty ignore.
1089 // The difference iterator always includes borders, so ignore it otherwise. 1089 std::vector<std::pair<int, int> > expected = original_expected;
1090 if (include_borders) { 1090 for (TilingData::DifferenceIterator iter(
1091 std::vector<std::pair<int, int> > expected = original_expected; 1091 &data, rect, gfx::Rect(), include_borders);
1092 for (TilingData::DifferenceIterator iter(&data, rect, gfx::Rect()); 1092 iter;
1093 iter; ++iter) { 1093 ++iter) {
1094 bool found = false; 1094 bool found = false;
1095 for (size_t i = 0; i < expected.size(); ++i) { 1095 for (size_t i = 0; i < expected.size(); ++i) {
1096 if (expected[i] == iter.index()) { 1096 if (expected[i] == iter.index()) {
1097 expected[i] = expected.back(); 1097 expected[i] = expected.back();
1098 expected.pop_back(); 1098 expected.pop_back();
1099 found = true; 1099 found = true;
1100 break; 1100 break;
1101 }
1102 } 1101 }
1103 EXPECT_TRUE(found);
1104 } 1102 }
1105 EXPECT_EQ(0u, expected.size()); 1103 EXPECT_TRUE(found);
1106 } 1104 }
1105 EXPECT_EQ(0u, expected.size());
1107 } 1106 }
1108 1107
1109 void TestIterateBorders(const TilingData& data, 1108 void TestIterateBorders(const TilingData& data,
1110 gfx::Rect rect, 1109 gfx::Rect rect,
1111 int expect_left, 1110 int expect_left,
1112 int expect_top, 1111 int expect_top,
1113 int expect_right, 1112 int expect_right,
1114 int expect_bottom) { 1113 int expect_bottom) {
1115 bool include_borders = true; 1114 bool include_borders = true;
1116 TestIterate(data, 1115 TestIterate(data,
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1243 TestIterateAll(big_border, gfx::Rect(30, 40), 0, 0, 0, 0); 1242 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); 1243 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); 1244 TestIterateAll(big_border, gfx::Rect(30, 40, 100, 100), 0, 0, -1, -1);
1246 } 1245 }
1247 1246
1248 TEST(TilingDataTest, IteratorNoTiles) { 1247 TEST(TilingDataTest, IteratorNoTiles) {
1249 TilingData data(gfx::Size(100, 100), gfx::Size(), false); 1248 TilingData data(gfx::Size(100, 100), gfx::Size(), false);
1250 TestIterateAll(data, gfx::Rect(100, 100), 0, 0, -1, -1); 1249 TestIterateAll(data, gfx::Rect(100, 100), 0, 0, -1, -1);
1251 } 1250 }
1252 1251
1253 void TestDiff( 1252 void TestDiff(const TilingData& data,
1254 const TilingData& data, 1253 gfx::Rect consider,
1255 gfx::Rect consider, 1254 gfx::Rect ignore,
1256 gfx::Rect ignore, 1255 size_t num_tiles,
1257 size_t num_tiles) { 1256 bool include_borders) {
1258
1259 std::vector<std::pair<int, int> > expected; 1257 std::vector<std::pair<int, int> > expected;
1260 for (int y = 0; y < data.num_tiles_y(); ++y) { 1258 for (int y = 0; y < data.num_tiles_y(); ++y) {
1261 for (int x = 0; x < data.num_tiles_x(); ++x) { 1259 for (int x = 0; x < data.num_tiles_x(); ++x) {
1262 gfx::Rect bounds = data.TileBoundsWithBorder(x, y); 1260 gfx::Rect bounds = include_borders ? data.TileBoundsWithBorder(x, y)
1261 : data.TileBounds(x, y);
1263 if (bounds.Intersects(consider) && !bounds.Intersects(ignore)) 1262 if (bounds.Intersects(consider) && !bounds.Intersects(ignore))
1264 expected.push_back(std::make_pair(x, y)); 1263 expected.push_back(std::make_pair(x, y));
1265 } 1264 }
1266 } 1265 }
1267 1266
1268 // Sanity check the test. 1267 // Sanity check the test.
1269 EXPECT_EQ(num_tiles, expected.size()); 1268 EXPECT_EQ(num_tiles, expected.size());
1270 1269
1271 for (TilingData::DifferenceIterator iter(&data, consider, ignore); 1270 for (TilingData::DifferenceIterator iter(
1272 iter; ++iter) { 1271 &data, consider, ignore, include_borders);
1272 iter;
1273 ++iter) {
1273 bool found = false; 1274 bool found = false;
1274 for (size_t i = 0; i < expected.size(); ++i) { 1275 for (size_t i = 0; i < expected.size(); ++i) {
1275 if (expected[i] == iter.index()) { 1276 if (expected[i] == iter.index()) {
1276 expected[i] = expected.back(); 1277 expected[i] = expected.back();
1277 expected.pop_back(); 1278 expected.pop_back();
1278 found = true; 1279 found = true;
1279 break; 1280 break;
1280 } 1281 }
1281 } 1282 }
1282 EXPECT_TRUE(found); 1283 EXPECT_TRUE(found);
1283 } 1284 }
1284 EXPECT_EQ(0u, expected.size()); 1285 EXPECT_EQ(0u, expected.size());
1285 } 1286 }
1286 1287
1287 TEST(TilingDataTest, DifferenceIteratorIgnoreGeometry) { 1288 TEST(TilingDataTest, DifferenceIteratorIgnoreGeometry) {
1288 // This test is checking that the iterator can handle different geometries of 1289 // This test is checking that the iterator can handle different geometries of
1289 // ignore rects relative to the consider rect. The consider rect indices 1290 // ignore rects relative to the consider rect. The consider rect indices
1290 // themselves are mostly tested by the non-difference iterator tests, so the 1291 // themselves are mostly tested by the non-difference iterator tests, so the
1291 // full rect is mostly used here for simplicity. 1292 // full rect is mostly used here for simplicity.
1292 1293
1293 // X border index by src coord: [0-10), [10-20), [20, 30), [30, 40) 1294 // X border index by src coord: [0-10), [10-20), [20, 30), [30, 40)
1294 // Y border index by src coord: [0-10), [10-20), [20, 25) 1295 // Y border index by src coord: [0-10), [10-20), [20, 25)
1295 TilingData data(gfx::Size(10, 10), gfx::Size(40, 25), false); 1296 TilingData data(gfx::Size(10, 10), gfx::Size(40, 25), false);
1296 1297
1297 // Fully ignored 1298 // Fully ignored
1298 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(40, 25), 0); 1299 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(40, 25), 0, true);
1299 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(-100, -100, 200, 200), 0); 1300 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(-100, -100, 200, 200), 0, true);
1300 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(9, 9, 30, 15), 0); 1301 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(9, 9, 30, 15), 0, true);
1301 TestDiff(data, gfx::Rect(15, 15, 8, 8), gfx::Rect(15, 15, 8, 8), 0); 1302 TestDiff(data, gfx::Rect(15, 15, 8, 8), gfx::Rect(15, 15, 8, 8), 0, true);
1303
1304 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(40, 25), 0, false);
1305 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(-100, -100, 200, 200), 0, false);
1306 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(9, 9, 30, 15), 0, false);
1307 TestDiff(data, gfx::Rect(15, 15, 8, 8), gfx::Rect(15, 15, 8, 8), 0, false);
1302 1308
1303 // Fully un-ignored 1309 // Fully un-ignored
1304 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(-30, -20, 8, 8), 12); 1310 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(-30, -20, 8, 8), 12, true);
1305 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(), 12); 1311 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(), 12, true);
1312
1313 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(-30, -20, 8, 8), 12, false);
1314 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(), 12, false);
1306 1315
1307 // Top left, remove 2x2 tiles 1316 // Top left, remove 2x2 tiles
1308 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(20, 19), 8); 1317 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(20, 19), 8, true);
1318 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(20, 19), 8, false);
1309 // Bottom right, remove 2x2 tiles 1319 // Bottom right, remove 2x2 tiles
1310 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(20, 15, 20, 6), 8); 1320 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(20, 15, 20, 6), 8, true);
1321 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(20, 15, 20, 6), 8, false);
1311 // Bottom left, remove 2x2 tiles 1322 // Bottom left, remove 2x2 tiles
1312 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(0, 15, 20, 6), 8); 1323 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(0, 15, 20, 6), 8, true);
1324 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(0, 15, 20, 6), 8, false);
1313 // Top right, remove 2x2 tiles 1325 // Top right, remove 2x2 tiles
1314 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(20, 0, 20, 19), 8); 1326 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(20, 0, 20, 19), 8, true);
1327 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(20, 0, 20, 19), 8, false);
1315 // Center, remove only one tile 1328 // Center, remove only one tile
1316 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(10, 10, 5, 5), 11); 1329 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(10, 10, 5, 5), 11, true);
1330 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(10, 10, 5, 5), 11, false);
1317 1331
1318 // Left column, flush left, removing two columns 1332 // Left column, flush left, removing two columns
1319 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(11, 25), 6); 1333 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(11, 25), 6, true);
1334 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(11, 25), 6, false);
1320 // Middle column, removing two columns 1335 // Middle column, removing two columns
1321 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(11, 0, 11, 25), 6); 1336 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(11, 0, 11, 25), 6, true);
1337 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(11, 0, 11, 25), 6, false);
1322 // Right column, flush right, removing one column 1338 // Right column, flush right, removing one column
1323 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(30, 0, 2, 25), 9); 1339 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(30, 0, 2, 25), 9, true);
1340 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(30, 0, 2, 25), 9, false);
1324 1341
1325 // Top row, flush top, removing one row 1342 // Top row, flush top, removing one row
1326 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(0, 5, 40, 5), 8); 1343 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(0, 5, 40, 5), 8, true);
1344 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(0, 5, 40, 5), 8, false);
1327 // Middle row, removing one row 1345 // Middle row, removing one row
1328 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(0, 13, 40, 5), 8); 1346 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(0, 13, 40, 5), 8, true);
1347 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(0, 13, 40, 5), 8, false);
1329 // Bottom row, flush bottom, removing two rows 1348 // Bottom row, flush bottom, removing two rows
1330 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(0, 13, 40, 12), 4); 1349 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(0, 13, 40, 12), 4, true);
1350 TestDiff(data, gfx::Rect(40, 25), gfx::Rect(0, 13, 40, 12), 4, false);
1331 1351
1332 // Non-intersecting, but still touching two of the same tiles. 1352 // 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); 1353 TestDiff(data, gfx::Rect(8, 0, 32, 25), gfx::Rect(0, 12, 5, 12), 10, true);
1354 TestDiff(data, gfx::Rect(8, 0, 32, 25), gfx::Rect(0, 12, 5, 12), 10, false);
1334 1355
1335 // Intersecting, but neither contains the other. 2x3 with one overlap. 1356 // 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); 1357 TestDiff(data, gfx::Rect(5, 2, 20, 10), gfx::Rect(25, 15, 5, 10), 5, true);
1358 TestDiff(data, gfx::Rect(5, 2, 20, 10), gfx::Rect(25, 15, 5, 10), 5, false);
1337 } 1359 }
1338 1360
1339 TEST(TilingDataTest, DifferenceIteratorManyBorderTexels) { 1361 TEST(TilingDataTest, DifferenceIteratorManyBorderTexels) {
1340 // X border index by src coord: [0-50), [10-60), [20-65) 1362 // 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) 1363 // Y border index by src coord: [0-60), [20-80), [40-100), [60-110)
1364 // X tile bounds by src coord: [0-30), [30-40), [40-65)
1365 // 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); 1366 TilingData data(gfx::Size(50, 60), gfx::Size(65, 110), 20);
1343 1367
1344 // Ignore one column, three rows 1368 // Ignore one column, over three rows.
1345 TestDiff(data, gfx::Rect(0, 30, 55, 80), gfx::Rect(5, 30, 5, 15), 9); 1369 TestDiff(data, gfx::Rect(0, 30, 55, 80), gfx::Rect(5, 30, 5, 15), 9, true);
1346 1370
1347 // Knock out three columns, leaving only one. 1371 // Knock out three rows, leaving only one.
1348 TestDiff(data, gfx::Rect(10, 30, 55, 80), gfx::Rect(30, 59, 20, 1), 3); 1372 TestDiff(data, gfx::Rect(10, 30, 55, 80), gfx::Rect(30, 59, 20, 1), 3, true);
1373
1374 // Knock out one row.
1375 TestDiff(data, gfx::Rect(10, 30, 55, 80), gfx::Rect(29, 59, 20, 1), 9, false);
1349 1376
1350 // Overlap all tiles with ignore rect. 1377 // Overlap all tiles with ignore rect.
1351 TestDiff(data, gfx::Rect(65, 110), gfx::Rect(30, 59, 1, 2), 0); 1378 TestDiff(data, gfx::Rect(65, 110), gfx::Rect(30, 59, 1, 2), 0, true);
1379
1380 TestDiff(data, gfx::Rect(65, 110), gfx::Rect(29, 39, 12, 42), 0, false);
1381
1382 gfx::Rect tile = data.TileBounds(1, 1);
1383
1384 // Ignore nine tiles.
1385 TestDiff(data, gfx::Rect(20, 30, 45, 80), tile, 3, true);
1386 // Ignore one tile.
1387 TestDiff(data, gfx::Rect(20, 30, 45, 80), tile, 11, false);
1388
1389 // Include nine tiles.
1390 TestDiff(data, tile, gfx::Rect(), 9, true);
1391 // Include one tile.
1392 TestDiff(data, tile, gfx::Rect(), 1, false);
1352 } 1393 }
1353 1394
1354 TEST(TilingDataTest, DifferenceIteratorOneTile) { 1395 TEST(TilingDataTest, DifferenceIteratorOneTile) {
1355 TilingData no_border(gfx::Size(1000, 1000), gfx::Size(30, 40), false); 1396 TilingData no_border(gfx::Size(1000, 1000), gfx::Size(30, 40), false);
1356 TestDiff(no_border, gfx::Rect(30, 40), gfx::Rect(), 1); 1397 TestDiff(no_border, gfx::Rect(30, 40), gfx::Rect(), 1, true);
1357 TestDiff(no_border, gfx::Rect(5, 5, 100, 100), gfx::Rect(5, 5, 1, 1), 0); 1398 TestDiff(
1399 no_border, gfx::Rect(5, 5, 100, 100), gfx::Rect(5, 5, 1, 1), 0, true);
1400 TestDiff(no_border, gfx::Rect(30, 40), gfx::Rect(), 1, false);
1401 TestDiff(
1402 no_border, gfx::Rect(5, 5, 100, 100), gfx::Rect(5, 5, 1, 1), 0, false);
1358 1403
1359 TilingData one_border(gfx::Size(1000, 1000), gfx::Size(30, 40), true); 1404 TilingData one_border(gfx::Size(1000, 1000), gfx::Size(30, 40), true);
1360 TestDiff(one_border, gfx::Rect(30, 40), gfx::Rect(), 1); 1405 TestDiff(one_border, gfx::Rect(30, 40), gfx::Rect(), 1, true);
1361 TestDiff(one_border, gfx::Rect(5, 5, 100, 100), gfx::Rect(5, 5, 1, 1), 0); 1406 TestDiff(
1407 one_border, gfx::Rect(5, 5, 100, 100), gfx::Rect(5, 5, 1, 1), 0, true);
1408 TestDiff(one_border, gfx::Rect(30, 40), gfx::Rect(), 1, false);
1409 TestDiff(
1410 one_border, gfx::Rect(5, 5, 100, 100), gfx::Rect(5, 5, 1, 1), 0, false);
1362 1411
1363 TilingData big_border(gfx::Size(1000, 1000), gfx::Size(30, 40), 50); 1412 TilingData big_border(gfx::Size(1000, 1000), gfx::Size(30, 40), 50);
1364 TestDiff(big_border, gfx::Rect(30, 40), gfx::Rect(), 1); 1413 TestDiff(big_border, gfx::Rect(30, 40), gfx::Rect(), 1, true);
1365 TestDiff(big_border, gfx::Rect(5, 5, 100, 100), gfx::Rect(5, 5, 1, 1), 0); 1414 TestDiff(
1415 big_border, gfx::Rect(5, 5, 100, 100), gfx::Rect(5, 5, 1, 1), 0, true);
1416 TestDiff(big_border, gfx::Rect(30, 40), gfx::Rect(), 1, false);
1417 TestDiff(
1418 big_border, gfx::Rect(5, 5, 100, 100), gfx::Rect(5, 5, 1, 1), 0, false);
1366 } 1419 }
1367 1420
1368 TEST(TilingDataTest, DifferenceIteratorNoTiles) { 1421 TEST(TilingDataTest, DifferenceIteratorNoTiles) {
1369 TilingData data(gfx::Size(100, 100), gfx::Size(), false); 1422 TilingData data(gfx::Size(100, 100), gfx::Size(), false);
1370 TestDiff(data, gfx::Rect(100, 100), gfx::Rect(5, 5), 0); 1423 TestDiff(data, gfx::Rect(100, 100), gfx::Rect(5, 5), 0, true);
1424 TestDiff(data, gfx::Rect(100, 100), gfx::Rect(5, 5), 0, false);
1371 } 1425 }
1372 1426
1373 void TestSpiralIterate(int source_line_number, 1427 void TestSpiralIterate(int source_line_number,
1374 const TilingData& tiling_data, 1428 const TilingData& tiling_data,
1375 const gfx::Rect& consider, 1429 const gfx::Rect& consider,
1376 const gfx::Rect& ignore, 1430 const gfx::Rect& ignore,
1377 const gfx::Rect& center, 1431 const gfx::Rect& center,
1378 const std::vector<std::pair<int, int> >& expected) { 1432 const std::vector<std::pair<int, int> >& expected) {
1379 std::vector<std::pair<int, int> > actual; 1433 std::vector<std::pair<int, int> > actual;
1380 for (TilingData::SpiralDifferenceIterator it( 1434 for (TilingData::SpiralDifferenceIterator it(
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
1933 expected.push_back(std::make_pair(2, 2)); 1987 expected.push_back(std::make_pair(2, 2));
1934 expected.push_back(std::make_pair(2, 1)); 1988 expected.push_back(std::make_pair(2, 1));
1935 expected.push_back(std::make_pair(2, 0)); 1989 expected.push_back(std::make_pair(2, 0));
1936 1990
1937 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected); 1991 TestSpiralIterate(__LINE__, tiling_data, consider, ignore, center, expected);
1938 } 1992 }
1939 1993
1940 } // namespace 1994 } // namespace
1941 1995
1942 } // namespace cc 1996 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698