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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 } | 209 } |
210 | 210 |
211 SkGradientShaderBase::SkGradientShaderBase(SkReadBuffer& buffer) : INHERITED(buf
fer) { | 211 SkGradientShaderBase::SkGradientShaderBase(SkReadBuffer& buffer) : INHERITED(buf
fer) { |
212 if (buffer.isVersionLT(SkReadBuffer::kNoUnitMappers_Version)) { | 212 if (buffer.isVersionLT(SkReadBuffer::kNoUnitMappers_Version)) { |
213 // skip the old SkUnitMapper slot | 213 // skip the old SkUnitMapper slot |
214 buffer.skipFlattenable(); | 214 buffer.skipFlattenable(); |
215 } | 215 } |
216 | 216 |
217 int colorCount = fColorCount = buffer.getArrayCount(); | 217 int colorCount = fColorCount = buffer.getArrayCount(); |
218 if (colorCount > kColorStorageCount) { | 218 if (colorCount > kColorStorageCount) { |
219 size_t allocSize = (sizeof(SkColor) + sizeof(SkPMColor) + sizeof(Rec)) *
colorCount; | 219 size_t allocSize = (sizeof(SkColor) + sizeof(SkScalar) + sizeof(Rec)) *
colorCount; |
220 if (buffer.validateAvailable(allocSize)) { | 220 if (buffer.validateAvailable(allocSize)) { |
221 fOrigColors = reinterpret_cast<SkColor*>(sk_malloc_throw(allocSize))
; | 221 fOrigColors = reinterpret_cast<SkColor*>(sk_malloc_throw(allocSize))
; |
222 } else { | 222 } else { |
223 fOrigColors = NULL; | 223 fOrigColors = NULL; |
224 colorCount = fColorCount = 0; | 224 colorCount = fColorCount = 0; |
225 } | 225 } |
226 } else { | 226 } else { |
227 fOrigColors = fStorage; | 227 fOrigColors = fStorage; |
228 } | 228 } |
229 buffer.readColorArray(fOrigColors, colorCount); | 229 buffer.readColorArray(fOrigColors, colorCount); |
230 | 230 |
| 231 fOrigPos = (SkScalar*)(fOrigColors + colorCount); |
| 232 |
231 { | 233 { |
232 uint32_t packed = buffer.readUInt(); | 234 uint32_t packed = buffer.readUInt(); |
233 fGradFlags = SkToU8(unpack_flags(packed)); | 235 fGradFlags = SkToU8(unpack_flags(packed)); |
234 fTileMode = unpack_mode(packed); | 236 fTileMode = unpack_mode(packed); |
235 } | 237 } |
236 fTileProc = gTileProcs[fTileMode]; | 238 fTileProc = gTileProcs[fTileMode]; |
237 fRecs = (Rec*)(fOrigColors + colorCount); | 239 fRecs = (Rec*)(fOrigPos + colorCount); |
238 if (colorCount > 2) { | 240 if (colorCount > 2) { |
239 Rec* recs = fRecs; | 241 Rec* recs = fRecs; |
240 recs[0].fPos = 0; | 242 recs[0].fPos = 0; |
| 243 fOrigPos[0] = 0; |
241 for (int i = 1; i < colorCount; i++) { | 244 for (int i = 1; i < colorCount; i++) { |
242 recs[i].fPos = buffer.readInt(); | 245 recs[i].fPos = buffer.readInt(); |
243 recs[i].fScale = buffer.readUInt(); | 246 recs[i].fScale = buffer.readUInt(); |
| 247 fOrigPos[i] = SkFixedToScalar(recs[i].fPos); |
244 } | 248 } |
| 249 } else { |
| 250 fOrigPos = NULL; |
245 } | 251 } |
246 buffer.readMatrix(&fPtsToUnit); | 252 buffer.readMatrix(&fPtsToUnit); |
247 this->initCommon(); | 253 this->initCommon(); |
248 } | 254 } |
249 #endif | 255 #endif |
250 | 256 |
251 SkGradientShaderBase::~SkGradientShaderBase() { | 257 SkGradientShaderBase::~SkGradientShaderBase() { |
252 if (fOrigColors != fStorage) { | 258 if (fOrigColors != fStorage) { |
253 sk_free(fOrigColors); | 259 sk_free(fOrigColors); |
254 } | 260 } |
(...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1217 (*stops)[i] = stop; | 1223 (*stops)[i] = stop; |
1218 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st
op) : 1.f; | 1224 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st
op) : 1.f; |
1219 } | 1225 } |
1220 } | 1226 } |
1221 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM
odeCount)); | 1227 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM
odeCount)); |
1222 | 1228 |
1223 return outColors; | 1229 return outColors; |
1224 } | 1230 } |
1225 | 1231 |
1226 #endif | 1232 #endif |
OLD | NEW |