diff options
Diffstat (limited to 'src/shaders/gradients')
-rw-r--r-- | src/shaders/gradients/SkTwoPointConicalGradient_gpu.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/shaders/gradients/SkTwoPointConicalGradient_gpu.cpp b/src/shaders/gradients/SkTwoPointConicalGradient_gpu.cpp index 38e4495c84..6956fa22aa 100644 --- a/src/shaders/gradients/SkTwoPointConicalGradient_gpu.cpp +++ b/src/shaders/gradients/SkTwoPointConicalGradient_gpu.cpp @@ -92,7 +92,9 @@ public: bool isNativelyFocal() const { return this->isFocal() && fData.fFocalData.isNativelyFocal(); } // Note that focalX = f = r0 / (r0 - r1), so 1 - focalX > 0 == r0 < r1 - bool isRadiusIncreasing() const { return this->isFocal() && 1 - fData.fFocalData.fFocalX > 0; } + bool isRadiusIncreasing() const { + return this->isFocal() ? 1 - fData.fFocalData.fFocalX > 0 : this->diffRadius() > 0; + } protected: void onGetGLSLProcessorKey(const GrShaderCaps& c, GrProcessorKeyBuilder* b) const override { @@ -237,7 +239,8 @@ protected: const char* p = coords2D.c_str(); if (effect.getType() == Type::kRadial) { - fragBuilder->codeAppendf("half %s = length(%s) - %s;", tName, p, p0.c_str()); + char sign = effect.diffRadius() < 0 ? '-' : '+'; + fragBuilder->codeAppendf("half %s = %clength(%s) - %s;", tName, sign, p, p0.c_str()); } else { // output will default to transparent black (we simply won't write anything // else to it if invalid, instead of discarding or returning prematurely) @@ -263,8 +266,9 @@ protected: void onSetData(const GrGLSLProgramDataManager& pdman, const GrFragmentProcessor& p) override { INHERITED::onSetData(pdman, p); const TwoPointConicalEffect& effect = p.cast<TwoPointConicalEffect>(); - // kRadialType should imply r1 - r0 = 1 (after our transformation) so r0 = r0 / (r1 - r0) - SkASSERT(effect.getType() == Type::kStrip || SkScalarNearlyZero(effect.diffRadius() - 1)); + // kRadialType should imply |r1 - r0| = 1 (after our transformation) + SkASSERT(effect.getType() == Type::kStrip || + SkScalarNearlyZero(SkTAbs(effect.diffRadius()) - 1)); pdman.set1f(fParamUni, effect.getType() == Type::kRadial ? effect.r0() : effect.r0() * effect.r0()); } @@ -407,12 +411,14 @@ std::unique_ptr<GrFragmentProcessor> Gr2PtConicalGradientEffect::Make( TwoPointConicalEffect::Data::Data(const SkTwoPointConicalGradient& shader, SkMatrix& matrix) { fType = shader.getType(); if (fType == Type::kRadial) { - SkScalar dr = shader.getDiffRadius(); - // Map center to (0, 0) and scale dr to 1 + // Map center to (0, 0) matrix.postTranslate(-shader.getStartCenter().fX, -shader.getStartCenter().fY); + + // scale |fDiffRadius| to 1 + SkScalar dr = shader.getDiffRadius(); matrix.postScale(1 / dr, 1 / dr); fRadius0 = shader.getStartRadius() / dr; - fDiffRadius = 1; + fDiffRadius = dr < 0 ? -1 : 1; } else if (fType == Type::kStrip) { fRadius0 = shader.getStartRadius() / shader.getCenterX1(); fDiffRadius = 0; |