| Index: src/effects/SkPerlinNoiseShader.cpp
|
| diff --git a/src/effects/SkPerlinNoiseShader.cpp b/src/effects/SkPerlinNoiseShader.cpp
|
| index f66655ce3f48d7823cae3a0fbba6795a862174c7..c9096f4f939e2a1e189f8c1dee29670626fe9fb6 100644
|
| --- a/src/effects/SkPerlinNoiseShader.cpp
|
| +++ b/src/effects/SkPerlinNoiseShader.cpp
|
| @@ -472,21 +472,15 @@ void SkPerlinNoiseShader::PerlinNoiseShaderContext::shadeSpan(
|
|
|
| class GrGLPerlinNoise : public GrGLSLFragmentProcessor {
|
| public:
|
| - GrGLPerlinNoise(const GrProcessor&);
|
| -
|
| void emitCode(EmitArgs&) override;
|
|
|
| - static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuilder* b);
|
| + static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuilder*);
|
|
|
| protected:
|
| void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override;
|
|
|
| private:
|
| -
|
| GrGLSLProgramDataManager::UniformHandle fStitchDataUni;
|
| - SkPerlinNoiseShader::Type fType;
|
| - bool fStitchTiles;
|
| - int fNumOctaves;
|
| GrGLSLProgramDataManager::UniformHandle fBaseFrequencyUni;
|
|
|
| typedef GrGLSLFragmentProcessor INHERITED;
|
| @@ -519,7 +513,7 @@ public:
|
|
|
| private:
|
| GrGLSLFragmentProcessor* onCreateGLSLInstance() const override {
|
| - return new GrGLPerlinNoise(*this);
|
| + return new GrGLPerlinNoise;
|
| }
|
|
|
| virtual void onGetGLSLProcessorKey(const GrGLSLCaps& caps,
|
| @@ -597,13 +591,9 @@ const GrFragmentProcessor* GrPerlinNoiseEffect::TestCreate(GrProcessorTestData*
|
| kNone_SkFilterQuality);
|
| }
|
|
|
| -GrGLPerlinNoise::GrGLPerlinNoise(const GrProcessor& processor)
|
| - : fType(processor.cast<GrPerlinNoiseEffect>().type())
|
| - , fStitchTiles(processor.cast<GrPerlinNoiseEffect>().stitchTiles())
|
| - , fNumOctaves(processor.cast<GrPerlinNoiseEffect>().numOctaves()) {
|
| -}
|
| -
|
| void GrGLPerlinNoise::emitCode(EmitArgs& args) {
|
| + const GrPerlinNoiseEffect& pne = args.fFp.cast<GrPerlinNoiseEffect>();
|
| +
|
| GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
|
| GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
|
| SkString vCoords = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
|
| @@ -614,7 +604,7 @@ void GrGLPerlinNoise::emitCode(EmitArgs& args) {
|
| const char* baseFrequencyUni = uniformHandler->getUniformCStr(fBaseFrequencyUni);
|
|
|
| const char* stitchDataUni = nullptr;
|
| - if (fStitchTiles) {
|
| + if (pne.stitchTiles()) {
|
| fStitchDataUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
|
| kVec2f_GrSLType, kDefault_GrSLPrecision,
|
| "stitchData");
|
| @@ -667,7 +657,7 @@ void GrGLPerlinNoise::emitCode(EmitArgs& args) {
|
| noiseSmooth, fractVal, fractVal, fractVal);
|
|
|
| // Adjust frequencies if we're stitching tiles
|
| - if (fStitchTiles) {
|
| + if (pne.stitchTiles()) {
|
| noiseCode.appendf("\n\tif(%s.x >= %s.x) { %s.x -= %s.x; }",
|
| floorVal, stitchData, floorVal, stitchData);
|
| noiseCode.appendf("\n\tif(%s.y >= %s.y) { %s.y -= %s.y; }",
|
| @@ -776,7 +766,7 @@ void GrGLPerlinNoise::emitCode(EmitArgs& args) {
|
| noiseCode.appendf("\n\treturn mix(%s.x, %s.y, %s.y);\n", ab, ab, noiseSmooth);
|
|
|
| SkString noiseFuncName;
|
| - if (fStitchTiles) {
|
| + if (pne.stitchTiles()) {
|
| fragBuilder->emitFunction(kFloat_GrSLType,
|
| "perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseStitchArgs),
|
| gPerlinNoiseStitchArgs, noiseCode.c_str(), &noiseFuncName);
|
| @@ -793,21 +783,21 @@ void GrGLPerlinNoise::emitCode(EmitArgs& args) {
|
| // Clear the color accumulator
|
| fragBuilder->codeAppendf("\n\t\t%s = vec4(0.0);", args.fOutputColor);
|
|
|
| - if (fStitchTiles) {
|
| + if (pne.stitchTiles()) {
|
| // Set up TurbulenceInitial stitch values.
|
| - fragBuilder->codeAppendf("\n\t\tvec2 %s = %s;", stitchData, stitchDataUni);
|
| + fragBuilder->codeAppendf("vec2 %s = %s;", stitchData, stitchDataUni);
|
| }
|
|
|
| - fragBuilder->codeAppendf("\n\t\tfloat %s = 1.0;", ratio);
|
| + fragBuilder->codeAppendf("float %s = 1.0;", ratio);
|
|
|
| // Loop over all octaves
|
| - fragBuilder->codeAppendf("\n\t\tfor (int octave = 0; octave < %d; ++octave) {", fNumOctaves);
|
| + fragBuilder->codeAppendf("for (int octave = 0; octave < %d; ++octave) {", pne.numOctaves());
|
|
|
| - fragBuilder->codeAppendf("\n\t\t\t%s += ", args.fOutputColor);
|
| - if (fType != SkPerlinNoiseShader::kFractalNoise_Type) {
|
| + fragBuilder->codeAppendf("%s += ", args.fOutputColor);
|
| + if (pne.type() != SkPerlinNoiseShader::kFractalNoise_Type) {
|
| fragBuilder->codeAppend("abs(");
|
| }
|
| - if (fStitchTiles) {
|
| + if (pne.stitchTiles()) {
|
| fragBuilder->codeAppendf(
|
| "vec4(\n\t\t\t\t%s(%s, %s, %s),\n\t\t\t\t%s(%s, %s, %s),"
|
| "\n\t\t\t\t%s(%s, %s, %s),\n\t\t\t\t%s(%s, %s, %s))",
|
| @@ -824,7 +814,7 @@ void GrGLPerlinNoise::emitCode(EmitArgs& args) {
|
| noiseFuncName.c_str(), chanCoordB, noiseVec,
|
| noiseFuncName.c_str(), chanCoordA, noiseVec);
|
| }
|
| - if (fType != SkPerlinNoiseShader::kFractalNoise_Type) {
|
| + if (pne.type() != SkPerlinNoiseShader::kFractalNoise_Type) {
|
| fragBuilder->codeAppendf(")"); // end of "abs("
|
| }
|
| fragBuilder->codeAppendf(" * %s;", ratio);
|
| @@ -832,12 +822,12 @@ void GrGLPerlinNoise::emitCode(EmitArgs& args) {
|
| fragBuilder->codeAppendf("\n\t\t\t%s *= vec2(2.0);", noiseVec);
|
| fragBuilder->codeAppendf("\n\t\t\t%s *= 0.5;", ratio);
|
|
|
| - if (fStitchTiles) {
|
| + if (pne.stitchTiles()) {
|
| fragBuilder->codeAppendf("\n\t\t\t%s *= vec2(2.0);", stitchData);
|
| }
|
| fragBuilder->codeAppend("\n\t\t}"); // end of the for loop on octaves
|
|
|
| - if (fType == SkPerlinNoiseShader::kFractalNoise_Type) {
|
| + if (pne.type() == SkPerlinNoiseShader::kFractalNoise_Type) {
|
| // The value of turbulenceFunctionResult comes from ((turbulenceFunctionResult) + 1) / 2
|
| // by fractalNoise and (turbulenceFunctionResult) by turbulence.
|
| fragBuilder->codeAppendf("\n\t\t%s = %s * vec4(0.5) + vec4(0.5);",
|
|
|