Merge branch 'graphics_cleanup' into 'main'

Couple of cleanups to the graphic subsystem

See merge request redox-os/base!144
This commit is contained in:
Jeremy Soller
2026-03-06 14:56:37 -07:00
8 changed files with 22 additions and 43 deletions
Generated
+1
View File
@@ -935,6 +935,7 @@ dependencies = [
"drm",
"libredox",
"log",
"plain",
"redox-ioctl",
"redox_syscall 0.7.3",
]
+1
View File
@@ -7,6 +7,7 @@ edition = "2021"
drm.workspace = true
log.workspace = true
libredox.workspace = true
plain = "0.2"
redox-ioctl.workspace = true
redox_syscall.workspace = true
+9 -32
View File
@@ -1,41 +1,15 @@
use std::fs::File;
use std::io;
use std::os::fd::{AsFd, BorrowedFd};
use std::os::unix::io::AsRawFd;
use std::{io, mem};
use drm::control::connector::{self, State};
use drm::control::Device as _;
use drm::{ClientCapability, Device as _, DriverCapability};
use syscall::CallFlags;
pub use crate::common::Damage;
extern "C" {
fn redox_sys_call_v0(
fd: usize,
payload: *mut u8,
payload_len: usize,
flags: usize,
metadata: *const u64,
metadata_len: usize,
) -> usize;
}
unsafe fn sys_call<T>(
fd: &impl AsRawFd,
payload: &mut T,
flags: usize,
metadata: &[u64],
) -> libredox::error::Result<usize> {
libredox::error::Error::demux(redox_sys_call_v0(
fd.as_raw_fd() as usize,
payload as *mut T as *mut u8,
mem::size_of::<T>(),
flags,
metadata.as_ptr(),
metadata.len(),
))
}
/// A graphics handle using the v2 graphics API.
///
/// The v2 graphics API allows creating framebuffers on the fly, using them for page flipping and
@@ -74,14 +48,17 @@ impl V2GraphicsHandle {
}
pub fn update_plane(&self, display_id: usize, fb_id: u32, damage: Damage) -> io::Result<()> {
let mut cmd = ipc::UpdatePlane {
let cmd = ipc::UpdatePlane {
display_id,
fb_id,
damage,
};
unsafe {
sys_call(&self.file, &mut cmd, 0, &[ipc::UPDATE_PLANE, 0, 0])?;
}
libredox::call::call_wo(
self.file.as_raw_fd() as usize,
unsafe { plain::as_bytes(&cmd) },
CallFlags::empty(),
&[ipc::UPDATE_PLANE, 0, 0],
)?;
Ok(())
}
}
+1 -1
View File
@@ -35,7 +35,7 @@ fn daemon(daemon: daemon::Daemon, mut pcid_handle: PciFunctionHandle) -> ! {
let irq_file = pci_allocate_interrupt_vector(&mut pcid_handle, "ihdgd");
let mut inputd_display_handle = DisplayHandle::new(format!("ihdg.{}", name)).unwrap();
let mut inputd_display_handle = DisplayHandle::new(format!("display.ihdg.{}", name)).unwrap();
let mut scheme = GraphicsScheme::new(device, format!("display.ihdg.{}", name));
+1 -1
View File
@@ -84,7 +84,7 @@ fn daemon(daemon: daemon::Daemon) -> ! {
};
}
let mut inputd_display_handle = DisplayHandle::new_early("vesa").unwrap();
let mut inputd_display_handle = DisplayHandle::new_early("display.vesa").unwrap();
let mut scheme = GraphicsScheme::new(FbAdapter { framebuffers }, "display.vesa".to_owned());
+1 -1
View File
@@ -571,7 +571,7 @@ impl<'a> GpuScheme {
};
let scheme = GraphicsScheme::new(adapter, "display.virtio-gpu".to_owned());
let handle = DisplayHandle::new("virtio-gpu").unwrap();
let handle = DisplayHandle::new("display.virtio-gpu").unwrap();
Ok((scheme, handle))
}
}
+4 -4
View File
@@ -153,13 +153,13 @@ pub struct KeymapActivate {
pub struct DisplayHandle(File);
impl DisplayHandle {
pub fn new<S: Into<String>>(device_name: S) -> io::Result<Self> {
let path = format!("/scheme/input/handle/display/{}", device_name.into());
pub fn new<S: Into<String>>(scheme_name: S) -> io::Result<Self> {
let path = format!("/scheme/input/handle/{}", scheme_name.into());
Ok(Self(File::open(path)?))
}
pub fn new_early<S: Into<String>>(device_name: S) -> io::Result<Self> {
let path = format!("/scheme/input/handle_early/display/{}", device_name.into());
pub fn new_early<S: Into<String>>(scheme_name: S) -> io::Result<Self> {
let path = format!("/scheme/input/handle_early/{}", scheme_name.into());
Ok(Self(File::open(path)?))
}
+4 -4
View File
@@ -176,7 +176,6 @@ impl SchemeSync for InputScheme {
let mut path_parts = path.split('/');
let command = path_parts.next().ok_or(SysError::new(EINVAL))?;
let fd = self.next_id.fetch_add(1, Ordering::SeqCst);
let handle_ty = match command {
"producer" => Handle::Producer,
@@ -210,7 +209,7 @@ impl SchemeSync for InputScheme {
}
}
"handle" | "handle_early" => {
let display = path_parts.collect::<Vec<_>>().join(".");
let display = path_parts.next().ok_or(SysError::new(EINVAL))?;
let needs_handoff = match command {
"handle_early" => self.display.is_none(),
@@ -228,7 +227,7 @@ impl SchemeSync for InputScheme {
if needs_handoff {
self.has_new_events = true;
self.display = Some(display.clone());
self.display = Some(display.to_owned());
for handle in self.handles.values_mut() {
match handle {
@@ -259,7 +258,7 @@ impl SchemeSync for InputScheme {
vec![]
},
notified: false,
device: display,
device: display.to_owned(),
is_earlyfb: command == "handle_early",
}
}
@@ -273,6 +272,7 @@ impl SchemeSync for InputScheme {
log::debug!("{path} channel has been opened");
let fd = self.next_id.fetch_add(1, Ordering::SeqCst);
self.handles.insert(fd, handle_ty);
Ok(OpenResult::ThisScheme {
number: fd,