aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bench/MathBench.cpp26
-rw-r--r--gm/gamut.cpp2
-rw-r--r--include/private/SkFloatBits.h38
-rw-r--r--include/private/SkFloatingPoint.h8
-rw-r--r--include/utils/SkRandom.h1
-rw-r--r--src/ports/SkScalerContext_win_dw.cpp8
-rw-r--r--src/shaders/gradients/SkLinearGradient.cpp4
7 files changed, 10 insertions, 77 deletions
diff --git a/bench/MathBench.cpp b/bench/MathBench.cpp
index 541a1052dc..7768253544 100644
--- a/bench/MathBench.cpp
+++ b/bench/MathBench.cpp
@@ -598,29 +598,3 @@ DEF_BENCH( return new CLZBench(true); )
DEF_BENCH( return new NormalizeBench(); )
DEF_BENCH( return new FixedMathBench(); )
-
-
-struct FloatToIntBench : public Benchmark {
- enum { N = 1000000 };
- float fFloats[N];
- int fInts [N];
-
- const char* onGetName() override { return "float_to_int"; }
- bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
-
- void onDelayedSetup() override {
- const auto f32 = 4294967296.0f;
- for (int i = 0; i < N; ++i) {
- fFloats[i] = -f32 + i*(2*f32/N);
- }
- }
-
- void onDraw(int loops, SkCanvas*) override {
- while (loops --> 0) {
- for (int i = 0; i < N; i++) {
- fInts[i] = SkFloatToIntFloor(fFloats[i]);
- }
- }
- }
-};
-DEF_BENCH( return new FloatToIntBench; )
diff --git a/gm/gamut.cpp b/gm/gamut.cpp
index 9339aa8274..abb7735138 100644
--- a/gm/gamut.cpp
+++ b/gm/gamut.cpp
@@ -41,7 +41,7 @@ protected:
struct BitmapCellRenderer : public CellRenderer {
BitmapCellRenderer(SkColor color, SkFilterQuality quality, float scale = 1.0f)
: fQuality(quality) {
- int scaledSize = SkFloatToIntRound(scale * gRectSize);
+ int scaledSize = sk_float_round2int(scale * gRectSize);
fBitmap.allocPixels(SkImageInfo::MakeS32(scaledSize, scaledSize, kPremul_SkAlphaType));
fBitmap.eraseColor(color);
const char* qualityNames[] = { "None", "Low", "Medium", "High" };
diff --git a/include/private/SkFloatBits.h b/include/private/SkFloatBits.h
index 7a4c708218..2740a25d04 100644
--- a/include/private/SkFloatBits.h
+++ b/include/private/SkFloatBits.h
@@ -72,46 +72,8 @@ static inline float Sk2sComplimentAsFloat(int32_t x) {
return SkBits2Float(Sk2sComplimentToSignBit(x));
}
-static inline int32_t pin_double_to_int(double x) {
- return (int32_t)SkTPin<double>(x, SK_MinS32, SK_MaxS32);
-}
-
-/** Return the floor of the float as an int.
- If the value is out of range, or NaN, return +/- SK_MaxS32
-*/
-static inline int32_t SkFloatToIntFloor(float x) {
-#ifdef SK_SUPPORT_LEGACY_FLOATBITS
- return pin_double_to_int(floor(x));
-#else
- return (int)floorf(x);
-#endif
-}
-
-/** Return the float rounded to an int.
- If the value is out of range, or NaN, return +/- SK_MaxS32
-*/
-static inline int32_t SkFloatToIntRound(float x) {
-#ifdef SK_SUPPORT_LEGACY_FLOATBITS
- return pin_double_to_int(floor((double)x + 0.5));
-#else
- return (int)floorf(x + 0.5f);
-#endif
-}
-
-/** Return the ceiling of the float as an int.
- If the value is out of range, or NaN, return +/- SK_MaxS32
-*/
-static inline int32_t SkFloatToIntCeil(float x) {
-#ifdef SK_SUPPORT_LEGACY_FLOATBITS
- return pin_double_to_int(ceil(x));
-#else
- return (int)ceilf(x);
-#endif
-}
-
// Scalar wrappers for float-bit routines
#define SkScalarAs2sCompliment(x) SkFloatAs2sCompliment(x)
-#define Sk2sComplimentAsScalar(x) Sk2sComplimentAsFloat(x)
#endif
diff --git a/include/private/SkFloatingPoint.h b/include/private/SkFloatingPoint.h
index 2267234822..c35c95194d 100644
--- a/include/private/SkFloatingPoint.h
+++ b/include/private/SkFloatingPoint.h
@@ -1,4 +1,3 @@
-
/*
* Copyright 2006 The Android Open Source Project
*
@@ -6,10 +5,10 @@
* found in the LICENSE file.
*/
-
#ifndef SkFloatingPoint_DEFINED
#define SkFloatingPoint_DEFINED
+#include "../private/SkFloatBits.h"
#include "SkTypes.h"
#include "SkSafe_math.h"
#include <float.h>
@@ -25,8 +24,6 @@
#include <unistd.h>
#endif
-#include "SkFloatBits.h"
-
// C++98 cmath std::pow seems to be the earliest portable way to get float pow.
// However, on Linux including cmath undefines isfinite.
// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14608
@@ -71,8 +68,7 @@ static inline float sk_float_pow(float base, float exp) {
#define sk_float_isfinite(x) _finite(x)
#define sk_float_isnan(x) _isnan(x)
static inline int sk_float_isinf(float x) {
- int32_t bits = SkFloat2Bits(x);
- return (bits << 1) == (0xFF << 24);
+ return x && (x + x == x);
}
#else
#define sk_float_isfinite(x) isfinite(x)
diff --git a/include/utils/SkRandom.h b/include/utils/SkRandom.h
index 7b5663118c..aec9940262 100644
--- a/include/utils/SkRandom.h
+++ b/include/utils/SkRandom.h
@@ -9,6 +9,7 @@
#define SkRandom_DEFINED
#include "../private/SkFixed.h"
+#include "../private/SkFloatBits.h"
#include "SkScalar.h"
/** \class SkRandom
diff --git a/src/ports/SkScalerContext_win_dw.cpp b/src/ports/SkScalerContext_win_dw.cpp
index 1b5cdc8c67..a84e653f28 100644
--- a/src/ports/SkScalerContext_win_dw.cpp
+++ b/src/ports/SkScalerContext_win_dw.cpp
@@ -867,10 +867,10 @@ void SkScalerContext_DW::generateColorGlyphImage(const SkGlyph& glyph) {
SkColor color;
if (colorGlyph->paletteIndex != 0xffff) {
- color = SkColorSetARGB(SkFloatToIntRound(colorGlyph->runColor.a * 255),
- SkFloatToIntRound(colorGlyph->runColor.r * 255),
- SkFloatToIntRound(colorGlyph->runColor.g * 255),
- SkFloatToIntRound(colorGlyph->runColor.b * 255));
+ color = SkColorSetARGB(sk_float_round2int(colorGlyph->runColor.a * 255),
+ sk_float_round2int(colorGlyph->runColor.r * 255),
+ sk_float_round2int(colorGlyph->runColor.g * 255),
+ sk_float_round2int(colorGlyph->runColor.b * 255));
} else {
// If all components of runColor are 0 or (equivalently) paletteIndex is 0xFFFF then
// the 'current brush' is used. fRec.getLuminanceColor() is kinda sorta what is wanted
diff --git a/src/shaders/gradients/SkLinearGradient.cpp b/src/shaders/gradients/SkLinearGradient.cpp
index 32b2ba5670..2645c38a51 100644
--- a/src/shaders/gradients/SkLinearGradient.cpp
+++ b/src/shaders/gradients/SkLinearGradient.cpp
@@ -636,7 +636,7 @@ void SkLinearGradient::LinearGradientContext::shade4_dx_clamp(SkPMColor dstC[],
if (fx < 0) {
// count is guaranteed to be positive, but the first arg may overflow int32 after
// increment => casting to uint32 ensures correct clamping.
- int n = SkTMin<uint32_t>(static_cast<uint32_t>(SkFloatToIntFloor(-fx * invDx)) + 1,
+ int n = SkTMin<uint32_t>(static_cast<uint32_t>(sk_float_floor2int(-fx * invDx)) + 1,
count);
SkASSERT(n > 0);
fill<apply_alpha>(dstC, n, rec[0].fColor);
@@ -652,7 +652,7 @@ void SkLinearGradient::LinearGradientContext::shade4_dx_clamp(SkPMColor dstC[],
if (fx > 1) {
// count is guaranteed to be positive, but the first arg may overflow int32 after
// increment => casting to uint32 ensures correct clamping.
- int n = SkTMin<uint32_t>(static_cast<uint32_t>(SkFloatToIntFloor((1 - fx) * invDx)) + 1,
+ int n = SkTMin<uint32_t>(static_cast<uint32_t>(sk_float_floor2int((1 - fx) * invDx)) + 1,
count);
SkASSERT(n > 0);
fill<apply_alpha>(dstC, n, rec[fRecs.count() - 1].fColor);