2016-04-06 13:08:59 +00:00
|
|
|
|
|
|
|
/*
|
2016-04-21 18:46:23 +00:00
|
|
|
* Copyright 2016 Google Inc.
|
2016-04-06 13:08:59 +00:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2016-07-26 19:02:50 +00:00
|
|
|
#include <Windows.h>
|
|
|
|
#include "WindowContextFactory_win.h"
|
|
|
|
|
2016-05-20 13:01:06 +00:00
|
|
|
#include "../VulkanWindowContext.h"
|
|
|
|
#include "Window_win.h"
|
2016-04-06 13:08:59 +00:00
|
|
|
|
|
|
|
#include "vk/GrVkInterface.h"
|
2016-04-21 18:46:23 +00:00
|
|
|
#include "vk/GrVkUtil.h"
|
2016-04-06 13:08:59 +00:00
|
|
|
|
2016-05-05 19:32:03 +00:00
|
|
|
namespace sk_app {
|
2016-07-26 19:02:50 +00:00
|
|
|
namespace window_context_factory {
|
2016-05-05 19:32:03 +00:00
|
|
|
|
2016-07-26 19:02:50 +00:00
|
|
|
WindowContext* NewVulkanForWin(HWND hwnd, const DisplayParams& params) {
|
|
|
|
auto createVkSurface = [hwnd] (VkInstance instance) -> VkSurfaceKHR {
|
|
|
|
static PFN_vkCreateWin32SurfaceKHR createWin32SurfaceKHR = nullptr;
|
|
|
|
if (!createWin32SurfaceKHR) {
|
|
|
|
createWin32SurfaceKHR = (PFN_vkCreateWin32SurfaceKHR)
|
|
|
|
vkGetInstanceProcAddr(instance, "vkCreateWin32SurfaceKHR");
|
|
|
|
}
|
|
|
|
HINSTANCE hinstance = GetModuleHandle(0);
|
|
|
|
VkSurfaceKHR surface;
|
2016-04-21 18:46:23 +00:00
|
|
|
|
2016-07-26 19:02:50 +00:00
|
|
|
VkWin32SurfaceCreateInfoKHR surfaceCreateInfo;
|
|
|
|
memset(&surfaceCreateInfo, 0, sizeof(VkWin32SurfaceCreateInfoKHR));
|
|
|
|
surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
|
|
|
|
surfaceCreateInfo.pNext = nullptr;
|
|
|
|
surfaceCreateInfo.flags = 0;
|
|
|
|
surfaceCreateInfo.hinstance = hinstance;
|
|
|
|
surfaceCreateInfo.hwnd = hwnd;
|
2016-04-06 13:08:59 +00:00
|
|
|
|
2016-07-26 19:02:50 +00:00
|
|
|
VkResult res = createWin32SurfaceKHR(instance, &surfaceCreateInfo, nullptr, &surface);
|
|
|
|
if (VK_SUCCESS != res) {
|
|
|
|
return VK_NULL_HANDLE;
|
|
|
|
}
|
2016-04-06 13:08:59 +00:00
|
|
|
|
2016-07-26 19:02:50 +00:00
|
|
|
return surface;
|
|
|
|
};
|
|
|
|
|
2017-10-06 18:50:29 +00:00
|
|
|
auto canPresent = [] (VkInstance instance, VkPhysicalDevice physDev,
|
|
|
|
uint32_t queueFamilyIndex) {
|
2016-07-26 19:02:50 +00:00
|
|
|
static PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR
|
2016-05-05 19:32:03 +00:00
|
|
|
getPhysicalDeviceWin32PresentationSupportKHR = nullptr;
|
2016-07-26 19:02:50 +00:00
|
|
|
if (!getPhysicalDeviceWin32PresentationSupportKHR) {
|
|
|
|
getPhysicalDeviceWin32PresentationSupportKHR =
|
|
|
|
(PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR)
|
|
|
|
vkGetInstanceProcAddr(instance,
|
|
|
|
"vkGetPhysicalDeviceWin32PresentationSupportKHR");
|
|
|
|
}
|
2016-04-21 18:46:23 +00:00
|
|
|
|
2016-07-26 19:02:50 +00:00
|
|
|
VkBool32 check = getPhysicalDeviceWin32PresentationSupportKHR(physDev, queueFamilyIndex);
|
|
|
|
return (VK_FALSE != check);
|
|
|
|
};
|
|
|
|
|
|
|
|
WindowContext* ctx = new VulkanWindowContext(params, createVkSurface, canPresent);
|
|
|
|
if (!ctx->isValid()) {
|
|
|
|
delete ctx;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return ctx;
|
2016-04-06 13:08:59 +00:00
|
|
|
}
|
2016-05-05 19:32:03 +00:00
|
|
|
|
2016-07-26 19:02:50 +00:00
|
|
|
} // namespace window_context_factory
|
|
|
|
} // namespace sk_app
|