From 5edf82e651630308f99b65506eaff0bb17c88e79 Mon Sep 17 00:00:00 2001 From: fmalita Date: Thu, 3 Mar 2016 06:41:54 -0800 Subject: [PATCH] [Reland] Fix SkTwoPointConicalGradient zero-radius handling r == 0 is within valid gradient range, we shouldn't skip it. BUG=skia:5023 R=caryclark@google.com,reed@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1756573002 Committed: https://skia.googlesource.com/skia/+/9c0b02a557e9be663a0eb07519e1b6a61a6c3df2 Review URL: https://codereview.chromium.org/1756573002 --- src/effects/gradients/SkGradientShader.cpp | 6 +++-- .../gradients/SkTwoPointConicalGradient.cpp | 4 ++-- tests/GradientTest.cpp | 24 +++++++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp index 5444c1caad..985d45966b 100644 --- a/src/effects/gradients/SkGradientShader.cpp +++ b/src/effects/gradients/SkGradientShader.cpp @@ -840,8 +840,10 @@ SkShader* SkGradientShader::CreateTwoPointConical(const SkPoint& start, if (!valid_grad(colors, pos, colorCount, mode)) { return nullptr; } - if (start == end && startRadius == endRadius) { - return SkShader::CreateEmptyShader(); + if (startRadius == endRadius) { + if (start == end || startRadius == 0) { + return SkShader::CreateEmptyShader(); + } } EXPAND_1_COLOR(colorCount); diff --git a/src/effects/gradients/SkTwoPointConicalGradient.cpp b/src/effects/gradients/SkTwoPointConicalGradient.cpp index b938ebdec7..2209306fe3 100644 --- a/src/effects/gradients/SkTwoPointConicalGradient.cpp +++ b/src/effects/gradients/SkTwoPointConicalGradient.cpp @@ -122,10 +122,10 @@ SkFixed TwoPtRadialContext::nextT() { // find_quad_roots returns the values sorted, so we start with the last float t = roots[countRoots - 1]; float r = lerp(fRec.fRadius, fRec.fDRadius, t); - if (r <= 0) { + if (r < 0) { t = roots[0]; // might be the same as roots[countRoots-1] r = lerp(fRec.fRadius, fRec.fDRadius, t); - if (r <= 0) { + if (r < 0) { return TwoPtRadial::kDontDrawT; } } diff --git a/tests/GradientTest.cpp b/tests/GradientTest.cpp index 6a277d520e..cc94cbaf75 100644 --- a/tests/GradientTest.cpp +++ b/tests/GradientTest.cpp @@ -6,6 +6,7 @@ */ #include "SkCanvas.h" +#include "SkColorPriv.h" #include "SkColorShader.h" #include "SkGradientShader.h" #include "SkShader.h" @@ -233,10 +234,33 @@ static void test_linear_fuzz(skiatest::Reporter* reporter) { surface->getCanvas()->drawRect(r, paint); } +// https://bugs.chromium.org/p/skia/issues/detail?id=5023 +// We should still shade pixels for which the radius is exactly 0. +static void test_two_point_conical_zero_radius(skiatest::Reporter* reporter) { + SkAutoTUnref surface(SkSurface::NewRasterN32Premul(5, 5)); + surface->getCanvas()->clear(SK_ColorRED); + + const SkColor colors[] = { SK_ColorGREEN, SK_ColorBLUE }; + SkAutoTUnref shader(SkGradientShader::CreateTwoPointConical( + SkPoint::Make(2.5f, 2.5f), 0, + SkPoint::Make(3.0f, 3.0f), 10, + colors, nullptr, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode)); + SkPaint p; + p.setShader(shader); + surface->getCanvas()->drawPaint(p); + + // r == 0 for the center pixel. + // verify that we draw it (no red bleed) + SkPMColor centerPMColor; + surface->readPixels(SkImageInfo::MakeN32Premul(1, 1), ¢erPMColor, sizeof(SkPMColor), 2, 2); + REPORTER_ASSERT(reporter, SkGetPackedR32(centerPMColor) == 0); +} + DEF_TEST(Gradient, reporter) { TestGradientShaders(reporter); TestConstantGradient(reporter); test_big_grad(reporter); test_nearly_vertical(reporter); test_linear_fuzz(reporter); + test_two_point_conical_zero_radius(reporter); } -- 2.34.1