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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING | 202 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING |
203 static SkShader::TileMode unpack_mode(uint32_t packed) { | 203 static SkShader::TileMode unpack_mode(uint32_t packed) { |
204 return (SkShader::TileMode)(packed & 0xF); | 204 return (SkShader::TileMode)(packed & 0xF); |
205 } | 205 } |
206 | 206 |
207 static uint32_t unpack_flags(uint32_t packed) { | 207 static uint32_t unpack_flags(uint32_t packed) { |
208 return packed >> 4; | 208 return packed >> 4; |
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)) { | |
213 // skip the old SkUnitMapper slot | |
214 buffer.skipFlattenable(); | |
215 } | |
216 | |
217 int colorCount = fColorCount = buffer.getArrayCount(); | 212 int colorCount = fColorCount = buffer.getArrayCount(); |
218 if (colorCount > kColorStorageCount) { | 213 if (colorCount > kColorStorageCount) { |
219 size_t allocSize = (sizeof(SkColor) + sizeof(SkScalar) + sizeof(Rec)) *
colorCount; | 214 size_t allocSize = (sizeof(SkColor) + sizeof(SkScalar) + sizeof(Rec)) *
colorCount; |
220 if (buffer.validateAvailable(allocSize)) { | 215 if (buffer.validateAvailable(allocSize)) { |
221 fOrigColors = reinterpret_cast<SkColor*>(sk_malloc_throw(allocSize))
; | 216 fOrigColors = reinterpret_cast<SkColor*>(sk_malloc_throw(allocSize))
; |
222 } else { | 217 } else { |
223 fOrigColors = NULL; | 218 fOrigColors = NULL; |
224 colorCount = fColorCount = 0; | 219 colorCount = fColorCount = 0; |
225 } | 220 } |
226 } else { | 221 } else { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 for (int i = 0; i < count; ++i) { | 306 for (int i = 0; i < count; ++i) { |
312 int offset = count - i - 1; | 307 int offset = count - i - 1; |
313 recsTemp[i].fPos = SK_Fixed1 - recSrc[offset].fPos; | 308 recsTemp[i].fPos = SK_Fixed1 - recSrc[offset].fPos; |
314 recsTemp[i].fScale = recSrc[offset].fScale; | 309 recsTemp[i].fScale = recSrc[offset].fScale; |
315 } | 310 } |
316 memcpy(recDst, recsTemp.get(), count * sizeof(Rec)); | 311 memcpy(recDst, recsTemp.get(), count * sizeof(Rec)); |
317 } | 312 } |
318 memcpy(colorDst, colorsTemp.get(), count * sizeof(SkColor)); | 313 memcpy(colorDst, colorsTemp.get(), count * sizeof(SkColor)); |
319 } | 314 } |
320 | 315 |
321 void SkGradientShaderBase::flipGradientColors() { | |
322 FlipGradientColors(fOrigColors, fRecs, fOrigColors, fRecs, fColorCount); | |
323 } | |
324 | |
325 bool SkGradientShaderBase::isOpaque() const { | 316 bool SkGradientShaderBase::isOpaque() const { |
326 return fColorsAreOpaque; | 317 return fColorsAreOpaque; |
327 } | 318 } |
328 | 319 |
329 static unsigned rounded_divide(unsigned numer, unsigned denom) { | 320 static unsigned rounded_divide(unsigned numer, unsigned denom) { |
330 return (numer + (denom >> 1)) / denom; | 321 return (numer + (denom >> 1)) / denom; |
331 } | 322 } |
332 | 323 |
333 bool SkGradientShaderBase::onAsLuminanceColor(SkColor* lum) const { | 324 bool SkGradientShaderBase::onAsLuminanceColor(SkColor* lum) const { |
334 // we just compute an average color. | 325 // we just compute an average color. |
(...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1235 (*stops)[i] = stop; | 1226 (*stops)[i] = stop; |
1236 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st
op) : 1.f; | 1227 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st
op) : 1.f; |
1237 } | 1228 } |
1238 } | 1229 } |
1239 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM
odeCount)); | 1230 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM
odeCount)); |
1240 | 1231 |
1241 return outColors; | 1232 return outColors; |
1242 } | 1233 } |
1243 | 1234 |
1244 #endif | 1235 #endif |
OLD | NEW |