Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Unified Diff: include/gpu/GrCacheable.h

Issue 392333008: Make GrCacheable implement its own ref counting. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: int32_t Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;
« no previous file with comments | « include/core/SkRefCnt.h ('k') | include/gpu/GrContext.h » ('j') | src/gpu/GrContext.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698