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

Unified 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, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/GrShapeTest.cpp
diff --git a/tests/GrShapeTest.cpp b/tests/GrShapeTest.cpp
index 26224792be6906a0d55ffc8b841302a2344f4deb..aa46cd981c2c315238d33893e20d146c65248ec1 100644
--- a/tests/GrShapeTest.cpp
+++ b/tests/GrShapeTest.cpp
@@ -257,6 +257,9 @@ static void test_basic(skiatest::Reporter* reporter, const GEO& geo) {
TestCase hairlineCase(geo, hairline, reporter);
// Since hairline style doesn't change the SkPath data, it is keyed identically to fill.
hairlineCase.compare(reporter, fillCase, TestCase::kAllSame_ComparisonExpecation);
+ REPORTER_ASSERT(reporter, hairlineCase.baseShape().style().isSimpleHairline());
+ REPORTER_ASSERT(reporter, hairlineCase.appliedFullStyleShape().style().isSimpleHairline());
+ REPORTER_ASSERT(reporter, hairlineCase.appliedPathEffectShape().style().isSimpleHairline());
}
template <typename GEO, typename T>
@@ -464,7 +467,7 @@ void test_unknown_path_effect(skiatest::Reporter* reporter, const GEO& geo) {
AddLineTosPathEffect() {}
};
- // This path effect should make the keys invalid when it is applied. We only produce a pathe
+ // This path effect should make the keys invalid when it is applied. We only produce a path
// effect key for dash path effects. So the only way another arbitrary path effect can produce
// a styled result with a key is to produce a non-path shape that has a purely geometric key.
SkPaint peStroke;
@@ -479,6 +482,52 @@ void test_unknown_path_effect(skiatest::Reporter* reporter, const GEO& geo) {
geoPEStrokeCase.testExpectations(reporter, expectations);
}
+template <typename GEO>
+void test_make_hairline_path_effect(skiatest::Reporter* reporter, const GEO& geo, bool isNonPath) {
+ /**
+ * This path effect just changes the stroke rec to hairline.
+ */
+ class MakeHairlinePathEffect : SkPathEffect {
+ public:
+ bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec* strokeRec,
+ const SkRect* cullR) const override {
+ *dst = src;
+ strokeRec->setHairlineStyle();
+ return true;
+ }
+ void computeFastBounds(SkRect* dst, const SkRect& src) const override { *dst = src; }
+ static sk_sp<SkPathEffect> Make() {
+ return sk_sp<SkPathEffect>(new MakeHairlinePathEffect);
+ }
+ Factory getFactory() const override { return nullptr; }
+ void toString(SkString*) const override {}
+ private:
+ MakeHairlinePathEffect() {}
+ };
+
+ SkPaint fill;
+ SkPaint pe;
+ pe.setPathEffect(MakeHairlinePathEffect::Make());
+
+ TestCase peCase(geo, pe, reporter);
+
+ SkPath a, b;
+ peCase.baseShape().asPath(&a);
+ peCase.appliedPathEffectShape().asPath(&b);
+ REPORTER_ASSERT(reporter, a == b);
+ peCase.appliedFullStyleShape().asPath(&b);
+ REPORTER_ASSERT(reporter, a == b);
+ REPORTER_ASSERT(reporter, peCase.appliedPathEffectShape().style().isSimpleHairline());
+ REPORTER_ASSERT(reporter, peCase.appliedFullStyleShape().style().isSimpleHairline());
+ if (isNonPath) {
+ REPORTER_ASSERT(reporter, peCase.appliedPathEffectKey() == peCase.baseKey());
+ REPORTER_ASSERT(reporter, peCase.appliedFullStyleKey() == peCase.baseKey());
+ } else {
+ REPORTER_ASSERT(reporter, peCase.appliedPathEffectKey().empty());
+ REPORTER_ASSERT(reporter, peCase.appliedFullStyleKey().empty());
+ }
+}
+
/**
* isNonPath indicates whether the initial shape made from the path is expected to be recognized
* as a simpler shape type (e.g. rrect)
@@ -623,6 +672,7 @@ DEF_TEST(GrShape, reporter) {
test_path_effect_makes_rrect(reporter, rr);
test_unknown_path_effect(reporter, rr);
test_path_effect_makes_empty_shape(reporter, rr);
+ test_make_hairline_path_effect(reporter, rr, true);
}
struct TestPath {
@@ -686,6 +736,7 @@ DEF_TEST(GrShape, reporter) {
test_miter_limit(reporter, path);
test_unknown_path_effect(reporter, path);
test_path_effect_makes_empty_shape(reporter, path);
+ test_make_hairline_path_effect(reporter, path, testPath.fIsRRectForStroke);
SkPaint fillPaint;
TestCase fillPathCase(path, fillPaint, reporter);
« 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