graphics/graphics-ipc: Use u32 fields in Damage
The fields should never be negative and this saves a couple of casts.
This commit is contained in:
@@ -221,7 +221,7 @@ impl TextScreen {
|
||||
} else {
|
||||
damage.push(Damage {
|
||||
x: 0,
|
||||
y: i32::try_from(change).unwrap() * 16,
|
||||
y: u32::try_from(change).unwrap() * 16,
|
||||
width,
|
||||
height: 16,
|
||||
});
|
||||
|
||||
@@ -142,8 +142,8 @@ impl<T: GraphicsAdapter> GraphicsScheme<T> {
|
||||
&[Damage {
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: resource.width() as i32,
|
||||
height: resource.height() as i32,
|
||||
width: resource.width(),
|
||||
height: resource.height(),
|
||||
}],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -111,18 +111,20 @@ impl Drop for DisplayMap {
|
||||
}
|
||||
|
||||
// Keep synced with orbital's SyncRect
|
||||
// Technically orbital uses i32 rather than u32, but values larger than i32::MAX
|
||||
// would be a bug anyway.
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
#[repr(packed)]
|
||||
pub struct Damage {
|
||||
pub x: i32,
|
||||
pub y: i32,
|
||||
pub width: i32,
|
||||
pub height: i32,
|
||||
pub x: u32,
|
||||
pub y: u32,
|
||||
pub width: u32,
|
||||
pub height: u32,
|
||||
}
|
||||
|
||||
impl Damage {
|
||||
#[must_use]
|
||||
pub fn clip(mut self, width: i32, height: i32) -> Self {
|
||||
pub fn clip(mut self, width: u32, height: u32) -> Self {
|
||||
// Clip damage
|
||||
self.x = cmp::min(self.x, width);
|
||||
if self.x + self.width > width {
|
||||
|
||||
@@ -91,10 +91,10 @@ impl GraphicScreen {
|
||||
self.height.try_into().unwrap(),
|
||||
);
|
||||
|
||||
let start_x: usize = sync_rect.x.try_into().unwrap_or(0);
|
||||
let start_y: usize = sync_rect.y.try_into().unwrap_or(0);
|
||||
let w: usize = sync_rect.width.try_into().unwrap_or(0);
|
||||
let h: usize = sync_rect.height.try_into().unwrap_or(0);
|
||||
let start_x: usize = sync_rect.x.try_into().unwrap();
|
||||
let start_y: usize = sync_rect.y.try_into().unwrap();
|
||||
let w: usize = sync_rect.width.try_into().unwrap();
|
||||
let h: usize = sync_rect.height.try_into().unwrap();
|
||||
|
||||
let offscreen_ptr = self.ptr.as_ptr() as *mut u32;
|
||||
let onscreen_ptr = framebuffer.onscreen as *mut u32; // FIXME use as_mut_ptr once stable
|
||||
|
||||
@@ -15,10 +15,10 @@ use crate::*;
|
||||
impl Into<GpuRect> for Damage {
|
||||
fn into(self) -> GpuRect {
|
||||
GpuRect {
|
||||
x: self.x as u32,
|
||||
y: self.y as u32,
|
||||
width: self.width as u32,
|
||||
height: self.height as u32,
|
||||
x: self.x,
|
||||
y: self.y,
|
||||
width: self.width,
|
||||
height: self.height,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -202,9 +202,7 @@ impl GraphicsAdapter for VirtGpuAdapter<'_> {
|
||||
for damage in damage {
|
||||
let flush = ResourceFlush::new(
|
||||
resource.id,
|
||||
damage
|
||||
.clip(resource.width as i32, resource.height as i32)
|
||||
.into(),
|
||||
damage.clip(resource.width, resource.height).into(),
|
||||
);
|
||||
let header = self.send_request(Dma::new(flush).unwrap()).await.unwrap();
|
||||
assert_eq!(header.ty, CommandTy::RespOkNodata);
|
||||
|
||||
Reference in New Issue
Block a user