From 970cb5597a046edeb38676cd3827811698c938e2 Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Fri, 15 Jul 2011 15:52:28 +0000 Subject: [PATCH] convolve GrRefCnt and SkRefCnt git-svn-id: http://skia.googlecode.com/svn/trunk@1873 2bbb7eff-a529-9590-31e7-b0007b416f81 --- gpu/include/GrRefCnt.h | 107 +++-------------------------------------- 1 file changed, 7 insertions(+), 100 deletions(-) diff --git a/gpu/include/GrRefCnt.h b/gpu/include/GrRefCnt.h index 9c9fed1b9..4919b975e 100644 --- a/gpu/include/GrRefCnt.h +++ b/gpu/include/GrRefCnt.h @@ -19,90 +19,15 @@ #define GrRefCnt_DEFINED #include "GrTypes.h" -#include "GrNoncopyable.h" +#include "SkRefCnt.h" -/** - * Base class for reference counting. When an object is first instantiated, - * its reference count is 1. If the object may be null, use GrSafeRef() and - * GrSafeUnref(). - * - * It is an error (though only checked for in the debug build) to call unref() - * such that the reference count becomes 0. - */ -class GR_API GrRefCnt : GrNoncopyable { -public: - GrRefCnt() : fRefCnt(1) {} - virtual ~GrRefCnt() { - GrAssert(1 == fRefCnt); -#if GR_DEBUG - fRefCnt = 0; // force validate() to trigger if called afterwards -#endif - } +typedef SkRefCnt GrRefCnt; +typedef SkAutoRef GrAutoRef; +typedef SkAutoUnref GrAutoUnref; - int32_t refcnt() const { return fRefCnt; } - - void ref() const { - GrAssert(fRefCnt > 0); - ++fRefCnt; - } - - void unref() const { - GrAssert(fRefCnt > 0); - if (1 == fRefCnt) { - delete this; - } else { - --fRefCnt; - } - } - -#if GR_DEBUG - void validate() const { - GrAssert(fRefCnt > 0); - } -#else - void validate() const {} -#endif - -private: - mutable int32_t fRefCnt; -}; - -/////////////////////////////////////////////////////////////////////////////// - -/** - * Call with instance/subclass of GrRefCnt. This does nothing if obj is null, - * but otherwise it calls ref(). - */ -static inline void GrSafeRef(const GrRefCnt* obj) { - if (obj) { - obj->ref(); - } -} - -/** - * Call with instance/subclass of GrRefCnt. This does nothing if obj is null, - * but otherwise it calls unref(). - */ -static inline void GrSafeUnref(const GrRefCnt* obj) { - if (obj) { - obj->unref(); - } -} - -/** - * Assigns src to dst, checking for NULLs in each, and correctly incrementing - * the reference count of src, and decrementing the reference count of dst - */ -template -static inline void GrSafeAssign(T*& dst, T* src) { - if (src) { - src->ref(); - } - if (dst) { - dst->unref(); - } - dst = src; -} +static void GrSafeRef(const SkRefCnt* obj) { SkSafeRef(obj); } +static void GrSafeUnref(const SkRefCnt* obj) { SkSafeUnref(obj); } +#define GrSafeAssign(a, b) SkRefCnt_SafeAssign(a, b) template static inline void GrSafeSetNull(T*& obj) { @@ -112,23 +37,5 @@ static inline void GrSafeSetNull(T*& obj) { } } -/////////////////////////////////////////////////////////////////////////////// - -class GrAutoRef : GrNoncopyable { -public: - GrAutoRef(GrRefCnt* obj) : fObj(obj) { GrSafeRef(obj); } - ~GrAutoRef() { GrSafeUnref(fObj); } -private: - GrRefCnt* fObj; -}; - -class GrAutoUnref : GrNoncopyable { -public: - GrAutoUnref(GrRefCnt* obj) : fObj(obj) {} - ~GrAutoUnref() { GrSafeUnref(fObj); } -private: - GrRefCnt* fObj; -}; - #endif