raw-window-handle 0.6

This commit is contained in:
Alex Janka 2024-02-08 15:07:56 +11:00
parent 66c0cf42a0
commit 55628b4023
2 changed files with 26 additions and 13 deletions

View file

@ -16,14 +16,16 @@ rust-version = "1.64.0"
[dependencies] [dependencies]
ash = { path = "../ash", version = "0.37", default-features = false } ash = { path = "../ash", version = "0.37", default-features = false }
raw-window-handle = "0.5" raw-window-handle = "0.6"
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies] [target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
raw-window-metal = "0.3" raw-window-metal = "0.4"
[dev-dependencies] [dev-dependencies]
winit = "0.27.1" winit = "0.27.1"
ash = { path = "../ash", version = "0.37", default-features = false, features = ["linked"] } ash = { path = "../ash", version = "0.37", default-features = false, features = [
"linked",
] }
[[example]] [[example]]
name = "winit" name = "winit"

View file

@ -1,6 +1,6 @@
#![warn(trivial_casts, trivial_numeric_casts)] #![warn(trivial_casts, trivial_numeric_casts)]
use std::os::raw::c_char; use std::{ffi::c_void, os::raw::c_char};
use ash::{ use ash::{
extensions::{ext, khr}, extensions::{ext, khr},
@ -42,23 +42,29 @@ pub unsafe fn create_surface(
match (display_handle, window_handle) { match (display_handle, window_handle) {
(RawDisplayHandle::Windows(_), RawWindowHandle::Win32(window)) => { (RawDisplayHandle::Windows(_), RawWindowHandle::Win32(window)) => {
let surface_desc = vk::Win32SurfaceCreateInfoKHR::builder() let surface_desc = vk::Win32SurfaceCreateInfoKHR::builder()
.hinstance(window.hinstance) .hinstance(window.hinstance.ok_or(vk::Result::ERROR_UNKNOWN)?.get() as *mut c_void)
.hwnd(window.hwnd); .hwnd(window.hwnd.get() as *mut c_void);
let surface_fn = khr::Win32Surface::new(entry, instance); let surface_fn = khr::Win32Surface::new(entry, instance);
surface_fn.create_win32_surface(&surface_desc, allocation_callbacks) surface_fn.create_win32_surface(&surface_desc, allocation_callbacks)
} }
(RawDisplayHandle::Wayland(display), RawWindowHandle::Wayland(window)) => { (RawDisplayHandle::Wayland(display), RawWindowHandle::Wayland(window)) => {
let surface_desc = vk::WaylandSurfaceCreateInfoKHR::builder() let surface_desc = vk::WaylandSurfaceCreateInfoKHR::builder()
.display(display.display) .display(display.display.as_ptr())
.surface(window.surface); .surface(window.surface.as_ptr());
let surface_fn = khr::WaylandSurface::new(entry, instance); let surface_fn = khr::WaylandSurface::new(entry, instance);
surface_fn.create_wayland_surface(&surface_desc, allocation_callbacks) surface_fn.create_wayland_surface(&surface_desc, allocation_callbacks)
} }
(RawDisplayHandle::Xlib(display), RawWindowHandle::Xlib(window)) => { (RawDisplayHandle::Xlib(display), RawWindowHandle::Xlib(window)) => {
let surface_desc = vk::XlibSurfaceCreateInfoKHR::builder() let surface_desc = vk::XlibSurfaceCreateInfoKHR::builder()
.dpy(display.display.cast()) .dpy(
display
.display
.ok_or(vk::Result::ERROR_UNKNOWN)?
.as_ptr()
.cast(),
)
.window(window.window); .window(window.window);
let surface_fn = khr::XlibSurface::new(entry, instance); let surface_fn = khr::XlibSurface::new(entry, instance);
surface_fn.create_xlib_surface(&surface_desc, allocation_callbacks) surface_fn.create_xlib_surface(&surface_desc, allocation_callbacks)
@ -66,15 +72,20 @@ pub unsafe fn create_surface(
(RawDisplayHandle::Xcb(display), RawWindowHandle::Xcb(window)) => { (RawDisplayHandle::Xcb(display), RawWindowHandle::Xcb(window)) => {
let surface_desc = vk::XcbSurfaceCreateInfoKHR::builder() let surface_desc = vk::XcbSurfaceCreateInfoKHR::builder()
.connection(display.connection) .connection(
.window(window.window); display
.connection
.ok_or(vk::Result::ERROR_UNKNOWN)?
.as_ptr(),
)
.window(window.window.get());
let surface_fn = khr::XcbSurface::new(entry, instance); let surface_fn = khr::XcbSurface::new(entry, instance);
surface_fn.create_xcb_surface(&surface_desc, allocation_callbacks) surface_fn.create_xcb_surface(&surface_desc, allocation_callbacks)
} }
(RawDisplayHandle::Android(_), RawWindowHandle::AndroidNdk(window)) => { (RawDisplayHandle::Android(_), RawWindowHandle::AndroidNdk(window)) => {
let surface_desc = let surface_desc =
vk::AndroidSurfaceCreateInfoKHR::builder().window(window.a_native_window); vk::AndroidSurfaceCreateInfoKHR::builder().window(window.a_native_window.as_ptr());
let surface_fn = khr::AndroidSurface::new(entry, instance); let surface_fn = khr::AndroidSurface::new(entry, instance);
surface_fn.create_android_surface(&surface_desc, allocation_callbacks) surface_fn.create_android_surface(&surface_desc, allocation_callbacks)
} }
@ -85,7 +96,7 @@ pub unsafe fn create_surface(
let layer = match appkit::metal_layer_from_handle(window) { let layer = match appkit::metal_layer_from_handle(window) {
Layer::Existing(layer) | Layer::Allocated(layer) => layer.cast(), Layer::Existing(layer) | Layer::Allocated(layer) => layer.cast(),
Layer::None => return Err(vk::Result::ERROR_INITIALIZATION_FAILED), // Layer::None => return Err(vk::Result::ERROR_INITIALIZATION_FAILED),
}; };
let surface_desc = vk::MetalSurfaceCreateInfoEXT::builder().layer(&*layer); let surface_desc = vk::MetalSurfaceCreateInfoEXT::builder().layer(&*layer);