Revert "Revert "Change how vertex/instance attributes are handled in geometry processors.""
This reverts commit 5045e501d2aec23e5f1e4b46346033ac3202c6b0.
TBR=csmartdalton@google.com
Change-Id: Ifbf5f1d8f8ef340fdc69653e931b6d68d4bf0854
Reviewed-on: https://skia-review.googlesource.com/135862
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/tests/PrimitiveProcessorTest.cpp b/tests/PrimitiveProcessorTest.cpp
index 74a73a6..60b2205 100644
--- a/tests/PrimitiveProcessorTest.cpp
+++ b/tests/PrimitiveProcessorTest.cpp
@@ -59,15 +59,15 @@
void onPrepareDraws(Target* target) override {
class GP : public GrGeometryProcessor {
public:
- GP(int numAttribs)
- : INHERITED(kGP_ClassID) {
+ GP(int numAttribs) : INHERITED(kGP_ClassID), fNumAttribs(numAttribs) {
SkASSERT(numAttribs > 1);
+ fAttribNames.reset(new SkString[numAttribs]);
+ fAttributes.reset(new Attribute[numAttribs]);
for (auto i = 0; i < numAttribs; ++i) {
- fAttribNames.push_back().printf("attr%d", i);
+ fAttribNames[i].printf("attr%d", i);
+ fAttributes[i] = {fAttribNames[i].c_str(), kFloat2_GrVertexAttribType};
}
- for (auto i = 0; i < numAttribs; ++i) {
- this->addVertexAttrib(fAttribNames[i].c_str(), kFloat2_GrVertexAttribType);
- }
+ this->setVertexAttributeCnt(numAttribs);
}
const char* name() const override { return "Dummy GP"; }
@@ -78,7 +78,7 @@
const GP& gp = args.fGP.cast<GP>();
args.fVaryingHandler->emitAttributes(gp);
this->writeOutputPosition(args.fVertBuilder, gpArgs,
- gp.getAttrib(0).name());
+ gp.fAttributes[0].name());
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
fragBuilder->codeAppendf("%s = half4(1);", args.fOutputColor);
fragBuilder->codeAppendf("%s = half4(1);", args.fOutputCoverage);
@@ -91,17 +91,24 @@
}
void getGLSLProcessorKey(const GrShaderCaps&,
GrProcessorKeyBuilder* builder) const override {
- builder->add32(this->numAttribs());
+ builder->add32(fNumAttribs);
}
private:
- SkTArray<SkString> fAttribNames;
+ const GrPrimitiveProcessor::Attribute& onVertexAttribute(int i) const override {
+ return fAttributes[i];
+ }
+
+ int fNumAttribs;
+ std::unique_ptr<SkString[]> fAttribNames;
+ std::unique_ptr<Attribute[]> fAttributes;
typedef GrGeometryProcessor INHERITED;
};
sk_sp<GrGeometryProcessor> gp(new GP(fNumAttribs));
QuadHelper helper;
- size_t vertexStride = gp->getVertexStride();
+ size_t vertexStride = fNumAttribs * GrVertexAttribTypeSize(kFloat2_GrVertexAttribType);
+ SkASSERT(vertexStride == gp->debugOnly_vertexStride());
SkPoint* vertices = reinterpret_cast<SkPoint*>(helper.init(target, vertexStride, 1));
SkPointPriv::SetRectTriStrip(vertices, 0.f, 0.f, 1.f, 1.f, vertexStride);
helper.recordDraw(target, gp.get(),