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 swapchain_fn: vk::KhrDisplaySwapchainFn, 12 } 13 14 impl DisplaySwapchain { new(instance: &Instance, device: &Device) -> Self15 pub fn new(instance: &Instance, device: &Device) -> Self { 16 let swapchain_fn = vk::KhrDisplaySwapchainFn::load(|name| unsafe { 17 mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) 18 }); 19 Self { 20 handle: device.handle(), 21 swapchain_fn, 22 } 23 } 24 name() -> &'static CStr25 pub fn name() -> &'static CStr { 26 vk::KhrDisplaySwapchainFn::name() 27 } 28 29 #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkCreateSharedSwapchainsKHR.html>"] create_shared_swapchains( &self, create_infos: &[vk::SwapchainCreateInfoKHR], allocation_callbacks: Option<&vk::AllocationCallbacks>, ) -> VkResult<Vec<vk::SwapchainKHR>>30 pub unsafe fn create_shared_swapchains( 31 &self, 32 create_infos: &[vk::SwapchainCreateInfoKHR], 33 allocation_callbacks: Option<&vk::AllocationCallbacks>, 34 ) -> VkResult<Vec<vk::SwapchainKHR>> { 35 let mut swapchains = Vec::with_capacity(create_infos.len()); 36 let err_code = self.swapchain_fn.create_shared_swapchains_khr( 37 self.handle, 38 create_infos.len() as u32, 39 create_infos.as_ptr(), 40 allocation_callbacks.as_raw_ptr(), 41 swapchains.as_mut_ptr(), 42 ); 43 swapchains.set_len(create_infos.len()); 44 err_code.result_with_success(swapchains) 45 } 46 fp(&self) -> &vk::KhrDisplaySwapchainFn47 pub fn fp(&self) -> &vk::KhrDisplaySwapchainFn { 48 &self.swapchain_fn 49 } 50 device(&self) -> vk::Device51 pub fn device(&self) -> vk::Device { 52 self.handle 53 } 54 } 55