Add GrPrimitiveType::kLinesAdjacency

Converts GrPrimitiveType to an enum class and adds kLinesAdjacency.

Bug: skia:
Change-Id: If57d26277182aac1375e8181211ddaf7ea6d1e0a
Reviewed-on: https://skia-review.googlesource.com/19581
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
This commit is contained in:
Chris Dalton 2017-06-12 20:44:08 -06:00 committed by Skia Commit-Bot
parent e93cf97175
commit f7eb015083
31 changed files with 136 additions and 100 deletions

View File

@ -216,24 +216,27 @@ static inline GrAA GrBoolToAA(bool aa) { return aa ? GrAA::kYes : GrAA::kNo; }
/**
* Geometric primitives used for drawing.
*/
enum GrPrimitiveType {
kTriangles_GrPrimitiveType,
kTriangleStrip_GrPrimitiveType,
kTriangleFan_GrPrimitiveType,
kPoints_GrPrimitiveType,
kLines_GrPrimitiveType, // 1 pix wide only
kLineStrip_GrPrimitiveType, // 1 pix wide only
kLast_GrPrimitiveType = kLineStrip_GrPrimitiveType
enum class GrPrimitiveType {
kTriangles,
kTriangleStrip,
kTriangleFan,
kPoints,
kLines, // 1 pix wide only
kLineStrip, // 1 pix wide only
kLinesAdjacency // requires geometry shader support.
};
static constexpr int kNumGrPrimitiveTypes = (int) GrPrimitiveType::kLinesAdjacency + 1;
static inline bool GrIsPrimTypeLines(GrPrimitiveType type) {
return kLines_GrPrimitiveType == type || kLineStrip_GrPrimitiveType == type;
return GrPrimitiveType::kLines == type ||
GrPrimitiveType::kLineStrip == type ||
GrPrimitiveType::kLinesAdjacency == type;
}
static inline bool GrIsPrimTypeTris(GrPrimitiveType type) {
return kTriangles_GrPrimitiveType == type ||
kTriangleStrip_GrPrimitiveType == type ||
kTriangleFan_GrPrimitiveType == type;
return GrPrimitiveType::kTriangles == type ||
GrPrimitiveType::kTriangleStrip == type ||
GrPrimitiveType::kTriangleFan == type;
}
/**

View File

@ -45,6 +45,8 @@ bool GrGpuCommandBuffer::draw(const GrPipeline& pipeline,
#ifdef SK_DEBUG
SkASSERT(!primProc.hasInstanceAttribs() || this->gpu()->caps()->instanceAttribSupport());
for (int i = 0; i < meshCount; ++i) {
SkASSERT(GrPrimitiveType::kLinesAdjacency != meshes[i].primitiveType() ||
this->gpu()->caps()->shaderCaps()->geometryShaderSupport());
SkASSERT(primProc.hasVertexAttribs() == meshes[i].hasVertexData());
SkASSERT(primProc.hasInstanceAttribs() == meshes[i].isInstanced());
}

View File

@ -132,7 +132,7 @@ public:
* Returns an index buffer that can be used to render quads.
* Six indices per quad: 0, 1, 2, 0, 2, 3, etc.
* The max number of quads is the buffer's index capacity divided by 6.
* Draw with kTriangles_GrPrimitiveType
* Draw with GrPrimitiveType::kTriangles
* @ return the quad index buffer
*/
const GrBuffer* refQuadIndexBuffer() {

View File

@ -291,9 +291,9 @@ void SkGpuDevice::drawPaint(const SkPaint& paint) {
// must be in SkCanvas::PointMode order
static const GrPrimitiveType gPointMode2PrimitiveType[] = {
kPoints_GrPrimitiveType,
kLines_GrPrimitiveType,
kLineStrip_GrPrimitiveType
GrPrimitiveType::kPoints,
GrPrimitiveType::kLines,
GrPrimitiveType::kLineStrip
};
void SkGpuDevice::drawPoints(SkCanvas::PointMode mode,
@ -346,7 +346,7 @@ void SkGpuDevice::drawPoints(SkCanvas::PointMode mode,
// This offsetting in device space matches the expectations of the Android framework for non-AA
// points and lines.
SkMatrix tempMatrix;
if (GrIsPrimTypeLines(primitiveType) || kPoints_GrPrimitiveType == primitiveType) {
if (GrIsPrimTypeLines(primitiveType) || GrPrimitiveType::kPoints == primitiveType) {
tempMatrix = *viewMatrix;
static const SkScalar kOffset = 0.063f; // Just greater than 1/16.
tempMatrix.postTranslate(kOffset, kOffset);
@ -1597,7 +1597,7 @@ void SkGpuDevice::wireframeVertices(SkVertices::VertexMode vmode, int vertexCoun
i += 6;
}
GrPrimitiveType primitiveType = kLines_GrPrimitiveType;
GrPrimitiveType primitiveType = GrPrimitiveType::kLines;
fRenderTargetContext->drawVertices(this->clip(),
std::move(grPaint),
this->ctm(),

View File

@ -165,14 +165,14 @@ GrSamplerParams::FilterMode GrSkFilterQualityToGrFilterMode(SkFilterQuality pain
static inline GrPrimitiveType SkVertexModeToGrPrimitiveType(SkVertices::VertexMode mode) {
switch (mode) {
case SkVertices::kTriangles_VertexMode:
return kTriangles_GrPrimitiveType;
return GrPrimitiveType::kTriangles;
case SkVertices::kTriangleStrip_VertexMode:
return kTriangleStrip_GrPrimitiveType;
return GrPrimitiveType::kTriangleStrip;
case SkVertices::kTriangleFan_VertexMode:
return kTriangleFan_GrPrimitiveType;
return GrPrimitiveType::kTriangleFan;
}
SkFAIL("Invalid mode");
return kPoints_GrPrimitiveType;
return GrPrimitiveType::kPoints;
}
//////////////////////////////////////////////////////////////////////////////

View File

@ -1062,6 +1062,9 @@
#define GR_GL_SYNC_FLUSH_COMMANDS_BIT 0x00000001
#define GR_GL_TIMEOUT_IGNORED 0xFFFFFFFFFFFFFFFFull
/* GL_EXT_geometry_shader */
#define GR_GL_LINES_ADJACENCY 0x000A
/* EGL Defines */
#define GR_EGL_NO_DISPLAY ((GrEGLDisplay)0)
#define GR_EGL_EXTENSIONS 0x3055

View File

@ -2426,15 +2426,6 @@ void GrGLGpu::flushViewport(const GrGLIRect& viewport) {
}
}
GrGLenum gPrimitiveType2GLMode[] = {
GR_GL_TRIANGLES,
GR_GL_TRIANGLE_STRIP,
GR_GL_TRIANGLE_FAN,
GR_GL_POINTS,
GR_GL_LINES,
GR_GL_LINE_STRIP
};
#define SWAP_PER_DRAW 0
#if SWAP_PER_DRAW
@ -2466,7 +2457,7 @@ void GrGLGpu::draw(const GrPipeline& pipeline,
bool hasPoints = false;
for (int i = 0; i < meshCount; ++i) {
if (meshes[i].primitiveType() == kPoints_GrPrimitiveType) {
if (meshes[i].primitiveType() == GrPrimitiveType::kPoints) {
hasPoints = true;
break;
}
@ -2511,9 +2502,30 @@ void GrGLGpu::draw(const GrPipeline& pipeline,
#endif
}
static GrGLenum gr_primitive_type_to_gl_mode(GrPrimitiveType primitiveType) {
switch (primitiveType) {
case GrPrimitiveType::kTriangles:
return GR_GL_TRIANGLES;
case GrPrimitiveType::kTriangleStrip:
return GR_GL_TRIANGLE_STRIP;
case GrPrimitiveType::kTriangleFan:
return GR_GL_TRIANGLE_FAN;
case GrPrimitiveType::kPoints:
return GR_GL_POINTS;
case GrPrimitiveType::kLines:
return GR_GL_LINES;
case GrPrimitiveType::kLineStrip:
return GR_GL_LINE_STRIP;
case GrPrimitiveType::kLinesAdjacency:
return GR_GL_LINES_ADJACENCY;
}
SkFAIL("invalid GrPrimitiveType");
return GR_GL_TRIANGLES;
}
void GrGLGpu::sendMeshToGpu(const GrPrimitiveProcessor& primProc, GrPrimitiveType primitiveType,
const GrBuffer* vertexBuffer, int vertexCount, int baseVertex) {
const GrGLenum glPrimType = gPrimitiveType2GLMode[primitiveType];
const GrGLenum glPrimType = gr_primitive_type_to_gl_mode(primitiveType);
if (this->glCaps().drawArraysBaseVertexIsBroken()) {
this->setupGeometry(primProc, nullptr, vertexBuffer, baseVertex, nullptr, 0);
GL_CALL(DrawArrays(glPrimType, 0, vertexCount));
@ -2529,7 +2541,7 @@ void GrGLGpu::sendIndexedMeshToGpu(const GrPrimitiveProcessor& primProc,
int indexCount, int baseIndex, uint16_t minIndexValue,
uint16_t maxIndexValue, const GrBuffer* vertexBuffer,
int baseVertex) {
const GrGLenum glPrimType = gPrimitiveType2GLMode[primitiveType];
const GrGLenum glPrimType = gr_primitive_type_to_gl_mode(primitiveType);
GrGLvoid* const indices = reinterpret_cast<void*>(indexBuffer->baseOffset() +
sizeof(uint16_t) * baseIndex);
@ -2549,7 +2561,7 @@ void GrGLGpu::sendInstancedMeshToGpu(const GrPrimitiveProcessor& primProc, GrPri
int vertexCount, int baseVertex,
const GrBuffer* instanceBuffer, int instanceCount,
int baseInstance) {
const GrGLenum glPrimType = gPrimitiveType2GLMode[primitiveType];
const GrGLenum glPrimType = gr_primitive_type_to_gl_mode(primitiveType);
this->setupGeometry(primProc, nullptr, vertexBuffer, 0, instanceBuffer, baseInstance);
GL_CALL(DrawArraysInstanced(glPrimType, baseVertex, vertexCount, instanceCount));
fStats.incNumDraws();
@ -2561,7 +2573,7 @@ void GrGLGpu::sendIndexedInstancedMeshToGpu(const GrPrimitiveProcessor& primProc
int baseIndex, const GrBuffer* vertexBuffer,
int baseVertex, const GrBuffer* instanceBuffer,
int instanceCount, int baseInstance) {
const GrGLenum glPrimType = gPrimitiveType2GLMode[primitiveType];
const GrGLenum glPrimType = gr_primitive_type_to_gl_mode(primitiveType);
GrGLvoid* indices = reinterpret_cast<void*>(indexBuffer->baseOffset() +
sizeof(uint16_t) * baseIndex);
this->setupGeometry(primProc, indexBuffer, vertexBuffer, baseVertex,

View File

@ -812,7 +812,7 @@ private:
extract_verts(tess, verts, vertexStride, fColor, idxs, canTweakAlphaForCoverage);
GrMesh mesh(kTriangles_GrPrimitiveType);
GrMesh mesh(GrPrimitiveType::kTriangles);
mesh.setIndexed(indexBuffer, tess.numIndices(), firstIndex, 0, tess.numPts() - 1);
mesh.setVertexData(vertexBuffer, firstVertex);
target->draw(gp.get(), this->pipeline(), mesh);
@ -897,7 +897,7 @@ private:
SkSTArray<kPreallocDrawCnt, Draw, true> draws;
create_vertices(segments, fanPt, &draws, verts, idxs);
GrMesh mesh(kTriangles_GrPrimitiveType);
GrMesh mesh(GrPrimitiveType::kTriangles);
for (int j = 0; j < draws.count(); ++j) {
const Draw& draw = draws[j];

View File

@ -231,7 +231,7 @@ private:
size_t vertexStride = gp->getVertexStride();
sk_sp<const GrBuffer> indexBuffer(get_index_buffer(target->resourceProvider()));
PatternHelper helper(kTriangles_GrPrimitiveType);
PatternHelper helper(GrPrimitiveType::kTriangles);
void* vertices =
helper.init(target, vertexStride, indexBuffer.get(), kVertsPerAAFillRect,
kIndicesPerAAFillRect, fRectCnt);

View File

@ -860,7 +860,7 @@ void AAHairlineOp::onPrepareDraws(Target* target) const {
add_line(&lines[2*i], toSrc, this->coverage(), &verts);
}
GrMesh mesh(kTriangles_GrPrimitiveType);
GrMesh mesh(GrPrimitiveType::kTriangles);
mesh.setIndexedPatterned(linesIndexBuffer.get(), kIdxsPerLineSeg, kLineSegNumVertices,
lineCount, kLineSegsNumInIdxBuffer);
mesh.setVertexData(vertexBuffer, firstVertex);
@ -917,7 +917,7 @@ void AAHairlineOp::onPrepareDraws(Target* target) const {
}
if (quadCount > 0) {
GrMesh mesh(kTriangles_GrPrimitiveType);
GrMesh mesh(GrPrimitiveType::kTriangles);
mesh.setIndexedPatterned(quadsIndexBuffer.get(), kIdxsPerQuad, kQuadNumVertices,
quadCount, kQuadsNumInIdxBuffer);
mesh.setVertexData(vertexBuffer, firstVertex);
@ -926,7 +926,7 @@ void AAHairlineOp::onPrepareDraws(Target* target) const {
}
if (conicCount > 0) {
GrMesh mesh(kTriangles_GrPrimitiveType);
GrMesh mesh(GrPrimitiveType::kTriangles);
mesh.setIndexedPatterned(quadsIndexBuffer.get(), kIdxsPerQuad, kQuadNumVertices,
conicCount, kQuadsNumInIdxBuffer);
mesh.setVertexData(vertexBuffer, firstVertex);

View File

@ -190,7 +190,7 @@ private:
return;
}
const GrBuffer* vertexBuffer;
GrMesh mesh(kTriangles_GrPrimitiveType);
GrMesh mesh(GrPrimitiveType::kTriangles);
int firstVertex;
void* verts = target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer,
&firstVertex);

View File

@ -262,7 +262,7 @@ void AAStrokeRectOp::onPrepareDraws(Target* target) const {
const sk_sp<const GrBuffer> indexBuffer(
GetIndexBuffer(target->resourceProvider(), this->miterStroke()));
PatternHelper helper(kTriangles_GrPrimitiveType);
PatternHelper helper(GrPrimitiveType::kTriangles);
void* vertices =
helper.init(target, vertexStride, indexBuffer.get(),
verticesPerInstance, indicesPerInstance, instanceCount);

View File

@ -139,7 +139,7 @@ void GrAtlasTextOp::onPrepareDraws(Target* target) const {
}
void GrAtlasTextOp::flush(GrLegacyMeshDrawOp::Target* target, FlushInfo* flushInfo) const {
GrMesh mesh(kTriangles_GrPrimitiveType);
GrMesh mesh(GrPrimitiveType::kTriangles);
int maxGlyphsPerDraw =
static_cast<int>(flushInfo->fIndexBuffer->gpuMemorySize() / sizeof(uint16_t) / 6);
mesh.setIndexedPatterned(flushInfo->fIndexBuffer.get(), kIndicesPerGlyph, kVerticesPerGlyph,

View File

@ -184,16 +184,16 @@ private:
if (this->isHairline()) {
if (isIndexed) {
maxIndices = 2 * maxVertices;
primitiveType = kLines_GrPrimitiveType;
primitiveType = GrPrimitiveType::kLines;
} else {
primitiveType = kLineStrip_GrPrimitiveType;
primitiveType = GrPrimitiveType::kLineStrip;
}
} else {
if (isIndexed) {
maxIndices = 3 * maxVertices;
primitiveType = kTriangles_GrPrimitiveType;
primitiveType = GrPrimitiveType::kTriangles;
} else {
primitiveType = kTriangleFan_GrPrimitiveType;
primitiveType = GrPrimitiveType::kTriangleFan;
}
}

View File

@ -58,7 +58,7 @@ GrDrawVerticesOp::GrDrawVerticesOp(sk_sp<SkVertices> vertices, GrPrimitiveType p
}
IsZeroArea zeroArea;
if (GrIsPrimTypeLines(primitiveType) || kPoints_GrPrimitiveType == primitiveType) {
if (GrIsPrimTypeLines(primitiveType) || GrPrimitiveType::kPoints == primitiveType) {
zeroArea = IsZeroArea::kYes;
} else {
zeroArea = IsZeroArea::kNo;
@ -300,15 +300,17 @@ bool GrDrawVerticesOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) {
static uint32_t seed_vertices(GrPrimitiveType type) {
switch (type) {
case kTriangles_GrPrimitiveType:
case kTriangleStrip_GrPrimitiveType:
case kTriangleFan_GrPrimitiveType:
case GrPrimitiveType::kTriangles:
case GrPrimitiveType::kTriangleStrip:
case GrPrimitiveType::kTriangleFan:
return 3;
case kPoints_GrPrimitiveType:
case GrPrimitiveType::kPoints:
return 1;
case kLines_GrPrimitiveType:
case kLineStrip_GrPrimitiveType:
case GrPrimitiveType::kLines:
case GrPrimitiveType::kLineStrip:
return 2;
case GrPrimitiveType::kLinesAdjacency:
return 4;
}
SkFAIL("Incomplete switch\n");
return 0;
@ -316,15 +318,17 @@ static uint32_t seed_vertices(GrPrimitiveType type) {
static uint32_t primitive_vertices(GrPrimitiveType type) {
switch (type) {
case kTriangles_GrPrimitiveType:
case GrPrimitiveType::kTriangles:
return 3;
case kLines_GrPrimitiveType:
case GrPrimitiveType::kLines:
return 2;
case kTriangleStrip_GrPrimitiveType:
case kTriangleFan_GrPrimitiveType:
case kPoints_GrPrimitiveType:
case kLineStrip_GrPrimitiveType:
case GrPrimitiveType::kTriangleStrip:
case GrPrimitiveType::kTriangleFan:
case GrPrimitiveType::kPoints:
case GrPrimitiveType::kLineStrip:
return 1;
case GrPrimitiveType::kLinesAdjacency:
return 4;
}
SkFAIL("Incomplete switch\n");
return 0;
@ -358,7 +362,7 @@ static void randomize_params(size_t count, size_t maxVertex, SkScalar min, SkSca
}
GR_LEGACY_MESH_DRAW_OP_TEST_DEFINE(VerticesOp) {
GrPrimitiveType type = GrPrimitiveType(random->nextULessThan(kLast_GrPrimitiveType + 1));
GrPrimitiveType type = GrPrimitiveType(random->nextULessThan(kNumGrPrimitiveTypes));
uint32_t primitiveCount = random->nextRangeU(1, 100);
// TODO make 'sensible' indexbuffers

View File

@ -70,9 +70,9 @@ private:
GrPrimitiveType primitiveType() const { return fPrimitiveType; }
bool combinablePrimitive() const {
return kTriangles_GrPrimitiveType == fPrimitiveType ||
kLines_GrPrimitiveType == fPrimitiveType ||
kPoints_GrPrimitiveType == fPrimitiveType;
return GrPrimitiveType::kTriangles == fPrimitiveType ||
GrPrimitiveType::kLines == fPrimitiveType ||
GrPrimitiveType::kPoints == fPrimitiveType;
}
bool onCombineIfPossible(GrOp* t, const GrCaps&) override;

View File

@ -86,7 +86,7 @@ private:
}
sk_sp<const GrBuffer> indexBuffer(target->resourceProvider()->refQuadIndexBuffer());
PatternHelper helper(kTriangles_GrPrimitiveType);
PatternHelper helper(GrPrimitiveType::kTriangles);
void* vertices = helper.init(target, vertexStride, indexBuffer.get(), kVertsPerRect,
kIndicesPerRect, numRects);
if (!vertices || !indexBuffer) {

View File

@ -330,8 +330,8 @@ private:
return;
}
GrPrimitiveType primitiveType = fIsIndexed ? kTriangles_GrPrimitiveType
: kTriangleFan_GrPrimitiveType;
GrPrimitiveType primitiveType = fIsIndexed ? GrPrimitiveType::kTriangles
: GrPrimitiveType::kTriangleFan;
// allocate vertex / index buffers
const GrBuffer* lineVertexBuffer;
@ -437,7 +437,7 @@ private:
target->makeVertexSpace(quadVertexStride, quadVertexOffset, &quadVertexBuffer,
&firstQuadVertex);
memcpy(quadVertices, quads.vertices, quadVertexStride * quadVertexOffset);
GrMesh quadMeshes(kTriangles_GrPrimitiveType);
GrMesh quadMeshes(GrPrimitiveType::kTriangles);
if (!fIsIndexed) {
quadMeshes.setNonIndexedNonInstanced(quadVertexOffset);
} else {

View File

@ -52,7 +52,7 @@ protected:
/** A specialization of InstanceHelper for quad rendering. */
class QuadHelper : private PatternHelper {
public:
QuadHelper() : INHERITED(kTriangles_GrPrimitiveType) {}
QuadHelper() : INHERITED(GrPrimitiveType::kTriangles) {}
/** Finds the cached quad index buffer and reserves vertex space. Returns nullptr on failure
and on success a pointer to the vertex data that the caller should populate before
calling recordDraws(). */

View File

@ -175,7 +175,7 @@ private:
int rectCount = fRects.count();
sk_sp<const GrBuffer> indexBuffer(target->resourceProvider()->refQuadIndexBuffer());
PatternHelper helper(kTriangles_GrPrimitiveType);
PatternHelper helper(GrPrimitiveType::kTriangles);
void* vertices = helper.init(target, vertexStride, indexBuffer.get(), kVertsPerRect,
kIndicesPerRect, rectCount);
if (!vertices || !indexBuffer) {
@ -296,7 +296,7 @@ private:
int rectCount = fRects.count();
sk_sp<const GrBuffer> indexBuffer(target->resourceProvider()->refQuadIndexBuffer());
PatternHelper helper(kTriangles_GrPrimitiveType);
PatternHelper helper(GrPrimitiveType::kTriangles);
void* vertices = helper.init(target, vertexStride, indexBuffer.get(), kVertsPerRect,
kIndicesPerRect, rectCount);
if (!vertices || !indexBuffer) {

View File

@ -144,11 +144,11 @@ private:
GrPrimitiveType primType;
if (fStrokeWidth > 0) {
primType = kTriangleStrip_GrPrimitiveType;
primType = GrPrimitiveType::kTriangleStrip;
init_stroke_rect_strip(vertex, fRect, fStrokeWidth);
} else {
// hairline
primType = kLineStrip_GrPrimitiveType;
primType = GrPrimitiveType::kLineStrip;
vertex[0].set(fRect.fLeft, fRect.fTop);
vertex[1].set(fRect.fRight, fRect.fTop);
vertex[2].set(fRect.fRight, fRect.fBottom);

View File

@ -1082,7 +1082,7 @@ private:
vertices += circle_type_to_vert_count(circle.fStroked) * vertexStride;
}
GrMesh mesh(kTriangles_GrPrimitiveType);
GrMesh mesh(GrPrimitiveType::kTriangles);
mesh.setIndexed(indexBuffer, fIndexCount, firstIndex, 0, fVertCount - 1);
mesh.setVertexData(vertexBuffer, firstVertex);
target->draw(gp.get(), fHelper.makePipeline(target), mesh);
@ -1987,7 +1987,7 @@ private:
currStartVertex += rrect_type_to_vert_count(rrect.fType);
}
GrMesh mesh(kTriangles_GrPrimitiveType);
GrMesh mesh(GrPrimitiveType::kTriangles);
mesh.setIndexed(indexBuffer, fIndexCount, firstIndex, 0, fVertCount - 1);
mesh.setVertexData(vertexBuffer, firstVertex);
target->draw(gp.get(), fHelper.makePipeline(target), mesh);
@ -2177,7 +2177,7 @@ private:
sk_sp<const GrBuffer> indexBuffer(ref_rrect_index_buffer(
fStroked ? kStroke_RRectType : kFill_RRectType, target->resourceProvider()));
PatternHelper helper(kTriangles_GrPrimitiveType);
PatternHelper helper(GrPrimitiveType::kTriangles);
EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(
helper.init(target, vertexStride, indexBuffer.get(), kVertsPerStandardRRect,
indicesPerInstance, fRRects.count()));

View File

@ -103,7 +103,7 @@ private:
size_t vertexStride = gp->getVertexStride();
sk_sp<const GrBuffer> indexBuffer(target->resourceProvider()->refQuadIndexBuffer());
PatternHelper helper(kTriangles_GrPrimitiveType);
PatternHelper helper(GrPrimitiveType::kTriangles);
void* vertices =
helper.init(target, vertexStride, indexBuffer.get(), kVertsPerInstance,
kIndicesPerInstance, numRects);

View File

@ -628,7 +628,7 @@ private:
}
}
GrMesh mesh(kTriangles_GrPrimitiveType);
GrMesh mesh(GrPrimitiveType::kTriangles);
mesh.setIndexed(indexBuffer, fIndexCount, firstIndex, 0, fVertCount - 1);
mesh.setVertexData(vertexBuffer, firstVertex);
target->draw(gp.get(), this->pipeline(), mesh);

View File

@ -679,7 +679,7 @@ private:
void flush(GrLegacyMeshDrawOp::Target* target, FlushInfo* flushInfo) const {
if (flushInfo->fInstancesToFlush) {
GrMesh mesh(kTriangles_GrPrimitiveType);
GrMesh mesh(GrPrimitiveType::kTriangles);
int maxInstancesPerDraw =
static_cast<int>(flushInfo->fIndexBuffer->gpuMemorySize() / sizeof(uint16_t) / 6);
mesh.setIndexedPatterned(flushInfo->fIndexBuffer.get(), kIndicesPerQuad,

View File

@ -313,7 +313,7 @@ private:
void drawVertices(Target* target, const GrGeometryProcessor* gp, const GrBuffer* vb,
int firstVertex, int count) const {
GrMesh mesh(TESSELLATOR_WIREFRAME ? kLines_GrPrimitiveType : kTriangles_GrPrimitiveType);
GrMesh mesh(TESSELLATOR_WIREFRAME ? GrPrimitiveType::kLines : GrPrimitiveType::kTriangles);
mesh.setNonIndexedNonInstanced(count);
mesh.setVertexData(vb, firstVertex);
target->draw(gp, this->pipeline(), mesh);

View File

@ -94,24 +94,35 @@ static void setup_vertex_input_state(const GrPrimitiveProcessor& primProc,
vertexInputInfo->pVertexAttributeDescriptions = attributeDesc;
}
static VkPrimitiveTopology gr_primitive_type_to_vk_topology(GrPrimitiveType primitiveType) {
switch (primitiveType) {
case GrPrimitiveType::kTriangles:
return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
case GrPrimitiveType::kTriangleStrip:
return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
case GrPrimitiveType::kTriangleFan:
return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN;
case GrPrimitiveType::kPoints:
return VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
case GrPrimitiveType::kLines:
return VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
case GrPrimitiveType::kLineStrip:
return VK_PRIMITIVE_TOPOLOGY_LINE_STRIP;
case GrPrimitiveType::kLinesAdjacency:
return VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY;
}
SkFAIL("invalid GrPrimitiveType");
return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
}
static void setup_input_assembly_state(GrPrimitiveType primitiveType,
VkPipelineInputAssemblyStateCreateInfo* inputAssemblyInfo) {
static const VkPrimitiveTopology gPrimitiveType2VkTopology[] = {
VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,
VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN,
VK_PRIMITIVE_TOPOLOGY_POINT_LIST,
VK_PRIMITIVE_TOPOLOGY_LINE_LIST,
VK_PRIMITIVE_TOPOLOGY_LINE_STRIP
};
memset(inputAssemblyInfo, 0, sizeof(VkPipelineInputAssemblyStateCreateInfo));
inputAssemblyInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
inputAssemblyInfo->pNext = nullptr;
inputAssemblyInfo->flags = 0;
inputAssemblyInfo->primitiveRestartEnable = false;
inputAssemblyInfo->topology = gPrimitiveType2VkTopology[primitiveType];
inputAssemblyInfo->topology = gr_primitive_type_to_vk_topology(primitiveType);
}

View File

@ -570,7 +570,7 @@ bool GrVkPipelineState::Desc::Build(Desc* desc,
const GrStencilSettings& stencil,
GrPrimitiveType primitiveType,
const GrShaderCaps& caps) {
if (!INHERITED::Build(desc, primProc, primitiveType == kPoints_GrPrimitiveType, pipeline,
if (!INHERITED::Build(desc, primProc, primitiveType == GrPrimitiveType::kPoints, pipeline,
caps)) {
return false;
}
@ -583,7 +583,7 @@ bool GrVkPipelineState::Desc::Build(Desc* desc,
b.add32(get_blend_info_key(pipeline));
b.add32(primitiveType);
b.add32((uint32_t)primitiveType);
return true;
}

View File

@ -147,7 +147,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrMeshTest, reporter, ctxInfo) {
auto vbuff = helper->makeVertexBuffer(expandedVertexData);
VALIDATE(vbuff);
for (int y = 0; y < kBoxCountY; ++y) {
GrMesh mesh(kTriangles_GrPrimitiveType);
GrMesh mesh(GrPrimitiveType::kTriangles);
mesh.setNonIndexedNonInstanced(kBoxCountX * 6);
mesh.setVertexData(vbuff.get(), y * kBoxCountX * 6);
helper->drawMesh(mesh);
@ -167,7 +167,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrMeshTest, reporter, ctxInfo) {
GR_STATIC_ASSERT(kIndexPatternRepeatCount >= 3);
int repetitionCount = SkTMin(3 - baseRepetition, kBoxCount - i);
GrMesh mesh(kTriangles_GrPrimitiveType);
GrMesh mesh(GrPrimitiveType::kTriangles);
mesh.setIndexed(ibuff.get(), repetitionCount * 6, baseRepetition * 6,
baseRepetition * 4, (baseRepetition + repetitionCount) * 4 - 1);
mesh.setVertexData(vbuff.get(), (i - baseRepetition) * 4);
@ -187,7 +187,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrMeshTest, reporter, ctxInfo) {
// Draw boxes one line at a time to exercise base vertex. setIndexedPatterned does not
// support a base index.
for (int y = 0; y < kBoxCountY; ++y) {
GrMesh mesh(kTriangles_GrPrimitiveType);
GrMesh mesh(GrPrimitiveType::kTriangles);
mesh.setIndexedPatterned(ibuff.get(), 6, 4, kBoxCountX, kIndexPatternRepeatCount);
mesh.setVertexData(vbuff.get(), y * kBoxCountX * 4);
helper->drawMesh(mesh);
@ -213,7 +213,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrMeshTest, reporter, ctxInfo) {
// Draw boxes one line at a time to exercise base instance, base vertex, and null vertex
// buffer. setIndexedInstanced intentionally does not support a base index.
for (int y = 0; y < kBoxCountY; ++y) {
GrMesh mesh(indexed ? kTriangles_GrPrimitiveType : kTriangleStrip_GrPrimitiveType);
GrMesh mesh(indexed ? GrPrimitiveType::kTriangles
: GrPrimitiveType::kTriangleStrip);
if (indexed) {
VALIDATE(idxbuff);
mesh.setIndexedInstanced(idxbuff.get(), 6,

View File

@ -126,7 +126,7 @@ private:
GrPipeline pipeline(rt, fScissorState, SkBlendMode::kSrc);
SkSTArray<kNumMeshes, GrMesh> meshes;
for (int i = 0; i < kNumMeshes; ++i) {
GrMesh& mesh = meshes.emplace_back(kTriangleStrip_GrPrimitiveType);
GrMesh& mesh = meshes.emplace_back(GrPrimitiveType::kTriangleStrip);
mesh.setNonIndexedNonInstanced(4);
mesh.setVertexData(fVertexBuffer.get(), 4 * i);
}

View File

@ -144,7 +144,7 @@ private:
}
}
GrMesh mesh(kTriangles_GrPrimitiveType);
GrMesh mesh(GrPrimitiveType::kTriangles);
mesh.setIndexed(indexBuffer, 6, firstIndex, 0, 3);
mesh.setVertexData(vertexBuffer, firstVertex);