Always destroy resources instead of simply "abandoning" them in Vulkan backend.

This also now requires that when using a vulkan GrContext, the backing VkDevice,
Queue, and Instance must be alive when the GrContext is first destroyed or
abandoned. Additionally any GrBackendTextures created from the GrContext must
be deleted before destroying or abandoning the GrContext.

Bug: skia:9603
Change-Id: Ibf194d2ffdcddd61e34214d7d59a2d9a33c880e5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/257921
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
diff --git a/tools/gpu/GrContextFactory.cpp b/tools/gpu/GrContextFactory.cpp
index be33802..4432c87 100644
--- a/tools/gpu/GrContextFactory.cpp
+++ b/tools/gpu/GrContextFactory.cpp
@@ -86,10 +86,18 @@
             if (context.fTestContext) {
                 auto restore = context.fTestContext->makeCurrentAndAutoRestore();
                 context.fTestContext->testAbandon();
+            }
+            bool requiresEarlyAbandon = (context.fGrContext->backend() == GrBackendApi::kVulkan);
+            if (requiresEarlyAbandon) {
+                context.fGrContext->abandonContext();
+            }
+            if (context.fTestContext) {
                 delete(context.fTestContext);
                 context.fTestContext = nullptr;
             }
-            context.fGrContext->abandonContext();
+            if (!requiresEarlyAbandon) {
+                context.fGrContext->abandonContext();
+            }
             context.fAbandoned = true;
         }
     }
@@ -108,11 +116,11 @@
                 restore = context.fTestContext->makeCurrentAndAutoRestore();
             }
             context.fGrContext->releaseResourcesAndAbandonContext();
-            context.fAbandoned = true;
             if (context.fTestContext) {
                 delete context.fTestContext;
                 context.fTestContext = nullptr;
             }
+            context.fAbandoned = true;
         }
     }
 }