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 "effects/GrExtractAlphaFragmentProcessor.h" | |
24 #include "gl/GrGLFragmentProcessor.h" | 23 #include "gl/GrGLFragmentProcessor.h" |
25 #include "gl/builders/GrGLProgramBuilder.h" | 24 #include "gl/builders/GrGLProgramBuilder.h" |
26 #endif | 25 #endif |
27 | 26 |
28 static const int kBlockSize = 256; | 27 static const int kBlockSize = 256; |
29 static const int kBlockMask = kBlockSize - 1; | 28 static const int kBlockMask = kBlockSize - 1; |
30 static const int kPerlinNoise = 4096; | 29 static const int kPerlinNoise = 4096; |
31 static const int kRandMaximum = SK_MaxS32; // 2**31 - 1 | 30 static const int kRandMaximum = SK_MaxS32; // 2**31 - 1 |
32 | 31 |
33 namespace { | 32 namespace { |
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 | 927 |
929 SkMatrix matrix = viewM; | 928 SkMatrix matrix = viewM; |
930 matrix.preConcat(localMatrix); | 929 matrix.preConcat(localMatrix); |
931 | 930 |
932 if (0 == fNumOctaves) { | 931 if (0 == fNumOctaves) { |
933 if (kFractalNoise_Type == fType) { | 932 if (kFractalNoise_Type == fType) { |
934 // Extract the incoming alpha and emit rgba = (a/4, a/4, a/4, a/2) | 933 // Extract the incoming alpha and emit rgba = (a/4, a/4, a/4, a/2) |
935 SkAutoTUnref<const GrFragmentProcessor> inner( | 934 SkAutoTUnref<const GrFragmentProcessor> inner( |
936 GrConstColorProcessor::Create(0x80404040, | 935 GrConstColorProcessor::Create(0x80404040, |
937 GrConstColorProcessor::kModulateRG
BA_InputMode)); | 936 GrConstColorProcessor::kModulateRG
BA_InputMode)); |
938 return GrExtractAlphaFragmentProcessor::Create(inner); | 937 return GrFragmentProcessor::MulOuputByInputAlpha(inner); |
939 } | 938 } |
940 // Emit zero. | 939 // Emit zero. |
941 return GrConstColorProcessor::Create(0x0, GrConstColorProcessor::kIgnore
_InputMode); | 940 return GrConstColorProcessor::Create(0x0, GrConstColorProcessor::kIgnore
_InputMode); |
942 } | 941 } |
943 | 942 |
944 // Either we don't stitch tiles, either we have a valid tile size | 943 // Either we don't stitch tiles, either we have a valid tile size |
945 SkASSERT(!fStitchTiles || !fTileSize.isEmpty()); | 944 SkASSERT(!fStitchTiles || !fTileSize.isEmpty()); |
946 | 945 |
947 SkPerlinNoiseShader::PaintingData* paintingData = | 946 SkPerlinNoiseShader::PaintingData* paintingData = |
948 new PaintingData(fTileSize, fSeed, fBaseFrequencyX, fBaseFrequencyY,
matrix); | 947 new PaintingData(fTileSize, fSeed, fBaseFrequencyX, fBaseFrequencyY,
matrix); |
949 SkAutoTUnref<GrTexture> permutationsTexture( | 948 SkAutoTUnref<GrTexture> permutationsTexture( |
950 GrRefCachedBitmapTexture(context, paintingData->getPermutationsBitmap(),
nullptr)); | 949 GrRefCachedBitmapTexture(context, paintingData->getPermutationsBitmap(),
nullptr)); |
951 SkAutoTUnref<GrTexture> noiseTexture( | 950 SkAutoTUnref<GrTexture> noiseTexture( |
952 GrRefCachedBitmapTexture(context, paintingData->getNoiseBitmap(), nullpt
r)); | 951 GrRefCachedBitmapTexture(context, paintingData->getNoiseBitmap(), nullpt
r)); |
953 | 952 |
954 SkMatrix m = viewM; | 953 SkMatrix m = viewM; |
955 m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1); | 954 m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1); |
956 m.setTranslateY(-localMatrix.getTranslateY() + SK_Scalar1); | 955 m.setTranslateY(-localMatrix.getTranslateY() + SK_Scalar1); |
957 if ((permutationsTexture) && (noiseTexture)) { | 956 if ((permutationsTexture) && (noiseTexture)) { |
958 SkAutoTUnref<GrFragmentProcessor> inner( | 957 SkAutoTUnref<GrFragmentProcessor> inner( |
959 GrPerlinNoiseEffect::Create(procDataManager, | 958 GrPerlinNoiseEffect::Create(procDataManager, |
960 fType, | 959 fType, |
961 fNumOctaves, | 960 fNumOctaves, |
962 fStitchTiles, | 961 fStitchTiles, |
963 paintingData, | 962 paintingData, |
964 permutationsTexture, noiseTexture, | 963 permutationsTexture, noiseTexture, |
965 m)); | 964 m)); |
966 return GrExtractAlphaFragmentProcessor::Create(inner); | 965 return GrFragmentProcessor::MulOuputByInputAlpha(inner); |
967 } | 966 } |
968 delete paintingData; | 967 delete paintingData; |
969 return nullptr; | 968 return nullptr; |
970 } | 969 } |
971 | 970 |
972 #endif | 971 #endif |
973 | 972 |
974 #ifndef SK_IGNORE_TO_STRING | 973 #ifndef SK_IGNORE_TO_STRING |
975 void SkPerlinNoiseShader::toString(SkString* str) const { | 974 void SkPerlinNoiseShader::toString(SkString* str) const { |
976 str->append("SkPerlinNoiseShader: ("); | 975 str->append("SkPerlinNoiseShader: ("); |
(...skipping 19 matching lines...) Expand all Loading... |
996 str->append(" seed: "); | 995 str->append(" seed: "); |
997 str->appendScalar(fSeed); | 996 str->appendScalar(fSeed); |
998 str->append(" stitch tiles: "); | 997 str->append(" stitch tiles: "); |
999 str->append(fStitchTiles ? "true " : "false "); | 998 str->append(fStitchTiles ? "true " : "false "); |
1000 | 999 |
1001 this->INHERITED::toString(str); | 1000 this->INHERITED::toString(str); |
1002 | 1001 |
1003 str->append(")"); | 1002 str->append(")"); |
1004 } | 1003 } |
1005 #endif | 1004 #endif |
OLD | NEW |