more float/double precision tweaks

git-svn-id: http://skia.googlecode.com/svn/trunk@355 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@android.com 2009-09-18 13:38:43 +00:00
parent 0b9e2dbf2f
commit ab7ac026d2

View File

@ -23,6 +23,10 @@
#ifdef SK_SCALAR_IS_FLOAT
#define kMatrix22Elem SK_Scalar1
static inline float SkDoubleToFloat(double x) {
return static_cast<float>(x);
}
#else
#define kMatrix22Elem SK_Fract1
#endif
@ -455,13 +459,7 @@ bool SkMatrix::setRectToRect(const SkRect& src, const SkRect& dst,
#ifdef SK_SCALAR_IS_FLOAT
static inline int fixmuladdmul(float a, float b, float c, float d,
float* result) {
*result = a * b + c * d;
return true;
}
static inline int fixmuladdmulshiftmul(float a, float b, float c, float d,
int /*shift not used*/, float scale, float* result) {
*result = (a * b + c * d) * scale;
*result = SkDoubleToFloat((double)a * b + (double)c * d);
return true;
}
@ -489,34 +487,6 @@ bool SkMatrix::setRectToRect(const SkRect& src, const SkRect& dst,
return false;
}
static inline bool fixmuladdmulshiftmul(SkFixed a, SkFixed b, SkFixed c,
SkFixed d, int shift, SkFixed scale, SkFixed* result) {
Sk64 tmp1, tmp2;
tmp1.setMul(a, b);
tmp2.setMul(c, d);
tmp1.add(tmp2);
int32_t hi = SkAbs32(tmp1.fHi);
int afterShift = 16;
if (hi >> 15) {
int clz = 17 - SkCLZ(hi);
SkASSERT(clz > 0 && clz <= 16);
afterShift -= clz;
shift += clz;
}
tmp1.roundRight(shift + 16);
SkASSERT(tmp1.is32());
tmp1.setMul(tmp1.get32(), scale);
tmp1.roundRight(afterShift);
if (tmp1.is32()) {
*result = tmp1.get32();
return true;
}
return false;
}
static inline SkFixed fracmuladdmul(SkFixed a, SkFract b, SkFixed c,
SkFract d) {
Sk64 tmp1, tmp2;
@ -690,9 +660,6 @@ bool SkMatrix::postConcat(const SkMatrix& mat) {
}
return 1.0 / det;
}
static inline float SkDoubleToFloat(double x) {
return static_cast<float>(x);
}
// we declar a,b,c,d to all be doubles, because we want to perform
// double-precision muls and subtract, even though the original values are
// from the matrix, which are floats.