Index: tools/viewer/sk_app/win/VulkanWindowContext_win.cpp |
diff --git a/tools/viewer/sk_app/win/VulkanWindowContext_win.cpp b/tools/viewer/sk_app/win/VulkanWindowContext_win.cpp |
index e4251b88cfca6063de433752a7487c2d49b47cb3..521a1ee3cd8f1d5d2963d56ce46c181c01d3b239 100644 |
--- a/tools/viewer/sk_app/win/VulkanWindowContext_win.cpp |
+++ b/tools/viewer/sk_app/win/VulkanWindowContext_win.cpp |
@@ -6,6 +6,9 @@ |
* found in the LICENSE file. |
*/ |
+#include <Windows.h> |
+#include "WindowContextFactory_win.h" |
+ |
#include "../VulkanWindowContext.h" |
#include "Window_win.h" |
@@ -13,51 +16,56 @@ |
#include "vk/GrVkUtil.h" |
namespace sk_app { |
+namespace window_context_factory { |
-// Platform dependant call |
-VkSurfaceKHR VulkanWindowContext::createVkSurface(VkInstance instance, void* platformData) { |
- static PFN_vkCreateWin32SurfaceKHR createWin32SurfaceKHR = nullptr; |
- if (!createWin32SurfaceKHR) { |
- createWin32SurfaceKHR = (PFN_vkCreateWin32SurfaceKHR) vkGetInstanceProcAddr(instance, |
- "vkCreateWin32SurfaceKHR"); |
- } |
+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; |
- if (!platformData) { |
- return VK_NULL_HANDLE; |
- } |
- ContextPlatformData_win* winPlatformData = |
- reinterpret_cast<ContextPlatformData_win*>(platformData); |
- VkSurfaceKHR surface; |
- |
- 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 = winPlatformData->fHInstance; |
- surfaceCreateInfo.hwnd = winPlatformData->fHWnd; |
- |
- VkResult res = createWin32SurfaceKHR(instance, &surfaceCreateInfo, nullptr, &surface); |
- if (VK_SUCCESS != res) { |
- return VK_NULL_HANDLE; |
- } |
+ 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; |
- return surface; |
-} |
+ VkResult res = createWin32SurfaceKHR(instance, &surfaceCreateInfo, nullptr, &surface); |
+ if (VK_SUCCESS != res) { |
+ return VK_NULL_HANDLE; |
+ } |
-// Platform dependant call |
-bool VulkanWindowContext::canPresent(VkInstance instance, VkPhysicalDevice physDev, |
- uint32_t queueFamilyIndex, void*) { |
- static PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR |
+ return surface; |
+ }; |
+ |
+ auto canPresent = [hwnd] (VkInstance instance, VkPhysicalDevice physDev, |
+ uint32_t queueFamilyIndex) { |
+ static PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR |
getPhysicalDeviceWin32PresentationSupportKHR = nullptr; |
- if (!getPhysicalDeviceWin32PresentationSupportKHR) { |
- getPhysicalDeviceWin32PresentationSupportKHR = |
- (PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR) vkGetInstanceProcAddr(instance, |
- "vkGetPhysicalDeviceWin32PresentationSupportKHR"); |
- } |
+ if (!getPhysicalDeviceWin32PresentationSupportKHR) { |
+ getPhysicalDeviceWin32PresentationSupportKHR = |
+ (PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR) |
+ vkGetInstanceProcAddr(instance, |
+ "vkGetPhysicalDeviceWin32PresentationSupportKHR"); |
+ } |
- VkBool32 check = getPhysicalDeviceWin32PresentationSupportKHR(physDev, queueFamilyIndex); |
- return (VK_FALSE != check); |
+ 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; |
} |
-} // namespace sk_app |
+} // namespace window_context_factory |
+} // namespace sk_app |