Make GrSemaphore a GrGpuResource
This makes semaphores get handled correctly when GrContext is abandoned or
asked to free all its resources.
Change-Id: I0b935bb95cf99b9acf647472bcd0231bb2759db6
Reviewed-on: https://skia-review.googlesource.com/150364
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
diff --git a/src/gpu/vk/GrVkSemaphore.cpp b/src/gpu/vk/GrVkSemaphore.cpp
index 7a56391..ef53b30 100644
--- a/src/gpu/vk/GrVkSemaphore.cpp
+++ b/src/gpu/vk/GrVkSemaphore.cpp
@@ -16,7 +16,7 @@
#undef CreateSemaphore
#endif
-sk_sp<GrVkSemaphore> GrVkSemaphore::Make(const GrVkGpu* gpu, bool isOwned) {
+sk_sp<GrVkSemaphore> GrVkSemaphore::Make(GrVkGpu* gpu, bool isOwned) {
VkSemaphoreCreateInfo createInfo;
memset(&createInfo, 0, sizeof(VkSemaphoreCreateInfo));
createInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
@@ -29,7 +29,7 @@
return sk_sp<GrVkSemaphore>(new GrVkSemaphore(gpu, semaphore, false, false, isOwned));
}
-sk_sp<GrVkSemaphore> GrVkSemaphore::MakeWrapped(const GrVkGpu* gpu,
+sk_sp<GrVkSemaphore> GrVkSemaphore::MakeWrapped(GrVkGpu* gpu,
VkSemaphore semaphore,
WrapType wrapType,
GrWrapOwnership ownership) {
@@ -42,18 +42,27 @@
kBorrow_GrWrapOwnership != ownership));
}
-GrVkSemaphore::GrVkSemaphore(const GrVkGpu* gpu, VkSemaphore semaphore, bool prohibitSignal,
+GrVkSemaphore::GrVkSemaphore(GrVkGpu* gpu, VkSemaphore semaphore, bool prohibitSignal,
bool prohibitWait, bool isOwned)
: INHERITED(gpu) {
fResource = new Resource(semaphore, prohibitSignal, prohibitWait, isOwned);
+ isOwned ? this->registerWithCache(SkBudgeted::kNo) : this->registerWithCacheWrapped();
}
-GrVkSemaphore::~GrVkSemaphore() {
- if (fGpu) {
- fResource->unref(static_cast<const GrVkGpu*>(fGpu));
- } else {
- fResource->unrefAndAbandon();
+void GrVkSemaphore::onRelease() {
+ if (fResource) {
+ fResource->unref(static_cast<const GrVkGpu*>(this->getGpu()));
+ fResource = nullptr;
}
+ INHERITED::onRelease();
+}
+
+void GrVkSemaphore::onAbandon() {
+ if (fResource) {
+ fResource->unrefAndAbandon();
+ fResource = nullptr;
+ }
+ INHERITED::onAbandon();
}
void GrVkSemaphore::Resource::freeGPUData(const GrVkGpu* gpu) const {