Commit acf5e9848529
tarball4 files changed+8-6
@@ -21,6 +21,8 @@ pub enum Error {
2121
DmabufUnsupported,2222
#[error("cannot import dmabuf with format {0:?}")]2323
UnsupportedDmabuf(smithay::backend::allocator::Format),24
+ #[error("staging memory is not mapped for the host")]25
+ StagingUnmapped,2426
#[error("cannot read the shm buffer")]2527
ShmAccess,2628
#[error("interrupted while waiting for a sync point")]@@ -592,7 +592,7 @@ impl VulkanRenderer {
592592
);593593
})?;594594
}595
- let mut data = staging.bytes()[..w as usize * h as usize * BYTES_PER_PIXEL].to_vec();595
+ let mut data = staging.bytes()?[..w as usize * h as usize * BYTES_PER_PIXEL].to_vec();596596
if swap {597597
for px in data.as_chunks_mut::<BYTES_PER_PIXEL>().0 {598598
px.swap(0, 2);@@ -112,7 +112,7 @@ pub(super) fn stage_rows<'a>(
112112
vk::BufferUsageFlags::TRANSFER_SRC,113113
MemoryLocation::CpuToGpu,114114
)?;115
- let dst = staging.bytes_mut();115
+ let dst = staging.bytes_mut()?;116116
for i in 0..h {117117
dst[i * line..(i + 1) * line].copy_from_slice(row(region.loc.y as usize + i));118118
}@@ -149,18 +149,18 @@ impl Staging {
149149
})150150
}151151
152
- pub fn bytes(&self) -> &[u8] {152
+ pub fn bytes(&self) -> Result<&[u8], Error> {153153
self.allocation154154
.as_ref()155155
.and_then(|a| a.mapped_slice())156
- .unwrap_or(&[])156
+ .ok_or(Error::StagingUnmapped)157157
}158158
159
- pub fn bytes_mut(&mut self) -> &mut [u8] {159
+ pub fn bytes_mut(&mut self) -> Result<&mut [u8], Error> {160160
self.allocation161161
.as_mut()162162
.and_then(|a| a.mapped_slice_mut())163
- .unwrap_or(&mut [])163
+ .ok_or(Error::StagingUnmapped)164164
}165165
}