Add new GrVkBackendContext::Create explicitly requiring vk proc getters

Also remove the feature of GrVkGpu that creates the instance/device if the client doesn't provide one.

Change-Id: Ie617313b6c684ed355333a475b80d0aae7e3a026
Reviewed-on: https://skia-review.googlesource.com/14261
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2017-04-24 16:49:05 -04:00 committed by Skia Commit-Bot
parent bb05f70b4b
commit c1889823de
5 changed files with 26 additions and 6 deletions

View File

@ -58,6 +58,20 @@ struct GrVkBackendContext : public SkRefCnt {
CanPresentFn = CanPresentFn(),
GrVkInterface::GetProc getProc = nullptr);
static const GrVkBackendContext* Create(const GrVkInterface::GetInstanceProc& getInstanceProc,
const GrVkInterface::GetDeviceProc& getDeviceProc,
uint32_t* presentQueueIndex = nullptr,
CanPresentFn canPresent = CanPresentFn()) {
auto getProc = [&getInstanceProc, &getDeviceProc](const char* proc_name,
VkInstance instance, VkDevice device) {
if (device != VK_NULL_HANDLE) {
return getDeviceProc(device, proc_name);
}
return getInstanceProc(instance, proc_name);
};
return Create(presentQueueIndex, canPresent, getProc);
}
~GrVkBackendContext() override;
};

View File

@ -40,6 +40,13 @@ public:
VkInstance, // instance or VK_NULL_HANDLE
VkDevice // device or VK_NULL_HANDLE
)>;
// This is typically vkGetInstanceProcAddr.
using GetInstanceProc = std::function<PFN_vkVoidFunction(VkInstance, const char*)>;
// This is typically vkGetDeviceProcAddr.
using GetDeviceProc = std::function<PFN_vkVoidFunction(VkDevice, const char*)>;
GrVkInterface(GetProc getProc,
VkInstance instance,
VkDevice device,

View File

@ -77,10 +77,7 @@ GrGpu* GrVkGpu::Create(GrBackendContext backendContext, const GrContextOptions&
const GrVkBackendContext* vkBackendContext =
reinterpret_cast<const GrVkBackendContext*>(backendContext);
if (!vkBackendContext) {
vkBackendContext = GrVkBackendContext::Create();
if (!vkBackendContext) {
return nullptr;
}
return nullptr;
} else {
vkBackendContext->ref();
}

View File

@ -109,7 +109,8 @@ GR_STATIC_ASSERT(sizeof(VkFence) <= sizeof(sk_gpu_test::PlatformFence));
class VkTestContextImpl : public sk_gpu_test::VkTestContext {
public:
static VkTestContext* Create() {
sk_sp<const GrVkBackendContext> backendContext(GrVkBackendContext::Create());
sk_sp<const GrVkBackendContext> backendContext(
GrVkBackendContext::Create(vkGetInstanceProcAddr, vkGetDeviceProcAddr));
if (!backendContext) {
return nullptr;
}

View File

@ -41,7 +41,8 @@ VulkanWindowContext::VulkanWindowContext(const DisplayParams& params,
, fBackbuffers(nullptr) {
// any config code here (particularly for msaa)?
fBackendContext.reset(GrVkBackendContext::Create(&fPresentQueueIndex, canPresent));
fBackendContext.reset(GrVkBackendContext::Create(vkGetInstanceProcAddr, vkGetDeviceProcAddr,
&fPresentQueueIndex, canPresent));
if (!(fBackendContext->fExtensions & kKHR_surface_GrVkExtensionFlag) ||
!(fBackendContext->fExtensions & kKHR_swapchain_GrVkExtensionFlag)) {