remove SK_SCALAR_IS_[FLOAT,FIXED] and assume floats

To keep the CL (slightly) managable, this does not make any changes to
existing macros (e.g. SkScalarMul). Just tackling #ifdef constructs this
time around.

BUG=
R=bsalomon@google.com, caryclark@google.com

Review URL: https://codereview.chromium.org/117053002

git-svn-id: http://skia.googlecode.com/svn/trunk@12712 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2013-12-17 16:44:46 +00:00
parent a34b638b90
commit 8f4d2306fa
69 changed files with 243 additions and 1449 deletions

View File

@ -84,9 +84,6 @@ private:
typedef SkBenchmark INHERITED;
};
// Fixed point can be 100x slower than float on these tests, causing
// bench to timeout.
#ifndef SK_SCALAR_IS_FIXED
DEF_BENCH( return new MorphologyBench(SMALL, kErode_MT); )
DEF_BENCH( return new MorphologyBench(SMALL, kDilate_MT); )
@ -97,4 +94,3 @@ DEF_BENCH( return new MorphologyBench(REAL, kErode_MT); )
DEF_BENCH( return new MorphologyBench(REAL, kDilate_MT); )
DEF_BENCH( return new MorphologyBench(0, kErode_MT); )
#endif

View File

@ -407,12 +407,6 @@ int tool_main(int argc, char** argv) {
writer.option("scale", SkStringPrintf("%d", FLAGS_scale).c_str());
writer.option("clip", SkStringPrintf("%d", FLAGS_clip).c_str());
#if defined(SK_SCALAR_IS_FIXED)
writer.option("scalar", "fixed");
#else
writer.option("scalar", "float");
#endif
#if defined(SK_BUILD_FOR_WIN32)
writer.option("system", "WIN32");
#elif defined(SK_BUILD_FOR_MAC)

View File

@ -10,20 +10,6 @@
// FIXME: needs to be in a header
bool SkSetPoly3To3_A(SkMatrix* matrix, const SkPoint src[3], const SkPoint dst[3]);
#ifdef SK_SCALAR_IS_FIXED
typedef int64_t SkDScalar;
static SkScalar SkDScalar_toScalar(SkDScalar value) {
SkDScalar result = (value + (1 << 15)) >> 16;
int top = result >> 31;
SkASSERT(top == 0 || top == -1);
return (SkScalar)result;
}
static SkScalar divide(SkDScalar numer, SkDScalar denom) {
denom >>= 16;
return numer / denom;
}
#else
typedef double SkDScalar;
static SkScalar SkDScalar_toScalar(SkDScalar value) {
@ -32,7 +18,6 @@ bool SkSetPoly3To3_A(SkMatrix* matrix, const SkPoint src[3], const SkPoint dst[3
static SkScalar divide(SkDScalar numer, SkDScalar denom) {
return static_cast<float>(numer / denom);
}
#endif
static SkDScalar SkDScalar_setMul(SkScalar a, SkScalar b) {
return (SkDScalar) ((SkDScalar) a * b);

View File

@ -18,16 +18,6 @@ public:
}
protected:
#ifdef SK_SCALAR_IS_FIXED
virtual uint32_t onGetFlags() const SK_OVERRIDE {
// SkCanvas::drawCircle, used by this test, performs a quick reject.
// The large size given to the device used by SkGPipeCanvas means that
// the device clip will not be set properly and circles will be
// rejected when in FIXED.
return this->INHERITED::onGetFlags() | GM::kSkipPipe_Flag;
}
#endif
virtual SkString onShortName() {
return SkString("blurs");
}

View File

@ -90,7 +90,6 @@
'../samplecode/SampleMipMap.cpp',
'../samplecode/SampleMovie.cpp',
'../samplecode/SampleOvalTest.cpp',
'../samplecode/SampleOverflow.cpp',
'../samplecode/SamplePatch.cpp',
'../samplecode/SamplePath.cpp',
'../samplecode/SamplePathClip.cpp',

View File

@ -37,14 +37,6 @@
///////////////////////////////////////////////////////////////////////////////
/* Scalars (the fractional value type in skia) can be implemented either as
floats or 16.16 integers (fixed). Exactly one of these two symbols must be
defined.
*/
//#define SK_SCALAR_IS_FLOAT
//#define SK_SCALAR_IS_FIXED
/* 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

View File

@ -282,10 +282,6 @@ typedef int64_t SkFixed48;
#define SkFixed48ToFixed(x) ((SkFixed)((x) >> 32))
#define SkFloatToFixed48(x) ((SkFixed48)((x) * (65536.0f * 65536.0f * 65536.0f)))
#ifdef SK_SCALAR_IS_FLOAT
#define SkScalarToFixed48(x) SkFloatToFixed48(x)
#else
#define SkScalarToFixed48(x) SkFixedToFixed48(x)
#endif
#endif

View File

@ -127,12 +127,7 @@ static inline int32_t SkFloatToIntCeil(float x) {
// Scalar wrappers for float-bit routines
#ifdef SK_SCALAR_IS_FLOAT
#define SkScalarAs2sCompliment(x) SkFloatAs2sCompliment(x)
#define Sk2sComplimentAsScalar(x) Sk2sComplimentAsFloat(x)
#else
#define SkScalarAs2sCompliment(x) (x)
#define Sk2sComplimentAsScalar(x) (x)
#endif
#endif

View File

@ -14,15 +14,10 @@
class SkString;
#ifdef SK_SCALAR_IS_FLOAT
// TODO: can we remove these 3 (need to check chrome/android)
typedef SkScalar SkPersp;
#define SkScalarToPersp(x) (x)
#define SkPerspToScalar(x) (x)
#else
typedef SkFract SkPersp;
#define SkScalarToPersp(x) SkFixedToFract(x)
#define SkPerspToScalar(x) SkFractToFixed(x)
#endif
/** \class SkMatrix
@ -543,13 +538,7 @@ public:
return 0 == memcmp(fMat, m.fMat, sizeof(fMat));
}
#ifdef SK_SCALAR_IS_FIXED
friend bool operator==(const SkMatrix& a, const SkMatrix& b) {
return a.cheapEqualTo(b);
}
#else
friend bool operator==(const SkMatrix& a, const SkMatrix& b);
#endif
friend bool operator!=(const SkMatrix& a, const SkMatrix& b) {
return !(a == b);
}

View File

@ -22,12 +22,6 @@
# error "can't have unittests without debug"
#endif
#if defined(SK_SCALAR_IS_FIXED) && defined(SK_SCALAR_IS_FLOAT)
# error "cannot define both SK_SCALAR_IS_FIXED and SK_SCALAR_IS_FLOAT"
#elif !defined(SK_SCALAR_IS_FIXED) && !defined(SK_SCALAR_IS_FLOAT)
# define SK_SCALAR_IS_FLOAT
#endif
/**
* Matrix calculations may be float or double.
* The default is double, as that is faster given our impl uses doubles

View File

@ -91,12 +91,6 @@
//////////////////////////////////////////////////////////////////////
#if !defined(SK_SCALAR_IS_FLOAT) && !defined(SK_SCALAR_IS_FIXED)
#define SK_SCALAR_IS_FLOAT
#endif
//////////////////////////////////////////////////////////////////////
#if !defined(SK_CPU_BENDIAN) && !defined(SK_CPU_LENDIAN)
#if defined (__ppc__) || defined(__PPC__) || defined(__ppc64__) \
|| defined(__PPC64__)

View File

@ -436,7 +436,6 @@ struct SK_API SkRect {
* returns false.
*/
bool isFinite() const {
#ifdef SK_SCALAR_IS_FLOAT
float accum = 0;
accum *= fLeft;
accum *= fTop;
@ -449,13 +448,6 @@ struct SK_API SkRect {
// value==value will be true iff value is not NaN
// TODO: is it faster to say !accum or accum==accum?
return accum == accum;
#else
// use bit-or for speed, since we don't care about short-circuting the
// tests, and we expect the common case will be that we need to check all.
int isNaN = (SK_FixedNaN == fLeft) | (SK_FixedNaN == fTop) |
(SK_FixedNaN == fRight) | (SK_FixedNaN == fBottom);
return !isNaN;
#endif
}
SkScalar x() const { return fLeft; }

View File

@ -1,4 +1,3 @@
/*
* Copyright 2006 The Android Open Source Project
*
@ -6,28 +5,12 @@
* found in the LICENSE file.
*/
#ifndef SkScalar_DEFINED
#define SkScalar_DEFINED
#include "SkFixed.h"
#include "SkFloatingPoint.h"
/** \file SkScalar.h
Types and macros for the data type SkScalar. This is the fractional numeric type
that, depending on the compile-time flag SK_SCALAR_IS_FLOAT, may be implemented
either as an IEEE float, or as a 16.16 SkFixed. The macros in this file are written
to allow the calling code to manipulate SkScalar values without knowing which representation
is in effect.
*/
#ifdef SK_SCALAR_IS_FLOAT
/** SkScalar is our type for fractional values and coordinates. Depending on
compile configurations, it is either represented as an IEEE float, or
as a 16.16 fixed point integer.
*/
typedef float SkScalar;
/** SK_Scalar1 is defined to be 1.0 represented as an SkScalar
@ -183,83 +166,6 @@
static inline bool SkScalarIsInt(SkScalar x) {
return x == (float)(int)x;
}
#else
typedef SkFixed SkScalar;
#define SK_Scalar1 SK_Fixed1
#define SK_ScalarHalf SK_FixedHalf
#define SK_ScalarInfinity SK_FixedMax
#define SK_ScalarNegativeInfinity SK_FixedMin
#define SK_ScalarMax SK_FixedMax
#define SK_ScalarMin SK_FixedMin
#define SK_ScalarNaN SK_FixedNaN
#define SkScalarIsNaN(x) ((x) == SK_FixedNaN)
#define SkScalarIsFinite(x) ((x) != SK_FixedNaN)
#define SkIntToScalar(n) SkIntToFixed(n)
#define SkFixedToScalar(x) (x)
#define SkScalarToFixed(x) (x)
#define SkScalarToFloat(n) SkFixedToFloat(n)
#ifndef SK_SCALAR_TO_FLOAT_EXCLUDED
#define SkFloatToScalar(n) SkFloatToFixed(n)
#endif
#define SkScalarToDouble(n) SkFixedToDouble(n)
#define SkDoubleToScalar(n) SkDoubleToFixed(n)
#define SkScalarFraction(x) SkFixedFraction(x)
#define SkScalarFloorToScalar(x) SkFixedFloorToFixed(x)
#define SkScalarCeilToScalar(x) SkFixedCeilToFixed(x)
#define SkScalarRoundToScalar(x) SkFixedRoundToFixed(x)
#define SkScalarFloorToInt(x) SkFixedFloorToInt(x)
#define SkScalarCeilToInt(x) SkFixedCeilToInt(x)
#define SkScalarRoundToInt(x) SkFixedRoundToInt(x)
#define SkScalarTruncToInt(x) (((x) < 0) ? SkScalarCeilToInt(x) : SkScalarFloorToInt(x))
#define SkScalarAbs(x) SkFixedAbs(x)
#define SkScalarCopySign(x, y) SkCopySign32(x, y)
#define SkScalarClampMax(x, max) SkClampMax(x, max)
#define SkScalarPin(x, min, max) SkPin32(x, min, max)
#define SkScalarSquare(x) SkFixedSquare(x)
#define SkScalarMul(a, b) SkFixedMul(a, b)
#define SkScalarMulAdd(a, b, c) SkFixedMulAdd(a, b, c)
#define SkScalarMulRound(a, b) SkFixedMulCommon(a, b, SK_FixedHalf)
#define SkScalarMulCeil(a, b) SkFixedMulCommon(a, b, SK_Fixed1 - 1)
#define SkScalarMulFloor(a, b) SkFixedMulCommon(a, b, 0)
#define SkScalarDiv(a, b) SkFixedDiv(a, b)
#define SkScalarMod(a, b) SkFixedMod(a, b)
#define SkScalarMulDiv(a, b, c) SkMulDiv(a, b, c)
#define SkScalarInvert(x) SkFixedInvert(x)
#define SkScalarFastInvert(x) SkFixedFastInvert(x)
#define SkScalarSqrt(x) SkFixedSqrt(x)
#define SkScalarAve(a, b) SkFixedAve(a, b)
#define SkScalarMean(a, b) SkFixedMean(a, b)
#define SkScalarHalf(a) ((a) >> 1)
#define SK_ScalarSqrt2 SK_FixedSqrt2
#define SK_ScalarPI SK_FixedPI
#define SK_ScalarTanPIOver8 SK_FixedTanPIOver8
#define SK_ScalarRoot2Over2 SK_FixedRoot2Over2
#define SkDegreesToRadians(degrees) SkFractMul(degrees, SK_FractPIOver180)
#define SkScalarSinCos(radians, cosPtr) SkFixedSinCos(radians, cosPtr)
#define SkScalarSin(radians) SkFixedSin(radians)
#define SkScalarCos(radians) SkFixedCos(radians)
#define SkScalarTan(val) SkFixedTan(val)
#define SkScalarASin(val) SkFixedASin(val)
#define SkScalarACos(val) SkFixedACos(val)
#define SkScalarATan2(y, x) SkFixedATan2(y,x)
#define SkScalarExp(x) SkFixedExp(x)
#define SkScalarLog(x) SkFixedLog(x)
#define SkMaxScalar(a, b) SkMax32(a, b)
#define SkMinScalar(a, b) SkMin32(a, b)
static inline bool SkScalarIsInt(SkFixed x) {
return 0 == (x & 0xffff);
}
#endif
// DEPRECATED : use ToInt or ToScalar variant
#define SkScalarFloor(x) SkScalarFloorToInt(x)
@ -329,7 +235,6 @@ SkScalar SkScalarInterpFunc(SkScalar searchKey, const SkScalar keys[],
* Helper to compare an array of scalars.
*/
static inline bool SkScalarsEqual(const SkScalar a[], const SkScalar b[], int n) {
#ifdef SK_SCALAR_IS_FLOAT
SkASSERT(n >= 0);
for (int i = 0; i < n; ++i) {
if (a[i] != b[i]) {
@ -337,9 +242,6 @@ static inline bool SkScalarsEqual(const SkScalar a[], const SkScalar b[], int n)
}
}
return true;
#else
return 0 == memcmp(a, b, n * sizeof(SkScalar));
#endif
}
#endif

View File

@ -86,11 +86,7 @@ char* SkStrAppendS64(char buffer[], int64_t, int minDigits);
* Thus if the caller wants to add a 0 at the end, buffer must be at least
* SkStrAppendScalar_MaxSize + 1 bytes large.
*/
#ifdef SK_SCALAR_IS_FLOAT
#define SkStrAppendScalar SkStrAppendFloat
#else
#define SkStrAppendScalar SkStrAppendFixed
#endif
char* SkStrAppendFloat(char buffer[], float);
char* SkStrAppendFixed(char buffer[], SkFixed);

View File

@ -19,17 +19,10 @@
class SkCanvas;
#ifdef SK_SCALAR_IS_FIXED
typedef SkFract SkUnitScalar;
#define SK_UnitScalar1 SK_Fract1
#define SkUnitScalarMul(a, b) SkFractMul(a, b)
#define SkUnitScalarDiv(a, b) SkFractDiv(a, b)
#else
typedef float SkUnitScalar;
#define SK_UnitScalar1 SK_Scalar1
#define SkUnitScalarMul(a, b) SkScalarMul(a, b)
#define SkUnitScalarDiv(a, b) SkScalarDiv(a, b)
#endif
struct SkUnit3D {
SkUnitScalar fX, fY, fZ;

View File

@ -16,12 +16,10 @@
// reconstruct the edges of the circle.
// see bug# 1504910
static void test_circlebounds(SkCanvas*) {
#ifdef SK_SCALAR_IS_FLOAT
SkRect r = { 1.39999998f, 1, 21.3999996f, 21 };
SkPath p;
p.addOval(r);
SkASSERT(r == p.getBounds());
#endif
}
class CircleView : public SampleView {

View File

@ -1,108 +0,0 @@
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SampleCode.h"
#include "SkView.h"
#include "SkCanvas.h"
#include "SkDevice.h"
#include "SkPaint.h"
static void DrawRoundRect() {
#ifdef SK_SCALAR_IS_FIXED
bool ret = false;
SkPaint paint;
SkBitmap bitmap;
SkMatrix matrix;
matrix.reset();
bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1370, 812);
bitmap.allocPixels();
SkCanvas canvas(bitmap);
// set up clipper
SkRect skclip;
skclip.set(SkIntToFixed(284), SkIntToFixed(40), SkIntToFixed(1370), SkIntToFixed(708));
ret = canvas.clipRect(skclip);
SkASSERT(ret);
matrix.set(SkMatrix::kMTransX, SkFloatToFixed(-1153.28));
matrix.set(SkMatrix::kMTransY, SkFloatToFixed(1180.50));
matrix.set(SkMatrix::kMScaleX, SkFloatToFixed(0.177171));
matrix.set(SkMatrix::kMScaleY, SkFloatToFixed(0.177043));
matrix.set(SkMatrix::kMSkewX, SkFloatToFixed(0.126968));
matrix.set(SkMatrix::kMSkewY, SkFloatToFixed(-0.126876));
matrix.set(SkMatrix::kMPersp0, SkFloatToFixed(0.0));
matrix.set(SkMatrix::kMPersp1, SkFloatToFixed(0.0));
ret = canvas.concat(matrix);
paint.setAntiAlias(true);
paint.setColor(0xb2202020);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(SkFloatToFixed(68.13));
SkRect r;
r.set(SkFloatToFixed(-313.714417), SkFloatToFixed(-4.826389), SkFloatToFixed(18014.447266), SkFloatToFixed(1858.154541));
canvas.drawRoundRect(r, SkFloatToFixed(91.756363), SkFloatToFixed(91.756363), paint);
#endif
}
#ifdef SK_SCALAR_IS_FLOATx // FIXME: unclear when if ever this can be enabled
static bool HitTestPath(const SkPath& path, SkScalar x, SkScalar y) {
SkRegion rgn, clip;
int ix = SkScalarFloor(x);
int iy = SkScalarFloor(y);
clip.setRect(ix, iy, ix + 1, iy + 1);
bool contains = rgn.setPath(path, clip);
return contains;
}
#endif
static void TestOverflowHitTest() {
SkPath path;
#ifdef SK_SCALAR_IS_FLOATx // FIXME: unclear when if ever this can be enabled
path.addCircle(0, 0, 70000, SkPath::kCCW_Direction);
SkASSERT(HitTestPath(path, 40000, 40000));
#endif
}
class OverflowView : public SampleView {
public:
OverflowView() {}
protected:
// overrides from SkEventSink
virtual bool onQuery(SkEvent* evt) {
if (SampleCode::TitleQ(*evt)) {
SampleCode::TitleR(evt, "Circles");
return true;
}
return this->INHERITED::onQuery(evt);
}
virtual void onDrawContent(SkCanvas* canvas) {
DrawRoundRect();
TestOverflowHitTest();
}
private:
typedef SampleView INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
static SkView* MyFactory() { return new OverflowView; }
static SkViewRegister reg(MyFactory);

View File

@ -21,7 +21,6 @@ enum SkDisplayMath_Properties {
};
const SkScalar SkDisplayMath::gConstants[] = {
#ifdef SK_SCALAR_IS_FLOAT
2.718281828f, // E
2.302585093f, // LN10
0.693147181f, // LN2
@ -30,16 +29,6 @@ const SkScalar SkDisplayMath::gConstants[] = {
3.141592654f, // PI
0.707106781f, // SQRT1_2
1.414213562f // SQRT2
#else
0x2B7E1, // E
0x24D76, // LN10
0xB172, // LN2
0x6F2E, // LOG10E
0x17154, // LOG2E
0x3243F, // PI
0xB505, // SQRT1_2
0x16A0A // SQRT2
#endif
};
enum SkDisplayMath_Functions {

View File

@ -226,11 +226,7 @@ bool SkDrawColor::setProperty(int index, SkScriptValue& value) {
switch (index) {
case SK_PROPERTY(alpha):
uint8_t alpha;
#ifdef SK_SCALAR_IS_FLOAT
alpha = scalar == SK_Scalar1 ? 255 : SkToU8((U8CPU) (scalar * 256));
#else
alpha = SkToU8((scalar - (scalar >= SK_ScalarHalf)) >> 8);
#endif
color = SkColorSetARGB(alpha, SkColorGetR(color),
SkColorGetG(color), SkColorGetB(color));
break;

View File

@ -14,20 +14,12 @@
#include "SkUnitMapper.h"
static SkScalar SkUnitToScalar(U16CPU x) {
#ifdef SK_SCALAR_IS_FLOAT
return x / 65535.0f;
#else
return x + (x >> 8);
#endif
}
static U16CPU SkScalarToUnit(SkScalar x) {
SkScalar pin = SkScalarPin(x, 0, SK_Scalar1);
#ifdef SK_SCALAR_IS_FLOAT
return (int) (pin * 65535.0f);
#else
return pin - (pin >= 32768);
#endif
}
class SkDrawGradientUnitMapper : public SkUnitMapper {

View File

@ -1650,13 +1650,8 @@ bool SkScriptEngine::ValueToString(SkScriptValue value, SkString* string) {
#define DEF_STRING_ANSWER NULL
#define testInt(expression) { #expression, SkType_Int, expression, DEF_SCALAR_ANSWER, DEF_STRING_ANSWER }
#ifdef SK_SCALAR_IS_FLOAT
#define testScalar(expression) { #expression, SkType_Float, 0, (float) expression, DEF_STRING_ANSWER }
#define testRemainder(exp1, exp2) { #exp1 "%" #exp2, SkType_Float, 0, sk_float_mod(exp1, exp2), DEF_STRING_ANSWER }
#else
#define testScalar(expression) { #expression, SkType_Float, 0, (int) ((expression) * 65536.0f), DEF_STRING_ANSWER }
#define testRemainder(exp1, exp2) { #exp1 "%" #exp2, SkType_Float, 0, (int) (sk_float_mod(exp1, exp2) * 65536.0f), DEF_STRING_ANSWER }
#endif
#define testTrue(expression) { #expression, SkType_Int, 1, DEF_SCALAR_ANSWER, DEF_STRING_ANSWER }
#define testFalse(expression) { #expression, SkType_Int, 0, DEF_SCALAR_ANSWER, DEF_STRING_ANSWER }

View File

@ -1274,13 +1274,8 @@ bool SkScriptEngine2::ValueToString(const SkScriptValue2& value, SkString* strin
#if defined(SK_SUPPORT_UNITTEST)
#define testInt(expression) { #expression, SkOperand2::kS32, expression, 0, NULL }
#ifdef SK_SCALAR_IS_FLOAT
#define testScalar(expression) { #expression, SkOperand2::kScalar, 0, (float) (expression), NULL }
#define testRemainder(exp1, exp2) { #exp1 "%" #exp2, SkOperand2::kScalar, 0, fmodf((float) exp1, (float) exp2), NULL }
#else
#define testScalar(expression) { #expression, SkOperand2::kScalar, 0, (int) ((expression) * 65536.0f), NULL }
#define testRemainder(exp1, exp2) { #exp1 "%" #exp2, SkOperand2::kScalar, 0, (int) (fmod(exp1, exp2) * 65536.0f), NULL }
#endif
#define testTrue(expression) { #expression, SkOperand2::kS32, 1, 0, NULL }
#define testFalse(expression) { #expression, SkOperand2::kS32, 0, 0, NULL }

View File

@ -1457,13 +1457,6 @@ bool SkCanvas::quickReject(const SkPath& path) const {
}
static inline int pinIntForScalar(int x) {
#ifdef SK_SCALAR_IS_FIXED
if (x < SK_MinS16) {
x = SK_MinS16;
} else if (x > SK_MaxS16) {
x = SK_MaxS16;
}
#endif
return x;
}
@ -1487,15 +1480,8 @@ bool SkCanvas::getClipBounds(SkRect* bounds) const {
// adjust it outwards in case we are antialiasing
const int inset = 1;
// SkRect::iset() will correctly assert if we pass a value out of range
// (when SkScalar==fixed), so we pin to legal values. This does not
// really returnt the correct answer, but its the best we can do given
// that we've promised to return SkRect (even though we support devices
// that can be larger than 32K in width or height).
r.iset(pinIntForScalar(ibounds.fLeft - inset),
pinIntForScalar(ibounds.fTop - inset),
pinIntForScalar(ibounds.fRight + inset),
pinIntForScalar(ibounds.fBottom + inset));
r.iset(ibounds.fLeft - inset, ibounds.fTop - inset,
ibounds.fRight + inset, ibounds.fBottom + inset);
inverse.mapRect(bounds, r);
}
return true;

View File

@ -31,11 +31,7 @@ static bool chopMonoCubicAtY(SkPoint pts[4], SkScalar y, SkScalar* t) {
// Initial guess.
// TODO(turk): Check for zero denominator? Shouldn't happen unless the curve
// is not only monotonic but degenerate.
#ifdef SK_SCALAR_IS_FLOAT
SkScalar t1 = ycrv[0] / (ycrv[0] - ycrv[3]);
#else // !SK_SCALAR_IS_FLOAT
SkScalar t1 = SkDivBits(ycrv[0], ycrv[0] - ycrv[3], 16);
#endif // !SK_SCALAR_IS_FLOAT
// Newton's iterations.
const SkScalar tol = SK_Scalar1 / 16384; // This leaves 2 fixed noise bits.
@ -53,11 +49,7 @@ static bool chopMonoCubicAtY(SkPoint pts[4], SkScalar y, SkScalar* t) {
SkScalar y0123 = SkScalarInterp(y012, y123, t0);
SkScalar yder = (y123 - y012) * 3;
// TODO(turk): check for yder==0: horizontal.
#ifdef SK_SCALAR_IS_FLOAT
t1 -= y0123 / yder;
#else // !SK_SCALAR_IS_FLOAT
t1 -= SkDivBits(y0123, yder, 16);
#endif // !SK_SCALAR_IS_FLOAT
converged = SkScalarAbs(t1 - t0) <= tol; // NaN-safe
++iters;
} while (!converged && (iters < maxiters));

View File

@ -36,19 +36,11 @@ int SkEdge::setLine(const SkPoint& p0, const SkPoint& p1, const SkIRect* clip,
SkFDot6 x0, y0, x1, y1;
{
#ifdef SK_SCALAR_IS_FLOAT
float scale = float(1 << (shift + 6));
x0 = int(p0.fX * scale);
y0 = int(p0.fY * scale);
x1 = int(p1.fX * scale);
y1 = int(p1.fY * scale);
#else
shift = 10 - shift;
x0 = p0.fX >> shift;
y0 = p0.fY >> shift;
x1 = p1.fX >> shift;
y1 = p1.fY >> shift;
#endif
}
int winding = 1;
@ -179,7 +171,6 @@ int SkQuadraticEdge::setQuadratic(const SkPoint pts[3], int shift)
SkFDot6 x0, y0, x1, y1, x2, y2;
{
#ifdef SK_SCALAR_IS_FLOAT
float scale = float(1 << (shift + 6));
x0 = int(pts[0].fX * scale);
y0 = int(pts[0].fY * scale);
@ -187,15 +178,6 @@ int SkQuadraticEdge::setQuadratic(const SkPoint pts[3], int shift)
y1 = int(pts[1].fY * scale);
x2 = int(pts[2].fX * scale);
y2 = int(pts[2].fY * scale);
#else
shift = 10 - shift;
x0 = pts[0].fX >> shift;
y0 = pts[0].fY >> shift;
x1 = pts[1].fX >> shift;
y1 = pts[1].fY >> shift;
x2 = pts[2].fX >> shift;
y2 = pts[2].fY >> shift;
#endif
}
int winding = 1;
@ -339,7 +321,6 @@ int SkCubicEdge::setCubic(const SkPoint pts[4], const SkIRect* clip, int shift)
SkFDot6 x0, y0, x1, y1, x2, y2, x3, y3;
{
#ifdef SK_SCALAR_IS_FLOAT
float scale = float(1 << (shift + 6));
x0 = int(pts[0].fX * scale);
y0 = int(pts[0].fY * scale);
@ -349,17 +330,6 @@ int SkCubicEdge::setCubic(const SkPoint pts[4], const SkIRect* clip, int shift)
y2 = int(pts[2].fY * scale);
x3 = int(pts[3].fX * scale);
y3 = int(pts[3].fY * scale);
#else
shift = 10 - shift;
x0 = pts[0].fX >> shift;
y0 = pts[0].fY >> shift;
x1 = pts[1].fX >> shift;
y1 = pts[1].fY >> shift;
x2 = pts[2].fX >> shift;
y2 = pts[2].fY >> shift;
x3 = pts[3].fX >> shift;
y3 = pts[3].fY >> shift;
#endif
}
int winding = 1;

View File

@ -89,19 +89,11 @@ int SkEdge::setLine(const SkPoint& p0, const SkPoint& p1, int shift) {
SkFDot6 x0, y0, x1, y1;
{
#ifdef SK_SCALAR_IS_FLOAT
float scale = float(1 << (shift + 6));
x0 = int(p0.fX * scale);
y0 = int(p0.fY * scale);
x1 = int(p1.fX * scale);
y1 = int(p1.fY * scale);
#else
shift = 10 - shift;
x0 = p0.fX >> shift;
y0 = p0.fY >> shift;
x1 = p1.fX >> shift;
y1 = p1.fY >> shift;
#endif
}
int winding = 1;

View File

@ -39,13 +39,8 @@ inline SkFixed SkFDot6ToFixed(SkFDot6 x) {
return x << 10;
}
#ifdef SK_SCALAR_IS_FLOAT
#define SkScalarToFDot6(x) (SkFDot6)((x) * 64)
#define SkFDot6ToScalar(x) ((SkScalar)(x) * 0.015625f)
#else
#define SkScalarToFDot6(x) ((x) >> 10)
#define SkFDot6ToScalar(x) ((x) << 10)
#endif
inline SkFixed SkFDot6Div(SkFDot6 a, SkFDot6 b) {
SkASSERT(b != 0);

View File

@ -24,9 +24,8 @@ SkFlattenableReadBuffer::SkFlattenableReadBuffer() {
// Set default values. These should be explicitly set by our client
// via setFlags() if the buffer came from serialization.
fFlags = 0;
#ifdef SK_SCALAR_IS_FLOAT
// TODO: remove this flag, since we're always floats (now)
fFlags |= kScalarIsFloat_Flag;
#endif
if (8 == sizeof(void*)) {
fFlags |= kPtrIs64Bit_Flag;
}

View File

@ -68,32 +68,18 @@ bool SkXRayCrossesLine(const SkXRay& pt, const SkPoint pts[2], bool* ambiguous)
involving integer multiplies by 2 or 3, but fewer calls to SkScalarMul.
May also introduce overflow of fixed when we compute our setup.
*/
#ifdef SK_SCALAR_IS_FIXED
#define DIRECT_EVAL_OF_POLYNOMIALS
#endif
// #define DIRECT_EVAL_OF_POLYNOMIALS
////////////////////////////////////////////////////////////////////////
#ifdef SK_SCALAR_IS_FIXED
static int is_not_monotonic(int a, int b, int c, int d)
{
return (((a - b) | (b - c) | (c - d)) & ((b - a) | (c - b) | (d - c))) >> 31;
}
static int is_not_monotonic(int a, int b, int c)
{
return (((a - b) | (b - c)) & ((b - a) | (c - b))) >> 31;
}
#else
static int is_not_monotonic(float a, float b, float c)
{
static int is_not_monotonic(float a, float b, float c) {
float ab = a - b;
float bc = b - c;
if (ab < 0)
if (ab < 0) {
bc = -bc;
}
return ab == 0 || bc < 0;
}
#endif
////////////////////////////////////////////////////////////////////////
@ -141,23 +127,11 @@ int SkFindUnitQuadRoots(SkScalar A, SkScalar B, SkScalar C, SkScalar roots[2])
SkScalar* r = roots;
#ifdef SK_SCALAR_IS_FLOAT
float R = B*B - 4*A*C;
if (R < 0 || SkScalarIsNaN(R)) { // complex roots
return 0;
}
R = sk_float_sqrt(R);
#else
Sk64 RR, tmp;
RR.setMul(B,B);
tmp.setMul(A,C);
tmp.shiftLeft(2);
RR.sub(tmp);
if (RR.isNeg())
return 0;
SkFixed R = RR.getSqrt();
#endif
SkScalar Q = (B < 0) ? -(B-R)/2 : -(B+R)/2;
r += valid_unit_divide(Q, A, r);
@ -172,25 +146,8 @@ int SkFindUnitQuadRoots(SkScalar A, SkScalar B, SkScalar C, SkScalar roots[2])
return (int)(r - roots);
}
#ifdef SK_SCALAR_IS_FIXED
/** Trim A/B/C down so that they are all <= 32bits
and then call SkFindUnitQuadRoots()
*/
static int Sk64FindFixedQuadRoots(const Sk64& A, const Sk64& B, const Sk64& C, SkFixed roots[2])
{
int na = A.shiftToMake32();
int nb = B.shiftToMake32();
int nc = C.shiftToMake32();
int shift = SkMax32(na, SkMax32(nb, nc));
SkASSERT(shift >= 0);
return SkFindUnitQuadRoots(A.getShiftRight(shift), B.getShiftRight(shift), C.getShiftRight(shift), roots);
}
#endif
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
static SkScalar eval_quad(const SkScalar src[], SkScalar t)
{
@ -297,11 +254,7 @@ int SkFindQuadExtrema(SkScalar a, SkScalar b, SkScalar c, SkScalar tValue[1])
/* At + B == 0
t = -B / A
*/
#ifdef SK_SCALAR_IS_FIXED
return is_not_monotonic(a, b, c) && valid_unit_divide(a - b, a - b - b + c, tValue);
#else
return valid_unit_divide(a - b, a - b - b + c, tValue);
#endif
}
static inline void flatten_double_quad_extrema(SkScalar coords[14])
@ -401,31 +354,7 @@ float SkFindQuadMaxCurvature(const SkPoint src[3]) {
SkScalar By = src[0].fY - src[1].fY - src[1].fY + src[2].fY;
SkScalar t = 0; // 0 means don't chop
#ifdef SK_SCALAR_IS_FLOAT
(void)valid_unit_divide(-(Ax * Bx + Ay * By), Bx * Bx + By * By, &t);
#else
// !!! should I use SkFloat here? seems like it
Sk64 numer, denom, tmp;
numer.setMul(Ax, -Bx);
tmp.setMul(Ay, -By);
numer.add(tmp);
if (numer.isPos()) // do nothing if numer <= 0
{
denom.setMul(Bx, Bx);
tmp.setMul(By, By);
denom.add(tmp);
SkASSERT(!denom.isNeg());
if (numer < denom)
{
t = numer.getFixedDiv(denom);
SkASSERT(t >= 0 && t <= SK_Fixed1); // assert that we're numerically stable (ha!)
if ((unsigned)t >= SK_Fixed1) // runtime check for numerical stability
t = 0; // ignore the chop
}
}
#endif
return t;
}
@ -441,11 +370,7 @@ int SkChopQuadAtMaxCurvature(const SkPoint src[3], SkPoint dst[5])
}
}
#ifdef SK_SCALAR_IS_FLOAT
#define SK_ScalarTwoThirds (0.666666666f)
#else
#define SK_ScalarTwoThirds ((SkFixed)(43691))
#endif
void SkConvertQuadToCubic(const SkPoint src[3], SkPoint dst[4]) {
const SkScalar scale = SK_ScalarTwoThirds;
@ -553,11 +478,6 @@ void SkEvalCubicAt(const SkPoint src[4], SkScalar t, SkPoint* loc, SkVector* tan
*/
int SkFindCubicExtrema(SkScalar a, SkScalar b, SkScalar c, SkScalar d, SkScalar tValues[2])
{
#ifdef SK_SCALAR_IS_FIXED
if (!is_not_monotonic(a, b, c, d))
return 0;
#endif
// we divide A,B,C by 3 to simplify
SkScalar A = d - a + 3*(b - c);
SkScalar B = 2*(a - b - b + c);
@ -747,29 +667,8 @@ int SkFindCubicInflections(const SkPoint src[4], SkScalar tValues[])
SkScalar By = src[2].fY - 2 * src[1].fY + src[0].fY;
SkScalar Cx = src[3].fX + 3 * (src[1].fX - src[2].fX) - src[0].fX;
SkScalar Cy = src[3].fY + 3 * (src[1].fY - src[2].fY) - src[0].fY;
int count;
#ifdef SK_SCALAR_IS_FLOAT
count = SkFindUnitQuadRoots(Bx*Cy - By*Cx, Ax*Cy - Ay*Cx, Ax*By - Ay*Bx, tValues);
#else
Sk64 A, B, C, tmp;
A.setMul(Bx, Cy);
tmp.setMul(By, Cx);
A.sub(tmp);
B.setMul(Ax, Cy);
tmp.setMul(Ay, Cx);
B.sub(tmp);
C.setMul(Ax, By);
tmp.setMul(Ay, Bx);
C.sub(tmp);
count = Sk64FindFixedQuadRoots(A, B, C, tValues);
#endif
return count;
return SkFindUnitQuadRoots(Bx*Cy - By*Cx, Ax*Cy - Ay*Cx, Ax*By - Ay*Bx, tValues);
}
int SkChopCubicAtInflections(const SkPoint src[], SkPoint dst[10])
@ -891,10 +790,6 @@ static void test_collaps_duplicates() {
}
#endif
#if defined _WIN32 && _MSC_VER >= 1300 && defined SK_SCALAR_IS_FIXED // disable warning : unreachable code if building fixed point for windows desktop
#pragma warning ( disable : 4702 )
#endif
static SkScalar SkScalarCubeRoot(SkScalar x) {
return sk_float_pow(x, 0.3333333f);
}

View File

@ -28,7 +28,6 @@ static SkScalar sect_with_horizontal(const SkPoint src[2], SkScalar Y) {
if (SkScalarNearlyZero(dy)) {
return SkScalarAve(src[0].fX, src[1].fX);
} else {
#ifdef SK_SCALAR_IS_FLOAT
// need the extra precision so we don't compute a value that exceeds
// our original limits
double X0 = src[0].fX;
@ -41,10 +40,6 @@ static SkScalar sect_with_horizontal(const SkPoint src[2], SkScalar Y) {
// when the doubles were added and subtracted, so we have to pin the
// answer :(
return (float)pin_unsorted(result, X0, X1);
#else
return src[0].fX + SkScalarMulDiv(Y - src[0].fY, src[1].fX - src[0].fX,
dy);
#endif
}
}
@ -54,7 +49,6 @@ static SkScalar sect_with_vertical(const SkPoint src[2], SkScalar X) {
if (SkScalarNearlyZero(dx)) {
return SkScalarAve(src[0].fY, src[1].fY);
} else {
#ifdef SK_SCALAR_IS_FLOAT
// need the extra precision so we don't compute a value that exceeds
// our original limits
double X0 = src[0].fX;
@ -63,10 +57,6 @@ static SkScalar sect_with_vertical(const SkPoint src[2], SkScalar X) {
double Y1 = src[1].fY;
double result = Y0 + ((double)X - X0) * (Y1 - Y0) / (X1 - X0);
return (float)result;
#else
return src[0].fY + SkScalarMulDiv(X - src[0].fX, src[1].fY - src[0].fY,
dx);
#endif
}
}
@ -167,7 +157,6 @@ static bool is_between_unsorted(SkScalar value,
}
#endif
#ifdef SK_SCALAR_IS_FLOAT
#ifdef SK_DEBUG
// This is an example of why we need to pin the result computed in
// sect_with_horizontal. If we didn't explicitly pin, is_between_unsorted would
@ -182,11 +171,9 @@ static void sect_with_horizontal_test_for_pin_results() {
SkASSERT(is_between_unsorted(x, pts[0].fX, pts[1].fX));
}
#endif
#endif
int SkLineClipper::ClipLine(const SkPoint pts[], const SkRect& clip,
SkPoint lines[]) {
#ifdef SK_SCALAR_IS_FLOAT
#ifdef SK_DEBUG
{
static bool gOnce;
@ -195,7 +182,6 @@ int SkLineClipper::ClipLine(const SkPoint pts[], const SkRect& clip,
gOnce = true;
}
}
#endif
#endif
int index0, index1;

View File

@ -12,11 +12,9 @@
#include "Sk64.h"
#include "SkScalar.h"
#ifdef SK_SCALAR_IS_FLOAT
const uint32_t gIEEENotANumber = 0x7FFFFFFF;
const uint32_t gIEEEInfinity = 0x7F800000;
const uint32_t gIEEENegativeInfinity = 0xFF800000;
#endif
#define sub_shift(zeros, x, n) \
zeros -= n; \
@ -376,7 +374,6 @@ SkFixed SkFixedMean(SkFixed a, SkFixed b) {
///////////////////////////////////////////////////////////////////////////////
#ifdef SK_SCALAR_IS_FLOAT
float SkScalarSinCos(float radians, float* cosValue) {
float sinValue = sk_float_sin(radians);
@ -392,7 +389,6 @@ float SkScalarSinCos(float radians, float* cosValue) {
}
return sinValue;
}
#endif
#define INTERP_SINTABLE
#define BUILD_TABLE_AT_RUNTIMEx

View File

@ -11,15 +11,11 @@
#include "SkOnce.h"
#include "SkString.h"
#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
/* [scale-x skew-x trans-x] [X] [X']
[skew-y scale-y trans-y] * [Y] = [Y']
@ -45,13 +41,7 @@ enum {
kRectStaysRect_Shift
};
#ifdef SK_SCALAR_IS_FLOAT
static const int32_t kScalar1Int = 0x3f800000;
#else
#define scalarAsInt(x) (x)
static const int32_t kScalar1Int = (1 << 16);
static const int32_t kPersp1Int = (1 << 30);
#endif
uint8_t SkMatrix::computePerspectiveTypeMask() const {
// Benchmarking suggests that replacing this set of SkScalarAs2sCompliment
@ -133,8 +123,6 @@ uint8_t SkMatrix::computeTypeMask() const {
///////////////////////////////////////////////////////////////////////////////
#ifdef SK_SCALAR_IS_FLOAT
bool operator==(const SkMatrix& a, const SkMatrix& b) {
const SkScalar* SK_RESTRICT ma = a.fMat;
const SkScalar* SK_RESTRICT mb = b.fMat;
@ -144,8 +132,6 @@ bool operator==(const SkMatrix& a, const SkMatrix& b) {
ma[6] == mb[6] && ma[7] == mb[7] && ma[8] == mb[8];
}
#endif
///////////////////////////////////////////////////////////////////////////////
// helper function to determine if upper-left 2x2 of matrix is degenerate
@ -612,7 +598,6 @@ 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 = SkDoubleToFloat((double)a * b + (double)c * d);
@ -629,54 +614,6 @@ bool SkMatrix::setRectToRect(const SkRect& src, const SkRect& dst,
result = a + b;
return 0;
}
#else
static inline bool fixmuladdmul(SkFixed a, SkFixed b, SkFixed c, SkFixed d,
SkFixed* result) {
Sk64 tmp1, tmp2;
tmp1.setMul(a, b);
tmp2.setMul(c, d);
tmp1.add(tmp2);
if (tmp1.isFixed()) {
*result = tmp1.getFixed();
return true;
}
return false;
}
static inline SkFixed fracmuladdmul(SkFixed a, SkFract b, SkFixed c,
SkFract d) {
Sk64 tmp1, tmp2;
tmp1.setMul(a, b);
tmp2.setMul(c, d);
tmp1.add(tmp2);
return tmp1.getFract();
}
static inline bool rowcol3(const SkFixed row[], const SkFixed col[],
SkFixed* result) {
Sk64 tmp1, tmp2;
tmp1.setMul(row[0], col[0]); // N * fixed
tmp2.setMul(row[1], col[3]); // N * fixed
tmp1.add(tmp2);
tmp2.setMul(row[2], col[6]); // N * fract
tmp2.roundRight(14); // make it fixed
tmp1.add(tmp2);
if (tmp1.isFixed()) {
*result = tmp1.getFixed();
return true;
}
return false;
}
static inline int negifaddoverflows(SkFixed& result, SkFixed a, SkFixed b) {
SkFixed c = a + b;
result = c;
return (c ^ a) & (c ^ b);
}
#endif
static void normalize_perspective(SkScalar mat[9]) {
if (SkScalarAbs(mat[SkMatrix::kMPersp2]) > kMatrix22Elem) {
@ -793,10 +730,8 @@ bool SkMatrix::postConcat(const SkMatrix& mat) {
precision may be most important (here and matrix concat). Hence to avoid
bitmap blitting artifacts when walking the inverse, we use doubles for
the intermediate math, even though we know that is more expensive.
The fixed counter part is us using Sk64 for temp calculations.
*/
#ifdef SK_SCALAR_IS_FLOAT
typedef double SkDetScalar;
#define SkPerspMul(a, b) SkScalarMul(a, b)
#define SkScalarMulShift(a, b, s) SkDoubleToFloat((a) * (b))
@ -827,54 +762,6 @@ bool SkMatrix::postConcat(const SkMatrix& mat) {
double scale) {
return SkDoubleToFloat((a * b - c * d) * scale);
}
#else
typedef SkFixed SkDetScalar;
#define SkPerspMul(a, b) SkFractMul(a, b)
#define SkScalarMulShift(a, b, s) SkMulShift(a, b, s)
static void set_muladdmul(Sk64* dst, int32_t a, int32_t b, int32_t c,
int32_t d) {
Sk64 tmp;
dst->setMul(a, b);
tmp.setMul(c, d);
dst->add(tmp);
}
static SkFixed sk_inv_determinant(const SkFixed mat[9], int isPerspective,
int* shift) {
Sk64 tmp1, tmp2;
if (isPerspective) {
tmp1.setMul(mat[SkMatrix::kMScaleX], fracmuladdmul(mat[SkMatrix::kMScaleY], mat[SkMatrix::kMPersp2], -mat[SkMatrix::kMTransY], mat[SkMatrix::kMPersp1]));
tmp2.setMul(mat[SkMatrix::kMSkewX], fracmuladdmul(mat[SkMatrix::kMTransY], mat[SkMatrix::kMPersp0], -mat[SkMatrix::kMSkewY], mat[SkMatrix::kMPersp2]));
tmp1.add(tmp2);
tmp2.setMul(mat[SkMatrix::kMTransX], fracmuladdmul(mat[SkMatrix::kMSkewY], mat[SkMatrix::kMPersp1], -mat[SkMatrix::kMScaleY], mat[SkMatrix::kMPersp0]));
tmp1.add(tmp2);
} else {
tmp1.setMul(mat[SkMatrix::kMScaleX], mat[SkMatrix::kMScaleY]);
tmp2.setMul(mat[SkMatrix::kMSkewX], mat[SkMatrix::kMSkewY]);
tmp1.sub(tmp2);
}
int s = tmp1.getClzAbs();
*shift = s;
SkFixed denom;
if (s <= 32) {
denom = tmp1.getShiftRight(33 - s);
} else {
denom = (int32_t)tmp1.fLo << (s - 33);
}
if (denom == 0) {
return 0;
}
/** This could perhaps be a special fractdiv function, since both of its
arguments are known to have bit 31 clear and bit 30 set (when they
are made positive), thus eliminating the need for calling clz()
*/
return SkFractDiv(SK_Fract1, denom);
}
#endif
void SkMatrix::SetAffineIdentity(SkScalar affine[6]) {
affine[kAScaleX] = SK_Scalar1;
@ -1955,14 +1842,8 @@ void SkMatrix::dump() const {
void SkMatrix::toString(SkString* str) const {
str->appendf("[%8.4f %8.4f %8.4f][%8.4f %8.4f %8.4f][%8.4f %8.4f %8.4f]",
#ifdef SK_SCALAR_IS_FLOAT
fMat[0], fMat[1], fMat[2], fMat[3], fMat[4], fMat[5],
fMat[6], fMat[7], fMat[8]);
#else
SkFixedToFloat(fMat[0]), SkFixedToFloat(fMat[1]), SkFixedToFloat(fMat[2]),
SkFixedToFloat(fMat[3]), SkFixedToFloat(fMat[4]), SkFixedToFloat(fMat[5]),
SkFractToFloat(fMat[6]), SkFractToFloat(fMat[7]), SkFractToFloat(fMat[8]));
#endif
}
#endif

View File

@ -1010,16 +1010,9 @@ static void set_bounds(const SkGlyph& g, SkRect* bounds) {
// we don't overflow along the way
typedef int64_t Sk48Dot16;
#ifdef SK_SCALAR_IS_FLOAT
static inline float Sk48Dot16ToScalar(Sk48Dot16 x) {
return (float) (x * 1.5258789e-5); // x * (1 / 65536.0f)
}
#else
static inline SkFixed Sk48Dot16ToScalar(Sk48Dot16 x) {
// just return the low 32bits
return static_cast<SkFixed>(x);
}
#endif
static void join_bounds_x(const SkGlyph& g, SkRect* bounds, Sk48Dot16 dx) {
SkScalar sx = Sk48Dot16ToScalar(dx);
@ -1556,13 +1549,8 @@ static bool tooBigForLCD(const SkScalerContext::Rec& rec) {
* typically returns the same looking resuts for tiny changes in the matrix.
*/
static SkScalar sk_relax(SkScalar x) {
#ifdef SK_SCALAR_IS_FLOAT
int n = sk_float_round2int(x * 1024);
return n / 1024.0f;
#else
// round to the nearest 10 fractional bits
return (x + (1 << 5)) & ~(1024 - 1);
#endif
}
void SkScalerContext::MakeRec(const SkPaint& paint,

View File

@ -23,12 +23,7 @@ enum {
static inline SkScalar tValue2Scalar(int t) {
SkASSERT((unsigned)t <= kMaxTValue);
#ifdef SK_SCALAR_IS_FLOAT
return t * 3.05185e-5f; // t / 32767
#else
return (t + (t >> 14)) << 1;
#endif
}
SkScalar SkPathMeasure::Segment::getScalarT() const {

View File

@ -338,9 +338,9 @@ void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const {
info.fWidth = fWidth;
info.fHeight = fHeight;
info.fFlags = SkPictInfo::kCrossProcess_Flag;
#ifdef SK_SCALAR_IS_FLOAT
// TODO: remove this flag, since we're always float (now)
info.fFlags |= SkPictInfo::kScalarIsFloat_Flag;
#endif
if (8 == sizeof(void*)) {
info.fFlags |= SkPictInfo::kPtrIs64Bit_Flag;
}

View File

@ -55,21 +55,6 @@ void SkRect::toQuad(SkPoint quad[4]) const {
quad[3].set(fLeft, fBottom);
}
#ifdef SK_SCALAR_IS_FLOAT
#define SkFLOATCODE(code) code
#else
#define SkFLOATCODE(code)
#endif
// For float compares (at least on x86, by removing the else from the min/max
// computation, we get MAXSS and MINSS instructions, and no branches.
// Fixed point has no such opportunity (afaik), so we leave the else in that case
#ifdef SK_SCALAR_IS_FLOAT
#define MINMAX_ELSE
#else
#define MINMAX_ELSE else
#endif
bool SkRect::setBoundsCheck(const SkPoint pts[], int count) {
SkASSERT((pts && count > 0) || count == 0);
@ -85,17 +70,22 @@ bool SkRect::setBoundsCheck(const SkPoint pts[], int count) {
// If all of the points are finite, accum should stay 0. If we encounter
// a NaN or infinity, then accum should become NaN.
SkFLOATCODE(float accum = 0;)
SkFLOATCODE(accum *= l; accum *= t;)
float accum = 0;
accum *= l; accum *= t;
for (int i = 1; i < count; i++) {
SkScalar x = pts[i].fX;
SkScalar y = pts[i].fY;
SkFLOATCODE(accum *= x; accum *= y;)
accum *= x; accum *= y;
if (x < l) l = x; MINMAX_ELSE if (x > r) r = x;
if (y < t) t = y; MINMAX_ELSE if (y > b) b = y;
// we use if instead of if/else, so we can generate min/max
// float instructions (at least on SSE)
if (x < l) l = x;
if (x > r) r = x;
if (y < t) t = y;
if (y > b) b = y;
}
SkASSERT(!accum || !SkScalarIsFinite(accum));

View File

@ -53,8 +53,6 @@ void SkScan::FillXRect(const SkXRect& xr, const SkRegion* clip,
SkScan::FillIRect(r, clip, blitter);
}
#ifdef SK_SCALAR_IS_FLOAT
void SkScan::FillRect(const SkRect& r, const SkRegion* clip,
SkBlitter* blitter) {
SkIRect ir;
@ -63,8 +61,6 @@ void SkScan::FillRect(const SkRect& r, const SkRegion* clip,
SkScan::FillIRect(ir, clip, blitter);
}
#endif
///////////////////////////////////////////////////////////////////////////////
void SkScan::FillIRect(const SkIRect& r, const SkRasterClip& clip,
@ -97,8 +93,6 @@ void SkScan::FillXRect(const SkXRect& xr, const SkRasterClip& clip,
FillXRect(xr, &wrapper.getRgn(), wrapper.getBlitter());
}
#ifdef SK_SCALAR_IS_FLOAT
void SkScan::FillRect(const SkRect& r, const SkRasterClip& clip,
SkBlitter* blitter) {
if (clip.isEmpty() || r.isEmpty()) {
@ -113,5 +107,3 @@ void SkScan::FillRect(const SkRect& r, const SkRasterClip& clip,
SkAAClipBlitterWrapper wrapper(clip, blitter);
FillRect(r, &wrapper.getRgn(), wrapper.getBlitter());
}
#endif

View File

@ -31,19 +31,8 @@ public:
static void FillIRect(const SkIRect&, const SkRasterClip&, SkBlitter*);
static void FillXRect(const SkXRect&, const SkRasterClip&, SkBlitter*);
#ifdef SK_SCALAR_IS_FIXED
static void FillRect(const SkRect& rect, const SkRasterClip& clip,
SkBlitter* blitter) {
SkScan::FillXRect(*(const SkXRect*)&rect, clip, blitter);
}
static void AntiFillRect(const SkRect& rect, const SkRasterClip& clip,
SkBlitter* blitter) {
SkScan::AntiFillXRect(*(const SkXRect*)&rect, clip, blitter);
}
#else
static void FillRect(const SkRect&, const SkRasterClip&, SkBlitter*);
static void AntiFillRect(const SkRect&, const SkRasterClip&, SkBlitter*);
#endif
static void AntiFillXRect(const SkXRect&, const SkRasterClip&, SkBlitter*);
static void FillPath(const SkPath&, const SkRasterClip&, SkBlitter*);
static void AntiFillPath(const SkPath&, const SkRasterClip&, SkBlitter*);
@ -67,19 +56,8 @@ private:
static void FillIRect(const SkIRect&, const SkRegion* clip, SkBlitter*);
static void FillXRect(const SkXRect&, const SkRegion* clip, SkBlitter*);
#ifdef SK_SCALAR_IS_FIXED
static void FillRect(const SkRect& rect, const SkRegion* clip,
SkBlitter* blitter) {
SkScan::FillXRect(*(const SkXRect*)&rect, clip, blitter);
}
static void AntiFillRect(const SkRect& rect, const SkRegion* clip,
SkBlitter* blitter) {
SkScan::AntiFillXRect(*(const SkXRect*)&rect, clip, blitter);
}
#else
static void FillRect(const SkRect&, const SkRegion* clip, SkBlitter*);
static void AntiFillRect(const SkRect&, const SkRegion* clip, SkBlitter*);
#endif
static void AntiFillXRect(const SkXRect&, const SkRegion*, SkBlitter*);
static void FillPath(const SkPath&, const SkRegion& clip, SkBlitter*);
static void AntiFillPath(const SkPath&, const SkRegion& clip, SkBlitter*,

View File

@ -589,13 +589,8 @@ static int rect_overflows_short_shift(SkIRect rect, int shift) {
}
static bool safeRoundOut(const SkRect& src, SkIRect* dst, int32_t maxInt) {
#ifdef SK_SCALAR_IS_FIXED
// the max-int (shifted) is exactly what we want to compare against, to know
// if we can survive shifting our fixed-point coordinates
const SkFixed maxScalar = maxInt;
#else
const SkScalar maxScalar = SkIntToScalar(maxInt);
#endif
if (fitsInsideLimit(src, maxScalar)) {
src.roundOut(dst);
return true;

View File

@ -602,7 +602,6 @@ void SkScan::AntiHairLineRgn(const SkPoint& pt0, const SkPoint& pt1,
SkPoint pts[2] = { pt0, pt1 };
#ifdef SK_SCALAR_IS_FLOAT
// We have to pre-clip the line to fit in a SkFixed, so we just chop
// the line. TODO find a way to actually draw beyond that range.
{
@ -613,7 +612,6 @@ void SkScan::AntiHairLineRgn(const SkPoint& pt0, const SkPoint& pt1,
return;
}
}
#endif
if (clip) {
SkRect clipBounds;
@ -828,8 +826,6 @@ void SkScan::AntiFillXRect(const SkXRect& xr, const SkRasterClip& clip,
}
}
#ifdef SK_SCALAR_IS_FLOAT
/* This guy takes a float-rect, but with the key improvement that it has
already been clipped, so we know that it is safe to convert it into a
XRect (fixedpoint), as it won't overflow.
@ -888,8 +884,6 @@ void SkScan::AntiFillRect(const SkRect& r, const SkRasterClip& clip,
}
}
#endif // SK_SCALAR_IS_FLOAT
///////////////////////////////////////////////////////////////////////////////
#define SkAlphaMulRound(a, b) SkMulDiv255Round(a, b)
@ -902,11 +896,7 @@ static void fillcheckrect(int L, int T, int R, int B, SkBlitter* blitter) {
}
static inline FDot8 SkScalarToFDot8(SkScalar x) {
#ifdef SK_SCALAR_IS_FLOAT
return (int)(x * 256);
#else
return x >> 8;
#endif
}
static inline int FDot8Floor(FDot8 x) {

View File

@ -47,7 +47,6 @@ void SkScan::HairLineRgn(const SkPoint& pt0, const SkPoint& pt1,
SkIRect clipR, ptsR;
SkPoint pts[2] = { pt0, pt1 };
#ifdef SK_SCALAR_IS_FLOAT
// We have to pre-clip the line to fit in a SkFixed, so we just chop
// the line. TODO find a way to actually draw beyond that range.
{
@ -58,7 +57,6 @@ void SkScan::HairLineRgn(const SkPoint& pt0, const SkPoint& pt1,
return;
}
}
#endif
if (clip) {
// Perform a clip in scalar space, so we catch huge values which might

View File

@ -153,11 +153,7 @@ static void RoundJoiner(SkPath* outer, SkPath* inner, const SkVector& beforeUnit
}
}
#ifdef SK_SCALAR_IS_FLOAT
#define kOneOverSqrt2 (0.707106781f)
#else
#define kOneOverSqrt2 (46341)
#endif
static void MiterJoiner(SkPath* outer, SkPath* inner, const SkVector& beforeUnitNormal,
const SkPoint& pivot, const SkVector& afterUnitNormal,

View File

@ -184,25 +184,12 @@ void SkArithmeticMode_scalar::toString(SkString* str) const {
///////////////////////////////////////////////////////////////////////////////
static bool fitsInBits(SkScalar x, int bits) {
#ifdef SK_SCALAR_IS_FIXED
x = SkAbs32(x);
x += 1 << 7;
x >>= 8;
return x < (1 << (bits - 1));
#else
return SkScalarAbs(x) < (1 << (bits - 1));
#endif
}
#if 0 // UNUSED
static int32_t toDot8(SkScalar x) {
#ifdef SK_SCALAR_IS_FIXED
x += 1 << 7;
x >>= 8;
return x;
#else
return (int32_t)(x * 256);
#endif
}
#endif

View File

@ -52,178 +52,7 @@ void SkSweepGradient::flatten(SkFlattenableWriteBuffer& buffer) const {
buffer.writePoint(fCenter);
}
#ifndef SK_SCALAR_IS_FLOAT
#ifdef COMPUTE_SWEEP_TABLE
#define PI 3.14159265
static bool gSweepTableReady;
static uint8_t gSweepTable[65];
/* Our table stores precomputed values for atan: [0...1] -> [0..PI/4]
We scale the results to [0..32]
*/
static const uint8_t* build_sweep_table() {
if (!gSweepTableReady) {
const int N = 65;
const double DENOM = N - 1;
for (int i = 0; i < N; i++)
{
double arg = i / DENOM;
double v = atan(arg);
int iv = (int)round(v * DENOM * 2 / PI);
// printf("[%d] atan(%g) = %g %d\n", i, arg, v, iv);
printf("%d, ", iv);
gSweepTable[i] = iv;
}
gSweepTableReady = true;
}
return gSweepTable;
}
#else
static const uint8_t gSweepTable[] = {
0, 1, 1, 2, 3, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 9,
10, 11, 11, 12, 12, 13, 13, 14, 15, 15, 16, 16, 17, 17, 18, 18,
19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 25, 26,
26, 27, 27, 27, 28, 28, 29, 29, 29, 30, 30, 30, 31, 31, 31, 32,
32
};
static const uint8_t* build_sweep_table() { return gSweepTable; }
#endif
#endif
// divide numer/denom, with a bias of 6bits. Assumes numer <= denom
// and denom != 0. Since our table is 6bits big (+1), this is a nice fit.
// Same as (but faster than) SkFixedDiv(numer, denom) >> 10
//unsigned div_64(int numer, int denom);
#ifndef SK_SCALAR_IS_FLOAT
static unsigned div_64(int numer, int denom) {
SkASSERT(numer <= denom);
SkASSERT(numer > 0);
SkASSERT(denom > 0);
int nbits = SkCLZ(numer);
int dbits = SkCLZ(denom);
int bits = 6 - nbits + dbits;
SkASSERT(bits <= 6);
if (bits < 0) { // detect underflow
return 0;
}
denom <<= dbits - 1;
numer <<= nbits - 1;
unsigned result = 0;
// do the first one
if ((numer -= denom) >= 0) {
result = 1;
} else {
numer += denom;
}
// Now fall into our switch statement if there are more bits to compute
if (bits > 0) {
// make room for the rest of the answer bits
result <<= bits;
switch (bits) {
case 6:
if ((numer = (numer << 1) - denom) >= 0)
result |= 32;
else
numer += denom;
case 5:
if ((numer = (numer << 1) - denom) >= 0)
result |= 16;
else
numer += denom;
case 4:
if ((numer = (numer << 1) - denom) >= 0)
result |= 8;
else
numer += denom;
case 3:
if ((numer = (numer << 1) - denom) >= 0)
result |= 4;
else
numer += denom;
case 2:
if ((numer = (numer << 1) - denom) >= 0)
result |= 2;
else
numer += denom;
case 1:
default: // not strictly need, but makes GCC make better ARM code
if ((numer = (numer << 1) - denom) >= 0)
result |= 1;
else
numer += denom;
}
}
return result;
}
#endif
// Given x,y in the first quadrant, return 0..63 for the angle [0..90]
#ifndef SK_SCALAR_IS_FLOAT
static unsigned atan_0_90(SkFixed y, SkFixed x) {
#ifdef SK_DEBUG
{
static bool gOnce;
if (!gOnce) {
gOnce = true;
SkASSERT(div_64(55, 55) == 64);
SkASSERT(div_64(128, 256) == 32);
SkASSERT(div_64(2326528, 4685824) == 31);
SkASSERT(div_64(753664, 5210112) == 9);
SkASSERT(div_64(229376, 4882432) == 3);
SkASSERT(div_64(2, 64) == 2);
SkASSERT(div_64(1, 64) == 1);
// test that we handle underflow correctly
SkASSERT(div_64(12345, 0x54321234) == 0);
}
}
#endif
SkASSERT(y > 0 && x > 0);
const uint8_t* table = build_sweep_table();
unsigned result;
bool swap = (x < y);
if (swap) {
// first part of the atan(v) = PI/2 - atan(1/v) identity
// since our div_64 and table want v <= 1, where v = y/x
SkTSwap<SkFixed>(x, y);
}
result = div_64(y, x);
#ifdef SK_DEBUG
{
unsigned result2 = SkDivBits(y, x, 6);
SkASSERT(result2 == result ||
(result == 1 && result2 == 0));
}
#endif
SkASSERT(result < SK_ARRAY_COUNT(gSweepTable));
result = table[result];
if (swap) {
// complete the atan(v) = PI/2 - atan(1/v) identity
result = 64 - result;
// pin to 63
result -= result >> 6;
}
SkASSERT(result <= 63);
return result;
}
#endif
// returns angle in a circle [0..2PI) -> [0..255]
#ifdef SK_SCALAR_IS_FLOAT
static unsigned SkATan2_255(float y, float x) {
// static const float g255Over2PI = 255 / (2 * SK_ScalarPI);
static const float g255Over2PI = 40.584510488433314f;
@ -239,62 +68,6 @@ static unsigned SkATan2_255(float y, float x) {
SkASSERT(ir >= 0 && ir <= 255);
return ir;
}
#else
static unsigned SkATan2_255(SkFixed y, SkFixed x) {
if (x == 0) {
if (y == 0) {
return 0;
}
return y < 0 ? 192 : 64;
}
if (y == 0) {
return x < 0 ? 128 : 0;
}
/* Find the right quadrant for x,y
Since atan_0_90 only handles the first quadrant, we rotate x,y
appropriately before calling it, and then add the right amount
to account for the real quadrant.
quadrant 0 : add 0 | x > 0 && y > 0
quadrant 1 : add 64 (90 degrees) | x < 0 && y > 0
quadrant 2 : add 128 (180 degrees) | x < 0 && y < 0
quadrant 3 : add 192 (270 degrees) | x > 0 && y < 0
map x<0 to (1 << 6)
map y<0 to (3 << 6)
add = map_x ^ map_y
*/
int xsign = x >> 31;
int ysign = y >> 31;
int add = ((-xsign) ^ (ysign & 3)) << 6;
#ifdef SK_DEBUG
if (0 == add)
SkASSERT(x > 0 && y > 0);
else if (64 == add)
SkASSERT(x < 0 && y > 0);
else if (128 == add)
SkASSERT(x < 0 && y < 0);
else if (192 == add)
SkASSERT(x > 0 && y < 0);
else
SkDEBUGFAIL("bad value for add");
#endif
/* This ^ trick makes x, y positive, and the swap<> handles quadrants
where we need to rotate x,y by 90 or -90
*/
x = (x ^ xsign) - xsign;
y = (y ^ ysign) - ysign;
if (add & 64) { // quads 1 or 3 need to swap x,y
SkTSwap<SkFixed>(x, y);
}
unsigned result = add + atan_0_90(y, x);
SkASSERT(result < 256);
return result;
}
#endif
void SkSweepGradient::shadeSpan(int x, int y, SkPMColor* SK_RESTRICT dstC,
int count) {

View File

@ -300,19 +300,10 @@ int num_quad_subdivs(const SkPoint p[3]) {
// = log4(d*d/tol*tol)/2
// = log2(d*d/tol*tol)
#ifdef SK_SCALAR_IS_FLOAT
// +1 since we're ignoring the mantissa contribution.
int log = get_float_exp(dsqd/(gSubdivTol*gSubdivTol)) + 1;
log = GrMin(GrMax(0, log), kMaxSub);
return log;
#else
SkScalar log = SkScalarLog(
SkScalarDiv(dsqd,
SkScalarMul(gSubdivTol, gSubdivTol)));
static const SkScalar conv = SkScalarInvert(SkScalarLog(2));
log = SkScalarMul(log, conv);
return GrMin(GrMax(0, SkScalarCeilToInt(log)),kMaxSub);
#endif
}
}

View File

@ -187,9 +187,6 @@ int GrPathUtils::worstCasePointCount(const SkPath& path, int* subpaths,
}
void GrPathUtils::QuadUVMatrix::set(const GrPoint qPts[3]) {
#ifndef SK_SCALAR_IS_FLOAT
GrCrash("Expected scalar is float.");
#endif
SkMatrix m;
// We want M such that M * xy_pt = uv_pt
// We know M * control_pts = [0 1/2 1]

View File

@ -87,9 +87,6 @@ static const bool kIsWrapped = false; // The constructor creates the GL path obj
GrGLPath::GrGLPath(GrGpuGL* gpu, const SkPath& path, const SkStrokeRec& stroke)
: INHERITED(gpu, kIsWrapped, path, stroke) {
#ifndef SK_SCALAR_IS_FLOAT
GrCrash("Assumes scalar is float.");
#endif
SkASSERT(!path.isEmpty());
GL_CALL_RET(fPathID, GenPaths(1));

View File

@ -233,7 +233,6 @@ void GrGLUniformManager::setMatrix4fv(UniformHandle u,
}
void GrGLUniformManager::setSkMatrix(UniformHandle u, const SkMatrix& matrix) const {
// GR_STATIC_ASSERT(SK_SCALAR_IS_FLOAT);
GrGLfloat mt[] = {
matrix.get(SkMatrix::kMScaleX),
matrix.get(SkMatrix::kMSkewY),

View File

@ -140,12 +140,6 @@ void SkPDFScalar::Append(SkScalar value, SkWStream* stream) {
// When using floats that are outside the whole value range, we can use
// integers instead.
#if defined(SK_SCALAR_IS_FIXED)
stream->writeScalarAsText(value);
return;
#endif // SK_SCALAR_IS_FIXED
#if !defined(SK_ALLOW_LARGE_PDF_SCALARS)
if (value > 32767 || value < -32767) {
stream->writeDecAsText(SkScalarRound(value));
@ -158,7 +152,7 @@ void SkPDFScalar::Append(SkScalar value, SkWStream* stream) {
return;
#endif // !SK_ALLOW_LARGE_PDF_SCALARS
#if defined(SK_SCALAR_IS_FLOAT) && defined(SK_ALLOW_LARGE_PDF_SCALARS)
#if defined(SK_ALLOW_LARGE_PDF_SCALARS)
// Floats have 24bits of significance, so anything outside that range is
// no more precise than an int. (Plus PDF doesn't support scientific
// notation, so this clamps to SK_Max/MinS32).
@ -185,7 +179,7 @@ void SkPDFScalar::Append(SkScalar value, SkWStream* stream) {
}
stream->writeText(buffer);
return;
#endif // SK_SCALAR_IS_FLOAT && SK_ALLOW_LARGE_PDF_SCALARS
#endif // SK_ALLOW_LARGE_PDF_SCALARS
}
SkPDFString::SkPDFString(const char value[])

View File

@ -14,12 +14,7 @@
// HB_Fixed is a 26.6 fixed point format.
static inline HB_Fixed SkScalarToHarfbuzzFixed(SkScalar value) {
#ifdef SK_SCALAR_IS_FLOAT
return static_cast<HB_Fixed>(value * 64);
#else
// convert .16 to .6
return value >> (16 - 6);
#endif
}
static HB_Bool stringToGlyphs(HB_Font hbFont, const HB_UChar16* characters,

View File

@ -12,7 +12,6 @@
static SkScalar SkScalarDotDiv(int count, const SkScalar a[], int step_a,
const SkScalar b[], int step_b,
SkScalar denom) {
#ifdef SK_SCALAR_IS_FLOAT
float prod = 0;
for (int i = 0; i < count; i++) {
prod += a[0] * b[0];
@ -20,24 +19,10 @@ static SkScalar SkScalarDotDiv(int count, const SkScalar a[], int step_a,
b += step_b;
}
return prod / denom;
#else
Sk64 prod, tmp;
prod.set(0);
for (int i = 0; i < count; i++) {
tmp.setMul(a[0], b[0]);
prod.add(tmp);
a += step_a;
b += step_b;
}
prod.div(denom, Sk64::kRound_DivOption);
return prod.get32();
#endif
}
static SkScalar SkScalarDot(int count, const SkScalar a[], int step_a,
const SkScalar b[], int step_b) {
#ifdef SK_SCALAR_IS_FLOAT
float prod = 0;
for (int i = 0; i < count; i++) {
prod += a[0] * b[0];
@ -45,24 +30,11 @@ static SkScalar SkScalarDot(int count, const SkScalar a[], int step_a,
b += step_b;
}
return prod;
#else
Sk64 prod, tmp;
prod.set(0);
for (int i = 0; i < count; i++) {
tmp.setMul(a[0], b[0]);
prod.add(tmp);
a += step_a;
b += step_b;
}
return prod.getFixed();
#endif
}
///////////////////////////////////////////////////////////////////////////////
SkUnitScalar SkPoint3D::normalize(SkUnit3D* unit) const {
#ifdef SK_SCALAR_IS_FLOAT
float mag = sk_float_sqrt(fX*fX + fY*fY + fZ*fZ);
if (mag) {
float scale = 1.0f / mag;
@ -72,26 +44,6 @@ SkUnitScalar SkPoint3D::normalize(SkUnit3D* unit) const {
} else {
unit->fX = unit->fY = unit->fZ = 0;
}
#else
Sk64 tmp1, tmp2;
tmp1.setMul(fX, fX);
tmp2.setMul(fY, fY);
tmp1.add(tmp2);
tmp2.setMul(fZ, fZ);
tmp1.add(tmp2);
SkFixed mag = tmp1.getSqrt();
if (mag) {
// what if mag < SK_Fixed1 ??? we will underflow the fixdiv
SkFixed scale = SkFixedDiv(SK_Fract1, mag);
unit->fX = SkFixedMul(fX, scale);
unit->fY = SkFixedMul(fY, scale);
unit->fZ = SkFixedMul(fZ, scale);
} else {
unit->fX = unit->fY = unit->fZ = 0;
}
#endif
return mag;
}

View File

@ -155,11 +155,7 @@ void SkInterpolator::reset(int elemCount, int frameCount) {
#define SK_Fixed2Third (SK_Fixed1*2/3)
static const SkScalar gIdentityBlend[4] = {
#ifdef SK_SCALAR_IS_FLOAT
0.33333333f, 0.33333333f, 0.66666667f, 0.66666667f
#else
SK_Fixed1Third, SK_Fixed1Third, SK_Fixed2Third, SK_Fixed2Third
#endif
};
bool SkInterpolator::setKeyFrame(int index, SkMSec time,

View File

@ -201,7 +201,7 @@ const char* SkParse::FindMSec(const char str[], SkMSec* value)
const char* SkParse::FindScalar(const char str[], SkScalar* value) {
SkASSERT(str);
str = skip_ws(str);
#ifdef SK_SCALAR_IS_FLOAT
char* stop;
float v = (float)strtod(str, &stop);
if (str == stop) {
@ -211,49 +211,6 @@ const char* SkParse::FindScalar(const char str[], SkScalar* value) {
*value = v;
}
return stop;
#else
int sign = 0;
if (*str == '-')
{
sign = -1;
str += 1;
}
if (!is_digit(*str) && *str != '.')
return NULL;
int n = 0;
while (is_digit(*str))
{
n = 10*n + *str - '0';
if (n > 0x7FFF)
return NULL;
str += 1;
}
n <<= 16;
if (*str == '.')
{
static const int gFractions[] = { (1 << 24) / 10, (1 << 24) / 100, (1 << 24) / 1000,
(1 << 24) / 10000, (1 << 24) / 100000 };
str += 1;
int d = 0;
const int* fraction = gFractions;
const int* end = &fraction[SK_ARRAY_COUNT(gFractions)];
while (is_digit(*str) && fraction < end)
d += (*str++ - '0') * *fraction++;
d += 0x80; // round
n += d >> 8;
}
while (is_digit(*str))
str += 1;
if (value)
{
n = (n ^ sign) - sign; // apply the sign
*value = SkFixedToScalar(n);
}
#endif
return str;
}
const char* SkParse::FindScalars(const char str[], SkScalar value[], int count)

View File

@ -188,7 +188,6 @@ bool SkParsePath::FromSVGString(const char data[], SkPath* result) {
#include "SkStream.h"
static void write_scalar(SkWStream* stream, SkScalar value) {
#ifdef SK_SCALAR_IS_FLOAT
char buffer[64];
#ifdef SK_BUILD_FOR_WIN32
int len = _snprintf(buffer, sizeof(buffer), "%g", value);
@ -196,10 +195,6 @@ static void write_scalar(SkWStream* stream, SkScalar value) {
int len = snprintf(buffer, sizeof(buffer), "%g", value);
#endif
char* stop = buffer + len;
#else
char buffer[SkStrAppendScalar_MaxSize];
char* stop = SkStrAppendScalar(buffer, value);
#endif
stream->write(buffer, stop - buffer);
}

View File

@ -277,11 +277,7 @@ JSBool SkJSDisplayable::GetProperty(JSContext *cx, JSObject *obj, jsval id,
if (SkScalarFraction(scalar) == 0)
*vp = INT_TO_JSVAL(SkScalarFloor(scalar));
else
#ifdef SK_SCALAR_IS_FLOAT
*vp = DOUBLE_TO_JSVAL(scalar);
#else
*vp = DOUBLE_TO_JSVAL(scalar / 65536.0f );
#endif
break;
case SkType_String:
str = JS_NewStringCopyN(cx, string->c_str(), string->size());
@ -323,11 +319,7 @@ JSBool SkJSDisplayable::SetProperty(JSContext *cx, JSObject *obj, jsval id, jsva
scalar = SkIntToScalar(JSVAL_TO_INT(value));
else {
SkASSERT(JSVAL_IS_DOUBLE(value));
#ifdef SK_SCALAR_IS_FLOAT
scalar = (float) *(double*) JSVAL_TO_DOUBLE(value);
#else
scalar = (SkFixed) (*(double*)JSVAL_TO_DOUBLE(value) * 65536.0);
#endif
}
break;
case SkType_String:

View File

@ -309,9 +309,7 @@ void SkXMLStreamWriter::UnitTest()
w.addAttribute("hello", "world");
w.addS32Attribute("dec", 42);
w.addHexAttribute("hex", 0x42, 3);
#ifdef SK_SCALAR_IS_FLOAT
w.addScalarAttribute("scalar", -4.2f);
#endif
w.startElement("elem1");
w.endElement();
w.startElement("elem1");

View File

@ -241,7 +241,6 @@ static void test_wacky_bitmapshader(skiatest::Reporter* reporter,
* memory allocation limit).
*/
static void test_giantrepeat_crbug118018(skiatest::Reporter* reporter) {
#ifdef SK_SCALAR_IS_FLOAT
static const struct {
int fWidth;
int fHeight;
@ -258,7 +257,6 @@ static void test_giantrepeat_crbug118018(skiatest::Reporter* reporter) {
gTests[i].fWidth, gTests[i].fHeight,
gTests[i].fExpectedToDraw);
}
#endif
}
///////////////////////////////////////////////////////////////////////////////

View File

@ -181,7 +181,6 @@ static void test_inversepathwithclip() {
}
static void test_bug533() {
#ifdef SK_SCALAR_IS_FLOAT
/*
http://code.google.com/p/skia/issues/detail?id=533
This particular test/bug only applies to the float case, where the
@ -196,7 +195,6 @@ static void test_bug533() {
SkAutoTUnref<SkCanvas> canvas(new_canvas(640, 480));
canvas.get()->drawPath(path, paint);
#endif
}
static void test_crbug_140642() {
@ -215,14 +213,11 @@ static void test_crbug_140642() {
stroke-dashoffset="-248.135982067">
*/
#ifdef SK_SCALAR_IS_FLOAT
const SkScalar vals[] = { 27734, 35660, 2157846850.0f, 247 };
SkDashPathEffect dontAssert(vals, 4, -248.135982067f);
#endif
}
static void test_crbug_124652() {
#ifdef SK_SCALAR_IS_FLOAT
/*
http://code.google.com/p/chromium/issues/detail?id=124652
This particular test/bug only applies to the float case, where
@ -231,11 +226,9 @@ static void test_crbug_124652() {
SkScalar intervals[2] = {837099584, 33450};
SkAutoTUnref<SkDashPathEffect> dash(
new SkDashPathEffect(intervals, 2, -10, false));
#endif
}
static void test_bigcubic() {
#ifdef SK_SCALAR_IS_FLOAT
SkPath path;
path.moveTo(64, 3);
path.cubicTo(-329936, -100000000, -329936, 100000000, 1153, 330003);
@ -245,7 +238,6 @@ static void test_bigcubic() {
SkAutoTUnref<SkCanvas> canvas(new_canvas(640, 480));
canvas.get()->drawPath(path, paint);
#endif
}
// we used to assert if the bounds of the device (clip) was larger than 32K

View File

@ -10,11 +10,9 @@
#include "SkRandom.h"
#include "SkRect.h"
#ifdef SK_SCALAR_IS_FLOAT
static float make_zero() {
return sk_float_sin(0);
}
#endif
struct RectCenter {
SkIRect fRect;
@ -59,14 +57,9 @@ static void check_invalid(skiatest::Reporter* reporter,
// Tests that isFinite() will reject any rect with +/-inf values
// as one of its coordinates.
DEF_TEST(InfRect, reporter) {
#ifdef SK_SCALAR_IS_FLOAT
float inf = 1 / make_zero(); // infinity
float nan = inf * 0;
SkASSERT(!(nan == nan));
#else
SkFixed inf = SK_FixedNaN;
SkFixed nan = SK_FixedNaN;
#endif
SkScalar small = SkIntToScalar(10);
SkScalar big = SkIntToScalar(100);

View File

@ -328,14 +328,11 @@ static void unittest_fastfloat(skiatest::Reporter* reporter) {
}
}
#ifdef SK_SCALAR_IS_FLOAT
static float make_zero() {
return sk_float_sin(0);
}
#endif
static void unittest_isfinite(skiatest::Reporter* reporter) {
#ifdef SK_SCALAR_IS_FLOAT
float nan = sk_float_asin(2);
float inf = 1.0f / make_zero();
float big = 3.40282e+038f;
@ -344,10 +341,6 @@ static void unittest_isfinite(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, !SkScalarIsNaN(-inf));
REPORTER_ASSERT(reporter, !SkScalarIsFinite(inf));
REPORTER_ASSERT(reporter, !SkScalarIsFinite(-inf));
#else
SkFixed nan = SK_FixedNaN;
SkFixed big = SK_FixedMax;
#endif
REPORTER_ASSERT(reporter, SkScalarIsNaN(nan));
REPORTER_ASSERT(reporter, !SkScalarIsNaN(big));
@ -607,37 +600,7 @@ DEF_TEST(Math, reporter) {
REPORTER_ASSERT(reporter, xr == check || xr == check-1);
}
#if !defined(SK_SCALAR_IS_FLOAT)
{
SkFixed s, c;
s = SkFixedSinCos(0, &c);
REPORTER_ASSERT(reporter, s == 0);
REPORTER_ASSERT(reporter, c == SK_Fixed1);
}
int maxDiff = 0;
for (i = 0; i < 1000; i++) {
SkFixed rads = rand.nextS() >> 10;
double frads = SkFixedToFloat(rads);
SkFixed s, c;
s = SkScalarSinCos(rads, &c);
double fs = sin(frads);
double fc = cos(frads);
SkFixed is = SkFloatToFixed(fs);
SkFixed ic = SkFloatToFixed(fc);
maxDiff = SkMax32(maxDiff, SkAbs32(is - s));
maxDiff = SkMax32(maxDiff, SkAbs32(ic - c));
}
SkDebugf("SinCos: maximum error = %d\n", maxDiff);
#endif
#ifdef SK_SCALAR_IS_FLOAT
test_blend(reporter);
#endif
if (false) test_floor(reporter);

View File

@ -24,14 +24,7 @@ static bool nearly_equal_mscalar(SkMScalar a, SkMScalar b) {
}
static bool nearly_equal_scalar(SkScalar a, SkScalar b) {
// Note that we get more compounded error for multiple operations when
// SK_SCALAR_IS_FIXED.
#ifdef SK_SCALAR_IS_FLOAT
const SkScalar tolerance = SK_Scalar1 / 200000;
#else
const SkScalar tolerance = SK_Scalar1 / 1024;
#endif
return SkScalarAbs(a - b) <= tolerance;
}

View File

@ -13,14 +13,7 @@
#include "SkRandom.h"
static bool nearly_equal_scalar(SkScalar a, SkScalar b) {
// Note that we get more compounded error for multiple operations when
// SK_SCALAR_IS_FIXED.
#ifdef SK_SCALAR_IS_FLOAT
const SkScalar tolerance = SK_Scalar1 / 200000;
#else
const SkScalar tolerance = SK_Scalar1 / 1024;
#endif
return SkScalarAbs(a - b) <= tolerance;
}
@ -40,7 +33,6 @@ static bool are_equal(skiatest::Reporter* reporter,
bool equal = a == b;
bool cheapEqual = a.cheapEqualTo(b);
if (equal != cheapEqual) {
#ifdef SK_SCALAR_IS_FLOAT
if (equal) {
bool foundZeroSignDiff = false;
for (int i = 0; i < 9; ++i) {
@ -70,9 +62,6 @@ static bool are_equal(skiatest::Reporter* reporter,
}
REPORTER_ASSERT(reporter, foundNaN);
}
#else
REPORTER_ASSERT(reporter, false);
#endif
}
return equal;
}
@ -299,16 +288,6 @@ static void test_matrix_is_similarity(skiatest::Reporter* reporter) {
mat.setPerspY(SkScalarToPersp(SK_Scalar1 / 2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
#ifdef SK_SCALAR_IS_FLOAT
/* We bypass the following tests for SK_SCALAR_IS_FIXED build.
* The long discussion can be found in this issue:
* http://codereview.appspot.com/5999050/
* In short, we haven't found a perfect way to fix the precision
* issue, i.e. the way we use tolerance in isSimilarityTransformation
* is incorrect. The situation becomes worse in fixed build, so
* we disabled rotation related tests for fixed build.
*/
// rotate
for (int angle = 0; angle < 360; ++angle) {
mat.reset();
@ -340,7 +319,6 @@ static void test_matrix_is_similarity(skiatest::Reporter* reporter) {
mat.setRotate(SkIntToScalar(30));
mat.postScale(SkIntToScalar(3), SkIntToScalar(2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
#endif
// all zero
mat.setAll(0, 0, 0, 0, 0, 0, 0, 0, 0);
@ -800,12 +778,7 @@ DEF_TEST(Matrix, reporter) {
mat.reset();
mat.set(SkMatrix::kMSkewX, SK_ScalarNaN);
mat2.set(SkMatrix::kMSkewX, SK_ScalarNaN);
// fixed pt doesn't have the property that NaN does not equal itself.
#ifdef SK_SCALAR_IS_FIXED
REPORTER_ASSERT(reporter, are_equal(reporter, mat, mat2));
#else
REPORTER_ASSERT(reporter, !are_equal(reporter, mat, mat2));
#endif
test_matrix_min_max_stretch(reporter);
test_matrix_is_similarity(reporter);

View File

@ -353,7 +353,6 @@ DEF_TEST(PDFPrimitives, reporter) {
SkAutoTUnref<SkPDFScalar> realHalf(new SkPDFScalar(SK_ScalarHalf));
SimpleCheckObjectOutput(reporter, realHalf.get(), "0.5");
#if defined(SK_SCALAR_IS_FLOAT)
SkAutoTUnref<SkPDFScalar> bigScalar(new SkPDFScalar(110999.75f));
#if !defined(SK_ALLOW_LARGE_PDF_SCALARS)
SimpleCheckObjectOutput(reporter, bigScalar.get(), "111000");
@ -365,7 +364,6 @@ DEF_TEST(PDFPrimitives, reporter) {
SkAutoTUnref<SkPDFScalar> smallestScalar(new SkPDFScalar(1.0/65536));
SimpleCheckObjectOutput(reporter, smallestScalar.get(), "0.00001526");
#endif
#endif
SkAutoTUnref<SkPDFString> stringSimple(

View File

@ -10,7 +10,6 @@
#include "SkPathMeasure.h"
static void test_small_segment3() {
#ifdef SK_SCALAR_IS_FLOAT
SkPath path;
const SkPoint pts[] = {
{ 0, 0 },
@ -25,11 +24,9 @@ static void test_small_segment3() {
SkPathMeasure meas(path, false);
meas.getLength();
#endif
}
static void test_small_segment2() {
#ifdef SK_SCALAR_IS_FLOAT
SkPath path;
const SkPoint pts[] = {
{ 0, 0 },
@ -43,11 +40,9 @@ static void test_small_segment2() {
}
SkPathMeasure meas(path, false);
meas.getLength();
#endif
}
static void test_small_segment() {
#ifdef SK_SCALAR_IS_FLOAT
SkPath path;
const SkPoint pts[] = {
{ 100000, 100000},
@ -77,7 +72,6 @@ static void test_small_segment() {
because distance >>> d.
*/
meas.getLength();
#endif
}
DEF_TEST(PathMeasure, reporter) {

View File

@ -830,7 +830,6 @@ static void test_direction(skiatest::Reporter* reporter) {
path.addCircle(0, 0, SkIntToScalar(2), SkPath::kCCW_Direction);
check_direction(reporter, path, SkPath::kCCW_Direction);
#ifdef SK_SCALAR_IS_FLOAT
// triangle with one point really far from the origin.
path.reset();
// the first point is roughly 1.05e10, 1.05e10
@ -838,7 +837,6 @@ static void test_direction(skiatest::Reporter* reporter) {
path.lineTo(110 * SK_Scalar1, -10 * SK_Scalar1);
path.lineTo(-10 * SK_Scalar1, 60 * SK_Scalar1);
check_direction(reporter, path, SkPath::kCCW_Direction);
#endif
path.reset();
path.conicTo(20, 0, 20, 20, 0.5f);

View File

@ -20,7 +20,6 @@ struct PointSet {
};
static void test_isRectFinite(skiatest::Reporter* reporter) {
#ifdef SK_SCALAR_IS_FLOAT
static const SkPoint gF0[] = {
{ 0, 0 }, { 1, 1 }
};
@ -61,7 +60,6 @@ static void test_isRectFinite(skiatest::Reporter* reporter) {
bool rectIsFinite = !r.isEmpty();
REPORTER_ASSERT(reporter, gSets[i].fIsFinite == rectIsFinite);
}
#endif
}
static bool isFinite_int(float x) {

View File

@ -157,14 +157,12 @@ DEF_TEST(String, reporter) {
{ SK_Scalar1, "1" },
{ -SK_Scalar1, "-1" },
{ SK_Scalar1/2, "0.5" },
#ifdef SK_SCALAR_IS_FLOAT
#ifdef SK_BUILD_FOR_WIN
{ 3.4028234e38f, "3.4028235e+038" },
{ -3.4028234e38f, "-3.4028235e+038" },
#else
{ 3.4028234e38f, "3.4028235e+38" },
{ -3.4028234e38f, "-3.4028235e+38" },
#endif
#endif
};
for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {

View File

@ -297,7 +297,7 @@ struct CanvasConfig {
static const CanvasConfig gCanvasConfigs[] = {
{kRaster_DevType, true},
{kRaster_DevType, false},
#if SK_SUPPORT_GPU && defined(SK_SCALAR_IS_FLOAT)
#if SK_SUPPORT_GPU
{kGpu_BottomLeft_DevType, true}, // row bytes has no meaning on gpu devices
{kGpu_TopLeft_DevType, true}, // row bytes has no meaning on gpu devices
#endif

View File

@ -195,11 +195,6 @@ int tool_main(int argc, char** argv) {
header.append(" SK_DEBUG");
#else
header.append(" SK_RELEASE");
#endif
#ifdef SK_SCALAR_IS_FIXED
header.append(" SK_SCALAR_IS_FIXED");
#else
header.append(" SK_SCALAR_IS_FLOAT");
#endif
header.appendf(" skia_arch_width=%d", (int)sizeof(void*) * 8);
SkDebugf("%s\n", header.c_str());