Change how GPs configure attributes

Adds setVertexAttributes and setInstanceAttributes. These take a pointer
to the first attribute, and a count. The count is the total number of
possible attributes, though some may not be initialized. The base class
computes the number of initialized attributes, pre-computes the strides,
and only allows subsequent access to the initialized attributes.

The attributes need to be allocated contiguously. Some GPs place them in
an array, though most just place them as consecutive members, and pass
a pointer to the first one.

Indexed access would be possible, but now it makes more sense to iterate
over all attributes, so enable that, and use range-based for everywhere.

Completely remove the per-attribute offset helper (again - possible, but
not real helpful), and make the stride always available. In many ops,
just use the GP's computed stride, rather than re-computing it.

Bug: skia:
Change-Id: Ie4cccb7969a98ee5a10b373e714fbd702e875b3e
Reviewed-on: https://skia-review.googlesource.com/c/169241
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Osman 2018-11-12 15:34:00 -05:00 committed by Skia Commit-Bot
parent e18d2772cd
commit f04fb3cacb
52 changed files with 324 additions and 659 deletions

View File

@ -52,7 +52,7 @@ public:
fInColor = {"inColor", kHalf4_GrVertexAttribType, kHalf4_GrSLType};
break;
}
this->setVertexAttributeCnt(2);
this->setVertexAttributes(&fInPosition, 2);
}
const char* name() const override { return "VertexColorXformGP"; }
@ -109,10 +109,6 @@ public:
}
private:
const GrPrimitiveProcessor::Attribute& onVertexAttribute(int i) const override {
return IthAttribute(i, fInPosition, fInColor);
}
Mode fMode;
sk_sp<GrColorSpaceXform> fColorSpaceXform;
@ -165,19 +161,7 @@ private:
void onPrepareDraws(Target* target) override {
sk_sp<GrGeometryProcessor> gp(new GP(fMode, fColorSpaceXform));
size_t vertexStride = sizeof(SkPoint);
switch (fMode) {
case kFloat_Mode:
vertexStride += sizeof(SkColor4f);
break;
case kHalf_Mode:
vertexStride += sizeof(uint64_t);
break;
default:
vertexStride += sizeof(uint32_t);
}
SkASSERT(vertexStride == gp->debugOnly_vertexStride());
size_t vertexStride = gp->vertexStride();
const int kVertexCount = 1024;
const GrBuffer* vertexBuffer = nullptr;
int firstVertex = 0;

View File

@ -100,7 +100,7 @@ private:
};
void onPrepareDraws(Target* target) override {
SkASSERT(this->gp()->debugOnly_vertexStride() == sizeof(Vertex));
SkASSERT(this->gp()->vertexStride() == sizeof(Vertex));
QuadHelper helper(target, sizeof(Vertex), 1);
Vertex* verts = reinterpret_cast<Vertex*>(helper.vertices());
if (!verts) {
@ -322,7 +322,7 @@ private:
};
void onPrepareDraws(Target* target) override {
SkASSERT(this->gp()->debugOnly_vertexStride() == sizeof(Vertex));
SkASSERT(this->gp()->vertexStride() == sizeof(Vertex));
QuadHelper helper(target, sizeof(Vertex), 1);
Vertex* verts = reinterpret_cast<Vertex*>(helper.vertices());
if (!verts) {

View File

@ -45,7 +45,7 @@ public:
ClockwiseTestProcessor(bool readSkFragCoord)
: GrGeometryProcessor(kClockwiseTestProcessor_ClassID)
, fReadSkFragCoord(readSkFragCoord) {
this->setVertexAttributeCnt(1);
this->setVertexAttributes(&gVertex, 1);
}
const char* name() const override { return "ClockwiseTestProcessor"; }
void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const final {
@ -54,8 +54,6 @@ public:
GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const final;
private:
const Attribute& onVertexAttribute(int i) const override { return gVertex; }
const bool fReadSkFragCoord;
friend class GLSLClockwiseTestProcessor;

View File

@ -85,7 +85,7 @@ private:
LocalCoords::kUnused_Type,
SkMatrix::I()));
SkASSERT(gp->debugOnly_vertexStride() == sizeof(SkPoint));
SkASSERT(gp->vertexStride() == sizeof(SkPoint));
QuadHelper helper(target, sizeof(SkPoint), 1);
SkPoint* verts = reinterpret_cast<SkPoint*>(helper.vertices());
if (!verts) {

View File

@ -322,19 +322,15 @@ private:
, fBones(bones)
, fBoneCount(boneCount) {
fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
int cnt = 1;
if (fFlags & kColorAttribute_GPFlag) {
fInColor = {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
++cnt;
}
if (fFlags & kLocalCoordAttribute_GPFlag) {
fInLocalCoords = {"inLocalCoord", kFloat2_GrVertexAttribType,
kFloat2_GrSLType};
++cnt;
}
if (fFlags & kCoverageAttribute_GPFlag) {
fInCoverage = {"inCoverage", kFloat_GrVertexAttribType, kHalf_GrSLType};
++cnt;
}
if (fFlags & kBonesAttribute_GPFlag) {
SkASSERT(bones && (boneCount > 0));
@ -346,22 +342,10 @@ private:
indicesGPUType = kHalf4_GrSLType;
}
fInBoneIndices = {"inBoneIndices", indicesCPUType, indicesGPUType};
++cnt;
fInBoneWeights = {"inBoneWeights", kUByte4_norm_GrVertexAttribType,
kHalf4_GrSLType};
++cnt;
}
this->setVertexAttributeCnt(cnt);
}
const Attribute& onVertexAttribute(int i) const override {
return IthInitializedAttribute(i,
fInPosition,
fInColor,
fInLocalCoords,
fInCoverage,
fInBoneIndices,
fInBoneWeights);
this->setVertexAttributes(&fInPosition, 6);
}
Attribute fInPosition;

View File

@ -39,36 +39,6 @@ protected:
fSampleShading = sampleShading;
}
/**
* Recursive helpers for implementing onVertexAttribute or onInstanceAttribute.
*/
template <typename... Args>
static const Attribute& IthAttribute(int i, const Attribute& attr0, const Args&... attrs) {
SkASSERT(attr0.isInitialized());
return (0 == i) ? attr0 : IthAttribute(i - 1, attrs...);
}
static const Attribute& IthAttribute(int i) {
SK_ABORT("Illegal attribute Index");
static constexpr Attribute kBogus;
return kBogus;
}
template <typename... Args>
static const Attribute& IthInitializedAttribute(int i, const Attribute& attr0,
const Args&... attrs) {
if (attr0.isInitialized()) {
if (0 == i) {
return attr0;
}
i -= 1;
}
return IthInitializedAttribute(i, attrs...);
}
static const Attribute& IthInitializedAttribute(int i) { return IthAttribute(i); }
private:
bool fWillUseGeoShader;
float fSampleShading;

View File

@ -38,18 +38,6 @@ public:
virtual bool isPathRendering() const override { return true; }
private:
const Attribute& onVertexAttribute(int i) const final {
SK_ABORT("No vertex attributes");
static constexpr Attribute kBogus;
return kBogus;
}
const Attribute& onInstanceAttribute(int i) const final {
SK_ABORT("No instanced attributes");
static constexpr Attribute kBogus;
return kBogus;
}
GrPathProcessor(const SkPMColor4f&, const SkMatrix& viewMatrix, const SkMatrix& localMatrix);
SkPMColor4f fColor;

View File

@ -24,56 +24,6 @@ const GrPrimitiveProcessor::TextureSampler& GrPrimitiveProcessor::textureSampler
return this->onTextureSampler(i);
}
const GrPrimitiveProcessor::Attribute& GrPrimitiveProcessor::vertexAttribute(int i) const {
SkASSERT(i >= 0 && i < this->numVertexAttributes());
const auto& result = this->onVertexAttribute(i);
SkASSERT(result.isInitialized());
return result;
}
const GrPrimitiveProcessor::Attribute& GrPrimitiveProcessor::instanceAttribute(int i) const {
SkASSERT(i >= 0 && i < this->numInstanceAttributes());
const auto& result = this->onInstanceAttribute(i);
SkASSERT(result.isInitialized());
return result;
}
#ifdef SK_DEBUG
size_t GrPrimitiveProcessor::debugOnly_vertexStride() const {
size_t stride = 0;
for (int i = 0; i < fVertexAttributeCnt; ++i) {
stride += this->vertexAttribute(i).sizeAlign4();
}
return stride;
}
size_t GrPrimitiveProcessor::debugOnly_instanceStride() const {
size_t stride = 0;
for (int i = 0; i < fInstanceAttributeCnt; ++i) {
stride += this->instanceAttribute(i).sizeAlign4();
}
return stride;
}
size_t GrPrimitiveProcessor::debugOnly_vertexAttributeOffset(int i) const {
SkASSERT(i >= 0 && i < fVertexAttributeCnt);
size_t offset = 0;
for (int j = 0; j < i; ++j) {
offset += this->vertexAttribute(j).sizeAlign4();
}
return offset;
}
size_t GrPrimitiveProcessor::debugOnly_instanceAttributeOffset(int i) const {
SkASSERT(i >= 0 && i < fInstanceAttributeCnt);
size_t offset = 0;
for (int j = 0; j < i; ++j) {
offset += this->instanceAttribute(j).sizeAlign4();
}
return offset;
}
#endif
uint32_t
GrPrimitiveProcessor::getTransformKey(const SkTArray<const GrCoordTransform*, true>& coords,
int numCoords) const {

View File

@ -80,34 +80,88 @@ public:
GrSLType fGPUType = kFloat_GrSLType;
};
class Iter {
public:
Iter() : fCurr(nullptr), fRemaining(0) {}
Iter(const Iter& iter) : fCurr(iter.fCurr), fRemaining(iter.fRemaining) {}
Iter& operator= (const Iter& iter) {
fCurr = iter.fCurr;
fRemaining = iter.fRemaining;
return *this;
}
Iter(const Attribute* attrs, int count) : fCurr(attrs), fRemaining(count) {
this->skipUninitialized();
}
bool operator!=(const Iter& that) const { return fCurr != that.fCurr; }
const Attribute& operator*() const { return *fCurr; }
void operator++() {
if (fRemaining) {
fRemaining--;
fCurr++;
this->skipUninitialized();
}
}
private:
void skipUninitialized() {
if (!fRemaining) {
fCurr = nullptr;
} else {
while (!fCurr->isInitialized()) {
++fCurr;
}
}
}
const Attribute* fCurr;
int fRemaining;
};
class AttributeSet {
public:
Iter begin() const { return Iter(fAttributes, fCount); }
Iter end() const { return Iter(); }
private:
friend class GrPrimitiveProcessor;
void init(const Attribute* attrs, int count) {
fAttributes = attrs;
fCount = 0;
fStride = 0;
for (int i = 0; i < count; ++i) {
if (attrs[i].isInitialized()) {
fCount++;
fStride += attrs[i].sizeAlign4();
}
}
}
const Attribute* fAttributes = nullptr;
int fCount = 0;
size_t fStride = 0;
};
GrPrimitiveProcessor(ClassID);
int numTextureSamplers() const { return fTextureSamplerCnt; }
const TextureSampler& textureSampler(int index) const;
int numVertexAttributes() const { return fVertexAttributeCnt; }
const Attribute& vertexAttribute(int i) const;
int numInstanceAttributes() const { return fInstanceAttributeCnt; }
const Attribute& instanceAttribute(int i) const;
int numVertexAttributes() const { return fVertexAttributes.fCount; }
const AttributeSet& vertexAttributes() const { return fVertexAttributes; }
int numInstanceAttributes() const { return fInstanceAttributes.fCount; }
const AttributeSet& instanceAttributes() const { return fInstanceAttributes; }
bool hasVertexAttributes() const { return SkToBool(fVertexAttributeCnt); }
bool hasInstanceAttributes() const { return SkToBool(fInstanceAttributeCnt); }
bool hasVertexAttributes() const { return SkToBool(fVertexAttributes.fCount); }
bool hasInstanceAttributes() const { return SkToBool(fInstanceAttributes.fCount); }
#ifdef SK_DEBUG
/**
* A common practice is to populate the the vertex/instance's memory using an implicit array of
* structs. In this case, it is best to assert that:
* debugOnly_stride == sizeof(struct) and
* offsetof(struct, field[i]) == debugOnly_AttributeOffset(i)
* In general having Op subclasses assert that attribute offsets and strides agree with their
* tessellation code's expectations is good practice.
* However, these functions walk the attributes to compute offsets and call virtual functions
* to access the attributes. Thus, they are only available in debug builds.
* stride == sizeof(struct)
*/
size_t debugOnly_vertexStride() const;
size_t debugOnly_instanceStride() const;
size_t debugOnly_vertexAttributeOffset(int) const;
size_t debugOnly_instanceAttributeOffset(int) const;
#endif
size_t vertexStride() const { return fVertexAttributes.fStride; }
size_t instanceStride() const { return fInstanceAttributes.fStride; }
// Only the GrGeometryProcessor subclass actually has a geo shader or vertex attributes, but
// we put these calls on the base class to prevent having to cast
@ -146,13 +200,12 @@ public:
virtual float getSampleShading() const { return 0.0; }
protected:
void setVertexAttributeCnt(int cnt) {
SkASSERT(cnt >= 0);
fVertexAttributeCnt = cnt;
void setVertexAttributes(const Attribute* attrs, int attrCount) {
fVertexAttributes.init(attrs, attrCount);
}
void setInstanceAttributeCnt(int cnt) {
SkASSERT(cnt >= 0);
fInstanceAttributeCnt = cnt;
void setInstanceAttributes(const Attribute* attrs, int attrCount) {
SkASSERT(attrCount >= 0);
fInstanceAttributes.init(attrs, attrCount);
}
void setTextureSamplerCnt(int cnt) {
SkASSERT(cnt >= 0);
@ -171,22 +224,11 @@ protected:
inline static const TextureSampler& IthTextureSampler(int i);
private:
virtual const Attribute& onVertexAttribute(int) const {
SK_ABORT("No vertex attributes");
static constexpr Attribute kBogus;
return kBogus;
}
virtual const Attribute& onInstanceAttribute(int i) const {
SK_ABORT("No instanced attributes");
static constexpr Attribute kBogus;
return kBogus;
}
virtual const TextureSampler& onTextureSampler(int) const { return IthTextureSampler(0); }
int fVertexAttributeCnt = 0;
int fInstanceAttributeCnt = 0;
AttributeSet fVertexAttributes;
AttributeSet fInstanceAttributes;
int fTextureSamplerCnt = 0;
typedef GrProcessor INHERITED;
};

View File

@ -250,13 +250,6 @@ private:
void initGS();
void initVS(GrResourceProvider*);
const Attribute& onVertexAttribute(int i) const override { return fVertexAttribute; }
const Attribute& onInstanceAttribute(int i) const override {
SkASSERT(fImpl == Impl::kVertexShader);
return fInstanceAttributes[i];
}
void appendGSMesh(GrBuffer* instanceBuffer, int instanceCount, int baseInstance,
SkTArray<GrMesh>* out) const;
void appendVSMesh(GrBuffer* instanceBuffer, int instanceCount, int baseInstance,

View File

@ -395,7 +395,7 @@ void GrCCCoverageProcessor::initGS() {
GR_STATIC_ASSERT(offsetof(TriPointInstance, fY) ==
GrVertexAttribTypeSize(kFloat3_GrVertexAttribType));
}
this->setVertexAttributeCnt(1);
this->setVertexAttributes(&fVertexAttribute, 1);
this->setWillUseGeoShader();
}

View File

@ -516,9 +516,9 @@ void GrCCCoverageProcessor::initVS(GrResourceProvider* rp) {
}
fInstanceAttributes[kInstanceAttribIdx_X] = {"X", xyAttribType, xySLType};
fInstanceAttributes[kInstanceAttribIdx_Y] = {"Y", xyAttribType, xySLType};
this->setInstanceAttributeCnt(2);
this->setInstanceAttributes(fInstanceAttributes, 2);
fVertexAttribute = {"vertexdata", kInt_GrVertexAttribType, kInt_GrSLType};
this->setVertexAttributeCnt(1);
this->setVertexAttributes(&fVertexAttribute, 1);
if (caps.usePrimitiveRestart()) {
fVSTriangleType = GrPrimitiveType::kTriangleStrip;

View File

@ -83,19 +83,10 @@ GrCCPathProcessor::GrCCPathProcessor(const GrTextureProxy* atlas,
, fAtlasSize(atlas->isize())
, fAtlasOrigin(atlas->origin()) {
// TODO: Can we just assert that atlas has GrCCAtlas::kTextureOrigin and remove fAtlasOrigin?
this->setInstanceAttributeCnt(kNumInstanceAttribs);
// Check that instance attributes exactly match Instance struct layout.
SkASSERT(!strcmp(this->instanceAttribute(0).name(), "devbounds"));
SkASSERT(!strcmp(this->instanceAttribute(1).name(), "devbounds45"));
SkASSERT(!strcmp(this->instanceAttribute(2).name(), "dev_to_atlas_offset"));
SkASSERT(!strcmp(this->instanceAttribute(3).name(), "color"));
SkASSERT(this->debugOnly_instanceAttributeOffset(0) == offsetof(Instance, fDevBounds));
SkASSERT(this->debugOnly_instanceAttributeOffset(1) == offsetof(Instance, fDevBounds45));
SkASSERT(this->debugOnly_instanceAttributeOffset(2) == offsetof(Instance, fDevToAtlasOffset));
SkASSERT(this->debugOnly_instanceAttributeOffset(3) == offsetof(Instance, fColor));
SkASSERT(this->debugOnly_instanceStride() == sizeof(Instance));
this->setInstanceAttributes(kInstanceAttribs, kNumInstanceAttribs);
SkASSERT(this->instanceStride() == sizeof(Instance));
this->setVertexAttributeCnt(1);
this->setVertexAttributes(&kEdgeNormsAttrib, 1);
this->setTextureSamplerCnt(1);
if (!viewMatrixIfUsingLocalCoords.invert(&fLocalMatrix)) {

View File

@ -91,8 +91,6 @@ public:
const SkRect& bounds) const;
private:
const Attribute& onVertexAttribute(int i) const override { return kEdgeNormsAttrib; }
const Attribute& onInstanceAttribute(int i) const override { return kInstanceAttribs[i]; }
const TextureSampler& onTextureSampler(int) const override { return fAtlasAccess; }
const TextureSampler fAtlasAccess;

View File

@ -70,15 +70,10 @@ inline void CubicStrokeInstance::set(const Sk4f& X, const Sk4f& Y, float dx, flo
class LinearStrokeProcessor : public GrGeometryProcessor {
public:
LinearStrokeProcessor() : GrGeometryProcessor(kLinearStrokeProcessor_ClassID) {
this->setInstanceAttributeCnt(2);
this->setInstanceAttributes(kInstanceAttribs, 2);
#ifdef SK_DEBUG
// Check that instance attributes exactly match the LinearStrokeInstance struct layout.
using Instance = LinearStrokeInstance;
SkASSERT(!strcmp(this->instanceAttribute(0).name(), "endpts"));
SkASSERT(this->debugOnly_instanceAttributeOffset(0) == offsetof(Instance, fEndpoints));
SkASSERT(!strcmp(this->instanceAttribute(1).name(), "stroke_radius"));
SkASSERT(this->debugOnly_instanceAttributeOffset(1) == offsetof(Instance, fStrokeRadius));
SkASSERT(this->debugOnly_instanceStride() == sizeof(Instance));
SkASSERT(this->instanceStride() == sizeof(Instance));
#endif
}
@ -91,8 +86,6 @@ private:
{"stroke_radius", kFloat_GrVertexAttribType, kFloat_GrSLType}
};
const Attribute& onInstanceAttribute(int i) const override { return kInstanceAttribs[i]; }
class Impl : public GrGLSLGeometryProcessor {
void setData(const GrGLSLProgramDataManager&, const GrPrimitiveProcessor&,
FPCoordTransformIter&&) override {}
@ -167,17 +160,10 @@ constexpr GrPrimitiveProcessor::Attribute LinearStrokeProcessor::kInstanceAttrib
class CubicStrokeProcessor : public GrGeometryProcessor {
public:
CubicStrokeProcessor() : GrGeometryProcessor(kCubicStrokeProcessor_ClassID) {
this->setInstanceAttributeCnt(3);
this->setInstanceAttributes(kInstanceAttribs, 3);
#ifdef SK_DEBUG
// Check that instance attributes exactly match the CubicStrokeInstance struct layout.
using Instance = CubicStrokeInstance;
SkASSERT(!strcmp(this->instanceAttribute(0).name(), "X"));
SkASSERT(this->debugOnly_instanceAttributeOffset(0) == offsetof(Instance, fX));
SkASSERT(!strcmp(this->instanceAttribute(1).name(), "Y"));
SkASSERT(this->debugOnly_instanceAttributeOffset(1) == offsetof(Instance, fY));
SkASSERT(!strcmp(this->instanceAttribute(2).name(), "stroke_info"));
SkASSERT(this->debugOnly_instanceAttributeOffset(2) == offsetof(Instance, fStrokeRadius));
SkASSERT(this->debugOnly_instanceStride() == sizeof(Instance));
SkASSERT(this->instanceStride() == sizeof(Instance));
#endif
}
@ -191,8 +177,6 @@ private:
{"stroke_info", kFloat2_GrVertexAttribType, kFloat2_GrSLType}
};
const Attribute& onInstanceAttribute(int i) const override { return kInstanceAttribs[i]; }
class Impl : public GrGLSLGeometryProcessor {
void setData(const GrGLSLProgramDataManager&, const GrPrimitiveProcessor&,
FPCoordTransformIter&&) override {}

View File

@ -240,7 +240,7 @@ GrConicEffect::GrConicEffect(const SkPMColor4f& color, const SkMatrix& viewMatri
, fUsesLocalCoords(usesLocalCoords)
, fCoverageScale(coverage)
, fEdgeType(edgeType) {
this->setVertexAttributeCnt(2);
this->setVertexAttributes(kAttributes, SK_ARRAY_COUNT(kAttributes));
}
//////////////////////////////////////////////////////////////////////////////
@ -440,7 +440,7 @@ GrQuadEffect::GrQuadEffect(const SkPMColor4f& color, const SkMatrix& viewMatrix,
, fUsesLocalCoords(usesLocalCoords)
, fCoverageScale(coverage)
, fEdgeType(edgeType) {
this->setVertexAttributeCnt(2);
this->setVertexAttributes(kAttributes, SK_ARRAY_COUNT(kAttributes));
}
//////////////////////////////////////////////////////////////////////////////

View File

@ -112,8 +112,6 @@ private:
GrConicEffect(const SkPMColor4f&, const SkMatrix& viewMatrix, uint8_t coverage, GrClipEdgeType,
const SkMatrix& localMatrix, bool usesLocalCoords);
const Attribute& onVertexAttribute(int i) const override { return kAttributes[i]; }
SkPMColor4f fColor;
SkMatrix fViewMatrix;
SkMatrix fLocalMatrix;
@ -198,8 +196,6 @@ private:
GrQuadEffect(const SkPMColor4f&, const SkMatrix& viewMatrix, uint8_t coverage, GrClipEdgeType,
const SkMatrix& localMatrix, bool usesLocalCoords);
const Attribute& onVertexAttribute(int i) const override { return kAttributes[i]; }
SkPMColor4f fColor;
SkMatrix fViewMatrix;
SkMatrix fLocalMatrix;

View File

@ -138,18 +138,15 @@ GrBitmapTextGeoProc::GrBitmapTextGeoProc(const GrShaderCaps& caps,
fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
}
fInTextureCoords = {"inTextureCoords", kUShort2_GrVertexAttribType,
caps.integerSupport() ? kUShort2_GrSLType : kFloat2_GrSLType };
int cnt = 2;
bool hasVertexColor = kA8_GrMaskFormat == fMaskFormat ||
kA565_GrMaskFormat == fMaskFormat;
if (hasVertexColor) {
fInColor = {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
++cnt;
}
this->setVertexAttributeCnt(cnt);
fInTextureCoords = {"inTextureCoords", kUShort2_GrVertexAttribType,
caps.integerSupport() ? kUShort2_GrSLType : kFloat2_GrSLType};
this->setVertexAttributes(&fInPosition, 3);
if (numActiveProxies) {
fAtlasSize = proxies[0]->isize();
@ -162,10 +159,6 @@ GrBitmapTextGeoProc::GrBitmapTextGeoProc(const GrShaderCaps& caps,
this->setTextureSamplerCnt(numActiveProxies);
}
const GrPrimitiveProcessor::Attribute& GrBitmapTextGeoProc::onVertexAttribute(int i) const {
return IthInitializedAttribute(i, fInPosition, fInColor, fInTextureCoords);
}
void GrBitmapTextGeoProc::addNewProxies(const sk_sp<GrTextureProxy>* proxies,
int numActiveProxies,
const GrSamplerState& params) {

View File

@ -59,7 +59,6 @@ private:
const GrSamplerState& params, GrMaskFormat format,
const SkMatrix& localMatrix, bool usesW);
const Attribute& onVertexAttribute(int i) const override;
const TextureSampler& onTextureSampler(int i) const override { return fTextureSamplers[i]; }
SkPMColor4f fColor;

View File

@ -206,8 +206,6 @@ private:
///////////////////////////////////////////////////////////////////////////////
constexpr GrPrimitiveProcessor::Attribute GrDistanceFieldA8TextGeoProc::kInColor;
GrDistanceFieldA8TextGeoProc::GrDistanceFieldA8TextGeoProc(const GrShaderCaps& caps,
const sk_sp<GrTextureProxy>* proxies,
int numProxies,
@ -232,9 +230,10 @@ GrDistanceFieldA8TextGeoProc::GrDistanceFieldA8TextGeoProc(const GrShaderCaps& c
} else {
fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
}
fInColor = {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType };
fInTextureCoords = {"inTextureCoords", kUShort2_GrVertexAttribType,
caps.integerSupport() ? kUShort2_GrSLType : kFloat2_GrSLType};
this->setVertexAttributeCnt(3);
this->setVertexAttributes(&fInPosition, 3);
if (numProxies) {
fAtlasSize = proxies[0]->isize();
@ -509,8 +508,6 @@ private:
};
///////////////////////////////////////////////////////////////////////////////
constexpr GrPrimitiveProcessor::Attribute GrDistanceFieldPathGeoProc::kInPosition;
constexpr GrPrimitiveProcessor::Attribute GrDistanceFieldPathGeoProc::kInColor;
GrDistanceFieldPathGeoProc::GrDistanceFieldPathGeoProc(const GrShaderCaps& caps,
const SkMatrix& matrix,
@ -524,9 +521,11 @@ GrDistanceFieldPathGeoProc::GrDistanceFieldPathGeoProc(const GrShaderCaps& caps,
SkASSERT(numProxies <= kMaxTextures);
SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask));
fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
fInColor = {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
fInTextureCoords = {"inTextureCoords", kUShort2_GrVertexAttribType,
caps.integerSupport() ? kUShort2_GrSLType : kFloat2_GrSLType};
this->setVertexAttributeCnt(3);
this->setVertexAttributes(&fInPosition, 3);
if (numProxies) {
fAtlasSize = proxies[0]->isize();
@ -570,10 +569,6 @@ GrDistanceFieldPathGeoProc::createGLSLInstance(const GrShaderCaps&) const {
return new GrGLDistanceFieldPathGeoProc();
}
const GrPrimitiveProcessor::Attribute& GrDistanceFieldPathGeoProc::onVertexAttribute(int i) const {
return IthAttribute(i, kInPosition, kInColor, fInTextureCoords);
}
///////////////////////////////////////////////////////////////////////////////
GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldPathGeoProc);
@ -828,8 +823,6 @@ private:
///////////////////////////////////////////////////////////////////////////////
constexpr GrPrimitiveProcessor::Attribute GrDistanceFieldLCDTextGeoProc::kInColor;
GrDistanceFieldLCDTextGeoProc::GrDistanceFieldLCDTextGeoProc(const GrShaderCaps& caps,
const sk_sp<GrTextureProxy>* proxies,
int numProxies,
@ -849,9 +842,10 @@ GrDistanceFieldLCDTextGeoProc::GrDistanceFieldLCDTextGeoProc(const GrShaderCaps&
} else {
fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
}
fInColor = {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
fInTextureCoords = {"inTextureCoords", kUShort2_GrVertexAttribType,
caps.integerSupport() ? kUShort2_GrSLType : kFloat2_GrSLType};
this->setVertexAttributeCnt(3);
this->setVertexAttributes(&fInPosition, 3);
if (numProxies) {
fAtlasSize = proxies[0]->isize();
@ -894,11 +888,6 @@ GrGLSLPrimitiveProcessor* GrDistanceFieldLCDTextGeoProc::createGLSLInstance(cons
return new GrGLDistanceFieldLCDTextGeoProc();
}
const GrPrimitiveProcessor::Attribute& GrDistanceFieldLCDTextGeoProc::onVertexAttribute(
int i) const {
return IthAttribute(i, fInPosition, kInColor, fInTextureCoords);
}
///////////////////////////////////////////////////////////////////////////////
GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldLCDTextGeoProc);

View File

@ -81,7 +81,7 @@ public:
const char* name() const override { return "DistanceFieldA8Text"; }
const Attribute& inPosition() const { return fInPosition; }
const Attribute& inColor() const { return kInColor; }
const Attribute& inColor() const { return fInColor; }
const Attribute& inTextureCoords() const { return fInTextureCoords; }
const SkMatrix& localMatrix() const { return fLocalMatrix; }
#ifdef SK_GAMMA_APPLY_TO_A8
@ -106,25 +106,19 @@ private:
#endif
uint32_t flags, const SkMatrix& localMatrix);
const Attribute& onVertexAttribute(int i) const override {
return IthAttribute(i, fInPosition, kInColor, fInTextureCoords);
}
const TextureSampler& onTextureSampler(int i) const override { return fTextureSamplers[i]; }
TextureSampler fTextureSamplers[kMaxTextures];
SkISize fAtlasSize; // size for all textures used with fTextureSamplers[].
SkMatrix fLocalMatrix;
Attribute fInPosition;
Attribute fInColor;
Attribute fInTextureCoords;
uint32_t fFlags;
#ifdef SK_GAMMA_APPLY_TO_A8
float fDistanceAdjust;
#endif
static constexpr Attribute kInColor =
{"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
GR_DECLARE_GEOMETRY_PROCESSOR_TEST
typedef GrGeometryProcessor INHERITED;
@ -154,8 +148,8 @@ public:
const char* name() const override { return "DistanceFieldPath"; }
const Attribute& inPosition() const { return kInPosition; }
const Attribute& inColor() const { return kInColor; }
const Attribute& inPosition() const { return fInPosition; }
const Attribute& inColor() const { return fInColor; }
const Attribute& inTextureCoords() const { return fInTextureCoords; }
const SkMatrix& matrix() const { return fMatrix; }
uint32_t getFlags() const { return fFlags; }
@ -174,18 +168,15 @@ private:
int numActiveProxies,
const GrSamplerState&, uint32_t flags);
const Attribute& onVertexAttribute(int i) const override;
const TextureSampler& onTextureSampler(int i) const override { return fTextureSamplers[i]; }
SkMatrix fMatrix; // view matrix if perspective, local matrix otherwise
TextureSampler fTextureSamplers[kMaxTextures];
SkISize fAtlasSize; // size for all textures used with fTextureSamplers[].
Attribute fInPosition;
Attribute fInColor;
Attribute fInTextureCoords;
uint32_t fFlags;
static constexpr Attribute kInPosition =
{"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
static constexpr Attribute kInColor =
{"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
GR_DECLARE_GEOMETRY_PROCESSOR_TEST
@ -234,7 +225,7 @@ public:
const char* name() const override { return "DistanceFieldLCDText"; }
const Attribute& inPosition() const { return fInPosition; }
const Attribute& inColor() const { return kInColor; }
const Attribute& inColor() const { return fInColor; }
const Attribute& inTextureCoords() const { return fInTextureCoords; }
DistanceAdjust getDistanceAdjust() const { return fDistanceAdjust; }
uint32_t getFlags() const { return fFlags; }
@ -252,7 +243,6 @@ private:
int numActiveProxies, const GrSamplerState& params,
DistanceAdjust wa, uint32_t flags, const SkMatrix& localMatrix);
const Attribute& onVertexAttribute(int) const override;
const TextureSampler& onTextureSampler(int i) const override { return fTextureSamplers[i]; }
TextureSampler fTextureSamplers[kMaxTextures];
@ -260,12 +250,10 @@ private:
const SkMatrix fLocalMatrix;
DistanceAdjust fDistanceAdjust;
Attribute fInPosition;
Attribute fInColor;
Attribute fInTextureCoords;
uint32_t fFlags;
static constexpr Attribute kInColor =
{"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
GR_DECLARE_GEOMETRY_PROCESSOR_TEST
typedef GrGeometryProcessor INHERITED;

View File

@ -63,7 +63,10 @@ private:
///////////////////////////////////////////////////////////////////////////////
GrRRectShadowGeoProc::GrRRectShadowGeoProc() : INHERITED(kGrRRectShadowGeoProc_ClassID) {
this->setVertexAttributeCnt(3);
fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
fInColor = {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
fInShadowParams = {"inShadowParams", kFloat3_GrVertexAttribType, kHalf3_GrSLType};
this->setVertexAttributes(&fInPosition, 3);
}
GrGLSLPrimitiveProcessor* GrRRectShadowGeoProc::createGLSLInstance(const GrShaderCaps&) const {
@ -72,10 +75,6 @@ GrGLSLPrimitiveProcessor* GrRRectShadowGeoProc::createGLSLInstance(const GrShade
///////////////////////////////////////////////////////////////////////////////
constexpr GrPrimitiveProcessor::Attribute GrRRectShadowGeoProc::kInPosition;
constexpr GrPrimitiveProcessor::Attribute GrRRectShadowGeoProc::kInColor;
constexpr GrPrimitiveProcessor::Attribute GrRRectShadowGeoProc::kInShadowParams;
GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrRRectShadowGeoProc);
#if GR_TEST_UTILS

View File

@ -25,9 +25,9 @@ public:
const char* name() const override { return "RRectShadow"; }
const Attribute& inPosition() const { return kInPosition; }
const Attribute& inColor() const { return kInColor; }
const Attribute& inShadowParams() const { return kInShadowParams; }
const Attribute& inPosition() const { return fInPosition; }
const Attribute& inColor() const { return fInColor; }
const Attribute& inShadowParams() const { return fInShadowParams; }
GrColor color() const { return fColor; }
void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override {}
@ -37,18 +37,11 @@ public:
private:
GrRRectShadowGeoProc();
const Attribute& onVertexAttribute(int i) const override {
return IthAttribute(i, kInPosition, kInColor, kInShadowParams);
}
GrColor fColor;
static constexpr Attribute kInPosition =
{"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
static constexpr Attribute kInColor =
{"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
static constexpr Attribute kInShadowParams =
{"inShadowParams", kFloat3_GrVertexAttribType, kHalf3_GrSLType};
Attribute fInPosition;
Attribute fInColor;
Attribute fInShadowParams;
GR_DECLARE_GEOMETRY_PROCESSOR_TEST

View File

@ -147,17 +147,15 @@ void GrGLProgramBuilder::computeCountsAndStrides(GrGLuint programID,
};
fVertexStride = 0;
int i = 0;
for (; i < fVertexAttributeCnt; i++) {
addAttr(i, primProc.vertexAttribute(i), &fVertexStride);
SkASSERT(fAttributes[i].fOffset == primProc.debugOnly_vertexAttributeOffset(i));
for (const auto& attr : primProc.vertexAttributes()) {
addAttr(i++, attr, &fVertexStride);
}
SkASSERT(fVertexStride == primProc.debugOnly_vertexStride());
SkASSERT(fVertexStride == primProc.vertexStride());
fInstanceStride = 0;
for (int j = 0; j < fInstanceAttributeCnt; j++, ++i) {
addAttr(i, primProc.instanceAttribute(j), &fInstanceStride);
SkASSERT(fAttributes[i].fOffset == primProc.debugOnly_instanceAttributeOffset(j));
for (const auto& attr : primProc.instanceAttributes()) {
addAttr(i++, attr, &fInstanceStride);
}
SkASSERT(fInstanceStride == primProc.debugOnly_instanceStride());
SkASSERT(fInstanceStride == primProc.instanceStride());
}
void GrGLProgramBuilder::addInputVars(const SkSL::Program::Inputs& inputs) {

View File

@ -67,13 +67,11 @@ void GrGLSLVaryingHandler::addVarying(const char* name, GrGLSLVarying* varying,
}
void GrGLSLVaryingHandler::emitAttributes(const GrGeometryProcessor& gp) {
int vaCount = gp.numVertexAttributes();
for (int i = 0; i < vaCount; i++) {
this->addAttribute(gp.vertexAttribute(i).asShaderVar());
for (const auto& attr : gp.vertexAttributes()) {
this->addAttribute(attr.asShaderVar());
}
int iaCount = gp.numInstanceAttributes();
for (int i = 0; i < iaCount; i++) {
this->addAttribute(gp.instanceAttribute(i).asShaderVar());
for (const auto& attr : gp.instanceAttributes()) {
this->addAttribute(attr.asShaderVar());
}
}

View File

@ -161,18 +161,16 @@ static MTLVertexDescriptor* create_vertex_descriptor(const GrPrimitiveProcessor&
int vertexAttributeCount = primProc.numVertexAttributes();
size_t vertexAttributeOffset = 0;
for (int vertexIndex = 0; vertexIndex < vertexAttributeCount; vertexIndex++) {
const GrGeometryProcessor::Attribute& attribute = primProc.vertexAttribute(vertexIndex);
for (const auto& attribute : primProc.vertexAttributes()) {
MTLVertexAttributeDescriptor* mtlAttribute = vertexDescriptor.attributes[attributeIndex];
mtlAttribute.format = attribute_type_to_mtlformat(attribute.cpuType());
mtlAttribute.offset = vertexAttributeOffset;
mtlAttribute.bufferIndex = vertexBinding;
SkASSERT(mtlAttribute.offset == primProc.debugOnly_vertexAttributeOffset(vertexIndex));
vertexAttributeOffset += attribute.sizeAlign4();
attributeIndex++;
}
SkASSERT(vertexAttributeOffset == primProc.debugOnly_vertexStride());
SkASSERT(vertexAttributeOffset == primProc.vertexStride());
if (vertexAttributeCount) {
MTLVertexBufferLayoutDescriptor* vertexBufferLayout =
@ -184,18 +182,16 @@ static MTLVertexDescriptor* create_vertex_descriptor(const GrPrimitiveProcessor&
int instanceAttributeCount = primProc.numInstanceAttributes();
size_t instanceAttributeOffset = 0;
for (int instanceIndex = 0; instanceIndex < instanceAttributeCount; instanceIndex++) {
const GrGeometryProcessor::Attribute& attribute = primProc.instanceAttribute(instanceIndex);
for (const auto& attribute : primProc.instanceAttributes()) {
MTLVertexAttributeDescriptor* mtlAttribute = vertexDescriptor.attributes[attributeIndex];
mtlAttribute.format = attribute_type_to_mtlformat(attribute.cpuType());
mtlAttribute.offset = instanceAttributeOffset;
mtlAttribute.bufferIndex = instanceBinding;
SkASSERT(mtlAttribute.offset == primProc.debugOnly_instanceAttributeOffset(instanceIndex));
instanceAttributeOffset += attribute.sizeAlign4();
attributeIndex++;
}
SkASSERT(instanceAttributeOffset == primProc.debugOnly_instanceStride());
SkASSERT(instanceAttributeOffset == primProc.instanceStride());
if (instanceAttributeCount) {
MTLVertexBufferLayoutDescriptor* instanceBufferLayout =

View File

@ -577,21 +577,21 @@ public:
GrGLSLVarying v(kHalf4_GrSLType);
varyingHandler->addVarying("QuadEdge", &v);
vertBuilder->codeAppendf("%s = %s;", v.vsOut(), qe.kInQuadEdge.name());
vertBuilder->codeAppendf("%s = %s;", v.vsOut(), qe.fInQuadEdge.name());
// Setup pass through color
varyingHandler->addPassThroughAttribute(qe.kInColor, args.fOutputColor);
varyingHandler->addPassThroughAttribute(qe.fInColor, args.fOutputColor);
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
// Setup position
this->writeOutputPosition(vertBuilder, gpArgs, qe.kInPosition.name());
this->writeOutputPosition(vertBuilder, gpArgs, qe.fInPosition.name());
// emit transforms
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
qe.kInPosition.asShaderVar(),
qe.fInPosition.asShaderVar(),
qe.fLocalMatrix,
args.fFPCoordTransformHandler);
@ -647,18 +647,16 @@ private:
: INHERITED(kQuadEdgeEffect_ClassID)
, fLocalMatrix(localMatrix)
, fUsesLocalCoords(usesLocalCoords) {
this->setVertexAttributeCnt(3);
fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
fInColor = {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
fInQuadEdge = {"inQuadEdge", kFloat4_GrVertexAttribType, kHalf4_GrSLType};
this->setVertexAttributes(&fInPosition, 3);
}
const Attribute& onVertexAttribute(int i) const override {
return IthAttribute(i, kInPosition, kInColor, kInQuadEdge);
}
static constexpr Attribute kInPosition =
{"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
static constexpr Attribute kInColor =
{"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
static constexpr Attribute kInQuadEdge =
{"inQuadEdge", kFloat4_GrVertexAttribType, kHalf4_GrSLType};
Attribute fInPosition;
Attribute fInColor;
Attribute fInQuadEdge;
SkMatrix fLocalMatrix;
bool fUsesLocalCoords;
@ -666,9 +664,6 @@ private:
typedef GrGeometryProcessor INHERITED;
};
constexpr GrPrimitiveProcessor::Attribute QuadEdgeEffect::kInPosition;
constexpr GrPrimitiveProcessor::Attribute QuadEdgeEffect::kInColor;
constexpr GrPrimitiveProcessor::Attribute QuadEdgeEffect::kInQuadEdge;
GR_DEFINE_GEOMETRY_PROCESSOR_TEST(QuadEdgeEffect);
@ -799,11 +794,7 @@ private:
return;
}
size_t vertexStride = fHelper.compatibleWithAlphaAsCoverage()
? sizeof(GrDefaultGeoProcFactory::PositionColorAttr)
: sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr);
SkASSERT(vertexStride == gp->debugOnly_vertexStride());
size_t vertexStride = gp->vertexStride();
GrAAConvexTessellator tess;
int instanceCount = fPaths.count();
@ -904,7 +895,7 @@ private:
const GrBuffer* vertexBuffer;
int firstVertex;
SkASSERT(sizeof(QuadVertex) == quadProcessor->debugOnly_vertexStride());
SkASSERT(sizeof(QuadVertex) == quadProcessor->vertexStride());
QuadVertex* verts = reinterpret_cast<QuadVertex*>(target->makeVertexSpace(
sizeof(QuadVertex), vertexCount, &vertexBuffer, &firstVertex));

View File

@ -244,17 +244,14 @@ private:
void onPrepareDraws(Target* target) override {
using namespace GrDefaultGeoProcFactory;
size_t vertexStride = sizeof(SkPoint) + sizeof(GrColor);
Color color(Color::kPremulGrColorAttribute_Type);
Coverage::Type coverageType = Coverage::kSolid_Type;
if (!fHelper.compatibleWithAlphaAsCoverage()) {
coverageType = Coverage::kAttribute_Type;
vertexStride += sizeof(float);
}
LocalCoords lc = LocalCoords::kUnused_Type;
if (fHelper.usesLocalCoords()) {
lc = LocalCoords::kHasExplicit_Type;
vertexStride += sizeof(SkPoint);
}
sk_sp<GrGeometryProcessor> gp =
@ -265,7 +262,7 @@ private:
return;
}
SkASSERT(vertexStride == gp->debugOnly_vertexStride());
size_t vertexStride = gp->vertexStride();
sk_sp<const GrBuffer> indexBuffer = get_index_buffer(target->resourceProvider());
PatternHelper helper(target, GrPrimitiveType::kTriangles, vertexStride, indexBuffer.get(),

View File

@ -976,7 +976,7 @@ void AAHairlineOp::onPrepareDraws(Target* target) {
const GrBuffer* vertexBuffer;
int firstVertex;
SkASSERT(sizeof(LineVertex) == lineGP->debugOnly_vertexStride());
SkASSERT(sizeof(LineVertex) == lineGP->vertexStride());
int vertexCount = kLineSegNumVertices * lineCount;
LineVertex* verts = reinterpret_cast<LineVertex*>(target->makeVertexSpace(
sizeof(LineVertex), vertexCount, &vertexBuffer, &firstVertex));
@ -1019,8 +1019,8 @@ void AAHairlineOp::onPrepareDraws(Target* target) {
sk_sp<const GrBuffer> quadsIndexBuffer = get_quads_index_buffer(target->resourceProvider());
SkASSERT(sizeof(BezierVertex) == quadGP->debugOnly_vertexStride());
SkASSERT(sizeof(BezierVertex) == conicGP->debugOnly_vertexStride());
SkASSERT(sizeof(BezierVertex) == quadGP->vertexStride());
SkASSERT(sizeof(BezierVertex) == conicGP->vertexStride());
int vertexCount = kQuadNumVertices * quadAndConicCount;
void* vertices = target->makeVertexSpace(sizeof(BezierVertex), vertexCount, &vertexBuffer,
&firstVertex);

View File

@ -247,11 +247,7 @@ private:
return;
}
size_t vertexStride = fHelper.compatibleWithAlphaAsCoverage()
? sizeof(GrDefaultGeoProcFactory::PositionColorAttr)
: sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr);
SkASSERT(vertexStride == gp->debugOnly_vertexStride());
size_t vertexStride = gp->vertexStride();
int instanceCount = fPaths.count();
int64_t vertexCount = 0;

View File

@ -274,11 +274,7 @@ void AAStrokeRectOp::onPrepareDraws(Target* target) {
return;
}
size_t vertexStride = fHelper.compatibleWithAlphaAsCoverage()
? sizeof(GrDefaultGeoProcFactory::PositionColorAttr)
: sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr);
SkASSERT(vertexStride == gp->debugOnly_vertexStride());
size_t vertexStride = gp->vertexStride();
int innerVertexNum = 4;
int outerVertexNum = this->miterStroke() ? 4 : 8;
int verticesPerInstance = (outerVertexNum + innerVertexNum) * 2;

View File

@ -326,8 +326,7 @@ void GrAtlasTextOp::onPrepareDraws(Target* target) {
}
flushInfo.fGlyphsToFlush = 0;
size_t vertexStride = GrTextBlob::GetVertexStride(maskFormat, vmPerspective);
SkASSERT(vertexStride == flushInfo.fGeometryProcessor->debugOnly_vertexStride());
size_t vertexStride = flushInfo.fGeometryProcessor->vertexStride();
int glyphCount = this->numGlyphs();
const GrBuffer* vertexBuffer;

View File

@ -627,14 +627,7 @@ private:
return;
}
size_t vertexStride;
if (fullDash) {
vertexStride =
SkPaint::kRound_Cap == fCap ? sizeof(DashCircleVertex) : sizeof(DashLineVertex);
} else {
vertexStride = sizeof(SkPoint);
}
SkASSERT(vertexStride == gp->debugOnly_vertexStride());
size_t vertexStride = gp->vertexStride();
QuadHelper helper(target, vertexStride, totalRectCount);
void* vertices = helper.vertices();
if (!vertices) {
@ -859,30 +852,20 @@ private:
DashingCircleEffect(const SkPMColor4f&, AAMode aaMode, const SkMatrix& localMatrix,
bool usesLocalCoords);
const Attribute& onVertexAttribute(int i) const override {
return IthAttribute(i, kInPosition, kInDashParams, kInCircleParams);
}
SkPMColor4f fColor;
SkMatrix fLocalMatrix;
bool fUsesLocalCoords;
AAMode fAAMode;
static constexpr Attribute kInPosition =
{"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
static constexpr Attribute kInDashParams =
{"inDashParams", kFloat3_GrVertexAttribType, kHalf3_GrSLType};
static constexpr Attribute kInCircleParams =
{"inCircleParams", kFloat2_GrVertexAttribType, kHalf2_GrSLType};
Attribute fInPosition;
Attribute fInDashParams;
Attribute fInCircleParams;
GR_DECLARE_GEOMETRY_PROCESSOR_TEST
friend class GLDashingCircleEffect;
typedef GrGeometryProcessor INHERITED;
};
constexpr GrPrimitiveProcessor::Attribute DashingCircleEffect::kInPosition;
constexpr GrPrimitiveProcessor::Attribute DashingCircleEffect::kInDashParams;
constexpr GrPrimitiveProcessor::Attribute DashingCircleEffect::kInCircleParams;
//////////////////////////////////////////////////////////////////////////////
@ -927,25 +910,25 @@ void GLDashingCircleEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
// XY are dashPos, Z is dashInterval
GrGLSLVarying dashParams(kHalf3_GrSLType);
varyingHandler->addVarying("DashParam", &dashParams);
vertBuilder->codeAppendf("%s = %s;", dashParams.vsOut(), dce.kInDashParams.name());
vertBuilder->codeAppendf("%s = %s;", dashParams.vsOut(), dce.fInDashParams.name());
// x refers to circle radius - 0.5, y refers to cicle's center x coord
GrGLSLVarying circleParams(kHalf2_GrSLType);
varyingHandler->addVarying("CircleParams", &circleParams);
vertBuilder->codeAppendf("%s = %s;", circleParams.vsOut(), dce.kInCircleParams.name());
vertBuilder->codeAppendf("%s = %s;", circleParams.vsOut(), dce.fInCircleParams.name());
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
// Setup pass through color
this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor, &fColorUniform);
// Setup position
this->writeOutputPosition(vertBuilder, gpArgs, dce.kInPosition.name());
this->writeOutputPosition(vertBuilder, gpArgs, dce.fInPosition.name());
// emit transforms
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
dce.kInPosition.asShaderVar(),
dce.fInPosition.asShaderVar(),
dce.localMatrix(),
args.fFPCoordTransformHandler);
@ -1016,7 +999,10 @@ DashingCircleEffect::DashingCircleEffect(const SkPMColor4f& color,
, fLocalMatrix(localMatrix)
, fUsesLocalCoords(usesLocalCoords)
, fAAMode(aaMode) {
this->setVertexAttributeCnt(3);
fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
fInDashParams = {"inDashParams", kFloat3_GrVertexAttribType, kHalf3_GrSLType};
fInCircleParams = {"inCircleParams", kFloat2_GrVertexAttribType, kHalf2_GrSLType};
this->setVertexAttributes(&fInPosition, 3);
}
GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingCircleEffect);
@ -1070,21 +1056,14 @@ private:
DashingLineEffect(const SkPMColor4f&, AAMode aaMode, const SkMatrix& localMatrix,
bool usesLocalCoords);
const Attribute& onVertexAttribute(int i) const override {
return IthAttribute(i, kInPosition, kInDashParams, kInRectParams);
}
SkPMColor4f fColor;
SkMatrix fLocalMatrix;
bool fUsesLocalCoords;
AAMode fAAMode;
static constexpr Attribute kInPosition =
{"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
static constexpr Attribute kInDashParams =
{"inDashParams", kFloat3_GrVertexAttribType, kHalf3_GrSLType};
static constexpr Attribute kInRectParams =
{"inRect", kFloat4_GrVertexAttribType, kHalf4_GrSLType};
Attribute fInPosition;
Attribute fInDashParams;
Attribute fInRect;
GR_DECLARE_GEOMETRY_PROCESSOR_TEST
@ -1092,9 +1071,6 @@ private:
typedef GrGeometryProcessor INHERITED;
};
constexpr GrPrimitiveProcessor::Attribute DashingLineEffect::kInPosition;
constexpr GrPrimitiveProcessor::Attribute DashingLineEffect::kInDashParams;
constexpr GrPrimitiveProcessor::Attribute DashingLineEffect::kInRectParams;
//////////////////////////////////////////////////////////////////////////////
@ -1132,26 +1108,26 @@ void GLDashingLineEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
// XY refers to dashPos, Z is the dash interval length
GrGLSLVarying inDashParams(kFloat3_GrSLType);
varyingHandler->addVarying("DashParams", &inDashParams);
vertBuilder->codeAppendf("%s = %s;", inDashParams.vsOut(), de.kInDashParams.name());
vertBuilder->codeAppendf("%s = %s;", inDashParams.vsOut(), de.fInDashParams.name());
// The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bottom - 0.5),
// respectively.
GrGLSLVarying inRectParams(kFloat4_GrSLType);
varyingHandler->addVarying("RectParams", &inRectParams);
vertBuilder->codeAppendf("%s = %s;", inRectParams.vsOut(), de.kInRectParams.name());
vertBuilder->codeAppendf("%s = %s;", inRectParams.vsOut(), de.fInRect.name());
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
// Setup pass through color
this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor, &fColorUniform);
// Setup position
this->writeOutputPosition(vertBuilder, gpArgs, de.kInPosition.name());
this->writeOutputPosition(vertBuilder, gpArgs, de.fInPosition.name());
// emit transforms
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
de.kInPosition.asShaderVar(),
de.fInPosition.asShaderVar(),
de.localMatrix(),
args.fFPCoordTransformHandler);
@ -1240,7 +1216,10 @@ DashingLineEffect::DashingLineEffect(const SkPMColor4f& color,
, fLocalMatrix(localMatrix)
, fUsesLocalCoords(usesLocalCoords)
, fAAMode(aaMode) {
this->setVertexAttributeCnt(3);
fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
fInDashParams = {"inDashParams", kFloat3_GrVertexAttribType, kHalf3_GrSLType};
fInRect = {"inRect", kFloat4_GrVertexAttribType, kHalf4_GrSLType};
this->setVertexAttributes(&fInPosition, 3);
}
GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingLineEffect);

View File

@ -415,7 +415,7 @@ private:
this->viewMatrix());
}
SkASSERT(gp->debugOnly_vertexStride() == sizeof(SkPoint));
SkASSERT(gp->vertexStride() == sizeof(SkPoint));
int instanceCount = fPaths.count();

View File

@ -130,9 +130,7 @@ void GrDrawAtlasOp::onPrepareDraws(Target* target) {
this->viewMatrix()));
int instanceCount = fGeoData.count();
size_t vertexStride =
sizeof(SkPoint) + sizeof(SkPoint) + (this->hasColors() ? sizeof(GrColor) : 0);
SkASSERT(vertexStride == gp->debugOnly_vertexStride());
size_t vertexStride = gp->vertexStride();
int numQuads = this->quadCount();
QuadHelper helper(target, vertexStride, numQuads);

View File

@ -226,14 +226,8 @@ void GrDrawVerticesOp::drawVolatile(Target* target) {
&hasLocalCoordsAttribute,
&hasBoneAttribute);
// Calculate the stride.
size_t vertexStride = sizeof(SkPoint) +
(hasColorAttribute ? sizeof(uint32_t) : 0) +
(hasLocalCoordsAttribute ? sizeof(SkPoint) : 0) +
(hasBoneAttribute ? 4 * (sizeof(int8_t) + sizeof(uint8_t)) : 0);
SkASSERT(vertexStride == gp->debugOnly_vertexStride());
// Allocate buffers.
size_t vertexStride = gp->vertexStride();
const GrBuffer* vertexBuffer = nullptr;
int firstVertex = 0;
void* verts = target->makeVertexSpace(vertexStride, fVertexCount, &vertexBuffer, &firstVertex);
@ -303,14 +297,8 @@ void GrDrawVerticesOp::drawNonVolatile(Target* target) {
return;
}
// Calculate the stride.
size_t vertexStride = sizeof(SkPoint) +
(hasColorAttribute ? sizeof(uint32_t) : 0) +
(hasLocalCoordsAttribute ? sizeof(SkPoint) : 0) +
(hasBoneAttribute ? 4 * (sizeof(int8_t) + sizeof(uint8_t)) : 0);
SkASSERT(vertexStride == gp->debugOnly_vertexStride());
// Allocate vertex buffer.
size_t vertexStride = gp->vertexStride();
vertexBuffer.reset(rp->createBuffer(fVertexCount * vertexStride,
kVertex_GrBufferType,
kStatic_GrAccessPattern,

View File

@ -62,19 +62,20 @@ public:
latticeGP.fColorSpaceXform.get());
args.fVaryingHandler->emitAttributes(latticeGP);
this->writeOutputPosition(args.fVertBuilder, gpArgs, latticeGP.kPositions.name());
this->writeOutputPosition(args.fVertBuilder, gpArgs, latticeGP.fInPosition.name());
this->emitTransforms(args.fVertBuilder,
args.fVaryingHandler,
args.fUniformHandler,
latticeGP.kTextureCoords.asShaderVar(),
latticeGP.fInTextureCoords.asShaderVar(),
args.fFPCoordTransformHandler);
args.fFragBuilder->codeAppend("float2 textureCoords;");
args.fVaryingHandler->addPassThroughAttribute(latticeGP.kTextureCoords,
args.fVaryingHandler->addPassThroughAttribute(latticeGP.fInTextureCoords,
"textureCoords");
args.fFragBuilder->codeAppend("float4 textureDomain;");
args.fVaryingHandler->addPassThroughAttribute(
latticeGP.kTextureDomain, "textureDomain", Interpolation::kCanBeFlat);
args.fVaryingHandler->addPassThroughAttribute(latticeGP.kColors, args.fOutputColor,
latticeGP.fInTextureDomain, "textureDomain", Interpolation::kCanBeFlat);
args.fVaryingHandler->addPassThroughAttribute(latticeGP.fInColor,
args.fOutputColor,
Interpolation::kCanBeFlat);
args.fFragBuilder->codeAppendf("%s = ", args.fOutputColor);
args.fFragBuilder->appendTextureLookupAndModulate(
@ -97,23 +98,19 @@ private:
: INHERITED(kLatticeGP_ClassID), fColorSpaceXform(std::move(csxf)) {
fSampler.reset(proxy->textureType(), proxy->config(), filter);
this->setTextureSamplerCnt(1);
this->setVertexAttributeCnt(4);
}
const Attribute& onVertexAttribute(int i) const override {
return IthAttribute(i, kPositions, kTextureCoords, kTextureDomain, kColors);
fInPosition = {"position", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
fInTextureCoords = {"textureCoords", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
fInTextureDomain = {"textureDomain", kFloat4_GrVertexAttribType, kFloat4_GrSLType};
fInColor = {"color", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
this->setVertexAttributes(&fInPosition, 4);
}
const TextureSampler& onTextureSampler(int) const override { return fSampler; }
static constexpr Attribute kPositions =
{"position", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
static constexpr Attribute kTextureCoords =
{"textureCoords", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
static constexpr Attribute kTextureDomain =
{"textureDomain", kFloat4_GrVertexAttribType, kFloat4_GrSLType};
static constexpr Attribute kColors =
{"color", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
Attribute fInPosition;
Attribute fInTextureCoords;
Attribute fInTextureDomain;
Attribute fInColor;
sk_sp<GrColorSpaceXform> fColorSpaceXform;
TextureSampler fSampler;
@ -121,11 +118,6 @@ private:
typedef GrGeometryProcessor INHERITED;
};
constexpr GrPrimitiveProcessor::Attribute LatticeGP::kPositions;
constexpr GrPrimitiveProcessor::Attribute LatticeGP::kTextureCoords;
constexpr GrPrimitiveProcessor::Attribute LatticeGP::kTextureDomain;
constexpr GrPrimitiveProcessor::Attribute LatticeGP::kColors;
class NonAALatticeOp final : public GrMeshDrawOp {
private:
using Helper = GrSimpleMeshDrawOpHelper;
@ -214,9 +206,7 @@ private:
return;
}
static constexpr size_t kVertexStide =
sizeof(SkPoint) + sizeof(SkPoint) + sizeof(SkRect) + sizeof(uint32_t);
SkASSERT(kVertexStide == gp->debugOnly_vertexStride());
size_t kVertexStride = gp->vertexStride();
int patchCnt = fPatches.count();
int numRects = 0;
@ -229,7 +219,7 @@ private:
}
sk_sp<const GrBuffer> indexBuffer = target->resourceProvider()->refQuadIndexBuffer();
PatternHelper helper(target, GrPrimitiveType::kTriangles, kVertexStide, indexBuffer.get(),
PatternHelper helper(target, GrPrimitiveType::kTriangles, kVertexStride, indexBuffer.get(),
kVertsPerRect, kIndicesPerRect, numRects);
void* vertices = helper.vertices();
if (!vertices || !indexBuffer) {
@ -260,7 +250,7 @@ private:
static const Sk4f kFlipMuls(1.f, -1.f, 1.f, -1.f);
while (patch.fIter->next(&srcR, &dstR)) {
auto vertices = reinterpret_cast<LatticeGP::Vertex*>(verts);
SkPointPriv::SetRectTriStrip(&vertices->fPosition, dstR, kVertexStide);
SkPointPriv::SetRectTriStrip(&vertices->fPosition, dstR, kVertexStride);
Sk4f coords(SkIntToScalar(srcR.fLeft), SkIntToScalar(srcR.fTop),
SkIntToScalar(srcR.fRight), SkIntToScalar(srcR.fBottom));
Sk4f domain = coords + kDomainOffsets;
@ -271,7 +261,7 @@ private:
domain = SkNx_shuffle<0, 3, 2, 1>(kFlipMuls * domain + kFlipOffsets);
}
SkPointPriv::SetRectTriStrip(&vertices->fTextureCoords, coords[0], coords[1],
coords[2], coords[3], kVertexStide);
coords[2], coords[3], kVertexStride);
for (int j = 0; j < kVertsPerRect; ++j) {
vertices[j].fTextureDomain = {domain[0], domain[1], domain[2], domain[3]};
}
@ -279,13 +269,13 @@ private:
for (int j = 0; j < kVertsPerRect; ++j) {
vertices[j].fColor = patchColor;
}
verts += kVertsPerRect * kVertexStide;
verts += kVertsPerRect * kVertexStride;
}
// If we didn't handle it above, apply the matrix here.
if (!isScaleTranslate) {
SkPoint* positions = reinterpret_cast<SkPoint*>(patchVerts);
SkMatrixPriv::MapPointsWithStride(patch.fViewMatrix, positions, kVertexStide,
SkMatrixPriv::MapPointsWithStride(patch.fViewMatrix, positions, kVertexStride,
kVertsPerRect * patch.fIter->numRectsToDraw());
}
}

View File

@ -188,10 +188,7 @@ private:
return;
}
static constexpr size_t kVertexStride =
sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr);
SkASSERT(kVertexStride == gp->debugOnly_vertexStride());
size_t kVertexStride = gp->vertexStride();
int rectCount = fRects.count();
sk_sp<const GrBuffer> indexBuffer = target->resourceProvider()->refQuadIndexBuffer();
@ -322,11 +319,7 @@ private:
SkDebugf("Couldn't create GrGeometryProcessor\n");
return;
}
size_t vertexStride = fHasLocalRect
? sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr)
: sizeof(GrDefaultGeoProcFactory::PositionColorAttr);
SkASSERT(vertexStride == gp->debugOnly_vertexStride());
size_t vertexStride = gp->vertexStride();
int rectCount = fRects.count();
sk_sp<const GrBuffer> indexBuffer = target->resourceProvider()->refQuadIndexBuffer();

View File

@ -155,10 +155,7 @@ private:
fViewMatrix);
}
static constexpr size_t kVertexStride = sizeof(GrDefaultGeoProcFactory::PositionAttr);
SkASSERT(kVertexStride == gp->debugOnly_vertexStride());
size_t kVertexStride = gp->vertexStride();
int vertexCount = kVertsPerHairlineRect;
if (fStrokeWidth > 0) {
vertexCount = kVertsPerStrokeRect;

View File

@ -75,27 +75,26 @@ public:
: INHERITED(kCircleGeometryProcessor_ClassID)
, fLocalMatrix(localMatrix)
, fStroke(stroke) {
int cnt = 3;
fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
fInColor = {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
fInCircleEdge = {"inCircleEdge", kFloat4_GrVertexAttribType, kFloat4_GrSLType};
if (clipPlane) {
fInClipPlane = {"inClipPlane", kFloat3_GrVertexAttribType, kHalf3_GrSLType};
++cnt;
}
if (isectPlane) {
fInIsectPlane = {"inIsectPlane", kFloat3_GrVertexAttribType, kHalf3_GrSLType};
++cnt;
}
if (unionPlane) {
fInUnionPlane = {"inUnionPlane", kFloat3_GrVertexAttribType, kHalf3_GrSLType};
++cnt;
}
if (roundCaps) {
SkASSERT(stroke);
SkASSERT(clipPlane);
fInRoundCapCenters =
{"inRoundCapCenters", kFloat4_GrVertexAttribType, kFloat4_GrSLType};
++cnt;
}
this->setVertexAttributeCnt(cnt);
this->setVertexAttributes(&fInPosition, 7);
}
~CircleGeometryProcessor() override {}
@ -125,7 +124,7 @@ private:
// emit attributes
varyingHandler->emitAttributes(cgp);
fragBuilder->codeAppend("float4 circleEdge;");
varyingHandler->addPassThroughAttribute(cgp.kInCircleEdge, "circleEdge");
varyingHandler->addPassThroughAttribute(cgp.fInCircleEdge, "circleEdge");
if (cgp.fInClipPlane.isInitialized()) {
fragBuilder->codeAppend("half3 clipPlane;");
varyingHandler->addPassThroughAttribute(cgp.fInClipPlane, "clipPlane");
@ -148,20 +147,20 @@ private:
// This is the cap radius in normalized space where the outer radius is 1 and
// circledEdge.w is the normalized inner radius.
vertBuilder->codeAppendf("%s = (1.0 - %s.w) / 2.0;", capRadius.vsOut(),
cgp.kInCircleEdge.name());
cgp.fInCircleEdge.name());
}
// setup pass through color
varyingHandler->addPassThroughAttribute(cgp.kInColor, args.fOutputColor);
varyingHandler->addPassThroughAttribute(cgp.fInColor, args.fOutputColor);
// Setup position
this->writeOutputPosition(vertBuilder, gpArgs, cgp.kInPosition.name());
this->writeOutputPosition(vertBuilder, gpArgs, cgp.fInPosition.name());
// emit transforms
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
cgp.kInPosition.asShaderVar(),
cgp.fInPosition.asShaderVar(),
cgp.fLocalMatrix,
args.fFPCoordTransformHandler);
@ -231,20 +230,11 @@ private:
typedef GrGLSLGeometryProcessor INHERITED;
};
const Attribute& onVertexAttribute(int i) const override {
return IthInitializedAttribute(i, kInPosition, kInColor, kInCircleEdge, fInClipPlane,
fInIsectPlane, fInUnionPlane, fInRoundCapCenters);
}
SkMatrix fLocalMatrix;
static constexpr Attribute kInPosition =
{"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
static constexpr Attribute kInColor =
{"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
static constexpr Attribute kInCircleEdge =
{"inCircleEdge", kFloat4_GrVertexAttribType, kFloat4_GrSLType};
Attribute fInPosition;
Attribute fInColor;
Attribute fInCircleEdge;
// Optional attributes.
Attribute fInClipPlane;
Attribute fInIsectPlane;
@ -256,9 +246,6 @@ private:
typedef GrGeometryProcessor INHERITED;
};
constexpr GrPrimitiveProcessor::Attribute CircleGeometryProcessor::kInPosition;
constexpr GrPrimitiveProcessor::Attribute CircleGeometryProcessor::kInColor;
constexpr GrPrimitiveProcessor::Attribute CircleGeometryProcessor::kInCircleEdge;
GR_DEFINE_GEOMETRY_PROCESSOR_TEST(CircleGeometryProcessor);
@ -279,7 +266,11 @@ class ButtCapDashedCircleGeometryProcessor : public GrGeometryProcessor {
public:
ButtCapDashedCircleGeometryProcessor(const SkMatrix& localMatrix)
: INHERITED(kButtCapStrokedCircleGeometryProcessor_ClassID), fLocalMatrix(localMatrix) {
this->setVertexAttributeCnt(4);
fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
fInColor = {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
fInCircleEdge = {"inCircleEdge", kFloat4_GrVertexAttribType, kFloat4_GrSLType};
fInDashParams = {"inDashParams", kFloat4_GrVertexAttribType, kFloat4_GrSLType};
this->setVertexAttributes(&fInPosition, 4);
}
~ButtCapDashedCircleGeometryProcessor() override {}
@ -310,11 +301,11 @@ private:
// emit attributes
varyingHandler->emitAttributes(bcscgp);
fragBuilder->codeAppend("float4 circleEdge;");
varyingHandler->addPassThroughAttribute(bcscgp.kInCircleEdge, "circleEdge");
varyingHandler->addPassThroughAttribute(bcscgp.fInCircleEdge, "circleEdge");
fragBuilder->codeAppend("float4 dashParams;");
varyingHandler->addPassThroughAttribute(
bcscgp.kInDashParams, "dashParams",
bcscgp.fInDashParams, "dashParams",
GrGLSLVaryingHandler::Interpolation::kCanBeFlat);
GrGLSLVarying wrapDashes(kHalf4_GrSLType);
varyingHandler->addVarying("wrapDashes", &wrapDashes,
@ -322,7 +313,7 @@ private:
GrGLSLVarying lastIntervalLength(kHalf_GrSLType);
varyingHandler->addVarying("lastIntervalLength", &lastIntervalLength,
GrGLSLVaryingHandler::Interpolation::kCanBeFlat);
vertBuilder->codeAppendf("float4 dashParams = %s;", bcscgp.kInDashParams.name());
vertBuilder->codeAppendf("float4 dashParams = %s;", bcscgp.fInDashParams.name());
// Our fragment shader works in on/off intervals as specified by dashParams.xy:
// x = length of on interval, y = length of on + off.
// There are two other parameters in dashParams.zw:
@ -384,17 +375,17 @@ private:
// setup pass through color
varyingHandler->addPassThroughAttribute(
bcscgp.kInColor, args.fOutputColor,
bcscgp.fInColor, args.fOutputColor,
GrGLSLVaryingHandler::Interpolation::kCanBeFlat);
// Setup position
this->writeOutputPosition(vertBuilder, gpArgs, bcscgp.kInPosition.name());
this->writeOutputPosition(vertBuilder, gpArgs, bcscgp.fInPosition.name());
// emit transforms
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
bcscgp.kInPosition.asShaderVar(),
bcscgp.fInPosition.asShaderVar(),
bcscgp.fLocalMatrix,
args.fFPCoordTransformHandler);
GrShaderVar fnArgs[] = {
@ -488,28 +479,16 @@ private:
typedef GrGLSLGeometryProcessor INHERITED;
};
const Attribute& onVertexAttribute(int i) const override {
return IthAttribute(i, kInPosition, kInColor, kInCircleEdge, kInDashParams);
}
SkMatrix fLocalMatrix;
static constexpr Attribute kInPosition =
{"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
static constexpr Attribute kInColor =
{"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
static constexpr Attribute kInCircleEdge =
{"inCircleEdge", kFloat4_GrVertexAttribType, kFloat4_GrSLType};
static constexpr Attribute kInDashParams =
{"inDashParams", kFloat4_GrVertexAttribType, kFloat4_GrSLType};
Attribute fInPosition;
Attribute fInColor;
Attribute fInCircleEdge;
Attribute fInDashParams;
GR_DECLARE_GEOMETRY_PROCESSOR_TEST
typedef GrGeometryProcessor INHERITED;
};
constexpr GrPrimitiveProcessor::Attribute ButtCapDashedCircleGeometryProcessor::kInPosition;
constexpr GrPrimitiveProcessor::Attribute ButtCapDashedCircleGeometryProcessor::kInColor;
constexpr GrPrimitiveProcessor::Attribute ButtCapDashedCircleGeometryProcessor::kInCircleEdge;
constexpr GrPrimitiveProcessor::Attribute ButtCapDashedCircleGeometryProcessor::kInDashParams;
#if GR_TEST_UTILS
sk_sp<GrGeometryProcessor> ButtCapDashedCircleGeometryProcessor::TestCreate(GrProcessorTestData* d) {
@ -533,7 +512,11 @@ public:
EllipseGeometryProcessor(bool stroke, const SkMatrix& localMatrix)
: INHERITED(kEllipseGeometryProcessor_ClassID)
, fLocalMatrix(localMatrix) {
this->setVertexAttributeCnt(4);
fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
fInColor = {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
fInEllipseOffset = {"inEllipseOffset", kFloat2_GrVertexAttribType, kHalf2_GrSLType};
fInEllipseRadii = {"inEllipseRadii", kFloat4_GrVertexAttribType, kHalf4_GrSLType};
this->setVertexAttributes(&fInPosition, 4);
fStroke = stroke;
}
@ -566,24 +549,24 @@ private:
GrGLSLVarying ellipseOffsets(kHalf2_GrSLType);
varyingHandler->addVarying("EllipseOffsets", &ellipseOffsets);
vertBuilder->codeAppendf("%s = %s;", ellipseOffsets.vsOut(),
egp.kInEllipseOffset.name());
egp.fInEllipseOffset.name());
GrGLSLVarying ellipseRadii(kHalf4_GrSLType);
varyingHandler->addVarying("EllipseRadii", &ellipseRadii);
vertBuilder->codeAppendf("%s = %s;", ellipseRadii.vsOut(), egp.kInEllipseRadii.name());
vertBuilder->codeAppendf("%s = %s;", ellipseRadii.vsOut(), egp.fInEllipseRadii.name());
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
// setup pass through color
varyingHandler->addPassThroughAttribute(egp.kInColor, args.fOutputColor);
varyingHandler->addPassThroughAttribute(egp.fInColor, args.fOutputColor);
// Setup position
this->writeOutputPosition(vertBuilder, gpArgs, egp.kInPosition.name());
this->writeOutputPosition(vertBuilder, gpArgs, egp.fInPosition.name());
// emit transforms
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
egp.kInPosition.asShaderVar(),
egp.fInPosition.asShaderVar(),
egp.fLocalMatrix,
args.fFPCoordTransformHandler);
// For stroked ellipses, we use the full ellipse equation (x^2/a^2 + y^2/b^2 = 1)
@ -639,18 +622,10 @@ private:
typedef GrGLSLGeometryProcessor INHERITED;
};
const Attribute& onVertexAttribute(int i) const override {
return IthAttribute(i, kInPosition, kInColor, kInEllipseOffset, kInEllipseRadii);
}
static constexpr Attribute kInPosition =
{"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
static constexpr Attribute kInColor =
{"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
static constexpr Attribute kInEllipseOffset =
{"inEllipseOffset", kFloat2_GrVertexAttribType, kHalf2_GrSLType};
static constexpr Attribute kInEllipseRadii =
{"inEllipseRadii", kFloat4_GrVertexAttribType, kHalf4_GrSLType};
Attribute fInPosition;
Attribute fInColor;
Attribute fInEllipseOffset;
Attribute fInEllipseRadii;
SkMatrix fLocalMatrix;
bool fStroke;
@ -659,10 +634,6 @@ private:
typedef GrGeometryProcessor INHERITED;
};
constexpr GrPrimitiveProcessor::Attribute EllipseGeometryProcessor::kInPosition;
constexpr GrPrimitiveProcessor::Attribute EllipseGeometryProcessor::kInColor;
constexpr GrPrimitiveProcessor::Attribute EllipseGeometryProcessor::kInEllipseOffset;
constexpr GrPrimitiveProcessor::Attribute EllipseGeometryProcessor::kInEllipseRadii;
GR_DEFINE_GEOMETRY_PROCESSOR_TEST(EllipseGeometryProcessor);
@ -692,7 +663,11 @@ public:
: INHERITED(kDIEllipseGeometryProcessor_ClassID)
, fViewMatrix(viewMatrix) {
fStyle = style;
this->setVertexAttributeCnt(4);
fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
fInColor = {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
fInEllipseOffsets0 = {"inEllipseOffsets0", kFloat2_GrVertexAttribType, kHalf2_GrSLType};
fInEllipseOffsets1 = {"inEllipseOffsets1", kFloat2_GrVertexAttribType, kHalf2_GrSLType};
this->setVertexAttributes(&fInPosition, 4);
}
~DIEllipseGeometryProcessor() override {}
@ -723,20 +698,20 @@ private:
GrGLSLVarying offsets0(kHalf2_GrSLType);
varyingHandler->addVarying("EllipseOffsets0", &offsets0);
vertBuilder->codeAppendf("%s = %s;", offsets0.vsOut(), diegp.kInEllipseOffsets0.name());
vertBuilder->codeAppendf("%s = %s;", offsets0.vsOut(), diegp.fInEllipseOffsets0.name());
GrGLSLVarying offsets1(kHalf2_GrSLType);
varyingHandler->addVarying("EllipseOffsets1", &offsets1);
vertBuilder->codeAppendf("%s = %s;", offsets1.vsOut(), diegp.kInEllipseOffsets1.name());
vertBuilder->codeAppendf("%s = %s;", offsets1.vsOut(), diegp.fInEllipseOffsets1.name());
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
varyingHandler->addPassThroughAttribute(diegp.kInColor, args.fOutputColor);
varyingHandler->addPassThroughAttribute(diegp.fInColor, args.fOutputColor);
// Setup position
this->writeOutputPosition(vertBuilder,
uniformHandler,
gpArgs,
diegp.kInPosition.name(),
diegp.fInPosition.name(),
diegp.fViewMatrix,
&fViewMatrixUniform);
@ -744,7 +719,7 @@ private:
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
diegp.kInPosition.asShaderVar(),
diegp.fInPosition.asShaderVar(),
args.fFPCoordTransformHandler);
// for outer curve
@ -815,20 +790,11 @@ private:
typedef GrGLSLGeometryProcessor INHERITED;
};
const Attribute& onVertexAttribute(int i) const override {
return IthAttribute(i, kInPosition, kInColor, kInEllipseOffsets0, kInEllipseOffsets1);
}
static constexpr Attribute kInPosition =
{"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
static constexpr Attribute kInColor =
{"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
static constexpr Attribute kInEllipseOffsets0 = {"inEllipseOffsets0",
kFloat2_GrVertexAttribType,
kHalf2_GrSLType};
static constexpr Attribute kInEllipseOffsets1 = {"inEllipseOffsets1",
kFloat2_GrVertexAttribType,
kHalf2_GrSLType};
Attribute fInPosition;
Attribute fInColor;
Attribute fInEllipseOffsets0;
Attribute fInEllipseOffsets1;
SkMatrix fViewMatrix;
DIEllipseStyle fStyle;
@ -837,10 +803,6 @@ private:
typedef GrGeometryProcessor INHERITED;
};
constexpr GrPrimitiveProcessor::Attribute DIEllipseGeometryProcessor::kInPosition;
constexpr GrPrimitiveProcessor::Attribute DIEllipseGeometryProcessor::kInColor;
constexpr GrPrimitiveProcessor::Attribute DIEllipseGeometryProcessor::kInEllipseOffsets0;
constexpr GrPrimitiveProcessor::Attribute DIEllipseGeometryProcessor::kInEllipseOffsets1;
GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DIEllipseGeometryProcessor);
@ -1179,21 +1141,7 @@ private:
sk_sp<GrGeometryProcessor> gp(new CircleGeometryProcessor(
!fAllFill, fClipPlane, fClipPlaneIsect, fClipPlaneUnion, fRoundCaps, localMatrix));
struct CircleVertex {
SkPoint fPos;
GrColor fColor;
SkPoint fOffset;
SkScalar fOuterRadius;
SkScalar fInnerRadius;
// These planes may or may not be present in the vertex buffer.
SkScalar fHalfPlanes[3][3];
};
size_t vertexStride = sizeof(CircleVertex) - (fClipPlane ? 0 : 3 * sizeof(SkScalar)) -
(fClipPlaneIsect ? 0 : 3 * sizeof(SkScalar)) -
(fClipPlaneUnion ? 0 : 3 * sizeof(SkScalar)) +
(fRoundCaps ? 2 * sizeof(SkPoint) : 0);
SkASSERT(vertexStride == gp->debugOnly_vertexStride());
size_t vertexStride = gp->vertexStride();
const GrBuffer* vertexBuffer;
int firstVertex;
@ -1553,7 +1501,7 @@ private:
};
static constexpr size_t kVertexStride = sizeof(CircleVertex);
SkASSERT(kVertexStride == gp->debugOnly_vertexStride());
SkASSERT(kVertexStride == gp->vertexStride());
const GrBuffer* vertexBuffer;
int firstVertex;
@ -1858,7 +1806,7 @@ private:
// Setup geometry processor
sk_sp<GrGeometryProcessor> gp(new EllipseGeometryProcessor(fStroked, localMatrix));
SkASSERT(sizeof(EllipseVertex) == gp->debugOnly_vertexStride());
SkASSERT(sizeof(EllipseVertex) == gp->vertexStride());
QuadHelper helper(target, sizeof(EllipseVertex), fEllipses.count());
EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(helper.vertices());
if (!verts) {
@ -2093,7 +2041,7 @@ private:
sk_sp<GrGeometryProcessor> gp(
new DIEllipseGeometryProcessor(this->viewMatrix(), this->style()));
SkASSERT(sizeof(DIEllipseVertex) == gp->debugOnly_vertexStride());
SkASSERT(sizeof(DIEllipseVertex) == gp->vertexStride());
QuadHelper helper(target, sizeof(DIEllipseVertex), fEllipses.count());
DIEllipseVertex* verts = reinterpret_cast<DIEllipseVertex*>(helper.vertices());
if (!verts) {
@ -2510,7 +2458,7 @@ private:
sk_sp<GrGeometryProcessor> gp(
new CircleGeometryProcessor(!fAllFill, false, false, false, false, localMatrix));
SkASSERT(sizeof(CircleVertex) == gp->debugOnly_vertexStride());
SkASSERT(sizeof(CircleVertex) == gp->vertexStride());
const GrBuffer* vertexBuffer;
int firstVertex;
@ -2800,7 +2748,7 @@ private:
// Setup geometry processor
sk_sp<GrGeometryProcessor> gp(new EllipseGeometryProcessor(fStroked, localMatrix));
SkASSERT(sizeof(EllipseVertex) == gp->debugOnly_vertexStride());
SkASSERT(sizeof(EllipseVertex) == gp->vertexStride());
// drop out the middle quad if we're stroked
int indicesPerInstance = fStroked ? kIndicesPerStrokeRRect : kIndicesPerFillRRect;

View File

@ -412,12 +412,6 @@ bool GrQuadPerEdgeAA::GPAttributes::needsPerspectiveInterpolation() const {
return fPositions.cpuType() == kFloat3_GrVertexAttribType;
}
int GrQuadPerEdgeAA::GPAttributes::vertexAttributeCount() const {
// Always has position, hence 1+
return (1 + this->hasLocalCoords() + this->hasVertexColors() + this->hasDomain() +
4 * this->usesCoverageAA());
}
uint32_t GrQuadPerEdgeAA::GPAttributes::getKey() const {
// aa, color, domain are single bit flags
uint32_t x = this->usesCoverageAA() ? 0 : 1;

View File

@ -72,7 +72,7 @@ public:
// using the localCoords() attribute as the 4th argument; it must set the transform data helper
// to use the identity matrix; it must manage the color space transform for the quad's paint
// color; it should include getKey() in the geometry processor's key builder; and it should
// return these managed attributes from its onVertexAttribute() function.
// add these attributes at construction time.
class GPAttributes {
public:
using Attribute = GrPrimitiveProcessor::Attribute;
@ -95,7 +95,8 @@ public:
bool needsPerspectiveInterpolation() const;
int vertexAttributeCount() const;
const Attribute* attributes() const { return &fPositions; }
int attributeCount() const { return 8; }
uint32_t getKey() const;

View File

@ -119,8 +119,7 @@ private:
SkDebugf("Couldn't create GrGeometryProcessor\n");
return;
}
static constexpr size_t kVertexStride = sizeof(GrDefaultGeoProcFactory::PositionColorAttr);
SkASSERT(kVertexStride == gp->debugOnly_vertexStride());
size_t kVertexStride = gp->vertexStride();
int numRegions = fRegions.count();
int numRects = 0;

View File

@ -541,7 +541,7 @@ private:
sk_sp<GrGeometryProcessor> gp = GrRRectShadowGeoProc::Make();
int instanceCount = fGeoData.count();
SkASSERT(sizeof(CircleVertex) == gp->debugOnly_vertexStride());
SkASSERT(sizeof(CircleVertex) == gp->vertexStride());
const GrBuffer* vertexBuffer;
int firstVertex;

View File

@ -367,9 +367,7 @@ private:
}
// allocate vertices
static constexpr size_t kVertexStride =
sizeof(SkPoint) + sizeof(GrColor) + 2 * sizeof(uint16_t);
SkASSERT(kVertexStride == flushInfo.fGeometryProcessor->debugOnly_vertexStride());
size_t kVertexStride = flushInfo.fGeometryProcessor->vertexStride();
const GrBuffer* vertexBuffer;

View File

@ -316,12 +316,9 @@ private:
void onPrepareDraws(Target* target) override {
sk_sp<GrGeometryProcessor> gp;
size_t vertexStride;
{
using namespace GrDefaultGeoProcFactory;
vertexStride = sizeof(SkPoint); // position
Color color(fColor);
LocalCoords::Type localCoordsType = fHelper.usesLocalCoords()
? LocalCoords::kUsePosition_Type
@ -329,12 +326,10 @@ private:
Coverage::Type coverageType;
if (fAntiAlias) {
color = Color(Color::kPremulGrColorAttribute_Type);
vertexStride += sizeof(uint32_t);
if (fHelper.compatibleWithAlphaAsCoverage()) {
coverageType = Coverage::kSolid_Type;
} else {
coverageType = Coverage::kAttribute_Type;
vertexStride += 4;
}
} else {
coverageType = Coverage::kSolid_Type;
@ -352,7 +347,7 @@ private:
if (!gp.get()) {
return;
}
SkASSERT(vertexStride == gp->debugOnly_vertexStride());
size_t vertexStride = gp->vertexStride();
if (fAntiAlias) {
this->drawAA(target, std::move(gp), vertexStride);
} else {

View File

@ -125,13 +125,7 @@ private:
, fPaintColorSpaceXform(std::move(paintColorSpaceXform))
, fSampler(textureType, textureConfig, filter) {
this->setTextureSamplerCnt(1);
this->setVertexAttributeCnt(fAttrs.vertexAttributeCount());
}
const Attribute& onVertexAttribute(int i) const override {
return IthInitializedAttribute(i, fAttrs.positions(), fAttrs.colors(), fAttrs.localCoords(),
fAttrs.domain(), fAttrs.edges(0), fAttrs.edges(1),
fAttrs.edges(2), fAttrs.edges(3));
this->setVertexAttributes(fAttrs.attributes(), fAttrs.attributeCount());
}
const TextureSampler& onTextureSampler(int) const override { return fSampler; }
@ -412,7 +406,7 @@ private:
int cnt) const {
TRACE_EVENT0("skia", TRACE_FUNC);
using Vertex = GrQuadPerEdgeAA::Vertex<PosDim, GrColor, 2, D, AA>;
SkASSERT(gp->debugOnly_vertexStride() == sizeof(Vertex));
SkASSERT(gp->vertexStride() == sizeof(Vertex));
auto vertices = static_cast<Vertex*>(v);
auto origin = proxy->origin();
const auto* texture = proxy->peekTexture();
@ -512,7 +506,7 @@ private:
tessFnIdx |= hasPerspective ? 0x4 : 0x0;
size_t vertexSize = kTessFnsAndVertexSizes[tessFnIdx].fVertexSize;
SkASSERT(vertexSize == gp->debugOnly_vertexStride());
SkASSERT(vertexSize == gp->vertexStride());
GrMesh* meshes = target->allocMeshes(numProxies);
const GrBuffer* vbuffer;

View File

@ -94,31 +94,27 @@ static void setup_vertex_input_state(const GrPrimitiveProcessor& primProc,
int vaCount = primProc.numVertexAttributes();
int attribIndex = 0;
size_t vertexAttributeOffset = 0;
for (; attribIndex < vaCount; attribIndex++) {
const GrGeometryProcessor::Attribute& attrib = primProc.vertexAttribute(attribIndex);
for (const auto& attrib : primProc.vertexAttributes()) {
VkVertexInputAttributeDescription& vkAttrib = attributeDesc[attribIndex];
vkAttrib.location = attribIndex; // for now assume location = attribIndex
vkAttrib.location = attribIndex++; // for now assume location = attribIndex
vkAttrib.binding = vertexBinding;
vkAttrib.format = attrib_type_to_vkformat(attrib.cpuType());
vkAttrib.offset = vertexAttributeOffset;
SkASSERT(vkAttrib.offset == primProc.debugOnly_vertexAttributeOffset(attribIndex));
vertexAttributeOffset += attrib.sizeAlign4();
}
SkASSERT(vertexAttributeOffset == primProc.debugOnly_vertexStride());
SkASSERT(vertexAttributeOffset == primProc.vertexStride());
int iaCount = primProc.numInstanceAttributes();
size_t instanceAttributeOffset = 0;
for (int iaIndex = 0; iaIndex < iaCount; ++iaIndex, ++attribIndex) {
const GrGeometryProcessor::Attribute& attrib = primProc.instanceAttribute(iaIndex);
for (const auto& attrib : primProc.instanceAttributes()) {
VkVertexInputAttributeDescription& vkAttrib = attributeDesc[attribIndex];
vkAttrib.location = attribIndex; // for now assume location = attribIndex
vkAttrib.location = attribIndex++; // for now assume location = attribIndex
vkAttrib.binding = instanceBinding;
vkAttrib.format = attrib_type_to_vkformat(attrib.cpuType());
vkAttrib.offset = instanceAttributeOffset;
SkASSERT(vkAttrib.offset == primProc.debugOnly_instanceAttributeOffset(iaIndex));
instanceAttributeOffset += attrib.sizeAlign4();
}
SkASSERT(instanceAttributeOffset == primProc.debugOnly_instanceStride());
SkASSERT(instanceAttributeOffset == primProc.instanceStride());
if (primProc.hasVertexAttributes()) {
bindingDescs->push_back() = {

View File

@ -295,43 +295,38 @@ public:
: INHERITED(kGrMeshTestProcessor_ClassID) {
if (instanced) {
fInstanceLocation = {"location", kFloat2_GrVertexAttribType, kHalf2_GrSLType};
fColor = {"color", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
this->setInstanceAttributeCnt(2);
fInstanceColor = {"color", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
this->setInstanceAttributes(&fInstanceLocation, 2);
if (hasVertexBuffer) {
fVertex = {"vertex", kFloat2_GrVertexAttribType, kHalf2_GrSLType};
this->setVertexAttributeCnt(1);
fVertexPosition = {"vertex", kFloat2_GrVertexAttribType, kHalf2_GrSLType};
this->setVertexAttributes(&fVertexPosition, 1);
}
} else {
fVertex = {"vertex", kFloat2_GrVertexAttribType, kHalf2_GrSLType};
fColor = {"color", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
this->setVertexAttributeCnt(2);
fVertexPosition = {"vertex", kFloat2_GrVertexAttribType, kHalf2_GrSLType};
fVertexColor = {"color", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
this->setVertexAttributes(&fVertexPosition, 2);
}
}
const char* name() const override { return "GrMeshTest Processor"; }
const Attribute& inColor() const {
return fVertexColor.isInitialized() ? fVertexColor : fInstanceColor;
}
void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const final {
b->add32(fInstanceLocation.isInitialized());
b->add32(fVertex.isInitialized());
b->add32(fVertexPosition.isInitialized());
}
GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const final;
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 fVertexPosition;
Attribute fVertexColor;
Attribute fInstanceLocation;
Attribute fVertex;
Attribute fColor;
Attribute fInstanceColor;
friend class GLSLMeshTestProcessor;
typedef GrGeometryProcessor INHERITED;
@ -346,14 +341,14 @@ class GLSLMeshTestProcessor : public GrGLSLGeometryProcessor {
GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
varyingHandler->emitAttributes(mp);
varyingHandler->addPassThroughAttribute(mp.fColor, args.fOutputColor);
varyingHandler->addPassThroughAttribute(mp.inColor(), args.fOutputColor);
GrGLSLVertexBuilder* v = args.fVertBuilder;
if (!mp.fInstanceLocation.isInitialized()) {
v->codeAppendf("float2 vertex = %s;", mp.fVertex.name());
v->codeAppendf("float2 vertex = %s;", mp.fVertexPosition.name());
} else {
if (mp.fVertex.isInitialized()) {
v->codeAppendf("float2 offset = %s;", mp.fVertex.name());
if (mp.fVertexPosition.isInitialized()) {
v->codeAppendf("float2 offset = %s;", mp.fVertexPosition.name());
} else {
v->codeAppend ("float2 offset = float2(sk_VertexID / 2, sk_VertexID % 2);");
}

View File

@ -57,7 +57,7 @@ class GrPipelineDynamicStateTestProcessor : public GrGeometryProcessor {
public:
GrPipelineDynamicStateTestProcessor()
: INHERITED(kGrPipelineDynamicStateTestProcessor_ClassID) {
this->setVertexAttributeCnt(2);
this->setVertexAttributes(kAttributes, SK_ARRAY_COUNT(kAttributes));
}
const char* name() const override { return "GrPipelineDynamicStateTest Processor"; }
@ -66,21 +66,19 @@ public:
GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const final;
private:
const Attribute& onVertexAttribute(int i) const override {
return IthAttribute(i, kVertex, kColor);
}
const Attribute& inVertex() const { return kAttributes[0]; }
const Attribute& inColor() const { return kAttributes[1]; }
static constexpr Attribute kVertex =
{"vertex", kFloat2_GrVertexAttribType, kHalf2_GrSLType};
static constexpr Attribute kColor =
{"color", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
private:
static constexpr Attribute kAttributes[] = {
{"vertex", kFloat2_GrVertexAttribType, kHalf2_GrSLType},
{"color", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType},
};
friend class GLSLPipelineDynamicStateTestProcessor;
typedef GrGeometryProcessor INHERITED;
};
constexpr GrPrimitiveProcessor::Attribute GrPipelineDynamicStateTestProcessor::kVertex;
constexpr GrPrimitiveProcessor::Attribute GrPipelineDynamicStateTestProcessor::kColor;
constexpr GrPrimitiveProcessor::Attribute GrPipelineDynamicStateTestProcessor::kAttributes[];
class GLSLPipelineDynamicStateTestProcessor : public GrGLSLGeometryProcessor {
void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcessor&,
@ -92,10 +90,10 @@ class GLSLPipelineDynamicStateTestProcessor : public GrGLSLGeometryProcessor {
GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
varyingHandler->emitAttributes(mp);
varyingHandler->addPassThroughAttribute(mp.kColor, args.fOutputColor);
varyingHandler->addPassThroughAttribute(mp.inColor(), args.fOutputColor);
GrGLSLVertexBuilder* v = args.fVertBuilder;
v->codeAppendf("float2 vertex = %s;", mp.kVertex.name());
v->codeAppendf("float2 vertex = %s;", mp.inVertex().name());
gpArgs->fPositionVar.set(kFloat2_GrSLType, "vertex");
GrGLSLFPFragmentBuilder* f = args.fFragBuilder;

View File

@ -108,10 +108,7 @@ private:
return;
}
size_t vertexStride = fHasLocalRect
? sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr)
: sizeof(GrDefaultGeoProcFactory::PositionColorAttr);
SkASSERT(vertexStride == gp->debugOnly_vertexStride());
size_t vertexStride = gp->vertexStride();
const GrBuffer* indexBuffer;
int firstIndex;

View File

@ -65,7 +65,7 @@ private:
fAttributes[i] = {fAttribNames[i].c_str(), kFloat2_GrVertexAttribType,
kFloat2_GrSLType};
}
this->setVertexAttributeCnt(numAttribs);
this->setVertexAttributes(fAttributes.get(), numAttribs);
}
const char* name() const override { return "Dummy GP"; }
@ -93,10 +93,6 @@ private:
}
private:
const GrPrimitiveProcessor::Attribute& onVertexAttribute(int i) const override {
return fAttributes[i];
}
int fNumAttribs;
std::unique_ptr<SkString[]> fAttribNames;
std::unique_ptr<Attribute[]> fAttributes;
@ -104,8 +100,7 @@ private:
typedef GrGeometryProcessor INHERITED;
};
sk_sp<GrGeometryProcessor> gp(new GP(fNumAttribs));
size_t vertexStride = fNumAttribs * GrVertexAttribTypeSize(kFloat2_GrVertexAttribType);
SkASSERT(vertexStride == gp->debugOnly_vertexStride());
size_t vertexStride = gp->vertexStride();
QuadHelper helper(target, vertexStride, 1);
SkPoint* vertices = reinterpret_cast<SkPoint*>(helper.vertices());
SkPointPriv::SetRectTriStrip(vertices, 0.f, 0.f, 1.f, 1.f, vertexStride);