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
|
|
|
|
2017-11-10 15:03:05 +00:00
|
|
|
#include "vk/VkTestUtils.h"
|
|
|
|
|
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) {
|
2017-11-10 15:03:05 +00:00
|
|
|
PFN_vkGetInstanceProcAddr instProc;
|
|
|
|
PFN_vkGetDeviceProcAddr devProc;
|
|
|
|
if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc, &devProc)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto createVkSurface = [hwnd, instProc] (VkInstance instance) -> VkSurfaceKHR {
|
2016-07-26 19:02:50 +00:00
|
|
|
static PFN_vkCreateWin32SurfaceKHR createWin32SurfaceKHR = nullptr;
|
|
|
|
if (!createWin32SurfaceKHR) {
|
|
|
|
createWin32SurfaceKHR = (PFN_vkCreateWin32SurfaceKHR)
|
2017-11-10 15:03:05 +00:00
|
|
|
instProc(instance, "vkCreateWin32SurfaceKHR");
|
2016-07-26 19:02:50 +00:00
|
|
|
}
|
|
|
|
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-11-10 15:03:05 +00:00
|
|
|
auto canPresent = [instProc] (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)
|
2017-11-10 15:03:05 +00:00
|
|
|
instProc(instance, "vkGetPhysicalDeviceWin32PresentationSupportKHR");
|
2016-07-26 19:02:50 +00:00
|
|
|
}
|
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);
|
|
|
|
};
|
|
|
|
|
2017-11-10 15:03:05 +00:00
|
|
|
WindowContext* ctx = new VulkanWindowContext(params, createVkSurface, canPresent,
|
|
|
|
instProc, devProc);
|
2016-07-26 19:02:50 +00:00
|
|
|
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
|