OLD | NEW |
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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 SkRRect rrectA = SkRRect::MakeEmpty(), rrectB = SkRRect::MakeEmpty(); | 289 SkRRect rrectA = SkRRect::MakeEmpty(), rrectB = SkRRect::MakeEmpty(); |
290 SkPath::Direction dirA = SkPath::kCW_Direction, dirB = SkPath::kCW_Direction
; | 290 SkPath::Direction dirA = SkPath::kCW_Direction, dirB = SkPath::kCW_Direction
; |
291 unsigned startA = ~0U, startB = ~0U; | 291 unsigned startA = ~0U, startB = ~0U; |
292 bool invertedA = true, invertedB = true; | 292 bool invertedA = true, invertedB = true; |
293 | 293 |
294 bool aIsRRect = a.asRRect(&rrectA, &dirA, &startA, &invertedA); | 294 bool aIsRRect = a.asRRect(&rrectA, &dirA, &startA, &invertedA); |
295 bool bIsRRect = b.asRRect(&rrectB, &dirB, &startB, &invertedB); | 295 bool bIsRRect = b.asRRect(&rrectB, &dirB, &startB, &invertedB); |
296 bool aHasPE = a.style().hasPathEffect(); | 296 bool aHasPE = a.style().hasPathEffect(); |
297 bool bHasPE = b.style().hasPathEffect(); | 297 bool bHasPE = b.style().hasPathEffect(); |
298 bool allowSameRRectButDiffStartAndDir = (aIsRRect && bIsRRect) && (aHasPE !=
bHasPE); | 298 bool allowSameRRectButDiffStartAndDir = (aIsRRect && bIsRRect) && (aHasPE !=
bHasPE); |
299 | 299 // GrShape will close paths with simple fill style. |
| 300 bool allowedClosednessDiff = (a.style().isSimpleFill() != b.style().isSimple
Fill()); |
300 SkPath pathA, pathB; | 301 SkPath pathA, pathB; |
301 a.asPath(&pathA); | 302 a.asPath(&pathA); |
302 b.asPath(&pathB); | 303 b.asPath(&pathB); |
303 | 304 |
304 // Having a dash path effect can allow 'a' but not 'b' to turn a inverse fil
l type into a | 305 // Having a dash path effect can allow 'a' but not 'b' to turn a inverse fil
l type into a |
305 // non-inverse fill type (or vice versa). | 306 // non-inverse fill type (or vice versa). |
306 bool ignoreInversenessDifference = false; | 307 bool ignoreInversenessDifference = false; |
307 if (pathA.isInverseFillType() != pathB.isInverseFillType()) { | 308 if (pathA.isInverseFillType() != pathB.isInverseFillType()) { |
308 const GrShape* s1 = pathA.isInverseFillType() ? &a : &b; | 309 const GrShape* s1 = pathA.isInverseFillType() ? &a : &b; |
309 const GrShape* s2 = pathA.isInverseFillType() ? &b : &a; | 310 const GrShape* s2 = pathA.isInverseFillType() ? &b : &a; |
(...skipping 10 matching lines...) Expand all Loading... |
320 ignoreWindingVsEvenOdd = true; | 321 ignoreWindingVsEvenOdd = true; |
321 } | 322 } |
322 } | 323 } |
323 if (allowSameRRectButDiffStartAndDir) { | 324 if (allowSameRRectButDiffStartAndDir) { |
324 REPORTER_ASSERT(r, rrectA == rrectB); | 325 REPORTER_ASSERT(r, rrectA == rrectB); |
325 REPORTER_ASSERT(r, paths_fill_same(pathA, pathB)); | 326 REPORTER_ASSERT(r, paths_fill_same(pathA, pathB)); |
326 REPORTER_ASSERT(r, ignoreInversenessDifference || invertedA == invertedB
); | 327 REPORTER_ASSERT(r, ignoreInversenessDifference || invertedA == invertedB
); |
327 } else { | 328 } else { |
328 SkPath pA = pathA; | 329 SkPath pA = pathA; |
329 SkPath pB = pathB; | 330 SkPath pB = pathB; |
| 331 REPORTER_ASSERT(r, a.inverseFilled() == pA.isInverseFillType()); |
| 332 REPORTER_ASSERT(r, b.inverseFilled() == pB.isInverseFillType()); |
330 if (ignoreInversenessDifference) { | 333 if (ignoreInversenessDifference) { |
331 pA.setFillType(SkPath::ConvertToNonInverseFillType(pathA.getFillType
())); | 334 pA.setFillType(SkPath::ConvertToNonInverseFillType(pathA.getFillType
())); |
332 pB.setFillType(SkPath::ConvertToNonInverseFillType(pathB.getFillType
())); | 335 pB.setFillType(SkPath::ConvertToNonInverseFillType(pathB.getFillType
())); |
333 } | 336 } |
334 if (ignoreWindingVsEvenOdd) { | 337 if (ignoreWindingVsEvenOdd) { |
335 pA.setFillType(pA.isInverseFillType() ? SkPath::kInverseEvenOdd_Fill
Type | 338 pA.setFillType(pA.isInverseFillType() ? SkPath::kInverseEvenOdd_Fill
Type |
336 : SkPath::kEvenOdd_FillType); | 339 : SkPath::kEvenOdd_FillType); |
337 pB.setFillType(pB.isInverseFillType() ? SkPath::kInverseEvenOdd_Fill
Type | 340 pB.setFillType(pB.isInverseFillType() ? SkPath::kInverseEvenOdd_Fill
Type |
338 : SkPath::kEvenOdd_FillType); | 341 : SkPath::kEvenOdd_FillType); |
339 } | 342 } |
340 if (!ignoreInversenessDifference && !ignoreWindingVsEvenOdd) { | 343 if (!ignoreInversenessDifference && !ignoreWindingVsEvenOdd) { |
341 REPORTER_ASSERT(r, keyA == keyB); | 344 REPORTER_ASSERT(r, keyA == keyB); |
342 } else { | 345 } else { |
343 REPORTER_ASSERT(r, keyA != keyB); | 346 REPORTER_ASSERT(r, keyA != keyB); |
344 } | 347 } |
345 if (a.style().isSimpleFill() != b.style().isSimpleFill()) { | 348 if (allowedClosednessDiff) { |
346 // GrShape will close paths with simple fill style. Make the non-fil
led path closed | 349 // GrShape will close paths with simple fill style. Make the non-fil
led path closed |
347 // so that the comparision will succeed. Make sure both are closed b
efore comparing. | 350 // so that the comparision will succeed. Make sure both are closed b
efore comparing. |
348 pA.close(); | 351 pA.close(); |
349 pB.close(); | 352 pB.close(); |
350 } | 353 } |
351 REPORTER_ASSERT(r, pA == pB); | 354 REPORTER_ASSERT(r, pA == pB); |
352 REPORTER_ASSERT(r, aIsRRect == bIsRRect); | 355 REPORTER_ASSERT(r, aIsRRect == bIsRRect); |
353 if (aIsRRect) { | 356 if (aIsRRect) { |
354 REPORTER_ASSERT(r, rrectA == rrectB); | 357 REPORTER_ASSERT(r, rrectA == rrectB); |
355 REPORTER_ASSERT(r, dirA == dirB); | 358 REPORTER_ASSERT(r, dirA == dirB); |
356 REPORTER_ASSERT(r, startA == startB); | 359 REPORTER_ASSERT(r, startA == startB); |
357 REPORTER_ASSERT(r, ignoreInversenessDifference || invertedA == inver
tedB); | 360 REPORTER_ASSERT(r, ignoreInversenessDifference || invertedA == inver
tedB); |
358 } | 361 } |
359 } | 362 } |
360 REPORTER_ASSERT(r, a.isEmpty() == b.isEmpty()); | 363 REPORTER_ASSERT(r, a.isEmpty() == b.isEmpty()); |
361 REPORTER_ASSERT(r, a.knownToBeClosed() == b.knownToBeClosed()); | 364 REPORTER_ASSERT(r, allowedClosednessDiff || a.knownToBeClosed() == b.knownTo
BeClosed()); |
| 365 // closedness can affect convexity. |
| 366 REPORTER_ASSERT(r, allowedClosednessDiff || a.knownToBeConvex() == b.knownTo
BeConvex()); |
| 367 if (a.knownToBeConvex()) { |
| 368 REPORTER_ASSERT(r, pathA.isConvex()); |
| 369 } |
| 370 if (b.knownToBeConvex()) { |
| 371 REPORTER_ASSERT(r, pathB.isConvex()); |
| 372 } |
362 REPORTER_ASSERT(r, a.bounds() == b.bounds()); | 373 REPORTER_ASSERT(r, a.bounds() == b.bounds()); |
363 REPORTER_ASSERT(r, a.segmentMask() == b.segmentMask()); | 374 REPORTER_ASSERT(r, a.segmentMask() == b.segmentMask()); |
364 SkPoint pts[4]; | 375 SkPoint pts[4]; |
365 REPORTER_ASSERT(r, a.asLine(pts) == b.asLine(pts + 2)); | 376 REPORTER_ASSERT(r, a.asLine(pts) == b.asLine(pts + 2)); |
| 377 // mayBeInverseFilledAfterStyling() is allowed to differ if one has a arbitr
ary PE and the other |
| 378 // doesn't (since the PE can set any fill type on its output path). |
| 379 // Moreover, dash style explicitly ignores inverseness. So if one is dashed
but not the other |
| 380 // then they may disagree about inverseness. |
| 381 if (a.style().hasNonDashPathEffect() == b.style().hasNonDashPathEffect() && |
| 382 a.style().isDashed() == b.style().isDashed()) { |
| 383 REPORTER_ASSERT(r, a.mayBeInverseFilledAfterStyling() == |
| 384 b.mayBeInverseFilledAfterStyling()); |
| 385 } |
366 if (a.asLine(pts)) { | 386 if (a.asLine(pts)) { |
367 REPORTER_ASSERT(r, pts[2] == pts[0] && pts[3] == pts[1]); | 387 REPORTER_ASSERT(r, pts[2] == pts[0] && pts[3] == pts[1]); |
368 } | 388 } |
| 389 REPORTER_ASSERT(r, ignoreInversenessDifference || a.inverseFilled() == b.inv
erseFilled()); |
369 } | 390 } |
370 | 391 |
371 void TestCase::compare(skiatest::Reporter* r, const TestCase& that, | 392 void TestCase::compare(skiatest::Reporter* r, const TestCase& that, |
372 ComparisonExpecation expectation) const { | 393 ComparisonExpecation expectation) const { |
373 SkPath a, b; | 394 SkPath a, b; |
374 switch (expectation) { | 395 switch (expectation) { |
375 case kAllDifferent_ComparisonExpecation: | 396 case kAllDifferent_ComparisonExpecation: |
376 REPORTER_ASSERT(r, fBaseKey != that.fBaseKey); | 397 REPORTER_ASSERT(r, fBaseKey != that.fBaseKey); |
377 REPORTER_ASSERT(r, fAppliedPEKey != that.fAppliedPEKey); | 398 REPORTER_ASSERT(r, fAppliedPEKey != that.fAppliedPEKey); |
378 REPORTER_ASSERT(r, fAppliedFullKey != that.fAppliedFullKey); | 399 REPORTER_ASSERT(r, fAppliedFullKey != that.fAppliedFullKey); |
(...skipping 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1499 REPORTER_ASSERT(reporter, testPath.fIsLine == strokePathCase.baseShape()
.asLine(nullptr)); | 1520 REPORTER_ASSERT(reporter, testPath.fIsLine == strokePathCase.baseShape()
.asLine(nullptr)); |
1500 } | 1521 } |
1501 | 1522 |
1502 // Test a volatile empty path. | 1523 // Test a volatile empty path. |
1503 test_volatile_path(reporter, SkPath(), true); | 1524 test_volatile_path(reporter, SkPath(), true); |
1504 | 1525 |
1505 test_empty_shape(reporter); | 1526 test_empty_shape(reporter); |
1506 } | 1527 } |
1507 | 1528 |
1508 #endif | 1529 #endif |
OLD | NEW |