Improve vulkano-win (#1386)

* Use winit's hinstance() function

* Require HasRawWindowHandle for the window and remove handle parameter

Co-authored-by: Antonino Siena <a.siena@gmx.de>
This commit is contained in:
Antonino Siena 2020-06-12 18:12:47 +02:00 committed by GitHub
parent c5dd6eda3e
commit b0c8eca283
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 8 deletions

View File

@ -9,24 +9,22 @@ use std::ffi::c_void;
use std::os::raw::c_ulong; use std::os::raw::c_ulong;
use std::sync::Arc; use std::sync::Arc;
use raw_window_handle::RawWindowHandle; use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
use vulkano::instance::Instance; use vulkano::instance::Instance;
use vulkano::swapchain::Surface; use vulkano::swapchain::Surface;
use vulkano::swapchain::SurfaceCreationError; use vulkano::swapchain::SurfaceCreationError;
/// Creates a vulkan surface from an os-dependent handle /// Creates a vulkan surface from a generic window
/// window here is a generic type for a Window which can be handed over /// which implements HasRawWindowHandle and thus can reveal the os-dependent handle
/// to ensure that it will be dropped after the surface
pub fn create_vk_surface_from_handle<W>( pub fn create_vk_surface_from_handle<W>(
window: W, window: W,
handle: RawWindowHandle,
instance: Arc<Instance>, instance: Arc<Instance>,
) -> Result<Arc<Surface<W>>, SurfaceCreationError> ) -> Result<Arc<Surface<W>>, SurfaceCreationError>
where where
W: Sized, W: HasRawWindowHandle,
{ {
unsafe { unsafe {
match handle { match window.raw_window_handle(){
#[cfg(target_os = "ios")] #[cfg(target_os = "ios")]
RawWindowHandle::IOS(h) => handle_to_surface(h.ui_view, instance, window), RawWindowHandle::IOS(h) => handle_to_surface(h.ui_view, instance, window),
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]

View File

@ -179,7 +179,7 @@ unsafe fn winit_to_surface<W: SafeBorrow<Window>>(
Surface::from_hwnd( Surface::from_hwnd(
instance, instance,
ptr::null() as *const (), // FIXME win.borrow().hinstance(),
win.borrow().hwnd(), win.borrow().hwnd(),
win, win,
) )