Add gr_cb class to help tracking command buffer uses of GrGpuResources.
Essentially GrGpuResources have two counts now. The original fRefCnt has
not changed and is still used for things like knowing if we can reuse
a scratch texture. The new fCommandBufferUsageCnt is used to track
when a resource is in use on a command buffer or gpu in general. We now
delay calling notifyRefCntIsZero until both of the counts are zero.
Bug: skia:11038
Change-Id: I1df62f28e4b98e8c1a5ab2fd33d4aead19788d93
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/343098
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrGpuResource.cpp b/src/gpu/GrGpuResource.cpp
index aef9000..19d1417 100644
--- a/src/gpu/GrGpuResource.cpp
+++ b/src/gpu/GrGpuResource.cpp
@@ -97,11 +97,16 @@
// Resources in the kUnbudgetedCacheable state are never purgeable when they have a unique
// key. The key must be removed/invalidated to make them purgeable.
return !this->hasRef() &&
+ this->hasNoCommandBufferUsages() &&
!(fBudgetedType == GrBudgetedType::kUnbudgetedCacheable && fUniqueKey.isValid());
}
bool GrGpuResource::hasRef() const { return this->internalHasRef(); }
+bool GrGpuResource::hasNoCommandBufferUsages() const {
+ return this->internalHasNoCommandBufferUsages();
+}
+
SkString GrGpuResource::getResourceName() const {
// Dump resource as "skia/gpu_resources/resource_#".
SkString resourceName("skia/gpu_resources/resource_");