| 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 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 } | 506 } |
| 507 sk_free(fCache16); | 507 sk_free(fCache16); |
| 508 fCache16 = fCache16Storage; | 508 fCache16 = fCache16Storage; |
| 509 } | 509 } |
| 510 } | 510 } |
| 511 return fCache16; | 511 return fCache16; |
| 512 } | 512 } |
| 513 | 513 |
| 514 const SkPMColor* SkGradientShaderBase::getCache32() const { | 514 const SkPMColor* SkGradientShaderBase::getCache32() const { |
| 515 if (fCache32 == NULL) { | 515 if (fCache32 == NULL) { |
| 516 SkImageInfo info; | 516 // double the count for dither entries |
| 517 info.fWidth = kCache32Count; | 517 const int entryCount = kCache32Count * 4; |
| 518 info.fHeight = 4; // for our 4 dither rows | 518 const size_t allocSize = sizeof(SkPMColor) * entryCount; |
| 519 info.fAlphaType = kPremul_SkAlphaType; | |
| 520 info.fColorType = kPMColor_SkColorType; | |
| 521 | 519 |
| 522 if (NULL == fCache32PixelRef) { | 520 if (NULL == fCache32PixelRef) { |
| 523 fCache32PixelRef = SkMallocPixelRef::NewAllocate(info, 0, NULL); | 521 fCache32PixelRef = SkNEW_ARGS(SkMallocPixelRef, |
| 522 (NULL, allocSize, NULL)); |
| 524 } | 523 } |
| 525 fCache32 = (SkPMColor*)fCache32PixelRef->getAddr(); | 524 fCache32 = (SkPMColor*)fCache32PixelRef->getAddr(); |
| 526 if (fColorCount == 2) { | 525 if (fColorCount == 2) { |
| 527 Build32bitCache(fCache32, fOrigColors[0], fOrigColors[1], | 526 Build32bitCache(fCache32, fOrigColors[0], fOrigColors[1], |
| 528 kCache32Count, fCacheAlpha, fGradFlags); | 527 kCache32Count, fCacheAlpha, fGradFlags); |
| 529 } else { | 528 } else { |
| 530 Rec* rec = fRecs; | 529 Rec* rec = fRecs; |
| 531 int prevIndex = 0; | 530 int prevIndex = 0; |
| 532 for (int i = 1; i < fColorCount; i++) { | 531 for (int i = 1; i < fColorCount; i++) { |
| 533 int nextIndex = SkFixedToFFFF(rec[i].fPos) >> kCache32Shift; | 532 int nextIndex = SkFixedToFFFF(rec[i].fPos) >> kCache32Shift; |
| 534 SkASSERT(nextIndex < kCache32Count); | 533 SkASSERT(nextIndex < kCache32Count); |
| 535 | 534 |
| 536 if (nextIndex > prevIndex) | 535 if (nextIndex > prevIndex) |
| 537 Build32bitCache(fCache32 + prevIndex, fOrigColors[i-1], | 536 Build32bitCache(fCache32 + prevIndex, fOrigColors[i-1], |
| 538 fOrigColors[i], nextIndex - prevIndex + 1, | 537 fOrigColors[i], nextIndex - prevIndex + 1, |
| 539 fCacheAlpha, fGradFlags); | 538 fCacheAlpha, fGradFlags); |
| 540 prevIndex = nextIndex; | 539 prevIndex = nextIndex; |
| 541 } | 540 } |
| 542 } | 541 } |
| 543 | 542 |
| 544 if (fMapper) { | 543 if (fMapper) { |
| 545 SkMallocPixelRef* newPR = SkMallocPixelRef::NewAllocate(info, 0, NUL
L); | 544 SkMallocPixelRef* newPR = SkNEW_ARGS(SkMallocPixelRef, |
| 545 (NULL, allocSize, NULL)); |
| 546 SkPMColor* linear = fCache32; // just computed linear data | 546 SkPMColor* linear = fCache32; // just computed linear data |
| 547 SkPMColor* mapped = (SkPMColor*)newPR->getAddr(); // storage for
mapped data | 547 SkPMColor* mapped = (SkPMColor*)newPR->getAddr(); // storage for
mapped data |
| 548 SkUnitMapper* map = fMapper; | 548 SkUnitMapper* map = fMapper; |
| 549 for (int i = 0; i < kCache32Count; i++) { | 549 for (int i = 0; i < kCache32Count; i++) { |
| 550 int index = map->mapUnit16((i << 8) | i) >> 8; | 550 int index = map->mapUnit16((i << 8) | i) >> 8; |
| 551 mapped[i + kCache32Count*0] = linear[index + kCache32Count*0]; | 551 mapped[i + kCache32Count*0] = linear[index + kCache32Count*0]; |
| 552 mapped[i + kCache32Count*1] = linear[index + kCache32Count*1]; | 552 mapped[i + kCache32Count*1] = linear[index + kCache32Count*1]; |
| 553 mapped[i + kCache32Count*2] = linear[index + kCache32Count*2]; | 553 mapped[i + kCache32Count*2] = linear[index + kCache32Count*2]; |
| 554 mapped[i + kCache32Count*3] = linear[index + kCache32Count*3]; | 554 mapped[i + kCache32Count*3] = linear[index + kCache32Count*3]; |
| 555 } | 555 } |
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1133 (*stops)[i] = stop; | 1133 (*stops)[i] = stop; |
| 1134 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st
op) : 1.f; | 1134 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st
op) : 1.f; |
| 1135 } | 1135 } |
| 1136 } | 1136 } |
| 1137 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM
odeCount)); | 1137 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM
odeCount)); |
| 1138 | 1138 |
| 1139 return outColors; | 1139 return outColors; |
| 1140 } | 1140 } |
| 1141 | 1141 |
| 1142 #endif | 1142 #endif |
| OLD | NEW |