aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-12-16 14:17:40 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-12-16 14:17:40 +0000
commit3c12840b234e614faf569e80f311a77ce65d9fe0 (patch)
treee1b5f9d9fa466f477412476d7fffcfe2943b4f29
parent96f5fa02e996e39179f2eb88d57e8ed6114b06c5 (diff)
remove SkFP.h and replace SkFP with SkScalar stop respecting SK_SOFTWARE_FLOAT, assume its always false stop respecting SK_SCALAR_SLOW_COMPARES, assume its always false
BUG= R=caryclark@google.com Review URL: https://codereview.chromium.org/116183002 git-svn-id: http://skia.googlecode.com/svn/trunk@12686 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--gyp/core.gypi1
-rw-r--r--include/config/SkUserConfig.h8
-rw-r--r--include/core/SkPostConfig.h10
-rw-r--r--src/core/SkFP.h79
-rw-r--r--src/core/SkGeometry.cpp73
-rw-r--r--src/core/SkMatrix.cpp25
-rw-r--r--src/core/SkRect.cpp21
7 files changed, 30 insertions, 187 deletions
diff --git a/gyp/core.gypi b/gyp/core.gypi
index 086ea84baf..c74c4874bf 100644
--- a/gyp/core.gypi
+++ b/gyp/core.gypi
@@ -83,7 +83,6 @@
'<(skia_src_path)/core/SkEdge.h',
'<(skia_src_path)/core/SkError.cpp',
'<(skia_src_path)/core/SkErrorInternals.h',
- '<(skia_src_path)/core/SkFP.h',
'<(skia_src_path)/core/SkFilterProc.cpp',
'<(skia_src_path)/core/SkFilterProc.h',
'<(skia_src_path)/core/SkFilterShader.cpp',
diff --git a/include/config/SkUserConfig.h b/include/config/SkUserConfig.h
index 236a99a03e..5cd381d74c 100644
--- a/include/config/SkUserConfig.h
+++ b/include/config/SkUserConfig.h
@@ -45,14 +45,6 @@
//#define SK_SCALAR_IS_FIXED
-/* For some performance-critical scalar operations, skia will optionally work
- around the standard float operators if it knows that the CPU does not have
- native support for floats. If your environment uses software floating point,
- define this flag.
- */
-//#define SK_SOFTWARE_FLOAT
-
-
/* Skia has lots of debug-only code. Often this is just null checks or other
parameter checking, but sometimes it can be quite intrusive (e.g. check that
each 32bit pixel is in premultiplied form). This code can be very useful
diff --git a/include/core/SkPostConfig.h b/include/core/SkPostConfig.h
index efb119fe4b..395ece89f1 100644
--- a/include/core/SkPostConfig.h
+++ b/include/core/SkPostConfig.h
@@ -139,16 +139,6 @@
///////////////////////////////////////////////////////////////////////////////
-#if defined(SK_SOFTWARE_FLOAT) && defined(SK_SCALAR_IS_FLOAT)
- // if this is defined, we convert floats to 2s compliment ints for compares.
-# ifndef SK_SCALAR_SLOW_COMPARES
-# define SK_SCALAR_SLOW_COMPARES
-# endif
-# ifndef SK_USE_FLOATBITS
-# define SK_USE_FLOATBITS
-# endif
-#endif
-
#ifdef SK_BUILD_FOR_WIN
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
diff --git a/src/core/SkFP.h b/src/core/SkFP.h
deleted file mode 100644
index 1d1507a369..0000000000
--- a/src/core/SkFP.h
+++ /dev/null
@@ -1,79 +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 SkFP_DEFINED
-#define SkFP_DEFINED
-
-#include "SkMath.h"
-
-#ifdef SK_SCALAR_IS_FLOAT
-
- typedef float SkFP;
-
- #define SkScalarToFP(n) (n)
- #define SkFPToScalar(n) (n)
- #define SkIntToFP(n) SkIntToScalar(n)
- #define SkFPRound(x) SkScalarRound(n)
- #define SkFPCeil(x) SkScalarCeil(n)
- #define SkFPFloor(x) SkScalarFloor(n)
-
- #define SkFPNeg(x) (-(x))
- #define SkFPAbs(x) SkScalarAbs(x)
- #define SkFPAdd(a, b) ((a) + (b))
- #define SkFPSub(a, b) ((a) - (b))
- #define SkFPMul(a, b) ((a) * (b))
- #define SkFPMulInt(a, n) ((a) * (n))
- #define SkFPDiv(a, b) ((a) / (b))
- #define SkFPDivInt(a, n) ((a) / (n))
- #define SkFPInvert(x) SkScalarInvert(x)
- #define SkFPSqrt(x) SkScalarSqrt(x)
- #define SkFPCubeRoot(x) sk_float_pow(x, 0.3333333f)
-
- #define SkFPLT(a, b) ((a) < (b))
- #define SkFPLE(a, b) ((a) <= (b))
- #define SkFPGT(a, b) ((a) > (b))
- #define SkFPGE(a, b) ((a) >= (b))
-
-#else // scalar is fixed
-
- #include "SkFloat.h"
-
- typedef int32_t SkFP;
-
- #define SkScalarToFP(n) SkFloat::SetShift(n, -16)
- #define SkFPToScalar(n) SkFloat::GetShift(n, -16)
- #define SkIntToFP(n) SkFloat::SetShift(n, 0)
- #define SkFPRound(x) SkFloat::Round(x);
- #define SkFPCeil(x) SkFloat::Ceil();
- #define SkFPFloor(x) SkFloat::Floor();
-
- #define SkFPNeg(x) SkFloat::Neg(x)
- #define SkFPAbs(x) SkFloat::Abs(x)
- #define SkFPAdd(a, b) SkFloat::Add(a, b)
- #define SkFPSub(a, b) SkFloat::Add(a, SkFloat::Neg(b))
- #define SkFPMul(a, b) SkFloat::Mul(a, b)
- #define SkFPMulInt(a, n) SkFloat::MulInt(a, n)
- #define SkFPDiv(a, b) SkFloat::Div(a, b)
- #define SkFPDivInt(a, n) SkFloat::DivInt(a, n)
- #define SkFPInvert(x) SkFloat::Invert(x)
- #define SkFPSqrt(x) SkFloat::Sqrt(x)
- #define SkFPCubeRoot(x) SkFloat::CubeRoot(x)
-
- #define SkFPLT(a, b) (SkFloat::Cmp(a, b) < 0)
- #define SkFPLE(a, b) (SkFloat::Cmp(a, b) <= 0)
- #define SkFPGT(a, b) (SkFloat::Cmp(a, b) > 0)
- #define SkFPGE(a, b) (SkFloat::Cmp(a, b) >= 0)
-
-#endif
-
-#ifdef SK_DEBUG
- void SkFP_UnitTest();
-#endif
-
-#endif
diff --git a/src/core/SkGeometry.cpp b/src/core/SkGeometry.cpp
index 11d52b594e..f07ca2a101 100644
--- a/src/core/SkGeometry.cpp
+++ b/src/core/SkGeometry.cpp
@@ -799,8 +799,6 @@ template <typename T> void bubble_sort(T array[], int count)
}
}
-#include "SkFP.h"
-
// newton refinement
#if 0
static SkScalar refine_cubic_root(const SkFP coeff[4], SkScalar root)
@@ -897,6 +895,10 @@ static void test_collaps_duplicates() {
#pragma warning ( disable : 4702 )
#endif
+static SkScalar SkScalarCubeRoot(SkScalar x) {
+ return sk_float_pow(x, 0.3333333f);
+}
+
/* Solve coeff(t) == 0, returning the number of roots that
lie withing 0 < t < 1.
coeff[0]t^3 + coeff[1]t^2 + coeff[2]t + coeff[3]
@@ -904,44 +906,35 @@ static void test_collaps_duplicates() {
Eliminates repeated roots (so that all tValues are distinct, and are always
in increasing order.
*/
-static int solve_cubic_polynomial(const SkFP coeff[4], SkScalar tValues[3])
+static int solve_cubic_polynomial(const SkScalar coeff[4], SkScalar tValues[3])
{
-#ifndef SK_SCALAR_IS_FLOAT
- return 0; // this is not yet implemented for software float
-#endif
-
if (SkScalarNearlyZero(coeff[0])) // we're just a quadratic
{
return SkFindUnitQuadRoots(coeff[1], coeff[2], coeff[3], tValues);
}
- SkFP a, b, c, Q, R;
+ SkScalar a, b, c, Q, R;
{
SkASSERT(coeff[0] != 0);
- SkFP inva = SkFPInvert(coeff[0]);
- a = SkFPMul(coeff[1], inva);
- b = SkFPMul(coeff[2], inva);
- c = SkFPMul(coeff[3], inva);
+ SkScalar inva = SkScalarInvert(coeff[0]);
+ a = coeff[1] * inva;
+ b = coeff[2] * inva;
+ c = coeff[3] * inva;
}
- Q = SkFPDivInt(SkFPSub(SkFPMul(a,a), SkFPMulInt(b, 3)), 9);
-// R = (2*a*a*a - 9*a*b + 27*c) / 54;
- R = SkFPMulInt(SkFPMul(SkFPMul(a, a), a), 2);
- R = SkFPSub(R, SkFPMulInt(SkFPMul(a, b), 9));
- R = SkFPAdd(R, SkFPMulInt(c, 27));
- R = SkFPDivInt(R, 54);
+ Q = (a*a - b*3) / 9;
+ R = (2*a*a*a - 9*a*b + 27*c) / 54;
- SkFP Q3 = SkFPMul(SkFPMul(Q, Q), Q);
- SkFP R2MinusQ3 = SkFPSub(SkFPMul(R,R), Q3);
- SkFP adiv3 = SkFPDivInt(a, 3);
+ SkScalar Q3 = Q * Q * Q;
+ SkScalar R2MinusQ3 = R * R - Q3;
+ SkScalar adiv3 = a / 3;
SkScalar* roots = tValues;
SkScalar r;
- if (SkFPLT(R2MinusQ3, 0)) // we have 3 real roots
+ if (R2MinusQ3 < 0) // we have 3 real roots
{
-#ifdef SK_SCALAR_IS_FLOAT
float theta = sk_float_acos(R / sk_float_sqrt(Q3));
float neg2RootQ = -2 * sk_float_sqrt(Q);
@@ -965,18 +958,17 @@ static int solve_cubic_polynomial(const SkFP coeff[4], SkScalar tValues[3])
bubble_sort(tValues, count);
count = collaps_duplicates(tValues, count);
roots = tValues + count; // so we compute the proper count below
-#endif
}
else // we have 1 real root
{
- SkFP A = SkFPAdd(SkFPAbs(R), SkFPSqrt(R2MinusQ3));
- A = SkFPCubeRoot(A);
- if (SkFPGT(R, 0))
- A = SkFPNeg(A);
+ SkScalar A = SkScalarAbs(R) + SkScalarSqrt(R2MinusQ3);
+ A = SkScalarCubeRoot(A);
+ if (R > 0)
+ A = -A;
if (A != 0)
- A = SkFPAdd(A, SkFPDiv(Q, A));
- r = SkFPToScalar(SkFPSub(A, adiv3));
+ A += Q / A;
+ r = A - adiv3;
if (is_unit_interval(r))
*roots++ = r;
}
@@ -995,21 +987,16 @@ static int solve_cubic_polynomial(const SkFP coeff[4], SkScalar tValues[3])
F' dot F'' -> CCt^3 + 3BCt^2 + (2BB + CA)t + AB
*/
-static void formulate_F1DotF2(const SkScalar src[], SkFP coeff[4])
+static void formulate_F1DotF2(const SkScalar src[], SkScalar coeff[4])
{
SkScalar a = src[2] - src[0];
SkScalar b = src[4] - 2 * src[2] + src[0];
SkScalar c = src[6] + 3 * (src[2] - src[4]) - src[0];
- SkFP A = SkScalarToFP(a);
- SkFP B = SkScalarToFP(b);
- SkFP C = SkScalarToFP(c);
-
- coeff[0] = SkFPMul(C, C);
- coeff[1] = SkFPMulInt(SkFPMul(B, C), 3);
- coeff[2] = SkFPMulInt(SkFPMul(B, B), 2);
- coeff[2] = SkFPAdd(coeff[2], SkFPMul(C, A));
- coeff[3] = SkFPMul(A, B);
+ coeff[0] = c * c;
+ coeff[1] = 3 * b * c;
+ coeff[2] = 2 * b * b + c * a;
+ coeff[3] = a * b;
}
// EXPERIMENTAL: can set this to zero to accept all t-values 0 < t < 1
@@ -1029,14 +1016,14 @@ static void formulate_F1DotF2(const SkScalar src[], SkFP coeff[4])
*/
int SkFindCubicMaxCurvature(const SkPoint src[4], SkScalar tValues[3])
{
- SkFP coeffX[4], coeffY[4];
- int i;
+ SkScalar coeffX[4], coeffY[4];
+ int i;
formulate_F1DotF2(&src[0].fX, coeffX);
formulate_F1DotF2(&src[0].fY, coeffY);
for (i = 0; i < 4; i++)
- coeffX[i] = SkFPAdd(coeffX[i],coeffY[i]);
+ coeffX[i] += coeffY[i];
SkScalar t[3];
int count = solve_cubic_polynomial(coeffX, t);
diff --git a/src/core/SkMatrix.cpp b/src/core/SkMatrix.cpp
index d9c2677a57..fd6290fdd6 100644
--- a/src/core/SkMatrix.cpp
+++ b/src/core/SkMatrix.cpp
@@ -53,18 +53,7 @@ enum {
static const int32_t kPersp1Int = (1 << 30);
#endif
-#ifdef SK_SCALAR_SLOW_COMPARES
- static const int32_t kPersp1Int = 0x3f800000;
-#endif
-
uint8_t SkMatrix::computePerspectiveTypeMask() const {
-#ifdef SK_SCALAR_SLOW_COMPARES
- if (SkScalarAs2sCompliment(fMat[kMPersp0]) |
- SkScalarAs2sCompliment(fMat[kMPersp1]) |
- (SkScalarAs2sCompliment(fMat[kMPersp2]) - kPersp1Int)) {
- return SkToU8(kORableMasks);
- }
-#else
// Benchmarking suggests that replacing this set of SkScalarAs2sCompliment
// is a win, but replacing those below is not. We don't yet understand
// that result.
@@ -76,7 +65,6 @@ uint8_t SkMatrix::computePerspectiveTypeMask() const {
// type mask computation.
return SkToU8(kORableMasks);
}
-#endif
return SkToU8(kOnlyPerspectiveValid_Mask | kUnknown_Mask);
}
@@ -84,18 +72,6 @@ uint8_t SkMatrix::computePerspectiveTypeMask() const {
uint8_t SkMatrix::computeTypeMask() const {
unsigned mask = 0;
-#ifdef SK_SCALAR_SLOW_COMPARES
- if (SkScalarAs2sCompliment(fMat[kMPersp0]) |
- SkScalarAs2sCompliment(fMat[kMPersp1]) |
- (SkScalarAs2sCompliment(fMat[kMPersp2]) - kPersp1Int)) {
- return SkToU8(kORableMasks);
- }
-
- if (SkScalarAs2sCompliment(fMat[kMTransX]) |
- SkScalarAs2sCompliment(fMat[kMTransY])) {
- mask |= kTranslate_Mask;
- }
-#else
if (fMat[kMPersp0] != 0 || fMat[kMPersp1] != 0 ||
fMat[kMPersp2] != kMatrix22Elem) {
// Once it is determined that that this is a perspective transform,
@@ -106,7 +82,6 @@ uint8_t SkMatrix::computeTypeMask() const {
if (fMat[kMTransX] != 0 || fMat[kMTransY] != 0) {
mask |= kTranslate_Mask;
}
-#endif
int m00 = SkScalarAs2sCompliment(fMat[SkMatrix::kMScaleX]);
int m01 = SkScalarAs2sCompliment(fMat[SkMatrix::kMSkewX]);
diff --git a/src/core/SkRect.cpp b/src/core/SkRect.cpp
index c62f2f3cf6..97de0a6a4a 100644
--- a/src/core/SkRect.cpp
+++ b/src/core/SkRect.cpp
@@ -78,24 +78,6 @@ bool SkRect::setBoundsCheck(const SkPoint pts[], int count) {
if (count <= 0) {
sk_bzero(this, sizeof(SkRect));
} else {
-#ifdef SK_SCALAR_SLOW_COMPARES
- int32_t l, t, r, b;
-
- l = r = SkScalarAs2sCompliment(pts[0].fX);
- t = b = SkScalarAs2sCompliment(pts[0].fY);
-
- for (int i = 1; i < count; i++) {
- int32_t x = SkScalarAs2sCompliment(pts[i].fX);
- int32_t y = SkScalarAs2sCompliment(pts[i].fY);
-
- if (x < l) l = x; else if (x > r) r = x;
- if (y < t) t = y; else if (y > b) b = y;
- }
- this->set(Sk2sComplimentAsScalar(l),
- Sk2sComplimentAsScalar(t),
- Sk2sComplimentAsScalar(r),
- Sk2sComplimentAsScalar(b));
-#else
SkScalar l, t, r, b;
l = r = pts[0].fX;
@@ -116,15 +98,12 @@ bool SkRect::setBoundsCheck(const SkPoint pts[], int count) {
if (y < t) t = y; MINMAX_ELSE if (y > b) b = y;
}
-#ifdef SK_SCALAR_IS_FLOAT
SkASSERT(!accum || !SkScalarIsFinite(accum));
if (accum) {
l = t = r = b = 0;
isFinite = false;
}
-#endif
this->set(l, t, r, b);
-#endif
}
return isFinite;