ash/extensions/khr/
xcb_surface.rs

1use crate::prelude::*;
2use crate::vk;
3use crate::RawPtr;
4use crate::{Entry, Instance};
5use std::ffi::CStr;
6use std::mem;
7
8#[derive(Clone)]
9pub struct XcbSurface {
10    handle: vk::Instance,
11    fp: vk::KhrXcbSurfaceFn,
12}
13
14impl XcbSurface {
15    pub fn new(entry: &Entry, instance: &Instance) -> Self {
16        let handle = instance.handle();
17        let fp = vk::KhrXcbSurfaceFn::load(|name| unsafe {
18            mem::transmute(entry.get_instance_proc_addr(handle, name.as_ptr()))
19        });
20        Self { handle, fp }
21    }
22
23    /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCreateXcbSurfaceKHR.html>
24    #[inline]
25    pub unsafe fn create_xcb_surface(
26        &self,
27        create_info: &vk::XcbSurfaceCreateInfoKHR,
28        allocation_callbacks: Option<&vk::AllocationCallbacks>,
29    ) -> VkResult<vk::SurfaceKHR> {
30        let mut surface = mem::zeroed();
31        (self.fp.create_xcb_surface_khr)(
32            self.handle,
33            create_info,
34            allocation_callbacks.as_raw_ptr(),
35            &mut surface,
36        )
37        .result_with_success(surface)
38    }
39
40    /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceXcbPresentationSupportKHR.html>
41    #[inline]
42    pub unsafe fn get_physical_device_xcb_presentation_support(
43        &self,
44        physical_device: vk::PhysicalDevice,
45        queue_family_index: u32,
46        connection: &mut vk::xcb_connection_t,
47        visual_id: vk::xcb_visualid_t,
48    ) -> bool {
49        let b = (self.fp.get_physical_device_xcb_presentation_support_khr)(
50            physical_device,
51            queue_family_index,
52            connection,
53            visual_id,
54        );
55
56        b > 0
57    }
58
59    #[inline]
60    pub const fn name() -> &'static CStr {
61        vk::KhrXcbSurfaceFn::name()
62    }
63
64    #[inline]
65    pub fn fp(&self) -> &vk::KhrXcbSurfaceFn {
66        &self.fp
67    }
68
69    #[inline]
70    pub fn instance(&self) -> vk::Instance {
71        self.handle
72    }
73}