diff --git a/drivers/graphics/driver-graphics/src/lib.rs b/drivers/graphics/driver-graphics/src/lib.rs index 25d54b3593..29bece881b 100644 --- a/drivers/graphics/driver-graphics/src/lib.rs +++ b/drivers/graphics/driver-graphics/src/lib.rs @@ -8,7 +8,8 @@ use std::mem; use std::mem::transmute; use std::sync::Arc; -use graphics_ipc::v1::{CursorDamage, Damage}; +use graphics_ipc::v1::CursorDamage; +use graphics_ipc::v2::Damage; use inputd::{VtEvent, VtEventKind}; use libredox::Fd; use redox_scheme::scheme::SchemeSync; diff --git a/drivers/graphics/graphics-ipc/src/common.rs b/drivers/graphics/graphics-ipc/src/common.rs index 81e02640d5..27138151d5 100644 --- a/drivers/graphics/graphics-ipc/src/common.rs +++ b/drivers/graphics/graphics-ipc/src/common.rs @@ -30,46 +30,3 @@ impl Damage { self } } - -pub struct DisplayMap { - offscreen: *mut [u32], - width: usize, - height: usize, -} - -impl DisplayMap { - pub(crate) unsafe fn new(offscreen: *mut [u32], width: usize, height: usize) -> Self { - DisplayMap { - offscreen, - width, - height, - } - } - - pub fn ptr(&self) -> *const [u32] { - self.offscreen - } - - pub fn ptr_mut(&mut self) -> *mut [u32] { - self.offscreen - } - - pub fn width(&self) -> usize { - self.width - } - - pub fn height(&self) -> usize { - self.height - } -} - -unsafe impl Send for DisplayMap {} -unsafe impl Sync for DisplayMap {} - -impl Drop for DisplayMap { - fn drop(&mut self) { - unsafe { - let _ = libredox::call::munmap(self.offscreen as *mut (), self.offscreen.len()); - } - } -} diff --git a/drivers/graphics/graphics-ipc/src/v1.rs b/drivers/graphics/graphics-ipc/src/v1.rs index 640d117bab..df882024c2 100644 --- a/drivers/graphics/graphics-ipc/src/v1.rs +++ b/drivers/graphics/graphics-ipc/src/v1.rs @@ -1,80 +1,4 @@ -use std::fs::File; -use std::os::unix::io::AsRawFd; -use std::{io, mem, ptr, slice}; - -use libredox::flag; - pub use crate::common::Damage; -pub use crate::common::DisplayMap; - -/// A graphics handle using the v1 graphics API. -/// -/// The v1 graphics API only allows a single framebuffer for each VT, requires each display to be -/// handled separately and doesn't support page flipping. -/// -/// This API is stable. No breaking changes are allowed to be made without a version bump. -pub struct V1GraphicsHandle { - file: File, -} - -impl V1GraphicsHandle { - pub fn from_file(file: File) -> io::Result { - Ok(V1GraphicsHandle { file }) - } - - pub fn map_display(&self) -> io::Result { - let mut buf: [u8; 4096] = [0; 4096]; - let count = - libredox::call::fpath(self.file.as_raw_fd() as usize, &mut buf).unwrap_or_else(|e| { - panic!("Could not read display path with fpath(): {e}"); - }); - - let url = - String::from_utf8(Vec::from(&buf[..count])).expect("Could not create Utf8 Url String"); - let path = url.split(':').nth(1).expect("Could not get path from url"); - - let mut path_parts = path.split('/').skip(1); - let width = path_parts - .next() - .unwrap_or("") - .parse::() - .unwrap_or(0); - let height = path_parts - .next() - .unwrap_or("") - .parse::() - .unwrap_or(0); - - let display_ptr = unsafe { - libredox::call::mmap(libredox::call::MmapArgs { - fd: self.file.as_raw_fd() as usize, - offset: 0, - length: (width * height * 4), - prot: flag::PROT_READ | flag::PROT_WRITE, - flags: flag::MAP_SHARED, - addr: core::ptr::null_mut(), - })? - }; - let offscreen = ptr::slice_from_raw_parts_mut(display_ptr as *mut u32, width * height); - - Ok(unsafe { DisplayMap::new(offscreen, width, height) }) - } - - pub fn sync_full_screen(&self) -> io::Result<()> { - libredox::call::fsync(self.file.as_raw_fd() as usize)?; - Ok(()) - } - - pub fn sync_rect(&self, sync_rect: Damage) -> io::Result<()> { - libredox::call::write(self.file.as_raw_fd() as usize, unsafe { - slice::from_raw_parts( - ptr::addr_of!(sync_rect).cast::(), - mem::size_of::(), - ) - })?; - Ok(()) - } -} #[derive(Debug, Copy, Clone)] #[repr(C, packed)] diff --git a/drivers/graphics/graphics-ipc/src/v2.rs b/drivers/graphics/graphics-ipc/src/v2.rs index fb9c98b997..19d50f33d1 100644 --- a/drivers/graphics/graphics-ipc/src/v2.rs +++ b/drivers/graphics/graphics-ipc/src/v2.rs @@ -9,7 +9,7 @@ use drm::control::Device as _; use drm::{ClientCapability, Device as _, DriverCapability}; use drm_fourcc::DrmFourcc; -pub use crate::common::{Damage, DisplayMap}; +pub use crate::common::Damage; extern "C" { fn redox_sys_call_v0(