• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use crate::prelude::*;
2 use crate::vk;
3 use crate::RawPtr;
4 use crate::{EntryCustom, Instance};
5 use std::ffi::CStr;
6 use std::mem;
7 
8 #[derive(Clone)]
9 pub struct Surface {
10     handle: vk::Instance,
11     surface_fn: vk::KhrSurfaceFn,
12 }
13 
14 impl Surface {
new<L>(entry: &EntryCustom<L>, instance: &Instance) -> Self15     pub fn new<L>(entry: &EntryCustom<L>, instance: &Instance) -> Self {
16         let surface_fn = vk::KhrSurfaceFn::load(|name| unsafe {
17             mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr()))
18         });
19         Self {
20             handle: instance.handle(),
21             surface_fn,
22         }
23     }
24 
name() -> &'static CStr25     pub fn name() -> &'static CStr {
26         vk::KhrSurfaceFn::name()
27     }
28 
29     #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceSurfaceSupportKHR.html>"]
get_physical_device_surface_support( &self, physical_device: vk::PhysicalDevice, queue_family_index: u32, surface: vk::SurfaceKHR, ) -> VkResult<bool>30     pub unsafe fn get_physical_device_surface_support(
31         &self,
32         physical_device: vk::PhysicalDevice,
33         queue_family_index: u32,
34         surface: vk::SurfaceKHR,
35     ) -> VkResult<bool> {
36         let mut b = 0;
37         self.surface_fn
38             .get_physical_device_surface_support_khr(
39                 physical_device,
40                 queue_family_index,
41                 surface,
42                 &mut b,
43             )
44             .result_with_success(b > 0)
45     }
46 
47     #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceSurfacePresentModesKHR.html>"]
get_physical_device_surface_present_modes( &self, physical_device: vk::PhysicalDevice, surface: vk::SurfaceKHR, ) -> VkResult<Vec<vk::PresentModeKHR>>48     pub unsafe fn get_physical_device_surface_present_modes(
49         &self,
50         physical_device: vk::PhysicalDevice,
51         surface: vk::SurfaceKHR,
52     ) -> VkResult<Vec<vk::PresentModeKHR>> {
53         read_into_uninitialized_vector(|count, data| {
54             self.surface_fn
55                 .get_physical_device_surface_present_modes_khr(
56                     physical_device,
57                     surface,
58                     count,
59                     data,
60                 )
61         })
62     }
63 
64     #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceSurfaceCapabilitiesKHR.html>"]
get_physical_device_surface_capabilities( &self, physical_device: vk::PhysicalDevice, surface: vk::SurfaceKHR, ) -> VkResult<vk::SurfaceCapabilitiesKHR>65     pub unsafe fn get_physical_device_surface_capabilities(
66         &self,
67         physical_device: vk::PhysicalDevice,
68         surface: vk::SurfaceKHR,
69     ) -> VkResult<vk::SurfaceCapabilitiesKHR> {
70         let mut surface_capabilities = mem::zeroed();
71         self.surface_fn
72             .get_physical_device_surface_capabilities_khr(
73                 physical_device,
74                 surface,
75                 &mut surface_capabilities,
76             )
77             .result_with_success(surface_capabilities)
78     }
79 
80     #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceSurfaceFormatsKHR.html>"]
get_physical_device_surface_formats( &self, physical_device: vk::PhysicalDevice, surface: vk::SurfaceKHR, ) -> VkResult<Vec<vk::SurfaceFormatKHR>>81     pub unsafe fn get_physical_device_surface_formats(
82         &self,
83         physical_device: vk::PhysicalDevice,
84         surface: vk::SurfaceKHR,
85     ) -> VkResult<Vec<vk::SurfaceFormatKHR>> {
86         read_into_uninitialized_vector(|count, data| {
87             self.surface_fn.get_physical_device_surface_formats_khr(
88                 physical_device,
89                 surface,
90                 count,
91                 data,
92             )
93         })
94     }
95 
96     #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkDestroySurfaceKHR.html>"]
destroy_surface( &self, surface: vk::SurfaceKHR, allocation_callbacks: Option<&vk::AllocationCallbacks>, )97     pub unsafe fn destroy_surface(
98         &self,
99         surface: vk::SurfaceKHR,
100         allocation_callbacks: Option<&vk::AllocationCallbacks>,
101     ) {
102         self.surface_fn.destroy_surface_khr(
103             self.handle,
104             surface,
105             allocation_callbacks.as_raw_ptr(),
106         );
107     }
108 
fp(&self) -> &vk::KhrSurfaceFn109     pub fn fp(&self) -> &vk::KhrSurfaceFn {
110         &self.surface_fn
111     }
112 
instance(&self) -> vk::Instance113     pub fn instance(&self) -> vk::Instance {
114         self.handle
115     }
116 }
117