diff options
author | kkinnunen <kkinnunen@nvidia.com> | 2015-05-13 00:02:26 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-13 00:02:26 -0700 |
commit | 8f827fe44aad3c93638bc0f5dec32812c9ba2c98 (patch) | |
tree | b260113cf56fbf1f745de60ce7d44cda9072b362 | |
parent | 6cbf18c70bf99f58b2bb1c49cdf8d41be561fee4 (diff) |
Fix SkStrokeRec == to report true for all fills
Fix SkStrokeRec == to report true for all fills, regardless
of the stale stroking data the object might contain.
Review URL: https://codereview.chromium.org/1130153002
-rw-r--r-- | include/core/SkStrokeRec.h | 20 | ||||
-rw-r--r-- | src/gpu/GrPath.h | 2 | ||||
-rw-r--r-- | tests/StrokeTest.cpp | 77 |
3 files changed, 92 insertions, 7 deletions
diff --git a/include/core/SkStrokeRec.h b/include/core/SkStrokeRec.h index 00b1fc1fca..b56dacb42c 100644 --- a/include/core/SkStrokeRec.h +++ b/include/core/SkStrokeRec.h @@ -95,12 +95,20 @@ public: */ void applyToPaint(SkPaint* paint) const; - bool operator==(const SkStrokeRec& other) const { - return fWidth == other.fWidth && - fMiterLimit == other.fMiterLimit && - fCap == other.fCap && - fJoin == other.fJoin && - fStrokeAndFill == other.fStrokeAndFill; + /** + * Compare if two SkStrokeRecs have an equal effect on a path. + * Equal SkStrokeRecs produce equal paths. Equality of produced + * paths does not take the ResScale parameter into account. + */ + bool hasEqualEffect(const SkStrokeRec& other) const { + if (!this->needToApply()) { + return this->getStyle() == other.getStyle(); + } + return fWidth == other.fWidth && + fMiterLimit == other.fMiterLimit && + fCap == other.fCap && + fJoin == other.fJoin && + fStrokeAndFill == other.fStrokeAndFill; } private: diff --git a/src/gpu/GrPath.h b/src/gpu/GrPath.h index 27bbdc0439..ab8c51f2af 100644 --- a/src/gpu/GrPath.h +++ b/src/gpu/GrPath.h @@ -31,7 +31,7 @@ public: static uint64_t ComputeStrokeKey(const SkStrokeRec&); bool isEqualTo(const SkPath& path, const SkStrokeRec& stroke) { - return fSkPath == path && fStroke == stroke; + return fSkPath == path && fStroke.hasEqualEffect(stroke); } const SkRect& getBounds() const { return fBounds; } diff --git a/tests/StrokeTest.cpp b/tests/StrokeTest.cpp index b8abbd3a8a..43b293fc12 100644 --- a/tests/StrokeTest.cpp +++ b/tests/StrokeTest.cpp @@ -9,6 +9,7 @@ #include "SkPath.h" #include "SkRect.h" #include "SkStroke.h" +#include "SkStrokeRec.h" #include "Test.h" static bool equal(const SkRect& a, const SkRect& b) { @@ -84,7 +85,83 @@ static void test_strokerect(skiatest::Reporter* reporter) { } } +static void test_strokerec_equality(skiatest::Reporter* reporter) { + { + SkStrokeRec s1(SkStrokeRec::kFill_InitStyle); + SkStrokeRec s2(SkStrokeRec::kFill_InitStyle); + REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2)); + + // Test that style mismatch is detected. + s2.setHairlineStyle(); + REPORTER_ASSERT(reporter, !s1.hasEqualEffect(s2)); + + s1.setHairlineStyle(); + REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2)); + + // ResScale is not part of equality. + s1.setResScale(2.1f); + s2.setResScale(1.2f); + REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2)); + s1.setFillStyle(); + s2.setFillStyle(); + REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2)); + s1.setStrokeStyle(1.0f, false); + s2.setStrokeStyle(1.0f, false); + s1.setStrokeParams(SkPaint::kButt_Cap, SkPaint::kRound_Join, 2.9f); + s2.setStrokeParams(SkPaint::kButt_Cap, SkPaint::kRound_Join, 2.9f); + REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2)); + } + + // Stroke parameters on fill or hairline style are not part of equality. + { + SkStrokeRec s1(SkStrokeRec::kFill_InitStyle); + SkStrokeRec s2(SkStrokeRec::kFill_InitStyle); + for (int i = 0; i < 2; ++i) { + s1.setStrokeParams(SkPaint::kButt_Cap, SkPaint::kRound_Join, 2.9f); + s2.setStrokeParams(SkPaint::kButt_Cap, SkPaint::kRound_Join, 2.1f); + REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2)); + s2.setStrokeParams(SkPaint::kButt_Cap, SkPaint::kBevel_Join, 2.9f); + REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2)); + s2.setStrokeParams(SkPaint::kRound_Cap, SkPaint::kRound_Join, 2.9f); + REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2)); + s1.setHairlineStyle(); + s2.setHairlineStyle(); + } + } + + // Stroke parameters on stroke style are part of equality. + { + SkStrokeRec s1(SkStrokeRec::kFill_InitStyle); + SkStrokeRec s2(SkStrokeRec::kFill_InitStyle); + s1.setStrokeParams(SkPaint::kButt_Cap, SkPaint::kRound_Join, 2.9f); + s2.setStrokeParams(SkPaint::kButt_Cap, SkPaint::kRound_Join, 2.9f); + s1.setStrokeStyle(1.0f, false); + + s2.setStrokeStyle(1.0f, true); + REPORTER_ASSERT(reporter, !s1.hasEqualEffect(s2)); + + s2.setStrokeStyle(2.1f, false); + REPORTER_ASSERT(reporter, !s1.hasEqualEffect(s2)); + + s2.setStrokeStyle(1.0f, false); + REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2)); + + s2.setStrokeParams(SkPaint::kButt_Cap, SkPaint::kRound_Join, 2.1f); + REPORTER_ASSERT(reporter, !s1.hasEqualEffect(s2)); + s2.setStrokeParams(SkPaint::kButt_Cap, SkPaint::kBevel_Join, 2.9f); + REPORTER_ASSERT(reporter, !s1.hasEqualEffect(s2)); + s2.setStrokeParams(SkPaint::kRound_Cap, SkPaint::kRound_Join, 2.9f); + REPORTER_ASSERT(reporter, !s1.hasEqualEffect(s2)); + + // Sets fill. + s1.setStrokeStyle(0.0f, true); + s2.setStrokeStyle(0.0f, true); + REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2)); + } +} + DEF_TEST(Stroke, reporter) { test_strokecubic(reporter); test_strokerect(reporter); + test_strokerec_equality(reporter); } |