From 72f78c37010eb2bf20be4884d4f376d122830dfd Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Thu, 21 Dec 2017 11:56:42 -0500 Subject: Make GrShape recognize horizontal/vertical dashed lines with 0 off intervals as rrects. Change-Id: Ic29b41911e0185d36093d5352f4494709e8124ba Reviewed-on: https://skia-review.googlesource.com/88428 Commit-Queue: Brian Salomon Reviewed-by: Greg Daniel --- tests/GrShapeTest.cpp | 134 ++++++++++++++++++++++++++++---------------------- 1 file changed, 74 insertions(+), 60 deletions(-) (limited to 'tests/GrShapeTest.cpp') diff --git a/tests/GrShapeTest.cpp b/tests/GrShapeTest.cpp index 826d0f864b..2b80a84d63 100644 --- a/tests/GrShapeTest.cpp +++ b/tests/GrShapeTest.cpp @@ -1934,66 +1934,80 @@ DEF_TEST(GrShape_lines, r) { } DEF_TEST(GrShape_stroked_lines, r) { - // Paints to try - SkPaint buttCap; - buttCap.setStyle(SkPaint::kStroke_Style); - buttCap.setStrokeWidth(4); - buttCap.setStrokeCap(SkPaint::kButt_Cap); - - SkPaint squareCap = buttCap; - squareCap.setStrokeCap(SkPaint::kSquare_Cap); - - SkPaint roundCap = buttCap; - roundCap.setStrokeCap(SkPaint::kRound_Cap); - - // vertical - SkPath linePath; - linePath.moveTo(4, 4); - linePath.lineTo(4, 5); - - SkPaint fill; - - make_TestCase(r, linePath, buttCap)->compare( - r, TestCase(r, SkRect::MakeLTRB(2, 4, 6, 5), fill), - TestCase::kAllSame_ComparisonExpecation); - - make_TestCase(r, linePath, squareCap)->compare( - r, TestCase(r, SkRect::MakeLTRB(2, 2, 6, 7), fill), - TestCase::kAllSame_ComparisonExpecation); - - make_TestCase(r, linePath, roundCap)->compare(r, - TestCase(r, SkRRect::MakeRectXY(SkRect::MakeLTRB(2, 2, 6, 7), 2, 2), fill), - TestCase::kAllSame_ComparisonExpecation); - - // horizontal - linePath.reset(); - linePath.moveTo(4, 4); - linePath.lineTo(5, 4); - - make_TestCase(r, linePath, buttCap)->compare( - r, TestCase(r, SkRect::MakeLTRB(4, 2, 5, 6), fill), - TestCase::kAllSame_ComparisonExpecation); - make_TestCase(r, linePath, squareCap)->compare( - r, TestCase(r, SkRect::MakeLTRB(2, 2, 7, 6), fill), - TestCase::kAllSame_ComparisonExpecation); - make_TestCase(r, linePath, roundCap)->compare( - r, TestCase(r, SkRRect::MakeRectXY(SkRect::MakeLTRB(2, 2, 7, 6), 2, 2), fill), - TestCase::kAllSame_ComparisonExpecation); - - // point - linePath.reset(); - linePath.moveTo(4, 4); - linePath.lineTo(4, 4); - - make_TestCase(r, linePath, buttCap)->compare( - r, TestCase(r, SkRect::MakeEmpty(), fill), - TestCase::kAllSame_ComparisonExpecation); - make_TestCase(r, linePath, squareCap)->compare( - r, TestCase(r, SkRect::MakeLTRB(2, 2, 6, 6), fill), - TestCase::kAllSame_ComparisonExpecation); - make_TestCase(r, linePath, roundCap)->compare( - r, TestCase(r, SkRRect::MakeRectXY(SkRect::MakeLTRB(2, 2, 6, 6), 2, 2), fill), - TestCase::kAllSame_ComparisonExpecation); + static constexpr SkScalar kIntervals1[] = {1.f, 0.f}; + auto dash1 = SkDashPathEffect::Make(kIntervals1, SK_ARRAY_COUNT(kIntervals1), 0.f); + REPORTER_ASSERT(r, dash1); + static constexpr SkScalar kIntervals2[] = {10.f, 0.f, 5.f, 0.f}; + auto dash2 = SkDashPathEffect::Make(kIntervals2, SK_ARRAY_COUNT(kIntervals2), 10.f); + REPORTER_ASSERT(r, dash2); + + sk_sp pathEffects[] = {nullptr, std::move(dash1), std::move(dash2)}; + + for (const auto& pe : pathEffects) { + // Paints to try + SkPaint buttCap; + buttCap.setStyle(SkPaint::kStroke_Style); + buttCap.setStrokeWidth(4); + buttCap.setStrokeCap(SkPaint::kButt_Cap); + buttCap.setPathEffect(pe); + + SkPaint squareCap = buttCap; + squareCap.setStrokeCap(SkPaint::kSquare_Cap); + squareCap.setPathEffect(pe); + + SkPaint roundCap = buttCap; + roundCap.setStrokeCap(SkPaint::kRound_Cap); + roundCap.setPathEffect(pe); + + // vertical + SkPath linePath; + linePath.moveTo(4, 4); + linePath.lineTo(4, 5); + + SkPaint fill; + + make_TestCase(r, linePath, buttCap)->compare( + r, TestCase(r, SkRect::MakeLTRB(2, 4, 6, 5), fill), + TestCase::kAllSame_ComparisonExpecation); + + make_TestCase(r, linePath, squareCap)->compare( + r, TestCase(r, SkRect::MakeLTRB(2, 2, 6, 7), fill), + TestCase::kAllSame_ComparisonExpecation); + + make_TestCase(r, linePath, roundCap)->compare(r, + TestCase(r, SkRRect::MakeRectXY(SkRect::MakeLTRB(2, 2, 6, 7), 2, 2), fill), + TestCase::kAllSame_ComparisonExpecation); + + // horizontal + linePath.reset(); + linePath.moveTo(4, 4); + linePath.lineTo(5, 4); + + make_TestCase(r, linePath, buttCap)->compare( + r, TestCase(r, SkRect::MakeLTRB(4, 2, 5, 6), fill), + TestCase::kAllSame_ComparisonExpecation); + make_TestCase(r, linePath, squareCap)->compare( + r, TestCase(r, SkRect::MakeLTRB(2, 2, 7, 6), fill), + TestCase::kAllSame_ComparisonExpecation); + make_TestCase(r, linePath, roundCap)->compare( + r, TestCase(r, SkRRect::MakeRectXY(SkRect::MakeLTRB(2, 2, 7, 6), 2, 2), fill), + TestCase::kAllSame_ComparisonExpecation); + + // point + linePath.reset(); + linePath.moveTo(4, 4); + linePath.lineTo(4, 4); + + make_TestCase(r, linePath, buttCap)->compare( + r, TestCase(r, SkRect::MakeEmpty(), fill), + TestCase::kAllSame_ComparisonExpecation); + make_TestCase(r, linePath, squareCap)->compare( + r, TestCase(r, SkRect::MakeLTRB(2, 2, 6, 6), fill), + TestCase::kAllSame_ComparisonExpecation); + make_TestCase(r, linePath, roundCap)->compare( + r, TestCase(r, SkRRect::MakeRectXY(SkRect::MakeLTRB(2, 2, 6, 6), 2, 2), fill), + TestCase::kAllSame_ComparisonExpecation); + } } DEF_TEST(GrShape_short_path_keys, r) { -- cgit v1.2.3