diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/Sk64.cpp | 54 | ||||
-rw-r--r-- | src/core/SkCordic.cpp | 289 | ||||
-rw-r--r-- | src/core/SkCordic.h | 28 | ||||
-rw-r--r-- | src/core/SkFloat.h | 2 | ||||
-rw-r--r-- | src/core/SkMath.cpp | 215 | ||||
-rw-r--r-- | src/core/SkMathPriv.h | 10 | ||||
-rw-r--r-- | src/core/SkPicturePlayback.cpp | 4 | ||||
-rw-r--r-- | src/effects/gradients/SkLinearGradient.cpp | 6 | ||||
-rw-r--r-- | src/utils/SkUnitMappers.cpp | 3 |
9 files changed, 12 insertions, 599 deletions
diff --git a/src/core/Sk64.cpp b/src/core/Sk64.cpp index 54b30221c9..1fb0454ae2 100644 --- a/src/core/Sk64.cpp +++ b/src/core/Sk64.cpp @@ -133,19 +133,14 @@ void Sk64::abs() } } +#if 0 SkBool Sk64::isFixed() const { Sk64 tmp = *this; tmp.roundRight(16); return tmp.is32(); } - -SkFract Sk64::getFract() const -{ - Sk64 tmp = *this; - tmp.roundRight(30); - return tmp.get32(); -} +#endif void Sk64::sub(const Sk64& a) { @@ -298,48 +293,3 @@ int32_t Sk64::getSqrt() const return value | fLo; } #endif - -SkFixed Sk64::getFixedDiv(const Sk64& denom) const -{ - Sk64 N = *this; - Sk64 D = denom; - int32_t sign = SkExtractSign(N.fHi ^ D.fHi); - SkFixed result; - - N.abs(); - D.abs(); - - // need to knock D down to just 31 bits - // either by rounding it to the right, or shifting N to the left - // then we can just call 64/32 div - - int nclz = N.fHi ? SkCLZ(N.fHi) : 32; - int dclz = D.fHi ? SkCLZ(D.fHi) : (33 - (D.fLo >> 31)); - - int shiftN = nclz - 1; - SkASSERT(shiftN >= 0); - int shiftD = 33 - dclz; - SkASSERT(shiftD >= 0); - - if (shiftD + shiftN < 16) - shiftD = 16 - shiftN; - else - shiftN = 16 - shiftD; - - D.roundRight(shiftD); - if (D.isZero()) - result = SK_MaxS32; - else - { - if (shiftN >= 0) - N.shiftLeft(shiftN); - else - N.roundRight(-shiftN); - N.div(D.get32(), Sk64::kTrunc_DivOption); - if (N.is32()) - result = N.get32(); - else - result = SK_MaxS32; - } - return SkApplySign(result, sign); -} diff --git a/src/core/SkCordic.cpp b/src/core/SkCordic.cpp deleted file mode 100644 index 3adc92faa1..0000000000 --- a/src/core/SkCordic.cpp +++ /dev/null @@ -1,289 +0,0 @@ -/* - * Copyright 2006 The Android Open Source Project - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "SkCordic.h" -#include "SkMathPriv.h" -#include "Sk64.h" - -// 0x20000000 equals pi / 4 -const int32_t kATanDegrees[] = { 0x20000000, - 0x12E4051D, 0x9FB385B, 0x51111D4, 0x28B0D43, 0x145D7E1, 0xA2F61E, 0x517C55, - 0x28BE53, 0x145F2E, 0xA2F98, 0x517CC, 0x28BE6, 0x145F3, 0xA2F9, 0x517C, - 0x28BE, 0x145F, 0xA2F, 0x517, 0x28B, 0x145, 0xA2, 0x51, 0x28, 0x14, - 0xA, 0x5, 0x2, 0x1 }; - -const int32_t kFixedInvGain1 = 0x18bde0bb; // 0.607252935 - -static void SkCircularRotation(int32_t* x0, int32_t* y0, int32_t* z0) -{ - int32_t t = 0; - int32_t x = *x0; - int32_t y = *y0; - int32_t z = *z0; - const int32_t* tanPtr = kATanDegrees; - do { - int32_t x1 = y >> t; - int32_t y1 = x >> t; - int32_t tan = *tanPtr++; - if (z >= 0) { - x -= x1; - y += y1; - z -= tan; - } else { - x += x1; - y -= y1; - z += tan; - } - } while (++t < 16); // 30); - *x0 = x; - *y0 = y; - *z0 = z; -} - -SkFixed SkCordicSinCos(SkFixed radians, SkFixed* cosp) -{ - int32_t scaledRadians = radians * 0x28be; // scale radians to 65536 / PI() - int quadrant = scaledRadians >> 30; - quadrant += 1; - if (quadrant & 2) - scaledRadians = -scaledRadians + 0x80000000; - /* |a| <= 90 degrees as a 1.31 number */ - SkFixed sin = 0; - SkFixed cos = kFixedInvGain1; - SkCircularRotation(&cos, &sin, &scaledRadians); - Sk64 scaled; - scaled.setMul(sin, 0x6488d); - sin = scaled.fHi; - scaled.setMul(cos, 0x6488d); - if (quadrant & 2) - scaled.fHi = - scaled.fHi; - *cosp = scaled.fHi; - return sin; -} - -SkFixed SkCordicTan(SkFixed a) -{ - int32_t cos; - int32_t sin = SkCordicSinCos(a, &cos); - return SkFixedDiv(sin, cos); -} - -static int32_t SkCircularVector(int32_t* y0, int32_t* x0, int32_t vecMode) -{ - int32_t x = *x0; - int32_t y = *y0; - int32_t z = 0; - int32_t t = 0; - const int32_t* tanPtr = kATanDegrees; - do { - int32_t x1 = y >> t; - int32_t y1 = x >> t; - int32_t tan = *tanPtr++; - if (y < vecMode) { - x -= x1; - y += y1; - z -= tan; - } else { - x += x1; - y -= y1; - z += tan; - } - } while (++t < 16); // 30 - Sk64 scaled; - scaled.setMul(z, 0x6488d); // scale back into the SkScalar space (0x100000000/0x28be) - return scaled.fHi; -} - -SkFixed SkCordicASin(SkFixed a) { - int32_t sign = SkExtractSign(a); - int32_t z = SkFixedAbs(a); - if (z >= SK_Fixed1) - return SkApplySign(SK_FixedPI>>1, sign); - int32_t x = kFixedInvGain1; - int32_t y = 0; - z *= 0x28be; - z = SkCircularVector(&y, &x, z); - z = SkApplySign(z, ~sign); - return z; -} - -SkFixed SkCordicACos(SkFixed a) { - int32_t z = SkCordicASin(a); - z = (SK_FixedPI>>1) - z; - return z; -} - -SkFixed SkCordicATan2(SkFixed y, SkFixed x) { - if ((x | y) == 0) - return 0; - int32_t xsign = SkExtractSign(x); - x = SkFixedAbs(x); - int32_t result = SkCircularVector(&y, &x, 0); - if (xsign) { - int32_t rsign = SkExtractSign(result); - if (y == 0) - rsign = 0; - SkFixed pi = SkApplySign(SK_FixedPI, rsign); - result = pi - result; - } - return result; -} - -const int32_t kATanHDegrees[] = { - 0x1661788D, 0xA680D61, 0x51EA6FC, 0x28CBFDD, 0x1460E34, - 0xA2FCE8, 0x517D2E, 0x28BE6E, 0x145F32, - 0xA2F98, 0x517CC, 0x28BE6, 0x145F3, 0xA2F9, 0x517C, - 0x28BE, 0x145F, 0xA2F, 0x517, 0x28B, 0x145, 0xA2, 0x51, 0x28, 0x14, - 0xA, 0x5, 0x2, 0x1 }; - -const int32_t kFixedInvGain2 = 0x31330AAA; // 1.207534495 - -static void SkHyperbolic(int32_t* x0, int32_t* y0, int32_t* z0, int mode) -{ - int32_t t = 1; - int32_t x = *x0; - int32_t y = *y0; - int32_t z = *z0; - const int32_t* tanPtr = kATanHDegrees; - int k = -3; - do { - int32_t x1 = y >> t; - int32_t y1 = x >> t; - int32_t tan = *tanPtr++; - int count = 2 + (k >> 31); - if (++k == 1) - k = -2; - do { - if (((y >> 31) & mode) | ~((z >> 31) | mode)) { - x += x1; - y += y1; - z -= tan; - } else { - x -= x1; - y -= y1; - z += tan; - } - } while (--count); - } while (++t < 30); - *x0 = x; - *y0 = y; - *z0 = z; -} - -SkFixed SkCordicLog(SkFixed a) { - a *= 0x28be; - int32_t x = a + 0x28BE60DB; // 1.0 - int32_t y = a - 0x28BE60DB; - int32_t z = 0; - SkHyperbolic(&x, &y, &z, -1); - Sk64 scaled; - scaled.setMul(z, 0x6488d); - z = scaled.fHi; - return z << 1; -} - -SkFixed SkCordicExp(SkFixed a) { - int32_t cosh = kFixedInvGain2; - int32_t sinh = 0; - SkHyperbolic(&cosh, &sinh, &a, 0); - return cosh + sinh; -} - -#ifdef SK_DEBUG - -#include "SkFloatingPoint.h" - -void SkCordic_UnitTest() -{ -#if defined(SK_SUPPORT_UNITTEST) - float val; - for (float angle = -720; angle < 720; angle += 30) { - float radian = angle * 3.1415925358f / 180.0f; - SkFixed f_angle = SkFloatToFixed(radian); - // sincos - float sine = sinf(radian); - float cosine = cosf(radian); - SkFixed f_cosine; - SkFixed f_sine = SkCordicSinCos(f_angle, &f_cosine); - float sine2 = (float) f_sine / 65536.0f; - float cosine2 = (float) f_cosine / 65536.0f; - float error = fabsf(sine - sine2); - if (error > 0.001) - SkDebugf("sin error : angle = %g ; sin = %g ; cordic = %g\n", angle, sine, sine2); - error = fabsf(cosine - cosine2); - if (error > 0.001) - SkDebugf("cos error : angle = %g ; cos = %g ; cordic = %g\n", angle, cosine, cosine2); - // tan - float _tan = tanf(radian); - SkFixed f_tan = SkCordicTan(f_angle); - float tan2 = (float) f_tan / 65536.0f; - error = fabsf(_tan - tan2); - if (error > 0.05 && fabsf(_tan) < 1e6) - SkDebugf("tan error : angle = %g ; tan = %g ; cordic = %g\n", angle, _tan, tan2); - } - for (val = -1; val <= 1; val += .1f) { - SkFixed f_val = SkFloatToFixed(val); - // asin - float arcsine = asinf(val); - SkFixed f_arcsine = SkCordicASin(f_val); - float arcsine2 = (float) f_arcsine / 65536.0f; - float error = fabsf(arcsine - arcsine2); - if (error > 0.001) - SkDebugf("asin error : val = %g ; asin = %g ; cordic = %g\n", val, arcsine, arcsine2); - } -#if 1 - for (val = -1; val <= 1; val += .1f) { -#else - val = .5; { -#endif - SkFixed f_val = SkFloatToFixed(val); - // acos - float arccos = acosf(val); - SkFixed f_arccos = SkCordicACos(f_val); - float arccos2 = (float) f_arccos / 65536.0f; - float error = fabsf(arccos - arccos2); - if (error > 0.001) - SkDebugf("acos error : val = %g ; acos = %g ; cordic = %g\n", val, arccos, arccos2); - } - // atan2 -#if 1 - for (val = -1000; val <= 1000; val += 500.f) { - for (float val2 = -1000; val2 <= 1000; val2 += 500.f) { -#else - val = 0; { - float val2 = -1000; { -#endif - SkFixed f_val = SkFloatToFixed(val); - SkFixed f_val2 = SkFloatToFixed(val2); - float arctan = atan2f(val, val2); - SkFixed f_arctan = SkCordicATan2(f_val, f_val2); - float arctan2 = (float) f_arctan / 65536.0f; - float error = fabsf(arctan - arctan2); - if (error > 0.001) - SkDebugf("atan2 error : val = %g ; val2 = %g ; atan2 = %g ; cordic = %g\n", val, val2, arctan, arctan2); - } - } - // log -#if 1 - for (val = 0.125f; val <= 8.f; val *= 2.0f) { -#else - val = .5; { -#endif - SkFixed f_val = SkFloatToFixed(val); - // acos - float log = logf(val); - SkFixed f_log = SkCordicLog(f_val); - float log2 = (float) f_log / 65536.0f; - float error = fabsf(log - log2); - if (error > 0.001) - SkDebugf("log error : val = %g ; log = %g ; cordic = %g\n", val, log, log2); - } - // exp -#endif -} - -#endif diff --git a/src/core/SkCordic.h b/src/core/SkCordic.h deleted file mode 100644 index fecf645643..0000000000 --- a/src/core/SkCordic.h +++ /dev/null @@ -1,28 +0,0 @@ - -/* - * Copyright 2006 The Android Open Source Project - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - - -#ifndef SkCordic_DEFINED -#define SkCordic_DEFINED - -#include "SkTypes.h" -#include "SkFixed.h" - -SkFixed SkCordicACos(SkFixed a); -SkFixed SkCordicASin(SkFixed a); -SkFixed SkCordicATan2(SkFixed y, SkFixed x); -SkFixed SkCordicExp(SkFixed a); -SkFixed SkCordicLog(SkFixed a); -SkFixed SkCordicSinCos(SkFixed radians, SkFixed* cosp); -SkFixed SkCordicTan(SkFixed a); - -#ifdef SK_DEBUG - void SkCordic_UnitTest(); -#endif - -#endif // SkCordic diff --git a/src/core/SkFloat.h b/src/core/SkFloat.h index 74cd19e542..0d4f9b41a7 100644 --- a/src/core/SkFloat.h +++ b/src/core/SkFloat.h @@ -20,12 +20,10 @@ public: // void setShift(int value, int shift) { fPacked = SetShift(value, shift); } void setInt(int value) { fPacked = SetShift(value, 0); } void setFixed(SkFixed value) { fPacked = SetShift(value, -16); } - void setFract(SkFract value) { fPacked = SetShift(value, -30); } // int getShift(int shift) const { return GetShift(fPacked, shift); } int getInt() const { return GetShift(fPacked, 0); } SkFixed getFixed() const { return GetShift(fPacked, -16); } - SkFract getFract() const { return GetShift(fPacked, -30); } void abs() { fPacked = Abs(fPacked); } void negate() { fPacked = Neg(fPacked); } diff --git a/src/core/SkMath.cpp b/src/core/SkMath.cpp index f1ba3a3a0c..1d356c7951 100644 --- a/src/core/SkMath.cpp +++ b/src/core/SkMath.cpp @@ -6,7 +6,6 @@ */ #include "SkMathPriv.h" -#include "SkCordic.h" #include "SkFloatBits.h" #include "SkFloatingPoint.h" #include "Sk64.h" @@ -54,63 +53,8 @@ int32_t SkMulDiv(int32_t numer1, int32_t numer2, int32_t denom) { return tmp.get32(); } -int32_t SkMulShift(int32_t a, int32_t b, unsigned shift) { - int sign = SkExtractSign(a ^ b); - - if (shift > 63) { - return sign; - } - - a = SkAbs32(a); - b = SkAbs32(b); - - uint32_t ah = a >> 16; - uint32_t al = a & 0xFFFF; - uint32_t bh = b >> 16; - uint32_t bl = b & 0xFFFF; - - uint32_t A = ah * bh; - uint32_t B = ah * bl + al * bh; - uint32_t C = al * bl; - - /* [ A ] - [ B ] - [ C ] - */ - uint32_t lo = C + (B << 16); - int32_t hi = A + (B >> 16) + (lo < C); - - if (sign < 0) { - hi = -hi - Sk32ToBool(lo); - lo = 0 - lo; - } - - if (shift == 0) { -#ifdef SK_DEBUGx - SkASSERT(((int32_t)lo >> 31) == hi); -#endif - return lo; - } else if (shift >= 32) { - return hi >> (shift - 32); - } else { -#ifdef SK_DEBUGx - int32_t tmp = hi >> shift; - SkASSERT(tmp == 0 || tmp == -1); -#endif - // we want (hi << (32 - shift)) | (lo >> shift) but rounded - int roundBit = (lo >> (shift - 1)) & 1; - return ((hi << (32 - shift)) | (lo >> shift)) + roundBit; - } -} - SkFixed SkFixedMul_portable(SkFixed a, SkFixed b) { -#if 0 - Sk64 tmp; - - tmp.setMul(a, b); - tmp.shiftRight(16); - return tmp.fLo; -#elif defined(SkLONGLONG) +#if defined(SkLONGLONG) return static_cast<SkFixed>((SkLONGLONG)a * b >> 16); #else int sa = SkExtractSign(a); @@ -130,103 +74,6 @@ SkFixed SkFixedMul_portable(SkFixed a, SkFixed b) { #endif } -SkFract SkFractMul_portable(SkFract a, SkFract b) { -#if 0 - Sk64 tmp; - tmp.setMul(a, b); - return tmp.getFract(); -#elif defined(SkLONGLONG) - return static_cast<SkFract>((SkLONGLONG)a * b >> 30); -#else - int sa = SkExtractSign(a); - int sb = SkExtractSign(b); - // now make them positive - a = SkApplySign(a, sa); - b = SkApplySign(b, sb); - - uint32_t ah = a >> 16; - uint32_t al = a & 0xFFFF; - uint32_t bh = b >> 16; - uint32_t bl = b & 0xFFFF; - - uint32_t A = ah * bh; - uint32_t B = ah * bl + al * bh; - uint32_t C = al * bl; - - /* [ A ] - [ B ] - [ C ] - */ - uint32_t Lo = C + (B << 16); - uint32_t Hi = A + (B >>16) + (Lo < C); - - SkASSERT((Hi >> 29) == 0); // else overflow - - int32_t R = (Hi << 2) + (Lo >> 30); - - return SkApplySign(R, sa ^ sb); -#endif -} - -int SkFixedMulCommon(SkFixed a, int b, int bias) { - // this function only works if b is 16bits - SkASSERT(b == (int16_t)b); - SkASSERT(b >= 0); - - int sa = SkExtractSign(a); - a = SkApplySign(a, sa); - uint32_t ah = a >> 16; - uint32_t al = a & 0xFFFF; - uint32_t R = ah * b + ((al * b + bias) >> 16); - return SkApplySign(R, sa); -} - -#ifdef SK_DEBUGx - #define TEST_FASTINVERT -#endif - -SkFixed SkFixedFastInvert(SkFixed x) { -/* Adapted (stolen) from gglRecip() -*/ - - if (x == SK_Fixed1) { - return SK_Fixed1; - } - - int sign = SkExtractSign(x); - uint32_t a = SkApplySign(x, sign); - - if (a <= 2) { - return SkApplySign(SK_MaxS32, sign); - } - -#ifdef TEST_FASTINVERT - SkFixed orig = a; - uint32_t slow = SkFixedDiv(SK_Fixed1, a); -#endif - - // normalize a - int lz = SkCLZ(a); - a = a << lz >> 16; - - // compute 1/a approximation (0.5 <= a < 1.0) - uint32_t r = 0x17400 - a; // (2.90625 (~2.914) - 2*a) >> 1 - - // Newton-Raphson iteration: - // x = r*(2 - a*r) = ((r/2)*(1 - a*r/2))*4 - r = ( (0x10000 - ((a*r)>>16)) * r ) >> 15; - r = ( (0x10000 - ((a*r)>>16)) * r ) >> (30 - lz); - -#ifdef TEST_FASTINVERT - SkDebugf("SkFixedFastInvert(%x %g) = %x %g Slow[%x %g]\n", - orig, orig/65536., - r, r/65536., - slow, slow/65536.); -#endif - - return SkApplySign(r, sign); -} - /////////////////////////////////////////////////////////////////////////////// #define DIVBITS_ITER(n) \ @@ -295,26 +142,6 @@ int32_t SkDivBits(int32_t numer, int32_t denom, int shift_bias) { return SkApplySign(result, sign); } -/* mod(float numer, float denom) seems to always return the sign - of the numer, so that's what we do too -*/ -SkFixed SkFixedMod(SkFixed numer, SkFixed denom) { - int sn = SkExtractSign(numer); - int sd = SkExtractSign(denom); - - numer = SkApplySign(numer, sn); - denom = SkApplySign(denom, sd); - - if (numer < denom) { - return SkApplySign(numer, sn); - } else if (numer == denom) { - return 0; - } else { - SkFixed div = SkFixedDiv(numer, denom); - return SkApplySign(SkFixedMul(denom, div & 0xFFFF), sn); - } -} - /* www.worldserver.com/turk/computergraphics/FixedSqrt.pdf */ int32_t SkSqrtBits(int32_t x, int count) { @@ -340,38 +167,6 @@ int32_t SkSqrtBits(int32_t x, int count) { return root; } -int32_t SkCubeRootBits(int32_t value, int bits) { - SkASSERT(bits > 0); - - int sign = SkExtractSign(value); - value = SkApplySign(value, sign); - - uint32_t root = 0; - uint32_t curr = (uint32_t)value >> 30; - value <<= 2; - - do { - root <<= 1; - uint32_t guess = root * root + root; - guess = (guess << 1) + guess; // guess *= 3 - if (guess < curr) { - curr -= guess + 1; - root |= 1; - } - curr = (curr << 3) | ((uint32_t)value >> 29); - value <<= 3; - } while (--bits); - - return SkApplySign(root, sign); -} - -SkFixed SkFixedMean(SkFixed a, SkFixed b) { - Sk64 tmp; - - tmp.setMul(a, b); - return tmp.getSqrt(); -} - /////////////////////////////////////////////////////////////////////////////// float SkScalarSinCos(float radians, float* cosValue) { @@ -503,11 +298,3 @@ SkFixed SkFixedSinCos(SkFixed radians, SkFixed* cosValuePtr) { return sinValue; } -/////////////////////////////////////////////////////////////////////////////// - -SkFixed SkFixedTan(SkFixed radians) { return SkCordicTan(radians); } -SkFixed SkFixedASin(SkFixed x) { return SkCordicASin(x); } -SkFixed SkFixedACos(SkFixed x) { return SkCordicACos(x); } -SkFixed SkFixedATan2(SkFixed y, SkFixed x) { return SkCordicATan2(y, x); } -SkFixed SkFixedExp(SkFixed x) { return SkCordicExp(x); } -SkFixed SkFixedLog(SkFixed x) { return SkCordicLog(x); } diff --git a/src/core/SkMathPriv.h b/src/core/SkMathPriv.h index 4eaad8b9b1..f93ab61078 100644 --- a/src/core/SkMathPriv.h +++ b/src/core/SkMathPriv.h @@ -39,16 +39,6 @@ static inline unsigned SkClampUMax(unsigned value, unsigned max) { return value; } -/** Computes the 64bit product of a * b, and then shifts the answer down by - shift bits, returning the low 32bits. shift must be [0..63] - e.g. to perform a fixedmul, call SkMulShift(a, b, 16) - */ -int32_t SkMulShift(int32_t a, int32_t b, unsigned shift); - -/** Return the integer cube root of value, with a bias of bitBias - */ -int32_t SkCubeRootBits(int32_t value, int bitBias); - /////////////////////////////////////////////////////////////////////////////// /** Return a*b/255, truncating away any fractional bits. Only valid if both diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp index 82c7a03bcd..cb73689eeb 100644 --- a/src/core/SkPicturePlayback.cpp +++ b/src/core/SkPicturePlayback.cpp @@ -1217,11 +1217,11 @@ void dumpMatrix(const SkMatrix& matrix) const { SkScalar perspX = matrix.getPerspX(); if (perspX != defaultMatrix.getPerspX()) bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer), - "{kPerspX, %g}, ", SkFractToFloat(perspX)); + "{kPerspX, %g}, ", perspX); SkScalar perspY = matrix.getPerspY(); if (perspY != defaultMatrix.getPerspY()) bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer), - "{kPerspY, %g}, ", SkFractToFloat(perspY)); + "{kPerspY, %g}, ", perspY); SkDebugf("%s{0}};\n", pBuffer); } diff --git a/src/effects/gradients/SkLinearGradient.cpp b/src/effects/gradients/SkLinearGradient.cpp index 5563a03f7e..70452962ac 100644 --- a/src/effects/gradients/SkLinearGradient.cpp +++ b/src/effects/gradients/SkLinearGradient.cpp @@ -377,6 +377,10 @@ void shadeSpan16_linear_repeat(TileProc proc, SkFixed dx, SkFixed fx, } } +static bool fixed_nearly_zero(SkFixed x) { + return SkAbs32(x) < (SK_Fixed1 >> 12); +} + void SkLinearGradient::shadeSpan16(int x, int y, uint16_t* SK_RESTRICT dstC, int count) { SkASSERT(count > 0); @@ -402,7 +406,7 @@ void SkLinearGradient::shadeSpan16(int x, int y, } LinearShade16Proc shadeProc = shadeSpan16_linear_repeat; - if (SkFixedNearlyZero(dx)) { + if (fixed_nearly_zero(dx)) { shadeProc = shadeSpan16_linear_vertical; } else if (SkShader::kClamp_TileMode == fTileMode) { shadeProc = shadeSpan16_linear_clamp; diff --git a/src/utils/SkUnitMappers.cpp b/src/utils/SkUnitMappers.cpp index 5976e9de52..f86a4542db 100644 --- a/src/utils/SkUnitMappers.cpp +++ b/src/utils/SkUnitMappers.cpp @@ -8,6 +8,7 @@ #include "SkUnitMappers.h" #include "SkFlattenableBuffers.h" + SkDiscreteMapper::SkDiscreteMapper(int segments) { if (segments < 2) { fSegments = 0; @@ -17,7 +18,7 @@ SkDiscreteMapper::SkDiscreteMapper(int segments) { segments = 0xFFFF; } fSegments = segments; - fScale = SK_Fract1 / (segments - 1); + fScale = (1 << 30) / (segments - 1); } } |