[canvaskit] Correctly translate between shadow radius and sigma
Bug: skia:
Change-Id: I7e069407334f8b0238fd6d9f529cdf30e3e269be
Reviewed-on: https://skia-review.googlesource.com/c/176960
Reviewed-by: Florin Malita <fmalita@chromium.org>
diff --git a/experimental/canvaskit/htmlcanvas/canvas2dcontext.js b/experimental/canvaskit/htmlcanvas/canvas2dcontext.js
index 72a44fa..dc2856d 100644
--- a/experimental/canvaskit/htmlcanvas/canvas2dcontext.js
+++ b/experimental/canvaskit/htmlcanvas/canvas2dcontext.js
@@ -1064,7 +1064,7 @@
var shadowPaint = basePaint.copy();
shadowPaint.setColor(alphaColor);
var blurEffect = CanvasKit.MakeBlurMaskFilter(CanvasKit.BlurStyle.Normal,
- Math.max(1, this._shadowBlur/2), // very little blur when < 1
+ SkBlurRadiusToSigma(this._shadowBlur),
false);
shadowPaint.setMaskFilter(blurEffect);
@@ -1180,3 +1180,17 @@
writable: false
});
}
+
+function SkBlurRadiusToSigma(radius) {
+ // Blink (Chrome) does the following, for legacy reasons, even though it
+ // is against the spec. https://bugs.chromium.org/p/chromium/issues/detail?id=179006
+ // This may change in future releases.
+ // This code is staying here in case any clients are interested in using it
+ // to match Blink "exactly".
+ // if (radius <= 0)
+ // return 0;
+ // return 0.288675 * radius + 0.5;
+ //
+ // This is what the spec says, which is how Firefox and others operate.
+ return radius/2;
+}
\ No newline at end of file