diff options
author | joshualitt <joshualitt@chromium.org> | 2015-09-17 11:50:57 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-17 11:50:57 -0700 |
commit | eb44d53cf96a7eaf103a98d76079ce1f5495e343 (patch) | |
tree | 5693fc5be9ef4dccb7917b13905d821963b48e4f | |
parent | a7008403dcd03302e88e2df546d8427afe9e0e80 (diff) |
add a ClassID function to GrBatch
BUG=skia:
Committed: https://skia.googlesource.com/skia/+/4078d529e9e199eea13456db7bf3a63a104ab5b9
Review URL: https://codereview.chromium.org/1352813003
34 files changed, 201 insertions, 100 deletions
diff --git a/gm/beziereffects.cpp b/gm/beziereffects.cpp index 1886a4a2b0..81d5c583d8 100644 --- a/gm/beziereffects.cpp +++ b/gm/beziereffects.cpp @@ -32,6 +32,7 @@ namespace skiagm { class BezierCubicOrConicTestBatch : public GrTestBatch { public: + DEFINE_BATCH_CLASS_ID struct Geometry : public GrTestBatch::Geometry { SkRect fBounds; }; @@ -46,8 +47,7 @@ public: private: BezierCubicOrConicTestBatch(const GrGeometryProcessor* gp, const Geometry& geo, const SkScalar klmEqs[9], SkScalar sign) - : INHERITED(gp, geo.fBounds) { - this->initClassID<BezierCubicOrConicTestBatch>(); + : INHERITED(ClassID(), gp, geo.fBounds) { for (int i = 0; i < 9; i++) { fKlmEqs[i] = klmEqs[i]; } @@ -432,6 +432,7 @@ private: class BezierQuadTestBatch : public GrTestBatch { public: + DEFINE_BATCH_CLASS_ID struct Geometry : public GrTestBatch::Geometry { SkRect fBounds; }; @@ -446,10 +447,9 @@ public: private: BezierQuadTestBatch(const GrGeometryProcessor* gp, const Geometry& geo, const GrPathUtils::QuadUVMatrix& devToUV) - : INHERITED(gp, geo.fBounds) + : INHERITED(ClassID(), gp, geo.fBounds) , fGeometry(geo) , fDevToUV(devToUV) { - this->initClassID<BezierQuadTestBatch>(); } struct Vertex { diff --git a/gm/convexpolyeffect.cpp b/gm/convexpolyeffect.cpp index c014e6a7f5..35cc49859b 100644 --- a/gm/convexpolyeffect.cpp +++ b/gm/convexpolyeffect.cpp @@ -31,6 +31,7 @@ namespace skiagm { class ConvexPolyTestBatch : public GrTestBatch { public: + DEFINE_BATCH_CLASS_ID struct Geometry : public GrTestBatch::Geometry { SkRect fBounds; }; @@ -43,9 +44,8 @@ public: private: ConvexPolyTestBatch(const GrGeometryProcessor* gp, const Geometry& geo) - : INHERITED(gp, geo.fBounds) + : INHERITED(ClassID(), gp, geo.fBounds) , fGeometry(geo) { - this->initClassID<ConvexPolyTestBatch>(); } Geometry* geoData(int index) override { diff --git a/src/gpu/GrAtlasTextContext.cpp b/src/gpu/GrAtlasTextContext.cpp index fa96a8ddda..822c480ef3 100644 --- a/src/gpu/GrAtlasTextContext.cpp +++ b/src/gpu/GrAtlasTextContext.cpp @@ -1431,6 +1431,8 @@ inline void GrAtlasTextContext::appendGlyphCommon(GrAtlasTextBlob* blob, Run* ru class TextBatch : public GrVertexBatch { public: + DEFINE_BATCH_CLASS_ID + typedef GrAtlasTextContext::DistanceAdjustTable DistanceAdjustTable; typedef GrAtlasTextBlob Blob; typedef Blob::Run Run; @@ -1448,7 +1450,6 @@ public: GrBatchFontCache* fontCache) { TextBatch* batch = new TextBatch; - batch->initClassID<TextBatch>(); batch->fFontCache = fontCache; switch (maskFormat) { case kA8_GrMaskFormat: @@ -1474,7 +1475,7 @@ public: SkColor filteredColor, bool isLCD, bool useBGR) { TextBatch* batch = new TextBatch; - batch->initClassID<TextBatch>(); + batch->fFontCache = fontCache; batch->fMaskType = isLCD ? kLCDDistanceField_MaskType : kGrayscaleDistanceField_MaskType; batch->fDistanceAdjustTable.reset(SkRef(distanceAdjustTable)); @@ -1783,7 +1784,7 @@ private: this->flush(target, &flushInfo); } - TextBatch() {} // initialized in factory functions. + TextBatch() : INHERITED(ClassID()) {} // initialized in factory functions. ~TextBatch() { for (int i = 0; i < fGeoCount; i++) { @@ -2044,6 +2045,8 @@ private: // Distance field properties SkAutoTUnref<const DistanceAdjustTable> fDistanceAdjustTable; SkColor fFilteredColor; + + typedef GrVertexBatch INHERITED; }; void GrAtlasTextContext::flushRunAsPaths(GrDrawContext* dc, GrRenderTarget* rt, diff --git a/src/gpu/GrDrawTarget.h b/src/gpu/GrDrawTarget.h index cae1552a3d..b12ac99de4 100644 --- a/src/gpu/GrDrawTarget.h +++ b/src/gpu/GrDrawTarget.h @@ -23,6 +23,7 @@ #include "SkClipStack.h" #include "SkMatrix.h" #include "SkPath.h" +#include "SkStringUtils.h" #include "SkStrokeRec.h" #include "SkTArray.h" #include "SkTLazy.h" diff --git a/src/gpu/GrOvalRenderer.cpp b/src/gpu/GrOvalRenderer.cpp index 8eed38233b..8a938c2265 100644 --- a/src/gpu/GrOvalRenderer.cpp +++ b/src/gpu/GrOvalRenderer.cpp @@ -606,13 +606,15 @@ bool GrOvalRenderer::DrawOval(GrDrawTarget* target, class CircleBatch : public GrVertexBatch { public: + DEFINE_BATCH_CLASS_ID + struct Geometry { - GrColor fColor; SkMatrix fViewMatrix; + SkRect fDevBounds; SkScalar fInnerRadius; SkScalar fOuterRadius; + GrColor fColor; bool fStroke; - SkRect fDevBounds; }; static GrDrawBatch* Create(const Geometry& geometry) { return new CircleBatch(geometry); } @@ -705,8 +707,7 @@ private: SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } - CircleBatch(const Geometry& geometry) { - this->initClassID<CircleBatch>(); + CircleBatch(const Geometry& geometry) : INHERITED(ClassID()) { fGeoData.push_back(geometry); this->setBounds(geometry.fDevBounds); @@ -753,6 +754,8 @@ private: BatchTracker fBatch; SkSTArray<1, Geometry, true> fGeoData; + + typedef GrVertexBatch INHERITED; }; static GrDrawBatch* create_circle_batch(GrColor color, @@ -821,15 +824,17 @@ void GrOvalRenderer::DrawCircle(GrDrawTarget* target, class EllipseBatch : public GrVertexBatch { public: + DEFINE_BATCH_CLASS_ID + struct Geometry { - GrColor fColor; SkMatrix fViewMatrix; + SkRect fDevBounds; SkScalar fXRadius; SkScalar fYRadius; SkScalar fInnerXRadius; SkScalar fInnerYRadius; + GrColor fColor; bool fStroke; - SkRect fDevBounds; }; static GrDrawBatch* Create(const Geometry& geometry) { return new EllipseBatch(geometry); } @@ -926,8 +931,7 @@ private: SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } - EllipseBatch(const Geometry& geometry) { - this->initClassID<EllipseBatch>(); + EllipseBatch(const Geometry& geometry) : INHERITED(ClassID()) { fGeoData.push_back(geometry); this->setBounds(geometry.fDevBounds); @@ -975,6 +979,8 @@ private: BatchTracker fBatch; SkSTArray<1, Geometry, true> fGeoData; + + typedef GrVertexBatch INHERITED; }; static GrDrawBatch* create_ellipse_batch(GrColor color, @@ -1085,17 +1091,19 @@ bool GrOvalRenderer::DrawEllipse(GrDrawTarget* target, class DIEllipseBatch : public GrVertexBatch { public: + DEFINE_BATCH_CLASS_ID + struct Geometry { - GrColor fColor; SkMatrix fViewMatrix; + SkRect fBounds; SkScalar fXRadius; SkScalar fYRadius; SkScalar fInnerXRadius; SkScalar fInnerYRadius; SkScalar fGeoDx; SkScalar fGeoDy; + GrColor fColor; DIEllipseEdgeEffect::Mode fMode; - SkRect fBounds; }; static GrDrawBatch* Create(const Geometry& geometry, const SkRect& bounds) { @@ -1186,8 +1194,7 @@ private: SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } - DIEllipseBatch(const Geometry& geometry, const SkRect& bounds) { - this->initClassID<DIEllipseBatch>(); + DIEllipseBatch(const Geometry& geometry, const SkRect& bounds) : INHERITED(ClassID()) { fGeoData.push_back(geometry); this->setBounds(bounds); @@ -1234,6 +1241,8 @@ private: BatchTracker fBatch; SkSTArray<1, Geometry, true> fGeoData; + + typedef GrVertexBatch INHERITED; }; static GrDrawBatch* create_diellipse_batch(GrColor color, @@ -1441,13 +1450,15 @@ bool GrOvalRenderer::DrawDRRect(GrDrawTarget* target, class RRectCircleRendererBatch : public GrVertexBatch { public: + DEFINE_BATCH_CLASS_ID + struct Geometry { - GrColor fColor; SkMatrix fViewMatrix; + SkRect fDevBounds; SkScalar fInnerRadius; SkScalar fOuterRadius; + GrColor fColor; bool fStroke; - SkRect fDevBounds; }; static GrDrawBatch* Create(const Geometry& geometry) { @@ -1563,8 +1574,7 @@ private: SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } - RRectCircleRendererBatch(const Geometry& geometry) { - this->initClassID<RRectCircleRendererBatch>(); + RRectCircleRendererBatch(const Geometry& geometry) : INHERITED(ClassID()) { fGeoData.push_back(geometry); this->setBounds(geometry.fDevBounds); @@ -1611,19 +1621,23 @@ private: BatchTracker fBatch; SkSTArray<1, Geometry, true> fGeoData; + + typedef GrVertexBatch INHERITED; }; class RRectEllipseRendererBatch : public GrVertexBatch { public: + DEFINE_BATCH_CLASS_ID + struct Geometry { - GrColor fColor; SkMatrix fViewMatrix; + SkRect fDevBounds; SkScalar fXRadius; SkScalar fYRadius; SkScalar fInnerXRadius; SkScalar fInnerYRadius; + GrColor fColor; bool fStroke; - SkRect fDevBounds; }; static GrDrawBatch* Create(const Geometry& geometry) { @@ -1749,8 +1763,7 @@ private: SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } - RRectEllipseRendererBatch(const Geometry& geometry) { - this->initClassID<RRectEllipseRendererBatch>(); + RRectEllipseRendererBatch(const Geometry& geometry) : INHERITED(ClassID()) { fGeoData.push_back(geometry); this->setBounds(geometry.fDevBounds); @@ -1798,6 +1811,8 @@ private: BatchTracker fBatch; SkSTArray<1, Geometry, true> fGeoData; + + typedef GrVertexBatch INHERITED; }; static GrDrawBatch* create_rrect_batch(GrColor color, diff --git a/src/gpu/batches/GrAAConvexPathRenderer.cpp b/src/gpu/batches/GrAAConvexPathRenderer.cpp index 75bf332790..543885e54f 100644 --- a/src/gpu/batches/GrAAConvexPathRenderer.cpp +++ b/src/gpu/batches/GrAAConvexPathRenderer.cpp @@ -733,6 +733,7 @@ static const GrGeometryProcessor* create_fill_gp(bool tweakAlphaForCoverage, class AAConvexPathBatch : public GrVertexBatch { public: + DEFINE_BATCH_CLASS_ID struct Geometry { GrColor fColor; SkMatrix fViewMatrix; @@ -752,7 +753,6 @@ public: } private: - void initBatchTracker(const GrPipelineOptimizations& opt) override { // Handle any color overrides if (!opt.readsColor()) { @@ -921,8 +921,7 @@ private: SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } - AAConvexPathBatch(const Geometry& geometry) { - this->initClassID<AAConvexPathBatch>(); + AAConvexPathBatch(const Geometry& geometry) : INHERITED(ClassID()) { fGeoData.push_back(geometry); // compute bounds @@ -979,6 +978,8 @@ private: BatchTracker fBatch; SkSTArray<1, Geometry, true> fGeoData; + + typedef GrVertexBatch INHERITED; }; bool GrAAConvexPathRenderer::onDrawPath(const DrawPathArgs& args) { diff --git a/src/gpu/batches/GrAADistanceFieldPathRenderer.cpp b/src/gpu/batches/GrAADistanceFieldPathRenderer.cpp index f06553c2d8..ee5fdb8a80 100644 --- a/src/gpu/batches/GrAADistanceFieldPathRenderer.cpp +++ b/src/gpu/batches/GrAADistanceFieldPathRenderer.cpp @@ -111,6 +111,8 @@ static const SkScalar kAntiAliasPad = 1.0f; class AADistanceFieldPathBatch : public GrVertexBatch { public: + DEFINE_BATCH_CLASS_ID + typedef GrAADistanceFieldPathRenderer::PathData PathData; typedef SkTDynamicHash<PathData, PathData::Key> PathCache; typedef GrAADistanceFieldPathRenderer::PathDataList PathDataList; @@ -276,8 +278,8 @@ private: AADistanceFieldPathBatch(const Geometry& geometry, GrColor color, const SkMatrix& viewMatrix, GrBatchAtlas* atlas, - PathCache* pathCache, PathDataList* pathList) { - this->initClassID<AADistanceFieldPathBatch>(); + PathCache* pathCache, PathDataList* pathList) + : INHERITED(ClassID()) { fBatch.fColor = color; fBatch.fViewMatrix = viewMatrix; fGeoData.push_back(geometry); @@ -519,6 +521,8 @@ private: GrBatchAtlas* fAtlas; PathCache* fPathCache; PathDataList* fPathList; + + typedef GrVertexBatch INHERITED; }; bool GrAADistanceFieldPathRenderer::onDrawPath(const DrawPathArgs& args) { diff --git a/src/gpu/batches/GrAAHairLinePathRenderer.cpp b/src/gpu/batches/GrAAHairLinePathRenderer.cpp index c6bdd055bb..d17ed09da9 100644 --- a/src/gpu/batches/GrAAHairLinePathRenderer.cpp +++ b/src/gpu/batches/GrAAHairLinePathRenderer.cpp @@ -672,6 +672,8 @@ bool check_bounds(const SkMatrix& viewMatrix, const SkRect& devBounds, void* ver class AAHairlineBatch : public GrVertexBatch { public: + DEFINE_BATCH_CLASS_ID + struct Geometry { GrColor fColor; uint8_t fCoverage; @@ -716,8 +718,7 @@ private: typedef SkTArray<int, true> IntArray; typedef SkTArray<float, true> FloatArray; - AAHairlineBatch(const Geometry& geometry) { - this->initClassID<AAHairlineBatch>(); + AAHairlineBatch(const Geometry& geometry) : INHERITED(ClassID()) { fGeoData.push_back(geometry); // compute bounds @@ -785,6 +786,8 @@ private: BatchTracker fBatch; SkSTArray<1, Geometry, true> fGeoData; + + typedef GrVertexBatch INHERITED; }; void AAHairlineBatch::onPrepareDraws(Target* target) { diff --git a/src/gpu/batches/GrAALinearizingConvexPathRenderer.cpp b/src/gpu/batches/GrAALinearizingConvexPathRenderer.cpp index d05fe4e908..a7e98249e2 100644 --- a/src/gpu/batches/GrAALinearizingConvexPathRenderer.cpp +++ b/src/gpu/batches/GrAALinearizingConvexPathRenderer.cpp @@ -119,6 +119,8 @@ static const GrGeometryProcessor* create_fill_gp(bool tweakAlphaForCoverage, class AAFlatteningConvexPathBatch : public GrVertexBatch { public: + DEFINE_BATCH_CLASS_ID + struct Geometry { GrColor fColor; SkMatrix fViewMatrix; @@ -258,8 +260,7 @@ private: SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } - AAFlatteningConvexPathBatch(const Geometry& geometry) { - this->initClassID<AAFlatteningConvexPathBatch>(); + AAFlatteningConvexPathBatch(const Geometry& geometry) : INHERITED(ClassID()) { fGeoData.push_back(geometry); // compute bounds @@ -308,6 +309,8 @@ private: BatchTracker fBatch; SkSTArray<1, Geometry, true> fGeoData; + + typedef GrVertexBatch INHERITED; }; bool GrAALinearizingConvexPathRenderer::onDrawPath(const DrawPathArgs& args) { diff --git a/src/gpu/batches/GrAAStrokeRectBatch.h b/src/gpu/batches/GrAAStrokeRectBatch.h index ae7534823b..fad5bd9d8d 100644 --- a/src/gpu/batches/GrAAStrokeRectBatch.h +++ b/src/gpu/batches/GrAAStrokeRectBatch.h @@ -18,6 +18,8 @@ class GrResourceProvider; class GrAAStrokeRectBatch : public GrVertexBatch { public: + DEFINE_BATCH_CLASS_ID + // TODO support AA rotated stroke rects by copying around view matrices struct Geometry { GrColor fColor; @@ -48,8 +50,8 @@ private: void onPrepareDraws(Target*) override; void initBatchTracker(const GrPipelineOptimizations&) override; - GrAAStrokeRectBatch(const Geometry& geometry, const SkMatrix& viewMatrix) { - this->initClassID<GrAAStrokeRectBatch>(); + GrAAStrokeRectBatch(const Geometry& geometry, const SkMatrix& viewMatrix) + : INHERITED(ClassID()) { fBatch.fViewMatrix = viewMatrix; fGeoData.push_back(geometry); @@ -105,6 +107,8 @@ private: BatchTracker fBatch; SkSTArray<1, Geometry, true> fGeoData; + + typedef GrVertexBatch INHERITED; }; diff --git a/src/gpu/batches/GrBatch.cpp b/src/gpu/batches/GrBatch.cpp index a3a9884b0f..19c19ffcf1 100644 --- a/src/gpu/batches/GrBatch.cpp +++ b/src/gpu/batches/GrBatch.cpp @@ -46,10 +46,10 @@ void GrBatch::operator delete(void* target) { return MemoryPoolAccessor().pool()->release(target); } -GrBatch::GrBatch() - : fClassID(kIllegalBatchID) +GrBatch::GrBatch(uint32_t classID) + : fClassID(classID) #if GR_BATCH_SPEW - , fUniqueID(GenID(&gCurrBatchUniqueID)) + , fUniqueID(GenBatchID()) #endif { SkDEBUGCODE(fUsed = false;) diff --git a/src/gpu/batches/GrBatch.h b/src/gpu/batches/GrBatch.h index b6eec1f969..c5fc80c5d5 100644 --- a/src/gpu/batches/GrBatch.h +++ b/src/gpu/batches/GrBatch.h @@ -41,9 +41,16 @@ class GrBatchFlushState; #define GrBATCH_INFO(...) #endif +// A helper macro to generate a class static id +#define DEFINE_BATCH_CLASS_ID \ + static uint32_t ClassID() { \ + static uint32_t kClassID = GenBatchClassID(); \ + return kClassID; \ + } + class GrBatch : public GrNonAtomicRef { public: - GrBatch(); + GrBatch(uint32_t classID); ~GrBatch() override; virtual const char* name() const = 0; @@ -69,10 +76,17 @@ public: } /** - * Helper for down-casting to a GrBatch subclass + * Helper for safely 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); } + template <typename T> const T& cast() const { + SkASSERT(T::ClassID() == this->classID()); + return *static_cast<const T*>(this); + } + + template <typename T> T* cast() { + SkASSERT(T::ClassID() == this->classID()); + return static_cast<T*>(this); + } uint32_t classID() const { SkASSERT(kIllegalBatchID != fClassID); return fClassID; } @@ -96,11 +110,6 @@ public: virtual SkString dumpInfo() const = 0; protected: - template <typename PROC_SUBCLASS> void initClassID() { - static uint32_t kClassID = GenID(&gCurrBatchClassID); - fClassID = kClassID; - } - // NOTE, compute some bounds, even if extremely conservative. Do *NOT* setLargest on the bounds // rect because we outset it for dst copy textures void setBounds(const SkRect& newBounds) { fBounds = newBounds; } @@ -109,6 +118,8 @@ protected: return fBounds.joinPossiblyEmptyRect(otherBounds); } + static uint32_t GenBatchClassID() { return GenID(&gCurrBatchClassID); } + SkRect fBounds; private: @@ -118,8 +129,7 @@ private: virtual void onDraw(GrBatchFlushState*) = 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 + // 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) { @@ -133,13 +143,14 @@ private: kIllegalBatchID = 0, }; - uint32_t fClassID; SkDEBUGCODE(bool fUsed;) + const uint32_t fClassID; #if GR_BATCH_SPEW - uint32_t fUniqueID; - static int32_t gCurrBatchUniqueID; + static uint32_t GenBatchID() { return GenID(&gCurrBatchUniqueID); } + const uint32_t fUniqueID; + static int32_t gCurrBatchUniqueID; #endif - static int32_t gCurrBatchClassID; + static int32_t gCurrBatchClassID; typedef GrNonAtomicRef INHERITED; }; diff --git a/src/gpu/batches/GrClearBatch.h b/src/gpu/batches/GrClearBatch.h index f13b073d75..b973dab557 100644 --- a/src/gpu/batches/GrClearBatch.h +++ b/src/gpu/batches/GrClearBatch.h @@ -15,11 +15,13 @@ class GrClearBatch final : public GrBatch { public: + DEFINE_BATCH_CLASS_ID + GrClearBatch(const SkIRect& rect, GrColor color, GrRenderTarget* rt) - : fRect(rect) + : INHERITED(ClassID()) + , fRect(rect) , fColor(color) , fRenderTarget(rt) { - this->initClassID<GrClearBatch>(); fBounds = SkRect::Make(rect); } @@ -50,15 +52,19 @@ private: SkIRect fRect; GrColor fColor; GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; + + typedef GrBatch INHERITED; }; class GrClearStencilClipBatch final : public GrBatch { public: + DEFINE_BATCH_CLASS_ID + GrClearStencilClipBatch(const SkIRect& rect, bool insideClip, GrRenderTarget* rt) - : fRect(rect) + : INHERITED(ClassID()) + , fRect(rect) , fInsideClip(insideClip) , fRenderTarget(rt) { - this->initClassID<GrClearStencilClipBatch>(); fBounds = SkRect::Make(rect); } @@ -86,6 +92,8 @@ private: SkIRect fRect; bool fInsideClip; GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; + + typedef GrBatch INHERITED; }; #endif diff --git a/src/gpu/batches/GrCopySurfaceBatch.h b/src/gpu/batches/GrCopySurfaceBatch.h index 584bbab5d7..ed5e77f5b0 100644 --- a/src/gpu/batches/GrCopySurfaceBatch.h +++ b/src/gpu/batches/GrCopySurfaceBatch.h @@ -15,6 +15,8 @@ class GrCopySurfaceBatch final : public GrBatch { public: + DEFINE_BATCH_CLASS_ID + static GrBatch* Create(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint); @@ -37,11 +39,11 @@ public: private: GrCopySurfaceBatch(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) - : fDst(dst) + : INHERITED(ClassID()) + , fDst(dst) , fSrc(src) , fSrcRect(srcRect) , fDstPoint(dstPoint) { - this->initClassID<GrCopySurfaceBatch>(); fBounds = SkRect::MakeXYWH(SkIntToScalar(dstPoint.fX), SkIntToScalar(dstPoint.fY), SkIntToScalar(srcRect.width()), SkIntToScalar(srcRect.height())); } @@ -58,6 +60,8 @@ private: GrPendingIOResource<GrSurface, kRead_GrIOType> fSrc; SkIRect fSrcRect; SkIPoint fDstPoint; + + typedef GrBatch INHERITED; }; #endif diff --git a/src/gpu/batches/GrDefaultPathRenderer.cpp b/src/gpu/batches/GrDefaultPathRenderer.cpp index f4ce7c85a5..67bccb63b4 100644 --- a/src/gpu/batches/GrDefaultPathRenderer.cpp +++ b/src/gpu/batches/GrDefaultPathRenderer.cpp @@ -211,6 +211,8 @@ static inline void add_quad(SkPoint** vert, const SkPoint* base, const SkPoint p class DefaultPathBatch : public GrVertexBatch { public: + DEFINE_BATCH_CLASS_ID + struct Geometry { GrColor fColor; SkPath fPath; @@ -376,8 +378,8 @@ private: SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } DefaultPathBatch(const Geometry& geometry, uint8_t coverage, const SkMatrix& viewMatrix, - bool isHairline, const SkRect& devBounds) { - this->initClassID<DefaultPathBatch>(); + bool isHairline, const SkRect& devBounds) + : INHERITED(ClassID()) { fBatch.fCoverage = coverage; fBatch.fIsHairline = isHairline; fBatch.fViewMatrix = viewMatrix; @@ -530,6 +532,8 @@ private: BatchTracker fBatch; SkSTArray<1, Geometry, true> fGeoData; + + typedef GrVertexBatch INHERITED; }; bool GrDefaultPathRenderer::internalDrawPath(GrDrawTarget* target, diff --git a/src/gpu/batches/GrDiscardBatch.h b/src/gpu/batches/GrDiscardBatch.h index 8a050a7122..c13e7327d7 100644 --- a/src/gpu/batches/GrDiscardBatch.h +++ b/src/gpu/batches/GrDiscardBatch.h @@ -15,9 +15,11 @@ class GrDiscardBatch final : public GrBatch { public: + DEFINE_BATCH_CLASS_ID + GrDiscardBatch(GrRenderTarget* rt) - : fRenderTarget(rt) { - this->initClassID<GrDiscardBatch>(); + : INHERITED(ClassID()) + , fRenderTarget(rt) { fBounds = SkRect::MakeWH(SkIntToScalar(rt->width()), SkIntToScalar(rt->height())); } @@ -43,6 +45,8 @@ private: } GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; + + typedef GrBatch INHERITED; }; #endif diff --git a/src/gpu/batches/GrDrawAtlasBatch.cpp b/src/gpu/batches/GrDrawAtlasBatch.cpp index 3596e16861..2254e9cdfe 100644 --- a/src/gpu/batches/GrDrawAtlasBatch.cpp +++ b/src/gpu/batches/GrDrawAtlasBatch.cpp @@ -77,8 +77,8 @@ void GrDrawAtlasBatch::onPrepareDraws(Target* target) { GrDrawAtlasBatch::GrDrawAtlasBatch(const Geometry& geometry, const SkMatrix& viewMatrix, int spriteCount, const SkRSXform* xforms, const SkRect* rects, - const SkColor* colors) { - this->initClassID<GrDrawAtlasBatch>(); + const SkColor* colors) + : INHERITED(ClassID()) { SkASSERT(xforms); SkASSERT(rects); diff --git a/src/gpu/batches/GrDrawAtlasBatch.h b/src/gpu/batches/GrDrawAtlasBatch.h index 9a864c01c9..de128f211d 100644 --- a/src/gpu/batches/GrDrawAtlasBatch.h +++ b/src/gpu/batches/GrDrawAtlasBatch.h @@ -14,11 +14,13 @@ class GrDrawAtlasBatch : public GrVertexBatch { public: + DEFINE_BATCH_CLASS_ID + struct Geometry { GrColor fColor; SkTArray<uint8_t, true> fVerts; }; - + static GrDrawBatch* Create(const Geometry& geometry, const SkMatrix& viewMatrix, int spriteCount, const SkRSXform* xforms, const SkRect* rects, const SkColor* colors) { @@ -66,6 +68,8 @@ private: bool fColorIgnored; bool fCoverageIgnored; bool fHasColors; + + typedef GrVertexBatch INHERITED; }; #endif diff --git a/src/gpu/batches/GrDrawBatch.cpp b/src/gpu/batches/GrDrawBatch.cpp index 5e5d41247a..43ef2ec64b 100644 --- a/src/gpu/batches/GrDrawBatch.cpp +++ b/src/gpu/batches/GrDrawBatch.cpp @@ -7,7 +7,7 @@ #include "GrDrawBatch.h" -GrDrawBatch::GrDrawBatch() : fPipelineInstalled(false) { } +GrDrawBatch::GrDrawBatch(uint32_t classID) : INHERITED(classID), fPipelineInstalled(false) { } GrDrawBatch::~GrDrawBatch() { if (fPipelineInstalled) { diff --git a/src/gpu/batches/GrDrawBatch.h b/src/gpu/batches/GrDrawBatch.h index f7c206d124..93326efad2 100644 --- a/src/gpu/batches/GrDrawBatch.h +++ b/src/gpu/batches/GrDrawBatch.h @@ -40,7 +40,7 @@ class GrDrawBatch : public GrBatch { public: class Target; - GrDrawBatch(); + GrDrawBatch(uint32_t classID); ~GrDrawBatch() override; virtual void getInvariantOutputColor(GrInitInvariantOutput* out) const = 0; diff --git a/src/gpu/batches/GrDrawPathBatch.cpp b/src/gpu/batches/GrDrawPathBatch.cpp index a47e665607..c56c4ad2cd 100644 --- a/src/gpu/batches/GrDrawPathBatch.cpp +++ b/src/gpu/batches/GrDrawPathBatch.cpp @@ -57,11 +57,10 @@ bool GrDrawPathRangeBatch::isWinding() const { GrDrawPathRangeBatch::GrDrawPathRangeBatch(const SkMatrix& viewMatrix, const SkMatrix& localMatrix, GrColor color, GrPathRangeDraw* pathRangeDraw) - : INHERITED(viewMatrix, color) + : INHERITED(ClassID(), viewMatrix, color) , fDraws(4) , fLocalMatrix(localMatrix) { SkDEBUGCODE(pathRangeDraw->fUsedInBatch = true;) - this->initClassID<GrDrawPathRangeBatch>(); fDraws.addToHead(SkRef(pathRangeDraw)); fTotalPathCount = pathRangeDraw->count(); // Don't compute a bounding box. For dst copy texture, we'll opt instead for it to just copy diff --git a/src/gpu/batches/GrDrawPathBatch.h b/src/gpu/batches/GrDrawPathBatch.h index 71ef9d42b4..228ad86617 100644 --- a/src/gpu/batches/GrDrawPathBatch.h +++ b/src/gpu/batches/GrDrawPathBatch.h @@ -30,8 +30,9 @@ public: void setStencilSettings(const GrStencilSettings& stencil) { fStencilSettings = stencil; } protected: - GrDrawPathBatchBase(const SkMatrix& viewMatrix, GrColor initialColor) - : fViewMatrix(viewMatrix) + GrDrawPathBatchBase(uint32_t classID, const SkMatrix& viewMatrix, GrColor initialColor) + : INHERITED(classID) + , fViewMatrix(viewMatrix) , fColor(initialColor) {} const GrStencilSettings& stencilSettings() const { return fStencilSettings; } @@ -55,6 +56,8 @@ private: class GrDrawPathBatch final : public GrDrawPathBatchBase { public: + DEFINE_BATCH_CLASS_ID + // This can't return a more abstract type because we install the stencil settings late :( static GrDrawPathBatchBase* Create(const SkMatrix& viewMatrix, GrColor color, const GrPath* path) { @@ -67,11 +70,10 @@ public: private: GrDrawPathBatch(const SkMatrix& viewMatrix, GrColor color, const GrPath* path) - : INHERITED(viewMatrix, color) + : INHERITED(ClassID(), viewMatrix, color) , fPath(path) { fBounds = path->getBounds(); viewMatrix.mapRect(&fBounds); - this->initClassID<GrDrawPathBatch>(); } bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { return false; } @@ -147,7 +149,9 @@ private: // Template this if we decide to support index types other than 16bit class GrDrawPathRangeBatch final : public GrDrawPathBatchBase { public: - // This can't return a more abstracet type because we install the stencil settings late :( + DEFINE_BATCH_CLASS_ID + + // This can't return a more abstract type because we install the stencil settings late :( static GrDrawPathBatchBase* Create(const SkMatrix& viewMatrix, const SkMatrix& localMatrix, GrColor color, GrPathRangeDraw* pathRangeDraw) { return SkNEW_ARGS(GrDrawPathRangeBatch, (viewMatrix, localMatrix, color, pathRangeDraw)); diff --git a/src/gpu/batches/GrDrawVerticesBatch.cpp b/src/gpu/batches/GrDrawVerticesBatch.cpp index f79b6859df..33bed0d0f8 100644 --- a/src/gpu/batches/GrDrawVerticesBatch.cpp +++ b/src/gpu/batches/GrDrawVerticesBatch.cpp @@ -45,8 +45,8 @@ GrDrawVerticesBatch::GrDrawVerticesBatch(const Geometry& geometry, GrPrimitiveTy const SkPoint* positions, int vertexCount, const uint16_t* indices, int indexCount, const GrColor* colors, const SkPoint* localCoords, - const SkRect& bounds) { - this->initClassID<GrDrawVerticesBatch>(); + const SkRect& bounds) + : INHERITED(ClassID()) { SkASSERT(positions); fBatch.fViewMatrix = viewMatrix; diff --git a/src/gpu/batches/GrDrawVerticesBatch.h b/src/gpu/batches/GrDrawVerticesBatch.h index aaa7b09812..49e93c8370 100644 --- a/src/gpu/batches/GrDrawVerticesBatch.h +++ b/src/gpu/batches/GrDrawVerticesBatch.h @@ -20,6 +20,8 @@ struct GrInitInvariantOutput; class GrDrawVerticesBatch : public GrVertexBatch { public: + DEFINE_BATCH_CLASS_ID + struct Geometry { GrColor fColor; SkTDArray<SkPoint> fPositions; @@ -91,6 +93,8 @@ private: BatchTracker fBatch; SkSTArray<1, Geometry, true> fGeoData; + + typedef GrVertexBatch INHERITED; }; #endif diff --git a/src/gpu/batches/GrStencilPathBatch.h b/src/gpu/batches/GrStencilPathBatch.h index 9f6740a046..a0dcadb620 100644 --- a/src/gpu/batches/GrStencilPathBatch.h +++ b/src/gpu/batches/GrStencilPathBatch.h @@ -17,6 +17,8 @@ class GrStencilPathBatch final : public GrBatch { public: + DEFINE_BATCH_CLASS_ID + static GrBatch* Create(const SkMatrix& viewMatrix, bool useHWAA, const GrStencilSettings& stencil, @@ -43,13 +45,13 @@ private: const GrScissorState& scissor, GrRenderTarget* renderTarget, const GrPath* path) - : fViewMatrix(viewMatrix) + : INHERITED(ClassID()) + , fViewMatrix(viewMatrix) , fUseHWAA(useHWAA) , fStencil(stencil) , fScissor(scissor) , fRenderTarget(renderTarget) , fPath(path) { - this->initClassID<GrStencilPathBatch>(); fBounds = path->getBounds(); } @@ -69,6 +71,8 @@ private: GrScissorState fScissor; GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; + + typedef GrBatch INHERITED; }; #endif diff --git a/src/gpu/batches/GrStrokeRectBatch.cpp b/src/gpu/batches/GrStrokeRectBatch.cpp index 766302bf5b..20c754c899 100644 --- a/src/gpu/batches/GrStrokeRectBatch.cpp +++ b/src/gpu/batches/GrStrokeRectBatch.cpp @@ -10,9 +10,8 @@ #include "GrBatchFlushState.h" #include "SkRandom.h" -GrStrokeRectBatch::GrStrokeRectBatch(const Geometry& geometry, bool snapToPixelCenters) { - this->initClassID<GrStrokeRectBatch>(); - +GrStrokeRectBatch::GrStrokeRectBatch(const Geometry& geometry, bool snapToPixelCenters) + : INHERITED(ClassID()) { fBatch.fHairline = geometry.fStrokeWidth == 0; fGeoData.push_back(geometry); diff --git a/src/gpu/batches/GrStrokeRectBatch.h b/src/gpu/batches/GrStrokeRectBatch.h index b374ea862d..b1cb8d4ccb 100644 --- a/src/gpu/batches/GrStrokeRectBatch.h +++ b/src/gpu/batches/GrStrokeRectBatch.h @@ -14,6 +14,8 @@ class GrStrokeRectBatch : public GrVertexBatch { public: + DEFINE_BATCH_CLASS_ID + struct Geometry { GrColor fColor; SkMatrix fViewMatrix; @@ -74,6 +76,8 @@ private: BatchTracker fBatch; SkSTArray<1, Geometry, true> fGeoData; + + typedef GrVertexBatch INHERITED; }; #endif diff --git a/src/gpu/batches/GrTInstanceBatch.h b/src/gpu/batches/GrTInstanceBatch.h index e314959bfc..014ec125fe 100644 --- a/src/gpu/batches/GrTInstanceBatch.h +++ b/src/gpu/batches/GrTInstanceBatch.h @@ -40,6 +40,8 @@ template <typename Impl> class GrTInstanceBatch : public GrVertexBatch { public: + DEFINE_BATCH_CLASS_ID + typedef typename Impl::Geometry Geometry; static GrTInstanceBatch* Create() { return new GrTInstanceBatch; } @@ -72,9 +74,7 @@ public: } private: - GrTInstanceBatch() { - this->initClassID<GrTInstanceBatch<Impl>>(); - + GrTInstanceBatch() : INHERITED(ClassID()) { // Push back an initial geometry fGeoData.push_back(); } @@ -136,6 +136,8 @@ private: GrPipelineOptimizations fOpts; SkSTArray<1, Geometry, true> fGeoData; + + typedef GrVertexBatch INHERITED; }; #endif diff --git a/src/gpu/batches/GrTessellatingPathRenderer.cpp b/src/gpu/batches/GrTessellatingPathRenderer.cpp index 46fa280cfd..901d38369c 100644 --- a/src/gpu/batches/GrTessellatingPathRenderer.cpp +++ b/src/gpu/batches/GrTessellatingPathRenderer.cpp @@ -1385,6 +1385,7 @@ bool GrTessellatingPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) cons class TessellatingPathBatch : public GrVertexBatch { public: + DEFINE_BATCH_CLASS_ID static GrDrawBatch* Create(const GrColor& color, const SkPath& path, @@ -1587,13 +1588,12 @@ private: const GrStrokeInfo& stroke, const SkMatrix& viewMatrix, const SkRect& clipBounds) - : fColor(color) + : INHERITED(ClassID()) + , fColor(color) , fPath(path) , fStroke(stroke) , fViewMatrix(viewMatrix) , fClipBounds(clipBounds) { - this->initClassID<TessellatingPathBatch>(); - fBounds = path.getBounds(); if (!stroke.isFillStyle()) { SkScalar radius = SkScalarHalf(stroke.getWidth()); @@ -1614,6 +1614,8 @@ private: SkMatrix fViewMatrix; SkRect fClipBounds; // in source space GrPipelineOptimizations fPipelineInfo; + + typedef GrVertexBatch INHERITED; }; bool GrTessellatingPathRenderer::onDrawPath(const DrawPathArgs& args) { diff --git a/src/gpu/batches/GrTestBatch.h b/src/gpu/batches/GrTestBatch.h index 085b184a28..02881c9668 100644 --- a/src/gpu/batches/GrTestBatch.h +++ b/src/gpu/batches/GrTestBatch.h @@ -50,7 +50,8 @@ public: } protected: - GrTestBatch(const GrGeometryProcessor* gp, const SkRect& bounds) { + GrTestBatch(uint32_t classID, const GrGeometryProcessor* gp, const SkRect& bounds) + : INHERITED(classID) { fGeometryProcessor.reset(SkRef(gp)); this->setBounds(bounds); @@ -82,6 +83,8 @@ private: SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor; BatchTracker fBatch; + + typedef GrVertexBatch INHERITED; }; #endif diff --git a/src/gpu/batches/GrVertexBatch.cpp b/src/gpu/batches/GrVertexBatch.cpp index 6e2c1577db..9ffe5180b7 100644 --- a/src/gpu/batches/GrVertexBatch.cpp +++ b/src/gpu/batches/GrVertexBatch.cpp @@ -9,7 +9,7 @@ #include "GrBatchFlushState.h" #include "GrResourceProvider.h" -GrVertexBatch::GrVertexBatch() : fDrawArrays(1) {} +GrVertexBatch::GrVertexBatch(uint32_t classID) : INHERITED(classID), fDrawArrays(1) {} void GrVertexBatch::onPrepare(GrBatchFlushState* state) { Target target(state, this); diff --git a/src/gpu/batches/GrVertexBatch.h b/src/gpu/batches/GrVertexBatch.h index e2265bc8fc..8922c30e2a 100644 --- a/src/gpu/batches/GrVertexBatch.h +++ b/src/gpu/batches/GrVertexBatch.h @@ -24,7 +24,7 @@ class GrVertexBatch : public GrDrawBatch { public: class Target; - GrVertexBatch(); + GrVertexBatch(uint32_t classID); protected: /** Helper for rendering instances using an instanced index index buffer. This class creates the diff --git a/src/gpu/effects/GrDashingEffect.cpp b/src/gpu/effects/GrDashingEffect.cpp index 3ca4c7ae4b..106ee49672 100644 --- a/src/gpu/effects/GrDashingEffect.cpp +++ b/src/gpu/effects/GrDashingEffect.cpp @@ -245,8 +245,9 @@ static GrGeometryProcessor* create_dash_gp(GrColor, class DashBatch : public GrVertexBatch { public: + DEFINE_BATCH_CLASS_ID + struct Geometry { - GrColor fColor; SkMatrix fViewMatrix; SkMatrix fSrcRotInv; SkPoint fPtsRot[2]; @@ -255,6 +256,7 @@ public: SkScalar fIntervals[2]; SkScalar fParallelScale; SkScalar fPerpendicularScale; + GrColor fColor; }; static GrDrawBatch* Create(const Geometry& geometry, SkPaint::Cap cap, DashAAMode aaMode, @@ -275,8 +277,8 @@ public: SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } private: - DashBatch(const Geometry& geometry, SkPaint::Cap cap, DashAAMode aaMode, bool fullDash) { - this->initClassID<DashBatch>(); + DashBatch(const Geometry& geometry, SkPaint::Cap cap, DashAAMode aaMode, bool fullDash) + : INHERITED(ClassID()) { fGeoData.push_back(geometry); fBatch.fAAMode = aaMode; @@ -674,6 +676,8 @@ private: BatchTracker fBatch; SkSTArray<1, Geometry, true> fGeoData; + + typedef GrVertexBatch INHERITED; }; static GrDrawBatch* create_batch(GrColor color, const SkMatrix& viewMatrix, const SkPoint pts[2], diff --git a/tests/GrPorterDuffTest.cpp b/tests/GrPorterDuffTest.cpp index 1328272a6a..a61ab5484b 100644 --- a/tests/GrPorterDuffTest.cpp +++ b/tests/GrPorterDuffTest.cpp @@ -1093,7 +1093,13 @@ static void test_color_opaque_no_coverage(skiatest::Reporter* reporter, const Gr } static void test_lcd_coverage_fallback_case(skiatest::Reporter* reporter, const GrCaps& caps) { - class : public GrVertexBatch { + class TestLCDCoverageBatch: public GrVertexBatch { + public: + DEFINE_BATCH_CLASS_ID + + TestLCDCoverageBatch() : INHERITED(ClassID()) {} + + private: void getInvariantOutputColor(GrInitInvariantOutput* out) const override { out->setKnownFourComponents(GrColorPackRGBA(123, 45, 67, 221)); } @@ -1108,6 +1114,7 @@ static void test_lcd_coverage_fallback_case(skiatest::Reporter* reporter, const bool onCombineIfPossible(GrBatch*, const GrCaps&) override { return false; } void onPrepareDraws(Target*) override {}; + typedef GrVertexBatch INHERITED; } testLCDCoverageBatch; GrProcOptInfo colorPOI, covPOI; |