1
0
Fork 0
forked from wry/wry

rect: safer construction

This commit is contained in:
Stipe Kotarac 2025-12-29 10:42:17 +01:00 committed by Julian Orth
parent 411af0ea18
commit a1dfc473a2
33 changed files with 245 additions and 159 deletions

View file

@ -102,7 +102,12 @@ impl VulkanShmImage {
data.data_copied.set(true);
data.buffer.set(Some(buffer.clone()));
if img.contents_are_undefined.get() {
damage = Region::new(Rect::new_sized(0, 0, img.width as _, img.height as _).unwrap());
damage = Region::new(Rect::new_sized_saturating(
0,
0,
img.width as _,
img.height as _,
));
}
self.calculate_copies(img, data, damage, buffer.offset);
self.async_release_from_gfx_queue(img, data, TransferType::Upload)?;
@ -186,7 +191,12 @@ impl VulkanShmImage {
if tt == TransferType::Download {
return Err(VulkanError::UndefinedContents);
}
damage = Region::new(Rect::new_sized(0, 0, img.width as _, img.height as _).unwrap());
damage = Region::new(Rect::new_sized_saturating(
0,
0,
img.width as _,
img.height as _,
));
}
let copies = &mut *self.calculate_copies(img, data, damage, 0);
@ -471,15 +481,12 @@ impl VulkanShmImage {
job.work.bpp = img.format.bpp as _;
job.work.rects.clear();
for copy in copies {
job.work.rects.push(
Rect::new_sized(
copy.image_offset.x as _,
copy.image_offset.y as _,
copy.image_extent.width as _,
copy.image_extent.height as _,
)
.unwrap(),
);
job.work.rects.push(Rect::new_sized_saturating(
copy.image_offset.x as _,
copy.image_offset.y as _,
copy.image_extent.width as _,
copy.image_extent.height as _,
));
}
pending = data.cpu.submit(job);
}