aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/gpu/GrContext.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/gpu/GrContext.h')
-rw-r--r--include/gpu/GrContext.h38
1 files changed, 31 insertions, 7 deletions
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index d2f3729f15..e1af73ccb2 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -295,6 +295,12 @@ public:
GrTexture* lockAndRefScratchTexture(const GrTextureDesc&, ScratchTexMatch match);
/**
+ * When done with an entry, call unlockScratchTexture(entry) on it, which returns
+ * it to the cache, where it may be purged. This does not unref the texture.
+ */
+ void unlockScratchTexture(GrTexture* texture);
+
+ /**
* Creates a texture that is outside the cache. Does not count against
* cache's budget.
*/
@@ -1045,7 +1051,15 @@ private:
size_t rowBytes,
bool filter);
- bool createNewScratchTexture(const GrTextureDesc& desc);
+ // Needed so GrTexture's returnToCache helper function can call
+ // addExistingTextureToCache
+ friend class GrTexture;
+ friend class GrStencilAndCoverPathRenderer;
+ friend class GrStencilAndCoverTextContext;
+
+ // Add an existing texture to the texture cache. This is intended solely
+ // for use with textures released from an GrAutoScratchTexture.
+ void addExistingTextureToCache(GrTexture* texture);
/**
* These functions create premul <-> unpremul effects if it is possible to generate a pair
@@ -1065,7 +1079,8 @@ private:
};
/**
- * This is deprecated. Don't use it.
+ * Gets and locks a scratch texture from a descriptor using either exact or approximate criteria.
+ * Unlocks texture in the destructor.
*/
class GrAutoScratchTexture : public ::SkNoncopyable {
public:
@@ -1088,16 +1103,25 @@ public:
void reset() {
if (fContext && fTexture) {
+ fContext->unlockScratchTexture(fTexture);
fTexture->unref();
fTexture = NULL;
}
}
- GrTexture* detach() {
- GrTexture* texture = fTexture;
- fTexture = NULL;
- return texture;
- }
+ /*
+ * 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 unlockScratchTexture 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* set(GrContext* context,
const GrTextureDesc& desc,