Revert "Revert "Make TessellatingPathOp be a non-legacy GrMeshDrawOp""

This reverts commit 7343c197fc.

The initial revert was because the random test factory was choosing msaa as the aatype when the render target was not msaa, triggering and assert.

Bug: skia:
Change-Id: I1bfec86492b69af1101c65d249140af804c16684
Reviewed-on: https://skia-review.googlesource.com/22203
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2017-07-11 09:03:10 -04:00 committed by Skia Commit-Bot
parent 8593248ad8
commit 9530f7ebf5
2 changed files with 77 additions and 68 deletions

View File

@ -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;
}
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);
}
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:
void getProcessorAnalysisInputs(GrProcessorAnalysisColor* color,
GrProcessorAnalysisCoverage* coverage) const override {
color->setToConstant(fColor);
*coverage = GrProcessorAnalysisCoverage::kSingleChannel;
}
void applyPipelineOptimizations(const PipelineOptimizations& optimizations) override {
optimizations.getOverrideColorIfSet(&fColor);
fCanTweakAlphaForCoverage = optimizations.canTweakAlphaForCoverage();
fNeedsLocalCoords = optimizations.readsLocalCoords();
}
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,24 @@ 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;
do {
aaType = kAATypes[random->nextULessThan(SK_ARRAY_COUNT(kAATypes))];
} while(GrAAType::kMSAA == aaType && GrFSAAType::kUnifiedMSAA != fsaaType);
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

View File

@ -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);
@ -334,6 +333,7 @@ DRAW_OP_TEST_EXTERN(NonAAFillRectOp);
DRAW_OP_TEST_EXTERN(NonAALatticeOp);
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();
@ -345,7 +345,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)
};
@ -363,6 +362,7 @@ void GrDrawRandomOp(SkRandom* random, GrRenderTargetContext* renderTargetContext
DRAW_OP_TEST_ENTRY(NonAALatticeOp),
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);