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 "SkHalf.h" | |
10 #include "SkLinearGradient.h" | 11 #include "SkLinearGradient.h" |
11 #include "SkRadialGradient.h" | 12 #include "SkRadialGradient.h" |
12 #include "SkTwoPointConicalGradient.h" | 13 #include "SkTwoPointConicalGradient.h" |
13 #include "SkSweepGradient.h" | 14 #include "SkSweepGradient.h" |
14 | 15 |
15 void SkGradientShaderBase::Descriptor::flatten(SkWriteBuffer& buffer) const { | 16 void SkGradientShaderBase::Descriptor::flatten(SkWriteBuffer& buffer) const { |
16 buffer.writeColorArray(fColors, fCount); | 17 buffer.writeColorArray(fColors, fCount); |
17 // TODO: Flatten fColors4f and fColorSpace | 18 // TODO: Flatten fColors4f and fColorSpace |
18 if (fPos) { | 19 if (fPos) { |
19 buffer.writeBool(true); | 20 buffer.writeBool(true); |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
537 | 538 |
538 if (nextIndex > prevIndex) | 539 if (nextIndex > prevIndex) |
539 Build32bitCache(cache->fCache32 + prevIndex, cache->fShader.fOri gColors[i-1], | 540 Build32bitCache(cache->fCache32 + prevIndex, cache->fShader.fOri gColors[i-1], |
540 cache->fShader.fOrigColors[i], nextIndex - prevI ndex + 1, | 541 cache->fShader.fOrigColors[i], nextIndex - prevI ndex + 1, |
541 cache->fCacheAlpha, cache->fShader.fGradFlags, c ache->fCacheDither); | 542 cache->fCacheAlpha, cache->fShader.fGradFlags, c ache->fCacheDither); |
542 prevIndex = nextIndex; | 543 prevIndex = nextIndex; |
543 } | 544 } |
544 } | 545 } |
545 } | 546 } |
546 | 547 |
548 void SkGradientShaderBase::initLinearBitmap(SkBitmap* bitmap) const { | |
549 const bool interpInPremul = SkToBool(fGradFlags & | |
550 SkGradientShader::kInterpolateColorsInP remul_Flag); | |
551 bitmap->lockPixels(); | |
552 SkHalf* pixelsF16 = reinterpret_cast<SkHalf*>(bitmap->getPixels()); | |
553 uint32_t* pixelsS32 = reinterpret_cast<uint32_t*>(bitmap->getPixels()); | |
554 | |
555 typedef std::function<void(const Sk4f&, int)> pixelWriteFn_t; | |
556 | |
557 pixelWriteFn_t writeF16Pixel = [&](const Sk4f& x, int index) { | |
558 Sk4h c = SkFloatToHalf_finite_ftz(x); | |
559 pixelsF16[4*index+0] = c[0]; | |
560 pixelsF16[4*index+1] = c[1]; | |
561 pixelsF16[4*index+2] = c[2]; | |
562 pixelsF16[4*index+3] = c[3]; | |
563 }; | |
564 pixelWriteFn_t writeS32Pixel = [&](const Sk4f& c, int index) { | |
565 pixelsS32[index] = Sk4f_toS32(c); | |
566 }; | |
567 | |
568 pixelWriteFn_t writeSizedPixel = | |
569 (kRGBA_F16_SkColorType == bitmap->colorType()) ? writeF16Pixel : writeS3 2Pixel; | |
570 pixelWriteFn_t writeUnpremulPixel = [&](const Sk4f& c, int index) { | |
571 writeSizedPixel(c * Sk4f(c[3], c[3], c[3], 1.0f), index); | |
572 }; | |
573 | |
574 pixelWriteFn_t writePixel = interpInPremul ? writeSizedPixel : writeUnpremul Pixel; | |
575 | |
576 int prevIndex = 0; | |
577 for (int i = 1; i < fColorCount; i++) { | |
578 int nextIndex = (fColorCount == 2) ? (kCache32Count - 1) | |
579 : SkFixedToFFFF(fRecs[i].fPos) >> kCache32Shift; | |
580 SkASSERT(nextIndex < kCache32Count); | |
581 | |
582 if (nextIndex > prevIndex) { | |
583 Sk4f c0 = Sk4f::Load(fOrigColors4f[i - 1].vec()); | |
584 Sk4f c1 = Sk4f::Load(fOrigColors4f[i].vec()); | |
585 if (interpInPremul) { | |
586 c0 = c0 * Sk4f(c0[3], c0[3], c0[3], 1.0f); | |
587 c1 = c1 * Sk4f(c1[3], c1[3], c1[3], 1.0f); | |
588 } | |
589 | |
590 Sk4f step = Sk4f(1.0f / static_cast<float>(nextIndex - prevIndex)); | |
591 Sk4f delta = (c1 - c0) * step; | |
592 | |
593 for (int curIndex = prevIndex; curIndex <= nextIndex; ++curIndex) { | |
594 writePixel(c0, curIndex); | |
595 c0 += delta; | |
596 } | |
597 } | |
598 prevIndex = nextIndex; | |
599 } | |
600 SkASSERT(prevIndex == kCache32Count - 1); | |
601 bitmap->unlockPixels(); | |
602 } | |
603 | |
547 /* | 604 /* |
548 * The gradient holds a cache for the most recent value of alpha. Successive | 605 * The gradient holds a cache for the most recent value of alpha. Successive |
549 * callers with the same alpha value will share the same cache. | 606 * callers with the same alpha value will share the same cache. |
550 */ | 607 */ |
551 SkGradientShaderBase::GradientShaderCache* SkGradientShaderBase::refCache(U8CPU alpha, | 608 SkGradientShaderBase::GradientShaderCache* SkGradientShaderBase::refCache(U8CPU alpha, |
552 bool d ither) const { | 609 bool d ither) const { |
553 SkAutoMutexAcquire ama(fCacheMutex); | 610 SkAutoMutexAcquire ama(fCacheMutex); |
554 if (!fCache || fCache->getAlpha() != alpha || fCache->getDither() != dither) { | 611 if (!fCache || fCache->getAlpha() != alpha || fCache->getDither() != dither) { |
555 fCache.reset(new GradientShaderCache(alpha, dither, *this)); | 612 fCache.reset(new GradientShaderCache(alpha, dither, *this)); |
556 } | 613 } |
557 // Increment the ref counter inside the mutex to ensure the returned pointer is still valid. | 614 // Increment the ref counter inside the mutex to ensure the returned pointer is still valid. |
558 // Otherwise, the pointer may have been overwritten on a different thread be fore the object's | 615 // Otherwise, the pointer may have been overwritten on a different thread be fore the object's |
559 // ref count was incremented. | 616 // ref count was incremented. |
560 fCache.get()->ref(); | 617 fCache.get()->ref(); |
561 return fCache; | 618 return fCache; |
562 } | 619 } |
563 | 620 |
564 SK_DECLARE_STATIC_MUTEX(gGradientCacheMutex); | 621 SK_DECLARE_STATIC_MUTEX(gGradientCacheMutex); |
565 /* | 622 /* |
566 * Because our caller might rebuild the same (logically the same) gradient | 623 * Because our caller might rebuild the same (logically the same) gradient |
567 * over and over, we'd like to return exactly the same "bitmap" if possible, | 624 * over and over, we'd like to return exactly the same "bitmap" if possible, |
568 * allowing the client to utilize a cache of our bitmap (e.g. with a GPU). | 625 * allowing the client to utilize a cache of our bitmap (e.g. with a GPU). |
569 * To do that, we maintain a private cache of built-bitmaps, based on our | 626 * To do that, we maintain a private cache of built-bitmaps, based on our |
570 * colors and positions. Note: we don't try to flatten the fMapper, so if one | 627 * colors and positions. Note: we don't try to flatten the fMapper, so if one |
571 * is present, we skip the cache for now. | 628 * is present, we skip the cache for now. |
572 */ | 629 */ |
573 void SkGradientShaderBase::getGradientTableBitmap(SkBitmap* bitmap) const { | 630 void SkGradientShaderBase::getGradientTableBitmap(SkBitmap* bitmap, |
574 // our caller assumes no external alpha, so we ensure that our cache is | 631 GradientBitmapType bitmapType) const { |
575 // built with 0xFF | 632 // our caller assumes no external alpha, so we ensure that our cache is buil t with 0xFF |
576 SkAutoTUnref<GradientShaderCache> cache(this->refCache(0xFF, true)); | 633 SkAutoTUnref<GradientShaderCache> cache(this->refCache(0xFF, true)); |
577 | 634 |
578 // build our key: [numColors + colors[] + {positions[]} + flags ] | 635 // build our key: [numColors + colors[] + {positions[]} + flags + colorType ] |
579 int count = 1 + fColorCount + 1; | 636 int count = 1 + fColorCount + 1 + 1; |
580 if (fColorCount > 2) { | 637 if (fColorCount > 2) { |
581 count += fColorCount - 1; // fRecs[].fPos | 638 count += fColorCount - 1; // fRecs[].fPos |
582 } | 639 } |
583 | 640 |
584 SkAutoSTMalloc<16, int32_t> storage(count); | 641 SkAutoSTMalloc<16, int32_t> storage(count); |
585 int32_t* buffer = storage.get(); | 642 int32_t* buffer = storage.get(); |
586 | 643 |
587 *buffer++ = fColorCount; | 644 *buffer++ = fColorCount; |
588 memcpy(buffer, fOrigColors, fColorCount * sizeof(SkColor)); | 645 memcpy(buffer, fOrigColors, fColorCount * sizeof(SkColor)); |
589 buffer += fColorCount; | 646 buffer += fColorCount; |
590 if (fColorCount > 2) { | 647 if (fColorCount > 2) { |
591 for (int i = 1; i < fColorCount; i++) { | 648 for (int i = 1; i < fColorCount; i++) { |
592 *buffer++ = fRecs[i].fPos; | 649 *buffer++ = fRecs[i].fPos; |
593 } | 650 } |
594 } | 651 } |
595 *buffer++ = fGradFlags; | 652 *buffer++ = fGradFlags; |
653 *buffer++ = static_cast<int32_t>(bitmapType); | |
596 SkASSERT(buffer - storage.get() == count); | 654 SkASSERT(buffer - storage.get() == count); |
597 | 655 |
598 /////////////////////////////////// | 656 /////////////////////////////////// |
599 | 657 |
600 static SkGradientBitmapCache* gCache; | 658 static SkGradientBitmapCache* gCache; |
601 // each cache cost 1K of RAM, since each bitmap will be 1x256 at 32bpp | 659 // each cache cost 1K or 2K of RAM, since each bitmap will be 1x256 at eithe r 32bpp or 64bpp |
602 static const int MAX_NUM_CACHED_GRADIENT_BITMAPS = 32; | 660 static const int MAX_NUM_CACHED_GRADIENT_BITMAPS = 32; |
603 SkAutoMutexAcquire ama(gGradientCacheMutex); | 661 SkAutoMutexAcquire ama(gGradientCacheMutex); |
604 | 662 |
605 if (nullptr == gCache) { | 663 if (nullptr == gCache) { |
606 gCache = new SkGradientBitmapCache(MAX_NUM_CACHED_GRADIENT_BITMAPS); | 664 gCache = new SkGradientBitmapCache(MAX_NUM_CACHED_GRADIENT_BITMAPS); |
607 } | 665 } |
608 size_t size = count * sizeof(int32_t); | 666 size_t size = count * sizeof(int32_t); |
609 | 667 |
610 if (!gCache->find(storage.get(), size, bitmap)) { | 668 if (!gCache->find(storage.get(), size, bitmap)) { |
611 // force our cahce32pixelref to be built | 669 if (GradientBitmapType::kLegacy == bitmapType) { |
612 (void)cache->getCache32(); | 670 // force our cache32pixelref to be built |
613 bitmap->setInfo(SkImageInfo::MakeN32Premul(kCache32Count, 1)); | 671 (void)cache->getCache32(); |
614 bitmap->setPixelRef(cache->getCache32PixelRef()); | 672 bitmap->setInfo(SkImageInfo::MakeN32Premul(kCache32Count, 1)); |
673 bitmap->setPixelRef(cache->getCache32PixelRef()); | |
674 } else { | |
675 // For these cases we use the bitmap cache, but not the GradientShad erCache. So just | |
676 // allocate and populate the bitmap's data directly. | |
615 | 677 |
678 SkImageInfo info; | |
679 switch (bitmapType) { | |
680 case GradientBitmapType::kSRGB: | |
681 info = SkImageInfo::Make(kCache32Count, 1, kRGBA_8888_SkColo rType, | |
682 kPremul_SkAlphaType, | |
683 SkColorSpace::NewNamed(SkColorSpace ::kSRGB_Named)); | |
684 break; | |
685 case GradientBitmapType::kHalfFloat: | |
686 info = SkImageInfo::Make(kCache32Count, 1, kRGBA_F16_SkColor Type, | |
687 kPremul_SkAlphaType, | |
688 SkColorSpace::NewNamed(SkColorSpace ::kSRGB_Named) | |
689 ->makeLinearGamma()); | |
690 break; | |
691 default: | |
692 SkFAIL("Unexpected bitmap type"); | |
693 return; | |
694 } | |
695 bitmap->allocPixels(info); | |
696 this->initLinearBitmap(bitmap); | |
697 } | |
616 gCache->add(storage.get(), size, *bitmap); | 698 gCache->add(storage.get(), size, *bitmap); |
617 } | 699 } |
618 } | 700 } |
619 | 701 |
620 void SkGradientShaderBase::commonAsAGradient(GradientInfo* info, bool flipGrad) const { | 702 void SkGradientShaderBase::commonAsAGradient(GradientInfo* info, bool flipGrad) const { |
621 if (info) { | 703 if (info) { |
622 if (info->fColorCount >= fColorCount) { | 704 if (info->fColorCount >= fColorCount) { |
623 SkColor* colorLoc; | 705 SkColor* colorLoc; |
624 Rec* recLoc; | 706 Rec* recLoc; |
625 if (flipGrad && (info->fColors || info->fColorOffsets)) { | 707 if (flipGrad && (info->fColors || info->fColorOffsets)) { |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
895 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 977 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
896 | 978 |
897 /////////////////////////////////////////////////////////////////////////////// | 979 /////////////////////////////////////////////////////////////////////////////// |
898 | 980 |
899 #if SK_SUPPORT_GPU | 981 #if SK_SUPPORT_GPU |
900 | 982 |
901 #include "GrContext.h" | 983 #include "GrContext.h" |
902 #include "GrInvariantOutput.h" | 984 #include "GrInvariantOutput.h" |
903 #include "GrTextureStripAtlas.h" | 985 #include "GrTextureStripAtlas.h" |
904 #include "gl/GrGLContext.h" | 986 #include "gl/GrGLContext.h" |
987 #include "glsl/GrGLSLColorSpaceXformHelper.h" | |
905 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 988 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
906 #include "glsl/GrGLSLProgramDataManager.h" | 989 #include "glsl/GrGLSLProgramDataManager.h" |
907 #include "glsl/GrGLSLUniformHandler.h" | 990 #include "glsl/GrGLSLUniformHandler.h" |
908 #include "SkGr.h" | 991 #include "SkGr.h" |
909 | 992 |
910 static inline bool close_to_one_half(const SkFixed& val) { | 993 static inline bool close_to_one_half(const SkFixed& val) { |
911 return SkScalarNearlyEqual(SkFixedToScalar(val), SK_ScalarHalf); | 994 return SkScalarNearlyEqual(SkFixedToScalar(val), SK_ScalarHalf); |
912 } | 995 } |
913 | 996 |
914 static inline int color_type_to_color_count(GrGradientEffect::ColorType colorTyp e) { | 997 static inline int color_type_to_color_count(GrGradientEffect::ColorType colorTyp e) { |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1106 | 1189 |
1107 break; | 1190 break; |
1108 } | 1191 } |
1109 | 1192 |
1110 case GrGradientEffect::kTexture_ColorType: { | 1193 case GrGradientEffect::kTexture_ColorType: { |
1111 SkScalar yCoord = e.getYCoord(); | 1194 SkScalar yCoord = e.getYCoord(); |
1112 if (yCoord != fCachedYCoord) { | 1195 if (yCoord != fCachedYCoord) { |
1113 pdman.set1f(fFSYUni, yCoord); | 1196 pdman.set1f(fFSYUni, yCoord); |
1114 fCachedYCoord = yCoord; | 1197 fCachedYCoord = yCoord; |
1115 } | 1198 } |
1199 if (SkToBool(e.fColorSpaceXform)) { | |
1200 pdman.setSkMatrix44(fColorSpaceXformUni, e.fColorSpaceXform->src ToDst()); | |
1201 } | |
1116 break; | 1202 break; |
1117 } | 1203 } |
1118 } | 1204 } |
1119 } | 1205 } |
1120 | 1206 |
1121 uint32_t GrGradientEffect::GLSLProcessor::GenBaseGradientKey(const GrProcessor& processor) { | 1207 uint32_t GrGradientEffect::GLSLProcessor::GenBaseGradientKey(const GrProcessor& processor) { |
1122 const GrGradientEffect& e = processor.cast<GrGradientEffect>(); | 1208 const GrGradientEffect& e = processor.cast<GrGradientEffect>(); |
1123 | 1209 |
1124 uint32_t key = 0; | 1210 uint32_t key = 0; |
1125 | 1211 |
(...skipping 17 matching lines...) Expand all Loading... | |
1143 | 1229 |
1144 if (SkShader::TileMode::kClamp_TileMode == e.fTileMode) { | 1230 if (SkShader::TileMode::kClamp_TileMode == e.fTileMode) { |
1145 key |= kClampTileMode; | 1231 key |= kClampTileMode; |
1146 } else if (SkShader::TileMode::kRepeat_TileMode == e.fTileMode) { | 1232 } else if (SkShader::TileMode::kRepeat_TileMode == e.fTileMode) { |
1147 key |= kRepeatTileMode; | 1233 key |= kRepeatTileMode; |
1148 } else { | 1234 } else { |
1149 key |= kMirrorTileMode; | 1235 key |= kMirrorTileMode; |
1150 } | 1236 } |
1151 #endif | 1237 #endif |
1152 | 1238 |
1239 key |= GrColorSpaceXform::XformKey(e.fColorSpaceXform.get()) << kReservedBit s; | |
1240 | |
1153 return key; | 1241 return key; |
1154 } | 1242 } |
1155 | 1243 |
1156 void GrGradientEffect::GLSLProcessor::emitColor(GrGLSLFPFragmentBuilder* fragBui lder, | 1244 void GrGradientEffect::GLSLProcessor::emitColor(GrGLSLFPFragmentBuilder* fragBui lder, |
1157 GrGLSLUniformHandler* uniformHan dler, | 1245 GrGLSLUniformHandler* uniformHan dler, |
1158 const GrGLSLCaps* glslCaps, | 1246 const GrGLSLCaps* glslCaps, |
1159 const GrGradientEffect& ge, | 1247 const GrGradientEffect& ge, |
1160 const char* gradientTValue, | 1248 const char* gradientTValue, |
1161 const char* outputColor, | 1249 const char* outputColor, |
1162 const char* inputColor, | 1250 const char* inputColor, |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1324 fragBuilder->codeAppend("colorTemp.rgb *= colorTemp.a;"); | 1412 fragBuilder->codeAppend("colorTemp.rgb *= colorTemp.a;"); |
1325 } | 1413 } |
1326 | 1414 |
1327 fragBuilder->codeAppendf("%s = %s;", outputColor, | 1415 fragBuilder->codeAppendf("%s = %s;", outputColor, |
1328 (GrGLSLExpr4(inputColor) * GrGLSLExpr4("col orTemp")).c_str()); | 1416 (GrGLSLExpr4(inputColor) * GrGLSLExpr4("col orTemp")).c_str()); |
1329 | 1417 |
1330 break; | 1418 break; |
1331 } | 1419 } |
1332 | 1420 |
1333 case kTexture_ColorType: { | 1421 case kTexture_ColorType: { |
1422 GrGLSLColorSpaceXformHelper colorSpaceHelper(uniformHandler, ge.fCol orSpaceXform.get(), | |
1423 &fColorSpaceXformUni); | |
1424 | |
1334 const char* fsyuni = uniformHandler->getUniformCStr(fFSYUni); | 1425 const char* fsyuni = uniformHandler->getUniformCStr(fFSYUni); |
1335 | 1426 |
1336 fragBuilder->codeAppendf("vec2 coord = vec2(%s, %s);", gradientTValu e, fsyuni); | 1427 fragBuilder->codeAppendf("vec2 coord = vec2(%s, %s);", gradientTValu e, fsyuni); |
1337 fragBuilder->codeAppendf("%s = ", outputColor); | 1428 fragBuilder->codeAppendf("%s = ", outputColor); |
1338 fragBuilder->appendTextureLookupAndModulate(inputColor, texSamplers[ 0], "coord"); | 1429 fragBuilder->appendTextureLookupAndModulate(inputColor, texSamplers[ 0], "coord", |
1430 kVec2f_GrSLType, &colorS paceHelper); | |
1339 fragBuilder->codeAppend(";"); | 1431 fragBuilder->codeAppend(";"); |
1340 | 1432 |
1341 break; | 1433 break; |
1342 } | 1434 } |
1343 } | 1435 } |
1344 } | 1436 } |
1345 | 1437 |
1346 ///////////////////////////////////////////////////////////////////// | 1438 ///////////////////////////////////////////////////////////////////// |
1347 | 1439 |
1348 GrGradientEffect::GrGradientEffect(const CreateArgs& args) { | 1440 GrGradientEffect::GrGradientEffect(const CreateArgs& args) { |
1349 const SkGradientShaderBase& shader(*args.fShader); | 1441 const SkGradientShaderBase& shader(*args.fShader); |
1350 | 1442 |
1351 fIsOpaque = shader.isOpaque(); | 1443 fIsOpaque = shader.isOpaque(); |
1352 | 1444 |
1353 fColorType = this->determineColorType(shader); | 1445 fColorType = this->determineColorType(shader); |
1446 fColorSpaceXform = std::move(args.fColorSpaceXform); | |
1354 | 1447 |
1355 if (kTexture_ColorType != fColorType) { | 1448 if (kTexture_ColorType != fColorType) { |
1356 SkASSERT(shader.fOrigColors && shader.fOrigColors4f); | 1449 SkASSERT(shader.fOrigColors && shader.fOrigColors4f); |
1357 if (args.fGammaCorrect) { | 1450 if (args.fGammaCorrect) { |
1358 fColors4f = SkTDArray<SkColor4f>(shader.fOrigColors4f, shader.fColor Count); | 1451 fColors4f = SkTDArray<SkColor4f>(shader.fOrigColors4f, shader.fColor Count); |
1359 fColorSpaceXform = std::move(args.fColorSpaceXform); | |
1360 } else { | 1452 } else { |
1361 fColors = SkTDArray<SkColor>(shader.fOrigColors, shader.fColorCount) ; | 1453 fColors = SkTDArray<SkColor>(shader.fOrigColors, shader.fColorCount) ; |
1362 } | 1454 } |
1363 | 1455 |
1364 #if GR_GL_USE_ACCURATE_HARD_STOP_GRADIENTS | 1456 #if GR_GL_USE_ACCURATE_HARD_STOP_GRADIENTS |
1365 if (shader.fOrigPos) { | 1457 if (shader.fOrigPos) { |
1366 fPositions = SkTDArray<SkScalar>(shader.fOrigPos, shader.fColorCount ); | 1458 fPositions = SkTDArray<SkScalar>(shader.fOrigPos, shader.fColorCount ); |
1367 } | 1459 } |
1368 #endif | 1460 #endif |
1369 } | 1461 } |
(...skipping 20 matching lines...) Expand all Loading... | |
1390 } | 1482 } |
1391 | 1483 |
1392 fCoordTransform.reset(kCoordSet, *args.fMatrix); | 1484 fCoordTransform.reset(kCoordSet, *args.fMatrix); |
1393 | 1485 |
1394 break; | 1486 break; |
1395 case kTexture_ColorType: | 1487 case kTexture_ColorType: |
1396 // doesn't matter how this is set, just be consistent because it is part of the | 1488 // doesn't matter how this is set, just be consistent because it is part of the |
1397 // effect key. | 1489 // effect key. |
1398 fPremulType = kBeforeInterp_PremulType; | 1490 fPremulType = kBeforeInterp_PremulType; |
1399 | 1491 |
1492 SkGradientShaderBase::GradientBitmapType bitmapType = | |
1493 SkGradientShaderBase::GradientBitmapType::kLegacy; | |
1494 if (args.fGammaCorrect) { | |
1495 // Try to use F16 if we can | |
1496 if (args.fContext->caps()->isConfigTexturable(kRGBA_half_GrPixel Config)) { | |
1497 bitmapType = SkGradientShaderBase::GradientBitmapType::kHalf Float; | |
1498 } else if (args.fContext->caps()->isConfigTexturable(kSRGBA_8888 _GrPixelConfig)) { | |
1499 bitmapType = SkGradientShaderBase::GradientBitmapType::kSRGB ; | |
1500 } else { | |
1501 // This should never happen, but just fall back to legacy be havior | |
1502 SkASSERT("Requesting a gamma-correct gradient FP without F16 or sRGB"); | |
bsalomon
2016/09/22 14:16:03
Won't this string always be true?
I believe we us
| |
1503 } | |
1504 } | |
1505 | |
1400 SkBitmap bitmap; | 1506 SkBitmap bitmap; |
1401 shader.getGradientTableBitmap(&bitmap); | 1507 shader.getGradientTableBitmap(&bitmap, bitmapType); |
1402 | 1508 |
1403 GrTextureStripAtlas::Desc desc; | 1509 GrTextureStripAtlas::Desc desc; |
1404 desc.fWidth = bitmap.width(); | 1510 desc.fWidth = bitmap.width(); |
1405 desc.fHeight = 32; | 1511 desc.fHeight = 32; |
1406 desc.fRowHeight = bitmap.height(); | 1512 desc.fRowHeight = bitmap.height(); |
1407 desc.fContext = args.fContext; | 1513 desc.fContext = args.fContext; |
1408 desc.fConfig = SkImageInfo2GrPixelConfig(bitmap.info(), *args.fConte xt->caps()); | 1514 desc.fConfig = SkImageInfo2GrPixelConfig(bitmap.info(), *args.fConte xt->caps()); |
1409 fAtlas = GrTextureStripAtlas::GetAtlas(desc); | 1515 fAtlas = GrTextureStripAtlas::GetAtlas(desc); |
1410 SkASSERT(fAtlas); | 1516 SkASSERT(fAtlas); |
1411 | 1517 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1508 (*stops)[i] = stop; | 1614 (*stops)[i] = stop; |
1509 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f; | 1615 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f; |
1510 } | 1616 } |
1511 } | 1617 } |
1512 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount)); | 1618 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount)); |
1513 | 1619 |
1514 return outColors; | 1620 return outColors; |
1515 } | 1621 } |
1516 | 1622 |
1517 #endif | 1623 #endif |
OLD | NEW |