aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/shaders/gradients
diff options
context:
space:
mode:
authorGravatar Yuqian Li <liyuqian@google.com>2018-03-19 14:23:48 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-03-19 18:50:46 +0000
commit650dd901e1b9d4e2016eea234cb392830b10c416 (patch)
treedd0e59fd7340de5bc77e5b84d32ce7edf1e4cba0 /src/shaders/gradients
parentcb88470d82d646972a7e83d04bb19444d87dd840 (diff)
Fix concentric 2pt conical gradient in GPU where r1 < r0
Bug: skia:7683 Change-Id: I6608e72fa695c855af6a6a447885c4889b09fc1d Reviewed-on: https://skia-review.googlesource.com/115042 Commit-Queue: Yuqian Li <liyuqian@google.com> Reviewed-by: Greg Daniel <egdaniel@google.com>
Diffstat (limited to 'src/shaders/gradients')
-rw-r--r--src/shaders/gradients/SkTwoPointConicalGradient_gpu.cpp20
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;