skia2/tools/sk_app/unix/VulkanWindowContext_unix.cpp
Greg Daniel 54bfb18dad Privately include our version of vulkan header file in all our src files.
This should allow clients to include Skia and their vulkan files in any
order. However, it does require that when clients are building their
files that include skia with vulkan, they must have vulkan/vulkan_core.h
on their include path somewhere.

Bug: skia:
Change-Id: I969db396c92127be7c8df754926d175f38b8aafa
Reviewed-on: https://skia-review.googlesource.com/c/172147
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2018-11-26 15:15:44 +00:00

88 lines
3.0 KiB
C++

/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "vk/GrVkVulkan.h"
#include "vk/GrVkInterface.h"
#include "vk/GrVkUtil.h"
#include "vk/VkTestUtils.h"
#include "WindowContextFactory_unix.h"
#include "../VulkanWindowContext.h"
#include <X11/Xlib-xcb.h>
namespace sk_app {
namespace window_context_factory {
WindowContext* NewVulkanForXlib(const XlibWindowInfo& info, const DisplayParams& displayParams) {
PFN_vkGetInstanceProcAddr instProc;
PFN_vkGetDeviceProcAddr devProc;
if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc, &devProc)) {
return nullptr;
}
auto createVkSurface = [&info, instProc](VkInstance instance) -> VkSurfaceKHR {
static PFN_vkCreateXcbSurfaceKHR createXcbSurfaceKHR = nullptr;
if (!createXcbSurfaceKHR) {
createXcbSurfaceKHR =
(PFN_vkCreateXcbSurfaceKHR) instProc(instance, "vkCreateXcbSurfaceKHR");
}
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;
};
auto canPresent = [&info, instProc](VkInstance instance, VkPhysicalDevice physDev,
uint32_t queueFamilyIndex) {
static PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR
getPhysicalDeviceXcbPresentationSupportKHR = nullptr;
if (!getPhysicalDeviceXcbPresentationSupportKHR) {
getPhysicalDeviceXcbPresentationSupportKHR =
(PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR)
instProc(instance, "vkGetPhysicalDeviceXcbPresentationSupportKHR");
}
Display* display = info.fDisplay;
VisualID visualID = info.fVisualInfo->visualid;
VkBool32 check = getPhysicalDeviceXcbPresentationSupportKHR(physDev,
queueFamilyIndex,
XGetXCBConnection(display),
visualID);
return (VK_FALSE != check);
};
WindowContext* context = new VulkanWindowContext(displayParams, createVkSurface, canPresent,
instProc, devProc);
if (!context->isValid()) {
delete context;
return nullptr;
}
return context;
}
} // namespace VulkanWindowContextFactory
} // namespace sk_app