OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkFixed_DEFINED | 8 #ifndef SkFixed_DEFINED |
9 #define SkFixed_DEFINED | 9 #define SkFixed_DEFINED |
10 | 10 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 // Left shifting a negative value has undefined behavior in C, so we cast to
unsigned before | 62 // Left shifting a negative value has undefined behavior in C, so we cast to
unsigned before |
63 // shifting. Then we force the cast to SkFixed to ensure that the answer is
signed (like the | 63 // shifting. Then we force the cast to SkFixed to ensure that the answer is
signed (like the |
64 // debug version). | 64 // debug version). |
65 #define SkIntToFixed(n) (SkFixed)((unsigned)(n) << 16) | 65 #define SkIntToFixed(n) (SkFixed)((unsigned)(n) << 16) |
66 #endif | 66 #endif |
67 | 67 |
68 #define SkFixedRoundToInt(x) (((x) + SK_FixedHalf) >> 16) | 68 #define SkFixedRoundToInt(x) (((x) + SK_FixedHalf) >> 16) |
69 #define SkFixedCeilToInt(x) (((x) + SK_Fixed1 - 1) >> 16) | 69 #define SkFixedCeilToInt(x) (((x) + SK_Fixed1 - 1) >> 16) |
70 #define SkFixedFloorToInt(x) ((x) >> 16) | 70 #define SkFixedFloorToInt(x) ((x) >> 16) |
71 | 71 |
72 #define SkFixedRoundToFixed(x) (((x) + SK_FixedHalf) & 0xFFFF0000) | 72 static inline SkFixed SkFixedRoundToFixed(SkFixed x) { |
73 #define SkFixedCeilToFixed(x) (((x) + SK_Fixed1 - 1) & 0xFFFF0000) | 73 return (x + SK_FixedHalf) & 0xFFFF0000; |
74 #define SkFixedFloorToFixed(x) ((x) & 0xFFFF0000) | 74 } |
| 75 static inline SkFixed SkFixedCeilToFixed(SkFixed x) { |
| 76 return (x + SK_Fixed1 - 1) & 0xFFFF0000; |
| 77 } |
| 78 static inline SkFixed SkFixedFloorToFixed(SkFixed x) { |
| 79 return x & 0xFFFF0000; |
| 80 } |
75 | 81 |
76 #define SkFixedAbs(x) SkAbs32(x) | 82 #define SkFixedAbs(x) SkAbs32(x) |
77 #define SkFixedAve(a, b) (((a) + (b)) >> 1) | 83 #define SkFixedAve(a, b) (((a) + (b)) >> 1) |
78 | 84 |
79 // The divide may exceed 32 bits. Clamp to a signed 32 bit result. | 85 // The divide may exceed 32 bits. Clamp to a signed 32 bit result. |
80 #define SkFixedDiv(numer, denom) \ | 86 #define SkFixedDiv(numer, denom) \ |
81 SkToS32(SkTPin<int64_t>((SkLeftShift((int64_t)(numer), 16) / (denom)), SK_Mi
nS32, SK_MaxS32)) | 87 SkToS32(SkTPin<int64_t>((SkLeftShift((int64_t)(numer), 16) / (denom)), SK_Mi
nS32, SK_MaxS32)) |
82 | 88 |
83 ////////////////////////////////////////////////////////////////////////////////
////////////////////// | 89 ////////////////////////////////////////////////////////////////////////////////
////////////////////// |
84 // Now look for ASM overrides for our portable versions (should consider putting
this in its own file) | 90 // Now look for ASM overrides for our portable versions (should consider putting
this in its own file) |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 156 |
151 #define SkIntToFixed3232(x) (SkLeftShift((SkFixed3232)(x), 32)) | 157 #define SkIntToFixed3232(x) (SkLeftShift((SkFixed3232)(x), 32)) |
152 #define SkFixed3232ToInt(x) ((int)((x) >> 32)) | 158 #define SkFixed3232ToInt(x) ((int)((x) >> 32)) |
153 #define SkFixedToFixed3232(x) (SkLeftShift((SkFixed3232)(x), 16)) | 159 #define SkFixedToFixed3232(x) (SkLeftShift((SkFixed3232)(x), 16)) |
154 #define SkFixed3232ToFixed(x) ((SkFixed)((x) >> 16)) | 160 #define SkFixed3232ToFixed(x) ((SkFixed)((x) >> 16)) |
155 #define SkFloatToFixed3232(x) ((SkFixed3232)((x) * (65536.0f * 65536.0f))) | 161 #define SkFloatToFixed3232(x) ((SkFixed3232)((x) * (65536.0f * 65536.0f))) |
156 | 162 |
157 #define SkScalarToFixed3232(x) SkFloatToFixed3232(x) | 163 #define SkScalarToFixed3232(x) SkFloatToFixed3232(x) |
158 | 164 |
159 #endif | 165 #endif |
OLD | NEW |