add a ClassID function to GrBatch
authorjoshualitt <joshualitt@chromium.org>
Thu, 17 Sep 2015 18:50:57 +0000 (11:50 -0700)
committerCommit bot <commit-bot@chromium.org>
Thu, 17 Sep 2015 18:50:57 +0000 (11:50 -0700)
BUG=skia:

Committed: https://skia.googlesource.com/skia/+/4078d529e9e199eea13456db7bf3a63a104ab5b9

Review URL: https://codereview.chromium.org/1352813003

34 files changed:
gm/beziereffects.cpp
gm/convexpolyeffect.cpp
src/gpu/GrAtlasTextContext.cpp
src/gpu/GrDrawTarget.h
src/gpu/GrOvalRenderer.cpp
src/gpu/batches/GrAAConvexPathRenderer.cpp
src/gpu/batches/GrAADistanceFieldPathRenderer.cpp
src/gpu/batches/GrAAHairLinePathRenderer.cpp
src/gpu/batches/GrAALinearizingConvexPathRenderer.cpp
src/gpu/batches/GrAAStrokeRectBatch.h
src/gpu/batches/GrBatch.cpp
src/gpu/batches/GrBatch.h
src/gpu/batches/GrClearBatch.h
src/gpu/batches/GrCopySurfaceBatch.h
src/gpu/batches/GrDefaultPathRenderer.cpp
src/gpu/batches/GrDiscardBatch.h
src/gpu/batches/GrDrawAtlasBatch.cpp
src/gpu/batches/GrDrawAtlasBatch.h
src/gpu/batches/GrDrawBatch.cpp
src/gpu/batches/GrDrawBatch.h
src/gpu/batches/GrDrawPathBatch.cpp
src/gpu/batches/GrDrawPathBatch.h
src/gpu/batches/GrDrawVerticesBatch.cpp
src/gpu/batches/GrDrawVerticesBatch.h
src/gpu/batches/GrStencilPathBatch.h
src/gpu/batches/GrStrokeRectBatch.cpp
src/gpu/batches/GrStrokeRectBatch.h
src/gpu/batches/GrTInstanceBatch.h
src/gpu/batches/GrTessellatingPathRenderer.cpp
src/gpu/batches/GrTestBatch.h
src/gpu/batches/GrVertexBatch.cpp
src/gpu/batches/GrVertexBatch.h
src/gpu/effects/GrDashingEffect.cpp
tests/GrPorterDuffTest.cpp

index 1886a4a..81d5c58 100644 (file)
@@ -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 {
index c014e6a..35cc498 100644 (file)
@@ -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 {
index fa96a8d..822c480 100644 (file)
@@ -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,
index cae1552..b12ac99 100644 (file)
@@ -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"
index 8eed382..8a938c2 100644 (file)
@@ -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,
index 75bf332..543885e 100644 (file)
@@ -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) {
index f06553c..ee5fdb8 100644 (file)
@@ -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) {
index c6bdd05..d17ed09 100644 (file)
@@ -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) {
index d05fe4e..a7e9824 100644 (file)
@@ -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) {
index ae75348..fad5bd9 100644 (file)
@@ -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;
 };
 
 
index a3a9884..19c19ff 100644 (file)
@@ -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;)
index b6eec1f..c5fc80c 100644 (file)
@@ -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;
 };
 
index f13b073..b973dab 100644 (file)
 
 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
index 584bbab..ed5e77f 100644 (file)
@@ -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
index f4ce7c8..67bccb6 100644 (file)
@@ -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,
index 8a050a7..c13e732 100644 (file)
 
 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
index 3596e16..2254e9c 100644 (file)
@@ -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);
     
index 9a864c0..de128f2 100644 (file)
 
 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
index 5e5d412..43ef2ec 100644 (file)
@@ -7,7 +7,7 @@
 
 #include "GrDrawBatch.h"
 
-GrDrawBatch::GrDrawBatch() : fPipelineInstalled(false) { }
+GrDrawBatch::GrDrawBatch(uint32_t classID) : INHERITED(classID), fPipelineInstalled(false) { }
 
 GrDrawBatch::~GrDrawBatch() {
     if (fPipelineInstalled) {
index f7c206d..93326ef 100644 (file)
@@ -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;
index a47e665..c56c4ad 100644 (file)
@@ -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
index 71ef9d4..228ad86 100644 (file)
@@ -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));
index f79b685..33bed0d 100644 (file)
@@ -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;
index aaa7b09..49e93c8 100644 (file)
@@ -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
index 9f6740a..a0dcadb 100644 (file)
@@ -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
index 766302b..20c754c 100644 (file)
@@ -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);
index b374ea8..b1cb8d4 100644 (file)
@@ -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
index e314959..014ec12 100644 (file)
@@ -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
index 46fa280..901d383 100644 (file)
@@ -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) {
index 085b184..02881c9 100644 (file)
@@ -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
index 6e2c157..9ffe518 100644 (file)
@@ -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);
index e2265bc..8922c30 100644 (file)
@@ -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
index 3ca4c7a..106ee49 100644 (file)
@@ -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],
index 1328272..a61ab54 100644 (file)
@@ -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;