1
0
Fork 0
forked from wry/wry

vulkan: implement async shm textures

This commit is contained in:
Julian Orth 2024-09-07 17:48:08 +02:00
parent b57d86c1bc
commit c712efcd35
10 changed files with 551 additions and 39 deletions

View file

@ -1 +1,2 @@
pub mod img_copy;
pub mod read_write;

View file

@ -0,0 +1,62 @@
use {
crate::{
cpu_worker::{AsyncCpuWork, CpuWork},
rect::Rect,
},
std::ptr,
};
#[expect(clippy::manual_non_exhaustive)]
pub struct ImgCopyWork {
pub src: *mut u8,
pub dst: *mut u8,
pub width: i32,
pub stride: i32,
pub bpp: i32,
pub rects: Vec<Rect>,
_priv: (),
}
unsafe impl Send for ImgCopyWork {}
impl ImgCopyWork {
pub unsafe fn new() -> Self {
Self {
src: ptr::null_mut(),
dst: ptr::null_mut(),
width: 0,
stride: 0,
bpp: 0,
rects: vec![],
_priv: (),
}
}
}
impl CpuWork for ImgCopyWork {
fn run(&mut self) -> Option<Box<dyn AsyncCpuWork>> {
for rect in &self.rects {
let mut offset = rect.y1() * self.stride + rect.x1() * self.bpp;
if rect.width() == self.width {
let offset = offset as usize;
let len = rect.height() * self.stride;
unsafe {
ptr::copy_nonoverlapping(self.src.add(offset), self.dst.add(offset), len as _);
}
} else {
let len = rect.width() * self.bpp;
for _ in 0..rect.height() {
unsafe {
ptr::copy_nonoverlapping(
self.src.add(offset as _),
self.dst.add(offset as _),
len as _,
);
}
offset += self.stride;
}
}
}
None
}
}

View file

@ -36,7 +36,6 @@ pub struct ReadWriteWork {
unsafe impl Send for ReadWriteWork {}
impl ReadWriteWork {
#[expect(dead_code)]
pub unsafe fn new() -> Self {
let cancel = Arc::new(CancelState::default());
ReadWriteWork {
@ -53,7 +52,6 @@ impl ReadWriteWork {
}
}
#[expect(dead_code)]
pub fn config(&mut self) -> &mut ReadWriteWorkConfig {
self.config.as_mut().unwrap()
}