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

Side by Side Diff: src/effects/SkPerlinNoiseShader.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 | « src/effects/SkMorphologyImageFilter.cpp ('k') | src/effects/SkTableColorFilter.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 "SkPerlinNoiseShader.h" 8 #include "SkPerlinNoiseShader.h"
9 #include "SkColorFilter.h" 9 #include "SkColorFilter.h"
10 #include "SkReadBuffer.h" 10 #include "SkReadBuffer.h"
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 GrGLSLProgramDataManager::UniformHandle fStitchDataUni; 488 GrGLSLProgramDataManager::UniformHandle fStitchDataUni;
489 GrGLSLProgramDataManager::UniformHandle fBaseFrequencyUni; 489 GrGLSLProgramDataManager::UniformHandle fBaseFrequencyUni;
490 490
491 typedef GrGLSLFragmentProcessor INHERITED; 491 typedef GrGLSLFragmentProcessor INHERITED;
492 }; 492 };
493 493
494 ///////////////////////////////////////////////////////////////////// 494 /////////////////////////////////////////////////////////////////////
495 495
496 class GrPerlinNoiseEffect : public GrFragmentProcessor { 496 class GrPerlinNoiseEffect : public GrFragmentProcessor {
497 public: 497 public:
498 static GrFragmentProcessor* Create(SkPerlinNoiseShader::Type type, 498 static sk_sp<GrFragmentProcessor> Make(SkPerlinNoiseShader::Type type,
499 int numOctaves, bool stitchTiles, 499 int numOctaves, bool stitchTiles,
500 SkPerlinNoiseShader::PaintingData* painti ngData, 500 SkPerlinNoiseShader::PaintingData* pa intingData,
501 GrTexture* permutationsTexture, GrTexture * noiseTexture, 501 GrTexture* permutationsTexture, GrTex ture* noiseTexture,
502 const SkMatrix& matrix) { 502 const SkMatrix& matrix) {
503 return new GrPerlinNoiseEffect(type, numOctaves, stitchTiles, paintingDa ta, 503 return sk_sp<GrFragmentProcessor>(
504 permutationsTexture, noiseTexture, matrix ); 504 new GrPerlinNoiseEffect(type, numOctaves, stitchTiles, paintingData,
505 permutationsTexture, noiseTexture, matrix));
505 } 506 }
506 507
507 virtual ~GrPerlinNoiseEffect() { delete fPaintingData; } 508 virtual ~GrPerlinNoiseEffect() { delete fPaintingData; }
508 509
509 const char* name() const override { return "PerlinNoise"; } 510 const char* name() const override { return "PerlinNoise"; }
510 511
511 const SkPerlinNoiseShader::StitchData& stitchData() const { return fPainting Data->fStitchDataInit; } 512 const SkPerlinNoiseShader::StitchData& stitchData() const { return fPainting Data->fStitchDataInit; }
512 513
513 SkPerlinNoiseShader::Type type() const { return fType; } 514 SkPerlinNoiseShader::Type type() const { return fType; }
514 bool stitchTiles() const { return fStitchTiles; } 515 bool stitchTiles() const { return fStitchTiles; }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 GrTextureAccess fNoiseAccess; 568 GrTextureAccess fNoiseAccess;
568 SkPerlinNoiseShader::PaintingData *fPaintingData; 569 SkPerlinNoiseShader::PaintingData *fPaintingData;
569 570
570 private: 571 private:
571 typedef GrFragmentProcessor INHERITED; 572 typedef GrFragmentProcessor INHERITED;
572 }; 573 };
573 574
574 ///////////////////////////////////////////////////////////////////// 575 /////////////////////////////////////////////////////////////////////
575 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrPerlinNoiseEffect); 576 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrPerlinNoiseEffect);
576 577
577 const GrFragmentProcessor* GrPerlinNoiseEffect::TestCreate(GrProcessorTestData* d) { 578 sk_sp<GrFragmentProcessor> GrPerlinNoiseEffect::TestCreate(GrProcessorTestData* d) {
578 int numOctaves = d->fRandom->nextRangeU(2, 10); 579 int numOctaves = d->fRandom->nextRangeU(2, 10);
579 bool stitchTiles = d->fRandom->nextBool(); 580 bool stitchTiles = d->fRandom->nextBool();
580 SkScalar seed = SkIntToScalar(d->fRandom->nextU()); 581 SkScalar seed = SkIntToScalar(d->fRandom->nextU());
581 SkISize tileSize = SkISize::Make(d->fRandom->nextRangeU(4, 4096), 582 SkISize tileSize = SkISize::Make(d->fRandom->nextRangeU(4, 4096),
582 d->fRandom->nextRangeU(4, 4096)); 583 d->fRandom->nextRangeU(4, 4096));
583 SkScalar baseFrequencyX = d->fRandom->nextRangeScalar(0.01f, 584 SkScalar baseFrequencyX = d->fRandom->nextRangeScalar(0.01f,
584 0.99f); 585 0.99f);
585 SkScalar baseFrequencyY = d->fRandom->nextRangeScalar(0.01f, 586 SkScalar baseFrequencyY = d->fRandom->nextRangeScalar(0.01f,
586 0.99f); 587 0.99f);
587 588
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 pdman.set2f(fBaseFrequencyUni, baseFrequency.fX, baseFrequency.fY); 886 pdman.set2f(fBaseFrequencyUni, baseFrequency.fX, baseFrequency.fY);
886 887
887 if (turbulence.stitchTiles()) { 888 if (turbulence.stitchTiles()) {
888 const SkPerlinNoiseShader::StitchData& stitchData = turbulence.stitchDat a(); 889 const SkPerlinNoiseShader::StitchData& stitchData = turbulence.stitchDat a();
889 pdman.set2f(fStitchDataUni, SkIntToScalar(stitchData.fWidth), 890 pdman.set2f(fStitchDataUni, SkIntToScalar(stitchData.fWidth),
890 SkIntToScalar(stitchData.fHeight)); 891 SkIntToScalar(stitchData.fHeight));
891 } 892 }
892 } 893 }
893 894
894 ///////////////////////////////////////////////////////////////////// 895 /////////////////////////////////////////////////////////////////////
895 const GrFragmentProcessor* SkPerlinNoiseShader::asFragmentProcessor( 896 sk_sp<GrFragmentProcessor> SkPerlinNoiseShader::asFragmentProcessor(
896 GrContext* context, 897 GrContext* context,
897 const SkMatrix& viewM, 898 const SkMatrix& viewM,
898 const SkMatrix* externalLoc alMatrix, 899 const SkMatrix* externalLoc alMatrix,
899 SkFilterQuality, 900 SkFilterQuality,
900 SkSourceGammaTreatment gamm aTreatment) const { 901 SkSourceGammaTreatment gamm aTreatment) const {
901 SkASSERT(context); 902 SkASSERT(context);
902 903
903 SkMatrix localMatrix = this->getLocalMatrix(); 904 SkMatrix localMatrix = this->getLocalMatrix();
904 if (externalLocalMatrix) { 905 if (externalLocalMatrix) {
905 localMatrix.preConcat(*externalLocalMatrix); 906 localMatrix.preConcat(*externalLocalMatrix);
906 } 907 }
907 908
908 SkMatrix matrix = viewM; 909 SkMatrix matrix = viewM;
909 matrix.preConcat(localMatrix); 910 matrix.preConcat(localMatrix);
910 911
911 if (0 == fNumOctaves) { 912 if (0 == fNumOctaves) {
912 if (kFractalNoise_Type == fType) { 913 if (kFractalNoise_Type == fType) {
913 // Extract the incoming alpha and emit rgba = (a/4, a/4, a/4, a/2) 914 // Extract the incoming alpha and emit rgba = (a/4, a/4, a/4, a/2)
914 SkAutoTUnref<const GrFragmentProcessor> inner( 915 sk_sp<GrFragmentProcessor> inner(
915 GrConstColorProcessor::Create(0x80404040, 916 GrConstColorProcessor::Make(0x80404040,
916 GrConstColorProcessor::kModulateRG BA_InputMode)); 917 GrConstColorProcessor::kModulateRGBA _InputMode));
917 return GrFragmentProcessor::MulOutputByInputAlpha(inner); 918 return GrFragmentProcessor::MulOutputByInputAlpha(std::move(inner));
918 } 919 }
919 // Emit zero. 920 // Emit zero.
920 return GrConstColorProcessor::Create(0x0, GrConstColorProcessor::kIgnore _InputMode); 921 return GrConstColorProcessor::Make(0x0, GrConstColorProcessor::kIgnore_I nputMode);
921 } 922 }
922 923
923 // Either we don't stitch tiles, either we have a valid tile size 924 // Either we don't stitch tiles, either we have a valid tile size
924 SkASSERT(!fStitchTiles || !fTileSize.isEmpty()); 925 SkASSERT(!fStitchTiles || !fTileSize.isEmpty());
925 926
926 SkPerlinNoiseShader::PaintingData* paintingData = 927 SkPerlinNoiseShader::PaintingData* paintingData =
927 new PaintingData(fTileSize, fSeed, fBaseFrequencyX, fBaseFrequencyY, matrix); 928 new PaintingData(fTileSize, fSeed, fBaseFrequencyX, fBaseFrequencyY, matrix);
928 SkAutoTUnref<GrTexture> permutationsTexture( 929 SkAutoTUnref<GrTexture> permutationsTexture(
929 GrRefCachedBitmapTexture(context, paintingData->getPermutationsBitmap(), 930 GrRefCachedBitmapTexture(context, paintingData->getPermutationsBitmap(),
930 GrTextureParams::ClampNoFilter(), gammaTreatmen t)); 931 GrTextureParams::ClampNoFilter(), gammaTreatmen t));
931 SkAutoTUnref<GrTexture> noiseTexture( 932 SkAutoTUnref<GrTexture> noiseTexture(
932 GrRefCachedBitmapTexture(context, paintingData->getNoiseBitmap(), 933 GrRefCachedBitmapTexture(context, paintingData->getNoiseBitmap(),
933 GrTextureParams::ClampNoFilter(), gammaTreatmen t)); 934 GrTextureParams::ClampNoFilter(), gammaTreatmen t));
934 935
935 SkMatrix m = viewM; 936 SkMatrix m = viewM;
936 m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1); 937 m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1);
937 m.setTranslateY(-localMatrix.getTranslateY() + SK_Scalar1); 938 m.setTranslateY(-localMatrix.getTranslateY() + SK_Scalar1);
938 if ((permutationsTexture) && (noiseTexture)) { 939 if ((permutationsTexture) && (noiseTexture)) {
939 SkAutoTUnref<GrFragmentProcessor> inner( 940 sk_sp<GrFragmentProcessor> inner(
940 GrPerlinNoiseEffect::Create(fType, 941 GrPerlinNoiseEffect::Make(fType,
941 fNumOctaves, 942 fNumOctaves,
942 fStitchTiles, 943 fStitchTiles,
943 paintingData, 944 paintingData,
944 permutationsTexture, noiseTexture, 945 permutationsTexture, noiseTexture,
945 m)); 946 m));
946 return GrFragmentProcessor::MulOutputByInputAlpha(inner); 947 return GrFragmentProcessor::MulOutputByInputAlpha(std::move(inner));
947 } 948 }
948 delete paintingData; 949 delete paintingData;
949 return nullptr; 950 return nullptr;
950 } 951 }
951 952
952 #endif 953 #endif
953 954
954 #ifndef SK_IGNORE_TO_STRING 955 #ifndef SK_IGNORE_TO_STRING
955 void SkPerlinNoiseShader::toString(SkString* str) const { 956 void SkPerlinNoiseShader::toString(SkString* str) const {
956 str->append("SkPerlinNoiseShader: ("); 957 str->append("SkPerlinNoiseShader: (");
(...skipping 19 matching lines...) Expand all
976 str->append(" seed: "); 977 str->append(" seed: ");
977 str->appendScalar(fSeed); 978 str->appendScalar(fSeed);
978 str->append(" stitch tiles: "); 979 str->append(" stitch tiles: ");
979 str->append(fStitchTiles ? "true " : "false "); 980 str->append(fStitchTiles ? "true " : "false ");
980 981
981 this->INHERITED::toString(str); 982 this->INHERITED::toString(str);
982 983
983 str->append(")"); 984 str->append(")");
984 } 985 }
985 #endif 986 #endif
OLDNEW
« no previous file with comments | « src/effects/SkMorphologyImageFilter.cpp ('k') | src/effects/SkTableColorFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698