diff options
author | Mike Reed <reed@google.com> | 2017-08-09 11:06:53 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-08-09 16:07:24 +0000 |
commit | 828f1d51958c17d716ac95182051a866be785e01 (patch) | |
tree | 325bab378605660b8905381aa5d6c907a2c1c215 /include/private/SkFloatingPoint.h | |
parent | 74c627f0bde675f13587b12069d6556868edf45e (diff) |
handle overflows in float->int
rects are already auto-vectorized, so no need to explicitly write a 4f version of SkRect::round()
Bug: skia:
Change-Id: I098945767bfcaa7093d770c376bd17ff3bdc9983
Reviewed-on: https://skia-review.googlesource.com/32060
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'include/private/SkFloatingPoint.h')
-rw-r--r-- | include/private/SkFloatingPoint.h | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/include/private/SkFloatingPoint.h b/include/private/SkFloatingPoint.h index c35c95194d..79a39a2840 100644 --- a/include/private/SkFloatingPoint.h +++ b/include/private/SkFloatingPoint.h @@ -78,9 +78,25 @@ static inline float sk_float_pow(float base, float exp) { #define sk_double_isnan(a) sk_float_isnan(a) -#define sk_float_floor2int(x) (int)sk_float_floor(x) -#define sk_float_round2int(x) (int)sk_float_floor((x) + 0.5f) -#define sk_float_ceil2int(x) (int)sk_float_ceil(x) +#define SK_MaxS32FitsInFloat 2147483520 +#define SK_MinS32FitsInFloat -SK_MaxS32FitsInFloat + +/** + * Return the closest int for the given float. Returns SK_MaxS32FitsInFloat for NaN. + */ +static inline int sk_float_saturate2int(float x) { + x = SkTMin<float>(x, SK_MaxS32FitsInFloat); + x = SkTMax<float>(x, SK_MinS32FitsInFloat); + return (int)x; +} + +#define sk_float_floor2int(x) sk_float_saturate2int(sk_float_floor(x)) +#define sk_float_round2int(x) sk_float_saturate2int(sk_float_floor((x) + 0.5f)) +#define sk_float_ceil2int(x) sk_float_saturate2int(sk_float_ceil(x)) + +#define sk_float_floor2int_no_saturate(x) (int)sk_float_floor(x) +#define sk_float_round2int_no_saturate(x) (int)sk_float_floor((x) + 0.5f) +#define sk_float_ceil2int_no_saturate(x) (int)sk_float_ceil(x) #define sk_double_floor(x) floor(x) #define sk_double_round(x) floor((x) + 0.5) |