Revert of GrResourceCache2 manages scratch texture. (patchset #14 id:260001 of https://codereview.chromium.org/608883003/)
Reason for revert:
Turning bots red:
Nanobench seems to be uniformly failing on Android
(http://108.170.220.21:10117/builders/Perf-Android-Venue8-PowerVR-x86-Release/builds/99/steps/RunNanobench/logs/stdio)
Ubuntu GTX660 32bit is failing in both Debug and Release on GM generation (it appears to be out of memory) (http://108.170.220.120:10117/builders/Test-Ubuntu12-ShuttleA-GTX660-x86-Debug/builds/2457/steps/GenerateGMs/logs/stdio)
Original issue's description:
> GrResourceCache2 manages scratch texture.
>
>
> BUG=skia:
>
> Committed: https://skia.googlesource.com/skia/+/3d398c876440deaab39bbf2a9b881c337e6dc8d4
R=bsalomon@google.com
TBR=bsalomon@google.com
NOTREECHECKS=true
NOTRY=true
BUG=skia:
Author: robertphillips@google.com
Review URL: https://codereview.chromium.org/611383003
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index d2f3729..e1af73c 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -295,6 +295,12 @@
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 @@
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 @@
};
/**
- * 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 @@
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,