| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 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 #include "SkClampRange.h" | 10 #include "SkClampRange.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 } | 22 } |
| 23 if (x1 <= edge) { | 23 if (x1 <= edge) { |
| 24 return count; | 24 return count; |
| 25 } | 25 } |
| 26 int64_t n = (edge - x0 + dx - 1) / dx; | 26 int64_t n = (edge - x0 + dx - 1) / dx; |
| 27 SkASSERT(n >= 0); | 27 SkASSERT(n >= 0); |
| 28 SkASSERT(n <= count); | 28 SkASSERT(n <= count); |
| 29 return (int)n; | 29 return (int)n; |
| 30 } | 30 } |
| 31 | 31 |
| 32 #ifdef SK_SUPPORT_LEGACY_GRADIENT_PRECISION | |
| 33 static bool overflows_gradfixed(int64_t x) { | |
| 34 return x < -SK_FixedMax || x > SK_FixedMax; | |
| 35 } | |
| 36 #endif | |
| 37 | |
| 38 void SkClampRange::initFor1(SkGradFixed fx) { | 32 void SkClampRange::initFor1(SkGradFixed fx) { |
| 39 fCount0 = fCount1 = fCount2 = 0; | 33 fCount0 = fCount1 = fCount2 = 0; |
| 40 if (fx <= 0) { | 34 if (fx <= 0) { |
| 41 fCount0 = 1; | 35 fCount0 = 1; |
| 42 } else if (fx < kFracMax_SkGradFixed) { | 36 } else if (fx < kFracMax_SkGradFixed) { |
| 43 fCount1 = 1; | 37 fCount1 = 1; |
| 44 fFx1 = fx; | 38 fFx1 = fx; |
| 45 } else { | 39 } else { |
| 46 fCount2 = 1; | 40 fCount2 = 1; |
| 47 } | 41 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 fCount0 = fCount1 = 0; | 75 fCount0 = fCount1 = 0; |
| 82 fCount2 = count; | 76 fCount2 = count; |
| 83 return; | 77 return; |
| 84 } | 78 } |
| 85 | 79 |
| 86 int extraCount = 0; | 80 int extraCount = 0; |
| 87 | 81 |
| 88 // now make ex be 1 past the last computed value | 82 // now make ex be 1 past the last computed value |
| 89 ex += dx; | 83 ex += dx; |
| 90 | 84 |
| 91 #ifdef SK_SUPPORT_LEGACY_GRADIENT_PRECISION | |
| 92 // now check for over/under flow | |
| 93 if (overflows_gradfixed(ex)) { | |
| 94 int originalCount = count; | |
| 95 int64_t ccount; | |
| 96 bool swap = dx < 0; | |
| 97 if (swap) { | |
| 98 dx = -dx; | |
| 99 fx = -fx; | |
| 100 } | |
| 101 | |
| 102 int shift = 0; | |
| 103 if (sizeof(SkGradFixed) == 8) { | |
| 104 shift = 16; | |
| 105 } | |
| 106 | |
| 107 ccount = ((SK_FixedMax << shift) - fx + dx - 1) / dx; | |
| 108 if (swap) { | |
| 109 dx = -dx; | |
| 110 fx = -fx; | |
| 111 } | |
| 112 SkASSERT(ccount > 0 && ccount <= SK_FixedMax); | |
| 113 | |
| 114 count = (int)ccount; | |
| 115 if (0 == count) { | |
| 116 this->initFor1(fx0); | |
| 117 if (dx > 0) { | |
| 118 fCount2 += originalCount - 1; | |
| 119 } else { | |
| 120 fCount0 += originalCount - 1; | |
| 121 } | |
| 122 return; | |
| 123 } | |
| 124 extraCount = originalCount - count; | |
| 125 ex = fx + dx * count; | |
| 126 } | |
| 127 #endif | |
| 128 | |
| 129 bool doSwap = dx < 0; | 85 bool doSwap = dx < 0; |
| 130 | 86 |
| 131 if (doSwap) { | 87 if (doSwap) { |
| 132 ex -= dx; | 88 ex -= dx; |
| 133 fx -= dx; | 89 fx -= dx; |
| 134 SkTSwap(fx, ex); | 90 SkTSwap(fx, ex); |
| 135 dx = -dx; | 91 dx = -dx; |
| 136 } | 92 } |
| 137 | 93 |
| 138 | 94 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 165 if (fCount1 > 0) { | 121 if (fCount1 > 0) { |
| 166 fFx1 = fx0 + fCount0 * dx; | 122 fFx1 = fx0 + fCount0 * dx; |
| 167 } | 123 } |
| 168 | 124 |
| 169 if (dx > 0) { | 125 if (dx > 0) { |
| 170 fCount2 += extraCount; | 126 fCount2 += extraCount; |
| 171 } else { | 127 } else { |
| 172 fCount0 += extraCount; | 128 fCount0 += extraCount; |
| 173 } | 129 } |
| 174 } | 130 } |
| OLD | NEW |