diff options
author | Jim Van Verth <jvanverth@google.com> | 2018-04-23 18:08:45 +0000 |
---|---|---|
committer | Jim Van Verth <jvanverth@google.com> | 2018-04-23 18:40:47 +0000 |
commit | 39e716562e9d44696ce86d0f680f74d1a4592c2f (patch) | |
tree | 620e4cd25df6e03d855e71f0debd6b0f67efeaa8 /src | |
parent | 4229b35c3e4f205da793b1c5648f5436a6f037e1 (diff) |
Revert "Remove ambient clamp hack for analytic shadows."
This reverts commit d75b34394b5c53b0a5e8144dd28f956fbc8b90b2.
Reason for revert: Breaking GMs
Original change's description:
> Remove ambient clamp hack for analytic shadows.
>
> The hack was added to make analytic ambient shadows match the geometric
> ones exactly. Removing it does produce a slight difference, but it's
> only visible at full black values (and then, only slightly) and this
> makes room to pass a blend parameter for falloff.
>
> Also fixes an issue with filling out arcs in the shadow tesselator.
>
> Bug: skia:7486
> Change-Id: If78d0104df7e18f4320c1658af75576f6a4a8c73
> Reviewed-on: https://skia-review.googlesource.com/122580
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Commit-Queue: Jim Van Verth <jvanverth@google.com>
TBR=jvanverth@google.com,bsalomon@google.com
# Not skipping CQ checks because original CL landed > 1 day ago.
Bug: skia:7486
Change-Id: If0a20a358759c08a3a475d60be54a3d62ff7b6ad
Reviewed-on: https://skia-review.googlesource.com/123120
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/GrRenderTargetContext.cpp | 7 | ||||
-rw-r--r-- | src/gpu/effects/GrShadowGeoProc.cpp | 2 | ||||
-rw-r--r-- | src/gpu/ops/GrShadowRRectOp.cpp | 75 | ||||
-rw-r--r-- | src/gpu/ops/GrShadowRRectOp.h | 2 | ||||
-rwxr-xr-x | src/utils/SkShadowTessellator.cpp | 2 |
5 files changed, 50 insertions, 38 deletions
diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp index aae0248ae4..e26ec9018b 100644 --- a/src/gpu/GrRenderTargetContext.cpp +++ b/src/gpu/GrRenderTargetContext.cpp @@ -1024,10 +1024,15 @@ bool GrRenderTargetContext::drawFastShadow(const GrClip& clip, // set a large inset to force a fill devSpaceInsetWidth = ambientRRect.width(); } + // the fraction of the blur we want to apply is devSpaceInsetWidth/devSpaceAmbientBlur, + // which is just 1/umbraRecipAlpha. + SkScalar blurClamp = SkScalarInvert(umbraRecipAlpha); + std::unique_ptr<GrDrawOp> op = GrShadowRRectOp::Make(ambientColor, viewMatrix, ambientRRect, devSpaceAmbientBlur, - devSpaceInsetWidth); + devSpaceInsetWidth, + blurClamp); SkASSERT(op); this->addDrawOp(clip, std::move(op)); } diff --git a/src/gpu/effects/GrShadowGeoProc.cpp b/src/gpu/effects/GrShadowGeoProc.cpp index 9f84aa2ae7..7eddaa41d8 100644 --- a/src/gpu/effects/GrShadowGeoProc.cpp +++ b/src/gpu/effects/GrShadowGeoProc.cpp @@ -45,7 +45,7 @@ public: fragBuilder->codeAppend("half d = length(shadowParams.xy);"); fragBuilder->codeAppend("half distance = shadowParams.z * (1.0 - d);"); - fragBuilder->codeAppend("half factor = 1.0 - clamp(distance, 0.0, 1.0);"); + fragBuilder->codeAppend("half factor = 1.0 - clamp(distance, 0.0, shadowParams.w);"); fragBuilder->codeAppend("factor = exp(-factor * factor * 4.0) - 0.018;"); fragBuilder->codeAppendf("%s = half4(factor);", args.fOutputCoverage); diff --git a/src/gpu/ops/GrShadowRRectOp.cpp b/src/gpu/ops/GrShadowRRectOp.cpp index bee4e2d235..ba96941073 100644 --- a/src/gpu/ops/GrShadowRRectOp.cpp +++ b/src/gpu/ops/GrShadowRRectOp.cpp @@ -188,7 +188,8 @@ public: // An insetWidth > 1/2 rect width or height indicates a simple fill. ShadowCircularRRectOp(GrColor color, const SkRect& devRect, - float devRadius, bool isCircle, float blurRadius, float insetWidth) + float devRadius, bool isCircle, float blurRadius, float insetWidth, + float blurClamp) : INHERITED(ClassID()) { SkRect bounds = devRect; SkASSERT(insetWidth > 0); @@ -224,7 +225,7 @@ public: this->setBounds(bounds, HasAABloat::kNo, IsZeroArea::kNo); fGeoData.emplace_back(Geometry{color, outerRadius, umbraInset, innerRadius, - blurRadius, bounds, type, isCircle}); + blurRadius, blurClamp, bounds, type, isCircle}); if (isCircle) { fVertCount = circle_type_to_vert_count(kStroke_RRectType == type); fIndexCount = circle_type_to_index_count(kStroke_RRectType == type); @@ -265,6 +266,7 @@ private: SkScalar fUmbraInset; SkScalar fInnerRadius; SkScalar fBlurRadius; + SkScalar fClampValue; SkRect fDevBounds; RRectType fType; bool fIsCircle; @@ -275,7 +277,7 @@ private: GrColor fColor; SkPoint fOffset; SkScalar fDistanceCorrection; - SkScalar fPad; // to be used later + SkScalar fClampValue; }; void fillInCircleVerts(const Geometry& args, bool isStroked, CircleVertex** verts) const { @@ -285,6 +287,7 @@ private: SkScalar innerRadius = args.fInnerRadius; SkScalar blurRadius = args.fBlurRadius; SkScalar distanceCorrection = outerRadius / blurRadius; + SkScalar clampValue = args.fClampValue; const SkRect& bounds = args.fDevBounds; @@ -299,56 +302,56 @@ private: (*verts)->fColor = color; (*verts)->fOffset = SkPoint::Make(-octOffset, -1); (*verts)->fDistanceCorrection = distanceCorrection; - (*verts)->fPad = 0; + (*verts)->fClampValue = clampValue; (*verts)++; (*verts)->fPos = center + SkPoint::Make(octOffset * halfWidth, -halfWidth); (*verts)->fColor = color; (*verts)->fOffset = SkPoint::Make(octOffset, -1); (*verts)->fDistanceCorrection = distanceCorrection; - (*verts)->fPad = 0; + (*verts)->fClampValue = clampValue; (*verts)++; (*verts)->fPos = center + SkPoint::Make(halfWidth, -octOffset * halfWidth); (*verts)->fColor = color; (*verts)->fOffset = SkPoint::Make(1, -octOffset); (*verts)->fDistanceCorrection = distanceCorrection; - (*verts)->fPad = 0; + (*verts)->fClampValue = clampValue; (*verts)++; (*verts)->fPos = center + SkPoint::Make(halfWidth, octOffset * halfWidth); (*verts)->fColor = color; (*verts)->fOffset = SkPoint::Make(1, octOffset); (*verts)->fDistanceCorrection = distanceCorrection; - (*verts)->fPad = 0; + (*verts)->fClampValue = clampValue; (*verts)++; (*verts)->fPos = center + SkPoint::Make(octOffset * halfWidth, halfWidth); (*verts)->fColor = color; (*verts)->fOffset = SkPoint::Make(octOffset, 1); (*verts)->fDistanceCorrection = distanceCorrection; - (*verts)->fPad = 0; + (*verts)->fClampValue = clampValue; (*verts)++; (*verts)->fPos = center + SkPoint::Make(-octOffset * halfWidth, halfWidth); (*verts)->fColor = color; (*verts)->fOffset = SkPoint::Make(-octOffset, 1); (*verts)->fDistanceCorrection = distanceCorrection; - (*verts)->fPad = 0; + (*verts)->fClampValue = clampValue; (*verts)++; (*verts)->fPos = center + SkPoint::Make(-halfWidth, octOffset * halfWidth); (*verts)->fColor = color; (*verts)->fOffset = SkPoint::Make(-1, octOffset); (*verts)->fDistanceCorrection = distanceCorrection; - (*verts)->fPad = 0; + (*verts)->fClampValue = clampValue; (*verts)++; (*verts)->fPos = center + SkPoint::Make(-halfWidth, -octOffset * halfWidth); (*verts)->fColor = color; (*verts)->fOffset = SkPoint::Make(-1, -octOffset); (*verts)->fDistanceCorrection = distanceCorrection; - (*verts)->fPad = 0; + (*verts)->fClampValue = clampValue; (*verts)++; if (isStroked) { @@ -363,56 +366,56 @@ private: (*verts)->fColor = color; (*verts)->fOffset = SkPoint::Make(-s * innerRadius, -c * innerRadius); (*verts)->fDistanceCorrection = distanceCorrection; - (*verts)->fPad = 0; + (*verts)->fClampValue = clampValue; (*verts)++; (*verts)->fPos = center + SkPoint::Make(s * r, -c * r); (*verts)->fColor = color; (*verts)->fOffset = SkPoint::Make(s * innerRadius, -c * innerRadius); (*verts)->fDistanceCorrection = distanceCorrection; - (*verts)->fPad = 0; + (*verts)->fClampValue = clampValue; (*verts)++; (*verts)->fPos = center + SkPoint::Make(c * r, -s * r); (*verts)->fColor = color; (*verts)->fOffset = SkPoint::Make(c * innerRadius, -s * innerRadius); (*verts)->fDistanceCorrection = distanceCorrection; - (*verts)->fPad = 0; + (*verts)->fClampValue = clampValue; (*verts)++; (*verts)->fPos = center + SkPoint::Make(c * r, s * r); (*verts)->fColor = color; (*verts)->fOffset = SkPoint::Make(c * innerRadius, s * innerRadius); (*verts)->fDistanceCorrection = distanceCorrection; - (*verts)->fPad = 0; + (*verts)->fClampValue = clampValue; (*verts)++; (*verts)->fPos = center + SkPoint::Make(s * r, c * r); (*verts)->fColor = color; (*verts)->fOffset = SkPoint::Make(s * innerRadius, c * innerRadius); (*verts)->fDistanceCorrection = distanceCorrection; - (*verts)->fPad = 0; + (*verts)->fClampValue = clampValue; (*verts)++; (*verts)->fPos = center + SkPoint::Make(-s * r, c * r); (*verts)->fColor = color; (*verts)->fOffset = SkPoint::Make(-s * innerRadius, c * innerRadius); (*verts)->fDistanceCorrection = distanceCorrection; - (*verts)->fPad = 0; + (*verts)->fClampValue = clampValue; (*verts)++; (*verts)->fPos = center + SkPoint::Make(-c * r, s * r); (*verts)->fColor = color; (*verts)->fOffset = SkPoint::Make(-c * innerRadius, s * innerRadius); (*verts)->fDistanceCorrection = distanceCorrection; - (*verts)->fPad = 0; + (*verts)->fClampValue = clampValue; (*verts)++; (*verts)->fPos = center + SkPoint::Make(-c * r, -s * r); (*verts)->fColor = color; (*verts)->fOffset = SkPoint::Make(-c * innerRadius, -s * innerRadius); (*verts)->fDistanceCorrection = distanceCorrection; - (*verts)->fPad = 0; + (*verts)->fClampValue = clampValue; (*verts)++; } else { // filled @@ -420,7 +423,7 @@ private: (*verts)->fColor = color; (*verts)->fOffset = SkPoint::Make(0, 0); (*verts)->fDistanceCorrection = distanceCorrection; - (*verts)->fPad = 0; + (*verts)->fClampValue = clampValue; (*verts)++; } } @@ -463,6 +466,7 @@ private: outerVec.fX + outerVec.fY); diagVec *= umbraInset / (2 * umbraInset - outerRadius); SkScalar distanceCorrection = umbraInset / blurRadius; + SkScalar clampValue = args.fClampValue; // build corner by corner for (int i = 0; i < 4; ++i) { @@ -471,7 +475,7 @@ private: (*verts)->fColor = color; (*verts)->fOffset = SkVector::Make(0, 0); (*verts)->fDistanceCorrection = distanceCorrection; - (*verts)->fPad = 0; + (*verts)->fClampValue = clampValue; (*verts)++; // outer points @@ -479,35 +483,35 @@ private: (*verts)->fColor = color; (*verts)->fOffset = SkVector::Make(0, -1); (*verts)->fDistanceCorrection = distanceCorrection; - (*verts)->fPad = 0; + (*verts)->fClampValue = clampValue; (*verts)++; (*verts)->fPos = SkPoint::Make(xOuter[i], yMid[i]); (*verts)->fColor = color; (*verts)->fOffset = outerVec; (*verts)->fDistanceCorrection = distanceCorrection; - (*verts)->fPad = 0; + (*verts)->fClampValue = clampValue; (*verts)++; (*verts)->fPos = SkPoint::Make(xOuter[i], yOuter[i]); (*verts)->fColor = color; (*verts)->fOffset = diagVec; (*verts)->fDistanceCorrection = distanceCorrection; - (*verts)->fPad = 0; + (*verts)->fClampValue = clampValue; (*verts)++; (*verts)->fPos = SkPoint::Make(xMid[i], yOuter[i]); (*verts)->fColor = color; (*verts)->fOffset = outerVec; (*verts)->fDistanceCorrection = distanceCorrection; - (*verts)->fPad = 0; + (*verts)->fClampValue = clampValue; (*verts)++; (*verts)->fPos = SkPoint::Make(xInner[i], yOuter[i]); (*verts)->fColor = color; (*verts)->fOffset = SkVector::Make(0, -1); (*verts)->fDistanceCorrection = distanceCorrection; - (*verts)->fPad = 0; + (*verts)->fClampValue = clampValue; (*verts)++; } @@ -525,7 +529,7 @@ private: (*verts)->fColor = color; (*verts)->fOffset = SkPoint::Make(0, 0); (*verts)->fDistanceCorrection = distanceCorrection; - (*verts)->fPad = 0; + (*verts)->fClampValue = clampValue; (*verts)++; // TR @@ -533,7 +537,7 @@ private: (*verts)->fColor = color; (*verts)->fOffset = SkPoint::Make(0, 0); (*verts)->fDistanceCorrection = distanceCorrection; - (*verts)->fPad = 0; + (*verts)->fClampValue = clampValue; (*verts)++; // BL @@ -541,7 +545,7 @@ private: (*verts)->fColor = color; (*verts)->fOffset = SkPoint::Make(0, 0); (*verts)->fDistanceCorrection = distanceCorrection; - (*verts)->fPad = 0; + (*verts)->fClampValue = clampValue; (*verts)++; // BR @@ -549,7 +553,7 @@ private: (*verts)->fColor = color; (*verts)->fOffset = SkPoint::Make(0, 0); (*verts)->fDistanceCorrection = distanceCorrection; - (*verts)->fPad = 0; + (*verts)->fClampValue = clampValue; (*verts)++; } @@ -644,7 +648,8 @@ std::unique_ptr<GrDrawOp> Make(GrColor color, const SkMatrix& viewMatrix, const SkRRect& rrect, SkScalar blurWidth, - SkScalar insetWidth) { + SkScalar insetWidth, + SkScalar blurClamp) { // Shadow rrect ops only handle simple circular rrects. SkASSERT(viewMatrix.isSimilarity() && SkRRectPriv::EqualRadii(rrect)); @@ -663,7 +668,8 @@ std::unique_ptr<GrDrawOp> Make(GrColor color, scaledRadius, rrect.isOval(), blurWidth, - scaledInsetWidth)); + scaledInsetWidth, + blurClamp)); } } @@ -683,20 +689,21 @@ GR_DRAW_OP_TEST_DEFINE(ShadowRRectOp) { viewMatrix.postScale(scale, scale); SkScalar insetWidth = random->nextSScalar1() * 72.f; SkScalar blurWidth = random->nextSScalar1() * 72.f; + SkScalar blurClamp = random->nextSScalar1(); bool isCircle = random->nextBool(); // This op doesn't use a full GrPaint, just a color. GrColor color = paint.getColor(); if (isCircle) { SkRect circle = GrTest::TestSquare(random); SkRRect rrect = SkRRect::MakeOval(circle); - return GrShadowRRectOp::Make(color, viewMatrix, rrect, blurWidth, insetWidth); + return GrShadowRRectOp::Make(color, viewMatrix, rrect, blurWidth, insetWidth, blurClamp); } else { SkRRect rrect; do { // This may return a rrect with elliptical corners, which we don't support. rrect = GrTest::TestRRectSimple(random); } while (!SkRRectPriv::IsSimpleCircular(rrect)); - return GrShadowRRectOp::Make(color, viewMatrix, rrect, blurWidth, insetWidth); + return GrShadowRRectOp::Make(color, viewMatrix, rrect, blurWidth, insetWidth, blurClamp); } } diff --git a/src/gpu/ops/GrShadowRRectOp.h b/src/gpu/ops/GrShadowRRectOp.h index 5ff084e3c8..3d8e92af00 100644 --- a/src/gpu/ops/GrShadowRRectOp.h +++ b/src/gpu/ops/GrShadowRRectOp.h @@ -19,7 +19,7 @@ class SkStrokeRec; namespace GrShadowRRectOp { std::unique_ptr<GrDrawOp> Make(GrColor, const SkMatrix& viewMatrix, const SkRRect& rrect, - SkScalar blurWidth, SkScalar insetWidth); + SkScalar blurWidth, SkScalar insetWidth, SkScalar blurClamp = 1); } #endif diff --git a/src/utils/SkShadowTessellator.cpp b/src/utils/SkShadowTessellator.cpp index 0bf1adaaa4..98c47a6f2d 100755 --- a/src/utils/SkShadowTessellator.cpp +++ b/src/utils/SkShadowTessellator.cpp @@ -121,7 +121,7 @@ static void compute_radial_steps(const SkVector& v1, const SkVector& v2, SkScala SkScalar rSin = v1.cross(v2); SkScalar theta = SkScalarATan2(rSin, rCos); - int steps = SkScalarRoundToInt(SkScalarAbs(r*theta*kRecipPixelsPerArcSegment)); + int steps = SkScalarFloorToInt(r*theta*kRecipPixelsPerArcSegment); SkScalar dTheta = theta / steps; *rotSin = SkScalarSinCos(dTheta, rotCos); |