ShadowUtils: Fix umbra inset calculation when determining if umbra is fully occluded.
authorBrian Salomon <bsalomon@google.com>
Mon, 6 Feb 2017 19:23:53 +0000 (14:23 -0500)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Tue, 7 Feb 2017 14:38:16 +0000 (14:38 +0000)
Change-Id: Id0db49ad45b341d39abf7ee532ecc0799a832192
Reviewed-on: https://skia-review.googlesource.com/8079
Commit-Queue: Stan Iliev <stani@google.com>
Reviewed-by: Jim Van Verth <jvanverth@google.com>
src/utils/SkShadowUtils.cpp

index ba4decc..c4b4e3d 100755 (executable)
@@ -499,6 +499,10 @@ void SkShadowUtils::DrawShadow(SkCanvas* canvas, const SkPath& path, SkScalar oc
                     SkScalar hh = h / 2.f;
                     SkScalar umbraInsetX = s * hw + factory.fRadius;
                     SkScalar umbraInsetY = s * hh + factory.fRadius;
+                    // The umbra is inset by radius along the diagonal, so adjust for that.
+                    SkScalar d = 1.f / SkScalarSqrt(hw * hw + hh * hh);
+                    umbraInsetX *= hw * d;
+                    umbraInsetY *= hh * d;
                     if (umbraInsetX > hw || umbraInsetY > hh) {
                         // There is no umbra to occlude.
                         factory.fOccluderType = SpotVerticesFactory::OccluderType::kTransparent;