diff options
author | robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-10-29 14:06:15 +0000 |
---|---|---|
committer | robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-10-29 14:06:15 +0000 |
commit | 9ef0426e7c126f6ad6ba833d4543b92a197c95af (patch) | |
tree | cf115ba1dcc4c092e4b0541b78bc6784b319a644 /include | |
parent | 0b7ab3bb49015c5316627d6893955596c59342b8 (diff) |
Don't reuse scratch textures patch
https://codereview.chromium.org/24222004/
git-svn-id: http://skia.googlecode.com/svn/trunk@11997 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include')
-rw-r--r-- | include/gpu/GrResource.h | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/include/gpu/GrResource.h b/include/gpu/GrResource.h index a3291e0c05..3fb2e7765d 100644 --- a/include/gpu/GrResource.h +++ b/include/gpu/GrResource.h @@ -66,10 +66,24 @@ public: void setCacheEntry(GrResourceEntry* cacheEntry) { fCacheEntry = cacheEntry; } GrResourceEntry* getCacheEntry() { return fCacheEntry; } - void incDeferredRefCount() const { SkASSERT(fDeferredRefCount >= 0); ++fDeferredRefCount; } - void decDeferredRefCount() const { SkASSERT(fDeferredRefCount > 0); --fDeferredRefCount; } + void incDeferredRefCount() const { + SkASSERT(fDeferredRefCount >= 0); + ++fDeferredRefCount; + } + + void decDeferredRefCount() const { + SkASSERT(fDeferredRefCount > 0); + --fDeferredRefCount; + if (0 == fDeferredRefCount && this->needsDeferredUnref()) { + SkASSERT(this->getRefCnt() > 1); + this->unref(); + } + } + int getDeferredRefCount() const { return fDeferredRefCount; } + void setNeedsDeferredUnref() { fFlags |= kDeferredUnref_FlagBit; } + protected: /** * isWrapped indicates we have wrapped a client-created backend resource in a GrResource. If it @@ -87,7 +101,8 @@ protected: virtual void onAbandon() {}; bool isInCache() const { return NULL != fCacheEntry; } - bool isWrapped() const { return kWrapped_Flag & fFlags; } + bool isWrapped() const { return kWrapped_FlagBit & fFlags; } + bool needsDeferredUnref() const { return SkToBool(kDeferredUnref_FlagBit & fFlags); } private: #ifdef SK_DEBUG @@ -105,7 +120,20 @@ private: mutable int fDeferredRefCount; // How many references in deferred drawing buffers. enum Flags { - kWrapped_Flag = 0x1, + /** + * This resource wraps a GPU resource given to us by the user. + * Lifetime management is left up to the user (i.e., we will not + * free it). + */ + kWrapped_FlagBit = 0x1, + + /** + * This texture should be de-refed when the deferred ref count goes + * to zero. A resource gets into this state when the resource cache + * is holding a ref-of-obligation (i.e., someone needs to own it but + * no one else wants to) but doesn't really want to keep it around. + */ + kDeferredUnref_FlagBit = 0x2, }; uint32_t fFlags; |