• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright 2006 The Android Open Source Project
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 
10 #ifndef SkFP_DEFINED
11 #define SkFP_DEFINED
12 
13 #include "SkMath.h"
14 
15 #ifdef SK_SCALAR_IS_FLOAT
16 
17     typedef float SkFP;
18 
19     #define SkScalarToFP(n)         (n)
20     #define SkFPToScalar(n)         (n)
21     #define SkIntToFP(n)            SkIntToScalar(n)
22     #define SkFPRound(x)            SkScalarRound(n)
23     #define SkFPCeil(x)             SkScalarCeil(n)
24     #define SkFPFloor(x)            SkScalarFloor(n)
25 
26     #define SkFPNeg(x)              (-(x))
27     #define SkFPAbs(x)              SkScalarAbs(x)
28     #define SkFPAdd(a, b)           ((a) + (b))
29     #define SkFPSub(a, b)           ((a) - (b))
30     #define SkFPMul(a, b)           ((a) * (b))
31     #define SkFPMulInt(a, n)        ((a) * (n))
32     #define SkFPDiv(a, b)           ((a) / (b))
33     #define SkFPDivInt(a, n)        ((a) / (n))
34     #define SkFPInvert(x)           SkScalarInvert(x)
35     #define SkFPSqrt(x)             SkScalarSqrt(x)
36     #define SkFPCubeRoot(x)         sk_float_pow(x, 0.3333333f)
37 
38     #define SkFPLT(a, b)            ((a) < (b))
39     #define SkFPLE(a, b)            ((a) <= (b))
40     #define SkFPGT(a, b)            ((a) > (b))
41     #define SkFPGE(a, b)            ((a) >= (b))
42 
43 #else   // scalar is fixed
44 
45     #include "SkFloat.h"
46 
47     typedef int32_t SkFP;
48 
49     #define SkScalarToFP(n)         SkFloat::SetShift(n, -16)
50     #define SkFPToScalar(n)         SkFloat::GetShift(n, -16)
51     #define SkIntToFP(n)            SkFloat::SetShift(n, 0)
52     #define SkFPRound(x)            SkFloat::Round(x);
53     #define SkFPCeil(x)             SkFloat::Ceil();
54     #define SkFPFloor(x)            SkFloat::Floor();
55 
56     #define SkFPNeg(x)              SkFloat::Neg(x)
57     #define SkFPAbs(x)              SkFloat::Abs(x)
58     #define SkFPAdd(a, b)           SkFloat::Add(a, b)
59     #define SkFPSub(a, b)           SkFloat::Add(a, SkFloat::Neg(b))
60     #define SkFPMul(a, b)           SkFloat::Mul(a, b)
61     #define SkFPMulInt(a, n)        SkFloat::MulInt(a, n)
62     #define SkFPDiv(a, b)           SkFloat::Div(a, b)
63     #define SkFPDivInt(a, n)        SkFloat::DivInt(a, n)
64     #define SkFPInvert(x)           SkFloat::Invert(x)
65     #define SkFPSqrt(x)             SkFloat::Sqrt(x)
66     #define SkFPCubeRoot(x)         SkFloat::CubeRoot(x)
67 
68     #define SkFPLT(a, b)            (SkFloat::Cmp(a, b) < 0)
69     #define SkFPLE(a, b)            (SkFloat::Cmp(a, b) <= 0)
70     #define SkFPGT(a, b)            (SkFloat::Cmp(a, b) > 0)
71     #define SkFPGE(a, b)            (SkFloat::Cmp(a, b) >= 0)
72 
73 #endif
74 
75 #ifdef SK_DEBUG
76     void SkFP_UnitTest();
77 #endif
78 
79 #endif
80