OLD | NEW |
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 "SkPerlinNoiseShader.h" | 9 #include "SkPerlinNoiseShader.h" |
10 #include "SkColorFilter.h" | 10 #include "SkColorFilter.h" |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 GrGLProgramDataManager::UniformHandle fBaseFrequencyUni; | 503 GrGLProgramDataManager::UniformHandle fBaseFrequencyUni; |
504 | 504 |
505 private: | 505 private: |
506 typedef GrGLFragmentProcessor INHERITED; | 506 typedef GrGLFragmentProcessor INHERITED; |
507 }; | 507 }; |
508 | 508 |
509 ///////////////////////////////////////////////////////////////////// | 509 ///////////////////////////////////////////////////////////////////// |
510 | 510 |
511 class GrPerlinNoiseEffect : public GrFragmentProcessor { | 511 class GrPerlinNoiseEffect : public GrFragmentProcessor { |
512 public: | 512 public: |
513 static GrFragmentProcessor* Create(GrProcessorDataManager* procDataManager, | 513 static GrFragmentProcessor* Create(SkPerlinNoiseShader::Type type, |
514 SkPerlinNoiseShader::Type type, | |
515 int numOctaves, bool stitchTiles, | 514 int numOctaves, bool stitchTiles, |
516 SkPerlinNoiseShader::PaintingData* painti
ngData, | 515 SkPerlinNoiseShader::PaintingData* painti
ngData, |
517 GrTexture* permutationsTexture, GrTexture
* noiseTexture, | 516 GrTexture* permutationsTexture, GrTexture
* noiseTexture, |
518 const SkMatrix& matrix) { | 517 const SkMatrix& matrix) { |
519 return new GrPerlinNoiseEffect(procDataManager, type, numOctaves, stitch
Tiles, paintingData, | 518 return new GrPerlinNoiseEffect(type, numOctaves, stitchTiles, paintingDa
ta, |
520 permutationsTexture, noiseTexture, matrix
); | 519 permutationsTexture, noiseTexture, matrix
); |
521 } | 520 } |
522 | 521 |
523 virtual ~GrPerlinNoiseEffect() { delete fPaintingData; } | 522 virtual ~GrPerlinNoiseEffect() { delete fPaintingData; } |
524 | 523 |
525 const char* name() const override { return "PerlinNoise"; } | 524 const char* name() const override { return "PerlinNoise"; } |
526 | 525 |
527 const SkPerlinNoiseShader::StitchData& stitchData() const { return fPainting
Data->fStitchDataInit; } | 526 const SkPerlinNoiseShader::StitchData& stitchData() const { return fPainting
Data->fStitchDataInit; } |
528 | 527 |
529 SkPerlinNoiseShader::Type type() const { return fType; } | 528 SkPerlinNoiseShader::Type type() const { return fType; } |
(...skipping 18 matching lines...) Expand all Loading... |
548 fPaintingData->fBaseFrequency == s.fPaintingData->fBaseFrequency
&& | 547 fPaintingData->fBaseFrequency == s.fPaintingData->fBaseFrequency
&& |
549 fNumOctaves == s.fNumOctaves && | 548 fNumOctaves == s.fNumOctaves && |
550 fStitchTiles == s.fStitchTiles && | 549 fStitchTiles == s.fStitchTiles && |
551 fPaintingData->fStitchDataInit == s.fPaintingData->fStitchDataIni
t; | 550 fPaintingData->fStitchDataInit == s.fPaintingData->fStitchDataIni
t; |
552 } | 551 } |
553 | 552 |
554 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { | 553 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { |
555 inout->setToUnknown(GrInvariantOutput::kWillNot_ReadInput); | 554 inout->setToUnknown(GrInvariantOutput::kWillNot_ReadInput); |
556 } | 555 } |
557 | 556 |
558 GrPerlinNoiseEffect(GrProcessorDataManager*, SkPerlinNoiseShader::Type type, | 557 GrPerlinNoiseEffect(SkPerlinNoiseShader::Type type, |
559 int numOctaves, bool stitchTiles, | 558 int numOctaves, bool stitchTiles, |
560 SkPerlinNoiseShader::PaintingData* paintingData, | 559 SkPerlinNoiseShader::PaintingData* paintingData, |
561 GrTexture* permutationsTexture, GrTexture* noiseTexture, | 560 GrTexture* permutationsTexture, GrTexture* noiseTexture, |
562 const SkMatrix& matrix) | 561 const SkMatrix& matrix) |
563 : fType(type) | 562 : fType(type) |
564 , fNumOctaves(numOctaves) | 563 , fNumOctaves(numOctaves) |
565 , fStitchTiles(stitchTiles) | 564 , fStitchTiles(stitchTiles) |
566 , fPermutationsAccess(permutationsTexture) | 565 , fPermutationsAccess(permutationsTexture) |
567 , fNoiseAccess(noiseTexture) | 566 , fNoiseAccess(noiseTexture) |
568 , fPaintingData(paintingData) { | 567 , fPaintingData(paintingData) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 | 602 |
604 SkAutoTUnref<SkShader> shader(d->fRandom->nextBool() ? | 603 SkAutoTUnref<SkShader> shader(d->fRandom->nextBool() ? |
605 SkPerlinNoiseShader::CreateFractalNoise(baseFrequencyX, baseFrequencyY,
numOctaves, seed, | 604 SkPerlinNoiseShader::CreateFractalNoise(baseFrequencyX, baseFrequencyY,
numOctaves, seed, |
606 stitchTiles ? &tileSize : nullpt
r) : | 605 stitchTiles ? &tileSize : nullpt
r) : |
607 SkPerlinNoiseShader::CreateTurbulence(baseFrequencyX, baseFrequencyY, nu
mOctaves, seed, | 606 SkPerlinNoiseShader::CreateTurbulence(baseFrequencyX, baseFrequencyY, nu
mOctaves, seed, |
608 stitchTiles ? &tileSize : nullptr))
; | 607 stitchTiles ? &tileSize : nullptr))
; |
609 | 608 |
610 GrPaint grPaint; | 609 GrPaint grPaint; |
611 return shader->asFragmentProcessor(d->fContext, | 610 return shader->asFragmentProcessor(d->fContext, |
612 GrTest::TestMatrix(d->fRandom), nullptr, | 611 GrTest::TestMatrix(d->fRandom), nullptr, |
613 kNone_SkFilterQuality, | 612 kNone_SkFilterQuality); |
614 grPaint.getProcessorDataManager()); | |
615 } | 613 } |
616 | 614 |
617 GrGLPerlinNoise::GrGLPerlinNoise(const GrProcessor& processor) | 615 GrGLPerlinNoise::GrGLPerlinNoise(const GrProcessor& processor) |
618 : fType(processor.cast<GrPerlinNoiseEffect>().type()) | 616 : fType(processor.cast<GrPerlinNoiseEffect>().type()) |
619 , fStitchTiles(processor.cast<GrPerlinNoiseEffect>().stitchTiles()) | 617 , fStitchTiles(processor.cast<GrPerlinNoiseEffect>().stitchTiles()) |
620 , fNumOctaves(processor.cast<GrPerlinNoiseEffect>().numOctaves()) { | 618 , fNumOctaves(processor.cast<GrPerlinNoiseEffect>().numOctaves()) { |
621 } | 619 } |
622 | 620 |
623 void GrGLPerlinNoise::emitCode(EmitArgs& args) { | 621 void GrGLPerlinNoise::emitCode(EmitArgs& args) { |
624 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); | 622 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 pdman.set2f(fStitchDataUni, SkIntToScalar(stitchData.fWidth), | 907 pdman.set2f(fStitchDataUni, SkIntToScalar(stitchData.fWidth), |
910 SkIntToScalar(stitchData.fHeight)); | 908 SkIntToScalar(stitchData.fHeight)); |
911 } | 909 } |
912 } | 910 } |
913 | 911 |
914 ///////////////////////////////////////////////////////////////////// | 912 ///////////////////////////////////////////////////////////////////// |
915 const GrFragmentProcessor* SkPerlinNoiseShader::asFragmentProcessor( | 913 const GrFragmentProcessor* SkPerlinNoiseShader::asFragmentProcessor( |
916 GrContext* context, | 914 GrContext* context, |
917 const SkMatrix& viewM, | 915 const SkMatrix& viewM, |
918 const SkMatrix* externalLoca
lMatrix, | 916 const SkMatrix* externalLoca
lMatrix, |
919 SkFilterQuality, | 917 SkFilterQuality) const { |
920 GrProcessorDataManager* proc
DataManager) const { | |
921 SkASSERT(context); | 918 SkASSERT(context); |
922 | 919 |
923 SkMatrix localMatrix = this->getLocalMatrix(); | 920 SkMatrix localMatrix = this->getLocalMatrix(); |
924 if (externalLocalMatrix) { | 921 if (externalLocalMatrix) { |
925 localMatrix.preConcat(*externalLocalMatrix); | 922 localMatrix.preConcat(*externalLocalMatrix); |
926 } | 923 } |
927 | 924 |
928 SkMatrix matrix = viewM; | 925 SkMatrix matrix = viewM; |
929 matrix.preConcat(localMatrix); | 926 matrix.preConcat(localMatrix); |
930 | 927 |
(...skipping 17 matching lines...) Expand all Loading... |
948 SkAutoTUnref<GrTexture> permutationsTexture( | 945 SkAutoTUnref<GrTexture> permutationsTexture( |
949 GrRefCachedBitmapTexture(context, paintingData->getPermutationsBitmap(),
nullptr)); | 946 GrRefCachedBitmapTexture(context, paintingData->getPermutationsBitmap(),
nullptr)); |
950 SkAutoTUnref<GrTexture> noiseTexture( | 947 SkAutoTUnref<GrTexture> noiseTexture( |
951 GrRefCachedBitmapTexture(context, paintingData->getNoiseBitmap(), nullpt
r)); | 948 GrRefCachedBitmapTexture(context, paintingData->getNoiseBitmap(), nullpt
r)); |
952 | 949 |
953 SkMatrix m = viewM; | 950 SkMatrix m = viewM; |
954 m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1); | 951 m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1); |
955 m.setTranslateY(-localMatrix.getTranslateY() + SK_Scalar1); | 952 m.setTranslateY(-localMatrix.getTranslateY() + SK_Scalar1); |
956 if ((permutationsTexture) && (noiseTexture)) { | 953 if ((permutationsTexture) && (noiseTexture)) { |
957 SkAutoTUnref<GrFragmentProcessor> inner( | 954 SkAutoTUnref<GrFragmentProcessor> inner( |
958 GrPerlinNoiseEffect::Create(procDataManager, | 955 GrPerlinNoiseEffect::Create(fType, |
959 fType, | |
960 fNumOctaves, | 956 fNumOctaves, |
961 fStitchTiles, | 957 fStitchTiles, |
962 paintingData, | 958 paintingData, |
963 permutationsTexture, noiseTexture, | 959 permutationsTexture, noiseTexture, |
964 m)); | 960 m)); |
965 return GrFragmentProcessor::MulOutputByInputAlpha(inner); | 961 return GrFragmentProcessor::MulOutputByInputAlpha(inner); |
966 } | 962 } |
967 delete paintingData; | 963 delete paintingData; |
968 return nullptr; | 964 return nullptr; |
969 } | 965 } |
(...skipping 25 matching lines...) Expand all Loading... |
995 str->append(" seed: "); | 991 str->append(" seed: "); |
996 str->appendScalar(fSeed); | 992 str->appendScalar(fSeed); |
997 str->append(" stitch tiles: "); | 993 str->append(" stitch tiles: "); |
998 str->append(fStitchTiles ? "true " : "false "); | 994 str->append(fStitchTiles ? "true " : "false "); |
999 | 995 |
1000 this->INHERITED::toString(str); | 996 this->INHERITED::toString(str); |
1001 | 997 |
1002 str->append(")"); | 998 str->append(")"); |
1003 } | 999 } |
1004 #endif | 1000 #endif |
OLD | NEW |