Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: src/effects/SkPerlinNoiseShader.cpp

Issue 2175563003: Bundle SkShader::asFragmentProcessor arguments in a struct (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix indentation to be less arbitrary Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkShader.cpp ('k') | src/effects/gradients/SkLinearGradient.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 0.99f); 585 0.99f);
586 SkScalar baseFrequencyY = d->fRandom->nextRangeScalar(0.01f, 586 SkScalar baseFrequencyY = d->fRandom->nextRangeScalar(0.01f,
587 0.99f); 587 0.99f);
588 588
589 sk_sp<SkShader> shader(d->fRandom->nextBool() ? 589 sk_sp<SkShader> shader(d->fRandom->nextBool() ?
590 SkPerlinNoiseShader::MakeFractalNoise(baseFrequencyX, baseFrequencyY, nu mOctaves, seed, 590 SkPerlinNoiseShader::MakeFractalNoise(baseFrequencyX, baseFrequencyY, nu mOctaves, seed,
591 stitchTiles ? &tileSize : nullptr) : 591 stitchTiles ? &tileSize : nullptr) :
592 SkPerlinNoiseShader::MakeTurbulence(baseFrequencyX, baseFrequencyY, numO ctaves, seed, 592 SkPerlinNoiseShader::MakeTurbulence(baseFrequencyX, baseFrequencyY, numO ctaves, seed,
593 stitchTiles ? &tileSize : nullptr)); 593 stitchTiles ? &tileSize : nullptr));
594 594
595 return shader->asFragmentProcessor(d->fContext, 595 SkMatrix viewMatrix = GrTest::TestMatrix(d->fRandom);
596 GrTest::TestMatrix(d->fRandom), nullptr, 596 return shader->asFragmentProcessor(SkShader::AsFPArgs(d->fContext, &viewMatr ix, nullptr,
597 kNone_SkFilterQuality, SkSourceGammaTreat ment::kRespect); 597 kNone_SkFilterQuality,
598 SkSourceGammaTreatment ::kRespect));
598 } 599 }
599 600
600 void GrGLPerlinNoise::emitCode(EmitArgs& args) { 601 void GrGLPerlinNoise::emitCode(EmitArgs& args) {
601 const GrPerlinNoiseEffect& pne = args.fFp.cast<GrPerlinNoiseEffect>(); 602 const GrPerlinNoiseEffect& pne = args.fFp.cast<GrPerlinNoiseEffect>();
602 603
603 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; 604 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
604 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; 605 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
605 SkString vCoords = fragBuilder->ensureFSCoords2D(args.fCoords, 0); 606 SkString vCoords = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
606 607
607 fBaseFrequencyUni = uniformHandler->addUniform(kFragment_GrShaderFlag, 608 fBaseFrequencyUni = uniformHandler->addUniform(kFragment_GrShaderFlag,
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 pdman.set2f(fBaseFrequencyUni, baseFrequency.fX, baseFrequency.fY); 887 pdman.set2f(fBaseFrequencyUni, baseFrequency.fX, baseFrequency.fY);
887 888
888 if (turbulence.stitchTiles()) { 889 if (turbulence.stitchTiles()) {
889 const SkPerlinNoiseShader::StitchData& stitchData = turbulence.stitchDat a(); 890 const SkPerlinNoiseShader::StitchData& stitchData = turbulence.stitchDat a();
890 pdman.set2f(fStitchDataUni, SkIntToScalar(stitchData.fWidth), 891 pdman.set2f(fStitchDataUni, SkIntToScalar(stitchData.fWidth),
891 SkIntToScalar(stitchData.fHeight)); 892 SkIntToScalar(stitchData.fHeight));
892 } 893 }
893 } 894 }
894 895
895 ///////////////////////////////////////////////////////////////////// 896 /////////////////////////////////////////////////////////////////////
896 sk_sp<GrFragmentProcessor> SkPerlinNoiseShader::asFragmentProcessor( 897 sk_sp<GrFragmentProcessor> SkPerlinNoiseShader::asFragmentProcessor(const AsFPAr gs& args) const {
897 GrContext* context, 898 SkASSERT(args.fContext);
898 const SkMatrix& viewM,
899 const SkMatrix* externalLoc alMatrix,
900 SkFilterQuality,
901 SkSourceGammaTreatment gamm aTreatment) const {
902 SkASSERT(context);
903 899
904 SkMatrix localMatrix = this->getLocalMatrix(); 900 SkMatrix localMatrix = this->getLocalMatrix();
905 if (externalLocalMatrix) { 901 if (args.fLocalMatrix) {
906 localMatrix.preConcat(*externalLocalMatrix); 902 localMatrix.preConcat(*args.fLocalMatrix);
907 } 903 }
908 904
909 SkMatrix matrix = viewM; 905 SkMatrix matrix = *args.fViewMatrix;
910 matrix.preConcat(localMatrix); 906 matrix.preConcat(localMatrix);
911 907
912 if (0 == fNumOctaves) { 908 if (0 == fNumOctaves) {
913 if (kFractalNoise_Type == fType) { 909 if (kFractalNoise_Type == fType) {
914 // Extract the incoming alpha and emit rgba = (a/4, a/4, a/4, a/2) 910 // Extract the incoming alpha and emit rgba = (a/4, a/4, a/4, a/2)
915 sk_sp<GrFragmentProcessor> inner( 911 sk_sp<GrFragmentProcessor> inner(
916 GrConstColorProcessor::Make(0x80404040, 912 GrConstColorProcessor::Make(0x80404040,
917 GrConstColorProcessor::kModulateRGBA _InputMode)); 913 GrConstColorProcessor::kModulateRGBA _InputMode));
918 return GrFragmentProcessor::MulOutputByInputAlpha(std::move(inner)); 914 return GrFragmentProcessor::MulOutputByInputAlpha(std::move(inner));
919 } 915 }
920 // Emit zero. 916 // Emit zero.
921 return GrConstColorProcessor::Make(0x0, GrConstColorProcessor::kIgnore_I nputMode); 917 return GrConstColorProcessor::Make(0x0, GrConstColorProcessor::kIgnore_I nputMode);
922 } 918 }
923 919
924 // Either we don't stitch tiles, either we have a valid tile size 920 // Either we don't stitch tiles, either we have a valid tile size
925 SkASSERT(!fStitchTiles || !fTileSize.isEmpty()); 921 SkASSERT(!fStitchTiles || !fTileSize.isEmpty());
926 922
927 SkPerlinNoiseShader::PaintingData* paintingData = 923 SkPerlinNoiseShader::PaintingData* paintingData =
928 new PaintingData(fTileSize, fSeed, fBaseFrequencyX, fBaseFrequencyY, matrix); 924 new PaintingData(fTileSize, fSeed, fBaseFrequencyX, fBaseFrequencyY, matrix);
929 SkAutoTUnref<GrTexture> permutationsTexture( 925 SkAutoTUnref<GrTexture> permutationsTexture(
930 GrRefCachedBitmapTexture(context, paintingData->getPermutationsBitmap(), 926 GrRefCachedBitmapTexture(args.fContext, paintingData->getPermutationsBit map(),
931 GrTextureParams::ClampNoFilter(), gammaTreatmen t)); 927 GrTextureParams::ClampNoFilter(), args.fGammaTr eatment));
932 SkAutoTUnref<GrTexture> noiseTexture( 928 SkAutoTUnref<GrTexture> noiseTexture(
933 GrRefCachedBitmapTexture(context, paintingData->getNoiseBitmap(), 929 GrRefCachedBitmapTexture(args.fContext, paintingData->getNoiseBitmap(),
934 GrTextureParams::ClampNoFilter(), gammaTreatmen t)); 930 GrTextureParams::ClampNoFilter(), args.fGammaTr eatment));
935 931
936 SkMatrix m = viewM; 932 SkMatrix m = *args.fViewMatrix;
937 m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1); 933 m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1);
938 m.setTranslateY(-localMatrix.getTranslateY() + SK_Scalar1); 934 m.setTranslateY(-localMatrix.getTranslateY() + SK_Scalar1);
939 if ((permutationsTexture) && (noiseTexture)) { 935 if ((permutationsTexture) && (noiseTexture)) {
940 sk_sp<GrFragmentProcessor> inner( 936 sk_sp<GrFragmentProcessor> inner(
941 GrPerlinNoiseEffect::Make(fType, 937 GrPerlinNoiseEffect::Make(fType,
942 fNumOctaves, 938 fNumOctaves,
943 fStitchTiles, 939 fStitchTiles,
944 paintingData, 940 paintingData,
945 permutationsTexture, noiseTexture, 941 permutationsTexture, noiseTexture,
946 m)); 942 m));
(...skipping 30 matching lines...) Expand all
977 str->append(" seed: "); 973 str->append(" seed: ");
978 str->appendScalar(fSeed); 974 str->appendScalar(fSeed);
979 str->append(" stitch tiles: "); 975 str->append(" stitch tiles: ");
980 str->append(fStitchTiles ? "true " : "false "); 976 str->append(fStitchTiles ? "true " : "false ");
981 977
982 this->INHERITED::toString(str); 978 this->INHERITED::toString(str);
983 979
984 str->append(")"); 980 str->append(")");
985 } 981 }
986 #endif 982 #endif
OLDNEW
« no previous file with comments | « src/core/SkShader.cpp ('k') | src/effects/gradients/SkLinearGradient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698