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

Unified Diff: src/gpu/GrGpuResource.cpp

Issue 729683002: Make GrResourceCache2 responsible for calling release, abandon, and ~. (Closed) Base URL: https://skia.googlesource.com/skia.git@revrev
Patch Set: tiny cleanup 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
« no previous file with comments | « include/gpu/GrGpuResource.h ('k') | src/gpu/GrGpuResourceCacheAccess.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrGpuResource.cpp
diff --git a/src/gpu/GrGpuResource.cpp b/src/gpu/GrGpuResource.cpp
index be8ea0daf07f744a921b06a2b3684be1b3c9066e..fcc5f4de509e56f5419371cb7e056e57f3d45fd9 100644
--- a/src/gpu/GrGpuResource.cpp
+++ b/src/gpu/GrGpuResource.cpp
@@ -36,26 +36,24 @@ void GrGpuResource::registerWithCache() {
}
GrGpuResource::~GrGpuResource() {
- // subclass should have released this.
+ // The cache should have released or destroyed this resource.
SkASSERT(this->wasDestroyed());
}
void GrGpuResource::release() {
- if (fGpu) {
- this->onRelease();
- get_resource_cache2(fGpu)->resourceAccess().removeResource(this);
- fGpu = NULL;
- fGpuMemorySize = 0;
- }
+ SkASSERT(fGpu);
+ this->onRelease();
+ get_resource_cache2(fGpu)->resourceAccess().removeResource(this);
+ fGpu = NULL;
+ fGpuMemorySize = 0;
}
void GrGpuResource::abandon() {
- if (fGpu) {
- this->onAbandon();
- get_resource_cache2(fGpu)->resourceAccess().removeResource(this);
- fGpu = NULL;
- fGpuMemorySize = 0;
- }
+ SkASSERT(fGpu);
+ this->onAbandon();
+ get_resource_cache2(fGpu)->resourceAccess().removeResource(this);
+ fGpu = NULL;
+ fGpuMemorySize = 0;
}
const GrContext* GrGpuResource::getContext() const {
@@ -90,7 +88,7 @@ bool GrGpuResource::setContentKey(const GrResourceKey& contentKey) {
SkASSERT(!contentKey.isScratch());
SkASSERT(this->internalHasRef());
- if (fContentKeySet) {
+ if (fContentKeySet || this->wasDestroyed()) {
return false;
}
@@ -105,8 +103,12 @@ bool GrGpuResource::setContentKey(const GrResourceKey& contentKey) {
}
void GrGpuResource::notifyIsPurgable() const {
- if (!this->wasDestroyed()) {
- get_resource_cache2(fGpu)->resourceAccess().notifyPurgable(this);
+ if (this->wasDestroyed()) {
+ // We've already been removed from the cache. Goodbye cruel world!
+ SkDELETE(this);
+ } else {
+ GrGpuResource* mutableThis = const_cast<GrGpuResource*>(this);
+ get_resource_cache2(fGpu)->resourceAccess().notifyPurgable(mutableThis);
}
}
« no previous file with comments | « include/gpu/GrGpuResource.h ('k') | src/gpu/GrGpuResourceCacheAccess.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698