1 use crate::prelude::*;
2 use crate::vk;
3 use crate::RawPtr;
4 use crate::{Entry, Instance};
5 use std::ffi::CStr;
6 use std::mem;
7 
8 #[derive(Clone)]
9 pub struct WaylandSurface {
10     handle: vk::Instance,
11     fp: vk::KhrWaylandSurfaceFn,
12 }
13 
14 impl WaylandSurface {
new(entry: &Entry, instance: &Instance) -> Self15     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     #[inline]
create_wayland_surface( &self, create_info: &vk::WaylandSurfaceCreateInfoKHR, allocation_callbacks: Option<&vk::AllocationCallbacks>, ) -> VkResult<vk::SurfaceKHR>25     pub unsafe fn create_wayland_surface(
26         &self,
27         create_info: &vk::WaylandSurfaceCreateInfoKHR,
28         allocation_callbacks: Option<&vk::AllocationCallbacks>,
29     ) -> VkResult<vk::SurfaceKHR> {
30         let mut surface = mem::zeroed();
31         (self.fp.create_wayland_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/vkGetPhysicalDeviceWaylandPresentationSupportKHR.html>
41     #[inline]
get_physical_device_wayland_presentation_support( &self, physical_device: vk::PhysicalDevice, queue_family_index: u32, wl_display: &mut vk::wl_display, ) -> bool42     pub unsafe fn get_physical_device_wayland_presentation_support(
43         &self,
44         physical_device: vk::PhysicalDevice,
45         queue_family_index: u32,
46         wl_display: &mut vk::wl_display,
47     ) -> bool {
48         let b = (self.fp.get_physical_device_wayland_presentation_support_khr)(
49             physical_device,
50             queue_family_index,
51             wl_display,
52         );
53 
54         b > 0
55     }
56 
57     #[inline]
name() -> &'static CStr58     pub const fn name() -> &'static CStr {
59         vk::KhrWaylandSurfaceFn::name()
60     }
61 
62     #[inline]
fp(&self) -> &vk::KhrWaylandSurfaceFn63     pub fn fp(&self) -> &vk::KhrWaylandSurfaceFn {
64         &self.fp
65     }
66 
67     #[inline]
instance(&self) -> vk::Instance68     pub fn instance(&self) -> vk::Instance {
69         self.handle
70     }
71 }
72