aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/gpu/GrContext.h
diff options
context:
space:
mode:
authorGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-06-22 12:41:43 +0000
committerGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-06-22 12:41:43 +0000
commit15c0fea699b25343fe6f49668a5632866e1a0306 (patch)
tree0616bf4168b4d98e02ae7cabf95623ef7ccb4fa5 /include/gpu/GrContext.h
parent5e2412983183f9c4075a795278f3ca4ffee0ed79 (diff)
AutoScratchTexture can now release its texture and it will return to the texture cache when freed
Diffstat (limited to 'include/gpu/GrContext.h')
-rw-r--r--include/gpu/GrContext.h46
1 files changed, 43 insertions, 3 deletions
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index 122baf1358..46e80e0c4f 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -100,10 +100,10 @@ public:
}
GrTexture* texture() const;
void reset() { fEntry = NULL; }
+ GrResourceEntry* cacheEntry() { return fEntry; }
private:
explicit TextureCacheEntry(GrResourceEntry* entry) { fEntry = entry; }
void set(GrResourceEntry* entry) { fEntry = entry; }
- GrResourceEntry* cacheEntry() { return fEntry; }
GrResourceEntry* fEntry;
friend class GrContext;
};
@@ -174,7 +174,7 @@ public:
* Returns a texture matching the desc. It's contents are unknown. Subsequent
* requests with the same descriptor are not guaranteed to return the same
* texture. The same texture is guaranteed not be returned again until it is
- * unlocked. Must call be balanced with an unlockTexture() call.
+ * unlocked. Call must be balanced with an unlockTexture() call.
*
* Textures created by createAndLockTexture() hide the complications of
* tiling non-power-of-two textures on APIs that don't support this (e.g.
@@ -192,6 +192,11 @@ public:
void unlockTexture(TextureCacheEntry entry);
/**
+ * Free any data associated with the provided entry in the texture cache
+ */
+ void freeEntry(TextureCacheEntry entry);
+
+ /**
* Creates a texture that is outside the cache. Does not count against
* cache's budget.
*/
@@ -772,6 +777,14 @@ private:
static int PaintStageVertexLayoutBits(
const GrPaint& paint,
const bool hasTexCoords[GrPaint::kTotalStages]);
+
+ // Needed so GrTexture's returnToCache helper function can call
+ // addExistingTextureToCache
+ friend class GrTexture;
+
+ // Add an existing texture to the texture cache. This is intended solely
+ // for use with textures released from an GrAutoScratchTexture.
+ void addExistingTextureToCache(GrTexture* texture);
};
/**
@@ -837,12 +850,39 @@ public:
}
void reset() {
- if (NULL != fContext) {
+ if (NULL != fContext && NULL != fEntry.cacheEntry()) {
fContext->unlockTexture(fEntry);
fEntry.reset();
}
}
+ /*
+ * When detaching a texture we do not unlock it in the texture cache but
+ * we do set the returnToCache flag. In this way the texture remains
+ * "locked" in the texture cache until it is freed and recycled in
+ * GrTexture::internal_dispose. In reality, the texture has been removed
+ * from the cache (because this is in AutoScratchTexture) and by not
+ * calling unlockTexture we simply don't re-add it. It will be reattached
+ * in GrTexture::internal_dispose.
+ *
+ * Note that the caller is assumed to accept and manage the ref to the
+ * returned texture.
+ */
+ GrTexture* detach() {
+ GrTexture* temp = this->texture();
+
+ GrAssert(1 == temp->getRefCnt());
+
+ // freeEntry will remove the texture cache's ref
+ temp->ref();
+ fContext->freeEntry(fEntry);
+ fEntry.reset();
+
+ temp->setFlag((GrTextureFlags) GrTexture::kReturnToCache_FlagBit);
+ GrAssert(1 == temp->getRefCnt());
+ return temp;
+ }
+
GrTexture* set(GrContext* context,
const GrTextureDesc& desc,
GrContext::ScratchTexMatch match =