Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(231)

Unified Diff: src/gpu/GrGpuResource.cpp

Issue 705413002: Remove GrResourceKey from GrResourceCache (Closed) Base URL: https://skia.googlesource.com/skia.git@content
Patch Set: update Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/gpu/GrGpuResource.cpp
diff --git a/src/gpu/GrGpuResource.cpp b/src/gpu/GrGpuResource.cpp
index b77acffc68c69599a8f58ac910b86c7134832aae..87c7349246aca003fb8cc86985e74d2a304e325d 100644
--- a/src/gpu/GrGpuResource.cpp
+++ b/src/gpu/GrGpuResource.cpp
@@ -29,7 +29,8 @@ GrGpuResource::GrGpuResource(GrGpu* gpu, bool isWrapped)
: fGpu(gpu)
, fCacheEntry(NULL)
, fUniqueID(CreateUniqueID())
- , fScratchKey(GrResourceKey::NullScratchKey()) {
+ , fScratchKey(GrResourceKey::NullScratchKey())
+ , fContentKeySet(false) {
if (isWrapped) {
fFlags = kWrapped_FlagBit;
} else {
@@ -78,24 +79,32 @@ GrContext* GrGpuResource::getContext() {
}
}
-bool GrGpuResource::setCacheEntry(GrResourceCacheEntry* cacheEntry) {
- // GrResourceCache never changes the cacheEntry once one has been added.
- SkASSERT(NULL == cacheEntry || NULL == fCacheEntry);
-
- fCacheEntry = cacheEntry;
- if (this->wasDestroyed() || NULL == cacheEntry) {
- return true;
+bool GrGpuResource::setContentKey(const GrResourceKey& contentKey) {
+ SkASSERT(!contentKey.isScratch());
+ // Currently this can only be called once and can't be called when the resource is scratch.
+ SkASSERT(this->internalHasRef());
+ SkASSERT(!this->internalHasPendingIO());
+
+ if (fContentKeySet) {
robertphillips 2014/11/11 15:04:44 Assert in here?
bsalomon 2014/11/11 15:17:22 Unit tests exercise this behavior.
+ return false;
}
- if (!cacheEntry->key().isScratch()) {
- if (!get_resource_cache2(fGpu)->didAddContentKey(this)) {
- fCacheEntry = NULL;
- return false;
- }
+ fContentKey = contentKey;
+ fContentKeySet = true;
+
+ if (!get_resource_cache2(fGpu)->didSetContentKey(this)) {
+ fContentKeySet = false;
+ return false;
}
return true;
}
+void GrGpuResource::setCacheEntry(GrResourceCacheEntry* cacheEntry) {
+ // GrResourceCache never changes the cacheEntry once one has been added.
+ SkASSERT(NULL == cacheEntry || NULL == fCacheEntry);
+ fCacheEntry = cacheEntry;
+}
+
void GrGpuResource::notifyIsPurgable() const {
if (fCacheEntry && !this->wasDestroyed()) {
get_resource_cache(fGpu)->notifyPurgable(this);
@@ -110,9 +119,8 @@ void GrGpuResource::setScratchKey(const GrResourceKey& scratchKey) {
}
const GrResourceKey* GrGpuResource::getContentKey() const {
- // Currently scratch resources have a cache entry in GrResourceCache with a scratch key.
- if (fCacheEntry && !fCacheEntry->key().isScratch()) {
- return &fCacheEntry->key();
+ if (fContentKeySet) {
+ return &fContentKey;
}
return NULL;
}

Powered by Google App Engine
This is Rietveld 408576698