aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/gpu/vk/GrVkBackendContext.h23
-rw-r--r--src/gpu/vk/GrVkBackendContext.cpp3
2 files changed, 20 insertions, 6 deletions
diff --git a/include/gpu/vk/GrVkBackendContext.h b/include/gpu/vk/GrVkBackendContext.h
index 5838caa323..987b32f3b3 100644
--- a/include/gpu/vk/GrVkBackendContext.h
+++ b/include/gpu/vk/GrVkBackendContext.h
@@ -45,15 +45,28 @@ struct GrVkBackendContext : public SkRefCnt {
uint32_t fExtensions;
uint32_t fFeatures;
sk_sp<const GrVkInterface> fInterface;
+ /**
+ * Controls whether this object destroys the instance and device upon destruction. The default
+ * is temporarily 'true' to avoid breaking existing clients but will be changed to 'false'.
+ */
+ bool fOwnsInstanceAndDevice = true;
using CanPresentFn = std::function<bool(VkInstance, VkPhysicalDevice,
uint32_t queueFamilyIndex)>;
- // Helper function to create the default Vulkan objects needed by the GrVkGpu object
- // If getProc is NULL, a default getProc will be constructed if we are statically linking
- // against Vulkan.
- // If presentQueueIndex is non-NULL, will try to set up presentQueue as part of device
- // creation using the platform-specific canPresent() function.
+ /**
+ * Helper function to create the Vulkan objects needed for a Vulkan-backed GrContext.
+ * If getProc is null, a default getProc will be constructed if we are statically linking
+ * against Vulkan. Note that this default behavior will be removed soon as well as the version
+ * that uses the unified "GetProc" instead of separate "GetInstanceProc" and "GetDeviceProc"
+ * functions.
+ *
+ * If presentQueueIndex is non-NULL, will try to set up presentQueue as part of device
+ * creation using the platform-specific canPresent() function.
+ *
+ * This will set fOwnsInstanceAndDevice to 'true'. If it is subsequently set to 'false' then
+ * the client owns the lifetime of the created VkDevice and VkInstance.
+ */
static const GrVkBackendContext* Create(uint32_t* presentQueueIndex = nullptr,
CanPresentFn = CanPresentFn(),
GrVkInterface::GetProc getProc = nullptr);
diff --git a/src/gpu/vk/GrVkBackendContext.cpp b/src/gpu/vk/GrVkBackendContext.cpp
index 2d8a7d5f66..fea1947489 100644
--- a/src/gpu/vk/GrVkBackendContext.cpp
+++ b/src/gpu/vk/GrVkBackendContext.cpp
@@ -301,12 +301,13 @@ const GrVkBackendContext* GrVkBackendContext::Create(uint32_t* presentQueueIndex
ctx->fExtensions = extensionFlags;
ctx->fFeatures = featureFlags;
ctx->fInterface.reset(interface.release());
+ ctx->fOwnsInstanceAndDevice = true;
return ctx;
}
GrVkBackendContext::~GrVkBackendContext() {
- if (fInterface == nullptr) {
+ if (fInterface == nullptr || !fOwnsInstanceAndDevice) {
return;
}