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 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 | 482 |
483 #if SK_SUPPORT_GPU | 483 #if SK_SUPPORT_GPU |
484 | 484 |
485 class GrGLPerlinNoise : public GrGLFragmentProcessor { | 485 class GrGLPerlinNoise : public GrGLFragmentProcessor { |
486 public: | 486 public: |
487 GrGLPerlinNoise(const GrProcessor&); | 487 GrGLPerlinNoise(const GrProcessor&); |
488 virtual ~GrGLPerlinNoise() {} | 488 virtual ~GrGLPerlinNoise() {} |
489 | 489 |
490 virtual void emitCode(EmitArgs&) override; | 490 virtual void emitCode(EmitArgs&) override; |
491 | 491 |
492 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; | 492 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder* b); |
493 | 493 |
494 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder* b); | 494 protected: |
| 495 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; |
495 | 496 |
496 private: | 497 private: |
497 | 498 |
498 GrGLProgramDataManager::UniformHandle fStitchDataUni; | 499 GrGLProgramDataManager::UniformHandle fStitchDataUni; |
499 SkPerlinNoiseShader::Type fType; | 500 SkPerlinNoiseShader::Type fType; |
500 bool fStitchTiles; | 501 bool fStitchTiles; |
501 int fNumOctaves; | 502 int fNumOctaves; |
502 GrGLProgramDataManager::UniformHandle fBaseFrequencyUni; | 503 GrGLProgramDataManager::UniformHandle fBaseFrequencyUni; |
503 GrGLProgramDataManager::UniformHandle fAlphaUni; | 504 GrGLProgramDataManager::UniformHandle fAlphaUni; |
504 | 505 |
(...skipping 15 matching lines...) Expand all Loading... |
520 paintingData, permutationsTextur
e, noiseTexture, | 521 paintingData, permutationsTextur
e, noiseTexture, |
521 matrix, alpha)); | 522 matrix, alpha)); |
522 } | 523 } |
523 | 524 |
524 virtual ~GrPerlinNoiseEffect() { | 525 virtual ~GrPerlinNoiseEffect() { |
525 SkDELETE(fPaintingData); | 526 SkDELETE(fPaintingData); |
526 } | 527 } |
527 | 528 |
528 const char* name() const override { return "PerlinNoise"; } | 529 const char* name() const override { return "PerlinNoise"; } |
529 | 530 |
530 GrGLFragmentProcessor* createGLInstance() const override { | |
531 return SkNEW_ARGS(GrGLPerlinNoise, (*this)); | |
532 } | |
533 | |
534 const SkPerlinNoiseShader::StitchData& stitchData() const { return fPainting
Data->fStitchDataInit; } | 531 const SkPerlinNoiseShader::StitchData& stitchData() const { return fPainting
Data->fStitchDataInit; } |
535 | 532 |
536 SkPerlinNoiseShader::Type type() const { return fType; } | 533 SkPerlinNoiseShader::Type type() const { return fType; } |
537 bool stitchTiles() const { return fStitchTiles; } | 534 bool stitchTiles() const { return fStitchTiles; } |
538 const SkVector& baseFrequency() const { return fPaintingData->fBaseFrequency
; } | 535 const SkVector& baseFrequency() const { return fPaintingData->fBaseFrequency
; } |
539 int numOctaves() const { return fNumOctaves; } | 536 int numOctaves() const { return fNumOctaves; } |
540 const SkMatrix& matrix() const { return fCoordTransform.getMatrix(); } | 537 const SkMatrix& matrix() const { return fCoordTransform.getMatrix(); } |
541 uint8_t alpha() const { return fAlpha; } | 538 uint8_t alpha() const { return fAlpha; } |
542 | 539 |
543 private: | 540 private: |
| 541 GrGLFragmentProcessor* onCreateGLInstance() const override { |
| 542 return SkNEW_ARGS(GrGLPerlinNoise, (*this)); |
| 543 } |
| 544 |
544 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, | 545 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, |
545 GrProcessorKeyBuilder* b) const override { | 546 GrProcessorKeyBuilder* b) const override { |
546 GrGLPerlinNoise::GenKey(*this, caps, b); | 547 GrGLPerlinNoise::GenKey(*this, caps, b); |
547 } | 548 } |
548 | 549 |
549 bool onIsEqual(const GrFragmentProcessor& sBase) const override { | 550 bool onIsEqual(const GrFragmentProcessor& sBase) const override { |
550 const GrPerlinNoiseEffect& s = sBase.cast<GrPerlinNoiseEffect>(); | 551 const GrPerlinNoiseEffect& s = sBase.cast<GrPerlinNoiseEffect>(); |
551 return fType == s.fType && | 552 return fType == s.fType && |
552 fPaintingData->fBaseFrequency == s.fPaintingData->fBaseFrequency
&& | 553 fPaintingData->fBaseFrequency == s.fPaintingData->fBaseFrequency
&& |
553 fNumOctaves == s.fNumOctaves && | 554 fNumOctaves == s.fNumOctaves && |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 break; | 910 break; |
910 } | 911 } |
911 | 912 |
912 if (turbulence.stitchTiles()) { | 913 if (turbulence.stitchTiles()) { |
913 key |= 0x4; // Flip the 3rd bit if tile stitching is on | 914 key |= 0x4; // Flip the 3rd bit if tile stitching is on |
914 } | 915 } |
915 | 916 |
916 b->add32(key); | 917 b->add32(key); |
917 } | 918 } |
918 | 919 |
919 void GrGLPerlinNoise::setData(const GrGLProgramDataManager& pdman, const GrProce
ssor& processor) { | 920 void GrGLPerlinNoise::onSetData(const GrGLProgramDataManager& pdman, const GrPro
cessor& processor) { |
920 INHERITED::setData(pdman, processor); | 921 INHERITED::onSetData(pdman, processor); |
921 | 922 |
922 const GrPerlinNoiseEffect& turbulence = processor.cast<GrPerlinNoiseEffect>(
); | 923 const GrPerlinNoiseEffect& turbulence = processor.cast<GrPerlinNoiseEffect>(
); |
923 | 924 |
924 const SkVector& baseFrequency = turbulence.baseFrequency(); | 925 const SkVector& baseFrequency = turbulence.baseFrequency(); |
925 pdman.set2f(fBaseFrequencyUni, baseFrequency.fX, baseFrequency.fY); | 926 pdman.set2f(fBaseFrequencyUni, baseFrequency.fX, baseFrequency.fY); |
926 pdman.set1f(fAlphaUni, SkIntToScalar(turbulence.alpha()) / 255); | 927 pdman.set1f(fAlphaUni, SkIntToScalar(turbulence.alpha()) / 255); |
927 | 928 |
928 if (turbulence.stitchTiles()) { | 929 if (turbulence.stitchTiles()) { |
929 const SkPerlinNoiseShader::StitchData& stitchData = turbulence.stitchDat
a(); | 930 const SkPerlinNoiseShader::StitchData& stitchData = turbulence.stitchDat
a(); |
930 pdman.set2f(fStitchDataUni, SkIntToScalar(stitchData.fWidth), | 931 pdman.set2f(fStitchDataUni, SkIntToScalar(stitchData.fWidth), |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1027 str->append(" seed: "); | 1028 str->append(" seed: "); |
1028 str->appendScalar(fSeed); | 1029 str->appendScalar(fSeed); |
1029 str->append(" stitch tiles: "); | 1030 str->append(" stitch tiles: "); |
1030 str->append(fStitchTiles ? "true " : "false "); | 1031 str->append(fStitchTiles ? "true " : "false "); |
1031 | 1032 |
1032 this->INHERITED::toString(str); | 1033 this->INHERITED::toString(str); |
1033 | 1034 |
1034 str->append(")"); | 1035 str->append(")"); |
1035 } | 1036 } |
1036 #endif | 1037 #endif |
OLD | NEW |