Flutter Engine
The Flutter Engine
GraphiteVulkanWindowContext_unix.cpp
Go to the documentation of this file.
1
2/*
3 * Copyright 2023 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
14#include <X11/Xlib-xcb.h>
15
16namespace skwindow {
17
18std::unique_ptr<WindowContext> MakeGraphiteVulkanForXlib(const XlibWindowInfo& info,
19 const DisplayParams& displayParams) {
21 if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc)) {
22 SkDebugf("Could not load vulkan library\n");
23 return nullptr;
24 }
25
26 auto createVkSurface = [&info, instProc](VkInstance instance) -> VkSurfaceKHR {
27 static PFN_vkCreateXcbSurfaceKHR createXcbSurfaceKHR = nullptr;
28 if (!createXcbSurfaceKHR) {
29 createXcbSurfaceKHR =
30 (PFN_vkCreateXcbSurfaceKHR) instProc(instance, "vkCreateXcbSurfaceKHR");
31 }
32
33 VkSurfaceKHR surface;
34
35 VkXcbSurfaceCreateInfoKHR surfaceCreateInfo;
36 memset(&surfaceCreateInfo, 0, sizeof(VkXcbSurfaceCreateInfoKHR));
38 surfaceCreateInfo.pNext = nullptr;
39 surfaceCreateInfo.flags = 0;
40 surfaceCreateInfo.connection = XGetXCBConnection(info.fDisplay);
41 surfaceCreateInfo.window = info.fWindow;
42
43 VkResult res = createXcbSurfaceKHR(instance, &surfaceCreateInfo, nullptr, &surface);
44 if (res != VK_SUCCESS) {
45 return VK_NULL_HANDLE;
46 }
47
48 return surface;
49 };
50
51 auto canPresent = [&info, instProc](VkInstance instance, VkPhysicalDevice physDev,
52 uint32_t queueFamilyIndex) {
54 getPhysicalDeviceXcbPresentationSupportKHR = nullptr;
55 if (!getPhysicalDeviceXcbPresentationSupportKHR) {
56 getPhysicalDeviceXcbPresentationSupportKHR =
58 instProc(instance, "vkGetPhysicalDeviceXcbPresentationSupportKHR");
59 }
60
61 Display* display = info.fDisplay;
62 VisualID visualID = XVisualIDFromVisual(DefaultVisual(info.fDisplay,
63 DefaultScreen(info.fDisplay)));
64 VkBool32 check = getPhysicalDeviceXcbPresentationSupportKHR(physDev,
65 queueFamilyIndex,
66 XGetXCBConnection(display),
67 visualID);
68 return (check != VK_FALSE);
69 };
70 std::unique_ptr<WindowContext> ctx(
71 new internal::GraphiteVulkanWindowContext(displayParams,
72 createVkSurface,
73 canPresent,
74 instProc));
75 if (!ctx->isValid()) {
76 return nullptr;
77 }
78 return ctx;
79}
80
81} // 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 > MakeGraphiteVulkanForXlib(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