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

Side by Side Diff: tests/GrShapeTest.cpp

Issue 2055253002: Add control over whether lines are special cased in SkDashPath. Disable when called from GrShape. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: update comments Created 4 years, 6 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
« no previous file with comments | « src/utils/SkDashPathPriv.h ('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 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include <initializer_list> 8 #include <initializer_list>
9 #include <functional> 9 #include <functional>
10 #include "Test.h" 10 #include "Test.h"
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 REPORTER_ASSERT(r, rrectA == rrectB); 318 REPORTER_ASSERT(r, rrectA == rrectB);
319 REPORTER_ASSERT(r, dirA == dirB); 319 REPORTER_ASSERT(r, dirA == dirB);
320 REPORTER_ASSERT(r, startA == startB); 320 REPORTER_ASSERT(r, startA == startB);
321 REPORTER_ASSERT(r, ignoreInversenessDifference || invertedA == inver tedB); 321 REPORTER_ASSERT(r, ignoreInversenessDifference || invertedA == inver tedB);
322 } 322 }
323 } 323 }
324 REPORTER_ASSERT(r, a.isEmpty() == b.isEmpty()); 324 REPORTER_ASSERT(r, a.isEmpty() == b.isEmpty());
325 REPORTER_ASSERT(r, a.knownToBeClosed() == b.knownToBeClosed()); 325 REPORTER_ASSERT(r, a.knownToBeClosed() == b.knownToBeClosed());
326 REPORTER_ASSERT(r, a.bounds() == b.bounds()); 326 REPORTER_ASSERT(r, a.bounds() == b.bounds());
327 REPORTER_ASSERT(r, a.segmentMask() == b.segmentMask()); 327 REPORTER_ASSERT(r, a.segmentMask() == b.segmentMask());
328 SkPoint pts[4];
329 REPORTER_ASSERT(r, a.asLine(pts) == b.asLine(pts + 2));
330 if (a.asLine(pts)) {
331 REPORTER_ASSERT(r, pts[2] == pts[0] && pts[3] == pts[1]);
332 }
328 } 333 }
329 334
330 void TestCase::compare(skiatest::Reporter* r, const TestCase& that, 335 void TestCase::compare(skiatest::Reporter* r, const TestCase& that,
331 ComparisonExpecation expectation) const { 336 ComparisonExpecation expectation) const {
332 SkPath a, b; 337 SkPath a, b;
333 switch (expectation) { 338 switch (expectation) {
334 case kAllDifferent_ComparisonExpecation: 339 case kAllDifferent_ComparisonExpecation:
335 REPORTER_ASSERT(r, fBaseKey != that.fBaseKey); 340 REPORTER_ASSERT(r, fBaseKey != that.fBaseKey);
336 REPORTER_ASSERT(r, fAppliedPEKey != that.fAppliedPEKey); 341 REPORTER_ASSERT(r, fAppliedPEKey != that.fAppliedPEKey);
337 REPORTER_ASSERT(r, fAppliedFullKey != that.fAppliedFullKey); 342 REPORTER_ASSERT(r, fAppliedFullKey != that.fAppliedFullKey);
(...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 reporter, r, 1267 reporter, r,
1263 [](SkPaint* p, SkPaint::Join j) { p->setStrokeJoin(j);}, 1268 [](SkPaint* p, SkPaint::Join j) { p->setStrokeJoin(j);},
1264 SkPaint::kMiter_Join, SkPaint::kRound_Join); 1269 SkPaint::kMiter_Join, SkPaint::kRound_Join);
1265 test_stroke_cap(reporter, r); 1270 test_stroke_cap(reporter, r);
1266 test_miter_limit(reporter, r); 1271 test_miter_limit(reporter, r);
1267 test_path_effect_makes_rrect(reporter, r); 1272 test_path_effect_makes_rrect(reporter, r);
1268 test_unknown_path_effect(reporter, r); 1273 test_unknown_path_effect(reporter, r);
1269 test_path_effect_makes_empty_shape(reporter, r); 1274 test_path_effect_makes_empty_shape(reporter, r);
1270 test_path_effect_fails(reporter, r); 1275 test_path_effect_fails(reporter, r);
1271 test_make_hairline_path_effect(reporter, r, true); 1276 test_make_hairline_path_effect(reporter, r, true);
1277 GrShape shape(r);
1278 REPORTER_ASSERT(reporter, !shape.asLine(nullptr));
1272 } 1279 }
1273 1280
1274 for (auto rr : { SkRRect::MakeRect(SkRect::MakeWH(10, 10)), 1281 for (auto rr : { SkRRect::MakeRect(SkRect::MakeWH(10, 10)),
1275 SkRRect::MakeRectXY(SkRect::MakeWH(10, 10), 3, 4), 1282 SkRRect::MakeRectXY(SkRect::MakeWH(10, 10), 3, 4),
1276 SkRRect::MakeOval(SkRect::MakeWH(20, 20))}) { 1283 SkRRect::MakeOval(SkRect::MakeWH(20, 20))}) {
1277 test_basic(reporter, rr); 1284 test_basic(reporter, rr);
1278 test_rrect(reporter, rr); 1285 test_rrect(reporter, rr);
1279 test_scale(reporter, rr); 1286 test_scale(reporter, rr);
1280 test_dash_fill(reporter, rr); 1287 test_dash_fill(reporter, rr);
1281 test_null_dash(reporter, rr); 1288 test_null_dash(reporter, rr);
1282 // Test modifying various stroke params. 1289 // Test modifying various stroke params.
1283 test_stroke_param<SkRRect, SkScalar>( 1290 test_stroke_param<SkRRect, SkScalar>(
1284 reporter, rr, 1291 reporter, rr,
1285 [](SkPaint* p, SkScalar w) { p->setStrokeWidth(w);}, 1292 [](SkPaint* p, SkScalar w) { p->setStrokeWidth(w);},
1286 SkIntToScalar(2), SkIntToScalar(4)); 1293 SkIntToScalar(2), SkIntToScalar(4));
1287 test_stroke_param<SkRRect, SkPaint::Join>( 1294 test_stroke_param<SkRRect, SkPaint::Join>(
1288 reporter, rr, 1295 reporter, rr,
1289 [](SkPaint* p, SkPaint::Join j) { p->setStrokeJoin(j); }, 1296 [](SkPaint* p, SkPaint::Join j) { p->setStrokeJoin(j); },
1290 SkPaint::kMiter_Join, SkPaint::kRound_Join); 1297 SkPaint::kMiter_Join, SkPaint::kRound_Join);
1291 test_stroke_cap(reporter, rr); 1298 test_stroke_cap(reporter, rr);
1292 test_miter_limit(reporter, rr); 1299 test_miter_limit(reporter, rr);
1293 test_path_effect_makes_rrect(reporter, rr); 1300 test_path_effect_makes_rrect(reporter, rr);
1294 test_unknown_path_effect(reporter, rr); 1301 test_unknown_path_effect(reporter, rr);
1295 test_path_effect_makes_empty_shape(reporter, rr); 1302 test_path_effect_makes_empty_shape(reporter, rr);
1296 test_path_effect_fails(reporter, rr); 1303 test_path_effect_fails(reporter, rr);
1297 test_make_hairline_path_effect(reporter, rr, true); 1304 test_make_hairline_path_effect(reporter, rr, true);
1305 GrShape shape(rr);
1306 REPORTER_ASSERT(reporter, !shape.asLine(nullptr));
1298 } 1307 }
1299 1308
1300 struct TestPath { 1309 struct TestPath {
1301 TestPath(const SkPath& path, bool isRRectFill, bool isRRectStroke, const SkRRect& rrect) 1310 TestPath(const SkPath& path, bool isRRectFill, bool isRRectStroke, bool isLine, const SkRRect& rrect)
1302 : fPath(path) 1311 : fPath(path)
1303 , fIsRRectForFill(isRRectFill) 1312 , fIsRRectForFill(isRRectFill)
1304 , fIsRRectForStroke(isRRectStroke) 1313 , fIsRRectForStroke(isRRectStroke)
1314 , fIsLine(isLine)
1305 , fRRect(rrect) {} 1315 , fRRect(rrect) {}
1306 SkPath fPath; 1316 SkPath fPath;
1307 bool fIsRRectForFill; 1317 bool fIsRRectForFill;
1308 bool fIsRRectForStroke; 1318 bool fIsRRectForStroke;
1319 bool fIsLine;
1309 SkRRect fRRect; 1320 SkRRect fRRect;
1310 }; 1321 };
1311 SkTArray<TestPath> paths; 1322 SkTArray<TestPath> paths;
1312 1323
1313 SkPath circlePath; 1324 SkPath circlePath;
1314 circlePath.addCircle(10, 10, 10); 1325 circlePath.addCircle(10, 10, 10);
1315 paths.emplace_back(circlePath, true, true, SkRRect::MakeOval(SkRect::MakeWH( 20,20))); 1326 paths.emplace_back(circlePath, true, true, false, SkRRect::MakeOval(SkRect:: MakeWH(20,20)));
1316 1327
1317 SkPath rectPath; 1328 SkPath rectPath;
1318 rectPath.addRect(SkRect::MakeWH(10, 10)); 1329 rectPath.addRect(SkRect::MakeWH(10, 10));
1319 paths.emplace_back(rectPath, true, true, SkRRect::MakeRect(SkRect::MakeWH(10 , 10))); 1330 paths.emplace_back(rectPath, true, true, false, SkRRect::MakeRect(SkRect::Ma keWH(10, 10)));
1320 1331
1321 SkPath openRectPath; 1332 SkPath openRectPath;
1322 openRectPath.moveTo(0, 0); 1333 openRectPath.moveTo(0, 0);
1323 openRectPath.lineTo(10, 0); 1334 openRectPath.lineTo(10, 0);
1324 openRectPath.lineTo(10, 10); 1335 openRectPath.lineTo(10, 10);
1325 openRectPath.lineTo(0, 10); 1336 openRectPath.lineTo(0, 10);
1326 paths.emplace_back(openRectPath, true, false, SkRRect::MakeRect(SkRect::Make WH(10, 10))); 1337 paths.emplace_back(openRectPath, true, false, false, SkRRect::MakeRect(SkRec t::MakeWH(10, 10)));
1327 1338
1328 SkPath quadPath; 1339 SkPath quadPath;
1329 quadPath.quadTo(10, 10, 5, 8); 1340 quadPath.quadTo(10, 10, 5, 8);
1330 paths.emplace_back(quadPath, false, false, SkRRect()); 1341 paths.emplace_back(quadPath, false, false, false, SkRRect());
1342
1343 SkPath linePath;
1344 linePath.lineTo(10, 10);
1345 paths.emplace_back(linePath, false, false, true, SkRRect());
1331 1346
1332 for (auto testPath : paths) { 1347 for (auto testPath : paths) {
1333 for (bool inverseFill : {false, true}) { 1348 for (bool inverseFill : {false, true}) {
1334 if (inverseFill) { 1349 if (inverseFill) {
1335 if (testPath.fPath.getFillType() == SkPath::kEvenOdd_FillType) { 1350 if (testPath.fPath.getFillType() == SkPath::kEvenOdd_FillType) {
1336 testPath.fPath.setFillType(SkPath::kInverseEvenOdd_FillType) ; 1351 testPath.fPath.setFillType(SkPath::kInverseEvenOdd_FillType) ;
1337 } else { 1352 } else {
1338 SkASSERT(testPath.fPath.getFillType() == SkPath::kWinding_Fi llType); 1353 SkASSERT(testPath.fPath.getFillType() == SkPath::kWinding_Fi llType);
1339 testPath.fPath.setFillType(SkPath::kInverseWinding_FillType) ; 1354 testPath.fPath.setFillType(SkPath::kInverseWinding_FillType) ;
1340 } 1355 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1392 TestCase strokePathCase(path, strokePaint, reporter); 1407 TestCase strokePathCase(path, strokePaint, reporter);
1393 REPORTER_ASSERT(reporter, testPath.fIsRRectForStroke == 1408 REPORTER_ASSERT(reporter, testPath.fIsRRectForStroke ==
1394 strokePathCase.baseShape().asRRect(&rrect, nul lptr, nullptr, 1409 strokePathCase.baseShape().asRRect(&rrect, nul lptr, nullptr,
1395 nullptr)); 1410 nullptr));
1396 if (testPath.fIsRRectForStroke) { 1411 if (testPath.fIsRRectForStroke) {
1397 REPORTER_ASSERT(reporter, rrect == testPath.fRRect); 1412 REPORTER_ASSERT(reporter, rrect == testPath.fRRect);
1398 TestCase strokeRRectCase(rrect, strokePaint, reporter); 1413 TestCase strokeRRectCase(rrect, strokePaint, reporter);
1399 strokePathCase.compare(reporter, strokeRRectCase, 1414 strokePathCase.compare(reporter, strokeRRectCase,
1400 TestCase::kAllSame_ComparisonExpecation); 1415 TestCase::kAllSame_ComparisonExpecation);
1401 } 1416 }
1417 REPORTER_ASSERT(reporter, testPath.fIsLine == fillPathCase.baseShape().a sLine(nullptr));
1418 REPORTER_ASSERT(reporter, testPath.fIsLine == strokePathCase.baseShape() .asLine(nullptr));
1402 } 1419 }
1403 1420
1404 // Test a volatile empty path. 1421 // Test a volatile empty path.
1405 test_volatile_path(reporter, SkPath(), true); 1422 test_volatile_path(reporter, SkPath(), true);
1406 1423
1407 test_empty_shape(reporter); 1424 test_empty_shape(reporter);
1408 } 1425 }
1409 1426
1410 #endif 1427 #endif
OLDNEW
« no previous file with comments | « src/utils/SkDashPathPriv.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698