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

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

Issue 2041113004: sk_sp for gpu. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Reserve correctly. 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/beziereffects.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 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 GrGLSLProgramDataManager::UniformHandle fStitchDataUni; 623 GrGLSLProgramDataManager::UniformHandle fStitchDataUni;
624 GrGLSLProgramDataManager::UniformHandle fBaseFrequencyUni; 624 GrGLSLProgramDataManager::UniformHandle fBaseFrequencyUni;
625 625
626 typedef GrGLSLFragmentProcessor INHERITED; 626 typedef GrGLSLFragmentProcessor INHERITED;
627 }; 627 };
628 628
629 ///////////////////////////////////////////////////////////////////// 629 /////////////////////////////////////////////////////////////////////
630 630
631 class GrPerlinNoise2Effect : public GrFragmentProcessor { 631 class GrPerlinNoise2Effect : public GrFragmentProcessor {
632 public: 632 public:
633 static GrFragmentProcessor* Create(SkPerlinNoiseShader2::Type type, 633 static sk_sp<GrFragmentProcessor> Make(SkPerlinNoiseShader2::Type type,
634 int numOctaves, bool stitchTiles, 634 int numOctaves, bool stitchTiles,
635 SkPerlinNoiseShader2::PaintingData* paint ingData, 635 SkPerlinNoiseShader2::PaintingData* p aintingData,
636 GrTexture* permutationsTexture, GrTexture * noiseTexture, 636 GrTexture* permutationsTexture, GrTex ture* noiseTexture,
637 const SkMatrix& matrix) { 637 const SkMatrix& matrix) {
638 return new GrPerlinNoise2Effect(type, numOctaves, stitchTiles, paintingD ata, 638 return sk_sp<GrFragmentProcessor>(
639 permutationsTexture, noiseTexture, matrix ); 639 new GrPerlinNoise2Effect(type, numOctaves, stitchTiles, paintingData ,
640 permutationsTexture, noiseTexture, matrix)) ;
640 } 641 }
641 642
642 virtual ~GrPerlinNoise2Effect() { delete fPaintingData; } 643 virtual ~GrPerlinNoise2Effect() { delete fPaintingData; }
643 644
644 const char* name() const override { return "PerlinNoise"; } 645 const char* name() const override { return "PerlinNoise"; }
645 646
646 const SkPerlinNoiseShader2::StitchData& stitchData() const { return fPaintin gData->fStitchDataInit; } 647 const SkPerlinNoiseShader2::StitchData& stitchData() const { return fPaintin gData->fStitchDataInit; }
647 648
648 SkPerlinNoiseShader2::Type type() const { return fType; } 649 SkPerlinNoiseShader2::Type type() const { return fType; }
649 bool stitchTiles() const { return fStitchTiles; } 650 bool stitchTiles() const { return fStitchTiles; }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 GrTextureAccess fNoiseAccess; 703 GrTextureAccess fNoiseAccess;
703 SkPerlinNoiseShader2::PaintingData *fPaintingData; 704 SkPerlinNoiseShader2::PaintingData *fPaintingData;
704 705
705 private: 706 private:
706 typedef GrFragmentProcessor INHERITED; 707 typedef GrFragmentProcessor INHERITED;
707 }; 708 };
708 709
709 ///////////////////////////////////////////////////////////////////// 710 /////////////////////////////////////////////////////////////////////
710 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrPerlinNoise2Effect); 711 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrPerlinNoise2Effect);
711 712
712 const GrFragmentProcessor* GrPerlinNoise2Effect::TestCreate(GrProcessorTestData* d) { 713 sk_sp<GrFragmentProcessor> GrPerlinNoise2Effect::TestCreate(GrProcessorTestData* d) {
713 int numOctaves = d->fRandom->nextRangeU(2, 10); 714 int numOctaves = d->fRandom->nextRangeU(2, 10);
714 bool stitchTiles = d->fRandom->nextBool(); 715 bool stitchTiles = d->fRandom->nextBool();
715 SkScalar seed = SkIntToScalar(d->fRandom->nextU()); 716 SkScalar seed = SkIntToScalar(d->fRandom->nextU());
716 SkISize tileSize = SkISize::Make(d->fRandom->nextRangeU(4, 4096), 717 SkISize tileSize = SkISize::Make(d->fRandom->nextRangeU(4, 4096),
717 d->fRandom->nextRangeU(4, 4096)); 718 d->fRandom->nextRangeU(4, 4096));
718 SkScalar baseFrequencyX = d->fRandom->nextRangeScalar(0.01f, 719 SkScalar baseFrequencyX = d->fRandom->nextRangeScalar(0.01f,
719 0.99f); 720 0.99f);
720 SkScalar baseFrequencyY = d->fRandom->nextRangeScalar(0.01f, 721 SkScalar baseFrequencyY = d->fRandom->nextRangeScalar(0.01f,
721 0.99f); 722 0.99f);
722 723
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 GrGLSLProgramDataManager::UniformHandle fOctavesUni; 1044 GrGLSLProgramDataManager::UniformHandle fOctavesUni;
1044 GrGLSLProgramDataManager::UniformHandle fBaseFrequencyUni; 1045 GrGLSLProgramDataManager::UniformHandle fBaseFrequencyUni;
1045 1046
1046 typedef GrGLSLFragmentProcessor INHERITED; 1047 typedef GrGLSLFragmentProcessor INHERITED;
1047 }; 1048 };
1048 1049
1049 ///////////////////////////////////////////////////////////////////// 1050 /////////////////////////////////////////////////////////////////////
1050 1051
1051 class GrImprovedPerlinNoiseEffect : public GrFragmentProcessor { 1052 class GrImprovedPerlinNoiseEffect : public GrFragmentProcessor {
1052 public: 1053 public:
1053 static GrFragmentProcessor* Create(int octaves, SkScalar z, 1054 static sk_sp<GrFragmentProcessor> Make(int octaves, SkScalar z,
1054 SkPerlinNoiseShader2::PaintingData* paint ingData, 1055 SkPerlinNoiseShader2::PaintingData* p aintingData,
1055 GrTexture* permutationsTexture, GrTexture * gradientTexture, 1056 GrTexture* permutationsTexture,
1056 const SkMatrix& matrix) { 1057 GrTexture* gradientTexture,
1057 return new GrImprovedPerlinNoiseEffect(octaves, z, paintingData, permuta tionsTexture, 1058 const SkMatrix& matrix) {
1058 gradientTexture, matrix); 1059 return sk_sp<GrFragmentProcessor>(
1060 new GrImprovedPerlinNoiseEffect(octaves, z, paintingData, permutatio nsTexture,
1061 gradientTexture, matrix));
1059 } 1062 }
1060 1063
1061 virtual ~GrImprovedPerlinNoiseEffect() { delete fPaintingData; } 1064 virtual ~GrImprovedPerlinNoiseEffect() { delete fPaintingData; }
1062 1065
1063 const char* name() const override { return "ImprovedPerlinNoise"; } 1066 const char* name() const override { return "ImprovedPerlinNoise"; }
1064 1067
1065 const SkVector& baseFrequency() const { return fPaintingData->fBaseFrequency ; } 1068 const SkVector& baseFrequency() const { return fPaintingData->fBaseFrequency ; }
1066 SkScalar z() const { return fZ; } 1069 SkScalar z() const { return fZ; }
1067 int octaves() const { return fOctaves; } 1070 int octaves() const { return fOctaves; }
1068 const SkMatrix& matrix() const { return fCoordTransform.getMatrix(); } 1071 const SkMatrix& matrix() const { return fCoordTransform.getMatrix(); }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 GrTextureAccess fGradientAccess; 1114 GrTextureAccess fGradientAccess;
1112 SkPerlinNoiseShader2::PaintingData *fPaintingData; 1115 SkPerlinNoiseShader2::PaintingData *fPaintingData;
1113 1116
1114 private: 1117 private:
1115 typedef GrFragmentProcessor INHERITED; 1118 typedef GrFragmentProcessor INHERITED;
1116 }; 1119 };
1117 1120
1118 ///////////////////////////////////////////////////////////////////// 1121 /////////////////////////////////////////////////////////////////////
1119 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrImprovedPerlinNoiseEffect); 1122 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrImprovedPerlinNoiseEffect);
1120 1123
1121 const GrFragmentProcessor* GrImprovedPerlinNoiseEffect::TestCreate(GrProcessorTe stData* d) { 1124 sk_sp<GrFragmentProcessor> GrImprovedPerlinNoiseEffect::TestCreate(GrProcessorTe stData* d) {
1122 SkScalar baseFrequencyX = d->fRandom->nextRangeScalar(0.01f, 1125 SkScalar baseFrequencyX = d->fRandom->nextRangeScalar(0.01f,
1123 0.99f); 1126 0.99f);
1124 SkScalar baseFrequencyY = d->fRandom->nextRangeScalar(0.01f, 1127 SkScalar baseFrequencyY = d->fRandom->nextRangeScalar(0.01f,
1125 0.99f); 1128 0.99f);
1126 int numOctaves = d->fRandom->nextRangeU(2, 10); 1129 int numOctaves = d->fRandom->nextRangeU(2, 10);
1127 SkScalar z = SkIntToScalar(d->fRandom->nextU()); 1130 SkScalar z = SkIntToScalar(d->fRandom->nextU());
1128 1131
1129 sk_sp<SkShader> shader(SkPerlinNoiseShader2::MakeImprovedNoise(baseFrequency X, 1132 sk_sp<SkShader> shader(SkPerlinNoiseShader2::MakeImprovedNoise(baseFrequency X,
1130 baseFrequency Y, 1133 baseFrequency Y,
1131 numOctaves, 1134 numOctaves,
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 1294
1292 const SkVector& baseFrequency = noise.baseFrequency(); 1295 const SkVector& baseFrequency = noise.baseFrequency();
1293 pdman.set2f(fBaseFrequencyUni, baseFrequency.fX, baseFrequency.fY); 1296 pdman.set2f(fBaseFrequencyUni, baseFrequency.fX, baseFrequency.fY);
1294 1297
1295 pdman.set1f(fOctavesUni, SkIntToScalar(noise.octaves())); 1298 pdman.set1f(fOctavesUni, SkIntToScalar(noise.octaves()));
1296 1299
1297 pdman.set1f(fZUni, noise.z()); 1300 pdman.set1f(fZUni, noise.z());
1298 } 1301 }
1299 1302
1300 ///////////////////////////////////////////////////////////////////// 1303 /////////////////////////////////////////////////////////////////////
1301 const GrFragmentProcessor* SkPerlinNoiseShader2::asFragmentProcessor( 1304 sk_sp<GrFragmentProcessor> SkPerlinNoiseShader2::asFragmentProcessor(
1302 GrContext* context, 1305 GrContext* context,
1303 const SkMatrix& viewM, 1306 const SkMatrix& viewM,
1304 const SkMatrix* externalLoca lMatrix, 1307 const SkMatrix* externalLoca lMatrix,
1305 SkFilterQuality, 1308 SkFilterQuality,
1306 SkSourceGammaTreatment gamma Treatment) const { 1309 SkSourceGammaTreatment gamma Treatment) const {
1307 SkASSERT(context); 1310 SkASSERT(context);
1308 1311
1309 SkMatrix localMatrix = this->getLocalMatrix(); 1312 SkMatrix localMatrix = this->getLocalMatrix();
1310 if (externalLocalMatrix) { 1313 if (externalLocalMatrix) {
1311 localMatrix.preConcat(*externalLocalMatrix); 1314 localMatrix.preConcat(*externalLocalMatrix);
(...skipping 14 matching lines...) Expand all
1326 1329
1327 if (fType == kImprovedNoise_Type) { 1330 if (fType == kImprovedNoise_Type) {
1328 GrTextureParams textureParams(SkShader::TileMode::kRepeat_TileMode, 1331 GrTextureParams textureParams(SkShader::TileMode::kRepeat_TileMode,
1329 GrTextureParams::FilterMode::kNone_FilterM ode); 1332 GrTextureParams::FilterMode::kNone_FilterM ode);
1330 SkAutoTUnref<GrTexture> permutationsTexture( 1333 SkAutoTUnref<GrTexture> permutationsTexture(
1331 GrRefCachedBitmapTexture(context, paintingData->getImprovedPermutati onsBitmap(), 1334 GrRefCachedBitmapTexture(context, paintingData->getImprovedPermutati onsBitmap(),
1332 textureParams, gammaTreatment)); 1335 textureParams, gammaTreatment));
1333 SkAutoTUnref<GrTexture> gradientTexture( 1336 SkAutoTUnref<GrTexture> gradientTexture(
1334 GrRefCachedBitmapTexture(context, paintingData->getGradientBitmap(), 1337 GrRefCachedBitmapTexture(context, paintingData->getGradientBitmap(),
1335 textureParams, gammaTreatment)); 1338 textureParams, gammaTreatment));
1336 return GrImprovedPerlinNoiseEffect::Create(fNumOctaves, fSeed, paintingD ata, 1339 return GrImprovedPerlinNoiseEffect::Make(fNumOctaves, fSeed, paintingDat a,
1337 permutationsTexture, gradient Texture, m); 1340 permutationsTexture, gradient Texture, m);
1338 } 1341 }
1339 1342
1340 if (0 == fNumOctaves) { 1343 if (0 == fNumOctaves) {
1341 if (kFractalNoise_Type == fType) { 1344 if (kFractalNoise_Type == fType) {
1342 // Extract the incoming alpha and emit rgba = (a/4, a/4, a/4, a/2) 1345 // Extract the incoming alpha and emit rgba = (a/4, a/4, a/4, a/2)
1343 SkAutoTUnref<const GrFragmentProcessor> inner( 1346 sk_sp<GrFragmentProcessor> inner(
1344 GrConstColorProcessor::Create(0x80404040, 1347 GrConstColorProcessor::Make(0x80404040,
1345 GrConstColorProcessor::kModulateRG BA_InputMode)); 1348 GrConstColorProcessor::kModulateRGBA _InputMode));
1346 return GrFragmentProcessor::MulOutputByInputAlpha(inner); 1349 return GrFragmentProcessor::MulOutputByInputAlpha(std::move(inner));
1347 } 1350 }
1348 // Emit zero. 1351 // Emit zero.
1349 return GrConstColorProcessor::Create(0x0, GrConstColorProcessor::kIgnore _InputMode); 1352 return GrConstColorProcessor::Make(0x0, GrConstColorProcessor::kIgnore_I nputMode);
1350 } 1353 }
1351 1354
1352 SkAutoTUnref<GrTexture> permutationsTexture( 1355 SkAutoTUnref<GrTexture> permutationsTexture(
1353 GrRefCachedBitmapTexture(context, paintingData->getPermutationsBitmap(), 1356 GrRefCachedBitmapTexture(context, paintingData->getPermutationsBitmap(),
1354 GrTextureParams::ClampNoFilter(), gammaTreatmen t)); 1357 GrTextureParams::ClampNoFilter(), gammaTreatmen t));
1355 SkAutoTUnref<GrTexture> noiseTexture( 1358 SkAutoTUnref<GrTexture> noiseTexture(
1356 GrRefCachedBitmapTexture(context, paintingData->getNoiseBitmap(), 1359 GrRefCachedBitmapTexture(context, paintingData->getNoiseBitmap(),
1357 GrTextureParams::ClampNoFilter(), gammaTreatmen t)); 1360 GrTextureParams::ClampNoFilter(), gammaTreatmen t));
1358 1361
1359 if ((permutationsTexture) && (noiseTexture)) { 1362 if ((permutationsTexture) && (noiseTexture)) {
1360 SkAutoTUnref<GrFragmentProcessor> inner( 1363 sk_sp<GrFragmentProcessor> inner(
1361 GrPerlinNoise2Effect::Create(fType, 1364 GrPerlinNoise2Effect::Make(fType,
1362 fNumOctaves, 1365 fNumOctaves,
1363 fStitchTiles, 1366 fStitchTiles,
1364 paintingData, 1367 paintingData,
1365 permutationsTexture, noiseTexture, 1368 permutationsTexture, noiseTexture,
1366 m)); 1369 m));
1367 return GrFragmentProcessor::MulOutputByInputAlpha(inner); 1370 return GrFragmentProcessor::MulOutputByInputAlpha(std::move(inner));
1368 } 1371 }
1369 delete paintingData; 1372 delete paintingData;
1370 return nullptr; 1373 return nullptr;
1371 } 1374 }
1372 1375
1373 #endif 1376 #endif
1374 1377
1375 #ifndef SK_IGNORE_TO_STRING 1378 #ifndef SK_IGNORE_TO_STRING
1376 void SkPerlinNoiseShader2::toString(SkString* str) const { 1379 void SkPerlinNoiseShader2::toString(SkString* str) const {
1377 str->append("SkPerlinNoiseShader2: ("); 1380 str->append("SkPerlinNoiseShader2: (");
(...skipping 19 matching lines...) Expand all
1397 str->append(" seed: "); 1400 str->append(" seed: ");
1398 str->appendScalar(fSeed); 1401 str->appendScalar(fSeed);
1399 str->append(" stitch tiles: "); 1402 str->append(" stitch tiles: ");
1400 str->append(fStitchTiles ? "true " : "false "); 1403 str->append(fStitchTiles ? "true " : "false ");
1401 1404
1402 this->INHERITED::toString(str); 1405 this->INHERITED::toString(str);
1403 1406
1404 str->append(")"); 1407 str->append(")");
1405 } 1408 }
1406 #endif 1409 #endif
OLDNEW
« no previous file with comments | « experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.h ('k') | gm/beziereffects.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698