use std::alloc::{Layout, LayoutError};
pub struct ScratchBuffer {
ptr: *mut u8,
layout: Layout,
}
impl ScratchBuffer {
pub fn new(size: usize) -> Result<Self, LayoutError> {
if size == 0 {
panic!("non zero size required");
}
let layout = Layout::from_size_align(size, 8)?;
let ptr = unsafe { std::alloc::alloc(layout) };
Ok(Self { ptr, layout })
}
pub unsafe fn ptr(&mut self) -> *mut u8 {
self.ptr
}
pub fn len(&self) -> usize {
self.layout.size()
}
}
unsafe impl Send for ScratchBuffer {}
unsafe impl Sync for ScratchBuffer {}
impl Drop for ScratchBuffer {
fn drop(&mut self) {
unsafe {
std::alloc::dealloc(self.ptr, self.layout);
}
}
}
pub struct Interface {
pub interface: fsr_sys::Interface,
pub scratch_buffer: ScratchBuffer,
}
unsafe impl Send for Interface {}
unsafe impl Sync for Interface {}