Chromium Code Reviews| 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 // double the count for dither entries | 516 const size_t rowBytes = kCache32Count * sizeof(SkPMColor); |
| 517 const int entryCount = kCache32Count * 4; | 517 |
| 518 const size_t allocSize = sizeof(SkPMColor) * entryCount; | 518 SkImageInfo info; |
| 519 info.fWidth = kCache32Count; | |
| 520 info.fHeight = 4; // for our 4 dither rows | |
| 521 info.fAlphaType = kPremul_SkAlphaType; | |
| 522 info.fColorType = kPMColor_SkColorType; | |
| 519 | 523 |
| 520 if (NULL == fCache32PixelRef) { | 524 if (NULL == fCache32PixelRef) { |
|
scroggo
2013/11/19 18:17:09
If fCache32PixelRef exists, should we get info fro
reed1
2013/11/20 20:56:56
not sure it matters, since it is always the same.
| |
| 521 fCache32PixelRef = SkNEW_ARGS(SkMallocPixelRef, | 525 fCache32PixelRef = SkNEW_ARGS(SkMallocPixelRef, |
| 522 (NULL, allocSize, NULL)); | 526 (info, NULL, rowBytes, NULL, true)); |
| 523 } | 527 } |
| 524 fCache32 = (SkPMColor*)fCache32PixelRef->getAddr(); | 528 fCache32 = (SkPMColor*)fCache32PixelRef->getAddr(); |
| 525 if (fColorCount == 2) { | 529 if (fColorCount == 2) { |
| 526 Build32bitCache(fCache32, fOrigColors[0], fOrigColors[1], | 530 Build32bitCache(fCache32, fOrigColors[0], fOrigColors[1], |
| 527 kCache32Count, fCacheAlpha, fGradFlags); | 531 kCache32Count, fCacheAlpha, fGradFlags); |
| 528 } else { | 532 } else { |
| 529 Rec* rec = fRecs; | 533 Rec* rec = fRecs; |
| 530 int prevIndex = 0; | 534 int prevIndex = 0; |
| 531 for (int i = 1; i < fColorCount; i++) { | 535 for (int i = 1; i < fColorCount; i++) { |
| 532 int nextIndex = SkFixedToFFFF(rec[i].fPos) >> kCache32Shift; | 536 int nextIndex = SkFixedToFFFF(rec[i].fPos) >> kCache32Shift; |
| 533 SkASSERT(nextIndex < kCache32Count); | 537 SkASSERT(nextIndex < kCache32Count); |
| 534 | 538 |
| 535 if (nextIndex > prevIndex) | 539 if (nextIndex > prevIndex) |
| 536 Build32bitCache(fCache32 + prevIndex, fOrigColors[i-1], | 540 Build32bitCache(fCache32 + prevIndex, fOrigColors[i-1], |
| 537 fOrigColors[i], nextIndex - prevIndex + 1, | 541 fOrigColors[i], nextIndex - prevIndex + 1, |
| 538 fCacheAlpha, fGradFlags); | 542 fCacheAlpha, fGradFlags); |
| 539 prevIndex = nextIndex; | 543 prevIndex = nextIndex; |
| 540 } | 544 } |
| 541 } | 545 } |
| 542 | 546 |
| 543 if (fMapper) { | 547 if (fMapper) { |
| 544 SkMallocPixelRef* newPR = SkNEW_ARGS(SkMallocPixelRef, | 548 SkMallocPixelRef* newPR = SkNEW_ARGS(SkMallocPixelRef, |
| 545 (NULL, allocSize, NULL)); | 549 (info, NULL, rowBytes, NULL, true)); |
| 546 SkPMColor* linear = fCache32; // just computed linear data | 550 SkPMColor* linear = fCache32; // just computed linear data |
| 547 SkPMColor* mapped = (SkPMColor*)newPR->getAddr(); // storage for mapped data | 551 SkPMColor* mapped = (SkPMColor*)newPR->getAddr(); // storage for mapped data |
| 548 SkUnitMapper* map = fMapper; | 552 SkUnitMapper* map = fMapper; |
| 549 for (int i = 0; i < kCache32Count; i++) { | 553 for (int i = 0; i < kCache32Count; i++) { |
| 550 int index = map->mapUnit16((i << 8) | i) >> 8; | 554 int index = map->mapUnit16((i << 8) | i) >> 8; |
| 551 mapped[i + kCache32Count*0] = linear[index + kCache32Count*0]; | 555 mapped[i + kCache32Count*0] = linear[index + kCache32Count*0]; |
| 552 mapped[i + kCache32Count*1] = linear[index + kCache32Count*1]; | 556 mapped[i + kCache32Count*1] = linear[index + kCache32Count*1]; |
| 553 mapped[i + kCache32Count*2] = linear[index + kCache32Count*2]; | 557 mapped[i + kCache32Count*2] = linear[index + kCache32Count*2]; |
| 554 mapped[i + kCache32Count*3] = linear[index + kCache32Count*3]; | 558 mapped[i + kCache32Count*3] = linear[index + kCache32Count*3]; |
| 555 } | 559 } |
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1133 (*stops)[i] = stop; | 1137 (*stops)[i] = stop; |
| 1134 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f; | 1138 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f; |
| 1135 } | 1139 } |
| 1136 } | 1140 } |
| 1137 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount)); | 1141 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount)); |
| 1138 | 1142 |
| 1139 return outColors; | 1143 return outColors; |
| 1140 } | 1144 } |
| 1141 | 1145 |
| 1142 #endif | 1146 #endif |
| OLD | NEW |