From cfa525eee6340623fc27c0303a29a189453c5576 Mon Sep 17 00:00:00 2001 From: Benjamin Saunders Date: Tue, 4 Jul 2017 00:03:21 -0700 Subject: [PATCH] Cleanup --- src/compositor/mod.rs | 23 ++++++++++++++--------- src/lib.rs | 4 ++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/compositor/mod.rs b/src/compositor/mod.rs index 4041e50..5058bca 100644 --- a/src/compositor/mod.rs +++ b/src/compositor/mod.rs @@ -32,8 +32,9 @@ impl<'a> Compositor<'a> { temp.split(|&x| x == b' ').map(|x| CString::new(x.to_vec()).expect("extension name contained null byte")).collect() } - pub fn vulkan_device_extensions_required(&self, physical_device: *mut VkPhysicalDevice_T) -> Vec { - let temp = unsafe { + /// Safety: physical_device must be a valid VkPhysicalDevice + pub unsafe fn vulkan_device_extensions_required(&self, physical_device: *mut VkPhysicalDevice_T) -> Vec { + let temp = { let n = self.0.GetVulkanDeviceExtensionsRequired.unwrap()(physical_device, ptr::null_mut(), 0); let mut buffer: Vec = Vec::new(); buffer.resize(n as usize, mem::uninitialized()); @@ -69,7 +70,11 @@ impl<'a> Compositor<'a> { /// Display the supplied texture for the next frame. /// /// If `bounds` is None, the entire texture will be used. Lens distortion is handled by the OpenVR implementation. - pub fn submit(&self, eye: Eye, texture: &Texture, bounds: Option<&texture::Bounds>) -> Result<(), CompositorError> { + /// + /// # Safety + /// + /// The handles you supply must be valid and comply with the graphics API's synchronization requirements. + pub unsafe fn submit(&self, eye: Eye, texture: &Texture, bounds: Option<&texture::Bounds>) -> Result<(), CompositorError> { use self::texture::Handle::*; let flags = match texture.handle { Vulkan(_) => sys::EVRSubmitFlags_EVRSubmitFlags_Submit_Default, @@ -89,12 +94,11 @@ impl<'a> Compositor<'a> { }, eColorSpace: texture.color_space as sys::EColorSpace, }; - let e = unsafe { - self.0.Submit.unwrap()(eye as sys::EVREye, - &texture as *const _ as *mut _, - bounds.map(|x| x as *const _ as *mut texture::Bounds as *mut _).unwrap_or(ptr::null_mut()), - flags) - }; + let e = self.0.Submit.unwrap()( + eye as sys::EVREye, + &texture as *const _ as *mut _, + bounds.map(|x| x as *const _ as *mut texture::Bounds as *mut _).unwrap_or(ptr::null_mut()), + flags); if e == sys::EVRCompositorError_EVRCompositorError_VRCompositorError_None { Ok(()) } else { @@ -159,6 +163,7 @@ impl error::Error for CompositorError { SHARED_TEXTURES_NOT_SUPPORTED => "SHARED_TEXTURES_NOT_SUPPORTED", INDEX_OUT_OF_RANGE => "INDEX_OUT_OF_RANGE", ALREADY_SUBMITTED => "ALREADY_SUBMITTED", + INVALID_BOUNDS => "INVALID_BOUNDS", _ => "UNKNOWN", } } diff --git a/src/lib.rs b/src/lib.rs index 873132b..4e7c967 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,8 +8,8 @@ use openvr_sys as sys; mod tracking; -mod system; -mod compositor; +pub mod system; +pub mod compositor; pub use tracking::*;