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.
|
|
|
|
*/
|
|
|
|
|
2018-11-20 22:12:36 +00:00
|
|
|
#include "vk/GrVkVulkan.h"
|
2016-05-23 20:13:36 +00:00
|
|
|
|
|
|
|
#include "vk/GrVkInterface.h"
|
|
|
|
#include "vk/GrVkUtil.h"
|
|
|
|
|
2017-11-10 15:03:05 +00:00
|
|
|
#include "vk/VkTestUtils.h"
|
|
|
|
|
2016-07-26 19:02:50 +00:00
|
|
|
#include "WindowContextFactory_unix.h"
|
|
|
|
#include "../VulkanWindowContext.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 {
|
|
|
|
|
|
|
|
WindowContext* NewVulkanForXlib(const XlibWindowInfo& info, const DisplayParams& displayParams) {
|
2017-11-10 15:03:05 +00:00
|
|
|
PFN_vkGetInstanceProcAddr instProc;
|
|
|
|
PFN_vkGetDeviceProcAddr devProc;
|
|
|
|
if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc, &devProc)) {
|
|
|
|
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);
|
|
|
|
};
|
2017-11-10 15:03:05 +00:00
|
|
|
WindowContext* context = new VulkanWindowContext(displayParams, createVkSurface, canPresent,
|
|
|
|
instProc, devProc);
|
2016-07-26 19:02:50 +00:00
|
|
|
if (!context->isValid()) {
|
|
|
|
delete context;
|
|
|
|
return nullptr;
|
2016-05-23 20:13:36 +00:00
|
|
|
}
|
2016-07-26 19:02:50 +00:00
|
|
|
return context;
|
2016-05-23 20:13:36 +00:00
|
|
|
}
|
|
|
|
|
2016-07-26 19:02:50 +00:00
|
|
|
} // namespace VulkanWindowContextFactory
|
2016-05-23 20:13:36 +00:00
|
|
|
|
2016-07-26 19:02:50 +00:00
|
|
|
} // namespace sk_app
|