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

Side by Side Diff: experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp

Issue 2037413002: Add SkSourceGammaTreatment enum so we know how to create mips (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix DM compilation Created 4 years, 6 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 711 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 722
723 sk_sp<SkShader> shader(d->fRandom->nextBool() ? 723 sk_sp<SkShader> shader(d->fRandom->nextBool() ?
724 SkPerlinNoiseShader2::MakeFractalNoise(baseFrequencyX, baseFrequencyY, n umOctaves, seed, 724 SkPerlinNoiseShader2::MakeFractalNoise(baseFrequencyX, baseFrequencyY, n umOctaves, seed,
725 stitchTiles ? &tileSize : nullptr ) : 725 stitchTiles ? &tileSize : nullptr ) :
726 SkPerlinNoiseShader2::MakeTurbulence(baseFrequencyX, baseFrequencyY, num Octaves, seed, 726 SkPerlinNoiseShader2::MakeTurbulence(baseFrequencyX, baseFrequencyY, num Octaves, seed,
727 stitchTiles ? &tileSize : nullptr)) ; 727 stitchTiles ? &tileSize : nullptr)) ;
728 728
729 GrPaint grPaint; 729 GrPaint grPaint;
730 return shader->asFragmentProcessor(d->fContext, 730 return shader->asFragmentProcessor(d->fContext,
731 GrTest::TestMatrix(d->fRandom), nullptr, 731 GrTest::TestMatrix(d->fRandom), nullptr,
732 kNone_SkFilterQuality); 732 kNone_SkFilterQuality, SkSourceGammaTreat ment::kRespect);
733 } 733 }
734 734
735 void GrGLPerlinNoise2::emitCode(EmitArgs& args) { 735 void GrGLPerlinNoise2::emitCode(EmitArgs& args) {
736 const GrPerlinNoise2Effect& pne = args.fFp.cast<GrPerlinNoise2Effect>(); 736 const GrPerlinNoise2Effect& pne = args.fFp.cast<GrPerlinNoise2Effect>();
737 737
738 GrGLSLFragmentBuilder* fsBuilder = args.fFragBuilder; 738 GrGLSLFragmentBuilder* fsBuilder = args.fFragBuilder;
739 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; 739 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
740 SkString vCoords = fsBuilder->ensureFSCoords2D(args.fCoords, 0); 740 SkString vCoords = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
741 741
742 fBaseFrequencyUni = uniformHandler->addUniform(kFragment_GrShaderFlag, 742 fBaseFrequencyUni = uniformHandler->addUniform(kFragment_GrShaderFlag,
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 SkScalar z = SkIntToScalar(d->fRandom->nextU()); 1127 SkScalar z = SkIntToScalar(d->fRandom->nextU());
1128 1128
1129 sk_sp<SkShader> shader(SkPerlinNoiseShader2::MakeImprovedNoise(baseFrequency X, 1129 sk_sp<SkShader> shader(SkPerlinNoiseShader2::MakeImprovedNoise(baseFrequency X,
1130 baseFrequency Y, 1130 baseFrequency Y,
1131 numOctaves, 1131 numOctaves,
1132 z)); 1132 z));
1133 1133
1134 GrPaint grPaint; 1134 GrPaint grPaint;
1135 return shader->asFragmentProcessor(d->fContext, 1135 return shader->asFragmentProcessor(d->fContext,
1136 GrTest::TestMatrix(d->fRandom), nullptr, 1136 GrTest::TestMatrix(d->fRandom), nullptr,
1137 kNone_SkFilterQuality); 1137 kNone_SkFilterQuality, SkSourceGammaTreat ment::kRespect);
1138 } 1138 }
1139 1139
1140 void GrGLImprovedPerlinNoise::emitCode(EmitArgs& args) { 1140 void GrGLImprovedPerlinNoise::emitCode(EmitArgs& args) {
1141 GrGLSLFragmentBuilder* fsBuilder = args.fFragBuilder; 1141 GrGLSLFragmentBuilder* fsBuilder = args.fFragBuilder;
1142 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; 1142 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
1143 SkString vCoords = fsBuilder->ensureFSCoords2D(args.fCoords, 0); 1143 SkString vCoords = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
1144 1144
1145 fBaseFrequencyUni = uniformHandler->addUniform(kFragment_GrShaderFlag, 1145 fBaseFrequencyUni = uniformHandler->addUniform(kFragment_GrShaderFlag,
1146 kVec2f_GrSLType, kDefault_GrS LPrecision, 1146 kVec2f_GrSLType, kDefault_GrS LPrecision,
1147 "baseFrequency"); 1147 "baseFrequency");
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1295 pdman.set1f(fOctavesUni, SkIntToScalar(noise.octaves())); 1295 pdman.set1f(fOctavesUni, SkIntToScalar(noise.octaves()));
1296 1296
1297 pdman.set1f(fZUni, noise.z()); 1297 pdman.set1f(fZUni, noise.z());
1298 } 1298 }
1299 1299
1300 ///////////////////////////////////////////////////////////////////// 1300 /////////////////////////////////////////////////////////////////////
1301 const GrFragmentProcessor* SkPerlinNoiseShader2::asFragmentProcessor( 1301 const GrFragmentProcessor* SkPerlinNoiseShader2::asFragmentProcessor(
1302 GrContext* context, 1302 GrContext* context,
1303 const SkMatrix& viewM, 1303 const SkMatrix& viewM,
1304 const SkMatrix* externalLoca lMatrix, 1304 const SkMatrix* externalLoca lMatrix,
1305 SkFilterQuality) const { 1305 SkFilterQuality,
1306 SkSourceGammaTreatment gamma Treatment) const {
1306 SkASSERT(context); 1307 SkASSERT(context);
1307 1308
1308 SkMatrix localMatrix = this->getLocalMatrix(); 1309 SkMatrix localMatrix = this->getLocalMatrix();
1309 if (externalLocalMatrix) { 1310 if (externalLocalMatrix) {
1310 localMatrix.preConcat(*externalLocalMatrix); 1311 localMatrix.preConcat(*externalLocalMatrix);
1311 } 1312 }
1312 1313
1313 SkMatrix matrix = viewM; 1314 SkMatrix matrix = viewM;
1314 matrix.preConcat(localMatrix); 1315 matrix.preConcat(localMatrix);
1315 1316
1316 // 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
1317 SkASSERT(!fStitchTiles || !fTileSize.isEmpty()); 1318 SkASSERT(!fStitchTiles || !fTileSize.isEmpty());
1318 1319
1319 SkPerlinNoiseShader2::PaintingData* paintingData = 1320 SkPerlinNoiseShader2::PaintingData* paintingData =
1320 new PaintingData(fTileSize, fSeed, fBaseFrequencyX, fBaseFrequencyY, matrix); 1321 new PaintingData(fTileSize, fSeed, fBaseFrequencyX, fBaseFrequencyY, matrix);
1321 1322
1322 SkMatrix m = viewM; 1323 SkMatrix m = viewM;
1323 m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1); 1324 m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1);
1324 m.setTranslateY(-localMatrix.getTranslateY() + SK_Scalar1); 1325 m.setTranslateY(-localMatrix.getTranslateY() + SK_Scalar1);
1325 1326
1326 if (fType == kImprovedNoise_Type) { 1327 if (fType == kImprovedNoise_Type) {
1327 GrTextureParams textureParams(SkShader::TileMode::kRepeat_TileMode, 1328 GrTextureParams textureParams(SkShader::TileMode::kRepeat_TileMode,
1328 GrTextureParams::FilterMode::kNone_FilterM ode); 1329 GrTextureParams::FilterMode::kNone_FilterM ode);
1329 SkAutoTUnref<GrTexture> permutationsTexture( 1330 SkAutoTUnref<GrTexture> permutationsTexture(
1330 GrRefCachedBitmapTexture(context, paintingData->getImprovedPermutati onsBitmap(), 1331 GrRefCachedBitmapTexture(context, paintingData->getImprovedPermutati onsBitmap(),
1331 textureParams)); 1332 textureParams, gammaTreatment));
1332 SkAutoTUnref<GrTexture> gradientTexture( 1333 SkAutoTUnref<GrTexture> gradientTexture(
1333 GrRefCachedBitmapTexture(context, paintingData->getGradientBitmap(), 1334 GrRefCachedBitmapTexture(context, paintingData->getGradientBitmap(),
1334 textureParams)); 1335 textureParams, gammaTreatment));
1335 return GrImprovedPerlinNoiseEffect::Create(fNumOctaves, fSeed, paintingD ata, 1336 return GrImprovedPerlinNoiseEffect::Create(fNumOctaves, fSeed, paintingD ata,
1336 permutationsTexture, gradient Texture, m); 1337 permutationsTexture, gradient Texture, m);
1337 } 1338 }
1338 1339
1339 if (0 == fNumOctaves) { 1340 if (0 == fNumOctaves) {
1340 if (kFractalNoise_Type == fType) { 1341 if (kFractalNoise_Type == fType) {
1341 // 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)
1342 SkAutoTUnref<const GrFragmentProcessor> inner( 1343 SkAutoTUnref<const GrFragmentProcessor> inner(
1343 GrConstColorProcessor::Create(0x80404040, 1344 GrConstColorProcessor::Create(0x80404040,
1344 GrConstColorProcessor::kModulateRG BA_InputMode)); 1345 GrConstColorProcessor::kModulateRG BA_InputMode));
1345 return GrFragmentProcessor::MulOutputByInputAlpha(inner); 1346 return GrFragmentProcessor::MulOutputByInputAlpha(inner);
1346 } 1347 }
1347 // Emit zero. 1348 // Emit zero.
1348 return GrConstColorProcessor::Create(0x0, GrConstColorProcessor::kIgnore _InputMode); 1349 return GrConstColorProcessor::Create(0x0, GrConstColorProcessor::kIgnore _InputMode);
1349 } 1350 }
1350 1351
1351 SkAutoTUnref<GrTexture> permutationsTexture( 1352 SkAutoTUnref<GrTexture> permutationsTexture(
1352 GrRefCachedBitmapTexture(context, paintingData->getPermutationsBitmap(), 1353 GrRefCachedBitmapTexture(context, paintingData->getPermutationsBitmap(),
1353 GrTextureParams::ClampNoFilter())); 1354 GrTextureParams::ClampNoFilter(), gammaTreatmen t));
1354 SkAutoTUnref<GrTexture> noiseTexture( 1355 SkAutoTUnref<GrTexture> noiseTexture(
1355 GrRefCachedBitmapTexture(context, paintingData->getNoiseBitmap(), 1356 GrRefCachedBitmapTexture(context, paintingData->getNoiseBitmap(),
1356 GrTextureParams::ClampNoFilter())); 1357 GrTextureParams::ClampNoFilter(), gammaTreatmen t));
1357 1358
1358 if ((permutationsTexture) && (noiseTexture)) { 1359 if ((permutationsTexture) && (noiseTexture)) {
1359 SkAutoTUnref<GrFragmentProcessor> inner( 1360 SkAutoTUnref<GrFragmentProcessor> inner(
1360 GrPerlinNoise2Effect::Create(fType, 1361 GrPerlinNoise2Effect::Create(fType,
1361 fNumOctaves, 1362 fNumOctaves,
1362 fStitchTiles, 1363 fStitchTiles,
1363 paintingData, 1364 paintingData,
1364 permutationsTexture, noiseTexture, 1365 permutationsTexture, noiseTexture,
1365 m)); 1366 m));
1366 return GrFragmentProcessor::MulOutputByInputAlpha(inner); 1367 return GrFragmentProcessor::MulOutputByInputAlpha(inner);
(...skipping 29 matching lines...) Expand all
1396 str->append(" seed: "); 1397 str->append(" seed: ");
1397 str->appendScalar(fSeed); 1398 str->appendScalar(fSeed);
1398 str->append(" stitch tiles: "); 1399 str->append(" stitch tiles: ");
1399 str->append(fStitchTiles ? "true " : "false "); 1400 str->append(fStitchTiles ? "true " : "false ");
1400 1401
1401 this->INHERITED::toString(str); 1402 this->INHERITED::toString(str);
1402 1403
1403 str->append(")"); 1404 str->append(")");
1404 } 1405 }
1405 #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