#include "SkClipStack.h"
class GrAutoScratchTexture;
+class GrCacheKey;
class GrDrawState;
class GrDrawTarget;
class GrFontCache;
void* srcData, size_t rowBytes);
/**
+ * Look for a texture that matches 'key' in the cache. If not found,
+ * return NULL.
+ */
+ GrTexture* findTexture(const GrCacheKey& key);
+
+ /**
* Search for an entry based on key and dimensions. If found, "lock" it and
* return it. The return value will be NULL if not found.
* Must be balanced with an unlockTexture() call.
ScratchTexMatch match);
/**
+ * Make a texture un-purgeable in the cache
+ */
+ void lockTexture(GrTexture* texture);
+
+ /**
* When done with an entry, call unlockTexture(entry) on it, which returns
* it to the cache, where it may be purged.
*/
}
+
+GrTexture* GrContext::findTexture(const GrCacheKey& key) {
+ return static_cast<GrTexture*>(fTextureCache->find(key.key()));
+}
+
GrTexture* GrContext::findAndLockTexture(const GrTextureDesc& desc,
const GrCacheData& cacheData,
const GrTextureParams* params) {
fTextureCache->unlock(texture->getCacheEntry());
}
+void GrContext::lockTexture(GrTexture* texture) {
+
+ if (NULL == texture->getCacheEntry()) {
+ // not in the cache
+ GrAssert(0);
+ return;
+ }
+
+ fTextureCache->lock(texture->getCacheEntry());
+}
+
void GrContext::unlockTexture(GrTexture* texture) {
ASSERT_OWNED_RESOURCE(texture);
GrAssert(NULL != texture->getCacheEntry());
}
}
+GrResource* GrResourceCache::find(const GrResourceKey& key) {
+ GrAutoResourceCacheValidate atcv(this);
+
+ GrResourceEntry* entry = fCache.find(key);
+ if (NULL == entry) {
+ return NULL;
+ }
+
+ return entry->fResource;
+}
+
GrResource* GrResourceCache::findAndLock(const GrResourceKey& key,
LockType type) {
GrAutoResourceCacheValidate atcv(this);
GrAutoResourceCacheValidate atcv(this);
this->internalDetach(entry, true);
- fCache.remove(entry->fKey, entry);
+ fCache.remove(entry->key(), entry);
#if GR_DEBUG
fExclusiveList.addToHead(entry);
}
}
+void GrResourceCache::lock(GrResourceEntry* entry) {
+ GrAutoResourceCacheValidate atcv(this);
+
+ GrAssert(entry);
+ GrAssert(fCache.find(entry->key()));
+
+ if (!entry->isLocked()) {
+ --fUnlockedEntryCount;
+ }
+
+ entry->lock();
+}
+
void GrResourceCache::unlock(GrResourceEntry* entry) {
GrAutoResourceCacheValidate atcv(this);
GrResourceEntry* prev = iter.prev();
if (!entry->isLocked()) {
// remove from our cache
- fCache.remove(entry->fKey, entry);
+ fCache.remove(entry->key(), entry);
// remove from our llist
this->internalDetach(entry, false);
friend class GrContext;
};
+
+class GrCacheKey {
+public:
+ GrCacheKey(const GrTextureDesc& desc, const GrResourceKey& key)
+ : fDesc(desc)
+ , fKey(key) {
+ }
+
+ void set(const GrTextureDesc& desc, const GrResourceKey& key) {
+ fDesc = desc;
+ fKey = key;
+ }
+
+ const GrTextureDesc& desc() const { return fDesc; }
+ const GrResourceKey& key() const { return fKey; }
+
+protected:
+ GrTextureDesc fDesc;
+ GrResourceKey fKey;
+};
+
///////////////////////////////////////////////////////////////////////////////
class GrResourceEntry {
};
/**
+ * Search for an entry with the same Key. If found, return it.
+ * If not found, return null.
+ */
+ GrResource* find(const GrResourceKey& key);
+
+ /**
* Search for an entry with the same Key. If found, "lock" it and return it.
* If not found, return null.
*/
void unlock(GrResourceEntry*);
/**
+ * Make a resource un-purgeable.
+ */
+ void lock(GrResourceEntry* entry);
+
+ /**
* Removes every resource in the cache that isn't locked.
*/
void purgeAllUnlocked();