2016-05-23 20:13:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/vk/GrVkVulkan.h"
|
2016-05-23 20:13:36 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/vk/GrVkInterface.h"
|
|
|
|
#include "src/gpu/vk/GrVkUtil.h"
|
2016-05-23 20:13:36 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/gpu/vk/VkTestUtils.h"
|
2017-11-10 15:03:05 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/sk_app/VulkanWindowContext.h"
|
|
|
|
#include "tools/sk_app/unix/WindowContextFactory_unix.h"
|
2016-05-23 20:13:36 +00:00
|
|
|
|
2018-09-19 15:31:27 +00:00
|
|
|
#include <X11/Xlib-xcb.h>
|
|
|
|
|
2016-07-26 19:02:50 +00:00
|
|
|
namespace sk_app {
|
2016-05-23 20:13:36 +00:00
|
|
|
|
2016-07-26 19:02:50 +00:00
|
|
|
namespace window_context_factory {
|
|
|
|
|
2019-08-01 20:21:49 +00:00
|
|
|
std::unique_ptr<WindowContext> MakeVulkanForXlib(const XlibWindowInfo& info,
|
|
|
|
const DisplayParams& displayParams) {
|
2017-11-10 15:03:05 +00:00
|
|
|
PFN_vkGetInstanceProcAddr instProc;
|
2022-01-14 16:30:38 +00:00
|
|
|
if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc)) {
|
2017-11-10 15:03:05 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto createVkSurface = [&info, instProc](VkInstance instance) -> VkSurfaceKHR {
|
2016-07-26 19:02:50 +00:00
|
|
|
static PFN_vkCreateXcbSurfaceKHR createXcbSurfaceKHR = nullptr;
|
|
|
|
if (!createXcbSurfaceKHR) {
|
|
|
|
createXcbSurfaceKHR =
|
2017-11-10 15:03:05 +00:00
|
|
|
(PFN_vkCreateXcbSurfaceKHR) instProc(instance, "vkCreateXcbSurfaceKHR");
|
2016-07-26 19:02:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VkSurfaceKHR surface;
|
|
|
|
|
|
|
|
VkXcbSurfaceCreateInfoKHR surfaceCreateInfo;
|
|
|
|
memset(&surfaceCreateInfo, 0, sizeof(VkXcbSurfaceCreateInfoKHR));
|
|
|
|
surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
|
|
|
|
surfaceCreateInfo.pNext = nullptr;
|
|
|
|
surfaceCreateInfo.flags = 0;
|
|
|
|
surfaceCreateInfo.connection = XGetXCBConnection(info.fDisplay);
|
|
|
|
surfaceCreateInfo.window = info.fWindow;
|
|
|
|
|
|
|
|
VkResult res = createXcbSurfaceKHR(instance, &surfaceCreateInfo, nullptr, &surface);
|
|
|
|
if (VK_SUCCESS != res) {
|
|
|
|
return VK_NULL_HANDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return surface;
|
|
|
|
};
|
|
|
|
|
2017-11-10 15:03:05 +00:00
|
|
|
auto canPresent = [&info, instProc](VkInstance instance, VkPhysicalDevice physDev,
|
2016-07-26 19:02:50 +00:00
|
|
|
uint32_t queueFamilyIndex) {
|
|
|
|
static PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR
|
|
|
|
getPhysicalDeviceXcbPresentationSupportKHR = nullptr;
|
|
|
|
if (!getPhysicalDeviceXcbPresentationSupportKHR) {
|
|
|
|
getPhysicalDeviceXcbPresentationSupportKHR =
|
|
|
|
(PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR)
|
2017-11-10 15:03:05 +00:00
|
|
|
instProc(instance, "vkGetPhysicalDeviceXcbPresentationSupportKHR");
|
2016-07-26 19:02:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Display* display = info.fDisplay;
|
|
|
|
VisualID visualID = info.fVisualInfo->visualid;
|
|
|
|
VkBool32 check = getPhysicalDeviceXcbPresentationSupportKHR(physDev,
|
|
|
|
queueFamilyIndex,
|
|
|
|
XGetXCBConnection(display),
|
|
|
|
visualID);
|
|
|
|
return (VK_FALSE != check);
|
|
|
|
};
|
2019-08-01 20:21:49 +00:00
|
|
|
std::unique_ptr<WindowContext> ctx(
|
2022-01-14 16:30:38 +00:00
|
|
|
new VulkanWindowContext(displayParams, createVkSurface, canPresent, instProc));
|
2019-08-01 20:21:49 +00:00
|
|
|
if (!ctx->isValid()) {
|
2016-07-26 19:02:50 +00:00
|
|
|
return nullptr;
|
2016-05-23 20:13:36 +00:00
|
|
|
}
|
2019-08-01 20:21:49 +00:00
|
|
|
return ctx;
|
2016-05-23 20:13:36 +00:00
|
|
|
}
|
|
|
|
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace window_context_factory
|
2016-05-23 20:13:36 +00:00
|
|
|
|
2016-07-26 19:02:50 +00:00
|
|
|
} // namespace sk_app
|