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 "SkPerlinNoiseShader2.h" | 9 #include "SkPerlinNoiseShader2.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 "glsl/GrGLSLFragmentProcessor.h" | 23 #include "glsl/GrGLSLFragmentProcessor.h" |
24 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 24 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
25 #include "glsl/GrGLSLProgramBuilder.h" | |
26 #include "glsl/GrGLSLProgramDataManager.h" | 25 #include "glsl/GrGLSLProgramDataManager.h" |
| 26 #include "glsl/GrGLSLUniformHandler.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 |
34 static uint8_t improved_noise_permutations[] = { | 34 static uint8_t improved_noise_permutations[] = { |
35 151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 2
25, 140, 36, 103, | 35 151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 2
25, 140, 36, 103, |
36 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148, 247, 120, 2
34, 75, 0, 26, | 36 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148, 247, 120, 2
34, 75, 0, 26, |
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 } | 751 } |
752 | 752 |
753 GrGLPerlinNoise2::GrGLPerlinNoise2(const GrProcessor& processor) | 753 GrGLPerlinNoise2::GrGLPerlinNoise2(const GrProcessor& processor) |
754 : fType(processor.cast<GrPerlinNoise2Effect>().type()) | 754 : fType(processor.cast<GrPerlinNoise2Effect>().type()) |
755 , fStitchTiles(processor.cast<GrPerlinNoise2Effect>().stitchTiles()) | 755 , fStitchTiles(processor.cast<GrPerlinNoise2Effect>().stitchTiles()) |
756 , fNumOctaves(processor.cast<GrPerlinNoise2Effect>().numOctaves()) { | 756 , fNumOctaves(processor.cast<GrPerlinNoise2Effect>().numOctaves()) { |
757 } | 757 } |
758 | 758 |
759 void GrGLPerlinNoise2::emitCode(EmitArgs& args) { | 759 void GrGLPerlinNoise2::emitCode(EmitArgs& args) { |
760 GrGLSLFragmentBuilder* fsBuilder = args.fFragBuilder; | 760 GrGLSLFragmentBuilder* fsBuilder = args.fFragBuilder; |
| 761 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
761 SkString vCoords = fsBuilder->ensureFSCoords2D(args.fCoords, 0); | 762 SkString vCoords = fsBuilder->ensureFSCoords2D(args.fCoords, 0); |
762 | 763 |
763 fBaseFrequencyUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragmen
t_Visibility, | 764 fBaseFrequencyUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragme
nt_Visibility, |
764 kVec2f_GrSLType, kDefault_GrSLPrecis
ion, | 765 kVec2f_GrSLType, kDefault_GrS
LPrecision, |
765 "baseFrequency"); | 766 "baseFrequency"); |
766 const char* baseFrequencyUni = args.fBuilder->getUniformCStr(fBaseFrequencyU
ni); | 767 const char* baseFrequencyUni = uniformHandler->getUniformCStr(fBaseFrequency
Uni); |
767 | 768 |
768 const char* stitchDataUni = nullptr; | 769 const char* stitchDataUni = nullptr; |
769 if (fStitchTiles) { | 770 if (fStitchTiles) { |
770 fStitchDataUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragme
nt_Visibility, | 771 fStitchDataUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragm
ent_Visibility, |
771 kVec2f_GrSLType, kDefault_GrSLPreci
sion, | 772 kVec2f_GrSLType, kDefault_Gr
SLPrecision, |
772 "stitchData"); | 773 "stitchData"); |
773 stitchDataUni = args.fBuilder->getUniformCStr(fStitchDataUni); | 774 stitchDataUni = uniformHandler->getUniformCStr(fStitchDataUni); |
774 } | 775 } |
775 | 776 |
776 // There are 4 lines, so the center of each line is 1/8, 3/8, 5/8 and 7/8 | 777 // There are 4 lines, so the center of each line is 1/8, 3/8, 5/8 and 7/8 |
777 const char* chanCoordR = "0.125"; | 778 const char* chanCoordR = "0.125"; |
778 const char* chanCoordG = "0.375"; | 779 const char* chanCoordG = "0.375"; |
779 const char* chanCoordB = "0.625"; | 780 const char* chanCoordB = "0.625"; |
780 const char* chanCoordA = "0.875"; | 781 const char* chanCoordA = "0.875"; |
781 const char* chanCoord = "chanCoord"; | 782 const char* chanCoord = "chanCoord"; |
782 const char* stitchData = "stitchData"; | 783 const char* stitchData = "stitchData"; |
783 const char* ratio = "ratio"; | 784 const char* ratio = "ratio"; |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1164 GrTest::TestMatrix(d->fRandom), nullptr, | 1165 GrTest::TestMatrix(d->fRandom), nullptr, |
1165 kNone_SkFilterQuality); | 1166 kNone_SkFilterQuality); |
1166 } | 1167 } |
1167 | 1168 |
1168 GrGLImprovedPerlinNoise::GrGLImprovedPerlinNoise(const GrProcessor& processor) | 1169 GrGLImprovedPerlinNoise::GrGLImprovedPerlinNoise(const GrProcessor& processor) |
1169 : fZ(processor.cast<GrImprovedPerlinNoiseEffect>().z()) { | 1170 : fZ(processor.cast<GrImprovedPerlinNoiseEffect>().z()) { |
1170 } | 1171 } |
1171 | 1172 |
1172 void GrGLImprovedPerlinNoise::emitCode(EmitArgs& args) { | 1173 void GrGLImprovedPerlinNoise::emitCode(EmitArgs& args) { |
1173 GrGLSLFragmentBuilder* fsBuilder = args.fFragBuilder; | 1174 GrGLSLFragmentBuilder* fsBuilder = args.fFragBuilder; |
| 1175 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
1174 SkString vCoords = fsBuilder->ensureFSCoords2D(args.fCoords, 0); | 1176 SkString vCoords = fsBuilder->ensureFSCoords2D(args.fCoords, 0); |
1175 | 1177 |
1176 fBaseFrequencyUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragmen
t_Visibility, | 1178 fBaseFrequencyUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragme
nt_Visibility, |
1177 kVec2f_GrSLType, kDefault_GrSLPrecis
ion, | 1179 kVec2f_GrSLType, kDefault_GrS
LPrecision, |
1178 "baseFrequency"); | 1180 "baseFrequency"); |
1179 const char* baseFrequencyUni = args.fBuilder->getUniformCStr(fBaseFrequencyU
ni); | 1181 const char* baseFrequencyUni = uniformHandler->getUniformCStr(fBaseFrequency
Uni); |
1180 | 1182 |
1181 fOctavesUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visi
bility, | 1183 fOctavesUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Vis
ibility, |
1182 kFloat_GrSLType, kDefault_GrSLPrecision, | 1184 kFloat_GrSLType, kDefault_GrSLPreci
sion, |
1183 "octaves"); | 1185 "octaves"); |
1184 const char* octavesUni = args.fBuilder->getUniformCStr(fOctavesUni); | 1186 const char* octavesUni = uniformHandler->getUniformCStr(fOctavesUni); |
1185 | 1187 |
1186 fZUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility
, | 1188 fZUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibilit
y, |
1187 kFloat_GrSLType, kDefault_GrSLPrecision, | 1189 kFloat_GrSLType, kDefault_GrSLPrecision, |
1188 "z"); | 1190 "z"); |
1189 const char* zUni = args.fBuilder->getUniformCStr(fZUni); | 1191 const char* zUni = uniformHandler->getUniformCStr(fZUni); |
1190 | 1192 |
1191 // fade function | 1193 // fade function |
1192 static const GrGLSLShaderVar fadeArgs[] = { | 1194 static const GrGLSLShaderVar fadeArgs[] = { |
1193 GrGLSLShaderVar("t", kVec3f_GrSLType) | 1195 GrGLSLShaderVar("t", kVec3f_GrSLType) |
1194 }; | 1196 }; |
1195 SkString fadeFuncName; | 1197 SkString fadeFuncName; |
1196 fsBuilder->emitFunction(kVec3f_GrSLType, "fade", SK_ARRAY_COUNT(fadeArgs), | 1198 fsBuilder->emitFunction(kVec3f_GrSLType, "fade", SK_ARRAY_COUNT(fadeArgs), |
1197 fadeArgs, | 1199 fadeArgs, |
1198 "return t * t * t * (t * (t * 6.0 - 15.0) + 10.0);",
| 1200 "return t * t * t * (t * (t * 6.0 - 15.0) + 10.0);",
|
1199 &fadeFuncName); | 1201 &fadeFuncName); |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1427 str->append(" seed: "); | 1429 str->append(" seed: "); |
1428 str->appendScalar(fSeed); | 1430 str->appendScalar(fSeed); |
1429 str->append(" stitch tiles: "); | 1431 str->append(" stitch tiles: "); |
1430 str->append(fStitchTiles ? "true " : "false "); | 1432 str->append(fStitchTiles ? "true " : "false "); |
1431 | 1433 |
1432 this->INHERITED::toString(str); | 1434 this->INHERITED::toString(str); |
1433 | 1435 |
1434 str->append(")"); | 1436 str->append(")"); |
1435 } | 1437 } |
1436 #endif | 1438 #endif |
OLD | NEW |