diff options
author | Brian Salomon <bsalomon@google.com> | 2014-10-07 15:07:38 -0400 |
---|---|---|
committer | Brian Salomon <bsalomon@google.com> | 2014-10-07 15:07:38 -0400 |
commit | 9323b8b8e16df4adcd63ee8496a6382e8df535c9 (patch) | |
tree | 12ff0bd9f07193593b7db1d52ef2fe0478c00aeb /include/gpu/GrContext.h | |
parent | 65be97d1a1eb5923b078bd1e7ec1e7da6e6427e2 (diff) |
Revert "GrResourceCache2 manages scratch texture."
This reverts commit d14e1a27643125bfef37fa0ed314b64c1fae22b7.
Diffstat (limited to 'include/gpu/GrContext.h')
-rw-r--r-- | include/gpu/GrContext.h | 56 |
1 files changed, 37 insertions, 19 deletions
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h index b8405ec419..4500936b82 100644 --- a/include/gpu/GrContext.h +++ b/include/gpu/GrContext.h @@ -290,13 +290,15 @@ public: * tiling non-power-of-two textures on APIs that don't support this (e.g. * unextended GLES2). Tiling a NPOT texture created by lockScratchTexture on * such an API will create gaps in the tiling pattern. This includes clamp - * mode. (This may be addressed in a future update.)7 - * - * internalFlag is a temporary workaround until changes in the internal - * architecture are complete. Use the default value. + * mode. (This may be addressed in a future update.) + */ + 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. */ - GrTexture* lockAndRefScratchTexture(const GrTextureDesc&, ScratchTexMatch match, - bool internalFlag = false); + void unlockScratchTexture(GrTexture* texture); /** * Creates a texture that is outside the cache. Does not count against @@ -1073,7 +1075,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 @@ -1093,7 +1103,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 SK_API GrAutoScratchTexture : public ::SkNoncopyable { public: @@ -1104,11 +1115,10 @@ public: GrAutoScratchTexture(GrContext* context, const GrTextureDesc& desc, - GrContext::ScratchTexMatch match = GrContext::kApprox_ScratchTexMatch, - bool internalFlag = false) + GrContext::ScratchTexMatch match = GrContext::kApprox_ScratchTexMatch) : fContext(NULL) , fTexture(NULL) { - this->set(context, desc, match, internalFlag); + this->set(context, desc, match); } ~GrAutoScratchTexture() { @@ -1117,26 +1127,34 @@ 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, - GrContext::ScratchTexMatch match = GrContext::kApprox_ScratchTexMatch, - bool internalFlag = 0) { + GrContext::ScratchTexMatch match = GrContext::kApprox_ScratchTexMatch) { this->reset(); fContext = context; if (fContext) { - fTexture = fContext->lockAndRefScratchTexture(desc, match, internalFlag); + fTexture = fContext->lockAndRefScratchTexture(desc, match); if (NULL == fTexture) { fContext = NULL; } |