Account for GrVkBackendContext assuming ownership of the VkInstance and VkDevice. (flutter/engine#3604)

This commit is contained in:
Chinmay Garde
2017-04-18 14:21:42 -07:00
committed by GitHub
parent 975cebb327
commit f05379f248
7 changed files with 27 additions and 3 deletions

View File

@@ -115,10 +115,14 @@ uint32_t VulkanApplication::GetAPIVersion() const {
return api_version_;
}
const VulkanHandle<VkInstance>& VulkanApplication::GetInstance() {
const VulkanHandle<VkInstance>& VulkanApplication::GetInstance() const {
return instance_;
}
void VulkanApplication::ReleaseInstanceOwnership() {
instance_.ReleaseOwnership();
}
std::vector<VkPhysicalDevice> VulkanApplication::GetPhysicalDevices() const {
if (!IsValid()) {
return {};

View File

@@ -33,7 +33,9 @@ class VulkanApplication {
uint32_t GetAPIVersion() const;
const VulkanHandle<VkInstance>& GetInstance();
const VulkanHandle<VkInstance>& GetInstance() const;
void ReleaseInstanceOwnership();
std::unique_ptr<VulkanDevice> AcquireFirstCompatibleLogicalDevice() const;

View File

@@ -148,6 +148,10 @@ const VulkanHandle<VkDevice>& VulkanDevice::GetHandle() const {
return device_;
}
void VulkanDevice::ReleaseDeviceOwnership() {
device_.ReleaseOwnership();
}
const VulkanHandle<VkPhysicalDevice>& VulkanDevice::GetPhysicalDeviceHandle()
const {
return physical_device_;

View File

@@ -35,6 +35,8 @@ class VulkanDevice {
uint32_t GetGraphicsQueueIndex() const;
void ReleaseDeviceOwnership();
FTL_WARN_UNUSED_RESULT
bool GetSurfaceCapabilities(const VulkanSurface& surface,
VkSurfaceCapabilitiesKHR* capabilities) const;

View File

@@ -50,6 +50,11 @@ class VulkanHandle {
operator Handle() const { return handle_; }
/// Relinquish responsibility of collecting the underlying handle when this
/// object is collected. It is the responsibility of the caller to ensure that
/// the lifetime of the handle extends past the lifetime of this object.
void ReleaseOwnership() { disposer_ = nullptr; }
private:
Handle handle_;
Disposer disposer_;

View File

@@ -129,6 +129,11 @@ sk_sp<GrVkBackendContext> VulkanWindow::CreateSkiaBackendContext() {
return nullptr;
}
// The Skia backend context takes ownership of the device and the instance.
// Make sure we release our ownership now.
logical_device_->ReleaseDeviceOwnership();
application_->ReleaseInstanceOwnership();
auto context = sk_make_sp<GrVkBackendContext>();
context->fInstance = application_->GetInstance();
context->fPhysicalDevice = logical_device_->GetPhysicalDeviceHandle();

View File

@@ -47,11 +47,13 @@ class VulkanWindow {
private:
bool valid_;
ftl::RefPtr<VulkanProcTable> vk;
// Note: The order of objects here is important because the
// GrVkBackendContext assumes ownership of the device and instance handles.
sk_sp<GrVkBackendContext> skia_vk_backend_context_;
std::unique_ptr<VulkanApplication> application_;
std::unique_ptr<VulkanDevice> logical_device_;
std::unique_ptr<VulkanSurface> surface_;
std::unique_ptr<VulkanSwapchain> swapchain_;
sk_sp<GrVkBackendContext> skia_vk_backend_context_;
sk_sp<GrContext> skia_gr_context_;
bool CreateSkiaGrContext();