* 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.
SkASSERT(fRefCnt > 0);
--fRefCnt;
if (0 == fRefCnt) {
- delete this;
+ GrTDeleteNonAtomicRef(static_cast<const TSubclass*>(this));
return;
}
}
typedef SkNoncopyable INHERITED;
};
+template<typename T> inline void GrTDeleteNonAtomicRef(const T* ref) {
+ delete ref;
+}
+
#endif
* 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
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;
static int32_t gCurrBatchUniqueID;
#endif
static int32_t gCurrBatchClassID;
- typedef GrNonAtomicRef INHERITED;
};
#endif