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

Side by Side Diff: experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.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, 4 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 | « experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.h ('k') | gm/dcshader.cpp » ('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 "SkDither.h" 8 #include "SkDither.h"
9 #include "SkPerlinNoiseShader2.h" 9 #include "SkPerlinNoiseShader2.h"
10 #include "SkColorFilter.h" 10 #include "SkColorFilter.h"
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 SkScalar baseFrequencyY = d->fRandom->nextRangeScalar(0.01f, 721 SkScalar baseFrequencyY = d->fRandom->nextRangeScalar(0.01f,
722 0.99f); 722 0.99f);
723 723
724 sk_sp<SkShader> shader(d->fRandom->nextBool() ? 724 sk_sp<SkShader> shader(d->fRandom->nextBool() ?
725 SkPerlinNoiseShader2::MakeFractalNoise(baseFrequencyX, baseFrequencyY, n umOctaves, seed, 725 SkPerlinNoiseShader2::MakeFractalNoise(baseFrequencyX, baseFrequencyY, n umOctaves, seed,
726 stitchTiles ? &tileSize : nullptr ) : 726 stitchTiles ? &tileSize : nullptr ) :
727 SkPerlinNoiseShader2::MakeTurbulence(baseFrequencyX, baseFrequencyY, num Octaves, seed, 727 SkPerlinNoiseShader2::MakeTurbulence(baseFrequencyX, baseFrequencyY, num Octaves, seed,
728 stitchTiles ? &tileSize : nullptr)) ; 728 stitchTiles ? &tileSize : nullptr)) ;
729 729
730 GrPaint grPaint; 730 GrPaint grPaint;
731 return shader->asFragmentProcessor(d->fContext, 731 SkMatrix viewMatrix = GrTest::TestMatrix(d->fRandom);
732 GrTest::TestMatrix(d->fRandom), nullptr, 732 return shader->asFragmentProcessor(SkShader::AsFPArgs(d->fContext, &viewMatr ix, nullptr,
733 kNone_SkFilterQuality, SkSourceGammaTreat ment::kRespect); 733 kNone_SkFilterQuality,
734 SkSourceGammaTreatment ::kRespect));
734 } 735 }
735 736
736 void GrGLPerlinNoise2::emitCode(EmitArgs& args) { 737 void GrGLPerlinNoise2::emitCode(EmitArgs& args) {
737 const GrPerlinNoise2Effect& pne = args.fFp.cast<GrPerlinNoise2Effect>(); 738 const GrPerlinNoise2Effect& pne = args.fFp.cast<GrPerlinNoise2Effect>();
738 739
739 GrGLSLFragmentBuilder* fsBuilder = args.fFragBuilder; 740 GrGLSLFragmentBuilder* fsBuilder = args.fFragBuilder;
740 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; 741 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
741 SkString vCoords = fsBuilder->ensureFSCoords2D(args.fCoords, 0); 742 SkString vCoords = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
742 743
743 fBaseFrequencyUni = uniformHandler->addUniform(kFragment_GrShaderFlag, 744 fBaseFrequencyUni = uniformHandler->addUniform(kFragment_GrShaderFlag,
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
1128 0.99f); 1129 0.99f);
1129 int numOctaves = d->fRandom->nextRangeU(2, 10); 1130 int numOctaves = d->fRandom->nextRangeU(2, 10);
1130 SkScalar z = SkIntToScalar(d->fRandom->nextU()); 1131 SkScalar z = SkIntToScalar(d->fRandom->nextU());
1131 1132
1132 sk_sp<SkShader> shader(SkPerlinNoiseShader2::MakeImprovedNoise(baseFrequency X, 1133 sk_sp<SkShader> shader(SkPerlinNoiseShader2::MakeImprovedNoise(baseFrequency X,
1133 baseFrequency Y, 1134 baseFrequency Y,
1134 numOctaves, 1135 numOctaves,
1135 z)); 1136 z));
1136 1137
1137 GrPaint grPaint; 1138 GrPaint grPaint;
1138 return shader->asFragmentProcessor(d->fContext, 1139 SkMatrix viewMatrix = GrTest::TestMatrix(d->fRandom);
1139 GrTest::TestMatrix(d->fRandom), nullptr, 1140 return shader->asFragmentProcessor(SkShader::AsFPArgs(d->fContext, &viewMatr ix, nullptr,
1140 kNone_SkFilterQuality, SkSourceGammaTreat ment::kRespect); 1141 kNone_SkFilterQuality,
1142 SkSourceGammaTreatment ::kRespect));
1141 } 1143 }
1142 1144
1143 void GrGLImprovedPerlinNoise::emitCode(EmitArgs& args) { 1145 void GrGLImprovedPerlinNoise::emitCode(EmitArgs& args) {
1144 GrGLSLFragmentBuilder* fsBuilder = args.fFragBuilder; 1146 GrGLSLFragmentBuilder* fsBuilder = args.fFragBuilder;
1145 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; 1147 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
1146 SkString vCoords = fsBuilder->ensureFSCoords2D(args.fCoords, 0); 1148 SkString vCoords = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
1147 1149
1148 fBaseFrequencyUni = uniformHandler->addUniform(kFragment_GrShaderFlag, 1150 fBaseFrequencyUni = uniformHandler->addUniform(kFragment_GrShaderFlag,
1149 kVec2f_GrSLType, kDefault_GrS LPrecision, 1151 kVec2f_GrSLType, kDefault_GrS LPrecision,
1150 "baseFrequency"); 1152 "baseFrequency");
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 1296
1295 const SkVector& baseFrequency = noise.baseFrequency(); 1297 const SkVector& baseFrequency = noise.baseFrequency();
1296 pdman.set2f(fBaseFrequencyUni, baseFrequency.fX, baseFrequency.fY); 1298 pdman.set2f(fBaseFrequencyUni, baseFrequency.fX, baseFrequency.fY);
1297 1299
1298 pdman.set1f(fOctavesUni, SkIntToScalar(noise.octaves())); 1300 pdman.set1f(fOctavesUni, SkIntToScalar(noise.octaves()));
1299 1301
1300 pdman.set1f(fZUni, noise.z()); 1302 pdman.set1f(fZUni, noise.z());
1301 } 1303 }
1302 1304
1303 ///////////////////////////////////////////////////////////////////// 1305 /////////////////////////////////////////////////////////////////////
1304 sk_sp<GrFragmentProcessor> SkPerlinNoiseShader2::asFragmentProcessor( 1306 sk_sp<GrFragmentProcessor> SkPerlinNoiseShader2::asFragmentProcessor(const AsFPA rgs& args) const {
1305 GrContext* context, 1307 SkASSERT(args.fContext);
1306 const SkMatrix& viewM,
1307 const SkMatrix* externalLoca lMatrix,
1308 SkFilterQuality,
1309 SkSourceGammaTreatment gamma Treatment) const {
1310 SkASSERT(context);
1311 1308
1312 SkMatrix localMatrix = this->getLocalMatrix(); 1309 SkMatrix localMatrix = this->getLocalMatrix();
1313 if (externalLocalMatrix) { 1310 if (args.fLocalMatrix) {
1314 localMatrix.preConcat(*externalLocalMatrix); 1311 localMatrix.preConcat(*args.fLocalMatrix);
1315 } 1312 }
1316 1313
1317 SkMatrix matrix = viewM; 1314 SkMatrix matrix = *args.fViewMatrix;
1318 matrix.preConcat(localMatrix); 1315 matrix.preConcat(localMatrix);
1319 1316
1320 // Either we don't stitch tiles, either we have a valid tile size 1317 // Either we don't stitch tiles, either we have a valid tile size
1321 SkASSERT(!fStitchTiles || !fTileSize.isEmpty()); 1318 SkASSERT(!fStitchTiles || !fTileSize.isEmpty());
1322 1319
1323 SkPerlinNoiseShader2::PaintingData* paintingData = 1320 SkPerlinNoiseShader2::PaintingData* paintingData =
1324 new PaintingData(fTileSize, fSeed, fBaseFrequencyX, fBaseFrequencyY, matrix); 1321 new PaintingData(fTileSize, fSeed, fBaseFrequencyX, fBaseFrequencyY, matrix);
1325 1322
1326 SkMatrix m = viewM; 1323 SkMatrix m = *args.fViewMatrix;
1327 m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1); 1324 m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1);
1328 m.setTranslateY(-localMatrix.getTranslateY() + SK_Scalar1); 1325 m.setTranslateY(-localMatrix.getTranslateY() + SK_Scalar1);
1329 1326
1330 if (fType == kImprovedNoise_Type) { 1327 if (fType == kImprovedNoise_Type) {
1331 GrTextureParams textureParams(SkShader::TileMode::kRepeat_TileMode, 1328 GrTextureParams textureParams(SkShader::TileMode::kRepeat_TileMode,
1332 GrTextureParams::FilterMode::kNone_FilterM ode); 1329 GrTextureParams::FilterMode::kNone_FilterM ode);
1333 SkAutoTUnref<GrTexture> permutationsTexture( 1330 SkAutoTUnref<GrTexture> permutationsTexture(
1334 GrRefCachedBitmapTexture(context, paintingData->getImprovedPermutati onsBitmap(), 1331 GrRefCachedBitmapTexture(args.fContext, paintingData->getImprovedPer mutationsBitmap(),
1335 textureParams, gammaTreatment)); 1332 textureParams, args.fGammaTreatment));
1336 SkAutoTUnref<GrTexture> gradientTexture( 1333 SkAutoTUnref<GrTexture> gradientTexture(
1337 GrRefCachedBitmapTexture(context, paintingData->getGradientBitmap(), 1334 GrRefCachedBitmapTexture(args.fContext, paintingData->getGradientBit map(),
1338 textureParams, gammaTreatment)); 1335 textureParams, args.fGammaTreatment));
1339 return GrImprovedPerlinNoiseEffect::Make(fNumOctaves, fSeed, paintingDat a, 1336 return GrImprovedPerlinNoiseEffect::Make(fNumOctaves, fSeed, paintingDat a,
1340 permutationsTexture, gradient Texture, m); 1337 permutationsTexture, gradient Texture, m);
1341 } 1338 }
1342 1339
1343 if (0 == fNumOctaves) { 1340 if (0 == fNumOctaves) {
1344 if (kFractalNoise_Type == fType) { 1341 if (kFractalNoise_Type == fType) {
1345 // Extract the incoming alpha and emit rgba = (a/4, a/4, a/4, a/2) 1342 // Extract the incoming alpha and emit rgba = (a/4, a/4, a/4, a/2)
1346 sk_sp<GrFragmentProcessor> inner( 1343 sk_sp<GrFragmentProcessor> inner(
1347 GrConstColorProcessor::Make(0x80404040, 1344 GrConstColorProcessor::Make(0x80404040,
1348 GrConstColorProcessor::kModulateRGBA _InputMode)); 1345 GrConstColorProcessor::kModulateRGBA _InputMode));
1349 return GrFragmentProcessor::MulOutputByInputAlpha(std::move(inner)); 1346 return GrFragmentProcessor::MulOutputByInputAlpha(std::move(inner));
1350 } 1347 }
1351 // Emit zero. 1348 // Emit zero.
1352 return GrConstColorProcessor::Make(0x0, GrConstColorProcessor::kIgnore_I nputMode); 1349 return GrConstColorProcessor::Make(0x0, GrConstColorProcessor::kIgnore_I nputMode);
1353 } 1350 }
1354 1351
1355 SkAutoTUnref<GrTexture> permutationsTexture( 1352 SkAutoTUnref<GrTexture> permutationsTexture(
1356 GrRefCachedBitmapTexture(context, paintingData->getPermutationsBitmap(), 1353 GrRefCachedBitmapTexture(args.fContext, paintingData->getPermutationsBit map(),
1357 GrTextureParams::ClampNoFilter(), gammaTreatmen t)); 1354 GrTextureParams::ClampNoFilter(), args.fGammaTr eatment));
1358 SkAutoTUnref<GrTexture> noiseTexture( 1355 SkAutoTUnref<GrTexture> noiseTexture(
1359 GrRefCachedBitmapTexture(context, paintingData->getNoiseBitmap(), 1356 GrRefCachedBitmapTexture(args.fContext, paintingData->getNoiseBitmap(),
1360 GrTextureParams::ClampNoFilter(), gammaTreatmen t)); 1357 GrTextureParams::ClampNoFilter(), args.fGammaTr eatment));
1361 1358
1362 if ((permutationsTexture) && (noiseTexture)) { 1359 if ((permutationsTexture) && (noiseTexture)) {
1363 sk_sp<GrFragmentProcessor> inner( 1360 sk_sp<GrFragmentProcessor> inner(
1364 GrPerlinNoise2Effect::Make(fType, 1361 GrPerlinNoise2Effect::Make(fType,
1365 fNumOctaves, 1362 fNumOctaves,
1366 fStitchTiles, 1363 fStitchTiles,
1367 paintingData, 1364 paintingData,
1368 permutationsTexture, noiseTexture, 1365 permutationsTexture, noiseTexture,
1369 m)); 1366 m));
1370 return GrFragmentProcessor::MulOutputByInputAlpha(std::move(inner)); 1367 return GrFragmentProcessor::MulOutputByInputAlpha(std::move(inner));
(...skipping 29 matching lines...) Expand all
1400 str->append(" seed: "); 1397 str->append(" seed: ");
1401 str->appendScalar(fSeed); 1398 str->appendScalar(fSeed);
1402 str->append(" stitch tiles: "); 1399 str->append(" stitch tiles: ");
1403 str->append(fStitchTiles ? "true " : "false "); 1400 str->append(fStitchTiles ? "true " : "false ");
1404 1401
1405 this->INHERITED::toString(str); 1402 this->INHERITED::toString(str);
1406 1403
1407 str->append(")"); 1404 str->append(")");
1408 } 1405 }
1409 #endif 1406 #endif
OLDNEW
« no previous file with comments | « experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.h ('k') | gm/dcshader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698