Using a RawWindowHandle with hal::create_surface for multi-backend compatibility

This commit is contained in:
TheArtist 2020-12-11 22:24:42 +02:00
parent 8ee8bb03bf
commit 84e95e539f
3 changed files with 21 additions and 3 deletions

1
Cargo.lock generated
View file

@ -753,6 +753,7 @@ dependencies = [
"lazy_static 1.4.0",
"log",
"parking_lot",
"raw-window-handle",
"renderdoc",
"smallvec",
"typed-arena",

View file

@ -27,6 +27,7 @@ parking_lot = "0.11"
smallvec = "1"
renderdoc = { version = "0.3", optional = true }
typed-arena = "2"
raw-window-handle = "0.3"
[dependencies.hal]
package = "gfx-hal"

View file

@ -4716,17 +4716,33 @@ pub unsafe extern "C" fn gfxCreateXcbSurfaceKHR(
) -> VkResult {
assert!(pAllocator.is_null());
let info = &*pCreateInfo;
#[cfg(all(feature = "gfx-backend-vulkan", target_os = "linux"))]
#[cfg(target_os = "linux")]
{
assert_eq!(info.flags, 0);
use raw_window_handle::{unix::XcbHandle, HasRawWindowHandle, RawWindowHandle};
struct HandleWrapper(XcbHandle);
unsafe impl HasRawWindowHandle for HandleWrapper {
fn raw_window_handle(&self) -> RawWindowHandle {
RawWindowHandle::Xcb(self.0)
}
}
let xcb_handle = XcbHandle {
window: info.window,
connection: info.connection,
..XcbHandle::empty()
};
*pSurface = Handle::new(
instance
.backend
.create_surface_from_xcb(info.connection, info.window),
.create_surface(&HandleWrapper(xcb_handle))
.unwrap(),
);
VkResult::VK_SUCCESS
}
#[cfg(not(all(feature = "gfx-backend-vulkan", target_os = "linux")))]
#[cfg(not(target_os = "linux"))]
{
let _ = (instance, info, pSurface);
unreachable!()