| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 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 "SkPerlinNoiseShader.h" | 8 #include "SkPerlinNoiseShader.h" |
| 9 #include "SkColorFilter.h" | 9 #include "SkColorFilter.h" |
| 10 #include "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
| (...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 0.99f); | 586 0.99f); |
| 587 | 587 |
| 588 sk_sp<SkShader> shader(d->fRandom->nextBool() ? | 588 sk_sp<SkShader> shader(d->fRandom->nextBool() ? |
| 589 SkPerlinNoiseShader::MakeFractalNoise(baseFrequencyX, baseFrequencyY, nu
mOctaves, seed, | 589 SkPerlinNoiseShader::MakeFractalNoise(baseFrequencyX, baseFrequencyY, nu
mOctaves, seed, |
| 590 stitchTiles ? &tileSize : nullptr)
: | 590 stitchTiles ? &tileSize : nullptr)
: |
| 591 SkPerlinNoiseShader::MakeTurbulence(baseFrequencyX, baseFrequencyY, numO
ctaves, seed, | 591 SkPerlinNoiseShader::MakeTurbulence(baseFrequencyX, baseFrequencyY, numO
ctaves, seed, |
| 592 stitchTiles ? &tileSize : nullptr)); | 592 stitchTiles ? &tileSize : nullptr)); |
| 593 | 593 |
| 594 return shader->asFragmentProcessor(d->fContext, | 594 return shader->asFragmentProcessor(d->fContext, |
| 595 GrTest::TestMatrix(d->fRandom), nullptr, | 595 GrTest::TestMatrix(d->fRandom), nullptr, |
| 596 kNone_SkFilterQuality); | 596 kNone_SkFilterQuality, SkSourceGammaTreat
ment::kRespect); |
| 597 } | 597 } |
| 598 | 598 |
| 599 void GrGLPerlinNoise::emitCode(EmitArgs& args) { | 599 void GrGLPerlinNoise::emitCode(EmitArgs& args) { |
| 600 const GrPerlinNoiseEffect& pne = args.fFp.cast<GrPerlinNoiseEffect>(); | 600 const GrPerlinNoiseEffect& pne = args.fFp.cast<GrPerlinNoiseEffect>(); |
| 601 | 601 |
| 602 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; | 602 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 603 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; | 603 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
| 604 SkString vCoords = fragBuilder->ensureFSCoords2D(args.fCoords, 0); | 604 SkString vCoords = fragBuilder->ensureFSCoords2D(args.fCoords, 0); |
| 605 | 605 |
| 606 fBaseFrequencyUni = uniformHandler->addUniform(kFragment_GrShaderFlag, | 606 fBaseFrequencyUni = uniformHandler->addUniform(kFragment_GrShaderFlag, |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 886 | 886 |
| 887 if (turbulence.stitchTiles()) { | 887 if (turbulence.stitchTiles()) { |
| 888 const SkPerlinNoiseShader::StitchData& stitchData = turbulence.stitchDat
a(); | 888 const SkPerlinNoiseShader::StitchData& stitchData = turbulence.stitchDat
a(); |
| 889 pdman.set2f(fStitchDataUni, SkIntToScalar(stitchData.fWidth), | 889 pdman.set2f(fStitchDataUni, SkIntToScalar(stitchData.fWidth), |
| 890 SkIntToScalar(stitchData.fHeight)); | 890 SkIntToScalar(stitchData.fHeight)); |
| 891 } | 891 } |
| 892 } | 892 } |
| 893 | 893 |
| 894 ///////////////////////////////////////////////////////////////////// | 894 ///////////////////////////////////////////////////////////////////// |
| 895 const GrFragmentProcessor* SkPerlinNoiseShader::asFragmentProcessor( | 895 const GrFragmentProcessor* SkPerlinNoiseShader::asFragmentProcessor( |
| 896 GrContext* context, | 896 GrContext* context, |
| 897 const SkMatrix& viewM, | 897 const SkMatrix& viewM, |
| 898 const SkMatrix* externalLoca
lMatrix, | 898 const SkMatrix* externalLoc
alMatrix, |
| 899 SkFilterQuality) const { | 899 SkFilterQuality, |
| 900 SkSourceGammaTreatment gamm
aTreatment) const { |
| 900 SkASSERT(context); | 901 SkASSERT(context); |
| 901 | 902 |
| 902 SkMatrix localMatrix = this->getLocalMatrix(); | 903 SkMatrix localMatrix = this->getLocalMatrix(); |
| 903 if (externalLocalMatrix) { | 904 if (externalLocalMatrix) { |
| 904 localMatrix.preConcat(*externalLocalMatrix); | 905 localMatrix.preConcat(*externalLocalMatrix); |
| 905 } | 906 } |
| 906 | 907 |
| 907 SkMatrix matrix = viewM; | 908 SkMatrix matrix = viewM; |
| 908 matrix.preConcat(localMatrix); | 909 matrix.preConcat(localMatrix); |
| 909 | 910 |
| 910 if (0 == fNumOctaves) { | 911 if (0 == fNumOctaves) { |
| 911 if (kFractalNoise_Type == fType) { | 912 if (kFractalNoise_Type == fType) { |
| 912 // Extract the incoming alpha and emit rgba = (a/4, a/4, a/4, a/2) | 913 // Extract the incoming alpha and emit rgba = (a/4, a/4, a/4, a/2) |
| 913 SkAutoTUnref<const GrFragmentProcessor> inner( | 914 SkAutoTUnref<const GrFragmentProcessor> inner( |
| 914 GrConstColorProcessor::Create(0x80404040, | 915 GrConstColorProcessor::Create(0x80404040, |
| 915 GrConstColorProcessor::kModulateRG
BA_InputMode)); | 916 GrConstColorProcessor::kModulateRG
BA_InputMode)); |
| 916 return GrFragmentProcessor::MulOutputByInputAlpha(inner); | 917 return GrFragmentProcessor::MulOutputByInputAlpha(inner); |
| 917 } | 918 } |
| 918 // Emit zero. | 919 // Emit zero. |
| 919 return GrConstColorProcessor::Create(0x0, GrConstColorProcessor::kIgnore
_InputMode); | 920 return GrConstColorProcessor::Create(0x0, GrConstColorProcessor::kIgnore
_InputMode); |
| 920 } | 921 } |
| 921 | 922 |
| 922 // Either we don't stitch tiles, either we have a valid tile size | 923 // Either we don't stitch tiles, either we have a valid tile size |
| 923 SkASSERT(!fStitchTiles || !fTileSize.isEmpty()); | 924 SkASSERT(!fStitchTiles || !fTileSize.isEmpty()); |
| 924 | 925 |
| 925 SkPerlinNoiseShader::PaintingData* paintingData = | 926 SkPerlinNoiseShader::PaintingData* paintingData = |
| 926 new PaintingData(fTileSize, fSeed, fBaseFrequencyX, fBaseFrequencyY,
matrix); | 927 new PaintingData(fTileSize, fSeed, fBaseFrequencyX, fBaseFrequencyY,
matrix); |
| 927 SkAutoTUnref<GrTexture> permutationsTexture( | 928 SkAutoTUnref<GrTexture> permutationsTexture( |
| 928 GrRefCachedBitmapTexture(context, paintingData->getPermutationsBitmap(), | 929 GrRefCachedBitmapTexture(context, paintingData->getPermutationsBitmap(), |
| 929 GrTextureParams::ClampNoFilter())); | 930 GrTextureParams::ClampNoFilter(), gammaTreatmen
t)); |
| 930 SkAutoTUnref<GrTexture> noiseTexture( | 931 SkAutoTUnref<GrTexture> noiseTexture( |
| 931 GrRefCachedBitmapTexture(context, paintingData->getNoiseBitmap(), | 932 GrRefCachedBitmapTexture(context, paintingData->getNoiseBitmap(), |
| 932 GrTextureParams::ClampNoFilter())); | 933 GrTextureParams::ClampNoFilter(), gammaTreatmen
t)); |
| 933 | 934 |
| 934 SkMatrix m = viewM; | 935 SkMatrix m = viewM; |
| 935 m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1); | 936 m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1); |
| 936 m.setTranslateY(-localMatrix.getTranslateY() + SK_Scalar1); | 937 m.setTranslateY(-localMatrix.getTranslateY() + SK_Scalar1); |
| 937 if ((permutationsTexture) && (noiseTexture)) { | 938 if ((permutationsTexture) && (noiseTexture)) { |
| 938 SkAutoTUnref<GrFragmentProcessor> inner( | 939 SkAutoTUnref<GrFragmentProcessor> inner( |
| 939 GrPerlinNoiseEffect::Create(fType, | 940 GrPerlinNoiseEffect::Create(fType, |
| 940 fNumOctaves, | 941 fNumOctaves, |
| 941 fStitchTiles, | 942 fStitchTiles, |
| 942 paintingData, | 943 paintingData, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 975 str->append(" seed: "); | 976 str->append(" seed: "); |
| 976 str->appendScalar(fSeed); | 977 str->appendScalar(fSeed); |
| 977 str->append(" stitch tiles: "); | 978 str->append(" stitch tiles: "); |
| 978 str->append(fStitchTiles ? "true " : "false "); | 979 str->append(fStitchTiles ? "true " : "false "); |
| 979 | 980 |
| 980 this->INHERITED::toString(str); | 981 this->INHERITED::toString(str); |
| 981 | 982 |
| 982 str->append(")"); | 983 str->append(")"); |
| 983 } | 984 } |
| 984 #endif | 985 #endif |
| OLD | NEW |