aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkDrawShadowInfo.h
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2018-05-24 12:30:23 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-05-24 16:57:48 +0000
commit4ade54d81ba2cde9cc14c85a25ef710bdc236c39 (patch)
tree8a8d89ca5278c6f448e057d42dc1c38537c17524 /src/core/SkDrawShadowInfo.h
parentab0dee1c39f916b2483c2f9e097d053d1ae551f0 (diff)
allow div-by-zero in shadow utils
Bug: oss-fuzz:6665 Change-Id: I5cbe02bf574d849340c85c0964d92ece45daac1f Reviewed-on: https://skia-review.googlesource.com/129932 Commit-Queue: Mike Reed <reed@google.com> Commit-Queue: Jim Van Verth <jvanverth@google.com> Auto-Submit: Mike Reed <reed@google.com> Reviewed-by: Jim Van Verth <jvanverth@google.com>
Diffstat (limited to 'src/core/SkDrawShadowInfo.h')
-rw-r--r--src/core/SkDrawShadowInfo.h13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/core/SkDrawShadowInfo.h b/src/core/SkDrawShadowInfo.h
index da63a08104..d5820919ea 100644
--- a/src/core/SkDrawShadowInfo.h
+++ b/src/core/SkDrawShadowInfo.h
@@ -30,6 +30,13 @@ namespace SkDrawShadowMetrics {
static constexpr auto kAmbientHeightFactor = 1.0f / 128.0f;
static constexpr auto kAmbientGeomFactor = 64.0f;
+static inline float divide_and_pin(float numer, float denom, float min, float max) {
+ float result = SkTPin(sk_ieee_float_divide(numer, denom), min, max);
+ // ensure that SkTPin handled non-finites correctly
+ SkASSERT(result >= min && result <= max);
+ return result;
+}
+
inline SkScalar AmbientBlurRadius(SkScalar height) {
return height*kAmbientHeightFactor*kAmbientGeomFactor;
}
@@ -39,15 +46,15 @@ inline SkScalar AmbientRecipAlpha(SkScalar height) {
}
inline SkScalar SpotBlurRadius(SkScalar occluderZ, SkScalar lightZ, SkScalar lightRadius) {
- return lightRadius*SkTPin(occluderZ / (lightZ - occluderZ), 0.0f, 0.95f);
+ return lightRadius*divide_and_pin(occluderZ, lightZ - occluderZ, 0.0f, 0.95f);
}
inline void GetSpotParams(SkScalar occluderZ, SkScalar lightX, SkScalar lightY, SkScalar lightZ,
SkScalar lightRadius,
SkScalar* blurRadius, SkScalar* scale, SkVector* translate) {
- SkScalar zRatio = SkTPin(occluderZ / (lightZ - occluderZ), 0.0f, 0.95f);
+ SkScalar zRatio = divide_and_pin(occluderZ, lightZ - occluderZ, 0.0f, 0.95f);
*blurRadius = lightRadius*zRatio;
- *scale = SkTPin(lightZ / (lightZ - occluderZ), 1.0f, 1.95f);
+ *scale = divide_and_pin(lightZ, lightZ - occluderZ, 1.0f, 1.95f);
*translate = SkVector::Make(-zRatio * lightX, -zRatio * lightY);
}