Skip to content

Commit

Permalink
Document SurfaceApi better (vulkano-rs#2340)
Browse files Browse the repository at this point in the history
* Document `SurfaceApi` better

* Add TryFrom<RawWindowHandle> for SurfaceApi

* Rename Qnx > QnxScreen to match the `from_qnx_screen` constructor
  • Loading branch information
Rua authored and hakolao committed Feb 20, 2024
1 parent 171461c commit a04402c
Showing 1 changed file with 77 additions and 6 deletions.
83 changes: 77 additions & 6 deletions vulkano/src/swapchain/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ impl Surface {
(RawWindowHandle::Xlib(window), RawDisplayHandle::Xlib(display)) => {
Self::from_xlib(instance, display.display, window.window, None)
}
_ => unimplemented!(),
_ => unimplemented!(
"the window was created with a windowing API that is not supported \
by Vulkan/Vulkano"
),
}
}

Expand All @@ -139,7 +142,7 @@ impl Surface {
/// # Safety
///
/// - `handle` must be a valid Vulkan object handle created from `instance`.
/// - `handle` must have been created from `api`.
/// - `handle` must have been created using the function specified by `api`.
/// - The window object that `handle` was created from must outlive the created `Surface`.
/// The `object` parameter can be used to ensure this.
pub unsafe fn from_handle(
Expand Down Expand Up @@ -998,7 +1001,7 @@ impl Surface {
Ok(Arc::new(Self::from_handle(
instance,
handle,
SurfaceApi::Qnx,
SurfaceApi::QnxScreen,
object,
)))
}
Expand Down Expand Up @@ -1676,29 +1679,97 @@ impl DisplaySurfaceCreateInfo {
}
}

/// The windowing API that was used to construct a surface.
/// The windowing API function that was used to construct a surface.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum SurfaceApi {
/// The surface was constructed using [`Surface::headless`] or the
/// `vkCreateHeadlessSurfaceEXT` Vulkan API function.
Headless,

/// The surface was constructed using [`Surface::from_display_plane`] or the
/// `vkCreateDisplayPlaneSurfaceKHR` Vulkan API function.
DisplayPlane,

// Alphabetical order
/*
Alphabetical order
*/
/// The surface was constructed using [`Surface::from_android`] or the
/// `vkCreateAndroidSurfaceKHR` Vulkan API function.
Android,

/// The surface was constructed using [`Surface::from_directfb`] or the
/// `vkCreateDirectFBSurfaceEXT` Vulkan API function.
DirectFB,

/// The surface was constructed using [`Surface::from_fuchsia_image_pipe`] or the
/// `vkCreateImagePipeSurfaceFUCHSIA` Vulkan API function.
FuchsiaImagePipe,

/// The surface was constructed using [`Surface::from_ggp_stream_descriptor`] or the
/// `vkCreateStreamDescriptorSurfaceGGP` Vulkan API function.
GgpStreamDescriptor,

/// The surface was constructed using [`Surface::from_ios`] or the
/// `vkCreateIOSSurfaceMVK` Vulkan API function.
Ios,

/// The surface was constructed using [`Surface::from_mac_os`] or the
/// `vkCreateMacOSSurfaceMVK` Vulkan API function.
MacOs,

/// The surface was constructed using [`Surface::from_metal`] or the
/// `vkCreateMetalSurfaceEXT` Vulkan API function.
Metal,
Qnx,

/// The surface was constructed using [`Surface::from_qnx_screen`] or the
/// `vkCreateScreenSurfaceQNX` Vulkan API function.
QnxScreen,

/// The surface was constructed using [`Surface::from_vi`] or the
/// `vkCreateViSurfaceNN` Vulkan API function.
Vi,

/// The surface was constructed using [`Surface::from_wayland`] or the
/// `vkCreateWaylandSurfaceKHR` Vulkan API function.
Wayland,

/// The surface was constructed using [`Surface::from_win32`] or the
/// `vkCreateWin32SurfaceKHR` Vulkan API function.
Win32,

/// The surface was constructed using [`Surface::from_xcb`] or the
/// `vkCreateXcbSurfaceKHR` Vulkan API function.
Xcb,

/// The surface was constructed using [`Surface::from_xlib`] or the
/// `vkCreateXlibSurfaceKHR` Vulkan API function.
Xlib,
}

impl TryFrom<RawWindowHandle> for SurfaceApi {
type Error = ();

fn try_from(handle: RawWindowHandle) -> Result<Self, Self::Error> {
match handle {
RawWindowHandle::UiKit(_) => Ok(SurfaceApi::Ios),
RawWindowHandle::AppKit(_) => Ok(SurfaceApi::MacOs),
RawWindowHandle::Orbital(_) => Err(()),
RawWindowHandle::Xlib(_) => Ok(SurfaceApi::Xlib),
RawWindowHandle::Xcb(_) => Ok(SurfaceApi::Xcb),
RawWindowHandle::Wayland(_) => Ok(SurfaceApi::Wayland),
RawWindowHandle::Drm(_) => Err(()),
RawWindowHandle::Gbm(_) => Err(()),
RawWindowHandle::Win32(_) => Ok(SurfaceApi::Win32),
RawWindowHandle::WinRt(_) => Err(()),
RawWindowHandle::Web(_) => Err(()),
RawWindowHandle::AndroidNdk(_) => Ok(SurfaceApi::Android),
RawWindowHandle::Haiku(_) => Err(()),
_ => Err(()),
}
}
}

vulkan_enum! {
#[non_exhaustive]

Expand Down

0 comments on commit a04402c

Please # to comment.