ash/extensions/khr/
wayland_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 WaylandSurface {
10    handle: vk::Instance,
11    fp: vk::KhrWaylandSurfaceFn,
12}
13
14impl WaylandSurface {
15    pub fn new(entry: &Entry, instance: &Instance) -> Self {
16        let handle = instance.handle();
17        let fp = vk::KhrWaylandSurfaceFn::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/vkCreateWaylandSurfaceKHR.html>
24    pub unsafe fn create_wayland_surface(
25        &self,
26        create_info: &vk::WaylandSurfaceCreateInfoKHR,
27        allocation_callbacks: Option<&vk::AllocationCallbacks>,
28    ) -> VkResult<vk::SurfaceKHR> {
29        let mut surface = mem::zeroed();
30        (self.fp.create_wayland_surface_khr)(
31            self.handle,
32            create_info,
33            allocation_callbacks.as_raw_ptr(),
34            &mut surface,
35        )
36        .result_with_success(surface)
37    }
38
39    /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetPhysicalDeviceWaylandPresentationSupportKHR.html>
40    pub unsafe fn get_physical_device_wayland_presentation_support(
41        &self,
42        physical_device: vk::PhysicalDevice,
43        queue_family_index: u32,
44        wl_display: &mut vk::wl_display,
45    ) -> bool {
46        let b = (self.fp.get_physical_device_wayland_presentation_support_khr)(
47            physical_device,
48            queue_family_index,
49            wl_display,
50        );
51
52        b > 0
53    }
54
55    pub const fn name() -> &'static CStr {
56        vk::KhrWaylandSurfaceFn::name()
57    }
58
59    pub fn fp(&self) -> &vk::KhrWaylandSurfaceFn {
60        &self.fp
61    }
62
63    pub fn instance(&self) -> vk::Instance {
64        self.handle
65    }
66}