Improve consistency of GP::ProgramImpl subclasses
Named "Impl" and nested in GP or makeProgramImpl definition.
Remove unused INHERITED typedefs.
Remove GenKey pattern.
Bug: skia:11358
Change-Id: Icb4d5a0844184f51d92135de6cee6f6e77f57a5e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/438478
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
diff --git a/src/gpu/ops/GrAAConvexPathRenderer.cpp b/src/gpu/ops/GrAAConvexPathRenderer.cpp
index ea13f42..58d5bd2 100644
--- a/src/gpu/ops/GrAAConvexPathRenderer.cpp
+++ b/src/gpu/ops/GrAAConvexPathRenderer.cpp
@@ -561,10 +561,51 @@
const char* name() const override { return "QuadEdge"; }
- class GLSLProcessor : public ProgramImpl {
- public:
- GLSLProcessor() {}
+ void addToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override {
+ b->addBool(fUsesLocalCoords, "usesLocalCoords");
+ b->addBits(ProgramImpl::kMatrixKeyBits,
+ ProgramImpl::ComputeMatrixKey(caps, fLocalMatrix),
+ "localMatrixType");
+ }
+ std::unique_ptr<ProgramImpl> makeProgramImpl(const GrShaderCaps&) const override;
+
+private:
+ QuadEdgeEffect(const SkMatrix& localMatrix, bool usesLocalCoords, bool wideColor)
+ : INHERITED(kQuadEdgeEffect_ClassID)
+ , fLocalMatrix(localMatrix)
+ , fUsesLocalCoords(usesLocalCoords) {
+ fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
+ fInColor = MakeColorAttribute("inColor", wideColor);
+ // GL on iOS 14 needs more precision for the quadedge attributes
+ fInQuadEdge = {"inQuadEdge", kFloat4_GrVertexAttribType, kFloat4_GrSLType};
+ this->setVertexAttributes(&fInPosition, 3);
+ }
+
+ Attribute fInPosition;
+ Attribute fInColor;
+ Attribute fInQuadEdge;
+
+ SkMatrix fLocalMatrix;
+ bool fUsesLocalCoords;
+
+ GR_DECLARE_GEOMETRY_PROCESSOR_TEST
+
+ using INHERITED = GrGeometryProcessor;
+};
+
+std::unique_ptr<GrGeometryProcessor::ProgramImpl> QuadEdgeEffect::makeProgramImpl(
+ const GrShaderCaps&) const {
+ class Impl : public ProgramImpl {
+ public:
+ void setData(const GrGLSLProgramDataManager& pdman,
+ const GrShaderCaps& shaderCaps,
+ const GrGeometryProcessor& geomProc) override {
+ const QuadEdgeEffect& qe = geomProc.cast<QuadEdgeEffect>();
+ SetTransform(pdman, shaderCaps, fLocalMatrixUniform, qe.fLocalMatrix, &fLocalMatrix);
+ }
+
+ private:
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
const QuadEdgeEffect& qe = args.fGeomProc.cast<QuadEdgeEffect>();
GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
@@ -618,61 +659,14 @@
fragBuilder->codeAppendf("half4 %s = half4(edgeAlpha);", args.fOutputCoverage);
}
- static inline void GenKey(const GrGeometryProcessor& gp,
- const GrShaderCaps& shaderCaps,
- GrProcessorKeyBuilder* b) {
- const QuadEdgeEffect& qee = gp.cast<QuadEdgeEffect>();
- b->addBool(qee.fUsesLocalCoords, "usesLocalCoords");
- b->addBits(kMatrixKeyBits,
- ComputeMatrixKey(shaderCaps, qee.fLocalMatrix),
- "localMatrixType");
- }
-
- void setData(const GrGLSLProgramDataManager& pdman,
- const GrShaderCaps& shaderCaps,
- const GrGeometryProcessor& geomProc) override {
- const QuadEdgeEffect& qe = geomProc.cast<QuadEdgeEffect>();
- SetTransform(pdman, shaderCaps, fLocalMatrixUniform, qe.fLocalMatrix, &fLocalMatrix);
- }
-
private:
- using INHERITED = ProgramImpl;
+ SkMatrix fLocalMatrix = SkMatrix::InvalidMatrix();
- SkMatrix fLocalMatrix = SkMatrix::InvalidMatrix();
UniformHandle fLocalMatrixUniform;
};
- void addToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override {
- GLSLProcessor::GenKey(*this, caps, b);
- }
-
- std::unique_ptr<ProgramImpl> makeProgramImpl(const GrShaderCaps&) const override {
- return std::make_unique<GLSLProcessor>();
- }
-
-private:
- QuadEdgeEffect(const SkMatrix& localMatrix, bool usesLocalCoords, bool wideColor)
- : INHERITED(kQuadEdgeEffect_ClassID)
- , fLocalMatrix(localMatrix)
- , fUsesLocalCoords(usesLocalCoords) {
- fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
- fInColor = MakeColorAttribute("inColor", wideColor);
- // GL on iOS 14 needs more precision for the quadedge attributes
- fInQuadEdge = {"inQuadEdge", kFloat4_GrVertexAttribType, kFloat4_GrSLType};
- this->setVertexAttributes(&fInPosition, 3);
- }
-
- Attribute fInPosition;
- Attribute fInColor;
- Attribute fInQuadEdge;
-
- SkMatrix fLocalMatrix;
- bool fUsesLocalCoords;
-
- GR_DECLARE_GEOMETRY_PROCESSOR_TEST
-
- using INHERITED = GrGeometryProcessor;
-};
+ return std::make_unique<Impl>();
+}
GR_DEFINE_GEOMETRY_PROCESSOR_TEST(QuadEdgeEffect);
diff --git a/src/gpu/ops/GrDashOp.cpp b/src/gpu/ops/GrDashOp.cpp
index 0c1e672..72ecaf6 100644
--- a/src/gpu/ops/GrDashOp.cpp
+++ b/src/gpu/ops/GrDashOp.cpp
@@ -799,8 +799,7 @@
//////////////////////////////////////////////////////////////////////////////
-class GLDashingCircleEffect;
-
+namespace {
/*
* This effect will draw a dotted line (defined as a dashed lined with round caps and no on
* interval). The radius of the dots is given by the strokeWidth and the spacing by the DashInfo.
@@ -822,20 +821,12 @@
const char* name() const override { return "DashingCircleEffect"; }
- AAMode aaMode() const { return fAAMode; }
-
- const SkPMColor4f& color() const { return fColor; }
-
- const SkMatrix& localMatrix() const { return fLocalMatrix; }
-
- bool usesLocalCoords() const { return fUsesLocalCoords; }
-
void addToKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
std::unique_ptr<ProgramImpl> makeProgramImpl(const GrShaderCaps&) const override;
private:
- friend class GLDashingCircleEffect;
+ class Impl;
DashingCircleEffect(const SkPMColor4f&, AAMode aaMode, const SkMatrix& localMatrix,
bool usesLocalCoords);
@@ -853,46 +844,31 @@
using INHERITED = GrGeometryProcessor;
};
+} // anonymous namespace
//////////////////////////////////////////////////////////////////////////////
-class GLDashingCircleEffect : public GrGeometryProcessor::ProgramImpl {
+class DashingCircleEffect::Impl : public ProgramImpl {
public:
- GLDashingCircleEffect();
-
- void onEmitCode(EmitArgs&, GrGPArgs*) override;
-
- static inline void GenKey(const GrGeometryProcessor&,
- const GrShaderCaps&,
- GrProcessorKeyBuilder*);
-
void setData(const GrGLSLProgramDataManager&,
const GrShaderCaps&,
const GrGeometryProcessor&) override;
private:
+ void onEmitCode(EmitArgs&, GrGPArgs*) override;
+
+ SkMatrix fLocalMatrix = SkMatrix::InvalidMatrix();
+ SkPMColor4f fColor = SK_PMColor4fILLEGAL;
+ float fPrevRadius = SK_FloatNaN;
+ float fPrevCenterX = SK_FloatNaN;
+ float fPrevIntervalLength = SK_FloatNaN;
+
UniformHandle fParamUniform;
UniformHandle fColorUniform;
UniformHandle fLocalMatrixUniform;
-
- SkMatrix fLocalMatrix;
- SkPMColor4f fColor;
- SkScalar fPrevRadius;
- SkScalar fPrevCenterX;
- SkScalar fPrevIntervalLength;
-
- using INHERITED = ProgramImpl;
};
-GLDashingCircleEffect::GLDashingCircleEffect() {
- fLocalMatrix = SkMatrix::InvalidMatrix();
- fColor = SK_PMColor4fILLEGAL;
- fPrevRadius = SK_ScalarMin;
- fPrevCenterX = SK_ScalarMin;
- fPrevIntervalLength = SK_ScalarMax;
-}
-
-void GLDashingCircleEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
+void DashingCircleEffect::Impl::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
const DashingCircleEffect& dce = args.fGeomProc.cast<DashingCircleEffect>();
GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
@@ -918,13 +894,13 @@
// Setup position
WriteOutputPosition(vertBuilder, gpArgs, dce.fInPosition.name());
- if (dce.usesLocalCoords()) {
+ if (dce.fUsesLocalCoords) {
WriteLocalCoord(vertBuilder,
uniformHandler,
*args.fShaderCaps,
gpArgs,
dce.fInPosition.asShaderVar(),
- dce.localMatrix(),
+ dce.fLocalMatrix,
&fLocalMatrixUniform);
}
@@ -936,7 +912,7 @@
dashParams.fsIn());
fragBuilder->codeAppendf("half2 center = half2(%s.y, 0.0);", circleParams.fsIn());
fragBuilder->codeAppend("half dist = length(center - fragPosShifted);");
- if (dce.aaMode() != AAMode::kNone) {
+ if (dce.fAAMode != AAMode::kNone) {
fragBuilder->codeAppendf("half diff = dist - %s.x;", circleParams.fsIn());
fragBuilder->codeAppend("diff = 1.0 - diff;");
fragBuilder->codeAppend("half alpha = saturate(diff);");
@@ -947,26 +923,15 @@
fragBuilder->codeAppendf("half4 %s = half4(alpha);", args.fOutputCoverage);
}
-void GLDashingCircleEffect::setData(const GrGLSLProgramDataManager& pdman,
- const GrShaderCaps& shaderCaps,
- const GrGeometryProcessor& geomProc) {
+void DashingCircleEffect::Impl::setData(const GrGLSLProgramDataManager& pdman,
+ const GrShaderCaps& shaderCaps,
+ const GrGeometryProcessor& geomProc) {
const DashingCircleEffect& dce = geomProc.cast<DashingCircleEffect>();
- if (dce.color() != fColor) {
- pdman.set4fv(fColorUniform, 1, dce.color().vec());
- fColor = dce.color();
+ if (dce.fColor != fColor) {
+ pdman.set4fv(fColorUniform, 1, dce.fColor.vec());
+ fColor = dce.fColor;
}
- SetTransform(pdman, shaderCaps, fLocalMatrixUniform, dce.localMatrix(), &fLocalMatrix);
-}
-
-void GLDashingCircleEffect::GenKey(const GrGeometryProcessor& gp,
- const GrShaderCaps& shaderCaps,
- GrProcessorKeyBuilder* b) {
- const DashingCircleEffect& dce = gp.cast<DashingCircleEffect>();
- uint32_t key = 0;
- key |= dce.usesLocalCoords() ? 0x1 : 0x0;
- key |= static_cast<uint32_t>(dce.aaMode()) << 1;
- key |= ComputeMatrixKey(shaderCaps, dce.localMatrix()) << 3;
- b->add32(key);
+ SetTransform(pdman, shaderCaps, fLocalMatrixUniform, dce.fLocalMatrix, &fLocalMatrix);
}
//////////////////////////////////////////////////////////////////////////////
@@ -982,12 +947,16 @@
}
void DashingCircleEffect::addToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const {
- GLDashingCircleEffect::GenKey(*this, caps, b);
+ uint32_t key = 0;
+ key |= fUsesLocalCoords ? 0x1 : 0x0;
+ key |= static_cast<uint32_t>(fAAMode) << 1;
+ key |= ProgramImpl::ComputeMatrixKey(caps, fLocalMatrix) << 3;
+ b->add32(key);
}
std::unique_ptr<GrGeometryProcessor::ProgramImpl> DashingCircleEffect::makeProgramImpl(
const GrShaderCaps&) const {
- return std::make_unique<GLDashingCircleEffect>();
+ return std::make_unique<Impl>();
}
DashingCircleEffect::DashingCircleEffect(const SkPMColor4f& color,
@@ -1022,8 +991,7 @@
//////////////////////////////////////////////////////////////////////////////
-class GLDashingLineEffect;
-
+namespace {
/*
* This effect will draw a dashed line. The width of the dash is given by the strokeWidth and the
* length and spacing by the DashInfo. Both of the previous two parameters are in device space.
@@ -1045,12 +1013,6 @@
const char* name() const override { return "DashingEffect"; }
- AAMode aaMode() const { return fAAMode; }
-
- const SkPMColor4f& color() const { return fColor; }
-
- const SkMatrix& localMatrix() const { return fLocalMatrix; }
-
bool usesLocalCoords() const { return fUsesLocalCoords; }
void addToKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
@@ -1058,7 +1020,7 @@
std::unique_ptr<ProgramImpl> makeProgramImpl(const GrShaderCaps&) const override;
private:
- friend class GLDashingLineEffect;
+ class Impl;
DashingLineEffect(const SkPMColor4f&, AAMode aaMode, const SkMatrix& localMatrix,
bool usesLocalCoords);
@@ -1076,36 +1038,27 @@
using INHERITED = GrGeometryProcessor;
};
+} // anonymous namespace
//////////////////////////////////////////////////////////////////////////////
-class GLDashingLineEffect : public GrGeometryProcessor::ProgramImpl {
+class DashingLineEffect::Impl : public ProgramImpl {
public:
- GLDashingLineEffect();
-
- void onEmitCode(EmitArgs&, GrGPArgs*) override;
-
- static inline void GenKey(const GrGeometryProcessor&,
- const GrShaderCaps&,
- GrProcessorKeyBuilder*);
-
void setData(const GrGLSLProgramDataManager&,
const GrShaderCaps&,
const GrGeometryProcessor&) override;
private:
- SkPMColor4f fColor;
- UniformHandle fColorUniform;
+ void onEmitCode(EmitArgs&, GrGPArgs*) override;
- SkMatrix fLocalMatrix;
+ SkPMColor4f fColor = SK_PMColor4fILLEGAL;
+ SkMatrix fLocalMatrix = SkMatrix::InvalidMatrix();
+
UniformHandle fLocalMatrixUniform;
-
- using INHERITED = ProgramImpl;
+ UniformHandle fColorUniform;
};
-GLDashingLineEffect::GLDashingLineEffect() : fColor(SK_PMColor4fILLEGAL) {}
-
-void GLDashingLineEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
+void DashingLineEffect::Impl::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
const DashingLineEffect& de = args.fGeomProc.cast<DashingLineEffect>();
GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
@@ -1139,7 +1092,7 @@
*args.fShaderCaps,
gpArgs,
de.fInPosition.asShaderVar(),
- de.localMatrix(),
+ de.fLocalMatrix,
&fLocalMatrixUniform);
}
@@ -1149,7 +1102,7 @@
inDashParams.fsIn());
fragBuilder->codeAppendf("half2 fragPosShifted = half2(xShifted, half(%s.y));",
inDashParams.fsIn());
- if (de.aaMode() == AAMode::kCoverage) {
+ if (de.fAAMode == AAMode::kCoverage) {
// The amount of coverage removed in x and y by the edges is computed as a pair of negative
// numbers, xSub and ySub.
fragBuilder->codeAppend("half xSub, ySub;");
@@ -1165,7 +1118,7 @@
// covered.
fragBuilder->codeAppendf(
"half alpha = (1.0 + max(xSub, -1.0)) * (1.0 + max(ySub, -1.0));");
- } else if (de.aaMode() == AAMode::kCoverageWithMSAA) {
+ } else if (de.fAAMode == AAMode::kCoverageWithMSAA) {
// For MSAA, we don't modulate the alpha by the Y distance, since MSAA coverage will handle
// AA on the the top and bottom edges. The shader is only responsible for intra-dash alpha.
fragBuilder->codeAppend("half xSub;");
@@ -1186,26 +1139,15 @@
fragBuilder->codeAppendf("half4 %s = half4(alpha);", args.fOutputCoverage);
}
-void GLDashingLineEffect::setData(const GrGLSLProgramDataManager& pdman,
- const GrShaderCaps& shaderCaps,
- const GrGeometryProcessor& geomProc) {
+void DashingLineEffect::Impl::setData(const GrGLSLProgramDataManager& pdman,
+ const GrShaderCaps& shaderCaps,
+ const GrGeometryProcessor& geomProc) {
const DashingLineEffect& de = geomProc.cast<DashingLineEffect>();
- if (de.color() != fColor) {
- pdman.set4fv(fColorUniform, 1, de.color().vec());
- fColor = de.color();
+ if (de.fColor != fColor) {
+ pdman.set4fv(fColorUniform, 1, de.fColor.vec());
+ fColor = de.fColor;
}
- SetTransform(pdman, shaderCaps, fLocalMatrixUniform, de.localMatrix(), &fLocalMatrix);
-}
-
-void GLDashingLineEffect::GenKey(const GrGeometryProcessor& gp,
- const GrShaderCaps& shaderCaps,
- GrProcessorKeyBuilder* b) {
- const DashingLineEffect& de = gp.cast<DashingLineEffect>();
- uint32_t key = 0;
- key |= de.usesLocalCoords() ? 0x1 : 0x0;
- key |= static_cast<int>(de.aaMode()) << 1;
- key |= ComputeMatrixKey(shaderCaps, de.localMatrix()) << 3;
- b->add32(key);
+ SetTransform(pdman, shaderCaps, fLocalMatrixUniform, de.fLocalMatrix, &fLocalMatrix);
}
//////////////////////////////////////////////////////////////////////////////
@@ -1221,12 +1163,16 @@
}
void DashingLineEffect::addToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const {
- GLDashingLineEffect::GenKey(*this, caps, b);
+ uint32_t key = 0;
+ key |= fUsesLocalCoords ? 0x1 : 0x0;
+ key |= static_cast<int>(fAAMode) << 1;
+ key |= ProgramImpl::ComputeMatrixKey(caps, fLocalMatrix) << 3;
+ b->add32(key);
}
std::unique_ptr<GrGeometryProcessor::ProgramImpl> DashingLineEffect::makeProgramImpl(
const GrShaderCaps&) const {
- return std::make_unique<GLDashingLineEffect>();
+ return std::make_unique<Impl>();
}
DashingLineEffect::DashingLineEffect(const SkPMColor4f& color,
diff --git a/src/gpu/ops/GrDrawAtlasPathOp.cpp b/src/gpu/ops/GrDrawAtlasPathOp.cpp
index db270cb..fc4c2fb 100644
--- a/src/gpu/ops/GrDrawAtlasPathOp.cpp
+++ b/src/gpu/ops/GrDrawAtlasPathOp.cpp
@@ -21,16 +21,18 @@
class DrawAtlasPathShader : public GrGeometryProcessor {
public:
- DrawAtlasPathShader(bool usesLocalCoords, const GrAtlasInstancedHelper* atlasHelper,
+ DrawAtlasPathShader(bool usesLocalCoords,
+ const GrAtlasInstancedHelper* atlasHelper,
const GrShaderCaps& shaderCaps)
: GrGeometryProcessor(kDrawAtlasPathShader_ClassID)
, fUsesLocalCoords(usesLocalCoords)
, fAtlasHelper(atlasHelper)
- , fAtlasAccess(GrSamplerState::Filter::kNearest, fAtlasHelper->proxy()->backendFormat(),
+ , fAtlasAccess(GrSamplerState::Filter::kNearest,
+ fAtlasHelper->proxy()->backendFormat(),
fAtlasHelper->atlasSwizzle()) {
if (!shaderCaps.vertexIDSupport()) {
- constexpr static Attribute kUnitCoordAttrib("unitCoord", kFloat2_GrVertexAttribType,
- kFloat2_GrSLType);
+ constexpr static Attribute kUnitCoordAttrib(
+ "unitCoord", kFloat2_GrVertexAttribType, kFloat2_GrSLType);
this->setVertexAttributes(&kUnitCoordAttrib, 1);
}
fAttribs.emplace_back("fillBounds", kFloat4_GrVertexAttribType, kFloat4_GrSLType);
@@ -47,6 +49,8 @@
}
private:
+ class Impl;
+
int colorAttribIdx() const { return fUsesLocalCoords ? 3 : 1; }
const char* name() const override { return "DrawAtlasPathShader"; }
void addToKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const override {
@@ -61,11 +65,18 @@
TextureSampler fAtlasAccess;
constexpr static int kMaxInstanceAttribs = 6;
SkSTArray<kMaxInstanceAttribs, GrGeometryProcessor::Attribute> fAttribs;
-
- class Impl;
};
class DrawAtlasPathShader::Impl : public ProgramImpl {
+public:
+ void setData(const GrGLSLProgramDataManager& pdman,
+ const GrShaderCaps&,
+ const GrGeometryProcessor& geomProc) override {
+ auto* atlasHelper = geomProc.cast<DrawAtlasPathShader>().fAtlasHelper;
+ atlasHelper->setUniformData(pdman, fAtlasAdjustUniform);
+ }
+
+private:
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
const auto& shader = args.fGeomProc.cast<DrawAtlasPathShader>();
args.fVaryingHandler->emitAttributes(shader);
@@ -97,13 +108,6 @@
GrGLSLVaryingHandler::Interpolation::kCanBeFlat);
}
- void setData(const GrGLSLProgramDataManager& pdman,
- const GrShaderCaps&,
- const GrGeometryProcessor& geomProc) override {
- auto* atlasHelper = geomProc.cast<DrawAtlasPathShader>().fAtlasHelper;
- atlasHelper->setUniformData(pdman, fAtlasAdjustUniform);
- }
-
GrGLSLUniformHandler::UniformHandle fAtlasAdjustUniform;
};
diff --git a/src/gpu/ops/GrDrawVerticesOp.cpp b/src/gpu/ops/GrDrawVerticesOp.cpp
index 059526d..1eea29a 100644
--- a/src/gpu/ops/GrDrawVerticesOp.cpp
+++ b/src/gpu/ops/GrDrawVerticesOp.cpp
@@ -53,19 +53,41 @@
const char* name() const override { return "VerticesGP"; }
- const SkPMColor4f& color() const { return fColor; }
- const SkMatrix& viewMatrix() const { return fViewMatrix; }
-
const Attribute& positionAttr() const { return fAttributes[kPositionIndex]; }
const Attribute& colorAttr() const { return fAttributes[kColorIndex]; }
const Attribute& localCoordsAttr() const { return fAttributes[kLocalCoordsIndex]; }
- class GLSLProcessor : public ProgramImpl {
- public:
- GLSLProcessor()
- : fViewMatrix(SkMatrix::InvalidMatrix())
- , fColor(SK_PMColor4fILLEGAL) {}
+ void addToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override {
+ uint32_t key = 0;
+ key |= (fColorArrayType == ColorArrayType::kSkColor) ? 0x1 : 0;
+ key |= ProgramImpl::ComputeMatrixKey(caps, fViewMatrix) << 20;
+ b->add32(key);
+ b->add32(GrColorSpaceXform::XformKey(fColorSpaceXform.get()));
+ }
+ std::unique_ptr<ProgramImpl> makeProgramImpl(const GrShaderCaps&) const override {
+ return std::make_unique<Impl>();
+ }
+
+private:
+ class Impl : public ProgramImpl {
+ public:
+ void setData(const GrGLSLProgramDataManager& pdman,
+ const GrShaderCaps& shaderCaps,
+ const GrGeometryProcessor& geomProc) override {
+ const VerticesGP& vgp = geomProc.cast<VerticesGP>();
+
+ SetTransform(pdman, shaderCaps, fViewMatrixUniform, vgp.fViewMatrix, &fViewMatrix);
+
+ if (!vgp.colorAttr().isInitialized() && vgp.fColor != fColor) {
+ pdman.set4fv(fColorUniform, 1, vgp.fColor.vec());
+ fColor = vgp.fColor;
+ }
+
+ fColorSpaceHelper.setData(pdman, vgp.fColorSpaceXform.get());
+ }
+
+ private:
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
const VerticesGP& gp = args.fGeomProc.cast<VerticesGP>();
GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
@@ -110,7 +132,7 @@
*args.fShaderCaps,
gpArgs,
gp.positionAttr().name(),
- gp.viewMatrix(),
+ gp.fViewMatrix,
&fViewMatrixUniform);
// emit transforms using either explicit local coords or positions
@@ -121,51 +143,16 @@
fragBuilder->codeAppendf("const half4 %s = half4(1);", args.fOutputCoverage);
}
- static inline void GenKey(const GrGeometryProcessor& gp,
- const GrShaderCaps& shaderCaps,
- GrProcessorKeyBuilder* b) {
- const VerticesGP& vgp = gp.cast<VerticesGP>();
- uint32_t key = 0;
- key |= (vgp.fColorArrayType == ColorArrayType::kSkColor) ? 0x1 : 0;
- key |= ComputeMatrixKey(shaderCaps, vgp.viewMatrix()) << 20;
- b->add32(key);
- b->add32(GrColorSpaceXform::XformKey(vgp.fColorSpaceXform.get()));
- }
-
- void setData(const GrGLSLProgramDataManager& pdman,
- const GrShaderCaps& shaderCaps,
- const GrGeometryProcessor& geomProc) override {
- const VerticesGP& vgp = geomProc.cast<VerticesGP>();
-
- SetTransform(pdman, shaderCaps, fViewMatrixUniform, vgp.viewMatrix(), &fViewMatrix);
-
- if (!vgp.colorAttr().isInitialized() && vgp.color() != fColor) {
- pdman.set4fv(fColorUniform, 1, vgp.color().vec());
- fColor = vgp.color();
- }
-
- fColorSpaceHelper.setData(pdman, vgp.fColorSpaceXform.get());
- }
-
private:
- SkMatrix fViewMatrix;
- SkPMColor4f fColor;
+ SkMatrix fViewMatrix = SkMatrix::InvalidMatrix();
+ SkPMColor4f fColor = SK_PMColor4fILLEGAL;
+
UniformHandle fViewMatrixUniform;
UniformHandle fColorUniform;
- GrGLSLColorSpaceXformHelper fColorSpaceHelper;
- using INHERITED = ProgramImpl;
+ GrGLSLColorSpaceXformHelper fColorSpaceHelper;
};
- void addToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override {
- GLSLProcessor::GenKey(*this, caps, b);
- }
-
- std::unique_ptr<ProgramImpl> makeProgramImpl(const GrShaderCaps&) const override {
- return std::make_unique<GLSLProcessor>();
- }
-
-private:
VerticesGP(LocalCoordsType localCoordsType,
ColorArrayType colorArrayType,
const SkPMColor4f& color,
diff --git a/src/gpu/ops/GrFillRRectOp.cpp b/src/gpu/ops/GrFillRRectOp.cpp
index b755d87..eab0c8e 100644
--- a/src/gpu/ops/GrFillRRectOp.cpp
+++ b/src/gpu/ops/GrFillRRectOp.cpp
@@ -344,6 +344,8 @@
std::unique_ptr<ProgramImpl> makeProgramImpl(const GrShaderCaps&) const final;
private:
+ class Impl;
+
Processor(GrAAType aaType, ProcessorFlags flags)
: INHERITED(kGrFillRRectOp_Processor_ClassID)
, fFlags(flags) {
@@ -375,8 +377,6 @@
SkSTArray<kMaxInstanceAttribs, Attribute> fInstanceAttribs;
const Attribute* fColorAttrib;
- class Impl;
-
using INHERITED = GrGeometryProcessor;
};
@@ -567,6 +567,12 @@
}
class FillRRectOp::Processor::Impl : public ProgramImpl {
+public:
+ void setData(const GrGLSLProgramDataManager&,
+ const GrShaderCaps&,
+ const GrGeometryProcessor&) override {}
+
+private:
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
GrGLSLVertexBuilder* v = args.fVertBuilder;
GrGLSLFPFragmentBuilder* f = args.fFragBuilder;
@@ -751,10 +757,6 @@
}
f->codeAppendf("half4 %s = half4(coverage);", args.fOutputCoverage);
}
-
- void setData(const GrGLSLProgramDataManager&,
- const GrShaderCaps&,
- const GrGeometryProcessor&) override {}
};
std::unique_ptr<GrGeometryProcessor::ProgramImpl> FillRRectOp::Processor::makeProgramImpl(
diff --git a/src/gpu/ops/GrLatticeOp.cpp b/src/gpu/ops/GrLatticeOp.cpp
index 5503e90..91138dc 100644
--- a/src/gpu/ops/GrLatticeOp.cpp
+++ b/src/gpu/ops/GrLatticeOp.cpp
@@ -46,7 +46,7 @@
}
std::unique_ptr<ProgramImpl> makeProgramImpl(const GrShaderCaps&) const override {
- class GLSLProcessor : public ProgramImpl {
+ class Impl : public ProgramImpl {
public:
void setData(const GrGLSLProgramDataManager& pdman,
const GrShaderCaps&,
@@ -86,9 +86,11 @@
args.fFragBuilder->codeAppend(";");
args.fFragBuilder->codeAppendf("const half4 %s = half4(1);", args.fOutputCoverage);
}
+
GrGLSLColorSpaceXformHelper fColorSpaceXformHelper;
};
- return std::make_unique<GLSLProcessor>();
+
+ return std::make_unique<Impl>();
}
private:
diff --git a/src/gpu/ops/GrOvalOpFactory.cpp b/src/gpu/ops/GrOvalOpFactory.cpp
index 9db38e5..a43a452 100644
--- a/src/gpu/ops/GrOvalOpFactory.cpp
+++ b/src/gpu/ops/GrOvalOpFactory.cpp
@@ -76,11 +76,18 @@
const char* name() const override { return "CircleGeometryProcessor"; }
void addToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override {
- GLSLProcessor::GenKey(*this, caps, b);
+ b->addBool(fStroke, "stroked" );
+ b->addBool(fInClipPlane.isInitialized(), "clipPlane" );
+ b->addBool(fInIsectPlane.isInitialized(), "isectPlane" );
+ b->addBool(fInUnionPlane.isInitialized(), "unionPlane" );
+ b->addBool(fInRoundCapCenters.isInitialized(), "roundCapCenters");
+ b->addBits(ProgramImpl::kMatrixKeyBits,
+ ProgramImpl::ComputeMatrixKey(caps, fLocalMatrix),
+ "localMatrixType");
}
std::unique_ptr<ProgramImpl> makeProgramImpl(const GrShaderCaps&) const override {
- return std::make_unique<GLSLProcessor>();
+ return std::make_unique<Impl>();
}
private:
@@ -111,10 +118,19 @@
this->setVertexAttributes(&fInPosition, 7);
}
- class GLSLProcessor : public ProgramImpl {
+ class Impl : public ProgramImpl {
public:
- GLSLProcessor() {}
+ void setData(const GrGLSLProgramDataManager& pdman,
+ const GrShaderCaps& shaderCaps,
+ const GrGeometryProcessor& geomProc) override {
+ SetTransform(pdman,
+ shaderCaps,
+ fLocalMatrixUniform,
+ geomProc.cast<CircleGeometryProcessor>().fLocalMatrix,
+ &fLocalMatrix);
+ }
+ private:
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
const CircleGeometryProcessor& cgp = args.fGeomProc.cast<CircleGeometryProcessor>();
GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
@@ -207,33 +223,6 @@
fragBuilder->codeAppendf("half4 %s = half4(edgeAlpha);", args.fOutputCoverage);
}
- static void GenKey(const GrGeometryProcessor& gp,
- const GrShaderCaps& shaderCaps,
- GrProcessorKeyBuilder* b) {
- const CircleGeometryProcessor& cgp = gp.cast<CircleGeometryProcessor>();
- b->addBool(cgp.fStroke, "stroked");
- b->addBool(cgp.fInClipPlane.isInitialized(), "clipPlane");
- b->addBool(cgp.fInIsectPlane.isInitialized(), "isectPlane");
- b->addBool(cgp.fInUnionPlane.isInitialized(), "unionPlane");
- b->addBool(cgp.fInRoundCapCenters.isInitialized(), "roundCapCenters");
- b->addBits(kMatrixKeyBits,
- ComputeMatrixKey(shaderCaps, cgp.fLocalMatrix),
- "localMatrixType");
- }
-
- void setData(const GrGLSLProgramDataManager& pdman,
- const GrShaderCaps& shaderCaps,
- const GrGeometryProcessor& geomProc) override {
- SetTransform(pdman,
- shaderCaps,
- fLocalMatrixUniform,
- geomProc.cast<CircleGeometryProcessor>().fLocalMatrix,
- &fLocalMatrix);
- }
-
- private:
- using INHERITED = ProgramImpl;
-
SkMatrix fLocalMatrix = SkMatrix::InvalidMatrix();
UniformHandle fLocalMatrixUniform;
};
@@ -285,11 +274,13 @@
const char* name() const override { return "ButtCapDashedCircleGeometryProcessor"; }
void addToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override {
- GLSLProcessor::GenKey(*this, caps, b);
+ b->addBits(ProgramImpl::kMatrixKeyBits,
+ ProgramImpl::ComputeMatrixKey(caps, fLocalMatrix),
+ "localMatrixType");
}
std::unique_ptr<ProgramImpl> makeProgramImpl(const GrShaderCaps&) const override {
- return std::make_unique<GLSLProcessor>();
+ return std::make_unique<Impl>();
}
private:
@@ -303,10 +294,19 @@
this->setVertexAttributes(&fInPosition, 4);
}
- class GLSLProcessor : public ProgramImpl {
+ class Impl : public ProgramImpl {
public:
- GLSLProcessor() {}
+ void setData(const GrGLSLProgramDataManager& pdman,
+ const GrShaderCaps& shaderCaps,
+ const GrGeometryProcessor& geomProc) override {
+ SetTransform(pdman,
+ shaderCaps,
+ fLocalMatrixUniform,
+ geomProc.cast<ButtCapDashedCircleGeometryProcessor>().fLocalMatrix,
+ &fLocalMatrix);
+ }
+ private:
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
const ButtCapDashedCircleGeometryProcessor& bcscgp =
args.fGeomProc.cast<ButtCapDashedCircleGeometryProcessor>();
@@ -480,29 +480,6 @@
fragBuilder->codeAppendf("half4 %s = half4(edgeAlpha);", args.fOutputCoverage);
}
- static void GenKey(const GrGeometryProcessor& gp,
- const GrShaderCaps& shaderCaps,
- GrProcessorKeyBuilder* b) {
- const ButtCapDashedCircleGeometryProcessor& bcscgp =
- gp.cast<ButtCapDashedCircleGeometryProcessor>();
- b->addBits(kMatrixKeyBits,
- ComputeMatrixKey(shaderCaps, bcscgp.fLocalMatrix),
- "localMatrixType");
- }
-
- void setData(const GrGLSLProgramDataManager& pdman,
- const GrShaderCaps& shaderCaps,
- const GrGeometryProcessor& geomProc) override {
- SetTransform(pdman,
- shaderCaps,
- fLocalMatrixUniform,
- geomProc.cast<ButtCapDashedCircleGeometryProcessor>().fLocalMatrix,
- &fLocalMatrix);
- }
-
- private:
- using INHERITED = ProgramImpl;
-
SkMatrix fLocalMatrix = SkMatrix::InvalidMatrix();
UniformHandle fLocalMatrixUniform;
};
@@ -550,11 +527,14 @@
const char* name() const override { return "EllipseGeometryProcessor"; }
void addToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override {
- GLSLProcessor::GenKey(*this, caps, b);
+ b->addBool(fStroke, "stroked");
+ b->addBits(ProgramImpl::kMatrixKeyBits,
+ ProgramImpl::ComputeMatrixKey(caps, fLocalMatrix),
+ "localMatrixType");
}
std::unique_ptr<ProgramImpl> makeProgramImpl(const GrShaderCaps&) const override {
- return std::make_unique<GLSLProcessor>();
+ return std::make_unique<Impl>();
}
private:
@@ -575,10 +555,16 @@
this->setVertexAttributes(&fInPosition, 4);
}
- class GLSLProcessor : public ProgramImpl {
+ class Impl : public ProgramImpl {
public:
- GLSLProcessor() {}
+ void setData(const GrGLSLProgramDataManager& pdman,
+ const GrShaderCaps& shaderCaps,
+ const GrGeometryProcessor& geomProc) override {
+ const EllipseGeometryProcessor& egp = geomProc.cast<EllipseGeometryProcessor>();
+ SetTransform(pdman, shaderCaps, fLocalMatrixUniform, egp.fLocalMatrix, &fLocalMatrix);
+ }
+ private:
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
const EllipseGeometryProcessor& egp = args.fGeomProc.cast<EllipseGeometryProcessor>();
GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
@@ -679,24 +665,6 @@
fragBuilder->codeAppendf("half4 %s = half4(half(edgeAlpha));", args.fOutputCoverage);
}
- static void GenKey(const GrGeometryProcessor& gp,
- const GrShaderCaps& shaderCaps,
- GrProcessorKeyBuilder* b) {
- const EllipseGeometryProcessor& egp = gp.cast<EllipseGeometryProcessor>();
- b->addBool(egp.fStroke, "stroked");
- b->addBits(kMatrixKeyBits,
- ComputeMatrixKey(shaderCaps, egp.fLocalMatrix),
- "localMatrixType");
- }
-
- void setData(const GrGLSLProgramDataManager& pdman,
- const GrShaderCaps& shaderCaps,
- const GrGeometryProcessor& geomProc) override {
- const EllipseGeometryProcessor& egp = geomProc.cast<EllipseGeometryProcessor>();
- SetTransform(pdman, shaderCaps, fLocalMatrixUniform, egp.fLocalMatrix, &fLocalMatrix);
- }
-
- private:
using INHERITED = ProgramImpl;
SkMatrix fLocalMatrix = SkMatrix::InvalidMatrix();
@@ -756,11 +724,14 @@
const char* name() const override { return "DIEllipseGeometryProcessor"; }
void addToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override {
- GLSLProcessor::GenKey(*this, caps, b);
+ b->addBits(2, static_cast<uint32_t>(fStyle), "style");
+ b->addBits(ProgramImpl::kMatrixKeyBits,
+ ProgramImpl::ComputeMatrixKey(caps, fViewMatrix),
+ "viewMatrixType");
}
std::unique_ptr<ProgramImpl> makeProgramImpl(const GrShaderCaps&) const override {
- return std::make_unique<GLSLProcessor>();
+ return std::make_unique<Impl>();
}
private:
@@ -783,10 +754,17 @@
this->setVertexAttributes(&fInPosition, 4);
}
- class GLSLProcessor : public ProgramImpl {
+ class Impl : public ProgramImpl {
public:
- GLSLProcessor() : fViewMatrix(SkMatrix::InvalidMatrix()) {}
+ void setData(const GrGLSLProgramDataManager& pdman,
+ const GrShaderCaps& shaderCaps,
+ const GrGeometryProcessor& geomProc) override {
+ const auto& diegp = geomProc.cast<DIEllipseGeometryProcessor>();
+ SetTransform(pdman, shaderCaps, fViewMatrixUniform, diegp.fViewMatrix, &fViewMatrix);
+ }
+
+ private:
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
const auto& diegp = args.fGeomProc.cast<DIEllipseGeometryProcessor>();
GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
@@ -878,29 +856,8 @@
fragBuilder->codeAppendf("half4 %s = half4(half(edgeAlpha));", args.fOutputCoverage);
}
- static void GenKey(const GrGeometryProcessor& gp,
- const GrShaderCaps& shaderCaps,
- GrProcessorKeyBuilder* b) {
- const DIEllipseGeometryProcessor& diegp = gp.cast<DIEllipseGeometryProcessor>();
- b->addBits(2, static_cast<uint32_t>(diegp.fStyle), "style");
- b->addBits(kMatrixKeyBits,
- ComputeMatrixKey(shaderCaps, diegp.fViewMatrix),
- "viewMatrixType");
- }
-
- void setData(const GrGLSLProgramDataManager& pdman,
- const GrShaderCaps& shaderCaps,
- const GrGeometryProcessor& geomProc) override {
- const auto& diegp = geomProc.cast<DIEllipseGeometryProcessor>();
-
- SetTransform(pdman, shaderCaps, fViewMatrixUniform, diegp.fViewMatrix, &fViewMatrix);
- }
-
- private:
- SkMatrix fViewMatrix;
+ SkMatrix fViewMatrix = SkMatrix::InvalidMatrix();
UniformHandle fViewMatrixUniform;
-
- using INHERITED = ProgramImpl;
};
Attribute fInPosition;
diff --git a/src/gpu/ops/GrQuadPerEdgeAA.cpp b/src/gpu/ops/GrQuadPerEdgeAA.cpp
index 0b71706..e95663c 100644
--- a/src/gpu/ops/GrQuadPerEdgeAA.cpp
+++ b/src/gpu/ops/GrQuadPerEdgeAA.cpp
@@ -546,8 +546,6 @@
class QuadPerEdgeAAGeometryProcessor : public GrGeometryProcessor {
public:
- using Saturate = GrTextureOp::Saturate;
-
static GrGeometryProcessor* Make(SkArenaAlloc* arena, const VertexSpec& spec) {
return arena->make([&](void* ptr) {
return new (ptr) QuadPerEdgeAAGeometryProcessor(spec);
@@ -603,7 +601,7 @@
}
std::unique_ptr<ProgramImpl> makeProgramImpl(const GrShaderCaps&) const override {
- class GLSLProcessor : public ProgramImpl {
+ class Impl : public ProgramImpl {
public:
void setData(const GrGLSLProgramDataManager& pdman,
const GrShaderCaps&,
@@ -760,12 +758,16 @@
args.fOutputCoverage);
}
}
+
GrGLSLColorSpaceXformHelper fTextureColorSpaceXformHelper;
};
- return std::make_unique<GLSLProcessor>();
+
+ return std::make_unique<Impl>();
}
private:
+ using Saturate = GrTextureOp::Saturate;
+
QuadPerEdgeAAGeometryProcessor(const VertexSpec& spec)
: INHERITED(kQuadPerEdgeAAGeometryProcessor_ClassID)
, fTextureColorSpaceXform(nullptr) {