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 "glsl/GrGLSLFragmentProcessor.h" |
24 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 24 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
25 #include "glsl/GrGLSLProgramBuilder.h" | 25 #include "glsl/GrGLSLProgramBuilder.h" |
26 #include "glsl/GrGLSLProgramDataManager.h" | 26 #include "glsl/GrGLSLProgramDataManager.h" |
27 #endif | 27 #endif |
28 | 28 |
29 static const int kBlockSize = 256; | 29 static const int kBlockSize = 256; |
30 static const int kBlockMask = kBlockSize - 1; | 30 static const int kBlockMask = kBlockSize - 1; |
31 static const int kPerlinNoise = 4096; | 31 static const int kPerlinNoise = 4096; |
32 static const int kRandMaximum = SK_MaxS32; // 2**31 - 1 | 32 static const int kRandMaximum = SK_MaxS32; // 2**31 - 1 |
33 | 33 |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 result[i] = SkDitherRGB32To565(shade(point, stitchData), dither); | 477 result[i] = SkDitherRGB32To565(shade(point, stitchData), dither); |
478 DITHER_INC_X(x); | 478 DITHER_INC_X(x); |
479 point.fX += SK_Scalar1; | 479 point.fX += SK_Scalar1; |
480 } | 480 } |
481 } | 481 } |
482 | 482 |
483 ///////////////////////////////////////////////////////////////////// | 483 ///////////////////////////////////////////////////////////////////// |
484 | 484 |
485 #if SK_SUPPORT_GPU | 485 #if SK_SUPPORT_GPU |
486 | 486 |
487 class GrGLPerlinNoise : public GrGLFragmentProcessor { | 487 class GrGLPerlinNoise : public GrGLSLFragmentProcessor { |
488 public: | 488 public: |
489 GrGLPerlinNoise(const GrProcessor&); | 489 GrGLPerlinNoise(const GrProcessor&); |
490 virtual ~GrGLPerlinNoise() {} | 490 virtual ~GrGLPerlinNoise() {} |
491 | 491 |
492 virtual void emitCode(EmitArgs&) override; | 492 virtual void emitCode(EmitArgs&) override; |
493 | 493 |
494 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder* b); | 494 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder* b); |
495 | 495 |
496 protected: | 496 protected: |
497 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; | 497 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; |
498 | 498 |
499 private: | 499 private: |
500 | 500 |
501 GrGLSLProgramDataManager::UniformHandle fStitchDataUni; | 501 GrGLSLProgramDataManager::UniformHandle fStitchDataUni; |
502 SkPerlinNoiseShader::Type fType; | 502 SkPerlinNoiseShader::Type fType; |
503 bool fStitchTiles; | 503 bool fStitchTiles; |
504 int fNumOctaves; | 504 int fNumOctaves; |
505 GrGLSLProgramDataManager::UniformHandle fBaseFrequencyUni; | 505 GrGLSLProgramDataManager::UniformHandle fBaseFrequencyUni; |
506 | 506 |
507 private: | 507 private: |
508 typedef GrGLFragmentProcessor INHERITED; | 508 typedef GrGLSLFragmentProcessor INHERITED; |
509 }; | 509 }; |
510 | 510 |
511 ///////////////////////////////////////////////////////////////////// | 511 ///////////////////////////////////////////////////////////////////// |
512 | 512 |
513 class GrPerlinNoiseEffect : public GrFragmentProcessor { | 513 class GrPerlinNoiseEffect : public GrFragmentProcessor { |
514 public: | 514 public: |
515 static GrFragmentProcessor* Create(SkPerlinNoiseShader::Type type, | 515 static GrFragmentProcessor* Create(SkPerlinNoiseShader::Type type, |
516 int numOctaves, bool stitchTiles, | 516 int numOctaves, bool stitchTiles, |
517 SkPerlinNoiseShader::PaintingData* painti
ngData, | 517 SkPerlinNoiseShader::PaintingData* painti
ngData, |
518 GrTexture* permutationsTexture, GrTexture
* noiseTexture, | 518 GrTexture* permutationsTexture, GrTexture
* noiseTexture, |
519 const SkMatrix& matrix) { | 519 const SkMatrix& matrix) { |
520 return new GrPerlinNoiseEffect(type, numOctaves, stitchTiles, paintingDa
ta, | 520 return new GrPerlinNoiseEffect(type, numOctaves, stitchTiles, paintingDa
ta, |
521 permutationsTexture, noiseTexture, matrix
); | 521 permutationsTexture, noiseTexture, matrix
); |
522 } | 522 } |
523 | 523 |
524 virtual ~GrPerlinNoiseEffect() { delete fPaintingData; } | 524 virtual ~GrPerlinNoiseEffect() { delete fPaintingData; } |
525 | 525 |
526 const char* name() const override { return "PerlinNoise"; } | 526 const char* name() const override { return "PerlinNoise"; } |
527 | 527 |
528 const SkPerlinNoiseShader::StitchData& stitchData() const { return fPainting
Data->fStitchDataInit; } | 528 const SkPerlinNoiseShader::StitchData& stitchData() const { return fPainting
Data->fStitchDataInit; } |
529 | 529 |
530 SkPerlinNoiseShader::Type type() const { return fType; } | 530 SkPerlinNoiseShader::Type type() const { return fType; } |
531 bool stitchTiles() const { return fStitchTiles; } | 531 bool stitchTiles() const { return fStitchTiles; } |
532 const SkVector& baseFrequency() const { return fPaintingData->fBaseFrequency
; } | 532 const SkVector& baseFrequency() const { return fPaintingData->fBaseFrequency
; } |
533 int numOctaves() const { return fNumOctaves; } | 533 int numOctaves() const { return fNumOctaves; } |
534 const SkMatrix& matrix() const { return fCoordTransform.getMatrix(); } | 534 const SkMatrix& matrix() const { return fCoordTransform.getMatrix(); } |
535 | 535 |
536 private: | 536 private: |
537 GrGLFragmentProcessor* onCreateGLInstance() const override { | 537 GrGLSLFragmentProcessor* 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>(); |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
996 str->append(" seed: "); | 996 str->append(" seed: "); |
997 str->appendScalar(fSeed); | 997 str->appendScalar(fSeed); |
998 str->append(" stitch tiles: "); | 998 str->append(" stitch tiles: "); |
999 str->append(fStitchTiles ? "true " : "false "); | 999 str->append(fStitchTiles ? "true " : "false "); |
1000 | 1000 |
1001 this->INHERITED::toString(str); | 1001 this->INHERITED::toString(str); |
1002 | 1002 |
1003 str->append(")"); | 1003 str->append(")"); |
1004 } | 1004 } |
1005 #endif | 1005 #endif |
OLD | NEW |