Make GrDrawVerticesOp a non-legacy GrMeshDrawOp
Change-Id: I0e1e6815ed41764115bc84a5967b3da3be4ce147 Reviewed-on: https://skia-review.googlesource.com/22722 Commit-Queue: Brian Salomon <bsalomon@google.com> Reviewed-by: Greg Daniel <egdaniel@google.com>
This commit is contained in:
parent
7d8955ee4b
commit
c2f425440a
@ -847,16 +847,11 @@ void GrRenderTargetContext::drawVertices(const GrClip& clip,
|
||||
AutoCheckFlush acf(this->drawingManager());
|
||||
|
||||
SkASSERT(vertices);
|
||||
std::unique_ptr<GrLegacyMeshDrawOp> op = GrDrawVerticesOp::Make(paint.getColor(),
|
||||
std::move(vertices), viewMatrix,
|
||||
this->isGammaCorrect(),
|
||||
fColorXformFromSRGB,
|
||||
overridePrimType);
|
||||
if (!op) {
|
||||
return;
|
||||
}
|
||||
GrPipelineBuilder pipelineBuilder(std::move(paint), GrAAType::kNone);
|
||||
this->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op));
|
||||
GrAAType aaType = this->chooseAAType(GrAA::kNo, GrAllowMixedSamples::kNo);
|
||||
std::unique_ptr<GrDrawOp> op =
|
||||
GrDrawVerticesOp::Make(std::move(paint), std::move(vertices), viewMatrix, aaType,
|
||||
this->isGammaCorrect(), fColorXformFromSRGB, overridePrimType);
|
||||
this->addDrawOp(clip, std::move(op));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -10,26 +10,28 @@
|
||||
#include "GrOpFlushState.h"
|
||||
#include "SkGr.h"
|
||||
|
||||
std::unique_ptr<GrLegacyMeshDrawOp> GrDrawVerticesOp::Make(GrColor color,
|
||||
sk_sp<SkVertices> vertices,
|
||||
const SkMatrix& viewMatrix,
|
||||
bool gammaCorrect,
|
||||
sk_sp<GrColorSpaceXform> colorSpaceXform,
|
||||
GrPrimitiveType* overridePrimType) {
|
||||
std::unique_ptr<GrDrawOp> GrDrawVerticesOp::Make(GrPaint&& paint,
|
||||
sk_sp<SkVertices> vertices,
|
||||
const SkMatrix& viewMatrix,
|
||||
GrAAType aaType,
|
||||
bool gammaCorrect,
|
||||
sk_sp<GrColorSpaceXform> colorSpaceXform,
|
||||
GrPrimitiveType* overridePrimType) {
|
||||
SkASSERT(vertices);
|
||||
GrPrimitiveType primType = overridePrimType ? *overridePrimType
|
||||
: SkVertexModeToGrPrimitiveType(vertices->mode());
|
||||
return std::unique_ptr<GrLegacyMeshDrawOp>(new GrDrawVerticesOp(std::move(vertices), primType,
|
||||
color, gammaCorrect,
|
||||
std::move(colorSpaceXform),
|
||||
viewMatrix));
|
||||
return Helper::FactoryHelper<GrDrawVerticesOp>(std::move(paint), std::move(vertices), primType,
|
||||
aaType, gammaCorrect, std::move(colorSpaceXform),
|
||||
viewMatrix);
|
||||
}
|
||||
|
||||
GrDrawVerticesOp::GrDrawVerticesOp(sk_sp<SkVertices> vertices, GrPrimitiveType primitiveType,
|
||||
GrColor color, bool gammaCorrect,
|
||||
GrDrawVerticesOp::GrDrawVerticesOp(const Helper::MakeArgs& helperArgs, GrColor color,
|
||||
sk_sp<SkVertices> vertices, GrPrimitiveType primitiveType,
|
||||
GrAAType aaType, bool gammaCorrect,
|
||||
sk_sp<GrColorSpaceXform> colorSpaceXform,
|
||||
const SkMatrix& viewMatrix)
|
||||
: INHERITED(ClassID())
|
||||
, fHelper(helperArgs, aaType)
|
||||
, fPrimitiveType(primitiveType)
|
||||
, fColorSpaceXform(std::move(colorSpaceXform)) {
|
||||
SkASSERT(vertices);
|
||||
@ -66,39 +68,47 @@ GrDrawVerticesOp::GrDrawVerticesOp(sk_sp<SkVertices> vertices, GrPrimitiveType p
|
||||
this->setTransformedBounds(mesh.fVertices->bounds(), viewMatrix, HasAABloat::kNo, zeroArea);
|
||||
}
|
||||
|
||||
void GrDrawVerticesOp::getProcessorAnalysisInputs(GrProcessorAnalysisColor* color,
|
||||
GrProcessorAnalysisCoverage* coverage) const {
|
||||
if (this->requiresPerVertexColors()) {
|
||||
color->setToUnknown();
|
||||
} else {
|
||||
color->setToConstant(fMeshes[0].fColor);
|
||||
}
|
||||
*coverage = GrProcessorAnalysisCoverage::kNone;
|
||||
SkString GrDrawVerticesOp::dumpInfo() const {
|
||||
SkString string;
|
||||
string.appendf("PrimType: %d, MeshCount %d, VCount: %d, ICount: %d\n", (int)fPrimitiveType,
|
||||
fMeshes.count(), fVertexCount, fIndexCount);
|
||||
string += fHelper.dumpInfo();
|
||||
string += INHERITED::dumpInfo();
|
||||
return string;
|
||||
}
|
||||
|
||||
void GrDrawVerticesOp::applyPipelineOptimizations(const PipelineOptimizations& optimizations) {
|
||||
SkASSERT(fMeshes.count() == 1);
|
||||
GrColor overrideColor;
|
||||
if (optimizations.getOverrideColorIfSet(&overrideColor)) {
|
||||
fMeshes[0].fColor = overrideColor;
|
||||
fMeshes[0].fIgnoreColors = true;
|
||||
GrDrawOp::FixedFunctionFlags GrDrawVerticesOp::fixedFunctionFlags() const {
|
||||
return fHelper.fixedFunctionFlags();
|
||||
}
|
||||
|
||||
GrDrawOp::RequiresDstTexture GrDrawVerticesOp::finalize(const GrCaps& caps,
|
||||
const GrAppliedClip* clip) {
|
||||
GrProcessorAnalysisColor gpColor;
|
||||
if (this->requiresPerVertexColors()) {
|
||||
gpColor.setToUnknown();
|
||||
} else {
|
||||
gpColor.setToConstant(fMeshes.front().fColor);
|
||||
}
|
||||
auto result =
|
||||
fHelper.xpRequiresDstTexture(caps, clip, GrProcessorAnalysisCoverage::kNone, &gpColor);
|
||||
if (gpColor.isConstant(&fMeshes.front().fColor)) {
|
||||
fMeshes.front().fIgnoreColors = true;
|
||||
fFlags &= ~kRequiresPerVertexColors_Flag;
|
||||
fColorArrayType = ColorArrayType::kPremulGrColor;
|
||||
fLinearizeColors = false;
|
||||
}
|
||||
if (optimizations.readsLocalCoords()) {
|
||||
fFlags |= kPipelineRequiresLocalCoords_Flag;
|
||||
} else {
|
||||
if (!fHelper.usesLocalCoords()) {
|
||||
fMeshes[0].fIgnoreTexCoords = true;
|
||||
fFlags &= ~kAnyMeshHasExplicitLocalCoords;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
sk_sp<GrGeometryProcessor> GrDrawVerticesOp::makeGP(bool* hasColorAttribute,
|
||||
bool* hasLocalCoordAttribute) const {
|
||||
using namespace GrDefaultGeoProcFactory;
|
||||
LocalCoords::Type localCoordsType;
|
||||
if (this->pipelineRequiresLocalCoords()) {
|
||||
if (fHelper.usesLocalCoords()) {
|
||||
// If we have multiple view matrices we will transform the positions into device space. We
|
||||
// must then also provide untransformed positions as local coords.
|
||||
if (this->anyMeshHasExplicitLocalCoords() || this->hasMultipleViewMatrices()) {
|
||||
@ -236,14 +246,13 @@ void GrDrawVerticesOp::onPrepareDraws(Target* target) const {
|
||||
mesh.setIndexed(indexBuffer, fIndexCount, firstIndex, 0, fVertexCount - 1);
|
||||
}
|
||||
mesh.setVertexData(vertexBuffer, firstVertex);
|
||||
target->draw(gp.get(), this->pipeline(), mesh);
|
||||
target->draw(gp.get(), fHelper.makePipeline(target), mesh);
|
||||
}
|
||||
|
||||
bool GrDrawVerticesOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) {
|
||||
GrDrawVerticesOp* that = t->cast<GrDrawVerticesOp>();
|
||||
|
||||
if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(),
|
||||
that->bounds(), caps)) {
|
||||
if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -361,7 +370,7 @@ static void randomize_params(size_t count, size_t maxVertex, SkScalar min, SkSca
|
||||
}
|
||||
}
|
||||
|
||||
GR_LEGACY_MESH_DRAW_OP_TEST_DEFINE(VerticesOp) {
|
||||
GR_DRAW_OP_TEST_DEFINE(GrDrawVerticesOp) {
|
||||
GrPrimitiveType type;
|
||||
do {
|
||||
type = GrPrimitiveType(random->nextULessThan(kNumGrPrimitiveTypes));
|
||||
@ -397,7 +406,6 @@ GR_LEGACY_MESH_DRAW_OP_TEST_DEFINE(VerticesOp) {
|
||||
|
||||
SkMatrix viewMatrix = GrTest::TestMatrix(random);
|
||||
|
||||
GrColor color = GrRandomColor(random);
|
||||
sk_sp<GrColorSpaceXform> colorSpaceXform = GrTest::TestColorXform(random);
|
||||
|
||||
static constexpr SkVertices::VertexMode kIgnoredMode = SkVertices::kTriangles_VertexMode;
|
||||
@ -405,9 +413,12 @@ GR_LEGACY_MESH_DRAW_OP_TEST_DEFINE(VerticesOp) {
|
||||
texCoords.begin(), colors.begin(),
|
||||
hasIndices ? indices.count() : 0,
|
||||
indices.begin());
|
||||
return std::unique_ptr<GrLegacyMeshDrawOp>(
|
||||
new GrDrawVerticesOp(std::move(vertices), type, color, linearizeColors,
|
||||
std::move(colorSpaceXform), viewMatrix));
|
||||
GrAAType aaType = GrAAType::kNone;
|
||||
if (GrFSAAType::kUnifiedMSAA == fsaaType && random->nextBool()) {
|
||||
aaType = GrAAType::kMSAA;
|
||||
}
|
||||
return GrDrawVerticesOp::Make(std::move(paint), std::move(vertices), viewMatrix, aaType,
|
||||
linearizeColors, std::move(colorSpaceXform), &type);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -11,46 +11,46 @@
|
||||
#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 "SkVertices.h"
|
||||
|
||||
#if GR_TEST_UTILS
|
||||
#include "GrDrawOpTest.h"
|
||||
#endif
|
||||
|
||||
class GrOpFlushState;
|
||||
class SkVertices;
|
||||
struct GrInitInvariantOutput;
|
||||
|
||||
class GrDrawVerticesOp final : public GrLegacyMeshDrawOp {
|
||||
class GrDrawVerticesOp final : public GrMeshDrawOp {
|
||||
private:
|
||||
using Helper = GrSimpleMeshDrawOpHelper;
|
||||
|
||||
public:
|
||||
DEFINE_OP_CLASS_ID
|
||||
|
||||
/**
|
||||
* Draw a SkVertices. The GrColor param is used if the vertices lack per-vertex color. If the
|
||||
* vertices lack local coords then the vertex positions are used as local coords. The primitive
|
||||
* type drawn is derived from the SkVertices object, unless overridePrimType is specified.
|
||||
* If gammaCorrect is true, the vertex colors will be linearized in the shader to get correct
|
||||
* rendering.
|
||||
* Draw a SkVertices. The GrPaint param's color is used if the vertices lack per-vertex color.
|
||||
* If the vertices lack local coords then the vertex positions are used as local coords. The
|
||||
* primitive type drawn is derived from the SkVertices object, unless overridePrimType is
|
||||
* specified. If gammaCorrect is true, the vertex colors will be linearized in the shader to get
|
||||
* correct rendering.
|
||||
*/
|
||||
static std::unique_ptr<GrLegacyMeshDrawOp> Make(GrColor color, sk_sp<SkVertices>,
|
||||
const SkMatrix& viewMatrix, bool gammaCorrect,
|
||||
sk_sp<GrColorSpaceXform> colorSpaceXform,
|
||||
GrPrimitiveType* overridePrimType = nullptr);
|
||||
static std::unique_ptr<GrDrawOp> Make(GrPaint&&, sk_sp<SkVertices>, const SkMatrix& viewMatrix,
|
||||
GrAAType, bool gammaCorrect, sk_sp<GrColorSpaceXform>,
|
||||
GrPrimitiveType* overridePrimType = nullptr);
|
||||
|
||||
GrDrawVerticesOp(const Helper::MakeArgs& helperArgs, GrColor, sk_sp<SkVertices>,
|
||||
GrPrimitiveType, GrAAType, bool gammaCorrect, sk_sp<GrColorSpaceXform>,
|
||||
const SkMatrix& viewMatrix);
|
||||
|
||||
const char* name() const override { return "DrawVerticesOp"; }
|
||||
|
||||
SkString dumpInfo() const override {
|
||||
SkString string;
|
||||
string.appendf("PrimType: %d, MeshCount %d, VCount: %d, ICount: %d\n",
|
||||
(int) fPrimitiveType, fMeshes.count(), fVertexCount, fIndexCount);
|
||||
string.append(DumpPipelineInfo(*this->pipeline()));
|
||||
string.append(INHERITED::dumpInfo());
|
||||
return string;
|
||||
}
|
||||
SkString dumpInfo() const override;
|
||||
|
||||
FixedFunctionFlags fixedFunctionFlags() const override;
|
||||
|
||||
RequiresDstTexture finalize(const GrCaps& caps, const GrAppliedClip* clip) override;
|
||||
|
||||
private:
|
||||
enum class ColorArrayType {
|
||||
@ -58,12 +58,6 @@ private:
|
||||
kSkColor,
|
||||
};
|
||||
|
||||
GrDrawVerticesOp(sk_sp<SkVertices>, GrPrimitiveType, GrColor, bool gammaCorrect,
|
||||
sk_sp<GrColorSpaceXform>, const SkMatrix& viewMatrix);
|
||||
|
||||
void getProcessorAnalysisInputs(GrProcessorAnalysisColor* color,
|
||||
GrProcessorAnalysisCoverage* coverage) const override;
|
||||
void applyPipelineOptimizations(const PipelineOptimizations&) override;
|
||||
void onPrepareDraws(Target*) const override;
|
||||
|
||||
sk_sp<GrGeometryProcessor> makeGP(bool* hasColorAttribute, bool* hasLocalCoordAttribute) const;
|
||||
@ -106,10 +100,6 @@ private:
|
||||
return SkToBool(kAnyMeshHasExplicitLocalCoords & fFlags);
|
||||
}
|
||||
|
||||
bool pipelineRequiresLocalCoords() const {
|
||||
return SkToBool(kPipelineRequiresLocalCoords_Flag & fFlags);
|
||||
}
|
||||
|
||||
bool hasMultipleViewMatrices() const {
|
||||
return SkToBool(kHasMultipleViewMatrices_Flag & fFlags);
|
||||
}
|
||||
@ -117,11 +107,12 @@ private:
|
||||
enum Flags {
|
||||
kRequiresPerVertexColors_Flag = 0x1,
|
||||
kAnyMeshHasExplicitLocalCoords = 0x2,
|
||||
kPipelineRequiresLocalCoords_Flag = 0x4,
|
||||
kHasMultipleViewMatrices_Flag = 0x8
|
||||
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;
|
||||
@ -131,13 +122,8 @@ private:
|
||||
ColorArrayType fColorArrayType;
|
||||
bool fLinearizeColors;
|
||||
sk_sp<GrColorSpaceXform> fColorSpaceXform;
|
||||
SkSTArray<1, Mesh, true> fMeshes;
|
||||
|
||||
typedef GrLegacyMeshDrawOp INHERITED;
|
||||
|
||||
#if GR_TEST_UTILS
|
||||
GR_LEGACY_MESH_DRAW_OP_TEST_FRIEND(VerticesOp);
|
||||
#endif
|
||||
typedef GrMeshDrawOp INHERITED;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -317,7 +317,6 @@ LEGACY_MESH_DRAW_OP_TEST_EXTERN(AAFlatteningConvexPathOp);
|
||||
LEGACY_MESH_DRAW_OP_TEST_EXTERN(AnalyticRectOp);
|
||||
LEGACY_MESH_DRAW_OP_TEST_EXTERN(DefaultPathOp);
|
||||
LEGACY_MESH_DRAW_OP_TEST_EXTERN(TextBlobOp);
|
||||
LEGACY_MESH_DRAW_OP_TEST_EXTERN(VerticesOp);
|
||||
|
||||
DRAW_OP_TEST_EXTERN(AAConvexPathOp);
|
||||
DRAW_OP_TEST_EXTERN(AAFillRectOp);
|
||||
@ -328,6 +327,7 @@ DRAW_OP_TEST_EXTERN(DashOp);
|
||||
DRAW_OP_TEST_EXTERN(DIEllipseOp);
|
||||
DRAW_OP_TEST_EXTERN(EllipseOp);
|
||||
DRAW_OP_TEST_EXTERN(GrDrawAtlasOp);
|
||||
DRAW_OP_TEST_EXTERN(GrDrawVerticesOp);
|
||||
DRAW_OP_TEST_EXTERN(NonAAFillRectOp);
|
||||
DRAW_OP_TEST_EXTERN(NonAALatticeOp);
|
||||
DRAW_OP_TEST_EXTERN(NonAAStrokeRectOp);
|
||||
@ -345,7 +345,6 @@ void GrDrawRandomOp(SkRandom* random, GrRenderTargetContext* renderTargetContext
|
||||
DRAW_OP_TEST_ENTRY(AnalyticRectOp),
|
||||
DRAW_OP_TEST_ENTRY(DefaultPathOp),
|
||||
DRAW_OP_TEST_ENTRY(TextBlobOp),
|
||||
DRAW_OP_TEST_ENTRY(VerticesOp)
|
||||
};
|
||||
|
||||
using MakeDrawOpFn = std::unique_ptr<GrDrawOp>(GrPaint&&, SkRandom*, GrContext*, GrFSAAType);
|
||||
@ -359,6 +358,7 @@ void GrDrawRandomOp(SkRandom* random, GrRenderTargetContext* renderTargetContext
|
||||
DRAW_OP_TEST_ENTRY(DIEllipseOp),
|
||||
DRAW_OP_TEST_ENTRY(EllipseOp),
|
||||
DRAW_OP_TEST_ENTRY(GrDrawAtlasOp),
|
||||
DRAW_OP_TEST_ENTRY(GrDrawVerticesOp),
|
||||
DRAW_OP_TEST_ENTRY(NonAAFillRectOp),
|
||||
DRAW_OP_TEST_ENTRY(NonAALatticeOp),
|
||||
DRAW_OP_TEST_ENTRY(NonAAStrokeRectOp),
|
||||
|
Loading…
Reference in New Issue
Block a user