| 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" |
| 11 #if SK_SUPPORT_GPU | 11 #if SK_SUPPORT_GPU |
| 12 #include "GrShape.h" | 12 #include "GrShape.h" |
| 13 #include "SkCanvas.h" | 13 #include "SkCanvas.h" |
| 14 #include "SkDashPathEffect.h" | 14 #include "SkDashPathEffect.h" |
| 15 #include "SkPath.h" | 15 #include "SkPath.h" |
| 16 #include "SkPathOps.h" |
| 16 #include "SkSurface.h" | 17 #include "SkSurface.h" |
| 17 | 18 |
| 18 using Key = SkTArray<uint32_t>; | 19 using Key = SkTArray<uint32_t>; |
| 19 | 20 |
| 20 static bool make_key(Key* key, const GrShape& shape) { | 21 static bool make_key(Key* key, const GrShape& shape) { |
| 21 int size = shape.unstyledKeySize(); | 22 int size = shape.unstyledKeySize(); |
| 22 if (size <= 0) { | 23 if (size <= 0) { |
| 23 key->reset(0); | 24 key->reset(0); |
| 24 return false; | 25 return false; |
| 25 } | 26 } |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 fAppliedPE.asPath(&b); | 221 fAppliedPE.asPath(&b); |
| 221 REPORTER_ASSERT(reporter, a == b); | 222 REPORTER_ASSERT(reporter, a == b); |
| 222 if (expectations.fStrokeApplies) { | 223 if (expectations.fStrokeApplies) { |
| 223 REPORTER_ASSERT(reporter, fBaseKey != fAppliedFullKey); | 224 REPORTER_ASSERT(reporter, fBaseKey != fAppliedFullKey); |
| 224 } else { | 225 } else { |
| 225 REPORTER_ASSERT(reporter, fBaseKey == fAppliedFullKey); | 226 REPORTER_ASSERT(reporter, fBaseKey == fAppliedFullKey); |
| 226 } | 227 } |
| 227 } | 228 } |
| 228 } | 229 } |
| 229 | 230 |
| 230 void TestCase::compare(skiatest::Reporter* reporter, const TestCase& that, | 231 static bool paths_fill_same(const SkPath& a, const SkPath& b) { |
| 232 SkPath pathXor; |
| 233 Op(a, b, SkPathOp::kXOR_SkPathOp, &pathXor); |
| 234 return pathXor.isEmpty(); |
| 235 } |
| 236 |
| 237 void check_equivalence(skiatest::Reporter* r, const GrShape& a, const GrShape& b
, |
| 238 const Key& keyA, const Key& keyB) { |
| 239 // GrShape only respects that input winding direction and start point for rr
ect shapes |
| 240 // when there is a path effect. Thus, if there are two GrShapes representing
the same rrect |
| 241 // but one has a path effect in its style and the other doesn't then asPath(
) and the unstyled |
| 242 // key will differ. GrShape will have canonicalized the direction and start
point for the shape |
| 243 // without the path effect. If *both* have path effects then they should hav
e both preserve |
| 244 // the direction and starting point. |
| 245 SkRRect rrectA = SkRRect::MakeEmpty(), rrectB = SkRRect::MakeEmpty(); |
| 246 SkPath::Direction dirA = SkPath::kCW_Direction, dirB = SkPath::kCW_Direction
; |
| 247 unsigned startA = ~0U, startB = ~0U; |
| 248 bool aIsRRect = a.asRRect(&rrectA, &dirA, &startA); |
| 249 bool bIsRRect = b.asRRect(&rrectB, &dirB, &startB); |
| 250 bool aHasPE = a.style().pathEffect(); |
| 251 bool bHasPE = b.style().pathEffect(); |
| 252 bool allowSameRRectButDiffStartAndDir = (aIsRRect && bIsRRect) && (aHasPE !=
bHasPE); |
| 253 SkPath pathA, pathB; |
| 254 a.asPath(&pathA); |
| 255 b.asPath(&pathB); |
| 256 if (allowSameRRectButDiffStartAndDir) { |
| 257 REPORTER_ASSERT(r, aIsRRect && bIsRRect); |
| 258 REPORTER_ASSERT(r, rrectA == rrectB); |
| 259 REPORTER_ASSERT(r, paths_fill_same(pathA, pathB)); |
| 260 } else { |
| 261 REPORTER_ASSERT(r, pathA == pathB); |
| 262 REPORTER_ASSERT(r, keyA == keyB); |
| 263 REPORTER_ASSERT(r, aIsRRect == bIsRRect); |
| 264 if (aIsRRect) { |
| 265 REPORTER_ASSERT(r, rrectA == rrectB); |
| 266 REPORTER_ASSERT(r, dirA == dirB); |
| 267 REPORTER_ASSERT(r, startA == startB); |
| 268 } |
| 269 } |
| 270 REPORTER_ASSERT(r, a.isEmpty() == b.isEmpty()); |
| 271 REPORTER_ASSERT(r, a.knownToBeClosed() == b.knownToBeClosed()); |
| 272 REPORTER_ASSERT(r, a.bounds() == b.bounds()); |
| 273 } |
| 274 |
| 275 void TestCase::compare(skiatest::Reporter* r, const TestCase& that, |
| 231 ComparisonExpecation expectation) const { | 276 ComparisonExpecation expectation) const { |
| 232 SkPath a, b; | 277 SkPath a, b; |
| 233 switch (expectation) { | 278 switch (expectation) { |
| 234 case kAllDifferent_ComparisonExpecation: | 279 case kAllDifferent_ComparisonExpecation: |
| 235 REPORTER_ASSERT(reporter, fBaseKey != that.fBaseKey); | 280 REPORTER_ASSERT(r, fBaseKey != that.fBaseKey); |
| 236 REPORTER_ASSERT(reporter, fAppliedPEKey != that.fAppliedPEKey); | 281 REPORTER_ASSERT(r, fAppliedPEKey != that.fAppliedPEKey); |
| 237 REPORTER_ASSERT(reporter, fAppliedFullKey != that.fAppliedFullKey); | 282 REPORTER_ASSERT(r, fAppliedFullKey != that.fAppliedFullKey); |
| 238 break; | 283 break; |
| 239 case kSameUpToPE_ComparisonExpecation: | 284 case kSameUpToPE_ComparisonExpecation: |
| 240 REPORTER_ASSERT(reporter, fBaseKey == that.fBaseKey); | 285 check_equivalence(r, fBase, that.fBase, fBaseKey, that.fBaseKey); |
| 241 fBase.asPath(&a); | 286 REPORTER_ASSERT(r, fAppliedPEKey != that.fAppliedPEKey); |
| 242 that.fBase.asPath(&b); | 287 REPORTER_ASSERT(r, fAppliedFullKey != that.fAppliedFullKey); |
| 243 REPORTER_ASSERT(reporter, a == b); | |
| 244 REPORTER_ASSERT(reporter, fBase.isEmpty() == that.fBase.isEmpty()); | |
| 245 REPORTER_ASSERT(reporter, fAppliedPEKey != that.fAppliedPEKey); | |
| 246 REPORTER_ASSERT(reporter, fAppliedFullKey != that.fAppliedFullKey); | |
| 247 break; | 288 break; |
| 248 case kSameUpToStroke_ComparisonExpecation: | 289 case kSameUpToStroke_ComparisonExpecation: |
| 249 REPORTER_ASSERT(reporter, fBaseKey == that.fBaseKey); | 290 check_equivalence(r, fBase, that.fBase, fBaseKey, that.fBaseKey); |
| 250 fBase.asPath(&a); | 291 check_equivalence(r, fAppliedPE, that.fAppliedPE, fAppliedPEKey, tha
t.fAppliedPEKey); |
| 251 that.fBase.asPath(&b); | 292 REPORTER_ASSERT(r, fAppliedFullKey != that.fAppliedFullKey); |
| 252 REPORTER_ASSERT(reporter, a == b); | |
| 253 REPORTER_ASSERT(reporter, fBase.isEmpty() == that.fBase.isEmpty()); | |
| 254 REPORTER_ASSERT(reporter, fAppliedPEKey == that.fAppliedPEKey); | |
| 255 fAppliedPE.asPath(&a); | |
| 256 that.fAppliedPE.asPath(&b); | |
| 257 REPORTER_ASSERT(reporter, a == b); | |
| 258 REPORTER_ASSERT(reporter, fAppliedPE.isEmpty() == that.fAppliedPE.is
Empty()); | |
| 259 REPORTER_ASSERT(reporter, fAppliedFullKey != that.fAppliedFullKey); | |
| 260 break; | 293 break; |
| 261 case kAllSame_ComparisonExpecation: | 294 case kAllSame_ComparisonExpecation: |
| 262 REPORTER_ASSERT(reporter, fBaseKey == that.fBaseKey); | 295 check_equivalence(r, fBase, that.fBase, fBaseKey, that.fBaseKey); |
| 263 fBase.asPath(&a); | 296 check_equivalence(r, fAppliedPE, that.fAppliedPE, fAppliedPEKey, tha
t.fAppliedPEKey); |
| 264 that.fBase.asPath(&b); | 297 check_equivalence(r, fAppliedFull, that.fAppliedFull, fAppliedFullKe
y, |
| 265 REPORTER_ASSERT(reporter, a == b); | 298 that.fAppliedFullKey); |
| 266 REPORTER_ASSERT(reporter, fBase.isEmpty() == that.fBase.isEmpty()); | |
| 267 REPORTER_ASSERT(reporter, fAppliedPEKey == that.fAppliedPEKey); | |
| 268 fAppliedPE.asPath(&a); | |
| 269 that.fAppliedPE.asPath(&b); | |
| 270 REPORTER_ASSERT(reporter, a == b); | |
| 271 REPORTER_ASSERT(reporter, fAppliedPE.isEmpty() == that.fAppliedPE.is
Empty()); | |
| 272 REPORTER_ASSERT(reporter, fAppliedFullKey == that.fAppliedFullKey); | |
| 273 fAppliedFull.asPath(&a); | |
| 274 that.fAppliedFull.asPath(&b); | |
| 275 REPORTER_ASSERT(reporter, a == b); | |
| 276 REPORTER_ASSERT(reporter, fAppliedFull.isEmpty() == that.fAppliedFul
l.isEmpty()); | |
| 277 break; | 299 break; |
| 278 } | 300 } |
| 279 } | 301 } |
| 280 } // namespace | 302 } // namespace |
| 281 | 303 |
| 282 static sk_sp<SkPathEffect> make_dash() { | 304 static sk_sp<SkPathEffect> make_dash() { |
| 283 static const SkScalar kIntervals[] = { 0.25, 3.f, 0.5, 2.f }; | 305 static const SkScalar kIntervals[] = { 0.25, 3.f, 0.5, 2.f }; |
| 284 static const SkScalar kPhase = 0.75; | 306 static const SkScalar kPhase = 0.75; |
| 285 return SkDashPathEffect::Make(kIntervals, SK_ARRAY_COUNT(kIntervals), kPhase
); | 307 return SkDashPathEffect::Make(kIntervals, SK_ARRAY_COUNT(kIntervals), kPhase
); |
| 286 } | 308 } |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 strokeDashCase1.compare(reporter, strokeDashCase2, TestCase::kSameUpToPE_Co
mparisonExpecation); | 434 strokeDashCase1.compare(reporter, strokeDashCase2, TestCase::kSameUpToPE_Co
mparisonExpecation); |
| 413 | 435 |
| 414 // Stroke and fill cases | 436 // Stroke and fill cases |
| 415 SkPaint strokeAndFill = stroke; | 437 SkPaint strokeAndFill = stroke; |
| 416 strokeAndFill.setStyle(SkPaint::kStrokeAndFill_Style); | 438 strokeAndFill.setStyle(SkPaint::kStrokeAndFill_Style); |
| 417 TestCase strokeAndFillCase1(geo, strokeAndFill, reporter, kS1); | 439 TestCase strokeAndFillCase1(geo, strokeAndFill, reporter, kS1); |
| 418 TestCase strokeAndFillCase2(geo, strokeAndFill, reporter, kS2); | 440 TestCase strokeAndFillCase2(geo, strokeAndFill, reporter, kS2); |
| 419 // Scale affects the stroke. Though, this can wind up creating a rect when t
he input is a rect. | 441 // Scale affects the stroke. Though, this can wind up creating a rect when t
he input is a rect. |
| 420 // In that case we wind up with a pure geometry key and the geometries are t
he same. | 442 // In that case we wind up with a pure geometry key and the geometries are t
he same. |
| 421 SkRRect rrect; | 443 SkRRect rrect; |
| 422 if (strokeAndFillCase1.appliedFullStyleShape().asRRect(&rrect)) { | 444 if (strokeAndFillCase1.appliedFullStyleShape().asRRect(&rrect, nullptr, null
ptr)) { |
| 423 // We currently only expect to get here in the rect->rect case. | 445 // We currently only expect to get here in the rect->rect case. |
| 424 REPORTER_ASSERT(reporter, rrect.isRect()); | 446 REPORTER_ASSERT(reporter, rrect.isRect()); |
| 425 REPORTER_ASSERT(reporter, strokeAndFillCase1.baseShape().asRRect(&rrect)
&& rrect.isRect()); | 447 REPORTER_ASSERT(reporter, |
| 448 strokeAndFillCase1.baseShape().asRRect(&rrect, nullptr,
nullptr) && |
| 449 rrect.isRect()); |
| 426 strokeAndFillCase1.compare(reporter, strokeAndFillCase2, | 450 strokeAndFillCase1.compare(reporter, strokeAndFillCase2, |
| 427 TestCase::kAllSame_ComparisonExpecation); | 451 TestCase::kAllSame_ComparisonExpecation); |
| 428 } else { | 452 } else { |
| 429 strokeAndFillCase1.compare(reporter, strokeAndFillCase2, | 453 strokeAndFillCase1.compare(reporter, strokeAndFillCase2, |
| 430 TestCase::kSameUpToStroke_ComparisonExpecatio
n); | 454 TestCase::kSameUpToStroke_ComparisonExpecatio
n); |
| 431 } | 455 } |
| 432 | 456 |
| 433 SkPaint strokeAndFillDash = strokeDash; | 457 SkPaint strokeAndFillDash = strokeDash; |
| 434 strokeAndFillDash.setStyle(SkPaint::kStrokeAndFill_Style); | 458 strokeAndFillDash.setStyle(SkPaint::kStrokeAndFill_Style); |
| 435 TestCase strokeAndFillDashCase1(geo, strokeAndFillDash, reporter, kS1); | 459 TestCase strokeAndFillDashCase1(geo, strokeAndFillDash, reporter, kS1); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 TestCase::kSameUpToStroke_ComparisonExpecation); | 678 TestCase::kSameUpToStroke_ComparisonExpecation); |
| 655 | 679 |
| 656 TestCase rrectFillCase(RRectPathEffect::RRect(), fill, reporter); | 680 TestCase rrectFillCase(RRectPathEffect::RRect(), fill, reporter); |
| 657 SkPaint stroke = peStroke; | 681 SkPaint stroke = peStroke; |
| 658 stroke.setPathEffect(nullptr); | 682 stroke.setPathEffect(nullptr); |
| 659 TestCase rrectStrokeCase(RRectPathEffect::RRect(), stroke, reporter); | 683 TestCase rrectStrokeCase(RRectPathEffect::RRect(), stroke, reporter); |
| 660 | 684 |
| 661 SkRRect rrect; | 685 SkRRect rrect; |
| 662 // Applying the path effect should make a SkRRect shape. There is no further
stroking in the | 686 // Applying the path effect should make a SkRRect shape. There is no further
stroking in the |
| 663 // geoPECase, so the full style should be the same as just the PE. | 687 // geoPECase, so the full style should be the same as just the PE. |
| 664 REPORTER_ASSERT(reporter, geoPECase.appliedPathEffectShape().asRRect(&rrect)
); | 688 REPORTER_ASSERT(reporter, geoPECase.appliedPathEffectShape().asRRect(&rrect,
nullptr, nullptr)); |
| 665 REPORTER_ASSERT(reporter, rrect == RRectPathEffect::RRect()); | 689 REPORTER_ASSERT(reporter, rrect == RRectPathEffect::RRect()); |
| 666 REPORTER_ASSERT(reporter, geoPECase.appliedPathEffectKey() == rrectFillCase.
baseKey()); | 690 REPORTER_ASSERT(reporter, geoPECase.appliedPathEffectKey() == rrectFillCase.
baseKey()); |
| 667 | 691 |
| 668 REPORTER_ASSERT(reporter, geoPECase.appliedFullStyleShape().asRRect(&rrect))
; | 692 REPORTER_ASSERT(reporter, geoPECase.appliedFullStyleShape().asRRect(&rrect,
nullptr, nullptr)); |
| 669 REPORTER_ASSERT(reporter, rrect == RRectPathEffect::RRect()); | 693 REPORTER_ASSERT(reporter, rrect == RRectPathEffect::RRect()); |
| 670 REPORTER_ASSERT(reporter, geoPECase.appliedFullStyleKey() == rrectFillCase.b
aseKey()); | 694 REPORTER_ASSERT(reporter, geoPECase.appliedFullStyleKey() == rrectFillCase.b
aseKey()); |
| 671 | 695 |
| 672 // In the PE+stroke case applying the full style should be the same as just
stroking the rrect. | 696 // In the PE+stroke case applying the full style should be the same as just
stroking the rrect. |
| 673 REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedPathEffectShape().asRRect(&
rrect)); | 697 REPORTER_ASSERT(reporter, |
| 698 geoPEStrokeCase.appliedPathEffectShape().asRRect(&rrect, nul
lptr, nullptr)); |
| 674 REPORTER_ASSERT(reporter, rrect == RRectPathEffect::RRect()); | 699 REPORTER_ASSERT(reporter, rrect == RRectPathEffect::RRect()); |
| 675 REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedPathEffectKey() == rrectFil
lCase.baseKey()); | 700 REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedPathEffectKey() == rrectFil
lCase.baseKey()); |
| 676 | 701 |
| 677 REPORTER_ASSERT(reporter, !geoPEStrokeCase.appliedFullStyleShape().asRRect(&
rrect)); | 702 REPORTER_ASSERT(reporter, |
| 703 !geoPEStrokeCase.appliedFullStyleShape().asRRect(&rrect, nul
lptr, nullptr)); |
| 678 REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedFullStyleKey() == | 704 REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedFullStyleKey() == |
| 679 rrectStrokeCase.appliedFullStyleKey()); | 705 rrectStrokeCase.appliedFullStyleKey()); |
| 680 } | 706 } |
| 681 | 707 |
| 682 template <typename GEO> | 708 template <typename GEO> |
| 683 void test_unknown_path_effect(skiatest::Reporter* reporter, const GEO& geo) { | 709 void test_unknown_path_effect(skiatest::Reporter* reporter, const GEO& geo) { |
| 684 /** | 710 /** |
| 685 * This path effect just adds two lineTos to the input path. | 711 * This path effect just adds two lineTos to the input path. |
| 686 */ | 712 */ |
| 687 class AddLineTosPathEffect : SkPathEffect { | 713 class AddLineTosPathEffect : SkPathEffect { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 private: | 768 private: |
| 743 MakeHairlinePathEffect() {} | 769 MakeHairlinePathEffect() {} |
| 744 }; | 770 }; |
| 745 | 771 |
| 746 SkPaint fill; | 772 SkPaint fill; |
| 747 SkPaint pe; | 773 SkPaint pe; |
| 748 pe.setPathEffect(MakeHairlinePathEffect::Make()); | 774 pe.setPathEffect(MakeHairlinePathEffect::Make()); |
| 749 | 775 |
| 750 TestCase peCase(geo, pe, reporter); | 776 TestCase peCase(geo, pe, reporter); |
| 751 | 777 |
| 752 SkPath a, b; | 778 SkPath a, b, c; |
| 753 peCase.baseShape().asPath(&a); | 779 peCase.baseShape().asPath(&a); |
| 754 peCase.appliedPathEffectShape().asPath(&b); | 780 peCase.appliedPathEffectShape().asPath(&b); |
| 755 REPORTER_ASSERT(reporter, a == b); | 781 peCase.appliedFullStyleShape().asPath(&c); |
| 756 peCase.appliedFullStyleShape().asPath(&b); | |
| 757 REPORTER_ASSERT(reporter, a == b); | |
| 758 REPORTER_ASSERT(reporter, peCase.appliedPathEffectShape().style().isSimpleHa
irline()); | |
| 759 REPORTER_ASSERT(reporter, peCase.appliedFullStyleShape().style().isSimpleHai
rline()); | |
| 760 if (isNonPath) { | 782 if (isNonPath) { |
| 761 REPORTER_ASSERT(reporter, peCase.appliedPathEffectKey() == peCase.baseKe
y()); | 783 // RRect types can have a change in start index or direction after the P
E is applied. This |
| 762 REPORTER_ASSERT(reporter, peCase.appliedFullStyleKey() == peCase.baseKey
()); | 784 // is because once the PE is applied, GrShape may canonicalize the dir a
nd index since it |
| 785 // is not germane to the styling any longer. |
| 786 // Instead we just check that the paths would fill the same both before
and after styling. |
| 787 REPORTER_ASSERT(reporter, paths_fill_same(a, b)); |
| 788 REPORTER_ASSERT(reporter, paths_fill_same(a, c)); |
| 763 } else { | 789 } else { |
| 790 REPORTER_ASSERT(reporter, a == b); |
| 791 REPORTER_ASSERT(reporter, a == c); |
| 764 REPORTER_ASSERT(reporter, peCase.appliedPathEffectKey().empty()); | 792 REPORTER_ASSERT(reporter, peCase.appliedPathEffectKey().empty()); |
| 765 REPORTER_ASSERT(reporter, peCase.appliedFullStyleKey().empty()); | 793 REPORTER_ASSERT(reporter, peCase.appliedFullStyleKey().empty()); |
| 766 } | 794 } |
| 795 REPORTER_ASSERT(reporter, peCase.appliedPathEffectShape().style().isSimpleHa
irline()); |
| 796 REPORTER_ASSERT(reporter, peCase.appliedFullStyleShape().style().isSimpleHai
rline()); |
| 767 } | 797 } |
| 768 | 798 |
| 769 /** | 799 /** |
| 770 * isNonPath indicates whether the initial shape made from the path is expected
to be recognized | 800 * isNonPath indicates whether the initial shape made from the path is expected
to be recognized |
| 771 * as a simpler shape type (e.g. rrect) | 801 * as a simpler shape type (e.g. rrect) |
| 772 */ | 802 */ |
| 773 void test_volatile_path(skiatest::Reporter* reporter, const SkPath& path, | 803 void test_volatile_path(skiatest::Reporter* reporter, const SkPath& path, |
| 774 bool isNonPath) { | 804 bool isNonPath) { |
| 775 SkPath vPath(path); | 805 SkPath vPath(path); |
| 776 vPath.setIsVolatile(true); | 806 vPath.setIsVolatile(true); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 TestCase::kAllSame_ComparisonExpecation)
; | 917 TestCase::kAllSame_ComparisonExpecation)
; |
| 888 | 918 |
| 889 // Same for a rect. | 919 // Same for a rect. |
| 890 SkRect emptyRect = SkRect::MakeEmpty(); | 920 SkRect emptyRect = SkRect::MakeEmpty(); |
| 891 TestCase dashAndStrokeEmptyRectCase(emptyRect, dashAndStroke, reporter); | 921 TestCase dashAndStrokeEmptyRectCase(emptyRect, dashAndStroke, reporter); |
| 892 dashAndStrokeEmptyRectCase.compare(reporter, fillEmptyCase, | 922 dashAndStrokeEmptyRectCase.compare(reporter, fillEmptyCase, |
| 893 TestCase::kAllSame_ComparisonExpecation); | 923 TestCase::kAllSame_ComparisonExpecation); |
| 894 } | 924 } |
| 895 | 925 |
| 896 DEF_TEST(GrShape, reporter) { | 926 DEF_TEST(GrShape, reporter) { |
| 897 sk_sp<SkPathEffect> dashPE = make_dash(); | 927 for (auto r : { SkRect::MakeWH(10, 20), |
| 928 SkRect::MakeWH(-10, -20), |
| 929 SkRect::MakeWH(-10, 20), |
| 930 SkRect::MakeWH(10, -20)}) { |
| 931 test_basic(reporter, r); |
| 932 test_scale(reporter, r); |
| 933 test_dash_fill(reporter, r); |
| 934 test_null_dash(reporter, r); |
| 935 // Test modifying various stroke params. |
| 936 test_stroke_param<SkRect, SkScalar>( |
| 937 reporter, r, |
| 938 [](SkPaint* p, SkScalar w) { p->setStrokeWidth(w);}, |
| 939 SkIntToScalar(2), SkIntToScalar(4)); |
| 940 test_stroke_param<SkRect, SkPaint::Join>( |
| 941 reporter, r, |
| 942 [](SkPaint* p, SkPaint::Join j) { p->setStrokeJoin(j);}, |
| 943 SkPaint::kMiter_Join, SkPaint::kRound_Join); |
| 944 test_stroke_cap(reporter, r); |
| 945 test_miter_limit(reporter, r); |
| 946 test_path_effect_makes_rrect(reporter, r); |
| 947 test_unknown_path_effect(reporter, r); |
| 948 test_path_effect_makes_empty_shape(reporter, r); |
| 949 test_make_hairline_path_effect(reporter, r, true); |
| 950 } |
| 898 | 951 |
| 899 for (auto rr : { SkRRect::MakeRect(SkRect::MakeWH(10, 10)), | 952 for (auto rr : { SkRRect::MakeRect(SkRect::MakeWH(10, 10)), |
| 900 SkRRect::MakeRectXY(SkRect::MakeWH(10, 10), 3, 4)}) { | 953 SkRRect::MakeRectXY(SkRect::MakeWH(10, 10), 3, 4), |
| 954 SkRRect::MakeOval(SkRect::MakeWH(20, 20))}) { |
| 901 test_basic(reporter, rr); | 955 test_basic(reporter, rr); |
| 902 test_scale(reporter, rr); | 956 test_scale(reporter, rr); |
| 903 test_dash_fill(reporter, rr); | 957 test_dash_fill(reporter, rr); |
| 904 test_null_dash(reporter, rr); | 958 test_null_dash(reporter, rr); |
| 905 // Test modifying various stroke params. | 959 // Test modifying various stroke params. |
| 906 test_stroke_param<SkRRect, SkScalar>( | 960 test_stroke_param<SkRRect, SkScalar>( |
| 907 reporter, rr, | 961 reporter, rr, |
| 908 [](SkPaint* p, SkScalar w) { p->setStrokeWidth(w);}, | 962 [](SkPaint* p, SkScalar w) { p->setStrokeWidth(w);}, |
| 909 SkIntToScalar(2), SkIntToScalar(4)); | 963 SkIntToScalar(2), SkIntToScalar(4)); |
| 910 test_stroke_param<SkRRect, SkPaint::Join>( | 964 test_stroke_param<SkRRect, SkPaint::Join>( |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 977 test_stroke_cap(reporter, path); | 1031 test_stroke_cap(reporter, path); |
| 978 test_miter_limit(reporter, path); | 1032 test_miter_limit(reporter, path); |
| 979 test_unknown_path_effect(reporter, path); | 1033 test_unknown_path_effect(reporter, path); |
| 980 test_path_effect_makes_empty_shape(reporter, path); | 1034 test_path_effect_makes_empty_shape(reporter, path); |
| 981 test_make_hairline_path_effect(reporter, path, testPath.fIsRRectForStrok
e); | 1035 test_make_hairline_path_effect(reporter, path, testPath.fIsRRectForStrok
e); |
| 982 | 1036 |
| 983 SkPaint fillPaint; | 1037 SkPaint fillPaint; |
| 984 TestCase fillPathCase(path, fillPaint, reporter); | 1038 TestCase fillPathCase(path, fillPaint, reporter); |
| 985 SkRRect rrect; | 1039 SkRRect rrect; |
| 986 REPORTER_ASSERT(reporter, testPath.fIsRRectForFill == | 1040 REPORTER_ASSERT(reporter, testPath.fIsRRectForFill == |
| 987 fillPathCase.baseShape().asRRect(&rrect)); | 1041 fillPathCase.baseShape().asRRect(&rrect, nullp
tr, nullptr)); |
| 988 if (testPath.fIsRRectForFill) { | 1042 if (testPath.fIsRRectForFill) { |
| 1043 TestCase fillPathCase2(path, fillPaint, reporter); |
| 989 REPORTER_ASSERT(reporter, rrect == testPath.fRRect); | 1044 REPORTER_ASSERT(reporter, rrect == testPath.fRRect); |
| 990 TestCase fillRRectCase(rrect, fillPaint, reporter); | 1045 TestCase fillRRectCase(rrect, fillPaint, reporter); |
| 991 fillPathCase.compare(reporter, fillRRectCase, TestCase::kAllSame_Com
parisonExpecation); | 1046 fillPathCase2.compare(reporter, fillRRectCase, TestCase::kAllSame_Co
mparisonExpecation); |
| 992 } | 1047 } |
| 993 | 1048 |
| 994 SkPaint strokePaint; | 1049 SkPaint strokePaint; |
| 995 strokePaint.setStrokeWidth(3.f); | 1050 strokePaint.setStrokeWidth(3.f); |
| 996 strokePaint.setStyle(SkPaint::kStroke_Style); | 1051 strokePaint.setStyle(SkPaint::kStroke_Style); |
| 997 TestCase strokePathCase(path, strokePaint, reporter); | 1052 TestCase strokePathCase(path, strokePaint, reporter); |
| 998 REPORTER_ASSERT(reporter, testPath.fIsRRectForStroke == | 1053 REPORTER_ASSERT(reporter, testPath.fIsRRectForStroke == |
| 999 strokePathCase.baseShape().asRRect(&rrect)); | 1054 strokePathCase.baseShape().asRRect(&rrect, nul
lptr, nullptr)); |
| 1000 if (testPath.fIsRRectForStroke) { | 1055 if (testPath.fIsRRectForStroke) { |
| 1001 REPORTER_ASSERT(reporter, rrect == testPath.fRRect); | 1056 REPORTER_ASSERT(reporter, rrect == testPath.fRRect); |
| 1002 TestCase strokeRRectCase(rrect, strokePaint, reporter); | 1057 TestCase strokeRRectCase(rrect, strokePaint, reporter); |
| 1003 strokePathCase.compare(reporter, strokeRRectCase, | 1058 strokePathCase.compare(reporter, strokeRRectCase, |
| 1004 TestCase::kAllSame_ComparisonExpecation); | 1059 TestCase::kAllSame_ComparisonExpecation); |
| 1005 } | 1060 } |
| 1006 } | 1061 } |
| 1007 | 1062 |
| 1008 // Test a volatile empty path. | 1063 // Test a volatile empty path. |
| 1009 test_volatile_path(reporter, SkPath(), true); | 1064 test_volatile_path(reporter, SkPath(), true); |
| 1010 | 1065 |
| 1011 test_empty_shape(reporter); | 1066 test_empty_shape(reporter); |
| 1012 } | 1067 } |
| 1013 | 1068 |
| 1014 #endif | 1069 #endif |
| OLD | NEW |