Use presence of a content key as non-scratch indicator

BUG=skia:2889

Review URL: https://codereview.chromium.org/639873002
This commit is contained in:
bsalomon 2014-10-08 10:48:15 -07:00 committed by Commit bot
parent 544fe2338f
commit 9eefe0851e
5 changed files with 23 additions and 26 deletions

View File

@ -71,7 +71,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;
};
@ -190,6 +181,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

View File

@ -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;
}

View File

@ -101,6 +101,13 @@ void GrGpuResource::setScratchKey(const GrResourceKey& scratchKey) {
fScratchKey = scratchKey;
}
const GrResourceKey* GrGpuResource::getContentKey() const {
if (fCacheEntry && !fCacheEntry->key().isScratch()) {
return &fCacheEntry->key();
}
return NULL;
}
uint32_t GrGpuResource::CreateUniqueID() {
static int32_t gUniqueID = SK_InvalidUniqueID;
uint32_t id;

View File

@ -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) {
// GrResourceCache2 is responsible for scratch resources.
SkASSERT(!key.isScratch());
GrAutoResourceCacheValidate atcv(this);
GrResourceCacheEntry* entry = NULL;
entry = fCache.find(key);
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;
}

View File

@ -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;
(NULL == resource->getContentKey());
} 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() && (NULL == resource->getContentKey());
}
}
private:
bool fFlushing;
};