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

Side by Side Diff: tests/GrShapeTest.cpp

Issue 1949903002: Add some more testing around hairline GrShapes (Closed) Base URL: https://skia.googlesource.com/skia.git@styleiface
Patch Set: Created 4 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
« no previous file with comments | « no previous file | 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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 TestCase::kSameUpToPE_ComparisonExpecation); 250 TestCase::kSameUpToPE_ComparisonExpecation);
251 stroke2RoundBevelCase.compare(reporter, stroke2RoundBevelDashCase, 251 stroke2RoundBevelCase.compare(reporter, stroke2RoundBevelDashCase,
252 TestCase::kSameUpToPE_ComparisonExpecation); 252 TestCase::kSameUpToPE_ComparisonExpecation);
253 253
254 SkPaint hairline; 254 SkPaint hairline;
255 hairline.setStyle(SkPaint::kStroke_Style); 255 hairline.setStyle(SkPaint::kStroke_Style);
256 hairline.setStrokeWidth(0.f); 256 hairline.setStrokeWidth(0.f);
257 TestCase hairlineCase(geo, hairline, reporter); 257 TestCase hairlineCase(geo, hairline, reporter);
258 // Since hairline style doesn't change the SkPath data, it is keyed identica lly to fill. 258 // Since hairline style doesn't change the SkPath data, it is keyed identica lly to fill.
259 hairlineCase.compare(reporter, fillCase, TestCase::kAllSame_ComparisonExpeca tion); 259 hairlineCase.compare(reporter, fillCase, TestCase::kAllSame_ComparisonExpeca tion);
260 REPORTER_ASSERT(reporter, hairlineCase.baseShape().style().isSimpleHairline( ));
261 REPORTER_ASSERT(reporter, hairlineCase.appliedFullStyleShape().style().isSim pleHairline());
262 REPORTER_ASSERT(reporter, hairlineCase.appliedPathEffectShape().style().isSi mpleHairline());
260 } 263 }
261 264
262 template <typename GEO, typename T> 265 template <typename GEO, typename T>
263 static void test_stroke_param(skiatest::Reporter* reporter, const GEO& geo, 266 static void test_stroke_param(skiatest::Reporter* reporter, const GEO& geo,
264 std::function<void(SkPaint*, T)> setter, T a, T b) { 267 std::function<void(SkPaint*, T)> setter, T a, T b) {
265 // Set the stroke width so that we don't get hairline. However, call the fun ction second so that 268 // Set the stroke width so that we don't get hairline. However, call the fun ction second so that
266 // it can override. 269 // it can override.
267 SkPaint strokeA; 270 SkPaint strokeA;
268 strokeA.setStyle(SkPaint::kStroke_Style); 271 strokeA.setStyle(SkPaint::kStroke_Style);
269 strokeA.setStrokeWidth(2.f); 272 strokeA.setStrokeWidth(2.f);
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 dst->growToInclude(0, 0); 460 dst->growToInclude(0, 0);
458 dst->growToInclude(10, 10); 461 dst->growToInclude(10, 10);
459 } 462 }
460 static sk_sp<SkPathEffect> Make() { return sk_sp<SkPathEffect>(new AddLi neTosPathEffect); } 463 static sk_sp<SkPathEffect> Make() { return sk_sp<SkPathEffect>(new AddLi neTosPathEffect); }
461 Factory getFactory() const override { return nullptr; } 464 Factory getFactory() const override { return nullptr; }
462 void toString(SkString*) const override {} 465 void toString(SkString*) const override {}
463 private: 466 private:
464 AddLineTosPathEffect() {} 467 AddLineTosPathEffect() {}
465 }; 468 };
466 469
467 // This path effect should make the keys invalid when it is applied. We onl y produce a pathe 470 // This path effect should make the keys invalid when it is applied. We onl y produce a path
468 // effect key for dash path effects. So the only way another arbitrary path effect can produce 471 // effect key for dash path effects. So the only way another arbitrary path effect can produce
469 // a styled result with a key is to produce a non-path shape that has a pur ely geometric key. 472 // a styled result with a key is to produce a non-path shape that has a pur ely geometric key.
470 SkPaint peStroke; 473 SkPaint peStroke;
471 peStroke.setPathEffect(AddLineTosPathEffect::Make()); 474 peStroke.setPathEffect(AddLineTosPathEffect::Make());
472 peStroke.setStrokeWidth(2.f); 475 peStroke.setStrokeWidth(2.f);
473 peStroke.setStyle(SkPaint::kStroke_Style); 476 peStroke.setStyle(SkPaint::kStroke_Style);
474 TestCase geoPEStrokeCase(geo, peStroke, reporter); 477 TestCase geoPEStrokeCase(geo, peStroke, reporter);
475 TestCase::SelfExpectations expectations; 478 TestCase::SelfExpectations expectations;
476 expectations.fPEHasEffect = true; 479 expectations.fPEHasEffect = true;
477 expectations.fPEHasValidKey = false; 480 expectations.fPEHasValidKey = false;
478 expectations.fStrokeApplies = true; 481 expectations.fStrokeApplies = true;
479 geoPEStrokeCase.testExpectations(reporter, expectations); 482 geoPEStrokeCase.testExpectations(reporter, expectations);
480 } 483 }
481 484
485 template <typename GEO>
486 void test_make_hairline_path_effect(skiatest::Reporter* reporter, const GEO& geo , bool isNonPath) {
487 /**
488 * This path effect just changes the stroke rec to hairline.
489 */
490 class MakeHairlinePathEffect : SkPathEffect {
491 public:
492 bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec* strokeRec,
493 const SkRect* cullR) const override {
494 *dst = src;
495 strokeRec->setHairlineStyle();
496 return true;
497 }
498 void computeFastBounds(SkRect* dst, const SkRect& src) const override { *dst = src; }
499 static sk_sp<SkPathEffect> Make() {
500 return sk_sp<SkPathEffect>(new MakeHairlinePathEffect);
501 }
502 Factory getFactory() const override { return nullptr; }
503 void toString(SkString*) const override {}
504 private:
505 MakeHairlinePathEffect() {}
506 };
507
508 SkPaint fill;
509 SkPaint pe;
510 pe.setPathEffect(MakeHairlinePathEffect::Make());
511
512 TestCase peCase(geo, pe, reporter);
513
514 SkPath a, b;
515 peCase.baseShape().asPath(&a);
516 peCase.appliedPathEffectShape().asPath(&b);
517 REPORTER_ASSERT(reporter, a == b);
518 peCase.appliedFullStyleShape().asPath(&b);
519 REPORTER_ASSERT(reporter, a == b);
520 REPORTER_ASSERT(reporter, peCase.appliedPathEffectShape().style().isSimpleHa irline());
521 REPORTER_ASSERT(reporter, peCase.appliedFullStyleShape().style().isSimpleHai rline());
522 if (isNonPath) {
523 REPORTER_ASSERT(reporter, peCase.appliedPathEffectKey() == peCase.baseKe y());
524 REPORTER_ASSERT(reporter, peCase.appliedFullStyleKey() == peCase.baseKey ());
525 } else {
526 REPORTER_ASSERT(reporter, peCase.appliedPathEffectKey().empty());
527 REPORTER_ASSERT(reporter, peCase.appliedFullStyleKey().empty());
528 }
529 }
530
482 /** 531 /**
483 * isNonPath indicates whether the initial shape made from the path is expected to be recognized 532 * isNonPath indicates whether the initial shape made from the path is expected to be recognized
484 * as a simpler shape type (e.g. rrect) 533 * as a simpler shape type (e.g. rrect)
485 */ 534 */
486 void test_volatile_path(skiatest::Reporter* reporter, const SkPath& path, 535 void test_volatile_path(skiatest::Reporter* reporter, const SkPath& path,
487 bool isNonPath) { 536 bool isNonPath) {
488 SkPath vPath(path); 537 SkPath vPath(path);
489 vPath.setIsVolatile(true); 538 vPath.setIsVolatile(true);
490 539
491 SkPaint dashAndStroke; 540 SkPaint dashAndStroke;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 [](SkPaint* p, SkPaint::Cap c) { p->setStrokeCap(c);}, 665 [](SkPaint* p, SkPaint::Cap c) { p->setStrokeCap(c);},
617 SkPaint::kButt_Cap, SkPaint::kRound_Cap); 666 SkPaint::kButt_Cap, SkPaint::kRound_Cap);
618 test_stroke_param<SkRRect, SkPaint::Join>( 667 test_stroke_param<SkRRect, SkPaint::Join>(
619 reporter, rr, 668 reporter, rr,
620 [](SkPaint* p, SkPaint::Join j) { p->setStrokeJoin(j); }, 669 [](SkPaint* p, SkPaint::Join j) { p->setStrokeJoin(j); },
621 SkPaint::kMiter_Join, SkPaint::kRound_Join); 670 SkPaint::kMiter_Join, SkPaint::kRound_Join);
622 test_miter_limit(reporter, rr); 671 test_miter_limit(reporter, rr);
623 test_path_effect_makes_rrect(reporter, rr); 672 test_path_effect_makes_rrect(reporter, rr);
624 test_unknown_path_effect(reporter, rr); 673 test_unknown_path_effect(reporter, rr);
625 test_path_effect_makes_empty_shape(reporter, rr); 674 test_path_effect_makes_empty_shape(reporter, rr);
675 test_make_hairline_path_effect(reporter, rr, true);
626 } 676 }
627 677
628 struct TestPath { 678 struct TestPath {
629 TestPath(const SkPath& path, bool isRRectFill, bool isRRectStroke ,const SkRRect& rrect) 679 TestPath(const SkPath& path, bool isRRectFill, bool isRRectStroke ,const SkRRect& rrect)
630 : fPath(path) 680 : fPath(path)
631 , fIsRRectForFill(isRRectFill) 681 , fIsRRectForFill(isRRectFill)
632 , fIsRRectForStroke(isRRectStroke) 682 , fIsRRectForStroke(isRRectStroke)
633 , fRRect(rrect) {} 683 , fRRect(rrect) {}
634 SkPath fPath; 684 SkPath fPath;
635 bool fIsRRectForFill; 685 bool fIsRRectForFill;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 reporter, path, 729 reporter, path,
680 [](SkPaint* p, SkPaint::Cap c) { p->setStrokeCap(c);}, 730 [](SkPaint* p, SkPaint::Cap c) { p->setStrokeCap(c);},
681 SkPaint::kButt_Cap, SkPaint::kRound_Cap); 731 SkPaint::kButt_Cap, SkPaint::kRound_Cap);
682 test_stroke_param<SkPath, SkPaint::Join>( 732 test_stroke_param<SkPath, SkPaint::Join>(
683 reporter, path, 733 reporter, path,
684 [](SkPaint* p, SkPaint::Join j) { p->setStrokeJoin(j);}, 734 [](SkPaint* p, SkPaint::Join j) { p->setStrokeJoin(j);},
685 SkPaint::kMiter_Join, SkPaint::kRound_Join); 735 SkPaint::kMiter_Join, SkPaint::kRound_Join);
686 test_miter_limit(reporter, path); 736 test_miter_limit(reporter, path);
687 test_unknown_path_effect(reporter, path); 737 test_unknown_path_effect(reporter, path);
688 test_path_effect_makes_empty_shape(reporter, path); 738 test_path_effect_makes_empty_shape(reporter, path);
739 test_make_hairline_path_effect(reporter, path, testPath.fIsRRectForStrok e);
689 740
690 SkPaint fillPaint; 741 SkPaint fillPaint;
691 TestCase fillPathCase(path, fillPaint, reporter); 742 TestCase fillPathCase(path, fillPaint, reporter);
692 SkRRect rrect; 743 SkRRect rrect;
693 REPORTER_ASSERT(reporter, testPath.fIsRRectForFill == 744 REPORTER_ASSERT(reporter, testPath.fIsRRectForFill ==
694 fillPathCase.baseShape().asRRect(&rrect)); 745 fillPathCase.baseShape().asRRect(&rrect));
695 if (testPath.fIsRRectForFill) { 746 if (testPath.fIsRRectForFill) {
696 REPORTER_ASSERT(reporter, rrect == testPath.fRRect); 747 REPORTER_ASSERT(reporter, rrect == testPath.fRRect);
697 TestCase fillRRectCase(rrect, fillPaint, reporter); 748 TestCase fillRRectCase(rrect, fillPaint, reporter);
698 fillPathCase.compare(reporter, fillRRectCase, TestCase::kAllSame_Com parisonExpecation); 749 fillPathCase.compare(reporter, fillRRectCase, TestCase::kAllSame_Com parisonExpecation);
(...skipping 13 matching lines...) Expand all
712 } 763 }
713 } 764 }
714 765
715 // Test a volatile empty path. 766 // Test a volatile empty path.
716 test_volatile_path(reporter, SkPath(), true); 767 test_volatile_path(reporter, SkPath(), true);
717 768
718 test_empty_shape(reporter); 769 test_empty_shape(reporter);
719 } 770 }
720 771
721 #endif 772 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698