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

Side by Side Diff: tests/PathTest.cpp

Issue 15080010: Add special handling of rectori case for gpu (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Added unit test Created 7 years, 7 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
« no previous file with comments | « src/gpu/GrContext.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "Test.h" 8 #include "Test.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkPaint.h" 10 #include "SkPaint.h"
(...skipping 1304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1315 path1.cubicTo(1, .5f, 1, .5f, 1, .5f); 1315 path1.cubicTo(1, .5f, 1, .5f, 1, .5f);
1316 } 1316 }
1317 path1.lineTo(r1[index].fX, r1[index].fY); 1317 path1.lineTo(r1[index].fX, r1[index].fY);
1318 } 1318 }
1319 path1.close(); 1319 path1.close();
1320 REPORTER_ASSERT(reporter, fail ^ path1.isRect(0)); 1320 REPORTER_ASSERT(reporter, fail ^ path1.isRect(0));
1321 } 1321 }
1322 1322
1323 static void test_isNestedRects(skiatest::Reporter* reporter) { 1323 static void test_isNestedRects(skiatest::Reporter* reporter) {
1324 // passing tests (all moveTo / lineTo... 1324 // passing tests (all moveTo / lineTo...
1325 SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; 1325 SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW
1326 SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}}; 1326 SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}};
1327 SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}}; 1327 SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}};
1328 SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}}; 1328 SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}};
1329 SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}}; 1329 SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}}; // CCW
1330 SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}}; 1330 SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
1331 SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}}; 1331 SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}};
1332 SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}}; 1332 SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}};
1333 SkPoint r9[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}}; 1333 SkPoint r9[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
1334 SkPoint ra[] = {{0, 0}, {0, .5f}, {0, 1}, {.5f, 1}, {1, 1}, {1, .5f}, 1334 SkPoint ra[] = {{0, 0}, {0, .5f}, {0, 1}, {.5f, 1}, {1, 1}, {1, .5f}, // CCW
1335 {1, 0}, {.5f, 0}}; 1335 {1, 0}, {.5f, 0}};
1336 SkPoint rb[] = {{0, 0}, {.5f, 0}, {1, 0}, {1, .5f}, {1, 1}, {.5f, 1}, 1336 SkPoint rb[] = {{0, 0}, {.5f, 0}, {1, 0}, {1, .5f}, {1, 1}, {.5f, 1}, // CW
1337 {0, 1}, {0, .5f}}; 1337 {0, 1}, {0, .5f}};
1338 SkPoint rc[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}; 1338 SkPoint rc[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}; // CW
1339 SkPoint rd[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}; 1339 SkPoint rd[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}; // CCW
1340 SkPoint re[] = {{0, 0}, {1, 0}, {1, 0}, {1, 1}, {0, 1}}; 1340 SkPoint re[] = {{0, 0}, {1, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW
1341 1341
1342 // failing tests 1342 // failing tests
1343 SkPoint f1[] = {{0, 0}, {1, 0}, {1, 1}}; // too few points 1343 SkPoint f1[] = {{0, 0}, {1, 0}, {1, 1}}; // too few points
1344 SkPoint f2[] = {{0, 0}, {1, 1}, {0, 1}, {1, 0}}; // diagonal 1344 SkPoint f2[] = {{0, 0}, {1, 1}, {0, 1}, {1, 0}}; // diagonal
1345 SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps 1345 SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps
1346 SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up 1346 SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up
1347 SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots 1347 SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots
1348 SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots 1348 SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots
1349 SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots 1349 SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots
1350 SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L' 1350 SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L'
1351 1351
1352 // failing, no close 1352 // failing, no close
1353 SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // close doesn't match 1353 SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // close doesn't match
1354 SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}}; // ditto 1354 SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}}; // ditto
1355 1355
1356 size_t testLen[] = { 1356 size_t testLen[] = {
1357 sizeof(r1), sizeof(r2), sizeof(r3), sizeof(r4), sizeof(r5), sizeof(r6), 1357 sizeof(r1), sizeof(r2), sizeof(r3), sizeof(r4), sizeof(r5), sizeof(r6),
1358 sizeof(r7), sizeof(r8), sizeof(r9), sizeof(ra), sizeof(rb), sizeof(rc), 1358 sizeof(r7), sizeof(r8), sizeof(r9), sizeof(ra), sizeof(rb), sizeof(rc),
1359 sizeof(rd), sizeof(re), 1359 sizeof(rd), sizeof(re),
1360 sizeof(f1), sizeof(f2), sizeof(f3), sizeof(f4), sizeof(f5), sizeof(f6), 1360 sizeof(f1), sizeof(f2), sizeof(f3), sizeof(f4), sizeof(f5), sizeof(f6),
1361 sizeof(f7), sizeof(f8), 1361 sizeof(f7), sizeof(f8),
1362 sizeof(c1), sizeof(c2) 1362 sizeof(c1), sizeof(c2)
1363 }; 1363 };
1364 SkPoint* tests[] = { 1364 SkPoint* tests[] = {
1365 r1, r2, r3, r4, r5, r6, r7, r8, r9, ra, rb, rc, rd, re, 1365 r1, r2, r3, r4, r5, r6, r7, r8, r9, ra, rb, rc, rd, re,
1366 f1, f2, f3, f4, f5, f6, f7, f8, 1366 f1, f2, f3, f4, f5, f6, f7, f8,
1367 c1, c2 1367 c1, c2
1368 }; 1368 };
1369 SkPath::Direction dirs[] = {
1370 SkPath::kCW_Direction, SkPath::kCW_Direction, SkPath::kCW_Direction,
1371 SkPath::kCW_Direction, SkPath::kCCW_Direction, SkPath::kCCW_Direction,
1372 SkPath::kCCW_Direction, SkPath::kCCW_Direction, SkPath::kCCW_Direction,
1373 SkPath::kCCW_Direction, SkPath::kCW_Direction, SkPath::kCW_Direction,
1374 SkPath::kCCW_Direction, SkPath::kCW_Direction, SkPath::kUnknown_Directio n,
1375 SkPath::kUnknown_Direction, SkPath::kUnknown_Direction, SkPath::kUnknown _Direction,
1376 SkPath::kUnknown_Direction, SkPath::kUnknown_Direction, SkPath::kUnknown _Direction,
1377 SkPath::kUnknown_Direction, SkPath::kUnknown_Direction, SkPath::kUnknown _Direction,
1378 };
1379 SkASSERT(SK_ARRAY_COUNT(tests) == SK_ARRAY_COUNT(dirs));
1380
1369 const SkPoint* lastPass = re; 1381 const SkPoint* lastPass = re;
1370 const SkPoint* lastClose = f8; 1382 const SkPoint* lastClose = f8;
1371 const size_t testCount = sizeof(tests) / sizeof(tests[0]); 1383 const size_t testCount = sizeof(tests) / sizeof(tests[0]);
1372 size_t index; 1384 size_t index;
1373 for (int rectFirst = 0; rectFirst <= 1; ++rectFirst) { 1385 for (int rectFirst = 0; rectFirst <= 1; ++rectFirst) {
1374 bool fail = false; 1386 bool fail = false;
1375 bool close = true; 1387 bool close = true;
1376 for (size_t testIndex = 0; testIndex < testCount; ++testIndex) { 1388 for (size_t testIndex = 0; testIndex < testCount; ++testIndex) {
1377 SkPath path; 1389 SkPath path;
1378 if (rectFirst) { 1390 if (rectFirst) {
1379 path.addRect(-1, -1, 2, 2, SkPath::kCW_Direction); 1391 path.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1380 } 1392 }
1381 path.moveTo(tests[testIndex][0].fX, tests[testIndex][0].fY); 1393 path.moveTo(tests[testIndex][0].fX, tests[testIndex][0].fY);
1382 for (index = 1; index < testLen[testIndex] / sizeof(SkPoint); ++inde x) { 1394 for (index = 1; index < testLen[testIndex] / sizeof(SkPoint); ++inde x) {
1383 path.lineTo(tests[testIndex][index].fX, tests[testIndex][index]. fY); 1395 path.lineTo(tests[testIndex][index].fX, tests[testIndex][index]. fY);
1384 } 1396 }
1385 if (close) { 1397 if (close) {
1386 path.close(); 1398 path.close();
1387 } 1399 }
1388 if (!rectFirst) { 1400 if (!rectFirst) {
1389 path.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction); 1401 path.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1390 } 1402 }
1391 REPORTER_ASSERT(reporter, fail ^ path.isNestedRects(0)); 1403 REPORTER_ASSERT(reporter, fail ^ path.isNestedRects(0));
1392 if (!fail) { 1404 if (!fail) {
1393 SkRect expected[2], computed[2]; 1405 SkRect expected[2], computed[2];
1406 SkPath::Direction expectedDirs[2], computedDirs[2];
1394 SkRect testBounds; 1407 SkRect testBounds;
1395 testBounds.set(tests[testIndex], testLen[testIndex] / sizeof(SkP oint)); 1408 testBounds.set(tests[testIndex], testLen[testIndex] / sizeof(SkP oint));
1396 expected[0] = SkRect::MakeLTRB(-1, -1, 2, 2); 1409 expected[0] = SkRect::MakeLTRB(-1, -1, 2, 2);
1397 expected[1] = testBounds; 1410 expected[1] = testBounds;
1398 REPORTER_ASSERT(reporter, path.isNestedRects(computed)); 1411 if (rectFirst) {
1412 expectedDirs[0] = SkPath::kCW_Direction;
1413 } else {
1414 expectedDirs[0] = SkPath::kCCW_Direction;
1415 }
1416 expectedDirs[1] = dirs[testIndex];
1417 REPORTER_ASSERT(reporter, path.isNestedRects(computed, computedD irs));
1399 REPORTER_ASSERT(reporter, expected[0] == computed[0]); 1418 REPORTER_ASSERT(reporter, expected[0] == computed[0]);
1400 REPORTER_ASSERT(reporter, expected[1] == computed[1]); 1419 REPORTER_ASSERT(reporter, expected[1] == computed[1]);
1420 REPORTER_ASSERT(reporter, expectedDirs[0] == computedDirs[0]);
1421 REPORTER_ASSERT(reporter, expectedDirs[1] == computedDirs[1]);
1401 } 1422 }
1402 if (tests[testIndex] == lastPass) { 1423 if (tests[testIndex] == lastPass) {
1403 fail = true; 1424 fail = true;
1404 } 1425 }
1405 if (tests[testIndex] == lastClose) { 1426 if (tests[testIndex] == lastClose) {
1406 close = false; 1427 close = false;
1407 } 1428 }
1408 } 1429 }
1409 1430
1410 // fail, close then line 1431 // fail, close then line
(...skipping 978 matching lines...) Expand 10 before | Expand all | Expand 10 after
2389 test_addrect_isfinite(reporter); 2410 test_addrect_isfinite(reporter);
2390 test_tricky_cubic(); 2411 test_tricky_cubic();
2391 test_clipped_cubic(); 2412 test_clipped_cubic();
2392 test_crbug_170666(); 2413 test_crbug_170666();
2393 test_bad_cubic_crbug229478(); 2414 test_bad_cubic_crbug229478();
2394 test_bad_cubic_crbug234190(); 2415 test_bad_cubic_crbug234190();
2395 } 2416 }
2396 2417
2397 #include "TestClassDef.h" 2418 #include "TestClassDef.h"
2398 DEFINE_TESTCLASS("Path", PathTestClass, TestPath) 2419 DEFINE_TESTCLASS("Path", PathTestClass, TestPath)
OLDNEW
« no previous file with comments | « src/gpu/GrContext.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698