Move cursor resource writing to driver-graphics
This commit is contained in:
@@ -21,6 +21,7 @@ pub trait GraphicsAdapter {
|
||||
|
||||
fn supports_hw_cursor(&self) -> bool;
|
||||
fn create_cursor_framebuffer(&mut self) -> Self::Cursor;
|
||||
fn map_cursor_framebuffer(&mut self, cursor: &Self::Cursor) -> *mut u8;
|
||||
fn handle_cursor(&mut self, cursor_damage: CursorDamage, cursor_resource: &mut Self::Cursor);
|
||||
}
|
||||
|
||||
@@ -247,10 +248,36 @@ impl<T: GraphicsAdapter> Scheme for GraphicsScheme<T> {
|
||||
let cursor_damage = unsafe { *buf.as_ptr().cast::<CursorDamage>() };
|
||||
|
||||
//There is always expected to be cursor_resource if supports_hw_cursor returns true
|
||||
if let Some(cursor_resource) = self.cursor_resources.get_mut(vt) {
|
||||
self.adapter.handle_cursor(cursor_damage, cursor_resource);
|
||||
let cursor_resource = self.cursor_resources.get_mut(vt).unwrap();
|
||||
|
||||
if cursor_damage.header != 0 {
|
||||
let w: i32 = cursor_damage.width;
|
||||
let h: i32 = cursor_damage.height;
|
||||
let cursor_image = cursor_damage.cursor_img_bytes;
|
||||
let cursor_ptr = self.adapter.map_cursor_framebuffer(cursor_resource);
|
||||
|
||||
//Clear previous image from backing storage
|
||||
unsafe {
|
||||
core::ptr::write_bytes(cursor_ptr as *mut u8, 0, 64 * 64 * 4);
|
||||
}
|
||||
|
||||
//Write image to backing storage
|
||||
for row in 0..h {
|
||||
let start: usize = (w * row) as usize;
|
||||
let end: usize = (w * row + w) as usize;
|
||||
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
cursor_image[start..end].as_ptr(),
|
||||
cursor_ptr.cast::<u32>().offset(64 * row as isize),
|
||||
w as usize,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.adapter.handle_cursor(cursor_damage, cursor_resource);
|
||||
|
||||
return Ok(buf.len());
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,10 @@ impl GraphicsAdapter for FbAdapter {
|
||||
unimplemented!("Vesad does not support this function");
|
||||
}
|
||||
|
||||
fn map_cursor_framebuffer(&mut self, _cursor: &Self::Cursor) -> *mut u8 {
|
||||
unimplemented!("Vesad does not support this function");
|
||||
}
|
||||
|
||||
fn handle_cursor(&mut self, _cursor_damage: CursorDamage, _cursor_resource: &mut VesadCursor) {
|
||||
unimplemented!("Vesad does not support this function");
|
||||
}
|
||||
|
||||
@@ -101,35 +101,12 @@ impl VirtGpuAdapter<'_> {
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
fn update_cursor(&mut self, cursor_damage: CursorDamage, cursor: &mut VirtGpuCursor) {
|
||||
fn update_cursor(&mut self, cursor_damage: CursorDamage, cursor: &VirtGpuCursor) {
|
||||
let x = cursor_damage.x;
|
||||
let y = cursor_damage.y;
|
||||
let hot_x = cursor_damage.hot_x;
|
||||
let hot_y = cursor_damage.hot_y;
|
||||
|
||||
let w: i32 = cursor_damage.width;
|
||||
let h: i32 = cursor_damage.height;
|
||||
let cursor_image = cursor_damage.cursor_img_bytes;
|
||||
|
||||
//Clear previous image from backing storage
|
||||
unsafe {
|
||||
core::ptr::write_bytes(cursor.sgl.as_ptr() as *mut u8, 0, 64 * 64 * 4);
|
||||
}
|
||||
|
||||
//Write image to backing storage
|
||||
for row in 0..h {
|
||||
let start: usize = (w * row) as usize;
|
||||
let end: usize = (w * row + w) as usize;
|
||||
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
cursor_image[start..end].as_ptr(),
|
||||
(cursor.sgl.as_ptr() as *mut u32).offset(64 * row as isize),
|
||||
w as usize,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//Transfering cursor resource to host
|
||||
futures::executor::block_on(async {
|
||||
let transfer_request = Dma::new(XferToHost2d::new(
|
||||
@@ -367,6 +344,10 @@ impl GraphicsAdapter for VirtGpuAdapter<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
fn map_cursor_framebuffer(&mut self, cursor: &Self::Cursor) -> *mut u8 {
|
||||
cursor.sgl.as_ptr()
|
||||
}
|
||||
|
||||
fn handle_cursor(&mut self, cursor_damage: CursorDamage, cursor: &mut VirtGpuCursor) {
|
||||
if !cursor.set {
|
||||
cursor.set = true;
|
||||
|
||||
Reference in New Issue
Block a user