| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 prev = curr; | 114 prev = curr; |
| 115 recs += 1; | 115 recs += 1; |
| 116 } | 116 } |
| 117 } else { // assume even distribution | 117 } else { // assume even distribution |
| 118 SkFixed dp = SK_Fixed1 / (desc.fCount - 1); | 118 SkFixed dp = SK_Fixed1 / (desc.fCount - 1); |
| 119 SkFixed p = dp; | 119 SkFixed p = dp; |
| 120 SkFixed scale = (desc.fCount - 1) << 8; // (1 << 24) / dp | 120 SkFixed scale = (desc.fCount - 1) << 8; // (1 << 24) / dp |
| 121 for (int i = 1; i < desc.fCount; i++) { | 121 for (int i = 1; i < desc.fCount; i++) { |
| 122 recs->fPos = p; | 122 recs->fPos = p; |
| 123 recs->fScale = scale; | 123 recs->fScale = scale; |
| 124 if (i == desc.fCount - 1) { |
| 125 recs->fPos = SK_Fixed1; |
| 126 } |
| 124 recs += 1; | 127 recs += 1; |
| 125 p += dp; | 128 p += dp; |
| 126 } | 129 } |
| 127 } | 130 } |
| 128 } | 131 } |
| 129 this->initCommon(); | 132 this->initCommon(); |
| 130 } | 133 } |
| 131 | 134 |
| 132 static uint32_t pack_mode_flags(SkShader::TileMode mode, uint32_t flags) { | 135 static uint32_t pack_mode_flags(SkShader::TileMode mode, uint32_t flags) { |
| 133 SkASSERT(0 == (flags >> 28)); | 136 SkASSERT(0 == (flags >> 28)); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 return kTwo_GpuColorType; | 233 return kTwo_GpuColorType; |
| 231 } else if (3 == fColorCount && | 234 } else if (3 == fColorCount && |
| 232 (SkScalarAbs( | 235 (SkScalarAbs( |
| 233 SkFixedToScalar(fRecs[1].fPos) - SK_ScalarHalf) < SK_Scalar1
/ 1000)) { | 236 SkFixedToScalar(fRecs[1].fPos) - SK_ScalarHalf) < SK_Scalar1
/ 1000)) { |
| 234 return kThree_GpuColorType; | 237 return kThree_GpuColorType; |
| 235 } | 238 } |
| 236 } | 239 } |
| 237 return kTexture_GpuColorType; | 240 return kTexture_GpuColorType; |
| 238 } | 241 } |
| 239 | 242 |
| 243 void SkGradientShaderBase::FlipGradientColors(SkColor* colorDst, Rec* recDst, |
| 244 SkColor* colorSrc, Rec* recSrc, |
| 245 int count) { |
| 246 SkAutoSTArray<8, SkColor> colorsTemp(count); |
| 247 for (int i = 0; i < count; ++i) { |
| 248 int offset = count - i - 1; |
| 249 colorsTemp[i] = colorSrc[offset]; |
| 250 } |
| 251 if (count > 2) { |
| 252 SkAutoSTArray<8, Rec> recsTemp(count); |
| 253 for (int i = 0; i < count; ++i) { |
| 254 int offset = count - i - 1; |
| 255 recsTemp[i].fPos = SK_Fixed1 - recSrc[offset].fPos; |
| 256 recsTemp[i].fScale = recSrc[offset].fScale; |
| 257 } |
| 258 memcpy(recDst, recsTemp.get(), count * sizeof(Rec)); |
| 259 } |
| 260 memcpy(colorDst, colorsTemp.get(), count * sizeof(SkColor)); |
| 261 } |
| 262 |
| 263 void SkGradientShaderBase::flipGradientColors() { |
| 264 FlipGradientColors(fOrigColors, fRecs, fOrigColors, fRecs, fColorCount); |
| 265 } |
| 266 /* |
| 240 // V23_COMPATIBILITY_CODE | 267 // V23_COMPATIBILITY_CODE |
| 241 void SkGradientShaderBase::flipGradientColors() { | 268 void SkGradientShaderBase::flipGradientColors() { |
| 242 SkAutoSTArray<8, SkColor> colorsTemp(fColorCount); | 269 SkAutoSTArray<8, SkColor> colorsTemp(fColorCount); |
| 243 for (int i = 0; i < fColorCount; ++i) { | 270 for (int i = 0; i < fColorCount; ++i) { |
| 244 int offset = fColorCount - i - 1; | 271 int offset = fColorCount - i - 1; |
| 245 colorsTemp[i] = fOrigColors[offset]; | 272 colorsTemp[i] = fOrigColors[offset]; |
| 246 } | 273 } |
| 247 if (fColorCount > 2) { | 274 if (fColorCount > 2) { |
| 248 SkAutoSTArray<8, Rec> recsTemp(fColorCount); | 275 SkAutoSTArray<8, Rec> recsTemp(fColorCount); |
| 249 for (int i = 0; i < fColorCount; ++i) { | 276 for (int i = 0; i < fColorCount; ++i) { |
| 250 int offset = fColorCount - i - 1; | 277 int offset = fColorCount - i - 1; |
| 251 recsTemp[i].fPos = 1 - fRecs[offset].fPos; | 278 recsTemp[i].fPos = 1 - fRecs[offset].fPos; |
| 252 recsTemp[i].fScale = fRecs[offset].fScale; | 279 recsTemp[i].fScale = fRecs[offset].fScale; |
| 253 } | 280 } |
| 254 memcpy(fRecs, recsTemp.get(), fColorCount * sizeof(Rec)); | 281 memcpy(fRecs, recsTemp.get(), fColorCount * sizeof(Rec)); |
| 255 } | 282 } |
| 256 memcpy(fOrigColors, colorsTemp.get(), fColorCount * sizeof(SkColor)); | 283 memcpy(fOrigColors, colorsTemp.get(), fColorCount * sizeof(SkColor)); |
| 257 } | 284 } |
| 285 */ |
| 258 | 286 |
| 259 bool SkGradientShaderBase::isOpaque() const { | 287 bool SkGradientShaderBase::isOpaque() const { |
| 260 return fColorsAreOpaque; | 288 return fColorsAreOpaque; |
| 261 } | 289 } |
| 262 | 290 |
| 263 bool SkGradientShaderBase::setContext(const SkBitmap& device, | 291 bool SkGradientShaderBase::setContext(const SkBitmap& device, |
| 264 const SkPaint& paint, | 292 const SkPaint& paint, |
| 265 const SkMatrix& matrix) { | 293 const SkMatrix& matrix) { |
| 266 if (!this->INHERITED::setContext(device, paint, matrix)) { | 294 if (!this->INHERITED::setContext(device, paint, matrix)) { |
| 267 return false; | 295 return false; |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 if (!gCache->find(storage.get(), size, bitmap)) { | 683 if (!gCache->find(storage.get(), size, bitmap)) { |
| 656 // force our cahce32pixelref to be built | 684 // force our cahce32pixelref to be built |
| 657 (void)this->getCache32(); | 685 (void)this->getCache32(); |
| 658 bitmap->setConfig(SkImageInfo::MakeN32Premul(kCache32Count, 1)); | 686 bitmap->setConfig(SkImageInfo::MakeN32Premul(kCache32Count, 1)); |
| 659 bitmap->setPixelRef(fCache32PixelRef); | 687 bitmap->setPixelRef(fCache32PixelRef); |
| 660 | 688 |
| 661 gCache->add(storage.get(), size, *bitmap); | 689 gCache->add(storage.get(), size, *bitmap); |
| 662 } | 690 } |
| 663 } | 691 } |
| 664 | 692 |
| 665 void SkGradientShaderBase::commonAsAGradient(GradientInfo* info) const { | 693 void SkGradientShaderBase::commonAsAGradient(GradientInfo* info, bool flipGrad)
const { |
| 666 if (info) { | 694 if (info) { |
| 667 if (info->fColorCount >= fColorCount) { | 695 if (info->fColorCount >= fColorCount) { |
| 696 SkColor* colorLoc; |
| 697 Rec* recLoc; |
| 698 if (flipGrad && (info->fColors || info->fColorOffsets)) { |
| 699 SkAutoSTArray<8, SkColor> colorStorage(fColorCount); |
| 700 SkAutoSTArray<8, Rec> recStorage(fColorCount); |
| 701 colorLoc = colorStorage.get(); |
| 702 recLoc = recStorage.get(); |
| 703 FlipGradientColors(colorLoc, recLoc, fOrigColors, fRecs, fColorC
ount); |
| 704 } else { |
| 705 colorLoc = fOrigColors; |
| 706 recLoc = fRecs; |
| 707 } |
| 668 if (info->fColors) { | 708 if (info->fColors) { |
| 669 memcpy(info->fColors, fOrigColors, fColorCount * sizeof(SkColor)
); | 709 memcpy(info->fColors, colorLoc, fColorCount * sizeof(SkColor
)); |
| 670 } | 710 } |
| 671 if (info->fColorOffsets) { | 711 if (info->fColorOffsets) { |
| 672 if (fColorCount == 2) { | 712 if (fColorCount == 2) { |
| 673 info->fColorOffsets[0] = 0; | 713 info->fColorOffsets[0] = 0; |
| 674 info->fColorOffsets[1] = SK_Scalar1; | 714 info->fColorOffsets[1] = SK_Scalar1; |
| 675 } else if (fColorCount > 2) { | 715 } else if (fColorCount > 2) { |
| 676 for (int i = 0; i < fColorCount; ++i) { | 716 for (int i = 0; i < fColorCount; ++i) { |
| 677 info->fColorOffsets[i] = SkFixedToScalar(fRecs[i].fPos); | 717 info->fColorOffsets[i] = SkFixedToScalar(recLoc[i].fPos)
; |
| 678 } | 718 } |
| 679 } | 719 } |
| 680 } | 720 } |
| 681 } | 721 } |
| 682 info->fColorCount = fColorCount; | 722 info->fColorCount = fColorCount; |
| 683 info->fTileMode = fTileMode; | 723 info->fTileMode = fTileMode; |
| 684 info->fGradientFlags = fGradFlags; | 724 info->fGradientFlags = fGradFlags; |
| 685 } | 725 } |
| 686 } | 726 } |
| 687 | 727 |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1176 (*stops)[i] = stop; | 1216 (*stops)[i] = stop; |
| 1177 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st
op) : 1.f; | 1217 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st
op) : 1.f; |
| 1178 } | 1218 } |
| 1179 } | 1219 } |
| 1180 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM
odeCount)); | 1220 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM
odeCount)); |
| 1181 | 1221 |
| 1182 return outColors; | 1222 return outColors; |
| 1183 } | 1223 } |
| 1184 | 1224 |
| 1185 #endif | 1225 #endif |
| OLD | NEW |