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" | 22 #include "effects/GrConstColorProcessor.h" |
23 #include "gl/GrGLFragmentProcessor.h" | 23 #include "gl/GrGLFragmentProcessor.h" |
24 #include "gl/builders/GrGLProgramBuilder.h" | 24 #include "gl/builders/GrGLProgramBuilder.h" |
| 25 #include "glsl/GrGLSLProgramDataManager.h" |
25 #endif | 26 #endif |
26 | 27 |
27 static const int kBlockSize = 256; | 28 static const int kBlockSize = 256; |
28 static const int kBlockMask = kBlockSize - 1; | 29 static const int kBlockMask = kBlockSize - 1; |
29 static const int kPerlinNoise = 4096; | 30 static const int kPerlinNoise = 4096; |
30 static const int kRandMaximum = SK_MaxS32; // 2**31 - 1 | 31 static const int kRandMaximum = SK_MaxS32; // 2**31 - 1 |
31 | 32 |
32 namespace { | 33 namespace { |
33 | 34 |
34 // noiseValue is the color component's value (or color) | 35 // noiseValue is the color component's value (or color) |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 class GrGLPerlinNoise : public GrGLFragmentProcessor { | 486 class GrGLPerlinNoise : public GrGLFragmentProcessor { |
486 public: | 487 public: |
487 GrGLPerlinNoise(const GrProcessor&); | 488 GrGLPerlinNoise(const GrProcessor&); |
488 virtual ~GrGLPerlinNoise() {} | 489 virtual ~GrGLPerlinNoise() {} |
489 | 490 |
490 virtual void emitCode(EmitArgs&) override; | 491 virtual void emitCode(EmitArgs&) override; |
491 | 492 |
492 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder* b); | 493 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder* b); |
493 | 494 |
494 protected: | 495 protected: |
495 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; | 496 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; |
496 | 497 |
497 private: | 498 private: |
498 | 499 |
499 GrGLProgramDataManager::UniformHandle fStitchDataUni; | 500 GrGLSLProgramDataManager::UniformHandle fStitchDataUni; |
500 SkPerlinNoiseShader::Type fType; | 501 SkPerlinNoiseShader::Type fType; |
501 bool fStitchTiles; | 502 bool fStitchTiles; |
502 int fNumOctaves; | 503 int fNumOctaves; |
503 GrGLProgramDataManager::UniformHandle fBaseFrequencyUni; | 504 GrGLSLProgramDataManager::UniformHandle fBaseFrequencyUni; |
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(SkPerlinNoiseShader::Type type, | 514 static GrFragmentProcessor* Create(SkPerlinNoiseShader::Type type, |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 break; | 888 break; |
888 } | 889 } |
889 | 890 |
890 if (turbulence.stitchTiles()) { | 891 if (turbulence.stitchTiles()) { |
891 key |= 0x4; // Flip the 3rd bit if tile stitching is on | 892 key |= 0x4; // Flip the 3rd bit if tile stitching is on |
892 } | 893 } |
893 | 894 |
894 b->add32(key); | 895 b->add32(key); |
895 } | 896 } |
896 | 897 |
897 void GrGLPerlinNoise::onSetData(const GrGLProgramDataManager& pdman, const GrPro
cessor& processor) { | 898 void GrGLPerlinNoise::onSetData(const GrGLSLProgramDataManager& pdman, |
| 899 const GrProcessor& processor) { |
898 INHERITED::onSetData(pdman, processor); | 900 INHERITED::onSetData(pdman, processor); |
899 | 901 |
900 const GrPerlinNoiseEffect& turbulence = processor.cast<GrPerlinNoiseEffect>(
); | 902 const GrPerlinNoiseEffect& turbulence = processor.cast<GrPerlinNoiseEffect>(
); |
901 | 903 |
902 const SkVector& baseFrequency = turbulence.baseFrequency(); | 904 const SkVector& baseFrequency = turbulence.baseFrequency(); |
903 pdman.set2f(fBaseFrequencyUni, baseFrequency.fX, baseFrequency.fY); | 905 pdman.set2f(fBaseFrequencyUni, baseFrequency.fX, baseFrequency.fY); |
904 | 906 |
905 if (turbulence.stitchTiles()) { | 907 if (turbulence.stitchTiles()) { |
906 const SkPerlinNoiseShader::StitchData& stitchData = turbulence.stitchDat
a(); | 908 const SkPerlinNoiseShader::StitchData& stitchData = turbulence.stitchDat
a(); |
907 pdman.set2f(fStitchDataUni, SkIntToScalar(stitchData.fWidth), | 909 pdman.set2f(fStitchDataUni, SkIntToScalar(stitchData.fWidth), |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
993 str->append(" seed: "); | 995 str->append(" seed: "); |
994 str->appendScalar(fSeed); | 996 str->appendScalar(fSeed); |
995 str->append(" stitch tiles: "); | 997 str->append(" stitch tiles: "); |
996 str->append(fStitchTiles ? "true " : "false "); | 998 str->append(fStitchTiles ? "true " : "false "); |
997 | 999 |
998 this->INHERITED::toString(str); | 1000 this->INHERITED::toString(str); |
999 | 1001 |
1000 str->append(")"); | 1002 str->append(")"); |
1001 } | 1003 } |
1002 #endif | 1004 #endif |
OLD | NEW |