Outline GrDrawAtlasOp and GrDrawVerticesOp

This makes it easier to switch all the ops over to using a GrRecordingContext (and better matches what we do with all the other ops)

Change-Id: Ie690975c31b8c9f4c7acebdc0185a145a0a263a5
Reviewed-on: https://skia-review.googlesource.com/c/191280
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Robert Phillips 2019-02-11 14:29:34 -05:00 committed by Skia Commit-Bot
parent 7f3618a2c9
commit b6e9d3c788
6 changed files with 287 additions and 254 deletions

View File

@ -16,6 +16,7 @@
#include "GrDrawingManager.h"
#include "GrFixedClip.h"
#include "GrGpuResourcePriv.h"
#include "GrMemoryPool.h"
#include "GrOpList.h"
#include "GrPathRenderer.h"
#include "GrQuad.h"

View File

@ -6,13 +6,71 @@
*/
#include "GrDrawAtlasOp.h"
#include "GrCaps.h"
#include "GrDefaultGeoProcFactory.h"
#include "GrDrawOpTest.h"
#include "GrOpFlushState.h"
#include "GrRecordingContext.h"
#include "GrRecordingContextPriv.h"
#include "GrSimpleMeshDrawOpHelper.h"
#include "SkGr.h"
#include "SkRSXform.h"
#include "SkRandom.h"
#include "SkRectPriv.h"
namespace {
class DrawAtlasOp final : public GrMeshDrawOp {
private:
using Helper = GrSimpleMeshDrawOpHelper;
public:
DEFINE_OP_CLASS_ID
DrawAtlasOp(const Helper::MakeArgs&, const SkPMColor4f& color,
const SkMatrix& viewMatrix, GrAAType, int spriteCount, const SkRSXform* xforms,
const SkRect* rects, const SkColor* colors);
const char* name() const override { return "DrawAtlasOp"; }
void visitProxies(const VisitProxyFunc& func, VisitorType) const override {
fHelper.visitProxies(func);
}
#ifdef SK_DEBUG
SkString dumpInfo() const override;
#endif
FixedFunctionFlags fixedFunctionFlags() const override;
GrProcessorSet::Analysis finalize(const GrCaps& caps, const GrAppliedClip* clip) override;
private:
void onPrepareDraws(Target*) override;
const SkPMColor4f& color() const { return fColor; }
const SkMatrix& viewMatrix() const { return fViewMatrix; }
bool hasColors() const { return fHasColors; }
int quadCount() const { return fQuadCount; }
CombineResult onCombineIfPossible(GrOp* t, const GrCaps&) override;
struct Geometry {
SkPMColor4f fColor;
SkTArray<uint8_t, true> fVerts;
};
SkSTArray<1, Geometry, true> fGeoData;
Helper fHelper;
SkMatrix fViewMatrix;
SkPMColor4f fColor;
int fQuadCount;
bool fHasColors;
typedef GrMeshDrawOp INHERITED;
};
static sk_sp<GrGeometryProcessor> make_gp(const GrShaderCaps* shaderCaps,
bool hasColors,
const SkPMColor4f& color,
@ -27,9 +85,9 @@ static sk_sp<GrGeometryProcessor> make_gp(const GrShaderCaps* shaderCaps,
LocalCoords::kHasExplicit_Type, viewMatrix);
}
GrDrawAtlasOp::GrDrawAtlasOp(const Helper::MakeArgs& helperArgs, const SkPMColor4f& color,
const SkMatrix& viewMatrix, GrAAType aaType, int spriteCount,
const SkRSXform* xforms, const SkRect* rects, const SkColor* colors)
DrawAtlasOp::DrawAtlasOp(const Helper::MakeArgs& helperArgs, const SkPMColor4f& color,
const SkMatrix& viewMatrix, GrAAType aaType, int spriteCount,
const SkRSXform* xforms, const SkRect* rects, const SkColor* colors)
: INHERITED(ClassID()), fHelper(helperArgs, aaType), fColor(color) {
SkASSERT(xforms);
SkASSERT(rects);
@ -110,7 +168,7 @@ GrDrawAtlasOp::GrDrawAtlasOp(const Helper::MakeArgs& helperArgs, const SkPMColor
}
#ifdef SK_DEBUG
SkString GrDrawAtlasOp::dumpInfo() const {
SkString DrawAtlasOp::dumpInfo() const {
SkString string;
for (const auto& geo : fGeoData) {
string.appendf("Color: 0x%08x, Quads: %d\n", geo.fColor.toBytes_RGBA(),
@ -122,7 +180,7 @@ SkString GrDrawAtlasOp::dumpInfo() const {
}
#endif
void GrDrawAtlasOp::onPrepareDraws(Target* target) {
void DrawAtlasOp::onPrepareDraws(Target* target) {
// Setup geometry processor
sk_sp<GrGeometryProcessor> gp(make_gp(target->caps().shaderCaps(),
this->hasColors(),
@ -152,8 +210,8 @@ void GrDrawAtlasOp::onPrepareDraws(Target* target) {
helper.recordDraw(target, std::move(gp), pipe.fPipeline, pipe.fFixedDynamicState);
}
GrOp::CombineResult GrDrawAtlasOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) {
GrDrawAtlasOp* that = t->cast<GrDrawAtlasOp>();
GrOp::CombineResult DrawAtlasOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) {
DrawAtlasOp* that = t->cast<DrawAtlasOp>();
if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) {
return CombineResult::kCannotCombine;
@ -178,11 +236,11 @@ GrOp::CombineResult GrDrawAtlasOp::onCombineIfPossible(GrOp* t, const GrCaps& ca
return CombineResult::kMerged;
}
GrDrawOp::FixedFunctionFlags GrDrawAtlasOp::fixedFunctionFlags() const {
GrDrawOp::FixedFunctionFlags DrawAtlasOp::fixedFunctionFlags() const {
return fHelper.fixedFunctionFlags();
}
GrProcessorSet::Analysis GrDrawAtlasOp::finalize(const GrCaps& caps, const GrAppliedClip* clip) {
GrProcessorSet::Analysis DrawAtlasOp::finalize(const GrCaps& caps, const GrAppliedClip* clip) {
GrProcessorAnalysisColor gpColor;
if (this->hasColors()) {
gpColor.setToUnknown();
@ -197,6 +255,22 @@ GrProcessorSet::Analysis GrDrawAtlasOp::finalize(const GrCaps& caps, const GrApp
return result;
}
} // anonymous namespace
std::unique_ptr<GrDrawOp> GrDrawAtlasOp::Make(GrContext* context,
GrPaint&& paint,
const SkMatrix& viewMatrix,
GrAAType aaType,
int spriteCount,
const SkRSXform* xforms,
const SkRect* rects,
const SkColor* colors) {
return GrSimpleMeshDrawOpHelper::FactoryHelper<DrawAtlasOp>(context, std::move(paint),
viewMatrix, aaType,
spriteCount, xforms,
rects, colors);
}
#if GR_TEST_UTILS
static SkRSXform random_xform(SkRandom* random) {
@ -240,7 +314,7 @@ static void randomize_params(uint32_t count, SkRandom* random, SkTArray<SkRSXfor
}
}
GR_DRAW_OP_TEST_DEFINE(GrDrawAtlasOp) {
GR_DRAW_OP_TEST_DEFINE(DrawAtlasOp) {
uint32_t spriteCount = random->nextRangeU(1, 100);
SkTArray<SkRSXform> xforms(spriteCount);

View File

@ -8,71 +8,23 @@
#ifndef GrDrawAtlasOp_DEFINED
#define GrDrawAtlasOp_DEFINED
#include "GrColor.h"
#include "GrDefaultGeoProcFactory.h"
#include "GrMeshDrawOp.h"
#include "GrSimpleMeshDrawOpHelper.h"
#include "GrTypesPriv.h"
#include "SkRefCnt.h"
class GrDrawAtlasOp final : public GrMeshDrawOp {
private:
using Helper = GrSimpleMeshDrawOpHelper;
class GrContext;
class GrDrawOp;
class GrPaint;
class SkMatrix;
public:
DEFINE_OP_CLASS_ID
static std::unique_ptr<GrDrawOp> Make(GrContext* context,
GrPaint&& paint,
const SkMatrix& viewMatrix,
GrAAType aaType,
int spriteCount,
const SkRSXform* xforms,
const SkRect* rects,
const SkColor* colors) {
return Helper::FactoryHelper<GrDrawAtlasOp>(context, std::move(paint), viewMatrix, aaType,
spriteCount, xforms, rects, colors);
}
GrDrawAtlasOp(const Helper::MakeArgs& helperArgs, const SkPMColor4f& color,
const SkMatrix& viewMatrix, GrAAType, int spriteCount, const SkRSXform* xforms,
const SkRect* rects, const SkColor* colors);
const char* name() const override { return "DrawAtlasOp"; }
void visitProxies(const VisitProxyFunc& func, VisitorType) const override {
fHelper.visitProxies(func);
}
#ifdef SK_DEBUG
SkString dumpInfo() const override;
#endif
FixedFunctionFlags fixedFunctionFlags() const override;
GrProcessorSet::Analysis finalize(const GrCaps& caps, const GrAppliedClip* clip) override;
private:
void onPrepareDraws(Target*) override;
const SkPMColor4f& color() const { return fColor; }
const SkMatrix& viewMatrix() const { return fViewMatrix; }
bool hasColors() const { return fHasColors; }
int quadCount() const { return fQuadCount; }
CombineResult onCombineIfPossible(GrOp* t, const GrCaps&) override;
struct Geometry {
SkPMColor4f fColor;
SkTArray<uint8_t, true> fVerts;
};
SkSTArray<1, Geometry, true> fGeoData;
Helper fHelper;
SkMatrix fViewMatrix;
SkPMColor4f fColor;
int fQuadCount;
bool fHasColors;
typedef GrMeshDrawOp INHERITED;
namespace GrDrawAtlasOp {
std::unique_ptr<GrDrawOp> Make(GrContext*,
GrPaint&&,
const SkMatrix& viewMatrix,
GrAAType,
int spriteCount,
const SkRSXform* xforms,
const SkRect* rects,
const SkColor* colors);
};
#endif

View File

@ -9,31 +9,132 @@
#include "GrCaps.h"
#include "GrDefaultGeoProcFactory.h"
#include "GrOpFlushState.h"
#include "GrSimpleMeshDrawOpHelper.h"
#include "SkGr.h"
#include "SkRectPriv.h"
std::unique_ptr<GrDrawOp> GrDrawVerticesOp::Make(GrContext* context,
GrPaint&& paint,
sk_sp<SkVertices> vertices,
const SkVertices::Bone bones[],
int boneCount,
const SkMatrix& viewMatrix,
GrAAType aaType,
sk_sp<GrColorSpaceXform> colorSpaceXform,
GrPrimitiveType* overridePrimType) {
SkASSERT(vertices);
GrPrimitiveType primType = overridePrimType ? *overridePrimType
: SkVertexModeToGrPrimitiveType(vertices->mode());
return Helper::FactoryHelper<GrDrawVerticesOp>(context, std::move(paint), std::move(vertices),
bones, boneCount, primType, aaType,
std::move(colorSpaceXform), viewMatrix);
}
namespace {
GrDrawVerticesOp::GrDrawVerticesOp(const Helper::MakeArgs& helperArgs, const SkPMColor4f& color,
sk_sp<SkVertices> vertices, const SkVertices::Bone bones[],
int boneCount, GrPrimitiveType primitiveType, GrAAType aaType,
sk_sp<GrColorSpaceXform> colorSpaceXform,
const SkMatrix& viewMatrix)
class DrawVerticesOp final : public GrMeshDrawOp {
private:
using Helper = GrSimpleMeshDrawOpHelper;
public:
DEFINE_OP_CLASS_ID
DrawVerticesOp(const Helper::MakeArgs&, const SkPMColor4f&, sk_sp<SkVertices>,
const SkVertices::Bone bones[], int boneCount, GrPrimitiveType, GrAAType,
sk_sp<GrColorSpaceXform>, const SkMatrix& viewMatrix);
const char* name() const override { return "DrawVerticesOp"; }
void visitProxies(const VisitProxyFunc& func, VisitorType) const override {
fHelper.visitProxies(func);
}
#ifdef SK_DEBUG
SkString dumpInfo() const override;
#endif
FixedFunctionFlags fixedFunctionFlags() const override;
GrProcessorSet::Analysis finalize(const GrCaps& caps, const GrAppliedClip* clip) override;
private:
enum class ColorArrayType {
kPremulGrColor,
kSkColor,
};
void onPrepareDraws(Target*) override;
void drawVolatile(Target*);
void drawNonVolatile(Target*);
void fillBuffers(bool hasColorAttribute,
bool hasLocalCoordsAttribute,
size_t vertexStride,
void* verts,
uint16_t* indices) const;
void drawVertices(Target*,
sk_sp<const GrGeometryProcessor>,
sk_sp<const GrBuffer> vertexBuffer,
int firstVertex,
sk_sp<const GrBuffer> indexBuffer,
int firstIndex);
sk_sp<GrGeometryProcessor> makeGP(const GrShaderCaps* shaderCaps,
bool* hasColorAttribute,
bool* hasLocalCoordAttribute) const;
GrPrimitiveType primitiveType() const { return fPrimitiveType; }
bool combinablePrimitive() const {
return GrPrimitiveType::kTriangles == fPrimitiveType ||
GrPrimitiveType::kLines == fPrimitiveType ||
GrPrimitiveType::kPoints == fPrimitiveType;
}
CombineResult onCombineIfPossible(GrOp* t, const GrCaps&) override;
struct Mesh {
SkPMColor4f fColor; // Used if this->hasPerVertexColors() is false.
sk_sp<SkVertices> fVertices;
SkMatrix fViewMatrix;
bool fIgnoreTexCoords;
bool fIgnoreColors;
bool hasExplicitLocalCoords() const {
return fVertices->hasTexCoords() && !fIgnoreTexCoords;
}
bool hasPerVertexColors() const {
return fVertices->hasColors() && !fIgnoreColors;
}
};
bool isIndexed() const {
// Consistency enforced in onCombineIfPossible.
return fMeshes[0].fVertices->hasIndices();
}
bool requiresPerVertexColors() const {
return SkToBool(kRequiresPerVertexColors_Flag & fFlags);
}
bool anyMeshHasExplicitLocalCoords() const {
return SkToBool(kAnyMeshHasExplicitLocalCoords_Flag & fFlags);
}
bool hasMultipleViewMatrices() const {
return SkToBool(kHasMultipleViewMatrices_Flag & fFlags);
}
enum Flags {
kRequiresPerVertexColors_Flag = 0x1,
kAnyMeshHasExplicitLocalCoords_Flag = 0x2,
kHasMultipleViewMatrices_Flag = 0x4,
};
Helper fHelper;
SkSTArray<1, Mesh, true> fMeshes;
// GrPrimitiveType is more expressive than fVertices.mode() so it is used instead and we ignore
// the SkVertices mode (though fPrimitiveType may have been inferred from it).
GrPrimitiveType fPrimitiveType;
uint32_t fFlags;
int fVertexCount;
int fIndexCount;
ColorArrayType fColorArrayType;
sk_sp<GrColorSpaceXform> fColorSpaceXform;
typedef GrMeshDrawOp INHERITED;
};
DrawVerticesOp::DrawVerticesOp(const Helper::MakeArgs& helperArgs, const SkPMColor4f& color,
sk_sp<SkVertices> vertices, const SkVertices::Bone bones[],
int boneCount, GrPrimitiveType primitiveType, GrAAType aaType,
sk_sp<GrColorSpaceXform> colorSpaceXform,
const SkMatrix& viewMatrix)
: INHERITED(ClassID())
, fHelper(helperArgs, aaType)
, fPrimitiveType(primitiveType)
@ -89,7 +190,7 @@ GrDrawVerticesOp::GrDrawVerticesOp(const Helper::MakeArgs& helperArgs, const SkP
}
#ifdef SK_DEBUG
SkString GrDrawVerticesOp::dumpInfo() const {
SkString DrawVerticesOp::dumpInfo() const {
SkString string;
string.appendf("PrimType: %d, MeshCount %d, VCount: %d, ICount: %d\n", (int)fPrimitiveType,
fMeshes.count(), fVertexCount, fIndexCount);
@ -99,11 +200,11 @@ SkString GrDrawVerticesOp::dumpInfo() const {
}
#endif
GrDrawOp::FixedFunctionFlags GrDrawVerticesOp::fixedFunctionFlags() const {
GrDrawOp::FixedFunctionFlags DrawVerticesOp::fixedFunctionFlags() const {
return fHelper.fixedFunctionFlags();
}
GrProcessorSet::Analysis GrDrawVerticesOp::finalize(const GrCaps& caps, const GrAppliedClip* clip) {
GrProcessorSet::Analysis DrawVerticesOp::finalize(const GrCaps& caps, const GrAppliedClip* clip) {
GrProcessorAnalysisColor gpColor;
if (this->requiresPerVertexColors()) {
gpColor.setToUnknown();
@ -124,9 +225,9 @@ GrProcessorSet::Analysis GrDrawVerticesOp::finalize(const GrCaps& caps, const Gr
return result;
}
sk_sp<GrGeometryProcessor> GrDrawVerticesOp::makeGP(const GrShaderCaps* shaderCaps,
bool* hasColorAttribute,
bool* hasLocalCoordAttribute) const {
sk_sp<GrGeometryProcessor> DrawVerticesOp::makeGP(const GrShaderCaps* shaderCaps,
bool* hasColorAttribute,
bool* hasLocalCoordAttribute) const {
using namespace GrDefaultGeoProcFactory;
LocalCoords::Type localCoordsType;
if (fHelper.usesLocalCoords()) {
@ -166,7 +267,7 @@ sk_sp<GrGeometryProcessor> GrDrawVerticesOp::makeGP(const GrShaderCaps* shaderCa
vm);
}
void GrDrawVerticesOp::onPrepareDraws(Target* target) {
void DrawVerticesOp::onPrepareDraws(Target* target) {
bool hasMapBufferSupport = GrCaps::kNone_MapFlags != target->caps().mapBufferFlags();
if (fMeshes[0].fVertices->isVolatile() || !hasMapBufferSupport) {
this->drawVolatile(target);
@ -175,7 +276,7 @@ void GrDrawVerticesOp::onPrepareDraws(Target* target) {
}
}
void GrDrawVerticesOp::drawVolatile(Target* target) {
void DrawVerticesOp::drawVolatile(Target* target) {
bool hasColorAttribute;
bool hasLocalCoordsAttribute;
sk_sp<GrGeometryProcessor> gp = this->makeGP(target->caps().shaderCaps(),
@ -215,7 +316,7 @@ void GrDrawVerticesOp::drawVolatile(Target* target) {
firstIndex);
}
void GrDrawVerticesOp::drawNonVolatile(Target* target) {
void DrawVerticesOp::drawNonVolatile(Target* target) {
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
bool hasColorAttribute;
@ -295,11 +396,11 @@ void GrDrawVerticesOp::drawNonVolatile(Target* target) {
0);
}
void GrDrawVerticesOp::fillBuffers(bool hasColorAttribute,
bool hasLocalCoordsAttribute,
size_t vertexStride,
void* verts,
uint16_t* indices) const {
void DrawVerticesOp::fillBuffers(bool hasColorAttribute,
bool hasLocalCoordsAttribute,
size_t vertexStride,
void* verts,
uint16_t* indices) const {
int instanceCount = fMeshes.count();
// Copy data into the buffers.
@ -387,12 +488,12 @@ void GrDrawVerticesOp::fillBuffers(bool hasColorAttribute,
}
}
void GrDrawVerticesOp::drawVertices(Target* target,
sk_sp<const GrGeometryProcessor> gp,
sk_sp<const GrBuffer> vertexBuffer,
int firstVertex,
sk_sp<const GrBuffer> indexBuffer,
int firstIndex) {
void DrawVerticesOp::drawVertices(Target* target,
sk_sp<const GrGeometryProcessor> gp,
sk_sp<const GrBuffer> vertexBuffer,
int firstVertex,
sk_sp<const GrBuffer> indexBuffer,
int firstIndex) {
GrMesh* mesh = target->allocMesh(this->primitiveType());
if (this->isIndexed()) {
mesh->setIndexed(std::move(indexBuffer), fIndexCount, firstIndex, 0, fVertexCount - 1,
@ -405,8 +506,8 @@ void GrDrawVerticesOp::drawVertices(Target* target,
target->draw(std::move(gp), pipe.fPipeline, pipe.fFixedDynamicState, mesh);
}
GrOp::CombineResult GrDrawVerticesOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) {
GrDrawVerticesOp* that = t->cast<GrDrawVerticesOp>();
GrOp::CombineResult DrawVerticesOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) {
DrawVerticesOp* that = t->cast<DrawVerticesOp>();
if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) {
return CombineResult::kCannotCombine;
@ -459,6 +560,28 @@ GrOp::CombineResult GrDrawVerticesOp::onCombineIfPossible(GrOp* t, const GrCaps&
return CombineResult::kMerged;
}
} // anonymous namespace
std::unique_ptr<GrDrawOp> GrDrawVerticesOp::Make(GrContext* context,
GrPaint&& paint,
sk_sp<SkVertices> vertices,
const SkVertices::Bone bones[],
int boneCount,
const SkMatrix& viewMatrix,
GrAAType aaType,
sk_sp<GrColorSpaceXform> colorSpaceXform,
GrPrimitiveType* overridePrimType) {
SkASSERT(vertices);
GrPrimitiveType primType = overridePrimType ? *overridePrimType
: SkVertexModeToGrPrimitiveType(vertices->mode());
return GrSimpleMeshDrawOpHelper::FactoryHelper<DrawVerticesOp>(context, std::move(paint),
std::move(vertices),
bones, boneCount,
primType, aaType,
std::move(colorSpaceXform),
viewMatrix);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
#if GR_TEST_UTILS
@ -526,7 +649,7 @@ static void randomize_params(size_t count, size_t maxVertex, SkScalar min, SkSca
}
}
GR_DRAW_OP_TEST_DEFINE(GrDrawVerticesOp) {
GR_DRAW_OP_TEST_DEFINE(DrawVerticesOp) {
GrPrimitiveType type;
do {
type = GrPrimitiveType(random->nextULessThan(kNumGrPrimitiveTypes));

View File

@ -8,26 +8,16 @@
#ifndef GrDrawVerticesOp_DEFINED
#define GrDrawVerticesOp_DEFINED
#include "GrColor.h"
#include "GrMeshDrawOp.h"
#include "GrRenderTargetContext.h"
#include "GrSimpleMeshDrawOpHelper.h"
#include "GrTypes.h"
#include "SkMatrix.h"
#include "SkRect.h"
#include "SkTDArray.h"
#include "GrTypesPriv.h"
#include "SkRefCnt.h"
#include "SkVertices.h"
class GrOpFlushState;
class SkVertices;
struct GrInitInvariantOutput;
class GrColorSpaceXform;
class GrContext;
class GrDrawOp;
class GrPaint;
class GrDrawVerticesOp final : public GrMeshDrawOp {
private:
using Helper = GrSimpleMeshDrawOpHelper;
public:
DEFINE_OP_CLASS_ID
namespace GrDrawVerticesOp {
/**
* Draw a SkVertices. The GrPaint param's color is used if the vertices lack per-vertex color.
@ -35,122 +25,15 @@ public:
* primitive type drawn is derived from the SkVertices object, unless overridePrimType is
* specified.
*/
static std::unique_ptr<GrDrawOp> Make(GrContext* context,
GrPaint&&,
sk_sp<SkVertices>,
const SkVertices::Bone bones[],
int boneCount,
const SkMatrix& viewMatrix,
GrAAType,
sk_sp<GrColorSpaceXform>,
GrPrimitiveType* overridePrimType = nullptr);
GrDrawVerticesOp(const Helper::MakeArgs&, const SkPMColor4f&, sk_sp<SkVertices>,
const SkVertices::Bone bones[], int boneCount, GrPrimitiveType, GrAAType,
sk_sp<GrColorSpaceXform>, const SkMatrix& viewMatrix);
const char* name() const override { return "DrawVerticesOp"; }
void visitProxies(const VisitProxyFunc& func, VisitorType) const override {
fHelper.visitProxies(func);
}
#ifdef SK_DEBUG
SkString dumpInfo() const override;
#endif
FixedFunctionFlags fixedFunctionFlags() const override;
GrProcessorSet::Analysis finalize(const GrCaps& caps, const GrAppliedClip* clip) override;
private:
enum class ColorArrayType {
kPremulGrColor,
kSkColor,
};
void onPrepareDraws(Target*) override;
void drawVolatile(Target*);
void drawNonVolatile(Target*);
void fillBuffers(bool hasColorAttribute,
bool hasLocalCoordsAttribute,
size_t vertexStride,
void* verts,
uint16_t* indices) const;
void drawVertices(Target*,
sk_sp<const GrGeometryProcessor>,
sk_sp<const GrBuffer> vertexBuffer,
int firstVertex,
sk_sp<const GrBuffer> indexBuffer,
int firstIndex);
sk_sp<GrGeometryProcessor> makeGP(const GrShaderCaps* shaderCaps,
bool* hasColorAttribute,
bool* hasLocalCoordAttribute) const;
GrPrimitiveType primitiveType() const { return fPrimitiveType; }
bool combinablePrimitive() const {
return GrPrimitiveType::kTriangles == fPrimitiveType ||
GrPrimitiveType::kLines == fPrimitiveType ||
GrPrimitiveType::kPoints == fPrimitiveType;
}
CombineResult onCombineIfPossible(GrOp* t, const GrCaps&) override;
struct Mesh {
SkPMColor4f fColor; // Used if this->hasPerVertexColors() is false.
sk_sp<SkVertices> fVertices;
SkMatrix fViewMatrix;
bool fIgnoreTexCoords;
bool fIgnoreColors;
bool hasExplicitLocalCoords() const {
return fVertices->hasTexCoords() && !fIgnoreTexCoords;
}
bool hasPerVertexColors() const {
return fVertices->hasColors() && !fIgnoreColors;
}
};
bool isIndexed() const {
// Consistency enforced in onCombineIfPossible.
return fMeshes[0].fVertices->hasIndices();
}
bool requiresPerVertexColors() const {
return SkToBool(kRequiresPerVertexColors_Flag & fFlags);
}
bool anyMeshHasExplicitLocalCoords() const {
return SkToBool(kAnyMeshHasExplicitLocalCoords_Flag & fFlags);
}
bool hasMultipleViewMatrices() const {
return SkToBool(kHasMultipleViewMatrices_Flag & fFlags);
}
enum Flags {
kRequiresPerVertexColors_Flag = 0x1,
kAnyMeshHasExplicitLocalCoords_Flag = 0x2,
kHasMultipleViewMatrices_Flag = 0x4,
};
Helper fHelper;
SkSTArray<1, Mesh, true> fMeshes;
// GrPrimitiveType is more expressive than fVertices.mode() so it is used instead and we ignore
// the SkVertices mode (though fPrimitiveType may have been inferred from it).
GrPrimitiveType fPrimitiveType;
uint32_t fFlags;
int fVertexCount;
int fIndexCount;
ColorArrayType fColorArrayType;
sk_sp<GrColorSpaceXform> fColorSpaceXform;
typedef GrMeshDrawOp INHERITED;
std::unique_ptr<GrDrawOp> Make(GrContext*,
GrPaint&&,
sk_sp<SkVertices>,
const SkVertices::Bone bones[],
int boneCount,
const SkMatrix& viewMatrix,
GrAAType,
sk_sp<GrColorSpaceXform>,
GrPrimitiveType* overridePrimType = nullptr);
};
#endif

View File

@ -175,8 +175,8 @@ DRAW_OP_TEST_EXTERN(DIEllipseOp);
DRAW_OP_TEST_EXTERN(EllipseOp);
DRAW_OP_TEST_EXTERN(FillRectOp);
DRAW_OP_TEST_EXTERN(GrAtlasTextOp);
DRAW_OP_TEST_EXTERN(GrDrawAtlasOp);
DRAW_OP_TEST_EXTERN(GrDrawVerticesOp);
DRAW_OP_TEST_EXTERN(DrawAtlasOp);
DRAW_OP_TEST_EXTERN(DrawVerticesOp);
DRAW_OP_TEST_EXTERN(NonAALatticeOp);
DRAW_OP_TEST_EXTERN(NonAAStrokeRectOp);
DRAW_OP_TEST_EXTERN(ShadowRRectOp);
@ -201,8 +201,8 @@ void GrDrawRandomOp(SkRandom* random, GrRenderTargetContext* renderTargetContext
DRAW_OP_TEST_ENTRY(EllipseOp),
DRAW_OP_TEST_ENTRY(FillRectOp),
DRAW_OP_TEST_ENTRY(GrAtlasTextOp),
DRAW_OP_TEST_ENTRY(GrDrawAtlasOp),
DRAW_OP_TEST_ENTRY(GrDrawVerticesOp),
DRAW_OP_TEST_ENTRY(DrawAtlasOp),
DRAW_OP_TEST_ENTRY(DrawVerticesOp),
DRAW_OP_TEST_ENTRY(NonAALatticeOp),
DRAW_OP_TEST_ENTRY(NonAAStrokeRectOp),
DRAW_OP_TEST_ENTRY(ShadowRRectOp),