Chromium Code Reviews| 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 10 matching lines...) Expand all Loading... | |
| 21 #define SK_Fixed1 (1 << 16) | 21 #define SK_Fixed1 (1 << 16) |
| 22 #define SK_FixedHalf (1 << 15) | 22 #define SK_FixedHalf (1 << 15) |
| 23 #define SK_FixedMax (0x7FFFFFFF) | 23 #define SK_FixedMax (0x7FFFFFFF) |
| 24 #define SK_FixedMin (-SK_FixedMax) | 24 #define SK_FixedMin (-SK_FixedMax) |
| 25 #define SK_FixedNaN ((int) 0x80000000) | 25 #define SK_FixedNaN ((int) 0x80000000) |
| 26 #define SK_FixedPI (0x3243F) | 26 #define SK_FixedPI (0x3243F) |
| 27 #define SK_FixedSqrt2 (92682) | 27 #define SK_FixedSqrt2 (92682) |
| 28 #define SK_FixedTanPIOver8 (0x6A0A) | 28 #define SK_FixedTanPIOver8 (0x6A0A) |
| 29 #define SK_FixedRoot2Over2 (0xB505) | 29 #define SK_FixedRoot2Over2 (0xB505) |
| 30 | 30 |
| 31 #define SkFixedToFloat(x) ((x) * 1.5258789e-5f) | 31 #define SkFixedToFloat(x) ((x) * 1.52587890625e-5f) |
|
bungeman-skia
2015/04/16 20:41:31
Note that this diff might not cause any change, si
| |
| 32 #if 1 | 32 #if 1 |
| 33 #define SkFloatToFixed(x) ((SkFixed)((x) * SK_Fixed1)) | 33 #define SkFloatToFixed(x) ((SkFixed)((x) * SK_Fixed1)) |
| 34 #else | 34 #else |
| 35 // pins over/under flows to max/min int32 (slower than just a cast) | 35 // pins over/under flows to max/min int32 (slower than just a cast) |
| 36 static inline SkFixed SkFloatToFixed(float x) { | 36 static inline SkFixed SkFloatToFixed(float x) { |
| 37 int64_t n = x * SK_Fixed1; | 37 int64_t n = x * SK_Fixed1; |
| 38 return (SkFixed)n; | 38 return (SkFixed)n; |
| 39 } | 39 } |
| 40 #endif | 40 #endif |
| 41 | 41 |
| 42 #ifdef SK_DEBUG | 42 #ifdef SK_DEBUG |
| 43 static inline SkFixed SkFloatToFixed_Check(float x) { | 43 static inline SkFixed SkFloatToFixed_Check(float x) { |
| 44 int64_t n64 = (int64_t)(x * SK_Fixed1); | 44 int64_t n64 = (int64_t)(x * SK_Fixed1); |
| 45 SkFixed n32 = (SkFixed)n64; | 45 SkFixed n32 = (SkFixed)n64; |
| 46 SkASSERT(n64 == n32); | 46 SkASSERT(n64 == n32); |
| 47 return n32; | 47 return n32; |
| 48 } | 48 } |
| 49 #else | 49 #else |
| 50 #define SkFloatToFixed_Check(x) SkFloatToFixed(x) | 50 #define SkFloatToFixed_Check(x) SkFloatToFixed(x) |
| 51 #endif | 51 #endif |
| 52 | 52 |
| 53 #define SkFixedToDouble(x) ((x) * 1.5258789e-5) | 53 #define SkFixedToDouble(x) ((x) * 1.52587890625e-5) |
|
bungeman-skia
2015/04/16 20:41:31
Note that no one is actually using this at the mom
| |
| 54 #define SkDoubleToFixed(x) ((SkFixed)((x) * SK_Fixed1)) | 54 #define SkDoubleToFixed(x) ((SkFixed)((x) * SK_Fixed1)) |
| 55 | 55 |
| 56 /** Converts an integer to a SkFixed, asserting that the result does not overflo w | 56 /** Converts an integer to a SkFixed, asserting that the result does not overflo w |
| 57 a 32 bit signed integer | 57 a 32 bit signed integer |
| 58 */ | 58 */ |
| 59 #ifdef SK_DEBUG | 59 #ifdef SK_DEBUG |
| 60 inline SkFixed SkIntToFixed(int n) | 60 inline SkFixed SkIntToFixed(int n) |
| 61 { | 61 { |
| 62 SkASSERT(n >= -32768 && n <= 32767); | 62 SkASSERT(n >= -32768 && n <= 32767); |
| 63 return n << 16; | 63 return n << 16; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 #define Sk48Dot16FloorToInt(x) static_cast<int>((x) >> 16) | 151 #define Sk48Dot16FloorToInt(x) static_cast<int>((x) >> 16) |
| 152 | 152 |
| 153 static inline float Sk48Dot16ToScalar(Sk48Dot16 x) { | 153 static inline float Sk48Dot16ToScalar(Sk48Dot16 x) { |
| 154 return static_cast<float>(x * 1.5258789e-5); // x * (1.0f / (1 << 16)) | 154 return static_cast<float>(x * 1.5258789e-5); // x * (1.0f / (1 << 16)) |
| 155 } | 155 } |
| 156 #define SkFloatTo48Dot16(x) (static_cast<Sk48Dot16>((x) * (1 << 16))) | 156 #define SkFloatTo48Dot16(x) (static_cast<Sk48Dot16>((x) * (1 << 16))) |
| 157 | 157 |
| 158 #define SkScalarTo48Dot16(x) SkFloatTo48Dot16(x) | 158 #define SkScalarTo48Dot16(x) SkFloatTo48Dot16(x) |
| 159 | 159 |
| 160 #endif | 160 #endif |
| OLD | NEW |