Last bit of GrGLSLFragmentProcessor-derived class cleanup

I believe these are the last two that used the dispreferred constructor pattern.

GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1667953005

Review URL: https://codereview.chromium.org/1667953005
This commit is contained in:
robertphillips 2016-02-05 07:15:39 -08:00 committed by Commit bot
parent f49c75a8f1
commit d3b32bf832
2 changed files with 28 additions and 52 deletions

View File

@ -609,8 +609,6 @@ void SkPerlinNoiseShader2::PerlinNoiseShaderContext::shadeSpan(
class GrGLPerlinNoise2 : public GrGLSLFragmentProcessor {
public:
GrGLPerlinNoise2(const GrProcessor&);
void emitCode(EmitArgs&) override;
static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuilder* b);
@ -619,14 +617,9 @@ protected:
void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override;
private:
GrGLSLProgramDataManager::UniformHandle fStitchDataUni;
SkPerlinNoiseShader2::Type fType;
bool fStitchTiles;
int fNumOctaves;
GrGLSLProgramDataManager::UniformHandle fBaseFrequencyUni;
private:
typedef GrGLSLFragmentProcessor INHERITED;
};
@ -657,7 +650,7 @@ public:
private:
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override {
return new GrGLPerlinNoise2(*this);
return new GrGLPerlinNoise2;
}
virtual void onGetGLSLProcessorKey(const GrGLSLCaps& caps,
@ -736,13 +729,9 @@ const GrFragmentProcessor* GrPerlinNoise2Effect::TestCreate(GrProcessorTestData*
kNone_SkFilterQuality);
}
GrGLPerlinNoise2::GrGLPerlinNoise2(const GrProcessor& processor)
: fType(processor.cast<GrPerlinNoise2Effect>().type())
, fStitchTiles(processor.cast<GrPerlinNoise2Effect>().stitchTiles())
, fNumOctaves(processor.cast<GrPerlinNoise2Effect>().numOctaves()) {
}
void GrGLPerlinNoise2::emitCode(EmitArgs& args) {
const GrPerlinNoise2Effect& pne = args.fFp.cast<GrPerlinNoise2Effect>();
GrGLSLFragmentBuilder* fsBuilder = args.fFragBuilder;
GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
SkString vCoords = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
@ -753,7 +742,7 @@ void GrGLPerlinNoise2::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");
@ -806,7 +795,7 @@ void GrGLPerlinNoise2::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; }",
@ -915,7 +904,7 @@ void GrGLPerlinNoise2::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()) {
fsBuilder->emitFunction(kFloat_GrSLType,
"perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseStitchArgs),
gPerlinNoiseStitchArgs, noiseCode.c_str(), &noiseFuncName);
@ -932,7 +921,7 @@ void GrGLPerlinNoise2::emitCode(EmitArgs& args) {
// Clear the color accumulator
fsBuilder->codeAppendf("\n\t\t%s = vec4(0.0);", args.fOutputColor);
if (fStitchTiles) {
if (pne.stitchTiles()) {
// Set up TurbulenceInitial stitch values.
fsBuilder->codeAppendf("\n\t\tvec2 %s = %s;", stitchData, stitchDataUni);
}
@ -940,13 +929,13 @@ void GrGLPerlinNoise2::emitCode(EmitArgs& args) {
fsBuilder->codeAppendf("\n\t\tfloat %s = 1.0;", ratio);
// Loop over all octaves
fsBuilder->codeAppendf("\n\t\tfor (int octave = 0; octave < %d; ++octave) {", fNumOctaves);
fsBuilder->codeAppendf("for (int octave = 0; octave < %d; ++octave) {", pne.numOctaves());
fsBuilder->codeAppendf("\n\t\t\t%s += ", args.fOutputColor);
if (fType != SkPerlinNoiseShader2::kFractalNoise_Type) {
if (pne.type() != SkPerlinNoiseShader2::kFractalNoise_Type) {
fsBuilder->codeAppend("abs(");
}
if (fStitchTiles) {
if (pne.stitchTiles()) {
fsBuilder->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))",
@ -963,7 +952,7 @@ void GrGLPerlinNoise2::emitCode(EmitArgs& args) {
noiseFuncName.c_str(), chanCoordB, noiseVec,
noiseFuncName.c_str(), chanCoordA, noiseVec);
}
if (fType != SkPerlinNoiseShader2::kFractalNoise_Type) {
if (pne.type() != SkPerlinNoiseShader2::kFractalNoise_Type) {
fsBuilder->codeAppendf(")"); // end of "abs("
}
fsBuilder->codeAppendf(" * %s;", ratio);
@ -971,12 +960,12 @@ void GrGLPerlinNoise2::emitCode(EmitArgs& args) {
fsBuilder->codeAppendf("\n\t\t\t%s *= vec2(2.0);", noiseVec);
fsBuilder->codeAppendf("\n\t\t\t%s *= 0.5;", ratio);
if (fStitchTiles) {
if (pne.stitchTiles()) {
fsBuilder->codeAppendf("\n\t\t\t%s *= vec2(2.0);", stitchData);
}
fsBuilder->codeAppend("\n\t\t}"); // end of the for loop on octaves
if (fType == SkPerlinNoiseShader2::kFractalNoise_Type) {
if (pne.type() == SkPerlinNoiseShader2::kFractalNoise_Type) {
// The value of turbulenceFunctionResult comes from ((turbulenceFunctionResult) + 1) / 2
// by fractalNoise and (turbulenceFunctionResult) by turbulence.
fsBuilder->codeAppendf("\n\t\t%s = %s * vec4(0.5) + vec4(0.5);",

View File

@ -1517,8 +1517,8 @@ SkString emitNormalFunc(BoundaryMode mode,
class GrGLLightingEffect : public GrGLSLFragmentProcessor {
public:
GrGLLightingEffect(const GrProcessor&);
virtual ~GrGLLightingEffect();
GrGLLightingEffect() : fLight(nullptr) { }
virtual ~GrGLLightingEffect() { delete fLight; }
void emitCode(EmitArgs&) override;
@ -1540,14 +1540,12 @@ private:
UniformHandle fImageIncrementUni;
UniformHandle fSurfaceScaleUni;
GrGLLight* fLight;
BoundaryMode fBoundaryMode;
};
///////////////////////////////////////////////////////////////////////////////
class GrGLDiffuseLightingEffect : public GrGLLightingEffect {
public:
GrGLDiffuseLightingEffect(const GrProcessor&);
void emitLightFunc(GrGLSLUniformHandler*, GrGLSLFragmentBuilder*, SkString* funcName) override;
protected:
@ -1563,7 +1561,6 @@ private:
class GrGLSpecularLightingEffect : public GrGLLightingEffect {
public:
GrGLSpecularLightingEffect(const GrProcessor&);
void emitLightFunc(GrGLSLUniformHandler*, GrGLSLFragmentBuilder*, SkString* funcName) override;
protected:
@ -1619,8 +1616,7 @@ GrDiffuseLightingEffect::GrDiffuseLightingEffect(GrTexture* texture,
bool GrDiffuseLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
const GrDiffuseLightingEffect& s = sBase.cast<GrDiffuseLightingEffect>();
return INHERITED::onIsEqual(sBase) &&
this->kd() == s.kd();
return INHERITED::onIsEqual(sBase) && this->kd() == s.kd();
}
void GrDiffuseLightingEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps,
@ -1629,7 +1625,7 @@ void GrDiffuseLightingEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps,
}
GrGLSLFragmentProcessor* GrDiffuseLightingEffect::onCreateGLSLInstance() const {
return new GrGLDiffuseLightingEffect(*this);
return new GrGLDiffuseLightingEffect;
}
GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDiffuseLightingEffect);
@ -1650,17 +1646,12 @@ const GrFragmentProcessor* GrDiffuseLightingEffect::TestCreate(GrProcessorTestDa
///////////////////////////////////////////////////////////////////////////////
GrGLLightingEffect::GrGLLightingEffect(const GrProcessor& fp) {
const GrLightingEffect& m = fp.cast<GrLightingEffect>();
fLight = m.light()->createGLLight();
fBoundaryMode = m.boundaryMode();
}
GrGLLightingEffect::~GrGLLightingEffect() {
delete fLight;
}
void GrGLLightingEffect::emitCode(EmitArgs& args) {
const GrLightingEffect& le = args.fFp.cast<GrLightingEffect>();
if (!fLight) {
fLight = le.light()->createGLLight();
}
GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
fImageIncrementUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
kVec2f_GrSLType, kDefault_GrSLPrecision,
@ -1707,7 +1698,7 @@ void GrGLLightingEffect::emitCode(EmitArgs& args) {
GrGLSLShaderVar("m", kFloat_GrSLType, 9),
GrGLSLShaderVar("surfaceScale", kFloat_GrSLType),
};
SkString normalBody = emitNormalFunc(fBoundaryMode,
SkString normalBody = emitNormalFunc(le.boundaryMode(),
pointToNormalName.c_str(),
sobelFuncName.c_str());
SkString normalName;
@ -1757,6 +1748,10 @@ void GrGLLightingEffect::GenKey(const GrProcessor& proc,
void GrGLLightingEffect::onSetData(const GrGLSLProgramDataManager& pdman,
const GrProcessor& proc) {
const GrLightingEffect& lighting = proc.cast<GrLightingEffect>();
if (!fLight) {
fLight = lighting.light()->createGLLight();
}
GrTexture* texture = lighting.texture(0);
float ySign = texture->origin() == kTopLeft_GrSurfaceOrigin ? -1.0f : 1.0f;
pdman.set2f(fImageIncrementUni, 1.0f / texture->width(), ySign / texture->height());
@ -1770,10 +1765,6 @@ void GrGLLightingEffect::onSetData(const GrGLSLProgramDataManager& pdman,
///////////////////////////////////////////////////////////////////////////////
GrGLDiffuseLightingEffect::GrGLDiffuseLightingEffect(const GrProcessor& proc)
: INHERITED(proc) {
}
void GrGLDiffuseLightingEffect::emitLightFunc(GrGLSLUniformHandler* uniformHandler,
GrGLSLFragmentBuilder* fragBuilder,
SkString* funcName) {
@ -1833,7 +1824,7 @@ void GrSpecularLightingEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps,
}
GrGLSLFragmentProcessor* GrSpecularLightingEffect::onCreateGLSLInstance() const {
return new GrGLSpecularLightingEffect(*this);
return new GrGLSpecularLightingEffect;
}
GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSpecularLightingEffect);
@ -1854,10 +1845,6 @@ const GrFragmentProcessor* GrSpecularLightingEffect::TestCreate(GrProcessorTestD
///////////////////////////////////////////////////////////////////////////////
GrGLSpecularLightingEffect::GrGLSpecularLightingEffect(const GrProcessor& proc)
: INHERITED(proc) {
}
void GrGLSpecularLightingEffect::emitLightFunc(GrGLSLUniformHandler* uniformHandler,
GrGLSLFragmentBuilder* fragBuilder,
SkString* funcName) {