|
56 | 56 | #include <sys/utsname.h>
|
57 | 57 | #endif
|
58 | 58 |
|
59 |
| -#ifdef VK_USE_PLATFORM_XCB_KHR |
60 |
| -#include <QX11Info> |
61 |
| -#endif |
62 |
| - |
63 | 59 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
64 | 60 | #include <wayland-client.h>
|
65 | 61 | #endif
|
@@ -785,21 +781,62 @@ bool VulkanCapsViewer::initVulkan()
|
785 | 781 |
|
786 | 782 | #if defined(VK_USE_PLATFORM_WAYLAND_KHR)
|
787 | 783 | if (surface_extension == VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME) {
|
788 |
| - VkWaylandSurfaceCreateInfoKHR surfaceCreateInfo = {}; |
789 |
| - surfaceCreateInfo.pNext = nullptr; |
790 |
| - surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR; |
791 |
| - surfaceCreateInfo.display = wl_display_connect(NULL); |
792 |
| - surfaceCreateInfo.surface = nullptr; |
793 |
| - surfaceResult = vkCreateWaylandSurfaceKHR(vulkanContext.instance, &surfaceCreateInfo, nullptr, &vulkanContext.surface); |
| 784 | + static const wl_registry_listener WAYLAND_LISTENER { |
| 785 | + .global = [](void *data, wl_registry*, uint32_t name, const char* interface, uint32_t){ |
| 786 | + if (!strcmp(interface, wl_compositor_interface.name)) { |
| 787 | + *static_cast<uint32_t *>(data) = name; |
| 788 | + } |
| 789 | + }, |
| 790 | + .global_remove = [](void*, wl_registry*, uint32_t){ |
| 791 | + |
| 792 | + } |
| 793 | + }; |
| 794 | + |
| 795 | + const auto wayland_display = wl_display_connect(nullptr); |
| 796 | + const auto wayland_registry = wl_display_get_registry(wayland_display); |
| 797 | + uint32_t wayland_compositor_name = 0; |
| 798 | + wl_registry_add_listener(wayland_registry, &WAYLAND_LISTENER, &wayland_compositor_name); |
| 799 | + wl_display_roundtrip(wayland_display); |
| 800 | + |
| 801 | + if (wayland_compositor_name > 0) { |
| 802 | + const auto wayland_compositor = static_cast<wl_compositor *>( |
| 803 | + wl_registry_bind(wayland_registry, wayland_compositor_name, &wl_compositor_interface, 1) |
| 804 | + ); |
| 805 | + const auto wayland_surface = wl_compositor_create_surface(wayland_compositor); |
| 806 | + VkWaylandSurfaceCreateInfoKHR surfaceCreateInfo = {}; |
| 807 | + surfaceCreateInfo.pNext = nullptr; |
| 808 | + surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR; |
| 809 | + surfaceCreateInfo.display = wayland_display; |
| 810 | + surfaceCreateInfo.surface = wayland_surface; |
| 811 | + surfaceResult = vkCreateWaylandSurfaceKHR(vulkanContext.instance, &surfaceCreateInfo, nullptr, &vulkanContext.surface); |
| 812 | + } |
794 | 813 | }
|
795 | 814 | #endif
|
796 |
| - |
797 | 815 | #if defined(VK_USE_PLATFORM_XCB_KHR)
|
798 | 816 | if (surface_extension == VK_KHR_XCB_SURFACE_EXTENSION_NAME) {
|
| 817 | + int xcb_screen_idx; |
| 818 | + const auto xcb_connection = xcb_connect(nullptr, &xcb_screen_idx); |
| 819 | + const auto xcb_setup = xcb_get_setup(xcb_connection); |
| 820 | + auto xcb_screen = xcb_setup_roots_iterator(xcb_setup); |
| 821 | + for (int i = 0; i < xcb_screen_idx; ++i) { |
| 822 | + xcb_screen_next(&xcb_screen); |
| 823 | + } |
| 824 | + const auto xcb_window = xcb_generate_id(xcb_connection); |
| 825 | + xcb_create_window( |
| 826 | + xcb_connection, |
| 827 | + xcb_screen.data->root_depth, |
| 828 | + xcb_window, |
| 829 | + xcb_screen.data->root, |
| 830 | + 0, 0, |
| 831 | + 800, 600, 0, |
| 832 | + XCB_WINDOW_CLASS_INPUT_OUTPUT, |
| 833 | + xcb_screen.data->root_visual, |
| 834 | + 0, nullptr); |
| 835 | + |
799 | 836 | VkXcbSurfaceCreateInfoKHR surfaceCreateInfo = {};
|
800 | 837 | surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
|
801 |
| - surfaceCreateInfo.connection = QX11Info::connection(); |
802 |
| - surfaceCreateInfo.window = static_cast<xcb_window_t>(this->winId()); |
| 838 | + surfaceCreateInfo.connection = xcb_connection; |
| 839 | + surfaceCreateInfo.window = xcb_window; |
803 | 840 | surfaceResult = vkCreateXcbSurfaceKHR(vulkanContext.instance, &surfaceCreateInfo, nullptr, &vulkanContext.surface);
|
804 | 841 | }
|
805 | 842 | #endif
|
|
0 commit comments