diff options
52 files changed, 488 insertions, 448 deletions
diff --git a/gm/beziereffects.cpp b/gm/beziereffects.cpp index 17b67ee901..a53ac0e96a 100644 --- a/gm/beziereffects.cpp +++ b/gm/beziereffects.cpp @@ -38,8 +38,8 @@ public: const char* name() const override { return "BezierCubicOrConicTestBatch"; } - static GrBatch* Create(const GrGeometryProcessor* gp, const Geometry& geo, - const SkScalar klmEqs[9], SkScalar sign) { + static GrDrawBatch* Create(const GrGeometryProcessor* gp, const Geometry& geo, + const SkScalar klmEqs[9], SkScalar sign) { return SkNEW_ARGS(BezierCubicOrConicTestBatch, (gp, geo, klmEqs, sign)); } @@ -228,7 +228,7 @@ protected: geometry.fColor = color; geometry.fBounds = bounds; - SkAutoTUnref<GrBatch> batch( + SkAutoTUnref<GrDrawBatch> batch( BezierCubicOrConicTestBatch::Create(gp, geometry, klmEqs, klmSigns[c])); tt.target()->drawBatch(pipelineBuilder, batch); @@ -373,7 +373,7 @@ protected: geometry.fColor = color; geometry.fBounds = bounds; - SkAutoTUnref<GrBatch> batch( + SkAutoTUnref<GrDrawBatch> batch( BezierCubicOrConicTestBatch::Create(gp, geometry, klmEqs, 1.f)); tt.target()->drawBatch(pipelineBuilder, batch); @@ -438,8 +438,8 @@ public: const char* name() const override { return "BezierQuadTestBatch"; } - static GrBatch* Create(const GrGeometryProcessor* gp, const Geometry& geo, - const GrPathUtils::QuadUVMatrix& devToUV) { + static GrDrawBatch* Create(const GrGeometryProcessor* gp, const Geometry& geo, + const GrPathUtils::QuadUVMatrix& devToUV) { return SkNEW_ARGS(BezierQuadTestBatch, (gp, geo, devToUV)); } @@ -613,7 +613,8 @@ protected: geometry.fColor = color; geometry.fBounds = bounds; - SkAutoTUnref<GrBatch> batch(BezierQuadTestBatch::Create(gp, geometry, DevToUV)); + SkAutoTUnref<GrDrawBatch> batch(BezierQuadTestBatch::Create(gp, geometry, + DevToUV)); tt.target()->drawBatch(pipelineBuilder, batch); } diff --git a/gm/convexpolyeffect.cpp b/gm/convexpolyeffect.cpp index ba5cc5be25..1c4a0b1841 100644 --- a/gm/convexpolyeffect.cpp +++ b/gm/convexpolyeffect.cpp @@ -36,7 +36,7 @@ public: const char* name() const override { return "ConvexPolyTestBatch"; } - static GrBatch* Create(const GrGeometryProcessor* gp, const Geometry& geo) { + static GrDrawBatch* Create(const GrGeometryProcessor* gp, const Geometry& geo) { return SkNEW_ARGS(ConvexPolyTestBatch, (gp, geo)); } @@ -197,7 +197,7 @@ protected: geometry.fColor = color.fColor; geometry.fBounds = p.getBounds(); - SkAutoTUnref<GrBatch> batch(ConvexPolyTestBatch::Create(gp, geometry)); + SkAutoTUnref<GrDrawBatch> batch(ConvexPolyTestBatch::Create(gp, geometry)); tt.target()->drawBatch(pipelineBuilder, batch); @@ -246,7 +246,7 @@ protected: geometry.fColor = color.fColor; geometry.fBounds = rect; - SkAutoTUnref<GrBatch> batch(ConvexPolyTestBatch::Create(gp, geometry)); + SkAutoTUnref<GrDrawBatch> batch(ConvexPolyTestBatch::Create(gp, geometry)); tt.target()->drawBatch(pipelineBuilder, batch); diff --git a/include/gpu/GrDrawContext.h b/include/gpu/GrDrawContext.h index bb16011a46..0f6552c401 100644 --- a/include/gpu/GrDrawContext.h +++ b/include/gpu/GrDrawContext.h @@ -12,9 +12,9 @@ #include "SkRefCnt.h" #include "SkSurfaceProps.h" -class GrBatch; class GrClip; class GrContext; +class GrDrawBatch; class GrDrawTarget; class GrPaint; class GrPathProcessor; @@ -265,7 +265,7 @@ public: * @param paint describes how to color pixels. * @param batch the batch to draw */ - void drawBatch(GrRenderTarget*, const GrClip&, const GrPaint&, GrBatch*); + void drawBatch(GrRenderTarget*, const GrClip&, const GrPaint&, GrDrawBatch*); private: friend class GrAtlasTextContext; // for access to drawBatch @@ -288,7 +288,7 @@ private: // This entry point allows the GrTextContext-derived classes to add their batches to // the drawTarget. - void drawBatch(GrPipelineBuilder* pipelineBuilder, GrBatch* batch); + void drawBatch(GrPipelineBuilder* pipelineBuilder, GrDrawBatch* batch); GrContext* fContext; // owning context -> no ref GrDrawTarget* fDrawTarget; diff --git a/src/gpu/GrAAConvexPathRenderer.cpp b/src/gpu/GrAAConvexPathRenderer.cpp index b5bea9f553..ac142e2ad6 100644 --- a/src/gpu/GrAAConvexPathRenderer.cpp +++ b/src/gpu/GrAAConvexPathRenderer.cpp @@ -739,7 +739,7 @@ static const GrGeometryProcessor* create_fill_gp(bool tweakAlphaForCoverage, return CreateForDeviceSpace(color, coverage, localCoords, viewMatrix); } -class AAConvexPathBatch : public GrBatch { +class AAConvexPathBatch : public GrVertexBatch { public: struct Geometry { GrColor fColor; @@ -747,7 +747,7 @@ public: SkPath fPath; }; - static GrBatch* Create(const Geometry& geometry) { + static GrDrawBatch* Create(const Geometry& geometry) { return SkNEW_ARGS(AAConvexPathBatch, (geometry)); } @@ -941,13 +941,12 @@ private: } bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { - if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *t->pipeline(), t->bounds(), - caps)) { + AAConvexPathBatch* that = t->cast<AAConvexPathBatch>(); + if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), + that->bounds(), caps)) { return false; } - AAConvexPathBatch* that = t->cast<AAConvexPathBatch>(); - if (this->color() != that->color()) { return false; } @@ -1002,7 +1001,7 @@ bool GrAAConvexPathRenderer::onDrawPath(const DrawPathArgs& args) { geometry.fViewMatrix = *args.fViewMatrix; geometry.fPath = *args.fPath; - SkAutoTUnref<GrBatch> batch(AAConvexPathBatch::Create(geometry)); + SkAutoTUnref<GrDrawBatch> batch(AAConvexPathBatch::Create(geometry)); args.fTarget->drawBatch(*args.fPipelineBuilder, batch); return true; @@ -1013,7 +1012,7 @@ bool GrAAConvexPathRenderer::onDrawPath(const DrawPathArgs& args) { #ifdef GR_TEST_UTILS -BATCH_TEST_DEFINE(AAConvexPathBatch) { +DRAW_BATCH_TEST_DEFINE(AAConvexPathBatch) { AAConvexPathBatch::Geometry geometry; geometry.fColor = GrRandomColor(random); geometry.fViewMatrix = GrTest::TestMatrixInvertible(random); diff --git a/src/gpu/GrAADistanceFieldPathRenderer.cpp b/src/gpu/GrAADistanceFieldPathRenderer.cpp index 50116dd3cb..c4d59dddf6 100755 --- a/src/gpu/GrAADistanceFieldPathRenderer.cpp +++ b/src/gpu/GrAADistanceFieldPathRenderer.cpp @@ -109,7 +109,7 @@ bool GrAADistanceFieldPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) c // padding around path bounds to allow for antialiased pixels static const SkScalar kAntiAliasPad = 1.0f; -class AADistanceFieldPathBatch : public GrBatch { +class AADistanceFieldPathBatch : public GrVertexBatch { public: typedef GrAADistanceFieldPathRenderer::PathData PathData; typedef SkTDynamicHash<PathData, PathData::Key> PathCache; @@ -123,8 +123,8 @@ public: PathData* fPathData; }; - static GrBatch* Create(const Geometry& geometry, GrColor color, const SkMatrix& viewMatrix, - GrBatchAtlas* atlas, PathCache* pathCache, PathDataList* pathList) { + static GrDrawBatch* Create(const Geometry& geometry, GrColor color, const SkMatrix& viewMatrix, + GrBatchAtlas* atlas, PathCache* pathCache, PathDataList* pathList) { return SkNEW_ARGS(AADistanceFieldPathBatch, (geometry, color, viewMatrix, atlas, pathCache, pathList)); } @@ -485,13 +485,12 @@ private: bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { - if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *t->pipeline(), t->bounds(), - caps)) { + AADistanceFieldPathBatch* that = t->cast<AADistanceFieldPathBatch>(); + if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), + that->bounds(), caps)) { return false; } - AADistanceFieldPathBatch* that = t->cast<AADistanceFieldPathBatch>(); - // TODO we could actually probably do a bunch of this work on the CPU, ie map viewMatrix, // maybe upload color via attribute if (this->color() != that->color()) { @@ -543,9 +542,9 @@ bool GrAADistanceFieldPathRenderer::onDrawPath(const DrawPathArgs& args) { geometry.fPath = *args.fPath; geometry.fAntiAlias = args.fAntiAlias; - SkAutoTUnref<GrBatch> batch(AADistanceFieldPathBatch::Create(geometry, args.fColor, - *args.fViewMatrix, fAtlas, - &fPathCache, &fPathList)); + SkAutoTUnref<GrDrawBatch> batch(AADistanceFieldPathBatch::Create(geometry, args.fColor, + *args.fViewMatrix, fAtlas, + &fPathCache, &fPathList)); args.fTarget->drawBatch(*args.fPipelineBuilder, batch); return true; @@ -597,7 +596,7 @@ struct PathTestStruct { PathDataList fPathList; }; -BATCH_TEST_DEFINE(AADistanceFieldPathBatch) { +DRAW_BATCH_TEST_DEFINE(AADistanceFieldPathBatch) { static PathTestStruct gTestStruct; if (context->uniqueID() != gTestStruct.fContextID) { diff --git a/src/gpu/GrAAHairLinePathRenderer.cpp b/src/gpu/GrAAHairLinePathRenderer.cpp index bfdff8dd86..f65fb74689 100644 --- a/src/gpu/GrAAHairLinePathRenderer.cpp +++ b/src/gpu/GrAAHairLinePathRenderer.cpp @@ -670,7 +670,7 @@ bool check_bounds(const SkMatrix& viewMatrix, const SkRect& devBounds, void* ver return true; } -class AAHairlineBatch : public GrBatch { +class AAHairlineBatch : public GrVertexBatch { public: struct Geometry { GrColor fColor; @@ -680,7 +680,7 @@ public: SkIRect fDevClipBounds; }; - static GrBatch* Create(const Geometry& geometry) { + static GrDrawBatch* Create(const Geometry& geometry) { return SkNEW_ARGS(AAHairlineBatch, (geometry)); } @@ -732,13 +732,13 @@ private: } bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { - if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *t->pipeline(), t->bounds(), - caps)) { + AAHairlineBatch* that = t->cast<AAHairlineBatch>(); + + if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), + that->bounds(), caps)) { return false; } - AAHairlineBatch* that = t->cast<AAHairlineBatch>(); - if (this->viewMatrix().hasPerspective() != that->viewMatrix().hasPerspective()) { return false; } @@ -950,11 +950,11 @@ void AAHairlineBatch::generateGeometry(GrBatchTarget* batchTarget) { } } -static GrBatch* create_hairline_batch(GrColor color, - const SkMatrix& viewMatrix, - const SkPath& path, - const GrStrokeInfo& stroke, - const SkIRect& devClipBounds) { +static GrDrawBatch* create_hairline_batch(GrColor color, + const SkMatrix& viewMatrix, + const SkPath& path, + const GrStrokeInfo& stroke, + const SkIRect& devClipBounds) { SkScalar hairlineCoverage; uint8_t newCoverage = 0xff; if (GrPathRenderer::IsStrokeHairlineOrEquivalent(stroke, viewMatrix, &hairlineCoverage)) { @@ -976,8 +976,8 @@ bool GrAAHairLinePathRenderer::onDrawPath(const DrawPathArgs& args) { args.fPipelineBuilder->clip().getConservativeBounds(args.fPipelineBuilder->getRenderTarget(), &devClipBounds); - SkAutoTUnref<GrBatch> batch(create_hairline_batch(args.fColor, *args.fViewMatrix, *args.fPath, - *args.fStroke, devClipBounds)); + SkAutoTUnref<GrDrawBatch> batch(create_hairline_batch(args.fColor, *args.fViewMatrix, *args.fPath, + *args.fStroke, devClipBounds)); args.fTarget->drawBatch(*args.fPipelineBuilder, batch); return true; @@ -987,7 +987,7 @@ bool GrAAHairLinePathRenderer::onDrawPath(const DrawPathArgs& args) { #ifdef GR_TEST_UTILS -BATCH_TEST_DEFINE(AAHairlineBatch) { +DRAW_BATCH_TEST_DEFINE(AAHairlineBatch) { GrColor color = GrRandomColor(random); SkMatrix viewMatrix = GrTest::TestMatrix(random); GrStrokeInfo stroke(SkStrokeRec::kHairline_InitStyle); diff --git a/src/gpu/GrAALinearizingConvexPathRenderer.cpp b/src/gpu/GrAALinearizingConvexPathRenderer.cpp index d1c6355daf..a019ed9fe0 100644 --- a/src/gpu/GrAALinearizingConvexPathRenderer.cpp +++ b/src/gpu/GrAALinearizingConvexPathRenderer.cpp @@ -114,7 +114,7 @@ static const GrGeometryProcessor* create_fill_gp(bool tweakAlphaForCoverage, return CreateForDeviceSpace(color, coverage, localCoords, viewMatrix); } -class AAFlatteningConvexPathBatch : public GrBatch { +class AAFlatteningConvexPathBatch : public GrVertexBatch { public: struct Geometry { GrColor fColor; @@ -125,7 +125,7 @@ public: SkScalar fMiterLimit; }; - static GrBatch* Create(const Geometry& geometry) { + static GrDrawBatch* Create(const Geometry& geometry) { return SkNEW_ARGS(AAFlatteningConvexPathBatch, (geometry)); } @@ -265,13 +265,12 @@ private: } bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { - if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *t->pipeline(), t->bounds(), - caps)) { + AAFlatteningConvexPathBatch* that = t->cast<AAFlatteningConvexPathBatch>(); + if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), + that->bounds(), caps)) { return false; } - AAFlatteningConvexPathBatch* that = t->cast<AAFlatteningConvexPathBatch>(); - SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->viewMatrix())) { return false; @@ -321,7 +320,7 @@ bool GrAALinearizingConvexPathRenderer::onDrawPath(const DrawPathArgs& args) { args.fStroke->getJoin(); geometry.fMiterLimit = args.fStroke->getMiter(); - SkAutoTUnref<GrBatch> batch(AAFlatteningConvexPathBatch::Create(geometry)); + SkAutoTUnref<GrDrawBatch> batch(AAFlatteningConvexPathBatch::Create(geometry)); args.fTarget->drawBatch(*args.fPipelineBuilder, batch); return true; @@ -331,7 +330,7 @@ bool GrAALinearizingConvexPathRenderer::onDrawPath(const DrawPathArgs& args) { #ifdef GR_TEST_UTILS -BATCH_TEST_DEFINE(AAFlatteningConvexPathBatch) { +DRAW_BATCH_TEST_DEFINE(AAFlatteningConvexPathBatch) { AAFlatteningConvexPathBatch::Geometry geometry; geometry.fColor = GrRandomColor(random); geometry.fViewMatrix = GrTest::TestMatrixInvertible(random); diff --git a/src/gpu/GrAtlasTextContext.cpp b/src/gpu/GrAtlasTextContext.cpp index e3149ad14a..3ba32cfe9b 100644 --- a/src/gpu/GrAtlasTextContext.cpp +++ b/src/gpu/GrAtlasTextContext.cpp @@ -1432,7 +1432,7 @@ inline void GrAtlasTextContext::appendGlyphCommon(GrAtlasTextBlob* blob, Run* ru subRun->fVertexEndIndex += vertexStride * kVerticesPerGlyph; } -class TextBatch : public GrBatch { +class TextBatch : public GrVertexBatch { public: typedef GrAtlasTextContext::DistanceAdjustTable DistanceAdjustTable; typedef GrAtlasTextBlob Blob; @@ -1893,13 +1893,12 @@ private: int numGlyphs() const { return fBatch.fNumGlyphs; } bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { - if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *t->pipeline(), t->bounds(), - caps)) { + TextBatch* that = t->cast<TextBatch>(); + if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), + that->bounds(), caps)) { return false; } - TextBatch* that = t->cast<TextBatch>(); - if (fMaskType != that->fMaskType) { return false; } @@ -2087,7 +2086,7 @@ void GrAtlasTextContext::flushRunAsPaths(GrRenderTarget* rt, const SkTextBlob::R } } -inline GrBatch* +inline GrDrawBatch* GrAtlasTextContext::createBatch(GrAtlasTextBlob* cacheBlob, const PerSubRunInfo& info, int glyphCount, int run, int subRun, GrColor color, SkScalar transX, SkScalar transY, @@ -2140,9 +2139,9 @@ inline void GrAtlasTextContext::flushRun(GrPipelineBuilder* pipelineBuilder, continue; } - SkAutoTUnref<GrBatch> batch(this->createBatch(cacheBlob, info, glyphCount, run, - subRun, color, transX, transY, - skPaint)); + SkAutoTUnref<GrDrawBatch> batch(this->createBatch(cacheBlob, info, glyphCount, run, + subRun, color, transX, transY, + skPaint)); fDrawContext->drawBatch(pipelineBuilder, batch); } } @@ -2227,7 +2226,7 @@ void GrAtlasTextContext::flush(GrAtlasTextBlob* cacheBlob, #ifdef GR_TEST_UTILS -BATCH_TEST_DEFINE(TextBlobBatch) { +DRAW_BATCH_TEST_DEFINE(TextBlobBatch) { static uint32_t gContextID = SK_InvalidGenID; static GrAtlasTextContext* gTextContext = NULL; static SkSurfaceProps gSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType); diff --git a/src/gpu/GrAtlasTextContext.h b/src/gpu/GrAtlasTextContext.h index 41c5217b9b..2945b02152 100644 --- a/src/gpu/GrAtlasTextContext.h +++ b/src/gpu/GrAtlasTextContext.h @@ -18,6 +18,7 @@ #include "GrBatchTest.h" #endif +class GrDrawBatch; class GrDrawContext; class GrDrawTarget; class GrPipelineBuilder; @@ -75,10 +76,10 @@ private: const SkPaint&, SkDrawFilter*, const SkMatrix& viewMatrix, const SkIRect& clipBounds, SkScalar x, SkScalar y); - inline GrBatch* createBatch(GrAtlasTextBlob*, const PerSubRunInfo&, - int glyphCount, int run, int subRun, - GrColor, SkScalar transX, SkScalar transY, - const SkPaint&); + inline GrDrawBatch* createBatch(GrAtlasTextBlob*, const PerSubRunInfo&, + int glyphCount, int run, int subRun, + GrColor, SkScalar transX, SkScalar transY, + const SkPaint&); inline void flushRun(GrPipelineBuilder*, GrAtlasTextBlob*, int run, GrColor, SkScalar transX, SkScalar transY, const SkPaint&); inline void flushBigGlyphs(GrAtlasTextBlob* cacheBlob, GrRenderTarget*, @@ -186,7 +187,7 @@ private: friend class TextBatch; #ifdef GR_TEST_UTILS - BATCH_TEST_FRIEND(TextBlobBatch); + DRAW_BATCH_TEST_FRIEND(TextBlobBatch); #endif typedef GrTextContext INHERITED; diff --git a/src/gpu/GrBatchTest.cpp b/src/gpu/GrBatchTest.cpp index 181f0e684a..1fc2ce85d9 100644 --- a/src/gpu/GrBatchTest.cpp +++ b/src/gpu/GrBatchTest.cpp @@ -11,45 +11,45 @@ #ifdef GR_TEST_UTILS -BATCH_TEST_EXTERN(AAConvexPathBatch); -BATCH_TEST_EXTERN(AADistanceFieldPathBatch); -BATCH_TEST_EXTERN(AAFillRectBatch); -BATCH_TEST_EXTERN(AAFillRectBatchLocalMatrix); -BATCH_TEST_EXTERN(AAHairlineBatch); -BATCH_TEST_EXTERN(AAStrokeRectBatch); -BATCH_TEST_EXTERN(DashBatch); -BATCH_TEST_EXTERN(DefaultPathBatch); -BATCH_TEST_EXTERN(CircleBatch); -BATCH_TEST_EXTERN(DIEllipseBatch); -BATCH_TEST_EXTERN(EllipseBatch); -BATCH_TEST_EXTERN(GrDrawAtlasBatch); -BATCH_TEST_EXTERN(GrStrokeRectBatch); -BATCH_TEST_EXTERN(RRectBatch); -BATCH_TEST_EXTERN(TesselatingPathBatch); -BATCH_TEST_EXTERN(TextBlobBatch); -BATCH_TEST_EXTERN(VerticesBatch); +DRAW_BATCH_TEST_EXTERN(AAConvexPathBatch); +DRAW_BATCH_TEST_EXTERN(AADistanceFieldPathBatch); +DRAW_BATCH_TEST_EXTERN(AAFillRectBatch); +DRAW_BATCH_TEST_EXTERN(AAFillRectBatchLocalMatrix); +DRAW_BATCH_TEST_EXTERN(AAHairlineBatch); +DRAW_BATCH_TEST_EXTERN(AAStrokeRectBatch); +DRAW_BATCH_TEST_EXTERN(DashBatch); +DRAW_BATCH_TEST_EXTERN(DefaultPathBatch); +DRAW_BATCH_TEST_EXTERN(CircleBatch); +DRAW_BATCH_TEST_EXTERN(DIEllipseBatch); +DRAW_BATCH_TEST_EXTERN(EllipseBatch); +DRAW_BATCH_TEST_EXTERN(GrDrawAtlasBatch); +DRAW_BATCH_TEST_EXTERN(GrStrokeRectBatch); +DRAW_BATCH_TEST_EXTERN(RRectBatch); +DRAW_BATCH_TEST_EXTERN(TesselatingPathBatch); +DRAW_BATCH_TEST_EXTERN(TextBlobBatch); +DRAW_BATCH_TEST_EXTERN(VerticesBatch); static BatchTestFunc gTestBatches[] = { - BATCH_TEST_ENTRY(AAConvexPathBatch), - BATCH_TEST_ENTRY(AADistanceFieldPathBatch), - BATCH_TEST_ENTRY(AAFillRectBatch), - BATCH_TEST_ENTRY(AAFillRectBatchLocalMatrix), - BATCH_TEST_ENTRY(AAHairlineBatch), - BATCH_TEST_ENTRY(AAStrokeRectBatch), - BATCH_TEST_ENTRY(DashBatch), - BATCH_TEST_ENTRY(DefaultPathBatch), - BATCH_TEST_ENTRY(CircleBatch), - BATCH_TEST_ENTRY(DIEllipseBatch), - BATCH_TEST_ENTRY(EllipseBatch), - BATCH_TEST_ENTRY(GrDrawAtlasBatch), - BATCH_TEST_ENTRY(GrStrokeRectBatch), - BATCH_TEST_ENTRY(RRectBatch), - BATCH_TEST_ENTRY(TesselatingPathBatch), - BATCH_TEST_ENTRY(TextBlobBatch), - BATCH_TEST_ENTRY(VerticesBatch) + DRAW_BATCH_TEST_ENTRY(AAConvexPathBatch), + DRAW_BATCH_TEST_ENTRY(AADistanceFieldPathBatch), + DRAW_BATCH_TEST_ENTRY(AAFillRectBatch), + DRAW_BATCH_TEST_ENTRY(AAFillRectBatchLocalMatrix), + DRAW_BATCH_TEST_ENTRY(AAHairlineBatch), + DRAW_BATCH_TEST_ENTRY(AAStrokeRectBatch), + DRAW_BATCH_TEST_ENTRY(DashBatch), + DRAW_BATCH_TEST_ENTRY(DefaultPathBatch), + DRAW_BATCH_TEST_ENTRY(CircleBatch), + DRAW_BATCH_TEST_ENTRY(DIEllipseBatch), + DRAW_BATCH_TEST_ENTRY(EllipseBatch), + DRAW_BATCH_TEST_ENTRY(GrDrawAtlasBatch), + DRAW_BATCH_TEST_ENTRY(GrStrokeRectBatch), + DRAW_BATCH_TEST_ENTRY(RRectBatch), + DRAW_BATCH_TEST_ENTRY(TesselatingPathBatch), + DRAW_BATCH_TEST_ENTRY(TextBlobBatch), + DRAW_BATCH_TEST_ENTRY(VerticesBatch) }; -GrBatch* GrRandomBatch(SkRandom* random, GrContext* context) { +GrDrawBatch* GrRandomDrawBatch(SkRandom* random, GrContext* context) { uint32_t index = random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gTestBatches))); BatchTestFunc func = gTestBatches[index]; return (*func)(random, context); diff --git a/src/gpu/GrBatchTest.h b/src/gpu/GrBatchTest.h index 9daa9609ce..32e8e28930 100644 --- a/src/gpu/GrBatchTest.h +++ b/src/gpu/GrBatchTest.h @@ -12,7 +12,7 @@ #ifdef GR_TEST_UTILS -class GrBatch; +class GrDrawBatch; class GrContext; class SkRandom; @@ -21,19 +21,19 @@ class SkRandom; * are generally useful for GrBatch testing */ -// Batches should define test functions using BATCH_TEST_DEFINE. The other macros defined below -// are used exclusively by the test harness. -typedef GrBatch* (*BatchTestFunc)(SkRandom* random, GrContext* context); -#define BATCH_TEST_DEFINE(Batch) \ - GrBatch* Batch##__Test(SkRandom* random, GrContext* context) -#define BATCH_TEST_EXTERN(Batch) \ - extern GrBatch* Batch##__Test(SkRandom*, GrContext* context); -#define BATCH_TEST_ENTRY(Batch) \ +// Batches should define test functions using DRAW_BATCH_TEST_DEFINE. The other macros defined +// below are used exclusively by the test harness. +typedef GrDrawBatch* (*BatchTestFunc)(SkRandom* random, GrContext* context); +#define DRAW_BATCH_TEST_DEFINE(Batch) \ + GrDrawBatch* Batch##__Test(SkRandom* random, GrContext* context) +#define DRAW_BATCH_TEST_EXTERN(Batch) \ + extern GrDrawBatch* Batch##__Test(SkRandom*, GrContext* context); +#define DRAW_BATCH_TEST_ENTRY(Batch) \ Batch##__Test -#define BATCH_TEST_FRIEND(Batch) \ - friend GrBatch* Batch##__Test(SkRandom* random, GrContext* context); +#define DRAW_BATCH_TEST_FRIEND(Batch) \ + friend GrDrawBatch* Batch##__Test(SkRandom* random, GrContext* context); -GrBatch* GrRandomBatch(SkRandom*, GrContext*); +GrDrawBatch* GrRandomDrawBatch(SkRandom*, GrContext*); #endif #endif diff --git a/src/gpu/GrBufferedDrawTarget.cpp b/src/gpu/GrBufferedDrawTarget.cpp index e33950bf08..36542a1127 100644 --- a/src/gpu/GrBufferedDrawTarget.cpp +++ b/src/gpu/GrBufferedDrawTarget.cpp @@ -26,7 +26,7 @@ GrBufferedDrawTarget::~GrBufferedDrawTarget() { this->reset(); } -void GrBufferedDrawTarget::onDrawBatch(GrBatch* batch) { +void GrBufferedDrawTarget::onDrawBatch(GrDrawBatch* batch) { fCommands->recordDrawBatch(batch, *this->caps()); } diff --git a/src/gpu/GrBufferedDrawTarget.h b/src/gpu/GrBufferedDrawTarget.h index cc5e0e33fe..bb7fd89a2c 100644 --- a/src/gpu/GrBufferedDrawTarget.h +++ b/src/gpu/GrBufferedDrawTarget.h @@ -78,7 +78,7 @@ private: void onFlush() override; // overrides from GrDrawTarget - void onDrawBatch(GrBatch*) override; + void onDrawBatch(GrDrawBatch*) override; void onStencilPath(const GrPipelineBuilder&, const GrPathProcessor*, const GrPath*, @@ -109,7 +109,7 @@ private: StateForPathDraw* SK_WARN_UNUSED_RESULT createStateForPathDraw( const GrPrimitiveProcessor*, - const GrDrawTarget::PipelineInfo&, + const PipelineInfo&, GrPipelineOptimizations* opts); // TODO: Use a single allocator for commands and records diff --git a/src/gpu/GrCommandBuilder.h b/src/gpu/GrCommandBuilder.h index 8d8e11c9f6..95fd8ec201 100644 --- a/src/gpu/GrCommandBuilder.h +++ b/src/gpu/GrCommandBuilder.h @@ -28,7 +28,7 @@ public: bool insideClip, GrRenderTarget* renderTarget); virtual Cmd* recordDiscard(GrRenderTarget*); - virtual Cmd* recordDrawBatch(GrBatch*, const GrCaps&) = 0; + virtual Cmd* recordDrawBatch(GrDrawBatch*, const GrCaps&) = 0; virtual Cmd* recordStencilPath(const GrPipelineBuilder&, const GrPathProcessor*, const GrPath*, diff --git a/src/gpu/GrDefaultPathRenderer.cpp b/src/gpu/GrDefaultPathRenderer.cpp index 1dd9deb891..5353877769 100644 --- a/src/gpu/GrDefaultPathRenderer.cpp +++ b/src/gpu/GrDefaultPathRenderer.cpp @@ -209,7 +209,7 @@ static inline void add_quad(SkPoint** vert, const SkPoint* base, const SkPoint p } } -class DefaultPathBatch : public GrBatch { +class DefaultPathBatch : public GrVertexBatch { public: struct Geometry { GrColor fColor; @@ -217,8 +217,9 @@ public: SkScalar fTolerance; }; - static GrBatch* Create(const Geometry& geometry, uint8_t coverage, const SkMatrix& viewMatrix, - bool isHairline, const SkRect& devBounds) { + static GrDrawBatch* Create(const Geometry& geometry, uint8_t coverage, + const SkMatrix& viewMatrix, bool isHairline, + const SkRect& devBounds) { return SkNEW_ARGS(DefaultPathBatch, (geometry, coverage, viewMatrix, isHairline, devBounds)); } @@ -387,13 +388,12 @@ private: } bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { - if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *t->pipeline(), t->bounds(), - caps)) { + DefaultPathBatch* that = t->cast<DefaultPathBatch>(); + if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), + that->bounds(), caps)) { return false; } - DefaultPathBatch* that = t->cast<DefaultPathBatch>(); - if (this->color() != that->color()) { return false; } @@ -697,8 +697,9 @@ bool GrDefaultPathRenderer::internalDrawPath(GrDrawTarget* target, geometry.fPath = path; geometry.fTolerance = srcSpaceTol; - SkAutoTUnref<GrBatch> batch(DefaultPathBatch::Create(geometry, newCoverage, viewMatrix, - isHairline, devBounds)); + SkAutoTUnref<GrDrawBatch> batch(DefaultPathBatch::Create(geometry, newCoverage, + viewMatrix, isHairline, + devBounds)); target->drawBatch(*pipelineBuilder, batch); } @@ -734,7 +735,7 @@ void GrDefaultPathRenderer::onStencilPath(const StencilPathArgs& args) { #ifdef GR_TEST_UTILS -BATCH_TEST_DEFINE(DefaultPathBatch) { +DRAW_BATCH_TEST_DEFINE(DefaultPathBatch) { GrColor color = GrRandomColor(random); SkMatrix viewMatrix = GrTest::TestMatrix(random); diff --git a/src/gpu/GrDrawContext.cpp b/src/gpu/GrDrawContext.cpp index c4716196b9..3033611146 100644 --- a/src/gpu/GrDrawContext.cpp +++ b/src/gpu/GrDrawContext.cpp @@ -304,7 +304,7 @@ void GrDrawContext::drawRect(GrRenderTarget* rt, width, viewMatrix, color); if (doAA) { - SkAutoTUnref<GrBatch> batch; + SkAutoTUnref<GrDrawBatch> batch; if (width >= 0) { batch.reset(GrRectBatchFactory::CreateStrokeAA(color, viewMatrix, rect, devBoundRect, *strokeInfo)); @@ -318,8 +318,8 @@ void GrDrawContext::drawRect(GrRenderTarget* rt, if (width >= 0) { // Non-AA hairlines are snapped to pixel centers to make which pixels are hit deterministic bool snapToPixelCenters = (0 == width && !rt->isUnifiedMultisampled()); - SkAutoTUnref<GrBatch> batch(GrRectBatchFactory::CreateStrokeBW(color, viewMatrix, rect, - width, snapToPixelCenters)); + SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateStrokeBW( + color, viewMatrix, rect, width, snapToPixelCenters)); // Depending on sub-pixel coordinates and the particular GPU, we may lose a corner of // hairline rects. We jam all the vertices to pixel centers to avoid this, but not when MSAA @@ -391,10 +391,10 @@ void GrDrawContext::drawVertices(GrRenderTarget* rt, GrDrawVerticesBatch::Geometry geometry; geometry.fColor = paint.getColor(); - SkAutoTUnref<GrBatch> batch(GrDrawVerticesBatch::Create(geometry, primitiveType, viewMatrix, - positions, vertexCount, indices, - indexCount, colors, texCoords, - bounds)); + SkAutoTUnref<GrDrawBatch> batch(GrDrawVerticesBatch::Create(geometry, primitiveType, viewMatrix, + positions, vertexCount, indices, + indexCount, colors, texCoords, + bounds)); fDrawTarget->drawBatch(pipelineBuilder, batch); } @@ -419,8 +419,8 @@ void GrDrawContext::drawAtlas(GrRenderTarget* rt, GrDrawAtlasBatch::Geometry geometry; geometry.fColor = paint.getColor(); - SkAutoTUnref<GrBatch> batch(GrDrawAtlasBatch::Create(geometry, viewMatrix, spriteCount, - xform, texRect, colors)); + SkAutoTUnref<GrDrawBatch> batch(GrDrawAtlasBatch::Create(geometry, viewMatrix, spriteCount, + xform, texRect, colors)); fDrawTarget->drawBatch(pipelineBuilder, batch); } @@ -601,7 +601,7 @@ static bool is_nested_rects(const SkMatrix& viewMatrix, } void GrDrawContext::drawBatch(GrRenderTarget* rt, const GrClip& clip, - const GrPaint& paint, GrBatch* batch) { + const GrPaint& paint, GrDrawBatch* batch) { RETURN_IF_ABANDONED AutoCheckFlush acf(fContext); @@ -649,9 +649,8 @@ void GrDrawContext::drawPath(GrRenderTarget* rt, SkRect rects[2]; if (is_nested_rects(viewMatrix, path, strokeInfo, rects)) { - SkAutoTUnref<GrBatch> batch(GrRectBatchFactory::CreateFillNestedRectsAA(color, - viewMatrix, - rects)); + SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateFillNestedRectsAA( + color, viewMatrix, rects)); fDrawTarget->drawBatch(pipelineBuilder, batch); return; } @@ -772,6 +771,6 @@ bool GrDrawContext::prepareToDraw(GrRenderTarget* rt) { return true; } -void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrBatch* batch) { +void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrDrawBatch* batch) { fDrawTarget->drawBatch(*pipelineBuilder, batch); } diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp index 6f01a2ff21..985254e668 100644 --- a/src/gpu/GrDrawTarget.cpp +++ b/src/gpu/GrDrawTarget.cpp @@ -125,7 +125,7 @@ void GrDrawTarget::flush() { this->reset(); } -void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, GrBatch* batch) { +void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, GrDrawBatch* batch) { // TODO some kind of checkdraw, but not at this level // Setup clip @@ -295,8 +295,8 @@ void GrDrawTarget::drawBWRect(const GrPipelineBuilder& pipelineBuilder, const SkRect& rect, const SkRect* localRect, const SkMatrix* localMatrix) { - SkAutoTUnref<GrBatch> batch(GrRectBatchFactory::CreateFillBW(color, viewMatrix, rect, localRect, - localMatrix)); + SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateFillBW(color, viewMatrix, rect, + localRect, localMatrix)); this->drawBatch(pipelineBuilder, batch); } @@ -305,7 +305,8 @@ void GrDrawTarget::drawAARect(const GrPipelineBuilder& pipelineBuilder, const SkMatrix& viewMatrix, const SkRect& rect, const SkRect& devRect) { - SkAutoTUnref<GrBatch> batch(GrRectBatchFactory::CreateFillAA(color, viewMatrix, rect, devRect)); + SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateFillAA(color, viewMatrix, rect, + devRect)); this->drawBatch(pipelineBuilder, batch); } @@ -480,7 +481,7 @@ GrDrawTarget::PipelineInfo::PipelineInfo(const GrPipelineBuilder* pipelineBuilde GrDrawTarget::PipelineInfo::PipelineInfo(const GrPipelineBuilder* pipelineBuilder, const GrScissorState* scissor, - const GrBatch* batch, + const GrDrawBatch* batch, const SkRect* devBounds, GrDrawTarget* target) { fArgs.fPipelineBuilder = pipelineBuilder; diff --git a/src/gpu/GrDrawTarget.h b/src/gpu/GrDrawTarget.h index c7a39e3bd3..d552d39008 100644 --- a/src/gpu/GrDrawTarget.h +++ b/src/gpu/GrDrawTarget.h @@ -34,6 +34,7 @@ class GrClip; class GrCaps; class GrPath; class GrPathRange; +class GrDrawBatch; class GrDrawTarget : public SkRefCnt { public: @@ -66,7 +67,7 @@ public: */ const GrCaps* caps() const { return fCaps; } - void drawBatch(const GrPipelineBuilder&, GrBatch*); + void drawBatch(const GrPipelineBuilder&, GrDrawBatch*); /** * Draws path into the stencil buffer. The fill must be either even/odd or @@ -206,7 +207,7 @@ public: const SkRect* devBounds, GrDrawTarget* target); PipelineInfo(const GrPipelineBuilder* pipelineBuilder, const GrScissorState* scissor, - const GrBatch* batch, const SkRect* devBounds, + const GrDrawBatch* batch, const SkRect* devBounds, GrDrawTarget* target); bool valid() const { return SkToBool(fArgs.fPipelineBuilder); } @@ -241,7 +242,7 @@ private: virtual void onFlush() = 0; - virtual void onDrawBatch(GrBatch*) = 0; + virtual void onDrawBatch(GrDrawBatch*) = 0; virtual void onStencilPath(const GrPipelineBuilder&, const GrPathProcessor*, const GrPath*, diff --git a/src/gpu/GrImmediateDrawTarget.cpp b/src/gpu/GrImmediateDrawTarget.cpp index 999446f0a4..3bff379cad 100644 --- a/src/gpu/GrImmediateDrawTarget.cpp +++ b/src/gpu/GrImmediateDrawTarget.cpp @@ -25,14 +25,17 @@ GrImmediateDrawTarget::~GrImmediateDrawTarget() { this->reset(); } -void GrImmediateDrawTarget::onDrawBatch(GrBatch* batch) { +void GrImmediateDrawTarget::onDrawBatch(GrDrawBatch* batch) { fBatchTarget.resetNumberOfDraws(); - batch->generateGeometry(&fBatchTarget); - batch->setNumberOfDraws(fBatchTarget.numberOfDraws()); + // TODO: encapsulate the specialization of GrVertexBatch in GrVertexBatch so that we can + // remove this cast. Currently all GrDrawBatches are in fact GrVertexBatch. + GrVertexBatch* vertexBatch = static_cast<GrVertexBatch*>(batch); + vertexBatch->generateGeometry(&fBatchTarget); + vertexBatch->setNumberOfDraws(fBatchTarget.numberOfDraws()); fBatchTarget.preFlush(); - fBatchTarget.flushNext(batch->numberOfDraws()); + fBatchTarget.flushNext(vertexBatch->numberOfDraws()); fBatchTarget.postFlush(); } diff --git a/src/gpu/GrImmediateDrawTarget.h b/src/gpu/GrImmediateDrawTarget.h index 997a31b594..e7ec287c4c 100644 --- a/src/gpu/GrImmediateDrawTarget.h +++ b/src/gpu/GrImmediateDrawTarget.h @@ -37,7 +37,7 @@ private: void onFlush() override; // overrides from GrDrawTarget - void onDrawBatch(GrBatch*) override; + void onDrawBatch(GrDrawBatch*) override; void onStencilPath(const GrPipelineBuilder&, const GrPathProcessor*, const GrPath*, diff --git a/src/gpu/GrInOrderCommandBuilder.cpp b/src/gpu/GrInOrderCommandBuilder.cpp index 208161ddae..31fc6a2580 100644 --- a/src/gpu/GrInOrderCommandBuilder.cpp +++ b/src/gpu/GrInOrderCommandBuilder.cpp @@ -25,7 +25,7 @@ static bool path_fill_type_is_winding(const GrStencilSettings& pathStencilSettin return isWinding; } -GrTargetCommands::Cmd* GrInOrderCommandBuilder::recordDrawBatch(GrBatch* batch, +GrTargetCommands::Cmd* GrInOrderCommandBuilder::recordDrawBatch(GrDrawBatch* batch, const GrCaps& caps) { GrBATCH_INFO("In-Recording (%s, %u)\n", batch->name(), batch->uniqueID()); if (!this->cmdBuffer()->empty() && diff --git a/src/gpu/GrInOrderCommandBuilder.h b/src/gpu/GrInOrderCommandBuilder.h index 7e16c948f5..2908e10449 100644 --- a/src/gpu/GrInOrderCommandBuilder.h +++ b/src/gpu/GrInOrderCommandBuilder.h @@ -17,7 +17,7 @@ public: GrInOrderCommandBuilder(GrGpu* gpu) : INHERITED(gpu) { } - Cmd* recordDrawBatch(GrBatch*, const GrCaps&) override; + Cmd* recordDrawBatch(GrDrawBatch*, const GrCaps&) override; Cmd* recordStencilPath(const GrPipelineBuilder&, const GrPathProcessor*, const GrPath*, diff --git a/src/gpu/GrOvalRenderer.cpp b/src/gpu/GrOvalRenderer.cpp index fa51bb2379..7b33afdd2f 100644 --- a/src/gpu/GrOvalRenderer.cpp +++ b/src/gpu/GrOvalRenderer.cpp @@ -625,7 +625,7 @@ bool GrOvalRenderer::DrawOval(GrDrawTarget* target, /////////////////////////////////////////////////////////////////////////////// -class CircleBatch : public GrBatch { +class CircleBatch : public GrVertexBatch { public: struct Geometry { GrColor fColor; @@ -636,7 +636,9 @@ public: SkRect fDevBounds; }; - static GrBatch* Create(const Geometry& geometry) { return SkNEW_ARGS(CircleBatch, (geometry)); } + static GrDrawBatch* Create(const Geometry& geometry) { + return SkNEW_ARGS(CircleBatch, (geometry)); + } const char* name() const override { return "CircleBatch"; } @@ -734,13 +736,12 @@ private: } bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { - if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *t->pipeline(), t->bounds(), - caps)) { + CircleBatch* that = t->cast<CircleBatch>(); + if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), + that->bounds(), caps)) { return false; } - CircleBatch* that = t->cast<CircleBatch>(); - // TODO use vertex color to avoid breaking batches if (this->color() != that->color()) { return false; @@ -777,11 +778,11 @@ private: SkSTArray<1, Geometry, true> fGeoData; }; -static GrBatch* create_circle_batch(GrColor color, - const SkMatrix& viewMatrix, - bool useCoverageAA, - const SkRect& circle, - const SkStrokeRec& stroke) { +static GrDrawBatch* create_circle_batch(GrColor color, + const SkMatrix& viewMatrix, + bool useCoverageAA, + const SkRect& circle, + const SkStrokeRec& stroke) { SkPoint center = SkPoint::Make(circle.centerX(), circle.centerY()); viewMatrix.mapPoints(¢er, 1); SkScalar radius = viewMatrix.mapRadius(SkScalarHalf(circle.width())); @@ -834,14 +835,14 @@ void GrOvalRenderer::DrawCircle(GrDrawTarget* target, bool useCoverageAA, const SkRect& circle, const SkStrokeRec& stroke) { - SkAutoTUnref<GrBatch> batch(create_circle_batch(color, viewMatrix, useCoverageAA, circle, - stroke)); + SkAutoTUnref<GrDrawBatch> batch(create_circle_batch(color, viewMatrix, useCoverageAA, circle, + stroke)); target->drawBatch(pipelineBuilder, batch); } /////////////////////////////////////////////////////////////////////////////// -class EllipseBatch : public GrBatch { +class EllipseBatch : public GrVertexBatch { public: struct Geometry { GrColor fColor; @@ -854,7 +855,7 @@ public: SkRect fDevBounds; }; - static GrBatch* Create(const Geometry& geometry) { + static GrDrawBatch* Create(const Geometry& geometry) { return SkNEW_ARGS(EllipseBatch, (geometry)); } @@ -958,13 +959,13 @@ private: } bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { - if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *t->pipeline(), t->bounds(), - caps)) { + EllipseBatch* that = t->cast<EllipseBatch>(); + + if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), + that->bounds(), caps)) { return false; } - EllipseBatch* that = t->cast<EllipseBatch>(); - // TODO use vertex color to avoid breaking batches if (this->color() != that->color()) { return false; @@ -1001,11 +1002,11 @@ private: SkSTArray<1, Geometry, true> fGeoData; }; -static GrBatch* create_ellipse_batch(GrColor color, - const SkMatrix& viewMatrix, - bool useCoverageAA, - const SkRect& ellipse, - const SkStrokeRec& stroke) { +static GrDrawBatch* create_ellipse_batch(GrColor color, + const SkMatrix& viewMatrix, + bool useCoverageAA, + const SkRect& ellipse, + const SkStrokeRec& stroke) { #ifdef SK_DEBUG { // we should have checked for this previously @@ -1095,8 +1096,8 @@ bool GrOvalRenderer::DrawEllipse(GrDrawTarget* target, bool useCoverageAA, const SkRect& ellipse, const SkStrokeRec& stroke) { - SkAutoTUnref<GrBatch> batch(create_ellipse_batch(color, viewMatrix, useCoverageAA, ellipse, - stroke)); + SkAutoTUnref<GrDrawBatch> batch(create_ellipse_batch(color, viewMatrix, useCoverageAA, ellipse, + stroke)); if (!batch) { return false; } @@ -1107,7 +1108,7 @@ bool GrOvalRenderer::DrawEllipse(GrDrawTarget* target, ///////////////////////////////////////////////////////////////////////////////////////////////// -class DIEllipseBatch : public GrBatch { +class DIEllipseBatch : public GrVertexBatch { public: struct Geometry { GrColor fColor; @@ -1122,7 +1123,7 @@ public: SkRect fBounds; }; - static GrBatch* Create(const Geometry& geometry, const SkRect& bounds) { + static GrDrawBatch* Create(const Geometry& geometry, const SkRect& bounds) { return SkNEW_ARGS(DIEllipseBatch, (geometry, bounds)); } @@ -1217,13 +1218,12 @@ private: } bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { - if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *t->pipeline(), t->bounds(), - caps)) { + DIEllipseBatch* that = t->cast<DIEllipseBatch>(); + if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), + that->bounds(), caps)) { return false; } - DIEllipseBatch* that = t->cast<DIEllipseBatch>(); - // TODO use vertex color to avoid breaking batches if (this->color() != that->color()) { return false; @@ -1260,11 +1260,11 @@ private: SkSTArray<1, Geometry, true> fGeoData; }; -static GrBatch* create_diellipse_batch(GrColor color, - const SkMatrix& viewMatrix, - bool useCoverageAA, - const SkRect& ellipse, - const SkStrokeRec& stroke) { +static GrDrawBatch* create_diellipse_batch(GrColor color, + const SkMatrix& viewMatrix, + bool useCoverageAA, + const SkRect& ellipse, + const SkStrokeRec& stroke) { SkPoint center = SkPoint::Make(ellipse.centerX(), ellipse.centerY()); SkScalar xRadius = SkScalarHalf(ellipse.width()); SkScalar yRadius = SkScalarHalf(ellipse.height()); @@ -1345,8 +1345,8 @@ bool GrOvalRenderer::DrawDIEllipse(GrDrawTarget* target, bool useCoverageAA, const SkRect& ellipse, const SkStrokeRec& stroke) { - SkAutoTUnref<GrBatch> batch(create_diellipse_batch(color, viewMatrix, useCoverageAA, ellipse, - stroke)); + SkAutoTUnref<GrDrawBatch> batch(create_diellipse_batch(color, viewMatrix, useCoverageAA, + ellipse, stroke)); if (!batch) { return false; } @@ -1463,7 +1463,7 @@ bool GrOvalRenderer::DrawDRRect(GrDrawTarget* target, /////////////////////////////////////////////////////////////////////////////////////////////////// -class RRectCircleRendererBatch : public GrBatch { +class RRectCircleRendererBatch : public GrVertexBatch { public: struct Geometry { GrColor fColor; @@ -1474,7 +1474,7 @@ public: SkRect fDevBounds; }; - static GrBatch* Create(const Geometry& geometry) { + static GrDrawBatch* Create(const Geometry& geometry) { return SkNEW_ARGS(RRectCircleRendererBatch, (geometry)); } @@ -1595,13 +1595,12 @@ private: } bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { - if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *t->pipeline(), t->bounds(), - caps)) { + RRectCircleRendererBatch* that = t->cast<RRectCircleRendererBatch>(); + if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), + that->bounds(), caps)) { return false; } - RRectCircleRendererBatch* that = t->cast<RRectCircleRendererBatch>(); - // TODO use vertex color to avoid breaking batches if (this->color() != that->color()) { return false; @@ -1638,7 +1637,7 @@ private: SkSTArray<1, Geometry, true> fGeoData; }; -class RRectEllipseRendererBatch : public GrBatch { +class RRectEllipseRendererBatch : public GrVertexBatch { public: struct Geometry { GrColor fColor; @@ -1651,7 +1650,7 @@ public: SkRect fDevBounds; }; - static GrBatch* Create(const Geometry& geometry) { + static GrDrawBatch* Create(const Geometry& geometry) { return SkNEW_ARGS(RRectEllipseRendererBatch, (geometry)); } @@ -1782,13 +1781,13 @@ private: } bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { - if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *t->pipeline(), t->bounds(), - caps)) { + RRectEllipseRendererBatch* that = t->cast<RRectEllipseRendererBatch>(); + + if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), + that->bounds(), caps)) { return false; } - RRectEllipseRendererBatch* that = t->cast<RRectEllipseRendererBatch>(); - // TODO use vertex color to avoid breaking batches if (this->color() != that->color()) { return false; @@ -1825,10 +1824,10 @@ private: SkSTArray<1, Geometry, true> fGeoData; }; -static GrBatch* create_rrect_batch(GrColor color, - const SkMatrix& viewMatrix, - const SkRRect& rrect, - const SkStrokeRec& stroke) { +static GrDrawBatch* create_rrect_batch(GrColor color, + const SkMatrix& viewMatrix, + const SkRRect& rrect, + const SkStrokeRec& stroke) { SkASSERT(viewMatrix.rectStaysRect()); SkASSERT(rrect.isSimple()); SkASSERT(!rrect.isOval()); @@ -1997,7 +1996,7 @@ bool GrOvalRenderer::DrawRRect(GrDrawTarget* target, return false; } - SkAutoTUnref<GrBatch> batch(create_rrect_batch(color, viewMatrix, rrect, stroke)); + SkAutoTUnref<GrDrawBatch> batch(create_rrect_batch(color, viewMatrix, rrect, stroke)); if (!batch) { return false; } @@ -2010,7 +2009,7 @@ bool GrOvalRenderer::DrawRRect(GrDrawTarget* target, #ifdef GR_TEST_UTILS -BATCH_TEST_DEFINE(CircleBatch) { +DRAW_BATCH_TEST_DEFINE(CircleBatch) { SkMatrix viewMatrix = GrTest::TestMatrix(random); GrColor color = GrRandomColor(random); bool useCoverageAA = random->nextBool(); @@ -2019,7 +2018,7 @@ BATCH_TEST_DEFINE(CircleBatch) { GrTest::TestStrokeRec(random)); } -BATCH_TEST_DEFINE(EllipseBatch) { +DRAW_BATCH_TEST_DEFINE(EllipseBatch) { SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); GrColor color = GrRandomColor(random); SkRect ellipse = GrTest::TestSquare(random); @@ -2027,7 +2026,7 @@ BATCH_TEST_DEFINE(EllipseBatch) { GrTest::TestStrokeRec(random)); } -BATCH_TEST_DEFINE(DIEllipseBatch) { +DRAW_BATCH_TEST_DEFINE(DIEllipseBatch) { SkMatrix viewMatrix = GrTest::TestMatrix(random); GrColor color = GrRandomColor(random); bool useCoverageAA = random->nextBool(); @@ -2036,7 +2035,7 @@ BATCH_TEST_DEFINE(DIEllipseBatch) { GrTest::TestStrokeRec(random)); } -BATCH_TEST_DEFINE(RRectBatch) { +DRAW_BATCH_TEST_DEFINE(RRectBatch) { SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); GrColor color = GrRandomColor(random); const SkRRect& rrect = GrTest::TestRRectSimple(random); diff --git a/src/gpu/GrPipelineBuilder.cpp b/src/gpu/GrPipelineBuilder.cpp index 1c4421836d..b0fc7b0f05 100644 --- a/src/gpu/GrPipelineBuilder.cpp +++ b/src/gpu/GrPipelineBuilder.cpp @@ -145,12 +145,12 @@ void GrPipelineBuilder::calcCoverageInvariantOutput(const GrPrimitiveProcessor* fCoverageProcInfoValid = false; } -void GrPipelineBuilder::calcColorInvariantOutput(const GrBatch* batch) const { +void GrPipelineBuilder::calcColorInvariantOutput(const GrDrawBatch* batch) const { fColorProcInfo.calcColorWithBatch(batch, fColorStages.begin(), this->numColorFragmentStages()); fColorProcInfoValid = false; } -void GrPipelineBuilder::calcCoverageInvariantOutput(const GrBatch* batch) const { +void GrPipelineBuilder::calcCoverageInvariantOutput(const GrDrawBatch* batch) const { fCoverageProcInfo.calcCoverageWithBatch(batch, fCoverageStages.begin(), this->numCoverageFragmentStages()); fCoverageProcInfoValid = false; diff --git a/src/gpu/GrPipelineBuilder.h b/src/gpu/GrPipelineBuilder.h index f36a36b086..ad1bbfb714 100644 --- a/src/gpu/GrPipelineBuilder.h +++ b/src/gpu/GrPipelineBuilder.h @@ -24,7 +24,7 @@ #include "effects/GrPorterDuffXferProcessor.h" #include "effects/GrSimpleTextureEffect.h" -class GrBatch; +class GrDrawBatch; class GrCaps; class GrPaint; class GrTexture; @@ -400,12 +400,12 @@ public: return fCoverageProcInfo; } - const GrProcOptInfo& colorProcInfo(const GrBatch* batch) const { + const GrProcOptInfo& colorProcInfo(const GrDrawBatch* batch) const { this->calcColorInvariantOutput(batch); return fColorProcInfo; } - const GrProcOptInfo& coverageProcInfo(const GrBatch* batch) const { + const GrProcOptInfo& coverageProcInfo(const GrDrawBatch* batch) const { this->calcCoverageInvariantOutput(batch); return fCoverageProcInfo; } @@ -434,8 +434,8 @@ private: /** * GrBatch provides the initial seed for these loops based off of its initial geometry data */ - void calcColorInvariantOutput(const GrBatch*) const; - void calcCoverageInvariantOutput(const GrBatch*) const; + void calcColorInvariantOutput(const GrDrawBatch*) const; + void calcCoverageInvariantOutput(const GrDrawBatch*) const; /** * If fColorProcInfoValid is false, function calculates the invariant output for the color diff --git a/src/gpu/GrProcOptInfo.cpp b/src/gpu/GrProcOptInfo.cpp index 17b42b6a49..e56fb743a6 100644 --- a/src/gpu/GrProcOptInfo.cpp +++ b/src/gpu/GrProcOptInfo.cpp @@ -11,7 +11,7 @@ #include "batches/GrBatch.h" -void GrProcOptInfo::calcColorWithBatch(const GrBatch* batch, +void GrProcOptInfo::calcColorWithBatch(const GrDrawBatch* batch, const GrFragmentStage* stages, int stageCount) { GrInitInvariantOutput out; @@ -20,7 +20,7 @@ void GrProcOptInfo::calcColorWithBatch(const GrBatch* batch, this->internalCalc(stages, stageCount, batch->willReadFragmentPosition()); } -void GrProcOptInfo::calcCoverageWithBatch(const GrBatch* batch, +void GrProcOptInfo::calcCoverageWithBatch(const GrDrawBatch* batch, const GrFragmentStage* stages, int stageCount) { GrInitInvariantOutput out; diff --git a/src/gpu/GrProcOptInfo.h b/src/gpu/GrProcOptInfo.h index 0430916405..cf7e3503b9 100644 --- a/src/gpu/GrProcOptInfo.h +++ b/src/gpu/GrProcOptInfo.h @@ -12,7 +12,7 @@ #include "GrInvariantOutput.h" #include "GrStagedProcessor.h" -class GrBatch; +class GrDrawBatch; class GrFragmentProcessor; class GrPrimitiveProcessor; class GrProcessor; @@ -34,8 +34,8 @@ public: void calcWithInitialValues(const GrFragmentStage*, int stageCount, GrColor startColor, GrColorComponentFlags flags, bool areCoverageStages); - void calcColorWithBatch(const GrBatch*, const GrFragmentStage*, int stagecount); - void calcCoverageWithBatch(const GrBatch*, const GrFragmentStage*, int stagecount); + void calcColorWithBatch(const GrDrawBatch*, const GrFragmentStage*, int stagecount); + void calcCoverageWithBatch(const GrDrawBatch*, const GrFragmentStage*, int stagecount); // TODO delete these when batch is everywhere void calcColorWithPrimProc(const GrPrimitiveProcessor*, const GrFragmentStage*, int stagecount); diff --git a/src/gpu/GrReorderCommandBuilder.cpp b/src/gpu/GrReorderCommandBuilder.cpp index 869ae532af..f08b7f17d0 100644 --- a/src/gpu/GrReorderCommandBuilder.cpp +++ b/src/gpu/GrReorderCommandBuilder.cpp @@ -15,7 +15,7 @@ static bool intersect(const Left& a, const Right& b) { a.fTop < b.fBottom && b.fTop < a.fBottom; } -GrTargetCommands::Cmd* GrReorderCommandBuilder::recordDrawBatch(GrBatch* batch, +GrTargetCommands::Cmd* GrReorderCommandBuilder::recordDrawBatch(GrDrawBatch* batch, const GrCaps& caps) { // Check if there is a Batch Draw we can batch with by linearly searching back until we either // 1) check every draw diff --git a/src/gpu/GrReorderCommandBuilder.h b/src/gpu/GrReorderCommandBuilder.h index 4a4ebe9c04..a5f984c573 100644 --- a/src/gpu/GrReorderCommandBuilder.h +++ b/src/gpu/GrReorderCommandBuilder.h @@ -17,7 +17,7 @@ public: GrReorderCommandBuilder(GrGpu* gpu) : INHERITED(gpu) {} - Cmd* recordDrawBatch(GrBatch*, const GrCaps&) override; + Cmd* recordDrawBatch(GrDrawBatch*, const GrCaps&) override; Cmd* recordStencilPath(const GrPipelineBuilder&, const GrPathProcessor*, const GrPath*, diff --git a/src/gpu/GrTargetCommands.cpp b/src/gpu/GrTargetCommands.cpp index 474bbbd787..2347db8ea2 100644 --- a/src/gpu/GrTargetCommands.cpp +++ b/src/gpu/GrTargetCommands.cpp @@ -30,8 +30,12 @@ void GrTargetCommands::flush(GrBufferedDrawTarget* bufferedDrawTarget) { if (Cmd::kDrawBatch_CmdType == genIter->type()) { DrawBatch* db = reinterpret_cast<DrawBatch*>(genIter.get()); fBatchTarget.resetNumberOfDraws(); - db->batch()->generateGeometry(&fBatchTarget); - db->batch()->setNumberOfDraws(fBatchTarget.numberOfDraws()); + // TODO: encapsulate the specialization of GrVertexBatch in GrVertexBatch so that we can + // remove this cast. Currently all GrDrawBatches are in fact GrVertexBatch. + GrVertexBatch* vertexBatch = static_cast<GrVertexBatch*>(db->batch()); + + vertexBatch->generateGeometry(&fBatchTarget); + vertexBatch->setNumberOfDraws(fBatchTarget.numberOfDraws()); } } @@ -76,7 +80,10 @@ void GrTargetCommands::DrawPaths::execute(GrGpu* gpu) { } void GrTargetCommands::DrawBatch::execute(GrGpu* gpu) { - fBatchTarget->flushNext(fBatch->numberOfDraws()); + // TODO: encapsulate the specialization of GrVertexBatch in GrVertexBatch so that we can + // remove this cast. Currently all GrDrawBatches are in fact GrVertexBatch. + const GrVertexBatch* vertexBatch = static_cast<const GrVertexBatch*>(fBatch.get()); + fBatchTarget->flushNext(vertexBatch->numberOfDraws()); } void GrTargetCommands::Clear::execute(GrGpu* gpu) { diff --git a/src/gpu/GrTargetCommands.h b/src/gpu/GrTargetCommands.h index a15ac88090..024048009d 100644 --- a/src/gpu/GrTargetCommands.h +++ b/src/gpu/GrTargetCommands.h @@ -232,19 +232,19 @@ private: }; struct DrawBatch : public Cmd { - DrawBatch(GrBatch* batch, GrBatchTarget* batchTarget) + DrawBatch(GrDrawBatch* batch, GrBatchTarget* batchTarget) : Cmd(kDrawBatch_CmdType) , fBatch(SkRef(batch)) , fBatchTarget(batchTarget) { SkASSERT(!batch->isUsed()); } - GrBatch* batch() { return fBatch; } + GrDrawBatch* batch() { return fBatch; } void execute(GrGpu*) override; private: - SkAutoTUnref<GrBatch> fBatch; - GrBatchTarget* fBatchTarget; + SkAutoTUnref<GrDrawBatch> fBatch; + GrBatchTarget* fBatchTarget; }; static const int kCmdBufferInitialSizeInBytes = 8 * 1024; diff --git a/src/gpu/GrTessellatingPathRenderer.cpp b/src/gpu/GrTessellatingPathRenderer.cpp index 9459cc55d1..30be341e0e 100644 --- a/src/gpu/GrTessellatingPathRenderer.cpp +++ b/src/gpu/GrTessellatingPathRenderer.cpp @@ -1384,14 +1384,14 @@ bool GrTessellatingPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) cons !args.fAntiAlias && !args.fPath->isConvex(); } -class TessellatingPathBatch : public GrBatch { +class TessellatingPathBatch : public GrVertexBatch { public: - static GrBatch* Create(const GrColor& color, - const SkPath& path, - const GrStrokeInfo& stroke, - const SkMatrix& viewMatrix, - SkRect clipBounds) { + static GrDrawBatch* Create(const GrColor& color, + const SkPath& path, + const GrStrokeInfo& stroke, + const SkMatrix& viewMatrix, + SkRect clipBounds) { return SkNEW_ARGS(TessellatingPathBatch, (color, path, stroke, viewMatrix, clipBounds)); } @@ -1620,9 +1620,9 @@ bool GrTessellatingPathRenderer::onDrawPath(const DrawPathArgs& args) { return false; } vmi.mapRect(&clipBounds); - SkAutoTUnref<GrBatch> batch(TessellatingPathBatch::Create(args.fColor, *args.fPath, - *args.fStroke, *args.fViewMatrix, - clipBounds)); + SkAutoTUnref<GrDrawBatch> batch(TessellatingPathBatch::Create(args.fColor, *args.fPath, + *args.fStroke, *args.fViewMatrix, + clipBounds)); args.fTarget->drawBatch(*args.fPipelineBuilder, batch); return true; @@ -1632,7 +1632,7 @@ bool GrTessellatingPathRenderer::onDrawPath(const DrawPathArgs& args) { #ifdef GR_TEST_UTILS -BATCH_TEST_DEFINE(TesselatingPathBatch) { +DRAW_BATCH_TEST_DEFINE(TesselatingPathBatch) { GrColor color = GrRandomColor(random); SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); SkPath path = GrTest::TestPath(random); diff --git a/src/gpu/batches/GrAAFillRectBatch.cpp b/src/gpu/batches/GrAAFillRectBatch.cpp index 4cea65ac56..9b190283ff 100644 --- a/src/gpu/batches/GrAAFillRectBatch.cpp +++ b/src/gpu/batches/GrAAFillRectBatch.cpp @@ -62,7 +62,7 @@ const GrIndexBuffer* get_index_buffer(GrResourceProvider* resourceProvider) { * SkPoint* fan0Position, const Geometry&) */ template <typename Base> -class AAFillRectBatch : public GrBatch { +class AAFillRectBatch : public GrVertexBatch { public: typedef typename Base::Geometry Geometry; @@ -165,12 +165,12 @@ private: bool coverageIgnored() const { return fBatch.fCoverageIgnored; } bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { - if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *t->pipeline(), t->bounds(), - caps)) { + AAFillRectBatch* that = t->cast<AAFillRectBatch>(); + if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), + that->bounds(), caps)) { return false; } - AAFillRectBatch* that = t->cast<AAFillRectBatch>(); if (!Base::CanCombineLocalCoords(this->viewMatrix(), that->viewMatrix(), this->usesLocalCoords())) { return false; @@ -399,10 +399,10 @@ typedef AAFillRectBatch<AAFillRectBatchLocalMatrixImp> AAFillRectBatchLocalMatri namespace GrAAFillRectBatch { -GrBatch* Create(GrColor color, - const SkMatrix& viewMatrix, - const SkRect& rect, - const SkRect& devRect) { +GrDrawBatch* Create(GrColor color, + const SkMatrix& viewMatrix, + const SkRect& rect, + const SkRect& devRect) { AAFillRectBatchNoLocalMatrix* batch = AAFillRectBatchNoLocalMatrix::Create(); AAFillRectBatchNoLocalMatrix::Geometry& geo = *batch->geometry(); geo.fColor = color; @@ -412,11 +412,11 @@ GrBatch* Create(GrColor color, return batch; } -GrBatch* Create(GrColor color, - const SkMatrix& viewMatrix, - const SkMatrix& localMatrix, - const SkRect& rect, - const SkRect& devRect) { +GrDrawBatch* Create(GrColor color, + const SkMatrix& viewMatrix, + const SkMatrix& localMatrix, + const SkRect& rect, + const SkRect& devRect) { AAFillRectBatchLocalMatrix* batch = AAFillRectBatchLocalMatrix::Create(); AAFillRectBatchLocalMatrix::Geometry& geo = *batch->geometry(); geo.fColor = color; @@ -435,7 +435,7 @@ GrBatch* Create(GrColor color, #include "GrBatchTest.h" -BATCH_TEST_DEFINE(AAFillRectBatch) { +DRAW_BATCH_TEST_DEFINE(AAFillRectBatch) { AAFillRectBatchNoLocalMatrix* batch = AAFillRectBatchNoLocalMatrix::Create(); AAFillRectBatchNoLocalMatrix::Geometry& geo = *batch->geometry(); geo.fColor = GrRandomColor(random); @@ -445,7 +445,7 @@ BATCH_TEST_DEFINE(AAFillRectBatch) { return batch; } -BATCH_TEST_DEFINE(AAFillRectBatchLocalMatrix) { +DRAW_BATCH_TEST_DEFINE(AAFillRectBatchLocalMatrix) { AAFillRectBatchLocalMatrix* batch = AAFillRectBatchLocalMatrix::Create(); AAFillRectBatchLocalMatrix::Geometry& geo = *batch->geometry(); geo.fColor = GrRandomColor(random); diff --git a/src/gpu/batches/GrAAFillRectBatch.h b/src/gpu/batches/GrAAFillRectBatch.h index 3fc1e3480c..5a657a3fa8 100644 --- a/src/gpu/batches/GrAAFillRectBatch.h +++ b/src/gpu/batches/GrAAFillRectBatch.h @@ -10,21 +10,21 @@ #include "GrColor.h" -class GrBatch; +class GrDrawBatch; class SkMatrix; struct SkRect; namespace GrAAFillRectBatch { -GrBatch* Create(GrColor color, - const SkMatrix& viewMatrix, - const SkRect& rect, - const SkRect& devRect); +GrDrawBatch* Create(GrColor color, + const SkMatrix& viewMatrix, + const SkRect& rect, + const SkRect& devRect); -GrBatch* Create(GrColor color, - const SkMatrix& viewMatrix, - const SkMatrix& localMatrix, - const SkRect& rect, - const SkRect& devRect); +GrDrawBatch* Create(GrColor color, + const SkMatrix& viewMatrix, + const SkMatrix& localMatrix, + const SkRect& rect, + const SkRect& devRect); }; #endif diff --git a/src/gpu/batches/GrAAStrokeRectBatch.cpp b/src/gpu/batches/GrAAStrokeRectBatch.cpp index 0083aaad6c..91ff230f0d 100644 --- a/src/gpu/batches/GrAAStrokeRectBatch.cpp +++ b/src/gpu/batches/GrAAStrokeRectBatch.cpp @@ -204,13 +204,13 @@ const GrIndexBuffer* GrAAStrokeRectBatch::GetIndexBuffer(GrResourceProvider* res } bool GrAAStrokeRectBatch::onCombineIfPossible(GrBatch* t, const GrCaps& caps) { - if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *t->pipeline(), t->bounds(), - caps)) { + GrAAStrokeRectBatch* that = t->cast<GrAAStrokeRectBatch>(); + + if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), + that->bounds(), caps)) { return false; } - GrAAStrokeRectBatch* that = t->cast<GrAAStrokeRectBatch>(); - // TODO batch across miterstroke changes if (this->miterStroke() != that->miterStroke()) { return false; @@ -356,7 +356,7 @@ void GrAAStrokeRectBatch::generateAAStrokeRectGeometry(void* vertices, #include "GrBatchTest.h" -BATCH_TEST_DEFINE(AAStrokeRectBatch) { +DRAW_BATCH_TEST_DEFINE(AAStrokeRectBatch) { bool miterStroke = random->nextBool(); // Create mock stroke rect diff --git a/src/gpu/batches/GrAAStrokeRectBatch.h b/src/gpu/batches/GrAAStrokeRectBatch.h index 7fa15f5326..b6fb89f502 100644 --- a/src/gpu/batches/GrAAStrokeRectBatch.h +++ b/src/gpu/batches/GrAAStrokeRectBatch.h @@ -14,7 +14,7 @@ #include "SkMatrix.h" #include "SkRect.h" -class GrAAStrokeRectBatch : public GrBatch { +class GrAAStrokeRectBatch : public GrVertexBatch { public: // TODO support AA rotated stroke rects by copying around view matrices struct Geometry { @@ -25,7 +25,7 @@ public: bool fMiterStroke; }; - static GrBatch* Create(const Geometry& geometry, const SkMatrix& viewMatrix) { + static GrDrawBatch* Create(const Geometry& geometry, const SkMatrix& viewMatrix) { return SkNEW_ARGS(GrAAStrokeRectBatch, (geometry, viewMatrix)); } diff --git a/src/gpu/batches/GrBWFillRectBatch.cpp b/src/gpu/batches/GrBWFillRectBatch.cpp index c3ddc2b6cb..0009789986 100644 --- a/src/gpu/batches/GrBWFillRectBatch.cpp +++ b/src/gpu/batches/GrBWFillRectBatch.cpp @@ -17,7 +17,7 @@ class GrBatchTarget; class SkMatrix; struct SkRect; -class BWFillRectBatch : public GrBatch { +class BWFillRectBatch : public GrVertexBatch { public: struct Geometry { SkMatrix fViewMatrix; @@ -29,7 +29,7 @@ public: bool fHasLocalMatrix; }; - static GrBatch* Create(const Geometry& geometry) { + static GrDrawBatch* Create(const Geometry& geometry) { return SkNEW_ARGS(BWFillRectBatch, (geometry)); } @@ -134,13 +134,12 @@ private: bool coverageIgnored() const { return fBatch.fCoverageIgnored; } bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { - if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *t->pipeline(), t->bounds(), - caps)) { + BWFillRectBatch* that = t->cast<BWFillRectBatch>(); + if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), + that->bounds(), caps)) { return false; } - BWFillRectBatch* that = t->cast<BWFillRectBatch>(); - if (this->hasLocalRect() != that->hasLocalRect()) { return false; } @@ -210,11 +209,11 @@ private: }; namespace GrBWFillRectBatch { -GrBatch* Create(GrColor color, - const SkMatrix& viewMatrix, - const SkRect& rect, - const SkRect* localRect, - const SkMatrix* localMatrix) { +GrDrawBatch* Create(GrColor color, + const SkMatrix& viewMatrix, + const SkRect& rect, + const SkRect* localRect, + const SkMatrix* localMatrix) { BWFillRectBatch::Geometry geometry; geometry.fColor = color; geometry.fViewMatrix = viewMatrix; @@ -244,7 +243,7 @@ GrBatch* Create(GrColor color, #include "GrBatchTest.h" -BATCH_TEST_DEFINE(RectBatch) { +DRAW_BATCH_TEST_DEFINE(RectBatch) { BWFillRectBatch::Geometry geometry; geometry.fColor = GrRandomColor(random); diff --git a/src/gpu/batches/GrBWFillRectBatch.h b/src/gpu/batches/GrBWFillRectBatch.h index ff1533caa2..c95fd7037b 100644 --- a/src/gpu/batches/GrBWFillRectBatch.h +++ b/src/gpu/batches/GrBWFillRectBatch.h @@ -10,12 +10,12 @@ #include "GrColor.h" -class GrBatch; +class GrDrawBatch; class SkMatrix; struct SkRect; namespace GrBWFillRectBatch { -GrBatch* Create(GrColor color, +GrDrawBatch* Create(GrColor color, const SkMatrix& viewMatrix, const SkRect& rect, const SkRect* localRect, diff --git a/src/gpu/batches/GrBatch.cpp b/src/gpu/batches/GrBatch.cpp index 3840b4c83b..b696d6b95b 100644 --- a/src/gpu/batches/GrBatch.cpp +++ b/src/gpu/batches/GrBatch.cpp @@ -50,8 +50,6 @@ void GrBatch::operator delete(void* target) { GrBatch::GrBatch() : fClassID(kIllegalBatchID) - , fNumberOfDraws(0) - , fPipelineInstalled(false) #if GR_BATCH_SPEW , fUniqueID(GenID(&gCurrBatchUniqueID)) #endif @@ -59,13 +57,34 @@ GrBatch::GrBatch() SkDEBUGCODE(fUsed = false;) } -GrBatch::~GrBatch() { +GrBatch::~GrBatch() {} + +////////////////////////////////////////////////////////////////////////////// + +GrDrawBatch::GrDrawBatch() : fPipelineInstalled(false) { } + +GrDrawBatch::~GrDrawBatch() { if (fPipelineInstalled) { this->pipeline()->~GrPipeline(); } } -void* GrBatch::InstancedHelper::init(GrBatchTarget* batchTarget, GrPrimitiveType primType, +bool GrDrawBatch::installPipeline(const GrPipeline::CreateArgs& args) { + GrPipelineOptimizations opts; + void* location = fPipelineStorage.get(); + if (!GrPipeline::CreateAt(location, args, &opts)) { + return false; + } + this->initBatchTracker(opts); + fPipelineInstalled = true; + return true; +} + +////////////////////////////////////////////////////////////////////////////// + +GrVertexBatch::GrVertexBatch() : fNumberOfDraws(0) {} + +void* GrVertexBatch::InstancedHelper::init(GrBatchTarget* batchTarget, GrPrimitiveType primType, size_t vertexStride, const GrIndexBuffer* indexBuffer, int verticesPerInstance, int indicesPerInstance, int instancesToDraw) { @@ -92,7 +111,8 @@ void* GrBatch::InstancedHelper::init(GrBatchTarget* batchTarget, GrPrimitiveType return vertices; } -void* GrBatch::QuadHelper::init(GrBatchTarget* batchTarget, size_t vertexStride, int quadsToDraw) { +void* GrVertexBatch::QuadHelper::init(GrBatchTarget* batchTarget, size_t vertexStride, + int quadsToDraw) { SkAutoTUnref<const GrIndexBuffer> quadIndexBuffer( batchTarget->resourceProvider()->refQuadIndexBuffer()); if (!quadIndexBuffer) { @@ -102,14 +122,3 @@ void* GrBatch::QuadHelper::init(GrBatchTarget* batchTarget, size_t vertexStride, return this->INHERITED::init(batchTarget, kTriangles_GrPrimitiveType, vertexStride, quadIndexBuffer, kVerticesPerQuad, kIndicesPerQuad, quadsToDraw); } - -bool GrBatch::installPipeline(const GrPipeline::CreateArgs& args) { - GrPipelineOptimizations opts; - void* location = fPipelineStorage.get(); - if (!GrPipeline::CreateAt(location, args, &opts)) { - return false; - } - this->initBatchTracker(opts); - fPipelineInstalled = true; - return true; -} diff --git a/src/gpu/batches/GrBatch.h b/src/gpu/batches/GrBatch.h index 35844cd99a..ef8f56c4b9 100644 --- a/src/gpu/batches/GrBatch.h +++ b/src/gpu/batches/GrBatch.h @@ -21,7 +21,7 @@ class GrPipeline; struct GrInitInvariantOutput; -/* +/** * GrBatch is the base class for all Ganesh deferred geometry generators. To facilitate * reorderable batching, Ganesh does not generate geometry inline with draw calls. Instead, it * captures the arguments to the draw and then generates the geometry on demand. This gives GrBatch @@ -51,8 +51,6 @@ public: ~GrBatch() override; virtual const char* name() const = 0; - virtual void getInvariantOutputColor(GrInitInvariantOutput* out) const = 0; - virtual void getInvariantOutputCoverage(GrInitInvariantOutput* out) const = 0; bool combineIfPossible(GrBatch* that, const GrCaps& caps) { if (this->classID() != that->classID()) { @@ -62,14 +60,8 @@ public: return this->onCombineIfPossible(that, caps); } - virtual void generateGeometry(GrBatchTarget*) = 0; - const SkRect& bounds() const { return fBounds; } - // TODO this goes away when batches are everywhere - void setNumberOfDraws(int numberOfDraws) { fNumberOfDraws = numberOfDraws; } - int numberOfDraws() const { return fNumberOfDraws; } - void* operator new(size_t size); void operator delete(void* target); @@ -81,28 +73,17 @@ public: } /** - * Helper for down-casting to a GrBatch subclass - */ + * Helper for down-casting to a GrBatch subclass + */ template <typename T> const T& cast() const { return *static_cast<const T*>(this); } template <typename T> T* cast() { return static_cast<T*>(this); } uint32_t classID() const { SkASSERT(kIllegalBatchID != fClassID); return fClassID; } - // TODO no GrPrimitiveProcessors yet read fragment position - bool willReadFragmentPosition() const { return false; } - - SkDEBUGCODE(bool isUsed() const { return fUsed; }) - - const GrPipeline* pipeline() const { - SkASSERT(fPipelineInstalled); - return reinterpret_cast<const GrPipeline*>(fPipelineStorage.get()); - } - - bool installPipeline(const GrPipeline::CreateArgs&); - #if GR_BATCH_SPEW uint32_t uniqueID() const { return fUniqueID; } #endif + SkDEBUGCODE(bool isUsed() const { return fUsed; }) protected: template <typename PROC_SUBCLASS> void initClassID() { @@ -118,8 +99,86 @@ protected: return fBounds.joinPossiblyEmptyRect(otherBounds); } + SkRect fBounds; + +private: + virtual bool onCombineIfPossible(GrBatch*, const GrCaps& caps) = 0; + + static uint32_t GenID(int32_t* idCounter) { + // fCurrProcessorClassID has been initialized to kIllegalProcessorClassID. The + // atomic inc returns the old value not the incremented value. So we add + // 1 to the returned value. + uint32_t id = static_cast<uint32_t>(sk_atomic_inc(idCounter)) + 1; + if (!id) { + SkFAIL("This should never wrap as it should only be called once for each GrBatch " + "subclass."); + } + return id; + } + + enum { + kIllegalBatchID = 0, + }; + + uint32_t fClassID; + SkDEBUGCODE(bool fUsed;) +#if GR_BATCH_SPEW + uint32_t fUniqueID; + static int32_t gCurrBatchUniqueID; +#endif + static int32_t gCurrBatchClassID; + typedef GrNonAtomicRef INHERITED; +}; + +/** + * Base class for GrBatches that draw. These batches have a GrPipeline installed by GrDrawTarget. + */ +class GrDrawBatch : public GrBatch { +public: + GrDrawBatch(); + ~GrDrawBatch() override; + + virtual void getInvariantOutputColor(GrInitInvariantOutput* out) const = 0; + virtual void getInvariantOutputCoverage(GrInitInvariantOutput* out) const = 0; + + const GrPipeline* pipeline() const { + SkASSERT(fPipelineInstalled); + return reinterpret_cast<const GrPipeline*>(fPipelineStorage.get()); + } + + bool installPipeline(const GrPipeline::CreateArgs&); + + // TODO no GrPrimitiveProcessors yet read fragment position + bool willReadFragmentPosition() const { return false; } + +private: + /** + * initBatchTracker is a hook for the some additional overrides / optimization possibilities + * from the GrXferProcessor. + */ + virtual void initBatchTracker(const GrPipelineOptimizations&) = 0; + + SkAlignedSTStorage<1, GrPipeline> fPipelineStorage; + bool fPipelineInstalled; + typedef GrBatch INHERITED; +}; + +/** + * Base class for vertex-based GrBatches. + */ +class GrVertexBatch : public GrDrawBatch { +public: + GrVertexBatch(); + + virtual void generateGeometry(GrBatchTarget*) = 0; + + // TODO this goes away when batches are everywhere + void setNumberOfDraws(int numberOfDraws) { fNumberOfDraws = numberOfDraws; } + int numberOfDraws() const { return fNumberOfDraws; } + +protected: /** Helper for rendering instances using an instanced index index buffer. This class creates the - space for the vertices and flushes the draws to the batch target.*/ + space for the vertices and flushes the draws to the batch target. */ class InstancedHelper { public: InstancedHelper() {} @@ -156,44 +215,9 @@ protected: typedef InstancedHelper INHERITED; }; - uint32_t fClassID; - SkRect fBounds; - private: - virtual bool onCombineIfPossible(GrBatch*, const GrCaps& caps) = 0; - - /* - * initBatchTracker is a hook for the some additional overrides / optimization possibilities - * from the GrXferProcessor. - */ - virtual void initBatchTracker(const GrPipelineOptimizations&) = 0; - - - static uint32_t GenID(int32_t* idCounter) { - // fCurrProcessorClassID has been initialized to kIllegalProcessorClassID. The - // atomic inc returns the old value not the incremented value. So we add - // 1 to the returned value. - uint32_t id = static_cast<uint32_t>(sk_atomic_inc(idCounter)) + 1; - if (!id) { - SkFAIL("This should never wrap as it should only be called once for each GrBatch " - "subclass."); - } - return id; - } - - enum { - kIllegalBatchID = 0, - }; - SkAlignedSTStorage<1, GrPipeline> fPipelineStorage; int fNumberOfDraws; - SkDEBUGCODE(bool fUsed;) - bool fPipelineInstalled; -#if GR_BATCH_SPEW - uint32_t fUniqueID; - static int32_t gCurrBatchUniqueID; -#endif - static int32_t gCurrBatchClassID; - typedef SkRefCnt INHERITED; + typedef GrDrawBatch INHERITED; }; #endif diff --git a/src/gpu/batches/GrDrawAtlasBatch.cpp b/src/gpu/batches/GrDrawAtlasBatch.cpp index f79412be54..28c6922d99 100644 --- a/src/gpu/batches/GrDrawAtlasBatch.cpp +++ b/src/gpu/batches/GrDrawAtlasBatch.cpp @@ -157,13 +157,13 @@ GrDrawAtlasBatch::GrDrawAtlasBatch(const Geometry& geometry, const SkMatrix& vie } bool GrDrawAtlasBatch::onCombineIfPossible(GrBatch* t, const GrCaps& caps) { - if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *t->pipeline(), t->bounds(), - caps)) { + GrDrawAtlasBatch* that = t->cast<GrDrawAtlasBatch>(); + + if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), + that->bounds(), caps)) { return false; } - - GrDrawAtlasBatch* that = t->cast<GrDrawAtlasBatch>(); - + // We currently use a uniform viewmatrix for this batch if (!this->viewMatrix().cheapEqualTo(that->viewMatrix())) { return false; @@ -231,7 +231,7 @@ static void randomize_params(uint32_t count, SkRandom* random, } } -BATCH_TEST_DEFINE(GrDrawAtlasBatch) { +DRAW_BATCH_TEST_DEFINE(GrDrawAtlasBatch) { uint32_t spriteCount = random->nextRangeU(1, 100); SkTArray<SkRSXform> xforms(spriteCount); diff --git a/src/gpu/batches/GrDrawAtlasBatch.h b/src/gpu/batches/GrDrawAtlasBatch.h index e6ce7a03df..6b46cfb0a3 100644 --- a/src/gpu/batches/GrDrawAtlasBatch.h +++ b/src/gpu/batches/GrDrawAtlasBatch.h @@ -12,15 +12,16 @@ #include "GrColor.h" #include "GrDefaultGeoProcFactory.h" -class GrDrawAtlasBatch : public GrBatch { +class GrDrawAtlasBatch : public GrVertexBatch { public: struct Geometry { GrColor fColor; SkTArray<uint8_t, true> fVerts; }; - static GrBatch* Create(const Geometry& geometry, const SkMatrix& viewMatrix, int spriteCount, - const SkRSXform* xforms, const SkRect* rects, const SkColor* colors) { + static GrDrawBatch* Create(const Geometry& geometry, const SkMatrix& viewMatrix, + int spriteCount, const SkRSXform* xforms, const SkRect* rects, + const SkColor* colors) { return SkNEW_ARGS(GrDrawAtlasBatch, (geometry, viewMatrix, spriteCount, xforms, rects, colors)); } diff --git a/src/gpu/batches/GrDrawVerticesBatch.cpp b/src/gpu/batches/GrDrawVerticesBatch.cpp index f36c54b067..ebfda36296 100644 --- a/src/gpu/batches/GrDrawVerticesBatch.cpp +++ b/src/gpu/batches/GrDrawVerticesBatch.cpp @@ -184,13 +184,13 @@ void GrDrawVerticesBatch::generateGeometry(GrBatchTarget* batchTarget) { } bool GrDrawVerticesBatch::onCombineIfPossible(GrBatch* t, const GrCaps& caps) { - if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *t->pipeline(), t->bounds(), - caps)) { + GrDrawVerticesBatch* that = t->cast<GrDrawVerticesBatch>(); + + if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), + that->bounds(), caps)) { return false; } - GrDrawVerticesBatch* that = t->cast<GrDrawVerticesBatch>(); - if (!this->batchablePrimitiveType() || this->primitiveType() != that->primitiveType()) { return false; } @@ -295,7 +295,7 @@ static void randomize_params(size_t count, size_t maxVertex, SkScalar min, SkSca } } -BATCH_TEST_DEFINE(VerticesBatch) { +DRAW_BATCH_TEST_DEFINE(VerticesBatch) { GrPrimitiveType type = GrPrimitiveType(random->nextULessThan(kLast_GrPrimitiveType + 1)); uint32_t primitiveCount = random->nextRangeU(1, 100); diff --git a/src/gpu/batches/GrDrawVerticesBatch.h b/src/gpu/batches/GrDrawVerticesBatch.h index 9446d88bde..11decbe01d 100644 --- a/src/gpu/batches/GrDrawVerticesBatch.h +++ b/src/gpu/batches/GrDrawVerticesBatch.h @@ -18,7 +18,7 @@ class GrBatchTarget; struct GrInitInvariantOutput; -class GrDrawVerticesBatch : public GrBatch { +class GrDrawVerticesBatch : public GrVertexBatch { public: struct Geometry { GrColor fColor; @@ -28,12 +28,12 @@ public: SkTDArray<SkPoint> fLocalCoords; }; - static GrBatch* Create(const Geometry& geometry, GrPrimitiveType primitiveType, - const SkMatrix& viewMatrix, - const SkPoint* positions, int vertexCount, - const uint16_t* indices, int indexCount, - const GrColor* colors, const SkPoint* localCoords, - const SkRect& bounds) { + static GrDrawBatch* Create(const Geometry& geometry, GrPrimitiveType primitiveType, + const SkMatrix& viewMatrix, + const SkPoint* positions, int vertexCount, + const uint16_t* indices, int indexCount, + const GrColor* colors, const SkPoint* localCoords, + const SkRect& bounds) { return SkNEW_ARGS(GrDrawVerticesBatch, (geometry, primitiveType, viewMatrix, positions, vertexCount, indices, indexCount, colors, localCoords, bounds)); diff --git a/src/gpu/batches/GrRectBatchFactory.cpp b/src/gpu/batches/GrRectBatchFactory.cpp index e874acbb49..86980d2944 100644 --- a/src/gpu/batches/GrRectBatchFactory.cpp +++ b/src/gpu/batches/GrRectBatchFactory.cpp @@ -12,12 +12,12 @@ #include "SkStrokeRec.h" -static GrBatch* create_stroke_aa_batch(GrColor color, - const SkMatrix& viewMatrix, - const SkRect& devOutside, - const SkRect& devOutsideAssist, - const SkRect& devInside, - bool miterStroke) { +static GrDrawBatch* create_stroke_aa_batch(GrColor color, + const SkMatrix& viewMatrix, + const SkRect& devOutside, + const SkRect& devOutsideAssist, + const SkRect& devInside, + bool miterStroke) { GrAAStrokeRectBatch::Geometry geometry; geometry.fColor = color; geometry.fDevOutside = devOutside; @@ -30,12 +30,11 @@ static GrBatch* create_stroke_aa_batch(GrColor color, namespace GrRectBatchFactory { - -GrBatch* CreateStrokeBW(GrColor color, - const SkMatrix& viewMatrix, - const SkRect& rect, - SkScalar strokeWidth, - bool snapToPixelCenters) { +GrDrawBatch* CreateStrokeBW(GrColor color, + const SkMatrix& viewMatrix, + const SkRect& rect, + SkScalar strokeWidth, + bool snapToPixelCenters) { GrStrokeRectBatch::Geometry geometry; geometry.fColor = color; geometry.fViewMatrix = viewMatrix; @@ -44,11 +43,11 @@ GrBatch* CreateStrokeBW(GrColor color, return GrStrokeRectBatch::Create(geometry, snapToPixelCenters); } -GrBatch* CreateStrokeAA(GrColor color, - const SkMatrix& viewMatrix, - const SkRect& rect, - const SkRect& devRect, - const SkStrokeRec& stroke) { +GrDrawBatch* CreateStrokeAA(GrColor color, + const SkMatrix& viewMatrix, + const SkRect& rect, + const SkRect& devRect, + const SkStrokeRec& stroke) { SkVector devStrokeSize; SkScalar width = stroke.getWidth(); if (width > 0) { @@ -103,9 +102,9 @@ GrBatch* CreateStrokeAA(GrColor color, miterStroke); } -GrBatch* CreateFillNestedRectsAA(GrColor color, - const SkMatrix& viewMatrix, - const SkRect rects[2]) { +GrDrawBatch* CreateFillNestedRectsAA(GrColor color, + const SkMatrix& viewMatrix, + const SkRect rects[2]) { SkASSERT(viewMatrix.rectStaysRect()); SkASSERT(!rects[0].isEmpty() && !rects[1].isEmpty()); diff --git a/src/gpu/batches/GrRectBatchFactory.h b/src/gpu/batches/GrRectBatchFactory.h index 6ded22db7b..7eaec795e8 100644 --- a/src/gpu/batches/GrRectBatchFactory.h +++ b/src/gpu/batches/GrRectBatchFactory.h @@ -22,7 +22,7 @@ class SkStrokeRec; */ namespace GrRectBatchFactory { -inline GrBatch* CreateFillBW(GrColor color, +inline GrDrawBatch* CreateFillBW(GrColor color, const SkMatrix& viewMatrix, const SkRect& rect, const SkRect* localRect, @@ -30,29 +30,29 @@ inline GrBatch* CreateFillBW(GrColor color, return GrBWFillRectBatch::Create(color, viewMatrix, rect, localRect, localMatrix); } -inline GrBatch* CreateFillAA(GrColor color, - const SkMatrix& viewMatrix, - const SkRect& rect, - const SkRect& devRect) { +inline GrDrawBatch* CreateFillAA(GrColor color, + const SkMatrix& viewMatrix, + const SkRect& rect, + const SkRect& devRect) { return GrAAFillRectBatch::Create(color, viewMatrix, rect, devRect); } -GrBatch* CreateStrokeBW(GrColor color, - const SkMatrix& viewMatrix, - const SkRect& rect, - SkScalar strokeWidth, - bool snapToPixelCenters); +GrDrawBatch* CreateStrokeBW(GrColor color, + const SkMatrix& viewMatrix, + const SkRect& rect, + SkScalar strokeWidth, + bool snapToPixelCenters); -GrBatch* CreateStrokeAA(GrColor, - const SkMatrix& viewMatrix, - const SkRect& rect, - const SkRect& devRect, - const SkStrokeRec& stroke); +GrDrawBatch* CreateStrokeAA(GrColor, + const SkMatrix& viewMatrix, + const SkRect& rect, + const SkRect& devRect, + const SkStrokeRec& stroke); // First rect is outer; second rect is inner -GrBatch* CreateFillNestedRectsAA(GrColor, - const SkMatrix& viewMatrix, - const SkRect rects[2]); +GrDrawBatch* CreateFillNestedRectsAA(GrColor, + const SkMatrix& viewMatrix, + const SkRect rects[2]); }; diff --git a/src/gpu/batches/GrStrokeRectBatch.cpp b/src/gpu/batches/GrStrokeRectBatch.cpp index 9c31149a5b..649ba01ddd 100644 --- a/src/gpu/batches/GrStrokeRectBatch.cpp +++ b/src/gpu/batches/GrStrokeRectBatch.cpp @@ -128,7 +128,7 @@ void GrStrokeRectBatch::generateGeometry(GrBatchTarget* batchTarget) { #ifdef GR_TEST_UTILS -BATCH_TEST_DEFINE(GrStrokeRectBatch) { +DRAW_BATCH_TEST_DEFINE(GrStrokeRectBatch) { GrStrokeRectBatch::Geometry geometry; geometry.fViewMatrix = GrTest::TestMatrix(random); geometry.fColor = GrRandomColor(random); diff --git a/src/gpu/batches/GrStrokeRectBatch.h b/src/gpu/batches/GrStrokeRectBatch.h index 7979a6492d..2c891a467d 100644 --- a/src/gpu/batches/GrStrokeRectBatch.h +++ b/src/gpu/batches/GrStrokeRectBatch.h @@ -12,7 +12,7 @@ #include "GrColor.h" #include "GrDefaultGeoProcFactory.h" -class GrStrokeRectBatch : public GrBatch { +class GrStrokeRectBatch : public GrVertexBatch { public: struct Geometry { GrColor fColor; @@ -21,7 +21,7 @@ public: SkScalar fStrokeWidth; }; - static GrBatch* Create(const Geometry& geometry, bool snapToPixelCenters) { + static GrDrawBatch* Create(const Geometry& geometry, bool snapToPixelCenters) { return SkNEW_ARGS(GrStrokeRectBatch, (geometry, snapToPixelCenters)); } diff --git a/src/gpu/batches/GrTestBatch.h b/src/gpu/batches/GrTestBatch.h index 68ea676d25..d8986b6816 100644 --- a/src/gpu/batches/GrTestBatch.h +++ b/src/gpu/batches/GrTestBatch.h @@ -16,7 +16,7 @@ * A simple batch only for testing purposes which actually doesn't batch at all, but can fit into * the batch pipeline and generate arbitrary geometry */ -class GrTestBatch : public GrBatch { +class GrTestBatch : public GrVertexBatch { public: struct Geometry { GrColor fColor; diff --git a/src/gpu/effects/GrDashingEffect.cpp b/src/gpu/effects/GrDashingEffect.cpp index 6a894f9e0e..92f6104e15 100644 --- a/src/gpu/effects/GrDashingEffect.cpp +++ b/src/gpu/effects/GrDashingEffect.cpp @@ -243,7 +243,7 @@ static GrGeometryProcessor* create_dash_gp(GrColor, const SkMatrix& localMatrix, bool usesLocalCoords); -class DashBatch : public GrBatch { +class DashBatch : public GrVertexBatch { public: struct Geometry { GrColor fColor; @@ -257,8 +257,8 @@ public: SkScalar fPerpendicularScale; }; - static GrBatch* Create(const Geometry& geometry, SkPaint::Cap cap, DashAAMode aaMode, - bool fullDash) { + static GrDrawBatch* Create(const Geometry& geometry, SkPaint::Cap cap, DashAAMode aaMode, + bool fullDash) { return SkNEW_ARGS(DashBatch, (geometry, cap, aaMode, fullDash)); } @@ -618,13 +618,12 @@ private: } bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { - if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *t->pipeline(), t->bounds(), - caps)) { + DashBatch* that = t->cast<DashBatch>(); + if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), + that->bounds(), caps)) { return false; } - DashBatch* that = t->cast<DashBatch>(); - if (this->aaMode() != that->aaMode()) { return false; } @@ -677,8 +676,8 @@ private: SkSTArray<1, Geometry, true> fGeoData; }; -static GrBatch* create_batch(GrColor color, const SkMatrix& viewMatrix, const SkPoint pts[2], - bool useAA, const GrStrokeInfo& strokeInfo, bool msaaRT) { +static GrDrawBatch* create_batch(GrColor color, const SkMatrix& viewMatrix, const SkPoint pts[2], + bool useAA, const GrStrokeInfo& strokeInfo, bool msaaRT) { const SkScalar* intervals = strokeInfo.getDashIntervals(); SkScalar phase = strokeInfo.getDashPhase(); @@ -734,7 +733,7 @@ bool GrDashingEffect::DrawDashLine(GrDrawTarget* target, const GrPipelineBuilder& pipelineBuilder, GrColor color, const SkMatrix& viewMatrix, const SkPoint pts[2], bool useAA, const GrStrokeInfo& strokeInfo) { - SkAutoTUnref<GrBatch> batch( + SkAutoTUnref<GrDrawBatch> batch( create_batch(color, viewMatrix, pts, useAA, strokeInfo, pipelineBuilder.getRenderTarget()->isUnifiedMultisampled())); if (!batch) { @@ -1229,7 +1228,7 @@ static GrGeometryProcessor* create_dash_gp(GrColor color, #ifdef GR_TEST_UTILS -BATCH_TEST_DEFINE(DashBatch) { +DRAW_BATCH_TEST_DEFINE(DashBatch) { GrColor color = GrRandomColor(random); SkMatrix viewMatrix = GrTest::TestMatrixPreservesRightAngles(random); bool useAA = random->nextBool(); diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp index 85ee100365..57a65a0aa9 100644 --- a/tests/GLProgramsTest.cpp +++ b/tests/GLProgramsTest.cpp @@ -238,7 +238,7 @@ bool GrDrawTarget::programUnitTest(GrContext* context, int maxStages) { pipelineBuilder.setRenderTarget(rt.get()); pipelineBuilder.setClip(clip); - SkAutoTUnref<GrBatch> batch(GrRandomBatch(&random, context)); + SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context)); SkASSERT(batch); GrProcessorDataManager procDataManager; diff --git a/tests/GrPorterDuffTest.cpp b/tests/GrPorterDuffTest.cpp index 0cd1db0131..c276e592f5 100644 --- a/tests/GrPorterDuffTest.cpp +++ b/tests/GrPorterDuffTest.cpp @@ -898,7 +898,7 @@ static void test_color_opaque_no_coverage(skiatest::Reporter* reporter, const Gr } static void test_lcd_coverage(skiatest::Reporter* reporter, const GrCaps& caps) { - class : public GrBatch { + class : public GrVertexBatch { void getInvariantOutputColor(GrInitInvariantOutput* out) const override { out->setKnownFourComponents(GrColorPackRGBA(123, 45, 67, 221)); } |