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 #include "SkGradientShaderPriv.h" | 8 #include "SkGradientShaderPriv.h" |
9 #include "SkLinearGradient.h" | 9 #include "SkLinearGradient.h" |
10 #include "SkRadialGradient.h" | 10 #include "SkRadialGradient.h" |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 int count = desc.fCount + dummyLast; | 154 int count = desc.fCount + dummyLast; |
155 for (int i = startIndex; i < count; i++) { | 155 for (int i = startIndex; i < count; i++) { |
156 // force the last value to be 1.0 | 156 // force the last value to be 1.0 |
157 SkScalar curr; | 157 SkScalar curr; |
158 if (i == desc.fCount) { // we're really at the dummyLast | 158 if (i == desc.fCount) { // we're really at the dummyLast |
159 curr = 1; | 159 curr = 1; |
160 } else { | 160 } else { |
161 curr = SkScalarPin(desc.fPos[i], 0, 1); | 161 curr = SkScalarPin(desc.fPos[i], 0, 1); |
162 } | 162 } |
163 *origPosPtr++ = curr; | 163 *origPosPtr++ = curr; |
164 | 164 |
165 recs->fPos = SkScalarToFixed(curr); | 165 recs->fPos = SkScalarToFixed(curr); |
166 if (curr > prev) { | 166 SkFixed diff = SkScalarToFixed(curr - prev); |
167 recs->fScale = (1 << 24) / SkScalarToFixed(curr - prev); | 167 if (diff > 0) { |
| 168 recs->fScale = (1 << 24) / diff; |
168 } else { | 169 } else { |
169 recs->fScale = 0; // ignore this segment | 170 recs->fScale = 0; // ignore this segment |
170 } | 171 } |
171 // get ready for the next value | 172 // get ready for the next value |
172 prev = curr; | 173 prev = curr; |
173 recs += 1; | 174 recs += 1; |
174 } | 175 } |
175 } else { // assume even distribution | 176 } else { // assume even distribution |
176 fOrigPos = NULL; | 177 fOrigPos = NULL; |
177 | 178 |
(...skipping 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1216 (*stops)[i] = stop; | 1217 (*stops)[i] = stop; |
1217 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st
op) : 1.f; | 1218 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st
op) : 1.f; |
1218 } | 1219 } |
1219 } | 1220 } |
1220 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM
odeCount)); | 1221 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM
odeCount)); |
1221 | 1222 |
1222 return outColors; | 1223 return outColors; |
1223 } | 1224 } |
1224 | 1225 |
1225 #endif | 1226 #endif |
OLD | NEW |