Add option for client to own semaphores after telling to skia to wait.

Bug: chromium:1004772
Change-Id: Ifdad0b12925d13d3e896f6321c35312f9daa330c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/301216
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 48b6982..8d0e518 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -290,14 +290,16 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 
-bool GrContext::wait(int numSemaphores, const GrBackendSemaphore waitSemaphores[]) {
+bool GrContext::wait(int numSemaphores, const GrBackendSemaphore waitSemaphores[],
+                     bool deleteSemaphoresAfterWait) {
     if (!fGpu || fGpu->caps()->semaphoreSupport()) {
         return false;
     }
+    GrWrapOwnership ownership =
+            deleteSemaphoresAfterWait ? kAdopt_GrWrapOwnership : kBorrow_GrWrapOwnership;
     for (int i = 0; i < numSemaphores; ++i) {
         std::unique_ptr<GrSemaphore> sema = fResourceProvider->wrapBackendSemaphore(
-                waitSemaphores[i], GrResourceProvider::SemaphoreWrapType::kWillWait,
-                kAdopt_GrWrapOwnership);
+                waitSemaphores[i], GrResourceProvider::SemaphoreWrapType::kWillWait, ownership);
         // If we failed to wrap the semaphore it means the client didn't give us a valid semaphore
         // to begin with. Therefore, it is fine to not wait on it.
         if (sema) {