diff options
Diffstat (limited to 'tools/gpu/vk/VkTestContext.cpp')
-rw-r--r-- | tools/gpu/vk/VkTestContext.cpp | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/tools/gpu/vk/VkTestContext.cpp b/tools/gpu/vk/VkTestContext.cpp index 25069fe521..592fb0f7b0 100644 --- a/tools/gpu/vk/VkTestContext.cpp +++ b/tools/gpu/vk/VkTestContext.cpp @@ -110,21 +110,24 @@ GR_STATIC_ASSERT(sizeof(VkFence) <= sizeof(sk_gpu_test::PlatformFence)); class VkTestContextImpl : public sk_gpu_test::VkTestContext { public: static VkTestContext* Create(VkTestContext* sharedContext) { - sk_sp<const GrVkBackendContext> backendContext; + GrVkBackendContext backendContext; + bool ownsContext = true; if (sharedContext) { backendContext = sharedContext->getVkBackendContext(); + // We always delete the parent context last so make sure the child does not think they + // own the vulkan context. + ownsContext = false; } else { PFN_vkGetInstanceProcAddr instProc; PFN_vkGetDeviceProcAddr devProc; if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc, &devProc)) { return nullptr; } - backendContext.reset(GrVkBackendContext::Create(instProc, devProc)); - } - if (!backendContext) { - return nullptr; + if (!sk_gpu_test::CreateVkBackendContext(instProc, devProc, &backendContext)) { + return nullptr; + } } - return new VkTestContextImpl(std::move(backendContext)); + return new VkTestContextImpl(backendContext, ownsContext); } ~VkTestContextImpl() override { this->teardown(); } @@ -143,14 +146,19 @@ public: protected: void teardown() override { INHERITED::teardown(); - fVk.reset(nullptr); + fVk.fMemoryAllocator.reset(); + if (fOwnsContext) { + GR_VK_CALL(this->vk(), DeviceWaitIdle(fVk.fDevice)); + GR_VK_CALL(this->vk(), DestroyDevice(fVk.fDevice, nullptr)); + GR_VK_CALL(this->vk(), DestroyInstance(fVk.fInstance, nullptr)); + } } private: - VkTestContextImpl(sk_sp<const GrVkBackendContext> backendContext) - : VkTestContext(std::move(backendContext)) { - fFenceSync.reset(new VkFenceSync(fVk->fInterface, fVk->fDevice, fVk->fQueue, - fVk->fGraphicsQueueIndex)); + VkTestContextImpl(const GrVkBackendContext& backendContext, bool ownsContext) + : VkTestContext(backendContext, ownsContext) { + fFenceSync.reset(new VkFenceSync(fVk.fInterface, fVk.fDevice, fVk.fQueue, + fVk.fGraphicsQueueIndex)); } void onPlatformMakeCurrent() const override {} |