Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(479)

Side by Side Diff: include/core/SkFixed.h

Issue 113873008: remove unused SkFixed and SkFract functions (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #ifndef SkFixed_DEFINED 10 #ifndef SkFixed_DEFINED
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 SkASSERT(n64 == n32); 48 SkASSERT(n64 == n32);
49 return n32; 49 return n32;
50 } 50 }
51 #else 51 #else
52 #define SkFloatToFixed_Check(x) SkFloatToFixed(x) 52 #define SkFloatToFixed_Check(x) SkFloatToFixed(x)
53 #endif 53 #endif
54 54
55 #define SkFixedToDouble(x) ((x) * 1.5258789e-5) 55 #define SkFixedToDouble(x) ((x) * 1.5258789e-5)
56 #define SkDoubleToFixed(x) ((SkFixed)((x) * SK_Fixed1)) 56 #define SkDoubleToFixed(x) ((SkFixed)((x) * SK_Fixed1))
57 57
58 /** 32 bit signed integer used to represent fractions values with 30 bits to the right of the decimal point
59 */
60 typedef int32_t SkFract;
61 #define SK_Fract1 (1 << 30)
62 #define Sk_FracHalf (1 << 29)
63 #define SK_FractPIOver180 (0x11DF46A)
64
65 #define SkFractToFloat(x) ((float)(x) * 0.00000000093132257f)
66 #define SkFloatToFract(x) ((SkFract)((x) * SK_Fract1))
67
68 /** Converts an integer to a SkFixed, asserting that the result does not overflo w 58 /** Converts an integer to a SkFixed, asserting that the result does not overflo w
69 a 32 bit signed integer 59 a 32 bit signed integer
70 */ 60 */
71 #ifdef SK_DEBUG 61 #ifdef SK_DEBUG
72 inline SkFixed SkIntToFixed(int n) 62 inline SkFixed SkIntToFixed(int n)
73 { 63 {
74 SkASSERT(n >= -32768 && n <= 32767); 64 SkASSERT(n >= -32768 && n <= 32767);
75 return n << 16; 65 return n << 16;
76 } 66 }
77 #else 67 #else
78 // force the cast to SkFixed to ensure that the answer is signed (like the debug version) 68 // force the cast to SkFixed to ensure that the answer is signed (like the debug version)
79 #define SkIntToFixed(n) (SkFixed)((n) << 16) 69 #define SkIntToFixed(n) (SkFixed)((n) << 16)
80 #endif 70 #endif
81 71
82 /** Converts a SkFixed to a SkFract, asserting that the result does not overflow
83 a 32 bit signed integer
84 */
85 #ifdef SK_DEBUG
86 inline SkFract SkFixedToFract(SkFixed x)
87 {
88 SkASSERT(x >= (-2 << 16) && x <= (2 << 16) - 1);
89 return x << 14;
90 }
91 #else
92 #define SkFixedToFract(x) ((x) << 14)
93 #endif
94
95 /** Returns the signed fraction of a SkFixed
96 */
97 inline SkFixed SkFixedFraction(SkFixed x)
98 {
99 SkFixed mask = x >> 31 << 16;
100 return (x & 0xFFFF) | mask;
101 }
102
103 /** Converts a SkFract to a SkFixed
104 */
105 #define SkFractToFixed(x) ((x) >> 14)
106
107 #define SkFixedRoundToInt(x) (((x) + SK_FixedHalf) >> 16) 72 #define SkFixedRoundToInt(x) (((x) + SK_FixedHalf) >> 16)
108 #define SkFixedCeilToInt(x) (((x) + SK_Fixed1 - 1) >> 16) 73 #define SkFixedCeilToInt(x) (((x) + SK_Fixed1 - 1) >> 16)
109 #define SkFixedFloorToInt(x) ((x) >> 16) 74 #define SkFixedFloorToInt(x) ((x) >> 16)
110 75
111 #define SkFixedRoundToFixed(x) (((x) + SK_FixedHalf) & 0xFFFF0000) 76 #define SkFixedRoundToFixed(x) (((x) + SK_FixedHalf) & 0xFFFF0000)
112 #define SkFixedCeilToFixed(x) (((x) + SK_Fixed1 - 1) & 0xFFFF0000) 77 #define SkFixedCeilToFixed(x) (((x) + SK_Fixed1 - 1) & 0xFFFF0000)
113 #define SkFixedFloorToFixed(x) ((x) & 0xFFFF0000) 78 #define SkFixedFloorToFixed(x) ((x) & 0xFFFF0000)
114 79
115 // DEPRECATED 80 // DEPRECATED
116 #define SkFixedFloor(x) SkFixedFloorToInt(x) 81 #define SkFixedFloor(x) SkFixedFloorToInt(x)
117 #define SkFixedCeil(x) SkFixedCeilToInt(x) 82 #define SkFixedCeil(x) SkFixedCeilToInt(x)
118 #define SkFixedRound(x) SkFixedRoundToInt(x) 83 #define SkFixedRound(x) SkFixedRoundToInt(x)
119 84
120 #define SkFixedAbs(x) SkAbs32(x) 85 #define SkFixedAbs(x) SkAbs32(x)
121 #define SkFixedAve(a, b) (((a) + (b)) >> 1) 86 #define SkFixedAve(a, b) (((a) + (b)) >> 1)
122 87
123 SkFixed SkFixedMul_portable(SkFixed, SkFixed); 88 SkFixed SkFixedMul_portable(SkFixed, SkFixed);
124 SkFract SkFractMul_portable(SkFract, SkFract);
125 inline SkFixed SkFixedSquare_portable(SkFixed value) 89 inline SkFixed SkFixedSquare_portable(SkFixed value)
126 { 90 {
127 uint32_t a = SkAbs32(value); 91 uint32_t a = SkAbs32(value);
128 uint32_t ah = a >> 16; 92 uint32_t ah = a >> 16;
129 uint32_t al = a & 0xFFFF; 93 uint32_t al = a & 0xFFFF;
130 SkFixed result = ah * a + al * ah + (al * al >> 16); 94 SkFixed result = ah * a + al * ah + (al * al >> 16);
131 if (result >= 0) 95 if (result >= 0)
132 return result; 96 return result;
133 else // Overflow. 97 else // Overflow.
134 return SK_FixedMax; 98 return SK_FixedMax;
135 } 99 }
136 100
137 #define SkFixedDiv(numer, denom) SkDivBits(numer, denom, 16) 101 #define SkFixedDiv(numer, denom) SkDivBits(numer, denom, 16)
138 SkFixed SkFixedDivInt(int32_t numer, int32_t denom);
139 SkFixed SkFixedMod(SkFixed numer, SkFixed denom);
140 #define SkFixedInvert(n) SkDivBits(SK_Fixed1, n, 16)
141 SkFixed SkFixedFastInvert(SkFixed n);
142 #define SkFixedSqrt(n) SkSqrtBits(n, 23)
143 SkFixed SkFixedMean(SkFixed a, SkFixed b); //*< returns sqrt(x*y)
144 int SkFixedMulCommon(SkFixed, int , int bias); // internal used by SkFixedMulFl oor, SkFixedMulCeil, SkFixedMulRound
145 102
146 #define SkFractDiv(numer, denom) SkDivBits(numer, denom, 30) 103 ///////////////////////////////////////////////////////////////////////////////
147 #define SkFractSqrt(n) SkSqrtBits(n, 30) 104 // TODO: move fixed sin/cos into SkCosineMapper, as that is the only caller
105 // or rewrite SkCosineMapper to not use it at all
148 106
149 SkFixed SkFixedSinCos(SkFixed radians, SkFixed* cosValueOrNull); 107 SkFixed SkFixedSinCos(SkFixed radians, SkFixed* cosValueOrNull);
150 #define SkFixedSin(radians) SkFixedSinCos(radians, NULL) 108 #define SkFixedSin(radians) SkFixedSinCos(radians, NULL)
151 inline SkFixed SkFixedCos(SkFixed radians) 109 static inline SkFixed SkFixedCos(SkFixed radians) {
152 {
153 SkFixed cosValue; 110 SkFixed cosValue;
154 (void)SkFixedSinCos(radians, &cosValue); 111 (void)SkFixedSinCos(radians, &cosValue);
155 return cosValue; 112 return cosValue;
156 } 113 }
157 SkFixed SkFixedTan(SkFixed radians);
158 SkFixed SkFixedASin(SkFixed);
159 SkFixed SkFixedACos(SkFixed);
160 SkFixed SkFixedATan2(SkFixed y, SkFixed x);
161 SkFixed SkFixedExp(SkFixed);
162 SkFixed SkFixedLog(SkFixed);
163
164 #define SK_FixedNearlyZero (SK_Fixed1 >> 12)
165
166 inline bool SkFixedNearlyZero(SkFixed x, SkFixed tolerance = SK_FixedNearlyZero)
167 {
168 SkASSERT(tolerance > 0);
169 return SkAbs32(x) < tolerance;
170 }
171 114
172 //////////////////////////////////////////////////////////////////////////////// ////////////////////// 115 //////////////////////////////////////////////////////////////////////////////// //////////////////////
173 // Now look for ASM overrides for our portable versions (should consider putting this in its own file) 116 // Now look for ASM overrides for our portable versions (should consider putting this in its own file)
174 117
175 #ifdef SkLONGLONG 118 #ifdef SkLONGLONG
176 inline SkFixed SkFixedMul_longlong(SkFixed a, SkFixed b) 119 inline SkFixed SkFixedMul_longlong(SkFixed a, SkFixed b)
177 { 120 {
178 return (SkFixed)((SkLONGLONG)a * b >> 16); 121 return (SkFixed)((SkLONGLONG)a * b >> 16);
179 } 122 }
180 inline SkFract SkFractMul_longlong(SkFract a, SkFract b)
181 {
182 return (SkFract)((SkLONGLONG)a * b >> 30);
183 }
184 inline SkFixed SkFixedSquare_longlong(SkFixed value) 123 inline SkFixed SkFixedSquare_longlong(SkFixed value)
185 { 124 {
186 return (SkFixed)((SkLONGLONG)value * value >> 16); 125 return (SkFixed)((SkLONGLONG)value * value >> 16);
187 } 126 }
188 #define SkFixedMul(a,b) SkFixedMul_longlong(a,b) 127 #define SkFixedMul(a,b) SkFixedMul_longlong(a,b)
189 #define SkFractMul(a,b) SkFractMul_longlong(a,b)
190 #define SkFixedSquare(a) SkFixedSquare_longlong(a) 128 #define SkFixedSquare(a) SkFixedSquare_longlong(a)
191 #endif 129 #endif
192 130
193 #if defined(SK_CPU_ARM) 131 #if defined(SK_CPU_ARM)
194 /* This guy does not handle NaN or other obscurities, but is faster than 132 /* This guy does not handle NaN or other obscurities, but is faster than
195 than (int)(x*65536) 133 than (int)(x*65536)
196 */ 134 */
197 inline SkFixed SkFloatToFixed_arm(float x) 135 inline SkFixed SkFloatToFixed_arm(float x)
198 { 136 {
199 int32_t y, z; 137 int32_t y, z;
(...skipping 16 matching lines...) Expand all
216 int32_t t; 154 int32_t t;
217 asm("smull %0, %2, %1, %3 \n" 155 asm("smull %0, %2, %1, %3 \n"
218 "mov %0, %0, lsr #16 \n" 156 "mov %0, %0, lsr #16 \n"
219 "orr %0, %0, %2, lsl #16 \n" 157 "orr %0, %0, %2, lsl #16 \n"
220 : "=r"(x), "=&r"(y), "=r"(t) 158 : "=r"(x), "=&r"(y), "=r"(t)
221 : "r"(x), "1"(y) 159 : "r"(x), "1"(y)
222 : 160 :
223 ); 161 );
224 return x; 162 return x;
225 } 163 }
226 inline SkFixed SkFixedMulAdd_arm(SkFixed x, SkFixed y, SkFixed a)
227 {
228 int32_t t;
229 asm("smull %0, %3, %1, %4 \n"
230 "add %0, %2, %0, lsr #16 \n"
231 "add %0, %0, %3, lsl #16 \n"
232 : "=r"(x), "=&r"(y), "=&r"(a), "=r"(t)
233 : "%r"(x), "1"(y), "2"(a)
234 :
235 );
236 return x;
237 }
238 inline SkFixed SkFractMul_arm(SkFixed x, SkFixed y)
239 {
240 int32_t t;
241 asm("smull %0, %2, %1, %3 \n"
242 "mov %0, %0, lsr #30 \n"
243 "orr %0, %0, %2, lsl #2 \n"
244 : "=r"(x), "=&r"(y), "=r"(t)
245 : "r"(x), "1"(y)
246 :
247 );
248 return x;
249 }
250 #undef SkFixedMul 164 #undef SkFixedMul
251 #undef SkFractMul
252 #define SkFixedMul(x, y) SkFixedMul_arm(x, y) 165 #define SkFixedMul(x, y) SkFixedMul_arm(x, y)
253 #define SkFractMul(x, y) SkFractMul_arm(x, y)
254 #define SkFixedMulAdd(x, y, a) SkFixedMulAdd_arm(x, y, a)
255 166
256 #undef SkFloatToFixed 167 #undef SkFloatToFixed
257 #define SkFloatToFixed(x) SkFloatToFixed_arm(x) 168 #define SkFloatToFixed(x) SkFloatToFixed_arm(x)
258 #endif 169 #endif
259 170
260 /////////////////////// Now define our macros to the portable versions if they w eren't overridden
261
262 #ifndef SkFixedSquare
263 #define SkFixedSquare(x) SkFixedSquare_portable(x)
264 #endif
265 #ifndef SkFixedMul 171 #ifndef SkFixedMul
266 #define SkFixedMul(x, y) SkFixedMul_portable(x, y) 172 #define SkFixedMul(x, y) SkFixedMul_portable(x, y)
267 #endif 173 #endif
268 #ifndef SkFractMul
269 #define SkFractMul(x, y) SkFractMul_portable(x, y)
270 #endif
271 #ifndef SkFixedMulAdd
272 #define SkFixedMulAdd(x, y, a) (SkFixedMul(x, y) + (a))
273 #endif
274 174
275 /////////////////////////////////////////////////////////////////////////////// 175 ///////////////////////////////////////////////////////////////////////////////
276 176
277 typedef int64_t SkFixed48; 177 typedef int64_t SkFixed48;
278 178
279 #define SkIntToFixed48(x) ((SkFixed48)(x) << 48) 179 #define SkIntToFixed48(x) ((SkFixed48)(x) << 48)
280 #define SkFixed48ToInt(x) ((int)((x) >> 48)) 180 #define SkFixed48ToInt(x) ((int)((x) >> 48))
281 #define SkFixedToFixed48(x) ((SkFixed48)(x) << 32) 181 #define SkFixedToFixed48(x) ((SkFixed48)(x) << 32)
282 #define SkFixed48ToFixed(x) ((SkFixed)((x) >> 32)) 182 #define SkFixed48ToFixed(x) ((SkFixed)((x) >> 32))
283 #define SkFloatToFixed48(x) ((SkFixed48)((x) * (65536.0f * 65536.0f * 65536. 0f))) 183 #define SkFloatToFixed48(x) ((SkFixed48)((x) * (65536.0f * 65536.0f * 65536. 0f)))
284 184
285 #define SkScalarToFixed48(x) SkFloatToFixed48(x) 185 #define SkScalarToFixed48(x) SkFloatToFixed48(x)
286 186
287 #endif 187 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698