aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/gpu
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2014-10-07 07:27:07 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-10-07 07:27:07 -0700
commitd14e1a27643125bfef37fa0ed314b64c1fae22b7 (patch)
treef4ee6543d77aff0e233dace6c81403364b79fdba /include/gpu
parentb109ac22b4ec3ab3478f5304c96564a0e9df6170 (diff)
GrResourceCache2 manages scratch texture.
Diffstat (limited to 'include/gpu')
-rw-r--r--include/gpu/GrContext.h56
-rw-r--r--include/gpu/GrGpuResource.h32
-rw-r--r--include/gpu/GrTexture.h2
-rw-r--r--include/gpu/SkGr.h4
-rw-r--r--include/gpu/SkGrPixelRef.h8
5 files changed, 40 insertions, 62 deletions
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index 4500936b82..b8405ec419 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -290,15 +290,13 @@ 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.)
- */
- 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.
+ * 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.
*/
- void unlockScratchTexture(GrTexture* texture);
+ GrTexture* lockAndRefScratchTexture(const GrTextureDesc&, ScratchTexMatch match,
+ bool internalFlag = false);
/**
* Creates a texture that is outside the cache. Does not count against
@@ -1075,15 +1073,7 @@ private:
size_t rowBytes,
bool filter);
- // 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);
+ bool createNewScratchTexture(const GrTextureDesc& desc);
/**
* These functions create premul <-> unpremul effects if it is possible to generate a pair
@@ -1103,8 +1093,7 @@ private:
};
/**
- * Gets and locks a scratch texture from a descriptor using either exact or approximate criteria.
- * Unlocks texture in the destructor.
+ * This is deprecated. Don't use it.
*/
class SK_API GrAutoScratchTexture : public ::SkNoncopyable {
public:
@@ -1115,10 +1104,11 @@ public:
GrAutoScratchTexture(GrContext* context,
const GrTextureDesc& desc,
- GrContext::ScratchTexMatch match = GrContext::kApprox_ScratchTexMatch)
+ GrContext::ScratchTexMatch match = GrContext::kApprox_ScratchTexMatch,
+ bool internalFlag = false)
: fContext(NULL)
, fTexture(NULL) {
- this->set(context, desc, match);
+ this->set(context, desc, match, internalFlag);
}
~GrAutoScratchTexture() {
@@ -1127,34 +1117,26 @@ public:
void reset() {
if (fContext && fTexture) {
- fContext->unlockScratchTexture(fTexture);
fTexture->unref();
fTexture = NULL;
}
}
- /*
- * 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* detach() {
+ GrTexture* texture = fTexture;
+ fTexture = NULL;
+ return texture;
+ }
GrTexture* set(GrContext* context,
const GrTextureDesc& desc,
- GrContext::ScratchTexMatch match = GrContext::kApprox_ScratchTexMatch) {
+ GrContext::ScratchTexMatch match = GrContext::kApprox_ScratchTexMatch,
+ bool internalFlag = 0) {
this->reset();
fContext = context;
if (fContext) {
- fTexture = fContext->lockAndRefScratchTexture(desc, match);
+ fTexture = fContext->lockAndRefScratchTexture(desc, match, internalFlag);
if (NULL == fTexture) {
fContext = NULL;
}
diff --git a/include/gpu/GrGpuResource.h b/include/gpu/GrGpuResource.h
index 61849e7232..17f34d62b2 100644
--- a/include/gpu/GrGpuResource.h
+++ b/include/gpu/GrGpuResource.h
@@ -49,27 +49,21 @@ 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 {
- ++fRefCnt;
- // pre-validate once internal_dispose is removed (and therefore 0 ref cnt is not allowed).
this->validate();
+ ++fRefCnt;
}
void unref() const {
this->validate();
--fRefCnt;
if (0 == fRefCnt && 0 == fPendingReads && 0 == fPendingWrites) {
- this->internal_dispose();
+ SkDELETE(this);
}
}
- 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); }
+ bool isPurgable() const { return this->reffedOnlyByCache() && !this->internalHasPendingIO(); }
+ bool reffedOnlyByCache() const { return 1 == fRefCnt; }
void validate() const {
#ifdef SK_DEBUG
@@ -80,9 +74,8 @@ public:
#endif
}
-
protected:
- GrIORef() : fRefCnt(1), fPendingReads(0), fPendingWrites(0) {}
+ GrIORef() : fRefCnt(1), fPendingReads(0), fPendingWrites(0), fIsScratch(kNo_IsScratch) { }
bool internalHasPendingRead() const { return SkToBool(fPendingReads); }
bool internalHasPendingWrite() const { return SkToBool(fPendingWrites); }
@@ -98,7 +91,7 @@ private:
this->validate();
--fPendingReads;
if (0 == fRefCnt && 0 == fPendingReads && 0 == fPendingWrites) {
- this->internal_dispose();
+ SkDELETE(this);
}
}
@@ -111,7 +104,7 @@ private:
this->validate();
--fPendingWrites;
if (0 == fRefCnt && 0 == fPendingReads && 0 == fPendingWrites) {
- this->internal_dispose();
+ SkDELETE(this);
}
}
@@ -122,6 +115,17 @@ 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 8bdff34df5..43b69eade2 100644
--- a/include/gpu/GrTexture.h
+++ b/include/gpu/GrTexture.h
@@ -99,8 +99,6 @@ 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 df2ae5a320..026525be5d 100644
--- a/include/gpu/SkGr.h
+++ b/include/gpu/SkGr.h
@@ -70,9 +70,7 @@ static inline GrColor SkColor2GrColorJustAlpha(SkColor c) {
bool GrIsBitmapInCache(const GrContext*, const SkBitmap&, const GrTextureParams*);
-GrTexture* GrLockAndRefCachedBitmapTexture(GrContext*, const SkBitmap&, const GrTextureParams*);
-
-void GrUnlockAndUnrefCachedBitmapTexture(GrTexture*);
+GrTexture* GrRefCachedBitmapTexture(GrContext*, const SkBitmap&, const GrTextureParams*);
////////////////////////////////////////////////////////////////////////////////
diff --git a/include/gpu/SkGrPixelRef.h b/include/gpu/SkGrPixelRef.h
index 7e6a9d02ed..9a81be67de 100644
--- a/include/gpu/SkGrPixelRef.h
+++ b/include/gpu/SkGrPixelRef.h
@@ -41,11 +41,9 @@ class SK_API SkGrPixelRef : public SkROLockPixelsPixelRef {
public:
SK_DECLARE_INST_COUNT(SkGrPixelRef)
/**
- * 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.
+ * Constructs a pixel ref around a GrSurface.
*/
- SkGrPixelRef(const SkImageInfo&, GrSurface*, bool transferCacheLock = false);
+ SkGrPixelRef(const SkImageInfo&, GrSurface*);
virtual ~SkGrPixelRef();
// override from SkPixelRef
@@ -58,8 +56,6 @@ protected:
private:
GrSurface* fSurface;
- bool fUnlock; // if true the pixel ref owns a texture cache lock on fSurface
-
typedef SkROLockPixelsPixelRef INHERITED;
};