diff options
-rw-r--r-- | src/gpu/GrNonAtomicRef.h | 15 | ||||
-rw-r--r-- | src/gpu/GrPipeline.h | 2 | ||||
-rw-r--r-- | src/gpu/batches/GrBatch.h | 5 |
3 files changed, 14 insertions, 8 deletions
diff --git a/src/gpu/GrNonAtomicRef.h b/src/gpu/GrNonAtomicRef.h index efa2881c5f..e1503bcf06 100644 --- a/src/gpu/GrNonAtomicRef.h +++ b/src/gpu/GrNonAtomicRef.h @@ -15,15 +15,18 @@ * A simple non-atomic ref used in the GrBackend when we don't want to pay for the overhead of a * threadsafe ref counted object */ -class GrNonAtomicRef : public SkNoncopyable { +template<typename TSubclass> class GrNonAtomicRef : public SkNoncopyable { public: GrNonAtomicRef() : fRefCnt(1) {} - virtual ~GrNonAtomicRef() { + +#ifdef SK_DEBUG + ~GrNonAtomicRef() { // fRefCnt can be one when a subclass is created statically SkASSERT((0 == fRefCnt || 1 == fRefCnt)); // Set to invalid values. - SkDEBUGCODE(fRefCnt = -10;) + fRefCnt = -10; } +#endif void ref() const { // Once the ref cnt reaches zero it should never be ref'ed again. @@ -35,7 +38,7 @@ public: SkASSERT(fRefCnt > 0); --fRefCnt; if (0 == fRefCnt) { - delete this; + GrTDeleteNonAtomicRef(static_cast<const TSubclass*>(this)); return; } } @@ -46,4 +49,8 @@ private: typedef SkNoncopyable INHERITED; }; +template<typename T> inline void GrTDeleteNonAtomicRef(const T* ref) { + delete ref; +} + #endif diff --git a/src/gpu/GrPipeline.h b/src/gpu/GrPipeline.h index 10ffc865f0..4f81ae40d0 100644 --- a/src/gpu/GrPipeline.h +++ b/src/gpu/GrPipeline.h @@ -41,7 +41,7 @@ struct GrPipelineOptimizations { * Class that holds an optimized version of a GrPipelineBuilder. It is meant to be an immutable * class, and contains all data needed to set the state for a gpu draw. */ -class GrPipeline : public GrNonAtomicRef { +class GrPipeline : public GrNonAtomicRef<GrPipeline> { public: /////////////////////////////////////////////////////////////////////////// /// @name Creation diff --git a/src/gpu/batches/GrBatch.h b/src/gpu/batches/GrBatch.h index a66d6ae308..b29c8a49b7 100644 --- a/src/gpu/batches/GrBatch.h +++ b/src/gpu/batches/GrBatch.h @@ -53,10 +53,10 @@ class GrRenderTarget; return kClassID; \ } -class GrBatch : public GrNonAtomicRef { +class GrBatch : public GrNonAtomicRef<GrBatch> { public: GrBatch(uint32_t classID); - ~GrBatch() override; + virtual ~GrBatch(); virtual const char* name() const = 0; @@ -159,7 +159,6 @@ private: static int32_t gCurrBatchUniqueID; #endif static int32_t gCurrBatchClassID; - typedef GrNonAtomicRef INHERITED; }; #endif |