ash/extensions/khr/
xlib_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 XlibSurface {
10    handle: vk::Instance,
11    fp: vk::KhrXlibSurfaceFn,
12}
13
14impl XlibSurface {
15    pub fn new(entry: &Entry, instance: &Instance) -> Self {
16        let handle = instance.handle();
17        let fp = vk::KhrXlibSurfaceFn::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/vkCreateXlibSurfaceKHR.html>
24    #[inline]
25    pub unsafe fn create_xlib_surface(
26        &self,
27        create_info: &vk::XlibSurfaceCreateInfoKHR,
28        allocation_callbacks: Option<&vk::AllocationCallbacks>,
29    ) -> VkResult<vk::SurfaceKHR> {
30        let mut surface = mem::zeroed();
31        (self.fp.create_xlib_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/vkGetPhysicalDeviceXlibPresentationSupportKHR.html>
41    #[inline]
42    pub unsafe fn get_physical_device_xlib_presentation_support(
43        &self,
44        physical_device: vk::PhysicalDevice,
45        queue_family_index: u32,
46        display: &mut vk::Display,
47        visual_id: vk::VisualID,
48    ) -> bool {
49        let b = (self.fp.get_physical_device_xlib_presentation_support_khr)(
50            physical_device,
51            queue_family_index,
52            display,
53            visual_id,
54        );
55
56        b > 0
57    }
58
59    #[inline]
60    pub const fn name() -> &'static CStr {
61        vk::KhrXlibSurfaceFn::name()
62    }
63
64    #[inline]
65    pub fn fp(&self) -> &vk::KhrXlibSurfaceFn {
66        &self.fp
67    }
68
69    #[inline]
70    pub fn instance(&self) -> vk::Instance {
71        self.handle
72    }
73}