Flutter Engine
The Flutter Engine
VulkanWindowContext_win.cpp
Go to the documentation of this file.
1
2/*
3 * Copyright 2016 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
10
13
15
17
18#include <Windows.h>
19
20namespace skwindow {
21
22std::unique_ptr<WindowContext> MakeVulkanForWin(HWND hwnd, const DisplayParams& params) {
24 if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc)) {
25 return nullptr;
26 }
27
28 auto createVkSurface = [hwnd, instProc] (VkInstance instance) -> VkSurfaceKHR {
29 static PFN_vkCreateWin32SurfaceKHR createWin32SurfaceKHR = nullptr;
30 if (!createWin32SurfaceKHR) {
31 createWin32SurfaceKHR = (PFN_vkCreateWin32SurfaceKHR)
32 instProc(instance, "vkCreateWin32SurfaceKHR");
33 }
34 HINSTANCE hinstance = GetModuleHandle(0);
35 VkSurfaceKHR surface;
36
37 VkWin32SurfaceCreateInfoKHR surfaceCreateInfo;
38 memset(&surfaceCreateInfo, 0, sizeof(VkWin32SurfaceCreateInfoKHR));
40 surfaceCreateInfo.pNext = nullptr;
41 surfaceCreateInfo.flags = 0;
42 surfaceCreateInfo.hinstance = hinstance;
43 surfaceCreateInfo.hwnd = hwnd;
44
45 VkResult res = createWin32SurfaceKHR(instance, &surfaceCreateInfo, nullptr, &surface);
46 if (VK_SUCCESS != res) {
47 return VK_NULL_HANDLE;
48 }
49
50 return surface;
51 };
52
53 auto canPresent = [instProc] (VkInstance instance, VkPhysicalDevice physDev,
54 uint32_t queueFamilyIndex) {
56 getPhysicalDeviceWin32PresentationSupportKHR = nullptr;
57 if (!getPhysicalDeviceWin32PresentationSupportKHR) {
58 getPhysicalDeviceWin32PresentationSupportKHR =
60 instProc(instance, "vkGetPhysicalDeviceWin32PresentationSupportKHR");
61 }
62
63 VkBool32 check = getPhysicalDeviceWin32PresentationSupportKHR(physDev, queueFamilyIndex);
64 return (VK_FALSE != check);
65 };
66
67 std::unique_ptr<WindowContext> ctx(
68 new internal::VulkanWindowContext(params, createVkSurface, canPresent, instProc));
69 if (!ctx->isValid()) {
70 return nullptr;
71 }
72 return ctx;
73}
74
75} // 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 > MakeVulkanForWin(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