| OLD | NEW |
| 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 SkScalar_DEFINED | 10 #ifndef SkScalar_DEFINED |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 // We rely on the following behavior of infinities and nans | 60 // We rely on the following behavior of infinities and nans |
| 61 // 0 * finite --> 0 | 61 // 0 * finite --> 0 |
| 62 // 0 * infinity --> NaN | 62 // 0 * infinity --> NaN |
| 63 // 0 * NaN --> NaN | 63 // 0 * NaN --> NaN |
| 64 float prod = x * 0; | 64 float prod = x * 0; |
| 65 // At this point, prod will either be NaN or 0 | 65 // At this point, prod will either be NaN or 0 |
| 66 // Therefore we can return (prod == prod) or (0 == prod). | 66 // Therefore we can return (prod == prod) or (0 == prod). |
| 67 return prod == prod; | 67 return prod == prod; |
| 68 } | 68 } |
| 69 | 69 |
| 70 #ifdef SK_DEBUG | |
| 71 /** SkIntToScalar(n) returns its integer argument as an SkScalar | |
| 72 * | |
| 73 * If we're compiling in DEBUG mode, and can thus afford some extra runtime | |
| 74 * cycles, check to make sure that the parameter passed in has not already | |
| 75 * been converted to SkScalar. (A double conversion like this is harmless | |
| 76 * for SK_SCALAR_IS_FLOAT, but for SK_SCALAR_IS_FIXED this causes trouble.) | |
| 77 * | |
| 78 * Note that we need all of these method signatures to properly handle the | |
| 79 * various types that we pass into SkIntToScalar() to date: | |
| 80 * int, size_t, U8CPU, etc., even though what we really mean is "anything | |
| 81 * but a float". | |
| 82 */ | |
| 83 static inline float SkIntToScalar(signed int param) { | |
| 84 return (float)param; | |
| 85 } | |
| 86 static inline float SkIntToScalar(unsigned int param) { | |
| 87 return (float)param; | |
| 88 } | |
| 89 static inline float SkIntToScalar(signed long param) { | |
| 90 return (float)param; | |
| 91 } | |
| 92 static inline float SkIntToScalar(unsigned long param) { | |
| 93 return (float)param; | |
| 94 } | |
| 95 static inline float SkIntToScalar(float /* param */) { | |
| 96 /* If the parameter passed into SkIntToScalar is a float, | |
| 97 * one of two things has happened: | |
| 98 * 1. the parameter was an SkScalar (which is typedef'd to float) | |
| 99 * 2. the parameter was a float instead of an int | |
| 100 * | |
| 101 * Either way, it's not good. | |
| 102 */ | |
| 103 SkDEBUGFAIL("looks like you passed an SkScalar into SkIntToScalar"); | |
| 104 return (float)0; | |
| 105 } | |
| 106 #else // not SK_DEBUG | |
| 107 /** SkIntToScalar(n) returns its integer argument as an SkScalar | 70 /** SkIntToScalar(n) returns its integer argument as an SkScalar |
| 108 */ | 71 */ |
| 109 #define SkIntToScalar(n) ((float)(n)) | 72 #define SkIntToScalar(n) ((float)(n)) |
| 110 #endif // not SK_DEBUG | |
| 111 /** SkFixedToScalar(n) returns its SkFixed argument as an SkScalar | 73 /** SkFixedToScalar(n) returns its SkFixed argument as an SkScalar |
| 112 */ | 74 */ |
| 113 #define SkFixedToScalar(x) SkFixedToFloat(x) | 75 #define SkFixedToScalar(x) SkFixedToFloat(x) |
| 114 /** SkScalarToFixed(n) returns its SkScalar argument as an SkFixed | 76 /** SkScalarToFixed(n) returns its SkScalar argument as an SkFixed |
| 115 */ | 77 */ |
| 116 #define SkScalarToFixed(x) SkFloatToFixed(x) | 78 #define SkScalarToFixed(x) SkFloatToFixed(x) |
| 117 | 79 |
| 118 #define SkScalarToFloat(n) (n) | 80 #define SkScalarToFloat(n) (n) |
| 119 #define SkFloatToScalar(n) (n) | 81 #define SkFloatToScalar(n) (n) |
| 120 | 82 |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 return false; | 332 return false; |
| 371 } | 333 } |
| 372 } | 334 } |
| 373 return true; | 335 return true; |
| 374 #else | 336 #else |
| 375 return 0 == memcmp(a, b, n * sizeof(SkScalar)); | 337 return 0 == memcmp(a, b, n * sizeof(SkScalar)); |
| 376 #endif | 338 #endif |
| 377 } | 339 } |
| 378 | 340 |
| 379 #endif | 341 #endif |
| OLD | NEW |