Use inputd's Damage everywhere instead of separate SyncRect types

This commit is contained in:
bjorn3
2024-12-22 19:45:27 +01:00
parent 15cee6bb48
commit 5f7ee8f646
4 changed files with 21 additions and 36 deletions
+4 -13
View File
@@ -1,3 +1,4 @@
use inputd::Damage;
use libredox::flag;
use std::fs::OpenOptions;
use std::mem;
@@ -11,16 +12,6 @@ use std::{
};
use syscall::{O_CLOEXEC, O_NONBLOCK, O_RDWR};
// Keep synced with vesad
#[derive(Clone, Copy)]
#[repr(C, packed)]
pub struct SyncRect {
pub x: i32,
pub y: i32,
pub w: i32,
pub h: i32,
}
fn display_fd_map(width: usize, height: usize, display_fd: usize) -> syscall::Result<*mut [u32]> {
unsafe {
let display_ptr = libredox::call::mmap(libredox::call::MmapArgs {
@@ -146,13 +137,13 @@ impl Display {
}
}
pub fn sync_rect(&mut self, sync_rect: SyncRect) -> syscall::Result<()> {
pub fn sync_rect(&mut self, sync_rect: Damage) -> syscall::Result<()> {
unsafe {
libredox::call::write(
self.display_file.as_raw_fd().as_raw_fd() as usize,
slice::from_raw_parts(
&sync_rect as *const SyncRect as *const u8,
mem::size_of::<SyncRect>(),
&sync_rect as *const Damage as *const u8,
mem::size_of::<Damage>(),
),
)?;
Ok(())
+5 -4
View File
@@ -5,10 +5,11 @@ use std::convert::{TryFrom, TryInto};
use std::os::fd::AsRawFd;
use std::{cmp, ptr};
use inputd::Damage;
use orbclient::{Event, EventOption, FONT};
use syscall::error::*;
use crate::display::{Display, SyncRect};
use crate::display::Display;
pub struct TextScreen {
console: ransid::Console,
@@ -315,11 +316,11 @@ impl TextScreen {
let width = self.display.width.try_into().unwrap();
for &change in self.changed.iter() {
self.display.sync_rect(SyncRect {
self.display.sync_rect(Damage {
x: 0,
y: i32::try_from(change).unwrap() * 16,
w: width,
h: 16,
width,
height: 16,
})?;
}
self.changed.clear();
+10 -19
View File
@@ -2,28 +2,19 @@ use std::collections::VecDeque;
use std::convert::TryInto;
use std::{cmp, mem, ptr, slice};
use inputd::Damage;
use orbclient::{Event, ResizeEvent};
use syscall::error::*;
use crate::display::OffscreenBuffer;
use crate::framebuffer::FrameBuffer;
// Keep synced with orbital
#[derive(Clone, Copy)]
#[repr(C, packed)]
pub struct SyncRect {
pub x: i32,
pub y: i32,
pub w: i32,
pub h: i32,
}
pub struct GraphicScreen {
pub width: usize,
pub height: usize,
pub offscreen: OffscreenBuffer,
pub input: VecDeque<Event>,
pub sync_rects: Vec<SyncRect>,
pub sync_rects: Vec<Damage>,
}
impl GraphicScreen {
@@ -117,22 +108,22 @@ impl GraphicScreen {
pub fn write(&mut self, buf: &[u8]) -> Result<usize> {
let sync_rects = unsafe {
slice::from_raw_parts(
buf.as_ptr() as *const SyncRect,
buf.len() / mem::size_of::<SyncRect>(),
buf.as_ptr() as *const Damage,
buf.len() / mem::size_of::<Damage>(),
)
};
self.sync_rects.extend_from_slice(sync_rects);
Ok(sync_rects.len() * mem::size_of::<SyncRect>())
Ok(sync_rects.len() * mem::size_of::<Damage>())
}
pub fn sync(&mut self, framebuffer: &mut FrameBuffer) {
for sync_rect in self.sync_rects.drain(..) {
let x = sync_rect.x.try_into().unwrap_or(0);
let y = sync_rect.y.try_into().unwrap_or(0);
let w = sync_rect.w.try_into().unwrap_or(0);
let h = sync_rect.h.try_into().unwrap_or(0);
let w = sync_rect.width.try_into().unwrap_or(0);
let h = sync_rect.height.try_into().unwrap_or(0);
let start_y = cmp::min(self.height, y);
let end_y = cmp::min(self.height, y + h);
@@ -161,11 +152,11 @@ impl GraphicScreen {
pub fn redraw(&mut self, framebuffer: &mut FrameBuffer) {
let width = self.width.try_into().unwrap();
let height = self.height.try_into().unwrap();
self.sync_rects.push(SyncRect {
self.sync_rects.push(Damage {
x: 0,
y: 0,
w: width,
h: height,
width,
height,
});
self.sync(framebuffer);
}
+2
View File
@@ -90,6 +90,8 @@ pub struct VtEvent {
pub stride: u32,
}
// Keep synced with orbital's SyncRect
#[derive(Debug, Copy, Clone)]
#[repr(packed)]
pub struct Damage {
pub x: i32,