diff --git a/src/gpu/GrBatchTest.cpp b/src/gpu/GrBatchTest.cpp index 8b9227c7aa..4ff9d4fe7e 100644 --- a/src/gpu/GrBatchTest.cpp +++ b/src/gpu/GrBatchTest.cpp @@ -11,11 +11,11 @@ #ifdef GR_TEST_UTILS -DRAW_BATCH_TEST_EXTERN(AAConvexPathBatch); -DRAW_BATCH_TEST_EXTERN(AADistanceFieldPathBatch); +DRAW_BATCH_TEST_EXTERN(AAConvexPathOp); +DRAW_BATCH_TEST_EXTERN(AADistanceFieldPathOp); DRAW_BATCH_TEST_EXTERN(AAFillRectOp); DRAW_BATCH_TEST_EXTERN(AAFillRectOpLocalMatrix); -DRAW_BATCH_TEST_EXTERN(AAHairlineBatch); +DRAW_BATCH_TEST_EXTERN(AAHairlineOp); DRAW_BATCH_TEST_EXTERN(AAStrokeRectOp); DRAW_BATCH_TEST_EXTERN(AnalyticRectOp); DRAW_BATCH_TEST_EXTERN(DashBatch); @@ -31,11 +31,11 @@ DRAW_BATCH_TEST_EXTERN(TextBlobBatch); DRAW_BATCH_TEST_EXTERN(VerticesOp); static BatchTestFunc gTestBatches[] = { - DRAW_BATCH_TEST_ENTRY(AAConvexPathBatch), - DRAW_BATCH_TEST_ENTRY(AADistanceFieldPathBatch), + DRAW_BATCH_TEST_ENTRY(AAConvexPathOp), + DRAW_BATCH_TEST_ENTRY(AADistanceFieldPathOp), DRAW_BATCH_TEST_ENTRY(AAFillRectOp), DRAW_BATCH_TEST_ENTRY(AAFillRectOpLocalMatrix), - DRAW_BATCH_TEST_ENTRY(AAHairlineBatch), + DRAW_BATCH_TEST_ENTRY(AAHairlineOp), DRAW_BATCH_TEST_ENTRY(AAStrokeRectOp), DRAW_BATCH_TEST_ENTRY(AnalyticRectOp), DRAW_BATCH_TEST_ENTRY(DashBatch), diff --git a/src/gpu/batches/GrAAConvexPathRenderer.cpp b/src/gpu/batches/GrAAConvexPathRenderer.cpp index 66ec342bdb..f8282b6a71 100644 --- a/src/gpu/batches/GrAAConvexPathRenderer.cpp +++ b/src/gpu/batches/GrAAConvexPathRenderer.cpp @@ -732,23 +732,18 @@ static sk_sp create_fill_gp(bool tweakAlphaForCoverage, return MakeForDeviceSpace(color, coverage, localCoords, viewMatrix); } -class AAConvexPathBatch final : public GrMeshDrawOp { +class AAConvexPathOp final : public GrMeshDrawOp { public: DEFINE_OP_CLASS_ID - AAConvexPathBatch(GrColor color, const SkMatrix& viewMatrix, const SkPath& path) - : INHERITED(ClassID()) { - fGeoData.emplace_back(Geometry{color, viewMatrix, path}); - this->setTransformedBounds(path.getBounds(), viewMatrix, HasAABloat::kYes, - IsZeroArea::kNo); + static sk_sp Make(GrColor color, const SkMatrix& viewMatrix, const SkPath& path) { + return sk_sp(new AAConvexPathOp(color, viewMatrix, path)); } - const char* name() const override { return "AAConvexBatch"; } + const char* name() const override { return "AAConvexPathOp"; } SkString dumpInfo() const override { SkString string; - for (const auto& geo : fGeoData) { - string.appendf("Color: 0x%08x\n", geo.fColor); - } + string.appendf("Color: 0x%08x, Count: %d\n", fColor, fPaths.count()); string.append(DumpPipelineInfo(*this->pipeline())); string.append(INHERITED::dumpInfo()); return string; @@ -757,26 +752,28 @@ public: void computePipelineOptimizations(GrInitInvariantOutput* color, GrInitInvariantOutput* coverage, GrBatchToXPOverrides* overrides) const override { - // When this is called on a batch, there is only one geometry bundle - color->setKnownFourComponents(fGeoData[0].fColor); + color->setKnownFourComponents(fColor); coverage->setUnknownSingleComponent(); } private: + AAConvexPathOp(GrColor color, const SkMatrix& viewMatrix, const SkPath& path) + : INHERITED(ClassID()), fColor(color) { + fPaths.emplace_back(PathData{viewMatrix, path}); + this->setTransformedBounds(path.getBounds(), viewMatrix, HasAABloat::kYes, IsZeroArea::kNo); + } + void initBatchTracker(const GrXPOverridesForBatch& overrides) override { // Handle any color overrides if (!overrides.readsColor()) { - fGeoData[0].fColor = GrColor_ILLEGAL; + fColor = GrColor_ILLEGAL; } - overrides.getOverrideColorIfSet(&fGeoData[0].fColor); + overrides.getOverrideColorIfSet(&fColor); - // setup batch properties - fBatch.fColorIgnored = !overrides.readsColor(); - fBatch.fColor = fGeoData[0].fColor; - fBatch.fUsesLocalCoords = overrides.readsLocalCoords(); - fBatch.fCoverageIgnored = !overrides.readsCoverage(); - fBatch.fLinesOnly = SkPath::kLine_SegmentMask == fGeoData[0].fPath.getSegmentMasks(); - fBatch.fCanTweakAlphaForCoverage = overrides.canTweakAlphaForCoverage(); + fUsesLocalCoords = overrides.readsLocalCoords(); + fCoverageIgnored = !overrides.readsCoverage(); + fLinesOnly = SkPath::kLine_SegmentMask == fPaths[0].fPath.getSegmentMasks(); + fCanTweakAlphaForCoverage = overrides.canTweakAlphaForCoverage(); } void prepareLinesOnlyDraws(Target* target) const { @@ -800,12 +797,12 @@ private: GrAAConvexTessellator tess; - int instanceCount = fGeoData.count(); + int instanceCount = fPaths.count(); for (int i = 0; i < instanceCount; i++) { tess.rewind(); - const Geometry& args = fGeoData[i]; + const PathData& args = fPaths[i]; if (!tess.tessellate(args.fViewMatrix, args.fPath)) { continue; @@ -830,7 +827,7 @@ private: return; } - extract_verts(tess, verts, vertexStride, args.fColor, idxs, canTweakAlphaForCoverage); + extract_verts(tess, verts, vertexStride, fColor, idxs, canTweakAlphaForCoverage); GrMesh mesh; mesh.initIndexed(kTriangles_GrPrimitiveType, @@ -849,7 +846,7 @@ private: } #endif - int instanceCount = fGeoData.count(); + int instanceCount = fPaths.count(); SkMatrix invert; if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) { @@ -863,7 +860,7 @@ private: // TODO generate all segments for all paths and use one vertex buffer for (int i = 0; i < instanceCount; i++) { - const Geometry& args = fGeoData[i]; + const PathData& args = fPaths[i]; // We use the fact that SkPath::transform path does subdivision based on // perspective. Otherwise, we apply the view matrix when copying to the @@ -933,7 +930,7 @@ private: } bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override { - AAConvexPathBatch* that = t->cast(); + AAConvexPathOp* that = t->cast(); if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), that->bounds(), caps)) { return false; @@ -952,41 +949,36 @@ private: return false; } - // In the event of two batches, one who can tweak, one who cannot, we just fall back to - // not tweaking + // In the event of two ops, one who can tweak, one who cannot, we just fall back to not + // tweaking if (this->canTweakAlphaForCoverage() != that->canTweakAlphaForCoverage()) { - fBatch.fCanTweakAlphaForCoverage = false; + fCanTweakAlphaForCoverage = false; } - fGeoData.push_back_n(that->fGeoData.count(), that->fGeoData.begin()); + fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin()); this->joinBounds(*that); return true; } - GrColor color() const { return fBatch.fColor; } - bool linesOnly() const { return fBatch.fLinesOnly; } - bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } - bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCoverage; } - const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } - bool coverageIgnored() const { return fBatch.fCoverageIgnored; } + GrColor color() const { return fColor; } + bool linesOnly() const { return fLinesOnly; } + bool usesLocalCoords() const { return fUsesLocalCoords; } + bool canTweakAlphaForCoverage() const { return fCanTweakAlphaForCoverage; } + const SkMatrix& viewMatrix() const { return fPaths[0].fViewMatrix; } + bool coverageIgnored() const { return fCoverageIgnored; } - struct BatchTracker { - GrColor fColor; - bool fUsesLocalCoords; - bool fColorIgnored; - bool fCoverageIgnored; - bool fLinesOnly; - bool fCanTweakAlphaForCoverage; - }; + GrColor fColor; + bool fUsesLocalCoords; + bool fCoverageIgnored; + bool fLinesOnly; + bool fCanTweakAlphaForCoverage; - struct Geometry { - GrColor fColor; + struct PathData { SkMatrix fViewMatrix; SkPath fPath; }; - BatchTracker fBatch; - SkSTArray<1, Geometry, true> fGeoData; + SkSTArray<1, PathData, true> fPaths; typedef GrMeshDrawOp INHERITED; }; @@ -1000,7 +992,7 @@ bool GrAAConvexPathRenderer::onDrawPath(const DrawPathArgs& args) { SkPath path; args.fShape->asPath(&path); - sk_sp op(new AAConvexPathBatch(args.fPaint->getColor(), *args.fViewMatrix, path)); + sk_sp op = AAConvexPathOp::Make(args.fPaint->getColor(), *args.fViewMatrix, path); GrPipelineBuilder pipelineBuilder(*args.fPaint, args.fAAType); pipelineBuilder.setUserStencil(args.fUserStencilSettings); @@ -1015,12 +1007,12 @@ bool GrAAConvexPathRenderer::onDrawPath(const DrawPathArgs& args) { #ifdef GR_TEST_UTILS -DRAW_BATCH_TEST_DEFINE(AAConvexPathBatch) { +DRAW_BATCH_TEST_DEFINE(AAConvexPathOp) { GrColor color = GrRandomColor(random); SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); SkPath path = GrTest::TestPathConvex(random); - return new AAConvexPathBatch(color, viewMatrix, path); + return AAConvexPathOp::Make(color, viewMatrix, path).release(); } #endif diff --git a/src/gpu/batches/GrAADistanceFieldPathRenderer.cpp b/src/gpu/batches/GrAADistanceFieldPathRenderer.cpp index 6d0eeeaac2..569c2cd7ce 100644 --- a/src/gpu/batches/GrAADistanceFieldPathRenderer.cpp +++ b/src/gpu/batches/GrAADistanceFieldPathRenderer.cpp @@ -118,38 +118,26 @@ bool GrAADistanceFieldPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) c // padding around path bounds to allow for antialiased pixels static const SkScalar kAntiAliasPad = 1.0f; -class AADistanceFieldPathBatch final : public GrMeshDrawOp { +class AADistanceFieldPathOp final : public GrMeshDrawOp { public: DEFINE_OP_CLASS_ID - typedef GrAADistanceFieldPathRenderer::ShapeData ShapeData; - typedef SkTDynamicHash ShapeCache; - typedef GrAADistanceFieldPathRenderer::ShapeDataList ShapeDataList; + using ShapeData = GrAADistanceFieldPathRenderer::ShapeData; + using ShapeCache = SkTDynamicHash; + using ShapeDataList = GrAADistanceFieldPathRenderer::ShapeDataList; - AADistanceFieldPathBatch(GrColor color, - const GrShape& shape, - const SkMatrix& viewMatrix, - GrBatchAtlas* atlas, - ShapeCache* shapeCache, ShapeDataList* shapeList, - bool gammaCorrect) - : INHERITED(ClassID()) { - SkASSERT(shape.hasUnstyledKey()); - fBatch.fViewMatrix = viewMatrix; - fGeoData.emplace_back(Geometry{color, shape}); - - fAtlas = atlas; - fShapeCache = shapeCache; - fShapeList = shapeList; - fGammaCorrect = gammaCorrect; - - // Compute bounds - this->setTransformedBounds(shape.bounds(), viewMatrix, HasAABloat::kYes, IsZeroArea::kNo); + static sk_sp Make(GrColor color, const GrShape& shape, const SkMatrix& viewMatrix, + GrBatchAtlas* atlas, ShapeCache* shapeCache, + ShapeDataList* shapeList, bool gammaCorrect) { + return sk_sp(new AADistanceFieldPathOp(color, shape, viewMatrix, atlas, + shapeCache, shapeList, gammaCorrect)); } - const char* name() const override { return "AADistanceFieldPathBatch"; } + + const char* name() const override { return "AADistanceFieldPathOp"; } SkString dumpInfo() const override { SkString string; - for (const auto& geo : fGeoData) { + for (const auto& geo : fShapes) { string.appendf("Color: 0x%08x\n", geo.fColor); } string.append(DumpPipelineInfo(*this->pipeline())); @@ -160,22 +148,38 @@ public: void computePipelineOptimizations(GrInitInvariantOutput* color, GrInitInvariantOutput* coverage, GrBatchToXPOverrides* overrides) const override { - color->setKnownFourComponents(fGeoData[0].fColor); + color->setKnownFourComponents(fShapes[0].fColor); coverage->setUnknownSingleComponent(); } private: + AADistanceFieldPathOp(GrColor color, const GrShape& shape, const SkMatrix& viewMatrix, + GrBatchAtlas* atlas, ShapeCache* shapeCache, ShapeDataList* shapeList, + bool gammaCorrect) + : INHERITED(ClassID()) { + SkASSERT(shape.hasUnstyledKey()); + fViewMatrix = viewMatrix; + fShapes.emplace_back(Entry{color, shape}); + + fAtlas = atlas; + fShapeCache = shapeCache; + fShapeList = shapeList; + fGammaCorrect = gammaCorrect; + + // Compute bounds + this->setTransformedBounds(shape.bounds(), viewMatrix, HasAABloat::kYes, IsZeroArea::kNo); + } + void initBatchTracker(const GrXPOverridesForBatch& overrides) override { // Handle any color overrides if (!overrides.readsColor()) { - fGeoData[0].fColor = GrColor_ILLEGAL; + fShapes[0].fColor = GrColor_ILLEGAL; } - overrides.getOverrideColorIfSet(&fGeoData[0].fColor); + overrides.getOverrideColorIfSet(&fShapes[0].fColor); - // setup batch properties - fBatch.fColorIgnored = !overrides.readsColor(); - fBatch.fUsesLocalCoords = overrides.readsLocalCoords(); - fBatch.fCoverageIgnored = !overrides.readsCoverage(); + fColorIgnored = !overrides.readsColor(); + fUsesLocalCoords = overrides.readsLocalCoords(); + fCoverageIgnored = !overrides.readsCoverage(); } struct FlushInfo { @@ -187,7 +191,7 @@ private: }; void onPrepareDraws(Target* target) const override { - int instanceCount = fGeoData.count(); + int instanceCount = fShapes.count(); SkMatrix invert; if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) { @@ -234,7 +238,7 @@ private: // Pointer to the next set of vertices to write. intptr_t offset = reinterpret_cast(vertices); for (int i = 0; i < instanceCount; i++) { - const Geometry& args = fGeoData[i]; + const Entry& args = fShapes[i]; // get mip level SkScalar maxScale = this->viewMatrix().getMaxScale(); @@ -463,12 +467,12 @@ private: } } - GrColor color() const { return fGeoData[0].fColor; } - const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; } - bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } + GrColor color() const { return fShapes[0].fColor; } + const SkMatrix& viewMatrix() const { return fViewMatrix; } + bool usesLocalCoords() const { return fUsesLocalCoords; } bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override { - AADistanceFieldPathBatch* that = t->cast(); + AADistanceFieldPathOp* that = t->cast(); if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), that->bounds(), caps)) { return false; @@ -479,25 +483,22 @@ private: return false; } - fGeoData.push_back_n(that->fGeoData.count(), that->fGeoData.begin()); + fShapes.push_back_n(that->fShapes.count(), that->fShapes.begin()); this->joinBounds(*that); return true; } - struct BatchTracker { - SkMatrix fViewMatrix; - bool fUsesLocalCoords; - bool fColorIgnored; - bool fCoverageIgnored; - }; + SkMatrix fViewMatrix; + bool fUsesLocalCoords; + bool fColorIgnored; + bool fCoverageIgnored; - struct Geometry { + struct Entry { GrColor fColor; GrShape fShape; }; - BatchTracker fBatch; - SkSTArray<1, Geometry> fGeoData; + SkSTArray<1, Entry> fShapes; GrBatchAtlas* fAtlas; ShapeCache* fShapeCache; ShapeDataList* fShapeList; @@ -524,9 +525,9 @@ bool GrAADistanceFieldPathRenderer::onDrawPath(const DrawPathArgs& args) { } } - sk_sp op(new AADistanceFieldPathBatch(args.fPaint->getColor(), *args.fShape, - *args.fViewMatrix, fAtlas.get(), &fShapeCache, - &fShapeList, args.fGammaCorrect)); + sk_sp op = AADistanceFieldPathOp::Make(args.fPaint->getColor(), *args.fShape, + *args.fViewMatrix, fAtlas.get(), &fShapeCache, + &fShapeList, args.fGammaCorrect); GrPipelineBuilder pipelineBuilder(*args.fPaint, args.fAAType); pipelineBuilder.setUserStencil(args.fUserStencilSettings); @@ -581,7 +582,7 @@ struct PathTestStruct { ShapeDataList fShapeList; }; -DRAW_BATCH_TEST_DEFINE(AADistanceFieldPathBatch) { +DRAW_BATCH_TEST_DEFINE(AADistanceFieldPathOp) { static PathTestStruct gTestStruct; if (context->uniqueID() != gTestStruct.fContextID) { @@ -602,13 +603,14 @@ DRAW_BATCH_TEST_DEFINE(AADistanceFieldPathBatch) { // This path renderer only allows fill styles. GrShape shape(GrTest::TestPath(random), GrStyle::SimpleFill()); - return new AADistanceFieldPathBatch(color, - shape, - viewMatrix, - gTestStruct.fAtlas.get(), - &gTestStruct.fShapeCache, - &gTestStruct.fShapeList, - gammaCorrect); + return AADistanceFieldPathOp::Make(color, + shape, + viewMatrix, + gTestStruct.fAtlas.get(), + &gTestStruct.fShapeCache, + &gTestStruct.fShapeList, + gammaCorrect) + .release(); } #endif diff --git a/src/gpu/batches/GrAADistanceFieldPathRenderer.h b/src/gpu/batches/GrAADistanceFieldPathRenderer.h index b4c3e6c44f..37c6099db3 100644 --- a/src/gpu/batches/GrAADistanceFieldPathRenderer.h +++ b/src/gpu/batches/GrAADistanceFieldPathRenderer.h @@ -95,7 +95,7 @@ private: typedef GrPathRenderer INHERITED; - friend class AADistanceFieldPathBatch; + friend class AADistanceFieldPathOp; friend struct PathTestStruct; }; diff --git a/src/gpu/batches/GrAAHairLinePathRenderer.cpp b/src/gpu/batches/GrAAHairLinePathRenderer.cpp index 76bdf8e01d..16fc63e500 100644 --- a/src/gpu/batches/GrAAHairLinePathRenderer.cpp +++ b/src/gpu/batches/GrAAHairLinePathRenderer.cpp @@ -675,29 +675,31 @@ bool check_bounds(const SkMatrix& viewMatrix, const SkRect& devBounds, void* ver return true; } -class AAHairlineBatch final : public GrMeshDrawOp { +class AAHairlineOp final : public GrMeshDrawOp { public: DEFINE_OP_CLASS_ID - AAHairlineBatch(GrColor color, - uint8_t coverage, - const SkMatrix& viewMatrix, - const SkPath& path, - SkIRect devClipBounds) : INHERITED(ClassID()) { - fGeoData.emplace_back(Geometry{color, coverage, viewMatrix, path, devClipBounds}); + static sk_sp Make(GrColor color, + const SkMatrix& viewMatrix, + const SkPath& path, + const GrStyle& style, + const SkIRect& devClipBounds) { + SkScalar hairlineCoverage; + uint8_t newCoverage = 0xff; + if (GrPathRenderer::IsStrokeHairlineOrEquivalent(style, viewMatrix, &hairlineCoverage)) { + newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff); + } - this->setTransformedBounds(path.getBounds(), viewMatrix, HasAABloat::kYes, - IsZeroArea::kYes); + return sk_sp( + new AAHairlineOp(color, newCoverage, viewMatrix, path, devClipBounds)); } - const char* name() const override { return "AAHairlineBatch"; } + const char* name() const override { return "AAHairlineOp"; } SkString dumpInfo() const override { SkString string; - for (const auto& geo : fGeoData) { - string.appendf("Color: 0x%08x Coverage: 0x%02x\n", geo.fColor, geo.fCoverage); - } - string.append(DumpPipelineInfo(*this->pipeline())); + string.appendf("Color: 0x%08x Coverage: 0x%02x, Count: %d\n", fColor, fCoverage, + fPaths.count()); string.append(INHERITED::dumpInfo()); return string; } @@ -705,25 +707,31 @@ public: void computePipelineOptimizations(GrInitInvariantOutput* color, GrInitInvariantOutput* coverage, GrBatchToXPOverrides* overrides) const override { - // When this is called on a batch, there is only one geometry bundle - color->setKnownFourComponents(fGeoData[0].fColor); + color->setKnownFourComponents(fColor); coverage->setUnknownSingleComponent(); } private: + AAHairlineOp(GrColor color, + uint8_t coverage, + const SkMatrix& viewMatrix, + const SkPath& path, + SkIRect devClipBounds) + : INHERITED(ClassID()), fColor(color), fCoverage(coverage) { + fPaths.emplace_back(PathData{viewMatrix, path, devClipBounds}); + + this->setTransformedBounds(path.getBounds(), viewMatrix, HasAABloat::kYes, + IsZeroArea::kYes); + } + void initBatchTracker(const GrXPOverridesForBatch& overrides) override { // Handle any color overrides if (!overrides.readsColor()) { - fGeoData[0].fColor = GrColor_ILLEGAL; + fColor = GrColor_ILLEGAL; } - overrides.getOverrideColorIfSet(&fGeoData[0].fColor); + overrides.getOverrideColorIfSet(&fColor); - // setup batch properties - fBatch.fColorIgnored = !overrides.readsColor(); - fBatch.fColor = fGeoData[0].fColor; - fBatch.fUsesLocalCoords = overrides.readsLocalCoords(); - fBatch.fCoverageIgnored = !overrides.readsCoverage(); - fBatch.fCoverage = fGeoData[0].fCoverage; + fUsesLocalCoords = overrides.readsLocalCoords(); } void onPrepareDraws(Target*) const override; @@ -733,7 +741,7 @@ private: typedef SkTArray FloatArray; bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override { - AAHairlineBatch* that = t->cast(); + AAHairlineOp* that = t->cast(); if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), that->bounds(), caps)) { @@ -766,42 +774,32 @@ private: return false; } - fGeoData.push_back_n(that->fGeoData.count(), that->fGeoData.begin()); + fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin()); this->joinBounds(*that); return true; } - GrColor color() const { return fBatch.fColor; } - uint8_t coverage() const { return fBatch.fCoverage; } - bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } - const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } - bool coverageIgnored() const { return fBatch.fCoverageIgnored; } + GrColor color() const { return fColor; } + uint8_t coverage() const { return fCoverage; } + bool usesLocalCoords() const { return fUsesLocalCoords; } + const SkMatrix& viewMatrix() const { return fPaths[0].fViewMatrix; } - - struct Geometry { - GrColor fColor; - uint8_t fCoverage; + struct PathData { SkMatrix fViewMatrix; SkPath fPath; SkIRect fDevClipBounds; }; - struct BatchTracker { - GrColor fColor; - uint8_t fCoverage; - SkRect fDevBounds; - bool fUsesLocalCoords; - bool fColorIgnored; - bool fCoverageIgnored; - }; + GrColor fColor; + uint8_t fCoverage; + bool fUsesLocalCoords; - BatchTracker fBatch; - SkSTArray<1, Geometry, true> fGeoData; + SkSTArray<1, PathData, true> fPaths; typedef GrMeshDrawOp INHERITED; }; -void AAHairlineBatch::onPrepareDraws(Target* target) const { +void AAHairlineOp::onPrepareDraws(Target* target) const { // Setup the viewmatrix and localmatrix for the GrGeometryProcessor. SkMatrix invert; if (!this->viewMatrix().invert(&invert)) { @@ -829,9 +827,9 @@ void AAHairlineBatch::onPrepareDraws(Target* target) const { FloatArray cWeights; int quadCount = 0; - int instanceCount = fGeoData.count(); + int instanceCount = fPaths.count(); for (int i = 0; i < instanceCount; i++) { - const Geometry& args = fGeoData[i]; + const PathData& args = fPaths[i]; quadCount += gather_lines_and_quads(args.fPath, args.fViewMatrix, args.fDevClipBounds, &lines, &quads, &conics, &qSubdivs, &cWeights); } @@ -951,20 +949,6 @@ void AAHairlineBatch::onPrepareDraws(Target* target) const { } } -static GrDrawOp* create_hairline_batch(GrColor color, - const SkMatrix& viewMatrix, - const SkPath& path, - const GrStyle& style, - const SkIRect& devClipBounds) { - SkScalar hairlineCoverage; - uint8_t newCoverage = 0xff; - if (GrPathRenderer::IsStrokeHairlineOrEquivalent(style, viewMatrix, &hairlineCoverage)) { - newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff); - } - - return new AAHairlineBatch(color, newCoverage, viewMatrix, path, devClipBounds); -} - bool GrAAHairLinePathRenderer::onDrawPath(const DrawPathArgs& args) { GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(), "GrAAHairlinePathRenderer::onDrawPath"); @@ -974,16 +958,13 @@ bool GrAAHairLinePathRenderer::onDrawPath(const DrawPathArgs& args) { args.fClip->getConservativeBounds(args.fRenderTargetContext->width(), args.fRenderTargetContext->height(), &devClipBounds); - SkPath path; args.fShape->asPath(&path); - sk_sp op(create_hairline_batch(args.fPaint->getColor(), *args.fViewMatrix, path, - args.fShape->style(), devClipBounds)); - + sk_sp op = AAHairlineOp::Make(args.fPaint->getColor(), *args.fViewMatrix, path, + args.fShape->style(), devClipBounds); GrPipelineBuilder pipelineBuilder(*args.fPaint, args.fAAType); pipelineBuilder.setUserStencil(args.fUserStencilSettings); args.fRenderTargetContext->addDrawOp(pipelineBuilder, *args.fClip, std::move(op)); - return true; } @@ -991,13 +972,14 @@ bool GrAAHairLinePathRenderer::onDrawPath(const DrawPathArgs& args) { #ifdef GR_TEST_UTILS -DRAW_BATCH_TEST_DEFINE(AAHairlineBatch) { +DRAW_BATCH_TEST_DEFINE(AAHairlineOp) { GrColor color = GrRandomColor(random); SkMatrix viewMatrix = GrTest::TestMatrix(random); SkPath path = GrTest::TestPath(random); SkIRect devClipBounds; devClipBounds.setEmpty(); - return create_hairline_batch(color, viewMatrix, path, GrStyle::SimpleHairline(), devClipBounds); + return AAHairlineOp::Make(color, viewMatrix, path, GrStyle::SimpleHairline(), devClipBounds) + .release(); } #endif