diff options
Diffstat (limited to 'include/gpu')
-rw-r--r-- | include/gpu/GrContext.h | 38 | ||||
-rw-r--r-- | include/gpu/GrGpuResource.h | 32 | ||||
-rw-r--r-- | include/gpu/GrTexture.h | 2 | ||||
-rw-r--r-- | include/gpu/SkGr.h | 4 | ||||
-rw-r--r-- | include/gpu/SkGrPixelRef.h | 8 |
5 files changed, 56 insertions, 28 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, diff --git a/include/gpu/GrGpuResource.h b/include/gpu/GrGpuResource.h index 17f34d62b2..61849e7232 100644 --- a/include/gpu/GrGpuResource.h +++ b/include/gpu/GrGpuResource.h @@ -49,21 +49,27 @@ public: // templated helper classes (e.g. SkAutoTUnref). However, we have different categories of // refs (e.g. pending reads). We also don't require thread safety as GrCacheable objects are // not intended to cross thread boundaries. + // internal_dispose() exists because of GrTexture's reliance on it. It will be removed + // soon. void ref() const { - this->validate(); ++fRefCnt; + // pre-validate once internal_dispose is removed (and therefore 0 ref cnt is not allowed). + this->validate(); } void unref() const { this->validate(); --fRefCnt; if (0 == fRefCnt && 0 == fPendingReads && 0 == fPendingWrites) { - SkDELETE(this); + this->internal_dispose(); } } - bool isPurgable() const { return this->reffedOnlyByCache() && !this->internalHasPendingIO(); } - bool reffedOnlyByCache() const { return 1 == fRefCnt; } + virtual void internal_dispose() const { SkDELETE(this); } + + /** This is exists to service the old mechanism for recycling scratch textures. It will + be removed soon. */ + bool unique() const { return 1 == (fRefCnt + fPendingReads + fPendingWrites); } void validate() const { #ifdef SK_DEBUG @@ -74,8 +80,9 @@ public: #endif } + protected: - GrIORef() : fRefCnt(1), fPendingReads(0), fPendingWrites(0), fIsScratch(kNo_IsScratch) { } + GrIORef() : fRefCnt(1), fPendingReads(0), fPendingWrites(0) {} bool internalHasPendingRead() const { return SkToBool(fPendingReads); } bool internalHasPendingWrite() const { return SkToBool(fPendingWrites); } @@ -91,7 +98,7 @@ private: this->validate(); --fPendingReads; if (0 == fRefCnt && 0 == fPendingReads && 0 == fPendingWrites) { - SkDELETE(this); + this->internal_dispose(); } } @@ -104,7 +111,7 @@ private: this->validate(); --fPendingWrites; if (0 == fRefCnt && 0 == fPendingReads && 0 == fPendingWrites) { - SkDELETE(this); + this->internal_dispose(); } } @@ -115,17 +122,6 @@ private: // This class is used to manage conversion of refs to pending reads/writes. friend class GrGpuResourceRef; - - // This is temporary until GrResourceCache is fully replaced by GrResourceCache2. - enum IsScratch { - kNo_IsScratch, - kYes_IsScratch - } fIsScratch; - - friend class GrContext; // to set the above field. - friend class GrResourceCache; // to check the above field. - friend class GrResourceCache2; // to check the above field. - template <typename, IOType> friend class GrPendingIOResource; }; diff --git a/include/gpu/GrTexture.h b/include/gpu/GrTexture.h index 43b69eade2..8bdff34df5 100644 --- a/include/gpu/GrTexture.h +++ b/include/gpu/GrTexture.h @@ -99,6 +99,8 @@ protected: void validateDesc() const; private: + void abandonReleaseCommon(); + virtual void internal_dispose() const SK_OVERRIDE; void dirtyMipMaps(bool mipMapsDirty); enum MipMapsStatus { diff --git a/include/gpu/SkGr.h b/include/gpu/SkGr.h index 026525be5d..df2ae5a320 100644 --- a/include/gpu/SkGr.h +++ b/include/gpu/SkGr.h @@ -70,7 +70,9 @@ static inline GrColor SkColor2GrColorJustAlpha(SkColor c) { bool GrIsBitmapInCache(const GrContext*, const SkBitmap&, const GrTextureParams*); -GrTexture* GrRefCachedBitmapTexture(GrContext*, const SkBitmap&, const GrTextureParams*); +GrTexture* GrLockAndRefCachedBitmapTexture(GrContext*, const SkBitmap&, const GrTextureParams*); + +void GrUnlockAndUnrefCachedBitmapTexture(GrTexture*); //////////////////////////////////////////////////////////////////////////////// diff --git a/include/gpu/SkGrPixelRef.h b/include/gpu/SkGrPixelRef.h index 9a81be67de..7e6a9d02ed 100644 --- a/include/gpu/SkGrPixelRef.h +++ b/include/gpu/SkGrPixelRef.h @@ -41,9 +41,11 @@ class SK_API SkGrPixelRef : public SkROLockPixelsPixelRef { public: SK_DECLARE_INST_COUNT(SkGrPixelRef) /** - * Constructs a pixel ref around a GrSurface. + * Constructs a pixel ref around a GrSurface. If the caller has locked the GrSurface in the + * cache and would like the pixel ref to unlock it in its destructor then transferCacheLock + * should be set to true. */ - SkGrPixelRef(const SkImageInfo&, GrSurface*); + SkGrPixelRef(const SkImageInfo&, GrSurface*, bool transferCacheLock = false); virtual ~SkGrPixelRef(); // override from SkPixelRef @@ -56,6 +58,8 @@ protected: private: GrSurface* fSurface; + bool fUnlock; // if true the pixel ref owns a texture cache lock on fSurface + typedef SkROLockPixelsPixelRef INHERITED; }; |