aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
authorGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-30 11:06:31 +0000
committerGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-30 11:06:31 +0000
commita9b0623eac4a473517c15418dbdc1e331ee752d2 (patch)
treef31354f880f7113eddfb28a301dc53d687b15d8c /src/gpu
parent9cb5adf50dc3e8f83904380934b08d135229ef6f (diff)
Added find, lock to GrContext & GrResourceCache interfaces
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/GrContext.cpp16
-rw-r--r--src/gpu/GrResourceCache.cpp28
-rw-r--r--src/gpu/GrResourceCache.h32
3 files changed, 74 insertions, 2 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 13ada9a677..6a4a5579db 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -207,6 +207,11 @@ void convolve_gaussian(GrDrawTarget* target,
}
+
+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) {
@@ -484,6 +489,17 @@ void GrContext::addExistingTextureToCache(GrTexture* texture) {
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());
diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp
index 777470b00d..ca69ce44ce 100644
--- a/src/gpu/GrResourceCache.cpp
+++ b/src/gpu/GrResourceCache.cpp
@@ -184,6 +184,17 @@ void GrResourceCache::attachToHead(GrResourceEntry* entry,
}
}
+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);
@@ -256,7 +267,7 @@ void GrResourceCache::makeExclusive(GrResourceEntry* entry) {
GrAutoResourceCacheValidate atcv(this);
this->internalDetach(entry, true);
- fCache.remove(entry->fKey, entry);
+ fCache.remove(entry->key(), entry);
#if GR_DEBUG
fExclusiveList.addToHead(entry);
@@ -291,6 +302,19 @@ void GrResourceCache::makeNonExclusive(GrResourceEntry* 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);
@@ -343,7 +367,7 @@ void GrResourceCache::purgeAsNeeded() {
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);
diff --git a/src/gpu/GrResourceCache.h b/src/gpu/GrResourceCache.h
index 5741e47dc9..52e7c5d649 100644
--- a/src/gpu/GrResourceCache.h
+++ b/src/gpu/GrResourceCache.h
@@ -117,6 +117,27 @@ private:
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 {
@@ -218,6 +239,12 @@ public:
};
/**
+ * 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.
*/
@@ -270,6 +297,11 @@ public:
void unlock(GrResourceEntry*);
/**
+ * Make a resource un-purgeable.
+ */
+ void lock(GrResourceEntry* entry);
+
+ /**
* Removes every resource in the cache that isn't locked.
*/
void purgeAllUnlocked();