diff options
-rw-r--r-- | bench/GrResourceCacheBench.cpp | 9 | ||||
-rw-r--r-- | include/gpu/GrGpuResource.h | 20 | ||||
-rwxr-xr-x | src/gpu/GrContext.cpp | 2 | ||||
-rw-r--r-- | src/gpu/GrGpuResource.cpp | 12 | ||||
-rw-r--r-- | src/gpu/GrResourceCache.cpp | 15 | ||||
-rw-r--r-- | src/gpu/GrResourceCache2.cpp | 6 |
6 files changed, 37 insertions, 27 deletions
diff --git a/bench/GrResourceCacheBench.cpp b/bench/GrResourceCacheBench.cpp index 894ec14fca..6a7c89acf8 100644 --- a/bench/GrResourceCacheBench.cpp +++ b/bench/GrResourceCacheBench.cpp @@ -64,7 +64,14 @@ public: } static GrResourceKey ComputeKey(const GrTextureDesc& desc) { - return GrTexturePriv::ComputeScratchKey(desc); + GrCacheID::Key key; + memset(&key, 0, sizeof(key)); + key.fData32[0] = (desc.fWidth) | (desc.fHeight << 16); + key.fData32[1] = desc.fConfig | desc.fSampleCnt << 16; + key.fData32[2] = desc.fFlags; + static int gType = GrResourceKey::GenerateResourceType(); + static int gDomain = GrCacheID::GenerateDomain(); + return GrResourceKey(GrCacheID(gDomain, key), gType, 0); } int fID; diff --git a/include/gpu/GrGpuResource.h b/include/gpu/GrGpuResource.h index 00a5035107..9b298dd2a6 100644 --- a/include/gpu/GrGpuResource.h +++ b/include/gpu/GrGpuResource.h @@ -70,7 +70,7 @@ public: } 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); } @@ -118,16 +118,7 @@ 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. + friend class GrResourceCache2; // to check IO ref counts. template <typename, GrIOType> friend class GrPendingIOResource; }; @@ -183,6 +174,7 @@ public: void setCacheEntry(GrResourceCacheEntry* cacheEntry) { fCacheEntry = cacheEntry; } GrResourceCacheEntry* getCacheEntry() const { return fCacheEntry; } + bool isScratch() const; /** * If this resource can be used as a scratch resource this returns a valid @@ -190,6 +182,12 @@ public: */ const GrResourceKey& getScratchKey() const { return fScratchKey; } + /** + * If this resource is currently cached by its contents then this will return + * the content key. Otherwise, NULL is returned. + */ + const GrResourceKey* getContentKey() const; + /** * Gets an id that is unique for this GrGpuResource object. It is static in that it does * not change when the content of the GrGpuResource object changes. This will never return diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index a722eed88a..6ece67fd10 100755 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -6,7 +6,6 @@ * found in the LICENSE file. */ - #include "GrContext.h" #include "effects/GrConfigConversionEffect.h" @@ -444,7 +443,6 @@ GrTexture* GrContext::createNewScratchTexture(const GrTextureDesc& desc) { return NULL; } fResourceCache->addResource(texture->getScratchKey(), texture); - texture->fIsScratch = GrGpuResource::kYes_IsScratch; return texture; } diff --git a/src/gpu/GrGpuResource.cpp b/src/gpu/GrGpuResource.cpp index fdb5d47980..705cdea424 100644 --- a/src/gpu/GrGpuResource.cpp +++ b/src/gpu/GrGpuResource.cpp @@ -91,6 +91,18 @@ void GrGpuResource::setScratchKey(const GrResourceKey& scratchKey) { fScratchKey = scratchKey; } +const GrResourceKey* GrGpuResource::getContentKey() const { + if (fCacheEntry && !fCacheEntry->key().isScratch()) { + return &fCacheEntry->key(); + } + return NULL; +} + +bool GrGpuResource::isScratch() const { + // Currently scratch resources have a cache entry in GrResourceCache with a scratch key. + return NULL != fCacheEntry && fCacheEntry->key().isScratch(); +} + uint32_t GrGpuResource::CreateUniqueID() { static int32_t gUniqueID = SK_InvalidUniqueID; uint32_t id; diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp index c683b5bcfc..f50ed7d032 100644 --- a/src/gpu/GrResourceCache.cpp +++ b/src/gpu/GrResourceCache.cpp @@ -6,13 +6,10 @@ * found in the LICENSE file. */ - - #include "GrResourceCache.h" #include "GrGpuResource.h" #include "GrTexturePriv.h" - DECLARE_SKMESSAGEBUS_MESSAGE(GrResourceInvalidatedMessage); /////////////////////////////////////////////////////////////////////////////// @@ -181,7 +178,7 @@ void GrResourceCache::notifyPurgable(const GrGpuResource* resource) { // scratch texture reuse is turned off. SkASSERT(resource->getCacheEntry()); if (resource->getCacheEntry()->key().getResourceType() == GrTexturePriv::ResourceType() && - resource->fIsScratch && + resource->getCacheEntry()->key().isScratch() && !fCaps->reuseScratchTextures() && !(static_cast<const GrTexture*>(resource)->desc().fFlags & kRenderTarget_GrTextureFlagBit)) { @@ -190,12 +187,12 @@ void GrResourceCache::notifyPurgable(const GrGpuResource* resource) { } GrGpuResource* GrResourceCache::find(const GrResourceKey& key) { - GrAutoResourceCacheValidate atcv(this); - - GrResourceCacheEntry* entry = NULL; + // GrResourceCache2 is responsible for scratch resources. + SkASSERT(!key.isScratch()); - entry = fCache.find(key); + GrAutoResourceCacheValidate atcv(this); + GrResourceCacheEntry* entry = fCache.find(key); if (NULL == entry) { return NULL; } @@ -204,8 +201,6 @@ GrGpuResource* GrResourceCache::find(const GrResourceKey& key) { this->internalDetach(entry); this->attachToHead(entry); - // GrResourceCache2 is responsible for scratch resources. - SkASSERT(GrGpuResource::kNo_IsScratch == entry->resource()->fIsScratch); return entry->fResource; } diff --git a/src/gpu/GrResourceCache2.cpp b/src/gpu/GrResourceCache2.cpp index 85e66a7642..5144c59eef 100644 --- a/src/gpu/GrResourceCache2.cpp +++ b/src/gpu/GrResourceCache2.cpp @@ -67,15 +67,15 @@ public: // either by drawing code or for pending io operations. // This will be removed when flush no longer creates resources. return resource->reffedOnlyByCache() && !resource->internalHasPendingIO() && - GrGpuResource::kYes_IsScratch == resource->fIsScratch; + resource->isScratch(); } else { // Because duties are currently shared between GrResourceCache and GrResourceCache2, the // current interpretation of this rule is that only GrResourceCache has a ref but that // it has been marked as a scratch resource. - return resource->reffedOnlyByCache() && - GrGpuResource::kYes_IsScratch == resource->fIsScratch; + return resource->reffedOnlyByCache() && resource->isScratch(); } } + private: bool fFlushing; }; |