| 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 "Sk4fLinearGradient.h" | 8 #include "Sk4fLinearGradient.h" |
| 9 #include "SkGradientShaderPriv.h" | 9 #include "SkGradientShaderPriv.h" |
| 10 #include "SkLinearGradient.h" | 10 #include "SkLinearGradient.h" |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 if (shader.fColorsAreOpaque && paintAlpha == 0xFF) { | 315 if (shader.fColorsAreOpaque && paintAlpha == 0xFF) { |
| 316 fFlags |= kOpaqueAlpha_Flag; | 316 fFlags |= kOpaqueAlpha_Flag; |
| 317 } | 317 } |
| 318 } | 318 } |
| 319 | 319 |
| 320 SkGradientShaderBase::GradientShaderCache::GradientShaderCache( | 320 SkGradientShaderBase::GradientShaderCache::GradientShaderCache( |
| 321 U8CPU alpha, bool dither, const SkGradientShaderBase& shader) | 321 U8CPU alpha, bool dither, const SkGradientShaderBase& shader) |
| 322 : fCacheAlpha(alpha) | 322 : fCacheAlpha(alpha) |
| 323 , fCacheDither(dither) | 323 , fCacheDither(dither) |
| 324 , fShader(shader) | 324 , fShader(shader) |
| 325 , fCache16Inited(false) | |
| 326 , fCache32Inited(false) | |
| 327 { | 325 { |
| 328 // Only initialize the cache in getCache16/32. | 326 // Only initialize the cache in getCache16/32. |
| 329 fCache16 = nullptr; | 327 fCache16 = nullptr; |
| 330 fCache32 = nullptr; | 328 fCache32 = nullptr; |
| 331 fCache16Storage = nullptr; | 329 fCache16Storage = nullptr; |
| 332 fCache32PixelRef = nullptr; | 330 fCache32PixelRef = nullptr; |
| 333 } | 331 } |
| 334 | 332 |
| 335 SkGradientShaderBase::GradientShaderCache::~GradientShaderCache() { | 333 SkGradientShaderBase::GradientShaderCache::~GradientShaderCache() { |
| 336 sk_free(fCache16Storage); | 334 sk_free(fCache16Storage); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 } while (--count != 0); | 536 } while (--count != 0); |
| 539 } | 537 } |
| 540 } | 538 } |
| 541 | 539 |
| 542 static inline int SkFixedToFFFF(SkFixed x) { | 540 static inline int SkFixedToFFFF(SkFixed x) { |
| 543 SkASSERT((unsigned)x <= SK_Fixed1); | 541 SkASSERT((unsigned)x <= SK_Fixed1); |
| 544 return x - (x >> 16); | 542 return x - (x >> 16); |
| 545 } | 543 } |
| 546 | 544 |
| 547 const uint16_t* SkGradientShaderBase::GradientShaderCache::getCache16() { | 545 const uint16_t* SkGradientShaderBase::GradientShaderCache::getCache16() { |
| 548 SkOnce(&fCache16Inited, &fCache16Mutex, SkGradientShaderBase::GradientShader
Cache::initCache16, | 546 fCache16InitOnce(SkGradientShaderBase::GradientShaderCache::initCache16, thi
s); |
| 549 this); | |
| 550 SkASSERT(fCache16); | 547 SkASSERT(fCache16); |
| 551 return fCache16; | 548 return fCache16; |
| 552 } | 549 } |
| 553 | 550 |
| 554 void SkGradientShaderBase::GradientShaderCache::initCache16(GradientShaderCache*
cache) { | 551 void SkGradientShaderBase::GradientShaderCache::initCache16(GradientShaderCache*
cache) { |
| 555 // double the count for dither entries | 552 // double the count for dither entries |
| 556 const int entryCount = kCache16Count * 2; | 553 const int entryCount = kCache16Count * 2; |
| 557 const size_t allocSize = sizeof(uint16_t) * entryCount; | 554 const size_t allocSize = sizeof(uint16_t) * entryCount; |
| 558 | 555 |
| 559 SkASSERT(nullptr == cache->fCache16Storage); | 556 SkASSERT(nullptr == cache->fCache16Storage); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 572 if (nextIndex > prevIndex) | 569 if (nextIndex > prevIndex) |
| 573 Build16bitCache(cache->fCache16 + prevIndex, cache->fShader.fOri
gColors[i-1], | 570 Build16bitCache(cache->fCache16 + prevIndex, cache->fShader.fOri
gColors[i-1], |
| 574 cache->fShader.fOrigColors[i], nextIndex - prevI
ndex + 1, | 571 cache->fShader.fOrigColors[i], nextIndex - prevI
ndex + 1, |
| 575 cache->fCacheDither); | 572 cache->fCacheDither); |
| 576 prevIndex = nextIndex; | 573 prevIndex = nextIndex; |
| 577 } | 574 } |
| 578 } | 575 } |
| 579 } | 576 } |
| 580 | 577 |
| 581 const SkPMColor* SkGradientShaderBase::GradientShaderCache::getCache32() { | 578 const SkPMColor* SkGradientShaderBase::GradientShaderCache::getCache32() { |
| 582 SkOnce(&fCache32Inited, &fCache32Mutex, SkGradientShaderBase::GradientShader
Cache::initCache32, | 579 fCache32InitOnce(SkGradientShaderBase::GradientShaderCache::initCache32, thi
s); |
| 583 this); | |
| 584 SkASSERT(fCache32); | 580 SkASSERT(fCache32); |
| 585 return fCache32; | 581 return fCache32; |
| 586 } | 582 } |
| 587 | 583 |
| 588 void SkGradientShaderBase::GradientShaderCache::initCache32(GradientShaderCache*
cache) { | 584 void SkGradientShaderBase::GradientShaderCache::initCache32(GradientShaderCache*
cache) { |
| 589 const int kNumberOfDitherRows = 4; | 585 const int kNumberOfDitherRows = 4; |
| 590 const SkImageInfo info = SkImageInfo::MakeN32Premul(kCache32Count, kNumberOf
DitherRows); | 586 const SkImageInfo info = SkImageInfo::MakeN32Premul(kCache32Count, kNumberOf
DitherRows); |
| 591 | 587 |
| 592 SkASSERT(nullptr == cache->fCache32PixelRef); | 588 SkASSERT(nullptr == cache->fCache32PixelRef); |
| 593 cache->fCache32PixelRef = SkMallocPixelRef::NewAllocate(info, 0, nullptr); | 589 cache->fCache32PixelRef = SkMallocPixelRef::NewAllocate(info, 0, nullptr); |
| (...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1207 (*stops)[i] = stop; | 1203 (*stops)[i] = stop; |
| 1208 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st
op) : 1.f; | 1204 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st
op) : 1.f; |
| 1209 } | 1205 } |
| 1210 } | 1206 } |
| 1211 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM
odeCount)); | 1207 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM
odeCount)); |
| 1212 | 1208 |
| 1213 return outColors; | 1209 return outColors; |
| 1214 } | 1210 } |
| 1215 | 1211 |
| 1216 #endif | 1212 #endif |
| OLD | NEW |