use std::{ffi::c_void, ptr::NonNull};
use crate::{bind, geo::Size, window::Window};
pub struct MetalView<'window> {
ptr: NonNull<c_void>,
window: &'window Window<'window>,
}
impl<'window> MetalView<'window> {
#[must_use]
pub fn new(window: &'window Window<'window>) -> Self {
let ptr = unsafe { bind::SDL_Metal_CreateView(window.as_ptr()) };
Self {
ptr: NonNull::new(ptr).unwrap(),
window,
}
}
#[must_use]
pub fn metal_layer(&self) -> *mut c_void {
unsafe { bind::SDL_Metal_GetLayer(self.ptr.as_ptr()) }
}
pub fn drawable_size(&self) -> Size {
let mut width = 0;
let mut height = 0;
unsafe { bind::SDL_Metal_GetDrawableSize(self.window.as_ptr(), &mut width, &mut height) }
Size {
width: width as _,
height: height as _,
}
}
}
impl Drop for MetalView<'_> {
fn drop(&mut self) {
unsafe { bind::SDL_Metal_DestroyView(self.ptr.as_ptr()) }
}
}