Flutter Engine
The Flutter Engine
VulkanWindowContext_unix.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 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
11
14
15#include <X11/Xlib-xcb.h>
16
17namespace skwindow {
18
19std::unique_ptr<WindowContext> MakeVulkanForXlib(const XlibWindowInfo& info,
20 const DisplayParams& displayParams) {
22 if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc)) {
23 SkDebugf("Could not load vulkan library\n");
24 return nullptr;
25 }
26
27 auto createVkSurface = [&info, instProc](VkInstance instance) -> VkSurfaceKHR {
28 static PFN_vkCreateXcbSurfaceKHR createXcbSurfaceKHR = nullptr;
29 if (!createXcbSurfaceKHR) {
30 createXcbSurfaceKHR =
31 (PFN_vkCreateXcbSurfaceKHR) instProc(instance, "vkCreateXcbSurfaceKHR");
32 }
33
34 VkSurfaceKHR surface;
35
36 VkXcbSurfaceCreateInfoKHR surfaceCreateInfo;
37 memset(&surfaceCreateInfo, 0, sizeof(VkXcbSurfaceCreateInfoKHR));
39 surfaceCreateInfo.pNext = nullptr;
40 surfaceCreateInfo.flags = 0;
41 surfaceCreateInfo.connection = XGetXCBConnection(info.fDisplay);
42 surfaceCreateInfo.window = info.fWindow;
43
44 VkResult res = createXcbSurfaceKHR(instance, &surfaceCreateInfo, nullptr, &surface);
45 if (VK_SUCCESS != res) {
46 return VK_NULL_HANDLE;
47 }
48
49 return surface;
50 };
51
52 auto canPresent = [&info, instProc](VkInstance instance, VkPhysicalDevice physDev,
53 uint32_t queueFamilyIndex) {
55 getPhysicalDeviceXcbPresentationSupportKHR = nullptr;
56 if (!getPhysicalDeviceXcbPresentationSupportKHR) {
57 getPhysicalDeviceXcbPresentationSupportKHR =
59 instProc(instance, "vkGetPhysicalDeviceXcbPresentationSupportKHR");
60 }
61
62 Display* display = info.fDisplay;
63 VisualID visualID = XVisualIDFromVisual(DefaultVisual(info.fDisplay,
64 DefaultScreen(info.fDisplay)));
65 VkBool32 check = getPhysicalDeviceXcbPresentationSupportKHR(physDev,
66 queueFamilyIndex,
67 XGetXCBConnection(display),
68 visualID);
69 return (VK_FALSE != check);
70 };
71 std::unique_ptr<WindowContext> ctx(
72 new internal::VulkanWindowContext(displayParams,
73 createVkSurface,
74 canPresent,
75 instProc));
76 if (!ctx->isValid()) {
77 return nullptr;
78 }
79 return ctx;
80}
81
82} // namespace skwindow
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
#define check(reporter, ref, unref, make, kill)
Definition: RefCntTest.cpp:85
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
VkInstance instance
Definition: main.cc:48
VkSurfaceKHR surface
Definition: main.cc:49
std::unique_ptr< WindowContext > MakeVulkanForXlib(const XlibWindowInfo &info, const DisplayParams &displayParams)
VkStructureType sType
Definition: vulkan_xcb.h:28
VkXcbSurfaceCreateFlagsKHR flags
Definition: vulkan_xcb.h:30
xcb_connection_t * connection
Definition: vulkan_xcb.h:31
#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_XCB_SURFACE_CREATE_INFO_KHR
Definition: vulkan_core.h:430
VkResult(VKAPI_PTR * PFN_vkCreateXcbSurfaceKHR)(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface)
Definition: vulkan_xcb.h:35
VkBool32(VKAPI_PTR * PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, xcb_connection_t *connection, xcb_visualid_t visual_id)
Definition: vulkan_xcb.h:36