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 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 GrGLProgramDataManager::UniformHandle fAlphaUni; | 508 GrGLProgramDataManager::UniformHandle fAlphaUni; |
509 | 509 |
510 private: | 510 private: |
511 typedef GrGLFragmentProcessor INHERITED; | 511 typedef GrGLFragmentProcessor INHERITED; |
512 }; | 512 }; |
513 | 513 |
514 ///////////////////////////////////////////////////////////////////// | 514 ///////////////////////////////////////////////////////////////////// |
515 | 515 |
516 class GrPerlinNoiseEffect : public GrFragmentProcessor { | 516 class GrPerlinNoiseEffect : public GrFragmentProcessor { |
517 public: | 517 public: |
518 static GrFragmentProcessor* Create(SkPerlinNoiseShader::Type type, | 518 static GrFragmentProcessor* Create(GrShaderDataManager* shaderDataManager, |
| 519 SkPerlinNoiseShader::Type type, |
519 int numOctaves, bool stitchTiles, | 520 int numOctaves, bool stitchTiles, |
520 SkPerlinNoiseShader::PaintingData* painti
ngData, | 521 SkPerlinNoiseShader::PaintingData* painti
ngData, |
521 GrTexture* permutationsTexture, GrTexture
* noiseTexture, | 522 GrTexture* permutationsTexture, GrTexture
* noiseTexture, |
522 const SkMatrix& matrix, uint8_t alpha) { | 523 const SkMatrix& matrix, uint8_t alpha) { |
523 return SkNEW_ARGS(GrPerlinNoiseEffect, (type, numOctaves, stitchTiles, p
aintingData, | 524 return SkNEW_ARGS(GrPerlinNoiseEffect, (shaderDataManager, type, numOcta
ves, stitchTiles, |
524 permutationsTexture, noiseTextur
e, matrix, alpha)); | 525 paintingData, permutationsTextur
e, noiseTexture, |
| 526 matrix, alpha)); |
525 } | 527 } |
526 | 528 |
527 virtual ~GrPerlinNoiseEffect() { | 529 virtual ~GrPerlinNoiseEffect() { |
528 SkDELETE(fPaintingData); | 530 SkDELETE(fPaintingData); |
529 } | 531 } |
530 | 532 |
531 const char* name() const override { return "PerlinNoise"; } | 533 const char* name() const override { return "PerlinNoise"; } |
532 | 534 |
533 virtual void getGLProcessorKey(const GrGLSLCaps& caps, | 535 virtual void getGLProcessorKey(const GrGLSLCaps& caps, |
534 GrProcessorKeyBuilder* b) const override { | 536 GrProcessorKeyBuilder* b) const override { |
(...skipping 21 matching lines...) Expand all Loading... |
556 fNumOctaves == s.fNumOctaves && | 558 fNumOctaves == s.fNumOctaves && |
557 fStitchTiles == s.fStitchTiles && | 559 fStitchTiles == s.fStitchTiles && |
558 fAlpha == s.fAlpha && | 560 fAlpha == s.fAlpha && |
559 fPaintingData->fStitchDataInit == s.fPaintingData->fStitchDataIni
t; | 561 fPaintingData->fStitchDataInit == s.fPaintingData->fStitchDataIni
t; |
560 } | 562 } |
561 | 563 |
562 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { | 564 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { |
563 inout->setToUnknown(GrInvariantOutput::kWillNot_ReadInput); | 565 inout->setToUnknown(GrInvariantOutput::kWillNot_ReadInput); |
564 } | 566 } |
565 | 567 |
566 GrPerlinNoiseEffect(SkPerlinNoiseShader::Type type, | 568 GrPerlinNoiseEffect(GrShaderDataManager*, SkPerlinNoiseShader::Type type, |
567 int numOctaves, bool stitchTiles, | 569 int numOctaves, bool stitchTiles, |
568 SkPerlinNoiseShader::PaintingData* paintingData, | 570 SkPerlinNoiseShader::PaintingData* paintingData, |
569 GrTexture* permutationsTexture, GrTexture* noiseTexture, | 571 GrTexture* permutationsTexture, GrTexture* noiseTexture, |
570 const SkMatrix& matrix, uint8_t alpha) | 572 const SkMatrix& matrix, uint8_t alpha) |
571 : fType(type) | 573 : fType(type) |
572 , fNumOctaves(numOctaves) | 574 , fNumOctaves(numOctaves) |
573 , fStitchTiles(stitchTiles) | 575 , fStitchTiles(stitchTiles) |
574 , fAlpha(alpha) | 576 , fAlpha(alpha) |
575 , fPermutationsAccess(permutationsTexture) | 577 , fPermutationsAccess(permutationsTexture) |
576 , fNoiseAccess(noiseTexture) | 578 , fNoiseAccess(noiseTexture) |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
938 pdman.set2f(fStitchDataUni, SkIntToScalar(stitchData.fWidth), | 940 pdman.set2f(fStitchDataUni, SkIntToScalar(stitchData.fWidth), |
939 SkIntToScalar(stitchData.fHeight)); | 941 SkIntToScalar(stitchData.fHeight)); |
940 } | 942 } |
941 } | 943 } |
942 | 944 |
943 ///////////////////////////////////////////////////////////////////// | 945 ///////////////////////////////////////////////////////////////////// |
944 | 946 |
945 bool SkPerlinNoiseShader::asFragmentProcessor(GrContext* context, const SkPaint&
paint, | 947 bool SkPerlinNoiseShader::asFragmentProcessor(GrContext* context, const SkPaint&
paint, |
946 const SkMatrix& viewM, | 948 const SkMatrix& viewM, |
947 const SkMatrix* externalLocalMatri
x, | 949 const SkMatrix* externalLocalMatri
x, |
948 GrColor* paintColor, GrShaderDataM
anager*, | 950 GrColor* paintColor, |
| 951 GrShaderDataManager* shaderDataMan
ager, |
949 GrFragmentProcessor** fp) const { | 952 GrFragmentProcessor** fp) const { |
950 SkASSERT(context); | 953 SkASSERT(context); |
951 | 954 |
952 *paintColor = SkColor2GrColorJustAlpha(paint.getColor()); | 955 *paintColor = SkColor2GrColorJustAlpha(paint.getColor()); |
953 | 956 |
954 SkMatrix localMatrix = this->getLocalMatrix(); | 957 SkMatrix localMatrix = this->getLocalMatrix(); |
955 if (externalLocalMatrix) { | 958 if (externalLocalMatrix) { |
956 localMatrix.preConcat(*externalLocalMatrix); | 959 localMatrix.preConcat(*externalLocalMatrix); |
957 } | 960 } |
958 | 961 |
(...skipping 18 matching lines...) Expand all Loading... |
977 SkNEW_ARGS(PaintingData, (fTileSize, fSeed, fBaseFrequencyX, fBaseFr
equencyY, matrix)); | 980 SkNEW_ARGS(PaintingData, (fTileSize, fSeed, fBaseFrequencyX, fBaseFr
equencyY, matrix)); |
978 SkAutoTUnref<GrTexture> permutationsTexture( | 981 SkAutoTUnref<GrTexture> permutationsTexture( |
979 GrRefCachedBitmapTexture(context, paintingData->getPermutationsBitmap(),
NULL)); | 982 GrRefCachedBitmapTexture(context, paintingData->getPermutationsBitmap(),
NULL)); |
980 SkAutoTUnref<GrTexture> noiseTexture( | 983 SkAutoTUnref<GrTexture> noiseTexture( |
981 GrRefCachedBitmapTexture(context, paintingData->getNoiseBitmap(), NULL))
; | 984 GrRefCachedBitmapTexture(context, paintingData->getNoiseBitmap(), NULL))
; |
982 | 985 |
983 SkMatrix m = viewM; | 986 SkMatrix m = viewM; |
984 m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1); | 987 m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1); |
985 m.setTranslateY(-localMatrix.getTranslateY() + SK_Scalar1); | 988 m.setTranslateY(-localMatrix.getTranslateY() + SK_Scalar1); |
986 if ((permutationsTexture) && (noiseTexture)) { | 989 if ((permutationsTexture) && (noiseTexture)) { |
987 *fp = GrPerlinNoiseEffect::Create(fType, | 990 *fp = GrPerlinNoiseEffect::Create(shaderDataManager, |
| 991 fType, |
988 fNumOctaves, | 992 fNumOctaves, |
989 fStitchTiles, | 993 fStitchTiles, |
990 paintingData, | 994 paintingData, |
991 permutationsTexture, noiseTexture, | 995 permutationsTexture, noiseTexture, |
992 m, paint.getAlpha()); | 996 m, paint.getAlpha()); |
993 } else { | 997 } else { |
994 SkDELETE(paintingData); | 998 SkDELETE(paintingData); |
995 *fp = NULL; | 999 *fp = NULL; |
996 } | 1000 } |
997 return true; | 1001 return true; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 str->append(" seed: "); | 1037 str->append(" seed: "); |
1034 str->appendScalar(fSeed); | 1038 str->appendScalar(fSeed); |
1035 str->append(" stitch tiles: "); | 1039 str->append(" stitch tiles: "); |
1036 str->append(fStitchTiles ? "true " : "false "); | 1040 str->append(fStitchTiles ? "true " : "false "); |
1037 | 1041 |
1038 this->INHERITED::toString(str); | 1042 this->INHERITED::toString(str); |
1039 | 1043 |
1040 str->append(")"); | 1044 str->append(")"); |
1041 } | 1045 } |
1042 #endif | 1046 #endif |
OLD | NEW |