diff --git a/src/buffer_object.rs b/src/buffer_object.rs index d123ec4..1995500 100644 --- a/src/buffer_object.rs +++ b/src/buffer_object.rs @@ -1,6 +1,6 @@ #![allow(clippy::unnecessary_cast)] -use crate::{AsRaw, Device, Format, Modifier, Ptr}; +use crate::{AsRaw, Format, Modifier, Ptr}; #[cfg(feature = "drm-support")] use drm::buffer::{Buffer as DrmBuffer, Handle, PlanarBuffer as DrmPlanarBuffer}; @@ -289,24 +289,11 @@ impl BufferObject { /// Map a region of a GBM buffer object for cpu access /// /// This function maps a region of a GBM bo for cpu read access. - pub fn map<'a, D, F, S>( - &'a self, - device: &Device, - x: u32, - y: u32, - width: u32, - height: u32, - f: F, - ) -> Result, WrongDeviceError> + pub fn map<'a, D, F, S>(&'a self, x: u32, y: u32, width: u32, height: u32, f: F) -> IoResult where D: AsFd + 'static, F: FnOnce(&MappedBufferObject<'a, T>) -> S, { - if *self._device != device.as_raw_mut() { - // not matching - return Err(WrongDeviceError); - } - unsafe { let mut data: *mut ::libc::c_void = ptr::null_mut(); let mut stride = 0; @@ -322,9 +309,9 @@ impl BufferObject { ); if ptr.is_null() { - Ok(Err(IoError::last_os_error())) + Err(IoError::last_os_error()) } else { - Ok(Ok(f(&MappedBufferObject { + Ok(f(&MappedBufferObject { bo: BORef::Ref(self), buffer: slice::from_raw_parts_mut(ptr as *mut _, (height * stride) as usize), data, @@ -333,7 +320,7 @@ impl BufferObject { width, x, y, - }))) + })) } } } @@ -343,22 +330,16 @@ impl BufferObject { /// This function maps a region of a GBM bo for cpu read/write access. pub fn map_mut<'a, D, F, S>( &'a mut self, - device: &Device, x: u32, y: u32, width: u32, height: u32, f: F, - ) -> Result, WrongDeviceError> + ) -> IoResult where D: AsFd + 'static, F: FnOnce(&mut MappedBufferObject<'a, T>) -> S, { - if *self._device != device.as_raw_mut() { - // not matching - return Err(WrongDeviceError); - } - unsafe { let mut data: *mut ::libc::c_void = ptr::null_mut(); let mut stride = 0; @@ -374,9 +355,9 @@ impl BufferObject { ); if ptr.is_null() { - Ok(Err(IoError::last_os_error())) + Err(IoError::last_os_error()) } else { - Ok(Ok(f(&mut MappedBufferObject { + Ok(f(&mut MappedBufferObject { bo: BORef::Mut(self), buffer: slice::from_raw_parts_mut(ptr as *mut _, (height * stride) as usize), data, @@ -385,7 +366,7 @@ impl BufferObject { width, x, y, - }))) + })) } } } @@ -604,21 +585,6 @@ impl DrmPlanarBuffer for BufferObject { } } -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -/// Thrown when the GBM device does not belong to the buffer object -pub struct WrongDeviceError; - -impl fmt::Display for WrongDeviceError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!( - f, - "The gbm device specified is not the one this buffer object belongs to" - ) - } -} - -impl error::Error for WrongDeviceError {} - /// Thrown when the fd is invalid #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct InvalidFdError;