aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/gpu/ops/GrTessellatingPathRenderer.cpp132
-rw-r--r--tools/gpu/GrTest.cpp4
2 files changed, 71 insertions, 65 deletions
diff --git a/src/gpu/ops/GrTessellatingPathRenderer.cpp b/src/gpu/ops/GrTessellatingPathRenderer.cpp
index 059afeb5f3..4a2d5f86d6 100644
--- a/src/gpu/ops/GrTessellatingPathRenderer.cpp
+++ b/src/gpu/ops/GrTessellatingPathRenderer.cpp
@@ -20,6 +20,7 @@
#include "GrTessellator.h"
#include "SkGeometry.h"
+#include "GrSimpleMeshDrawOpHelper.h"
#include "ops/GrMeshDrawOp.h"
#include <stdio.h>
@@ -155,17 +156,23 @@ bool GrTessellatingPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) cons
return true;
}
-class TessellatingPathOp final : public GrLegacyMeshDrawOp {
+namespace {
+
+class TessellatingPathOp final : public GrMeshDrawOp {
+private:
+ using Helper = GrSimpleMeshDrawOpHelperWithStencil;
+
public:
DEFINE_OP_CLASS_ID
- static std::unique_ptr<GrLegacyMeshDrawOp> Make(const GrColor& color,
- const GrShape& shape,
- const SkMatrix& viewMatrix,
- SkIRect devClipBounds,
- bool antiAlias) {
- return std::unique_ptr<GrLegacyMeshDrawOp>(
- new TessellatingPathOp(color, shape, viewMatrix, devClipBounds, antiAlias));
+ static std::unique_ptr<GrDrawOp> Make(GrPaint&& paint,
+ const GrShape& shape,
+ const SkMatrix& viewMatrix,
+ SkIRect devClipBounds,
+ GrAAType aaType,
+ const GrUserStencilSettings* stencilSettings) {
+ return Helper::FactoryHelper<TessellatingPathOp>(std::move(paint), shape, viewMatrix,
+ devClipBounds, aaType, stencilSettings);
}
const char* name() const override { return "TessellatingPathOp"; }
@@ -173,24 +180,45 @@ public:
SkString dumpInfo() const override {
SkString string;
string.appendf("Color 0x%08x, aa: %d\n", fColor, fAntiAlias);
- string.append(DumpPipelineInfo(*this->pipeline()));
- string.append(INHERITED::dumpInfo());
+ string += fHelper.dumpInfo();
+ string += INHERITED::dumpInfo();
return string;
}
-private:
- void getProcessorAnalysisInputs(GrProcessorAnalysisColor* color,
- GrProcessorAnalysisCoverage* coverage) const override {
- color->setToConstant(fColor);
- *coverage = GrProcessorAnalysisCoverage::kSingleChannel;
+ TessellatingPathOp(Helper::MakeArgs helperArgs,
+ GrColor color,
+ const GrShape& shape,
+ const SkMatrix& viewMatrix,
+ const SkIRect& devClipBounds,
+ GrAAType aaType,
+ const GrUserStencilSettings* stencilSettings)
+ : INHERITED(ClassID())
+ , fHelper(helperArgs, aaType, stencilSettings)
+ , fColor(color)
+ , fShape(shape)
+ , fViewMatrix(viewMatrix)
+ , fDevClipBounds(devClipBounds)
+ , fAntiAlias(GrAAType::kCoverage == aaType) {
+ SkRect devBounds;
+ viewMatrix.mapRect(&devBounds, shape.bounds());
+ if (shape.inverseFilled()) {
+ // Because the clip bounds are used to add a contour for inverse fills, they must also
+ // include the path bounds.
+ devBounds.join(SkRect::Make(fDevClipBounds));
+ }
+ this->setBounds(devBounds, HasAABloat::kNo, IsZeroArea::kNo);
}
- void applyPipelineOptimizations(const PipelineOptimizations& optimizations) override {
- optimizations.getOverrideColorIfSet(&fColor);
- fCanTweakAlphaForCoverage = optimizations.canTweakAlphaForCoverage();
- fNeedsLocalCoords = optimizations.readsLocalCoords();
+ FixedFunctionFlags fixedFunctionFlags() const override { return fHelper.fixedFunctionFlags(); }
+
+ RequiresDstTexture finalize(const GrCaps& caps, const GrAppliedClip* clip) override {
+ GrProcessorAnalysisCoverage coverage = fAntiAlias
+ ? GrProcessorAnalysisCoverage::kSingleChannel
+ : GrProcessorAnalysisCoverage::kNone;
+ return fHelper.xpRequiresDstTexture(caps, clip, coverage, &fColor);
}
+private:
SkPath getPath() const {
SkASSERT(!fShape.style().applies());
SkPath path;
@@ -260,9 +288,9 @@ private:
SkScalar tol = GrPathUtils::kDefaultTolerance;
bool isLinear;
DynamicVertexAllocator allocator(gp->getVertexStride(), target);
- int count = GrTessellator::PathToTriangles(path, tol, clipBounds, &allocator,
- true, fColor, fCanTweakAlphaForCoverage,
- &isLinear);
+ int count =
+ GrTessellator::PathToTriangles(path, tol, clipBounds, &allocator, true, fColor,
+ fHelper.compatibleWithAlphaAsCoverage(), &isLinear);
if (count == 0) {
return;
}
@@ -275,13 +303,13 @@ private:
using namespace GrDefaultGeoProcFactory;
Color color(fColor);
- LocalCoords::Type localCoordsType = fNeedsLocalCoords
+ LocalCoords::Type localCoordsType = fHelper.usesLocalCoords()
? LocalCoords::kUsePosition_Type
: LocalCoords::kUnused_Type;
Coverage::Type coverageType;
if (fAntiAlias) {
color = Color(Color::kPremulGrColorAttribute_Type);
- if (fCanTweakAlphaForCoverage) {
+ if (fHelper.compatibleWithAlphaAsCoverage()) {
coverageType = Coverage::kSolid_Type;
} else {
coverageType = Coverage::kAttribute_Type;
@@ -312,43 +340,23 @@ private:
GrMesh mesh(TESSELLATOR_WIREFRAME ? GrPrimitiveType::kLines : GrPrimitiveType::kTriangles);
mesh.setNonIndexedNonInstanced(count);
mesh.setVertexData(vb, firstVertex);
- target->draw(gp, this->pipeline(), mesh);
+ target->draw(gp, fHelper.makePipeline(target), mesh);
}
bool onCombineIfPossible(GrOp*, const GrCaps&) override { return false; }
- TessellatingPathOp(const GrColor& color,
- const GrShape& shape,
- const SkMatrix& viewMatrix,
- const SkIRect& devClipBounds,
- bool antiAlias)
- : INHERITED(ClassID())
- , fColor(color)
- , fShape(shape)
- , fViewMatrix(viewMatrix)
- , fDevClipBounds(devClipBounds)
- , fAntiAlias(antiAlias) {
- SkRect devBounds;
- viewMatrix.mapRect(&devBounds, shape.bounds());
- if (shape.inverseFilled()) {
- // Because the clip bounds are used to add a contour for inverse fills, they must also
- // include the path bounds.
- devBounds.join(SkRect::Make(fDevClipBounds));
- }
- this->setBounds(devBounds, HasAABloat::kNo, IsZeroArea::kNo);
- }
-
+ Helper fHelper;
GrColor fColor;
GrShape fShape;
SkMatrix fViewMatrix;
SkIRect fDevClipBounds;
bool fAntiAlias;
- bool fCanTweakAlphaForCoverage;
- bool fNeedsLocalCoords;
- typedef GrLegacyMeshDrawOp INHERITED;
+ typedef GrMeshDrawOp INHERITED;
};
+} // anonymous namespace
+
bool GrTessellatingPathRenderer::onDrawPath(const DrawPathArgs& args) {
GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
"GrTessellatingPathRenderer::onDrawPath");
@@ -356,16 +364,13 @@ bool GrTessellatingPathRenderer::onDrawPath(const DrawPathArgs& args) {
args.fClip->getConservativeBounds(args.fRenderTargetContext->width(),
args.fRenderTargetContext->height(),
&clipBoundsI);
- std::unique_ptr<GrLegacyMeshDrawOp> op =
- TessellatingPathOp::Make(args.fPaint.getColor(),
- *args.fShape,
- *args.fViewMatrix,
- clipBoundsI,
- GrAAType::kCoverage == args.fAAType);
- GrPipelineBuilder pipelineBuilder(std::move(args.fPaint), args.fAAType);
- pipelineBuilder.setUserStencil(args.fUserStencilSettings);
- args.fRenderTargetContext->addLegacyMeshDrawOp(std::move(pipelineBuilder), *args.fClip,
- std::move(op));
+ std::unique_ptr<GrDrawOp> op = TessellatingPathOp::Make(std::move(args.fPaint),
+ *args.fShape,
+ *args.fViewMatrix,
+ clipBoundsI,
+ args.fAAType,
+ args.fUserStencilSettings);
+ args.fRenderTargetContext->addDrawOp(*args.fClip, std::move(op));
return true;
}
@@ -373,20 +378,21 @@ bool GrTessellatingPathRenderer::onDrawPath(const DrawPathArgs& args) {
#if GR_TEST_UTILS
-GR_LEGACY_MESH_DRAW_OP_TEST_DEFINE(TesselatingPathOp) {
- GrColor color = GrRandomColor(random);
+GR_DRAW_OP_TEST_DEFINE(TesselatingPathOp) {
SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random);
SkPath path = GrTest::TestPath(random);
SkIRect devClipBounds = SkIRect::MakeLTRB(
random->nextU(), random->nextU(), random->nextU(), random->nextU());
devClipBounds.sort();
- bool antiAlias = random->nextBool();
+ static constexpr GrAAType kAATypes[] = {GrAAType::kNone, GrAAType::kMSAA, GrAAType::kCoverage};
+ GrAAType aaType = kAATypes[random->nextULessThan(SK_ARRAY_COUNT(kAATypes))];
GrStyle style;
do {
GrTest::TestStyle(random, &style);
} while (!style.isSimpleFill());
GrShape shape(path, style);
- return TessellatingPathOp::Make(color, shape, viewMatrix, devClipBounds, antiAlias);
+ return TessellatingPathOp::Make(std::move(paint), shape, viewMatrix, devClipBounds, aaType,
+ GrGetRandomStencil(random, context));
}
#endif
diff --git a/tools/gpu/GrTest.cpp b/tools/gpu/GrTest.cpp
index ec8af81f94..9925630e10 100644
--- a/tools/gpu/GrTest.cpp
+++ b/tools/gpu/GrTest.cpp
@@ -319,7 +319,6 @@ LEGACY_MESH_DRAW_OP_TEST_EXTERN(DashOp);
LEGACY_MESH_DRAW_OP_TEST_EXTERN(DefaultPathOp);
LEGACY_MESH_DRAW_OP_TEST_EXTERN(GrDrawAtlasOp);
LEGACY_MESH_DRAW_OP_TEST_EXTERN(SmallPathOp);
-LEGACY_MESH_DRAW_OP_TEST_EXTERN(TesselatingPathOp);
LEGACY_MESH_DRAW_OP_TEST_EXTERN(TextBlobOp);
LEGACY_MESH_DRAW_OP_TEST_EXTERN(VerticesOp);
@@ -333,6 +332,7 @@ DRAW_OP_TEST_EXTERN(EllipseOp);
DRAW_OP_TEST_EXTERN(NonAAFillRectOp)
DRAW_OP_TEST_EXTERN(NonAAStrokeRectOp);
DRAW_OP_TEST_EXTERN(RRectOp);
+DRAW_OP_TEST_EXTERN(TesselatingPathOp);
void GrDrawRandomOp(SkRandom* random, GrRenderTargetContext* renderTargetContext, GrPaint&& paint) {
GrContext* context = renderTargetContext->surfPriv().getContext();
@@ -344,7 +344,6 @@ void GrDrawRandomOp(SkRandom* random, GrRenderTargetContext* renderTargetContext
DRAW_OP_TEST_ENTRY(DefaultPathOp),
DRAW_OP_TEST_ENTRY(GrDrawAtlasOp),
DRAW_OP_TEST_ENTRY(SmallPathOp),
- DRAW_OP_TEST_ENTRY(TesselatingPathOp),
DRAW_OP_TEST_ENTRY(TextBlobOp),
DRAW_OP_TEST_ENTRY(VerticesOp)
};
@@ -361,6 +360,7 @@ void GrDrawRandomOp(SkRandom* random, GrRenderTargetContext* renderTargetContext
DRAW_OP_TEST_ENTRY(NonAAFillRectOp),
DRAW_OP_TEST_ENTRY(NonAAStrokeRectOp),
DRAW_OP_TEST_ENTRY(RRectOp),
+ DRAW_OP_TEST_ENTRY(TesselatingPathOp),
};
static constexpr size_t kTotal = SK_ARRAY_COUNT(gLegacyFactories) + SK_ARRAY_COUNT(gFactories);