| 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" |
| 11 #include "SkReadBuffer.h" | 11 #include "SkReadBuffer.h" |
| 12 #include "SkWriteBuffer.h" | 12 #include "SkWriteBuffer.h" |
| 13 #include "SkShader.h" | 13 #include "SkShader.h" |
| 14 #include "SkUnPreMultiply.h" | 14 #include "SkUnPreMultiply.h" |
| 15 #include "SkString.h" | 15 #include "SkString.h" |
| 16 | 16 |
| 17 #if SK_SUPPORT_GPU | 17 #if SK_SUPPORT_GPU |
| 18 #include "GrContext.h" | 18 #include "GrContext.h" |
| 19 #include "GrCoordTransform.h" | 19 #include "GrCoordTransform.h" |
| 20 #include "GrInvariantOutput.h" | 20 #include "GrInvariantOutput.h" |
| 21 #include "SkGr.h" | 21 #include "SkGr.h" |
| 22 #include "effects/GrConstColorProcessor.h" |
| 23 #include "effects/GrExtractAlphaFragmentProcessor.h" |
| 22 #include "gl/GrGLFragmentProcessor.h" | 24 #include "gl/GrGLFragmentProcessor.h" |
| 23 #include "gl/builders/GrGLProgramBuilder.h" | 25 #include "gl/builders/GrGLProgramBuilder.h" |
| 24 #endif | 26 #endif |
| 25 | 27 |
| 26 static const int kBlockSize = 256; | 28 static const int kBlockSize = 256; |
| 27 static const int kBlockMask = kBlockSize - 1; | 29 static const int kBlockMask = kBlockSize - 1; |
| 28 static const int kPerlinNoise = 4096; | 30 static const int kPerlinNoise = 4096; |
| 29 static const int kRandMaximum = SK_MaxS32; // 2**31 - 1 | 31 static const int kRandMaximum = SK_MaxS32; // 2**31 - 1 |
| 30 | 32 |
| 31 namespace { | 33 namespace { |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 protected: | 495 protected: |
| 494 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; | 496 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; |
| 495 | 497 |
| 496 private: | 498 private: |
| 497 | 499 |
| 498 GrGLProgramDataManager::UniformHandle fStitchDataUni; | 500 GrGLProgramDataManager::UniformHandle fStitchDataUni; |
| 499 SkPerlinNoiseShader::Type fType; | 501 SkPerlinNoiseShader::Type fType; |
| 500 bool fStitchTiles; | 502 bool fStitchTiles; |
| 501 int fNumOctaves; | 503 int fNumOctaves; |
| 502 GrGLProgramDataManager::UniformHandle fBaseFrequencyUni; | 504 GrGLProgramDataManager::UniformHandle fBaseFrequencyUni; |
| 503 GrGLProgramDataManager::UniformHandle fAlphaUni; | |
| 504 | 505 |
| 505 private: | 506 private: |
| 506 typedef GrGLFragmentProcessor INHERITED; | 507 typedef GrGLFragmentProcessor INHERITED; |
| 507 }; | 508 }; |
| 508 | 509 |
| 509 ///////////////////////////////////////////////////////////////////// | 510 ///////////////////////////////////////////////////////////////////// |
| 510 | 511 |
| 511 class GrPerlinNoiseEffect : public GrFragmentProcessor { | 512 class GrPerlinNoiseEffect : public GrFragmentProcessor { |
| 512 public: | 513 public: |
| 513 static GrFragmentProcessor* Create(GrProcessorDataManager* procDataManager, | 514 static GrFragmentProcessor* Create(GrProcessorDataManager* procDataManager, |
| 514 SkPerlinNoiseShader::Type type, | 515 SkPerlinNoiseShader::Type type, |
| 515 int numOctaves, bool stitchTiles, | 516 int numOctaves, bool stitchTiles, |
| 516 SkPerlinNoiseShader::PaintingData* painti
ngData, | 517 SkPerlinNoiseShader::PaintingData* painti
ngData, |
| 517 GrTexture* permutationsTexture, GrTexture
* noiseTexture, | 518 GrTexture* permutationsTexture, GrTexture
* noiseTexture, |
| 518 const SkMatrix& matrix, uint8_t alpha) { | 519 const SkMatrix& matrix) { |
| 519 return new GrPerlinNoiseEffect(procDataManager, type, numOctaves, stitch
Tiles, paintingData, | 520 return new GrPerlinNoiseEffect(procDataManager, type, numOctaves, stitch
Tiles, paintingData, |
| 520 permutationsTexture, noiseTexture, matrix
, alpha); | 521 permutationsTexture, noiseTexture, matrix
); |
| 521 } | 522 } |
| 522 | 523 |
| 523 virtual ~GrPerlinNoiseEffect() { delete fPaintingData; } | 524 virtual ~GrPerlinNoiseEffect() { delete fPaintingData; } |
| 524 | 525 |
| 525 const char* name() const override { return "PerlinNoise"; } | 526 const char* name() const override { return "PerlinNoise"; } |
| 526 | 527 |
| 527 const SkPerlinNoiseShader::StitchData& stitchData() const { return fPainting
Data->fStitchDataInit; } | 528 const SkPerlinNoiseShader::StitchData& stitchData() const { return fPainting
Data->fStitchDataInit; } |
| 528 | 529 |
| 529 SkPerlinNoiseShader::Type type() const { return fType; } | 530 SkPerlinNoiseShader::Type type() const { return fType; } |
| 530 bool stitchTiles() const { return fStitchTiles; } | 531 bool stitchTiles() const { return fStitchTiles; } |
| 531 const SkVector& baseFrequency() const { return fPaintingData->fBaseFrequency
; } | 532 const SkVector& baseFrequency() const { return fPaintingData->fBaseFrequency
; } |
| 532 int numOctaves() const { return fNumOctaves; } | 533 int numOctaves() const { return fNumOctaves; } |
| 533 const SkMatrix& matrix() const { return fCoordTransform.getMatrix(); } | 534 const SkMatrix& matrix() const { return fCoordTransform.getMatrix(); } |
| 534 uint8_t alpha() const { return fAlpha; } | |
| 535 | 535 |
| 536 private: | 536 private: |
| 537 GrGLFragmentProcessor* onCreateGLInstance() const override { | 537 GrGLFragmentProcessor* onCreateGLInstance() const override { |
| 538 return new GrGLPerlinNoise(*this); | 538 return new GrGLPerlinNoise(*this); |
| 539 } | 539 } |
| 540 | 540 |
| 541 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, | 541 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, |
| 542 GrProcessorKeyBuilder* b) const override { | 542 GrProcessorKeyBuilder* b) const override { |
| 543 GrGLPerlinNoise::GenKey(*this, caps, b); | 543 GrGLPerlinNoise::GenKey(*this, caps, b); |
| 544 } | 544 } |
| 545 | 545 |
| 546 bool onIsEqual(const GrFragmentProcessor& sBase) const override { | 546 bool onIsEqual(const GrFragmentProcessor& sBase) const override { |
| 547 const GrPerlinNoiseEffect& s = sBase.cast<GrPerlinNoiseEffect>(); | 547 const GrPerlinNoiseEffect& s = sBase.cast<GrPerlinNoiseEffect>(); |
| 548 return fType == s.fType && | 548 return fType == s.fType && |
| 549 fPaintingData->fBaseFrequency == s.fPaintingData->fBaseFrequency
&& | 549 fPaintingData->fBaseFrequency == s.fPaintingData->fBaseFrequency
&& |
| 550 fNumOctaves == s.fNumOctaves && | 550 fNumOctaves == s.fNumOctaves && |
| 551 fStitchTiles == s.fStitchTiles && | 551 fStitchTiles == s.fStitchTiles && |
| 552 fAlpha == s.fAlpha && | |
| 553 fPaintingData->fStitchDataInit == s.fPaintingData->fStitchDataIni
t; | 552 fPaintingData->fStitchDataInit == s.fPaintingData->fStitchDataIni
t; |
| 554 } | 553 } |
| 555 | 554 |
| 556 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { | 555 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { |
| 557 inout->setToUnknown(GrInvariantOutput::kWillNot_ReadInput); | 556 inout->setToUnknown(GrInvariantOutput::kWillNot_ReadInput); |
| 558 } | 557 } |
| 559 | 558 |
| 560 GrPerlinNoiseEffect(GrProcessorDataManager*, SkPerlinNoiseShader::Type type, | 559 GrPerlinNoiseEffect(GrProcessorDataManager*, SkPerlinNoiseShader::Type type, |
| 561 int numOctaves, bool stitchTiles, | 560 int numOctaves, bool stitchTiles, |
| 562 SkPerlinNoiseShader::PaintingData* paintingData, | 561 SkPerlinNoiseShader::PaintingData* paintingData, |
| 563 GrTexture* permutationsTexture, GrTexture* noiseTexture, | 562 GrTexture* permutationsTexture, GrTexture* noiseTexture, |
| 564 const SkMatrix& matrix, uint8_t alpha) | 563 const SkMatrix& matrix) |
| 565 : fType(type) | 564 : fType(type) |
| 566 , fNumOctaves(numOctaves) | 565 , fNumOctaves(numOctaves) |
| 567 , fStitchTiles(stitchTiles) | 566 , fStitchTiles(stitchTiles) |
| 568 , fAlpha(alpha) | |
| 569 , fPermutationsAccess(permutationsTexture) | 567 , fPermutationsAccess(permutationsTexture) |
| 570 , fNoiseAccess(noiseTexture) | 568 , fNoiseAccess(noiseTexture) |
| 571 , fPaintingData(paintingData) { | 569 , fPaintingData(paintingData) { |
| 572 this->initClassID<GrPerlinNoiseEffect>(); | 570 this->initClassID<GrPerlinNoiseEffect>(); |
| 573 this->addTextureAccess(&fPermutationsAccess); | 571 this->addTextureAccess(&fPermutationsAccess); |
| 574 this->addTextureAccess(&fNoiseAccess); | 572 this->addTextureAccess(&fNoiseAccess); |
| 575 fCoordTransform.reset(kLocal_GrCoordSet, matrix); | 573 fCoordTransform.reset(kLocal_GrCoordSet, matrix); |
| 576 this->addCoordTransform(&fCoordTransform); | 574 this->addCoordTransform(&fCoordTransform); |
| 577 } | 575 } |
| 578 | 576 |
| 579 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 577 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 580 | 578 |
| 581 SkPerlinNoiseShader::Type fType; | 579 SkPerlinNoiseShader::Type fType; |
| 582 GrCoordTransform fCoordTransform; | 580 GrCoordTransform fCoordTransform; |
| 583 int fNumOctaves; | 581 int fNumOctaves; |
| 584 bool fStitchTiles; | 582 bool fStitchTiles; |
| 585 uint8_t fAlpha; | |
| 586 GrTextureAccess fPermutationsAccess; | 583 GrTextureAccess fPermutationsAccess; |
| 587 GrTextureAccess fNoiseAccess; | 584 GrTextureAccess fNoiseAccess; |
| 588 SkPerlinNoiseShader::PaintingData *fPaintingData; | 585 SkPerlinNoiseShader::PaintingData *fPaintingData; |
| 589 | 586 |
| 590 private: | 587 private: |
| 591 typedef GrFragmentProcessor INHERITED; | 588 typedef GrFragmentProcessor INHERITED; |
| 592 }; | 589 }; |
| 593 | 590 |
| 594 ///////////////////////////////////////////////////////////////////// | 591 ///////////////////////////////////////////////////////////////////// |
| 595 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrPerlinNoiseEffect); | 592 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrPerlinNoiseEffect); |
| 596 | 593 |
| 597 GrFragmentProcessor* GrPerlinNoiseEffect::TestCreate(GrProcessorTestData* d) { | 594 const GrFragmentProcessor* GrPerlinNoiseEffect::TestCreate(GrProcessorTestData*
d) { |
| 598 int numOctaves = d->fRandom->nextRangeU(2, 10); | 595 int numOctaves = d->fRandom->nextRangeU(2, 10); |
| 599 bool stitchTiles = d->fRandom->nextBool(); | 596 bool stitchTiles = d->fRandom->nextBool(); |
| 600 SkScalar seed = SkIntToScalar(d->fRandom->nextU()); | 597 SkScalar seed = SkIntToScalar(d->fRandom->nextU()); |
| 601 SkISize tileSize = SkISize::Make(d->fRandom->nextRangeU(4, 4096), | 598 SkISize tileSize = SkISize::Make(d->fRandom->nextRangeU(4, 4096), |
| 602 d->fRandom->nextRangeU(4, 4096)); | 599 d->fRandom->nextRangeU(4, 4096)); |
| 603 SkScalar baseFrequencyX = d->fRandom->nextRangeScalar(0.01f, | 600 SkScalar baseFrequencyX = d->fRandom->nextRangeScalar(0.01f, |
| 604 0.99f); | 601 0.99f); |
| 605 SkScalar baseFrequencyY = d->fRandom->nextRangeScalar(0.01f, | 602 SkScalar baseFrequencyY = d->fRandom->nextRangeScalar(0.01f, |
| 606 0.99f); | 603 0.99f); |
| 607 | 604 |
| 608 SkShader* shader = d->fRandom->nextBool() ? | 605 SkShader* shader = d->fRandom->nextBool() ? |
| 609 SkPerlinNoiseShader::CreateFractalNoise(baseFrequencyX, baseFrequencyY,
numOctaves, seed, | 606 SkPerlinNoiseShader::CreateFractalNoise(baseFrequencyX, baseFrequencyY,
numOctaves, seed, |
| 610 stitchTiles ? &tileSize : nullpt
r) : | 607 stitchTiles ? &tileSize : nullpt
r) : |
| 611 SkPerlinNoiseShader::CreateTurbulence(baseFrequencyX, baseFrequencyY, nu
mOctaves, seed, | 608 SkPerlinNoiseShader::CreateTurbulence(baseFrequencyX, baseFrequencyY, nu
mOctaves, seed, |
| 612 stitchTiles ? &tileSize : nullptr); | 609 stitchTiles ? &tileSize : nullptr); |
| 613 | 610 |
| 614 SkPaint paint; | |
| 615 GrColor paintColor; | |
| 616 GrFragmentProcessor* effect; | |
| 617 GrPaint grPaint; | 611 GrPaint grPaint; |
| 618 SkAssertResult(shader->asFragmentProcessor(d->fContext, paint, | 612 return shader->asFragmentProcessor(d->fContext, |
| 619 GrTest::TestMatrix(d->fRandom), n
ullptr, | 613 GrTest::TestMatrix(d->fRandom), nullptr, |
| 620 &paintColor, grPaint.getProcessor
DataManager(), | 614 kNone_SkFilterQuality, |
| 621 &effect)); | 615 grPaint.getProcessorDataManager()); |
| 622 | |
| 623 delete shader; | |
| 624 | |
| 625 return effect; | |
| 626 } | 616 } |
| 627 | 617 |
| 628 GrGLPerlinNoise::GrGLPerlinNoise(const GrProcessor& processor) | 618 GrGLPerlinNoise::GrGLPerlinNoise(const GrProcessor& processor) |
| 629 : fType(processor.cast<GrPerlinNoiseEffect>().type()) | 619 : fType(processor.cast<GrPerlinNoiseEffect>().type()) |
| 630 , fStitchTiles(processor.cast<GrPerlinNoiseEffect>().stitchTiles()) | 620 , fStitchTiles(processor.cast<GrPerlinNoiseEffect>().stitchTiles()) |
| 631 , fNumOctaves(processor.cast<GrPerlinNoiseEffect>().numOctaves()) { | 621 , fNumOctaves(processor.cast<GrPerlinNoiseEffect>().numOctaves()) { |
| 632 } | 622 } |
| 633 | 623 |
| 634 void GrGLPerlinNoise::emitCode(EmitArgs& args) { | 624 void GrGLPerlinNoise::emitCode(EmitArgs& args) { |
| 635 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); | 625 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); |
| 636 SkString vCoords = fsBuilder->ensureFSCoords2D(args.fCoords, 0); | 626 SkString vCoords = fsBuilder->ensureFSCoords2D(args.fCoords, 0); |
| 637 | 627 |
| 638 fBaseFrequencyUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_
Visibility, | 628 fBaseFrequencyUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_
Visibility, |
| 639 kVec2f_GrSLType, kDefault_GrSLPrecis
ion, | 629 kVec2f_GrSLType, kDefault_GrSLPrecis
ion, |
| 640 "baseFrequency"); | 630 "baseFrequency"); |
| 641 const char* baseFrequencyUni = args.fBuilder->getUniformCStr(fBaseFrequencyU
ni); | 631 const char* baseFrequencyUni = args.fBuilder->getUniformCStr(fBaseFrequencyU
ni); |
| 642 fAlphaUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibili
ty, | |
| 643 kFloat_GrSLType, kDefault_GrSLPrecision, | |
| 644 "alpha"); | |
| 645 const char* alphaUni = args.fBuilder->getUniformCStr(fAlphaUni); | |
| 646 | 632 |
| 647 const char* stitchDataUni = nullptr; | 633 const char* stitchDataUni = nullptr; |
| 648 if (fStitchTiles) { | 634 if (fStitchTiles) { |
| 649 fStitchDataUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment
_Visibility, | 635 fStitchDataUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment
_Visibility, |
| 650 kVec2f_GrSLType, kDefault_GrSLPreci
sion, | 636 kVec2f_GrSLType, kDefault_GrSLPreci
sion, |
| 651 "stitchData"); | 637 "stitchData"); |
| 652 stitchDataUni = args.fBuilder->getUniformCStr(fStitchDataUni); | 638 stitchDataUni = args.fBuilder->getUniformCStr(fStitchDataUni); |
| 653 } | 639 } |
| 654 | 640 |
| 655 // There are 4 lines, so the center of each line is 1/8, 3/8, 5/8 and 7/8 | 641 // There are 4 lines, so the center of each line is 1/8, 3/8, 5/8 and 7/8 |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 } | 854 } |
| 869 fsBuilder->codeAppend("\n\t\t}"); // end of the for loop on octaves | 855 fsBuilder->codeAppend("\n\t\t}"); // end of the for loop on octaves |
| 870 | 856 |
| 871 if (fType == SkPerlinNoiseShader::kFractalNoise_Type) { | 857 if (fType == SkPerlinNoiseShader::kFractalNoise_Type) { |
| 872 // The value of turbulenceFunctionResult comes from ((turbulenceFunction
Result) + 1) / 2 | 858 // The value of turbulenceFunctionResult comes from ((turbulenceFunction
Result) + 1) / 2 |
| 873 // by fractalNoise and (turbulenceFunctionResult) by turbulence. | 859 // by fractalNoise and (turbulenceFunctionResult) by turbulence. |
| 874 fsBuilder->codeAppendf("\n\t\t%s = %s * vec4(0.5) + vec4(0.5);", | 860 fsBuilder->codeAppendf("\n\t\t%s = %s * vec4(0.5) + vec4(0.5);", |
| 875 args.fOutputColor,args.fOutputColor); | 861 args.fOutputColor,args.fOutputColor); |
| 876 } | 862 } |
| 877 | 863 |
| 878 fsBuilder->codeAppendf("\n\t\t%s.a *= %s;", args.fOutputColor, alphaUni); | |
| 879 | |
| 880 // Clamp values | 864 // Clamp values |
| 881 fsBuilder->codeAppendf("\n\t\t%s = clamp(%s, 0.0, 1.0);", args.fOutputColor,
args.fOutputColor); | 865 fsBuilder->codeAppendf("\n\t\t%s = clamp(%s, 0.0, 1.0);", args.fOutputColor,
args.fOutputColor); |
| 882 | 866 |
| 883 // Pre-multiply the result | 867 // Pre-multiply the result |
| 884 fsBuilder->codeAppendf("\n\t\t%s = vec4(%s.rgb * %s.aaa, %s.a);\n", | 868 fsBuilder->codeAppendf("\n\t\t%s = vec4(%s.rgb * %s.aaa, %s.a);\n", |
| 885 args.fOutputColor, args.fOutputColor, | 869 args.fOutputColor, args.fOutputColor, |
| 886 args.fOutputColor, args.fOutputColor); | 870 args.fOutputColor, args.fOutputColor); |
| 887 } | 871 } |
| 888 | 872 |
| 889 void GrGLPerlinNoise::GenKey(const GrProcessor& processor, const GrGLSLCaps&, | 873 void GrGLPerlinNoise::GenKey(const GrProcessor& processor, const GrGLSLCaps&, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 913 b->add32(key); | 897 b->add32(key); |
| 914 } | 898 } |
| 915 | 899 |
| 916 void GrGLPerlinNoise::onSetData(const GrGLProgramDataManager& pdman, const GrPro
cessor& processor) { | 900 void GrGLPerlinNoise::onSetData(const GrGLProgramDataManager& pdman, const GrPro
cessor& processor) { |
| 917 INHERITED::onSetData(pdman, processor); | 901 INHERITED::onSetData(pdman, processor); |
| 918 | 902 |
| 919 const GrPerlinNoiseEffect& turbulence = processor.cast<GrPerlinNoiseEffect>(
); | 903 const GrPerlinNoiseEffect& turbulence = processor.cast<GrPerlinNoiseEffect>(
); |
| 920 | 904 |
| 921 const SkVector& baseFrequency = turbulence.baseFrequency(); | 905 const SkVector& baseFrequency = turbulence.baseFrequency(); |
| 922 pdman.set2f(fBaseFrequencyUni, baseFrequency.fX, baseFrequency.fY); | 906 pdman.set2f(fBaseFrequencyUni, baseFrequency.fX, baseFrequency.fY); |
| 923 pdman.set1f(fAlphaUni, SkIntToScalar(turbulence.alpha()) / 255); | |
| 924 | 907 |
| 925 if (turbulence.stitchTiles()) { | 908 if (turbulence.stitchTiles()) { |
| 926 const SkPerlinNoiseShader::StitchData& stitchData = turbulence.stitchDat
a(); | 909 const SkPerlinNoiseShader::StitchData& stitchData = turbulence.stitchDat
a(); |
| 927 pdman.set2f(fStitchDataUni, SkIntToScalar(stitchData.fWidth), | 910 pdman.set2f(fStitchDataUni, SkIntToScalar(stitchData.fWidth), |
| 928 SkIntToScalar(stitchData.fHeight)); | 911 SkIntToScalar(stitchData.fHeight)); |
| 929 } | 912 } |
| 930 } | 913 } |
| 931 | 914 |
| 932 ///////////////////////////////////////////////////////////////////// | 915 ///////////////////////////////////////////////////////////////////// |
| 933 | 916 const GrFragmentProcessor* SkPerlinNoiseShader::asFragmentProcessor( |
| 934 bool SkPerlinNoiseShader::asFragmentProcessor(GrContext* context, const SkPaint&
paint, | 917 GrContext* context, |
| 935 const SkMatrix& viewM, | 918 const SkMatrix& viewM, |
| 936 const SkMatrix* externalLocalMatri
x, | 919 const SkMatrix* externalLoca
lMatrix, |
| 937 GrColor* paintColor, | 920 SkFilterQuality, |
| 938 GrProcessorDataManager* procDataMa
nager, | 921 GrProcessorDataManager* proc
DataManager) const { |
| 939 GrFragmentProcessor** fp) const { | |
| 940 SkASSERT(context); | 922 SkASSERT(context); |
| 941 | 923 |
| 942 *paintColor = SkColor2GrColorJustAlpha(paint.getColor()); | |
| 943 | |
| 944 SkMatrix localMatrix = this->getLocalMatrix(); | 924 SkMatrix localMatrix = this->getLocalMatrix(); |
| 945 if (externalLocalMatrix) { | 925 if (externalLocalMatrix) { |
| 946 localMatrix.preConcat(*externalLocalMatrix); | 926 localMatrix.preConcat(*externalLocalMatrix); |
| 947 } | 927 } |
| 948 | 928 |
| 949 SkMatrix matrix = viewM; | 929 SkMatrix matrix = viewM; |
| 950 matrix.preConcat(localMatrix); | 930 matrix.preConcat(localMatrix); |
| 951 | 931 |
| 952 if (0 == fNumOctaves) { | 932 if (0 == fNumOctaves) { |
| 953 if (kFractalNoise_Type == fType) { | 933 if (kFractalNoise_Type == fType) { |
| 954 uint32_t alpha = paint.getAlpha() >> 1; | 934 // Extract the incoming alpha and emit rgba = (a/4, a/4, a/4, a/2) |
| 955 uint32_t rgb = alpha >> 1; | 935 SkAutoTUnref<const GrFragmentProcessor> inner( |
| 956 *paintColor = GrColorPackRGBA(rgb, rgb, rgb, alpha); | 936 GrConstColorProcessor::Create(0x80404040, |
| 957 } else { | 937 GrConstColorProcessor::kModulateRG
BA_InputMode)); |
| 958 *paintColor = 0; | 938 return GrExtractAlphaFragmentProcessor::Create(inner); |
| 959 } | 939 } |
| 960 return true; | 940 // Emit zero. |
| 941 return GrConstColorProcessor::Create(0x0, GrConstColorProcessor::kIgnore
_InputMode); |
| 961 } | 942 } |
| 962 | 943 |
| 963 // Either we don't stitch tiles, either we have a valid tile size | 944 // Either we don't stitch tiles, either we have a valid tile size |
| 964 SkASSERT(!fStitchTiles || !fTileSize.isEmpty()); | 945 SkASSERT(!fStitchTiles || !fTileSize.isEmpty()); |
| 965 | 946 |
| 966 SkPerlinNoiseShader::PaintingData* paintingData = | 947 SkPerlinNoiseShader::PaintingData* paintingData = |
| 967 new PaintingData(fTileSize, fSeed, fBaseFrequencyX, fBaseFrequencyY,
matrix); | 948 new PaintingData(fTileSize, fSeed, fBaseFrequencyX, fBaseFrequencyY,
matrix); |
| 968 SkAutoTUnref<GrTexture> permutationsTexture( | 949 SkAutoTUnref<GrTexture> permutationsTexture( |
| 969 GrRefCachedBitmapTexture(context, paintingData->getPermutationsBitmap(),
nullptr)); | 950 GrRefCachedBitmapTexture(context, paintingData->getPermutationsBitmap(),
nullptr)); |
| 970 SkAutoTUnref<GrTexture> noiseTexture( | 951 SkAutoTUnref<GrTexture> noiseTexture( |
| 971 GrRefCachedBitmapTexture(context, paintingData->getNoiseBitmap(), nullpt
r)); | 952 GrRefCachedBitmapTexture(context, paintingData->getNoiseBitmap(), nullpt
r)); |
| 972 | 953 |
| 973 SkMatrix m = viewM; | 954 SkMatrix m = viewM; |
| 974 m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1); | 955 m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1); |
| 975 m.setTranslateY(-localMatrix.getTranslateY() + SK_Scalar1); | 956 m.setTranslateY(-localMatrix.getTranslateY() + SK_Scalar1); |
| 976 if ((permutationsTexture) && (noiseTexture)) { | 957 if ((permutationsTexture) && (noiseTexture)) { |
| 977 *fp = GrPerlinNoiseEffect::Create(procDataManager, | 958 SkAutoTUnref<GrFragmentProcessor> inner( |
| 978 fType, | 959 GrPerlinNoiseEffect::Create(procDataManager, |
| 979 fNumOctaves, | 960 fType, |
| 980 fStitchTiles, | 961 fNumOctaves, |
| 981 paintingData, | 962 fStitchTiles, |
| 982 permutationsTexture, noiseTexture, | 963 paintingData, |
| 983 m, paint.getAlpha()); | 964 permutationsTexture, noiseTexture, |
| 984 } else { | 965 m)); |
| 985 delete paintingData; | 966 return GrExtractAlphaFragmentProcessor::Create(inner); |
| 986 *fp = nullptr; | |
| 987 } | 967 } |
| 988 return true; | 968 delete paintingData; |
| 989 } | 969 return nullptr; |
| 990 | |
| 991 #else | |
| 992 | |
| 993 bool SkPerlinNoiseShader::asFragmentProcessor(GrContext*, const SkPaint&, const
SkMatrix&, | |
| 994 const SkMatrix*, GrColor*, GrProce
ssorDataManager*, | |
| 995 GrFragmentProcessor**) const { | |
| 996 SkDEBUGFAIL("Should not call in GPU-less build"); | |
| 997 return false; | |
| 998 } | 970 } |
| 999 | 971 |
| 1000 #endif | 972 #endif |
| 1001 | 973 |
| 1002 #ifndef SK_IGNORE_TO_STRING | 974 #ifndef SK_IGNORE_TO_STRING |
| 1003 void SkPerlinNoiseShader::toString(SkString* str) const { | 975 void SkPerlinNoiseShader::toString(SkString* str) const { |
| 1004 str->append("SkPerlinNoiseShader: ("); | 976 str->append("SkPerlinNoiseShader: ("); |
| 1005 | 977 |
| 1006 str->append("type: "); | 978 str->append("type: "); |
| 1007 switch (fType) { | 979 switch (fType) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1024 str->append(" seed: "); | 996 str->append(" seed: "); |
| 1025 str->appendScalar(fSeed); | 997 str->appendScalar(fSeed); |
| 1026 str->append(" stitch tiles: "); | 998 str->append(" stitch tiles: "); |
| 1027 str->append(fStitchTiles ? "true " : "false "); | 999 str->append(fStitchTiles ? "true " : "false "); |
| 1028 | 1000 |
| 1029 this->INHERITED::toString(str); | 1001 this->INHERITED::toString(str); |
| 1030 | 1002 |
| 1031 str->append(")"); | 1003 str->append(")"); |
| 1032 } | 1004 } |
| 1033 #endif | 1005 #endif |
| OLD | NEW |