Flutter Engine
The Flutter Engine
GraphiteVulkanWindowContext_win.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9
12
14
15#include <Windows.h>
16
17namespace skwindow {
18
19std::unique_ptr<WindowContext> MakeGraphiteVulkanForWin(HWND hwnd, const DisplayParams& params) {
21 if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc)) {
22 return nullptr;
23 }
24
25 auto createVkSurface = [hwnd, instProc] (VkInstance instance) -> VkSurfaceKHR {
26 static PFN_vkCreateWin32SurfaceKHR createWin32SurfaceKHR = nullptr;
27 if (!createWin32SurfaceKHR) {
28 createWin32SurfaceKHR = (PFN_vkCreateWin32SurfaceKHR)
29 instProc(instance, "vkCreateWin32SurfaceKHR");
30 }
31 HINSTANCE hinstance = GetModuleHandle(0);
32 VkSurfaceKHR surface;
33
34 VkWin32SurfaceCreateInfoKHR surfaceCreateInfo;
35 memset(&surfaceCreateInfo, 0, sizeof(VkWin32SurfaceCreateInfoKHR));
37 surfaceCreateInfo.pNext = nullptr;
38 surfaceCreateInfo.flags = 0;
39 surfaceCreateInfo.hinstance = hinstance;
40 surfaceCreateInfo.hwnd = hwnd;
41
42 VkResult res = createWin32SurfaceKHR(instance, &surfaceCreateInfo, nullptr, &surface);
43 if (VK_SUCCESS != res) {
44 return VK_NULL_HANDLE;
45 }
46
47 return surface;
48 };
49
50 auto canPresent = [instProc] (VkInstance instance, VkPhysicalDevice physDev,
51 uint32_t queueFamilyIndex) {
53 getPhysicalDeviceWin32PresentationSupportKHR = nullptr;
54 if (!getPhysicalDeviceWin32PresentationSupportKHR) {
55 getPhysicalDeviceWin32PresentationSupportKHR =
57 instProc(instance, "vkGetPhysicalDeviceWin32PresentationSupportKHR");
58 }
59
60 VkBool32 check = getPhysicalDeviceWin32PresentationSupportKHR(physDev, queueFamilyIndex);
61 return (VK_FALSE != check);
62 };
63
64 std::unique_ptr<WindowContext> ctx(
65 new internal::GraphiteVulkanWindowContext(params, createVkSurface,
66 canPresent, instProc));
67 if (!ctx->isValid()) {
68 return nullptr;
69 }
70 return ctx;
71}
72
73} // namespace skwindow
#define check(reporter, ref, unref, make, kill)
Definition: RefCntTest.cpp:85
const EmbeddedViewParams * params
VkInstance instance
Definition: main.cc:48
VkSurfaceKHR surface
Definition: main.cc:49
std::unique_ptr< WindowContext > MakeGraphiteVulkanForWin(HWND hwnd, const DisplayParams &params)
VkWin32SurfaceCreateFlagsKHR flags
Definition: vulkan_win32.h:30
#define VK_FALSE
Definition: vulkan_core.h:125
VkResult
Definition: vulkan_core.h:140
@ VK_SUCCESS
Definition: vulkan_core.h:141
#define VK_NULL_HANDLE
Definition: vulkan_core.h:46
uint32_t VkBool32
Definition: vulkan_core.h:94
PFN_vkVoidFunction(VKAPI_PTR * PFN_vkGetInstanceProcAddr)(VkInstance instance, const char *pName)
Definition: vulkan_core.h:3989
@ VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR
Definition: vulkan_core.h:433
VkResult(VKAPI_PTR * PFN_vkCreateWin32SurfaceKHR)(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface)
Definition: vulkan_win32.h:35
VkBool32(VKAPI_PTR * PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex)
Definition: vulkan_win32.h:36