diff options
-rw-r--r-- | src/effects/gradients/SkTwoPointConicalGradient.cpp | 7 | ||||
-rw-r--r-- | src/effects/gradients/SkTwoPointConicalGradient.h | 1 | ||||
-rw-r--r-- | tests/GradientTest.cpp | 30 |
3 files changed, 34 insertions, 4 deletions
diff --git a/src/effects/gradients/SkTwoPointConicalGradient.cpp b/src/effects/gradients/SkTwoPointConicalGradient.cpp index 37b49f0d47..7cb094391a 100644 --- a/src/effects/gradients/SkTwoPointConicalGradient.cpp +++ b/src/effects/gradients/SkTwoPointConicalGradient.cpp @@ -74,6 +74,8 @@ void TwoPtRadial::init(const SkPoint& center0, SkScalar rad0, fA = sqr(fDCenterX) + sqr(fDCenterY) - sqr(fDRadius); fRadius2 = sqr(fRadius); fRDR = fRadius * fDRadius; + + fConeFillsPlane = rad0 != rad1 && SkMaxScalar(rad0, rad1) > SkPoint::Distance(center0, center1); } void TwoPtRadial::setup(SkScalar fx, SkScalar fy, SkScalar dfx, SkScalar dfy) { @@ -189,10 +191,7 @@ SkTwoPointConicalGradient::SkTwoPointConicalGradient( } bool SkTwoPointConicalGradient::isOpaque() const { - // Because areas outside the cone are left untouched, we cannot treat the - // shader as opaque even if the gradient itself is opaque. - // TODO(junov): Compute whether the cone fills the plane crbug.com/222380 - return false; + return INHERITED::isOpaque() && this->fRec.fConeFillsPlane; } void SkTwoPointConicalGradient::shadeSpan(int x, int y, SkPMColor* dstCParam, diff --git a/src/effects/gradients/SkTwoPointConicalGradient.h b/src/effects/gradients/SkTwoPointConicalGradient.h index 1358f0b2ac..a78837077b 100644 --- a/src/effects/gradients/SkTwoPointConicalGradient.h +++ b/src/effects/gradients/SkTwoPointConicalGradient.h @@ -23,6 +23,7 @@ struct TwoPtRadial { float fA; float fRadius2; float fRDR; + bool fConeFillsPlane; void init(const SkPoint& center0, SkScalar rad0, const SkPoint& center1, SkScalar rad1); diff --git a/tests/GradientTest.cpp b/tests/GradientTest.cpp index cf8fbee206..b67cc05380 100644 --- a/tests/GradientTest.cpp +++ b/tests/GradientTest.cpp @@ -126,6 +126,34 @@ static void conical_gradproc(skiatest::Reporter* reporter, const GradRec& rec) { rec.gradCheck(reporter, s, &info, SkShader::kConical_GradientType); REPORTER_ASSERT(reporter, !memcmp(info.fPoint, rec.fPoint, 2 * sizeof(SkPoint))); REPORTER_ASSERT(reporter, !memcmp(info.fRadius, rec.fRadius, 2 * sizeof(SkScalar))); + REPORTER_ASSERT(reporter, !s->isOpaque()); +} + +// 2-point radial gradient should behave as opaque when it extends to the entire plane +static void conical_gradproc_opaque(skiatest::Reporter* reporter, const GradRec& rec) { + SkAutoTUnref<SkShader> s(SkGradientShader::CreateTwoPointConical(rec.fPoint[0], + rec.fRadius[0], + rec.fPoint[0], + rec.fRadius[1], + rec.fColors, + rec.fPos, + rec.fColorCount, + rec.fTileMode)); + REPORTER_ASSERT(reporter, s->isOpaque()); +} + +// 2nd circle center lies on edge of first circle should not be considered opaque +static void conical_gradproc_not_opaque(skiatest::Reporter* reporter, const GradRec& rec) { + SkScalar dist = SkPoint::Distance(rec.fPoint[0], rec.fPoint[1]); + SkAutoTUnref<SkShader> s(SkGradientShader::CreateTwoPointConical(rec.fPoint[0], + dist, + rec.fPoint[1], + rec.fRadius[1], + rec.fColors, + rec.fPos, + rec.fColorCount, + rec.fTileMode)); + REPORTER_ASSERT(reporter, !s->isOpaque()); } // Ensure that repeated color gradients behave like drawing a single color @@ -185,6 +213,8 @@ static void TestGradientShaders(skiatest::Reporter* reporter) { radial2_gradproc, sweep_gradproc, conical_gradproc, + conical_gradproc_opaque, + conical_gradproc_not_opaque, }; for (size_t i = 0; i < SK_ARRAY_COUNT(gProcs); ++i) { |