1 use crate::prelude::*;
2 use crate::vk;
3 use crate::RawPtr;
4 use crate::{Device, Instance};
5 use std::ffi::CStr;
6 use std::mem;
7 
8 #[derive(Clone)]
9 pub struct DisplaySwapchain {
10     handle: vk::Device,
11     fp: vk::KhrDisplaySwapchainFn,
12 }
13 
14 impl DisplaySwapchain {
new(instance: &Instance, device: &Device) -> Self15     pub fn new(instance: &Instance, device: &Device) -> Self {
16         let handle = device.handle();
17         let fp = vk::KhrDisplaySwapchainFn::load(|name| unsafe {
18             mem::transmute(instance.get_device_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/vkCreateSharedSwapchainsKHR.html>
24     #[inline]
create_shared_swapchains( &self, create_infos: &[vk::SwapchainCreateInfoKHR], allocation_callbacks: Option<&vk::AllocationCallbacks>, ) -> VkResult<Vec<vk::SwapchainKHR>>25     pub unsafe fn create_shared_swapchains(
26         &self,
27         create_infos: &[vk::SwapchainCreateInfoKHR],
28         allocation_callbacks: Option<&vk::AllocationCallbacks>,
29     ) -> VkResult<Vec<vk::SwapchainKHR>> {
30         let mut swapchains = Vec::with_capacity(create_infos.len());
31         (self.fp.create_shared_swapchains_khr)(
32             self.handle,
33             create_infos.len() as u32,
34             create_infos.as_ptr(),
35             allocation_callbacks.as_raw_ptr(),
36             swapchains.as_mut_ptr(),
37         )
38         .result()?;
39         swapchains.set_len(create_infos.len());
40         Ok(swapchains)
41     }
42 
43     #[inline]
name() -> &'static CStr44     pub const fn name() -> &'static CStr {
45         vk::KhrDisplaySwapchainFn::name()
46     }
47 
48     #[inline]
fp(&self) -> &vk::KhrDisplaySwapchainFn49     pub fn fp(&self) -> &vk::KhrDisplaySwapchainFn {
50         &self.fp
51     }
52 
53     #[inline]
device(&self) -> vk::Device54     pub fn device(&self) -> vk::Device {
55         self.handle
56     }
57 }
58