aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2018-06-19 14:33:47 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-06-19 20:01:29 +0000
commit92be2f74db81f0ed480b55c58cbde39270f9b772 (patch)
treed2b7135f511a318f10c5c86f2537c07051c922bd /tests
parentf5ac906476cd26f2967a48340940e6af580fa71f (diff)
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>
Diffstat (limited to 'tests')
-rw-r--r--tests/GrMeshTest.cpp51
-rw-r--r--tests/GrPipelineDynamicStateTest.cpp22
-rw-r--r--tests/OnFlushCallbackTest.cpp9
-rw-r--r--tests/PrimitiveProcessorTest.cpp27
4 files changed, 66 insertions, 43 deletions
diff --git a/tests/GrMeshTest.cpp b/tests/GrMeshTest.cpp
index 4d9773b1a9..f95dbc8603 100644
--- a/tests/GrMeshTest.cpp
+++ b/tests/GrMeshTest.cpp
@@ -294,35 +294,46 @@ private:
class GrMeshTestProcessor : public GrGeometryProcessor {
public:
GrMeshTestProcessor(bool instanced, bool hasVertexBuffer)
- : INHERITED(kGrMeshTestProcessor_ClassID)
- , fInstanceLocation(nullptr)
- , fVertex(nullptr)
- , fColor(nullptr) {
+ : INHERITED(kGrMeshTestProcessor_ClassID) {
if (instanced) {
- fInstanceLocation = &this->addInstanceAttrib("location", kHalf2_GrVertexAttribType);
+ fInstanceLocation = {"location", kHalf2_GrVertexAttribType};
+ fColor = {"color", kUByte4_norm_GrVertexAttribType};
+ this->setInstanceAttributeCnt(2);
if (hasVertexBuffer) {
- fVertex = &this->addVertexAttrib("vertex", kHalf2_GrVertexAttribType);
+ fVertex = {"vertex", kHalf2_GrVertexAttribType};
+ this->setVertexAttributeCnt(1);
}
- fColor = &this->addInstanceAttrib("color", kUByte4_norm_GrVertexAttribType);
} else {
- fVertex = &this->addVertexAttrib("vertex", kHalf2_GrVertexAttribType);
- fColor = &this->addVertexAttrib("color", kUByte4_norm_GrVertexAttribType);
+ fVertex = {"vertex", kHalf2_GrVertexAttribType};
+ fColor = {"color", kUByte4_norm_GrVertexAttribType};
+ this->setVertexAttributeCnt(2);
}
}
const char* name() const override { return "GrMeshTest Processor"; }
void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const final {
- b->add32(SkToBool(fInstanceLocation));
- b->add32(SkToBool(fVertex));
+ b->add32(fInstanceLocation.isInitialized());
+ b->add32(fVertex.isInitialized());
}
GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const final;
-protected:
- const Attribute* fInstanceLocation;
- const Attribute* fVertex;
- const Attribute* fColor;
+private:
+ const Attribute& onVertexAttribute(int i) const override {
+ if (fInstanceLocation.isInitialized()) {
+ return fVertex;
+ }
+ return IthAttribute(i, fVertex, fColor);
+ }
+
+ const Attribute& onInstanceAttribute(int i) const override {
+ return IthAttribute(i, fInstanceLocation, fColor);
+ }
+
+ Attribute fInstanceLocation;
+ Attribute fVertex;
+ Attribute fColor;
friend class GLSLMeshTestProcessor;
typedef GrGeometryProcessor INHERITED;
@@ -340,15 +351,15 @@ class GLSLMeshTestProcessor : public GrGLSLGeometryProcessor {
varyingHandler->addPassThroughAttribute(mp.fColor, args.fOutputColor);
GrGLSLVertexBuilder* v = args.fVertBuilder;
- if (!mp.fInstanceLocation) {
- v->codeAppendf("float2 vertex = %s;", mp.fVertex->name());
+ if (!mp.fInstanceLocation.isInitialized()) {
+ v->codeAppendf("float2 vertex = %s;", mp.fVertex.name());
} else {
- if (mp.fVertex) {
- v->codeAppendf("float2 offset = %s;", mp.fVertex->name());
+ if (mp.fVertex.isInitialized()) {
+ v->codeAppendf("float2 offset = %s;", mp.fVertex.name());
} else {
v->codeAppend ("float2 offset = float2(sk_VertexID / 2, sk_VertexID % 2);");
}
- v->codeAppendf("float2 vertex = %s + offset * %i;", mp.fInstanceLocation->name(),
+ v->codeAppendf("float2 vertex = %s + offset * %i;", mp.fInstanceLocation.name(),
kBoxSize);
}
gpArgs->fPositionVar.set(kFloat2_GrSLType, "vertex");
diff --git a/tests/GrPipelineDynamicStateTest.cpp b/tests/GrPipelineDynamicStateTest.cpp
index a197650c4f..b5bc74d382 100644
--- a/tests/GrPipelineDynamicStateTest.cpp
+++ b/tests/GrPipelineDynamicStateTest.cpp
@@ -58,9 +58,9 @@ struct Vertex {
class GrPipelineDynamicStateTestProcessor : public GrGeometryProcessor {
public:
GrPipelineDynamicStateTestProcessor()
- : INHERITED(kGrPipelineDynamicStateTestProcessor_ClassID)
- , fVertex(this->addVertexAttrib("vertex", kHalf2_GrVertexAttribType))
- , fColor(this->addVertexAttrib("color", kUByte4_norm_GrVertexAttribType)) {}
+ : INHERITED(kGrPipelineDynamicStateTestProcessor_ClassID) {
+ this->setVertexAttributeCnt(2);
+ }
const char* name() const override { return "GrPipelineDynamicStateTest Processor"; }
@@ -68,13 +68,19 @@ public:
GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const final;
-protected:
- const Attribute& fVertex;
- const Attribute& fColor;
+private:
+ const Attribute& onVertexAttribute(int i) const override {
+ return IthAttribute(i, kVertex, kColor);
+ }
+
+ static constexpr Attribute kVertex = {"vertex", kHalf2_GrVertexAttribType};
+ static constexpr Attribute kColor = {"color", kUByte4_norm_GrVertexAttribType};
friend class GLSLPipelineDynamicStateTestProcessor;
typedef GrGeometryProcessor INHERITED;
};
+constexpr GrPrimitiveProcessor::Attribute GrPipelineDynamicStateTestProcessor::kVertex;
+constexpr GrPrimitiveProcessor::Attribute GrPipelineDynamicStateTestProcessor::kColor;
class GLSLPipelineDynamicStateTestProcessor : public GrGLSLGeometryProcessor {
void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcessor&,
@@ -86,10 +92,10 @@ class GLSLPipelineDynamicStateTestProcessor : public GrGLSLGeometryProcessor {
GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
varyingHandler->emitAttributes(mp);
- varyingHandler->addPassThroughAttribute(&mp.fColor, args.fOutputColor);
+ varyingHandler->addPassThroughAttribute(mp.kColor, args.fOutputColor);
GrGLSLVertexBuilder* v = args.fVertBuilder;
- v->codeAppendf("float2 vertex = %s;", mp.fVertex.name());
+ v->codeAppendf("float2 vertex = %s;", mp.kVertex.name());
gpArgs->fPositionVar.set(kFloat2_GrSLType, "vertex");
GrGLSLFPFragmentBuilder* f = args.fFragBuilder;
diff --git a/tests/OnFlushCallbackTest.cpp b/tests/OnFlushCallbackTest.cpp
index e2f6fbf9e1..a8752057c8 100644
--- a/tests/OnFlushCallbackTest.cpp
+++ b/tests/OnFlushCallbackTest.cpp
@@ -110,11 +110,10 @@ private:
return;
}
- size_t vertexStride = gp->getVertexStride();
-
- SkASSERT(fHasLocalRect
- ? vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr)
- : vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAttr));
+ size_t vertexStride = fHasLocalRect
+ ? sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr)
+ : sizeof(GrDefaultGeoProcFactory::PositionColorAttr);
+ SkASSERT(vertexStride == gp->debugOnly_vertexStride());
const GrBuffer* indexBuffer;
int firstIndex;
diff --git a/tests/PrimitiveProcessorTest.cpp b/tests/PrimitiveProcessorTest.cpp
index 74a73a66a9..60b2205cf7 100644
--- a/tests/PrimitiveProcessorTest.cpp
+++ b/tests/PrimitiveProcessorTest.cpp
@@ -59,15 +59,15 @@ private:
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);
- }
- for (auto i = 0; i < numAttribs; ++i) {
- this->addVertexAttrib(fAttribNames[i].c_str(), kFloat2_GrVertexAttribType);
+ fAttribNames[i].printf("attr%d", i);
+ fAttributes[i] = {fAttribNames[i].c_str(), kFloat2_GrVertexAttribType};
}
+ this->setVertexAttributeCnt(numAttribs);
}
const char* name() const override { return "Dummy GP"; }
@@ -78,7 +78,7 @@ private:
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 @@ private:
}
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(),