Use presence of a content key as non-scratch indicator
BUG=skia:2889
Review URL: https://codereview.chromium.org/639873002
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index a722eed..6ece67f 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 @@
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 a074d7c..5452184 100644
--- a/src/gpu/GrGpuResource.cpp
+++ b/src/gpu/GrGpuResource.cpp
@@ -101,6 +101,13 @@
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;
diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp
index c683b5b..f50ed7d 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 @@
// 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 @@
}
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 @@
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 85e66a7..76673cf 100644
--- a/src/gpu/GrResourceCache2.cpp
+++ b/src/gpu/GrResourceCache2.cpp
@@ -67,15 +67,15 @@
// 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;
};