Chromium Code Reviews| Index: include/gpu/GrCacheable.h |
| diff --git a/include/gpu/GrCacheable.h b/include/gpu/GrCacheable.h |
| index 344ae6b58319edd1e41fe7222ef0087a188c79e3..2ef9f7728af63dfa14ee30018332d51e9768ac29 100644 |
| --- a/include/gpu/GrCacheable.h |
| +++ b/include/gpu/GrCacheable.h |
| @@ -15,10 +15,26 @@ class GrResourceCacheEntry; |
| /** |
| * Base class for objects that can be kept in the GrResourceCache. |
| */ |
| -class GrCacheable : public SkRefCnt { |
| +class GrCacheable : public SkNoncopyable { |
| public: |
|
robertphillips
2014/07/21 20:53:05
This macro call needs to go (along with those in a
|
| SK_DECLARE_INST_COUNT(GrCacheable) |
| + // These method signatures are written to mirror SkRefCnt. However, we don't require |
| + // thread safety as GrCacheable objects are not intended to cross thread boundaries. |
| + // internal_dispose() exists because of GrTexture's reliance on it. It will be removed |
| + // soon. |
| + void ref() const { ++fRefCnt; } |
| + void unref() const { --fRefCnt; if (0 == fRefCnt) { this->internal_dispose(); } } |
| + virtual void internal_dispose() const { SkDELETE(this); } |
| + bool unique() const { return 1 == fRefCnt; } |
| +#ifdef SK_DEBUG |
| + void validate() const { |
| + SkASSERT(fRefCnt > 0); |
| + } |
| +#endif |
| + |
| + virtual ~GrCacheable() { SkASSERT(0 == fRefCnt); } |
| + |
| /** |
| * Retrieves the amount of GPU memory used by this resource in bytes. It is |
| * approximate since we aren't aware of additional padding or copies made |
| @@ -50,7 +66,8 @@ public: |
| protected: |
| GrCacheable() |
| - : fCacheEntry(NULL) |
| + : fRefCnt(1) |
| + , fCacheEntry(NULL) |
| , fGenID(0) {} |
| bool isInCache() const { return NULL != fCacheEntry; } |
| @@ -64,6 +81,7 @@ protected: |
| void didChangeGpuMemorySize() const; |
| private: |
| + mutable int32_t fRefCnt; |
| GrResourceCacheEntry* fCacheEntry; // NULL if not in cache |
| mutable uint32_t fGenID; |