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

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: remove extra blank line 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
« no previous file with comments | « include/core/SkRefCnt.h ('k') | include/gpu/GrContext.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/gpu/GrCacheable.h
diff --git a/include/gpu/GrCacheable.h b/include/gpu/GrCacheable.h
index 344ae6b58319edd1e41fe7222ef0087a188c79e3..0efc7f7d61e805ada59ace13c873dd23a9536aa8 100644
--- a/include/gpu/GrCacheable.h
+++ b/include/gpu/GrCacheable.h
@@ -15,9 +15,25 @@ class GrResourceCacheEntry;
/**
* Base class for objects that can be kept in the GrResourceCache.
*/
-class GrCacheable : public SkRefCnt {
+class GrCacheable : public SkNoncopyable {
public:
- SK_DECLARE_INST_COUNT(GrCacheable)
+ SK_DECLARE_INST_COUNT_ROOT(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
@@ -50,7 +66,8 @@ public:
protected:
GrCacheable()
- : fCacheEntry(NULL)
+ : fRefCnt(1)
+ , fCacheEntry(NULL)
, fGenID(0) {}
bool isInCache() const { return NULL != fCacheEntry; }
@@ -64,10 +81,11 @@ protected:
void didChangeGpuMemorySize() const;
private:
+ mutable int32_t fRefCnt;
GrResourceCacheEntry* fCacheEntry; // NULL if not in cache
mutable uint32_t fGenID;
- typedef SkRefCnt INHERITED;
+ typedef SkNoncopyable INHERITED;
};
#endif
« no previous file with comments | « include/core/SkRefCnt.h ('k') | include/gpu/GrContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698