diff --git a/drivers/graphics/console-draw/src/lib.rs b/drivers/graphics/console-draw/src/lib.rs index c066a622c9..eb7d217da6 100644 --- a/drivers/graphics/console-draw/src/lib.rs +++ b/drivers/graphics/console-draw/src/lib.rs @@ -7,9 +7,49 @@ use std::{cmp, io, mem, ptr}; use drm::buffer::{Buffer, DrmFourcc}; use drm::control::dumbbuffer::{DumbBuffer, DumbMapping}; use drm::control::{framebuffer, ClipRect, Device}; -use graphics_ipc::v2::{Damage, V2GraphicsHandle}; +use graphics_ipc::v2::V2GraphicsHandle; use orbclient::FONT; +#[derive(Debug, Copy, Clone)] +#[repr(C, packed)] +pub struct Damage { + pub x: u32, + pub y: u32, + pub width: u32, + pub height: u32, +} + +impl Damage { + pub const NONE: Self = Damage { + x: 0, + y: 0, + width: 0, + height: 0, + }; + + pub fn merge(self, other: Self) -> Self { + if self.width == 0 || self.height == 0 { + return other; + } + + if other.width == 0 || other.height == 0 { + return self; + } + + let x = cmp::min(self.x, other.x); + let y = cmp::min(self.y, other.y); + let x2 = cmp::max(self.x + self.width, other.x + other.width); + let y2 = cmp::max(self.y + self.height, other.y + other.height); + + Damage { + x, + y, + width: x2 - x, + height: y2 - y, + } + } +} + pub struct V2DisplayMap { pub display_handle: V2GraphicsHandle, fb: framebuffer::Handle, diff --git a/drivers/graphics/driver-graphics/src/lib.rs b/drivers/graphics/driver-graphics/src/lib.rs index 376bce72e8..6bd5966cf2 100644 --- a/drivers/graphics/driver-graphics/src/lib.rs +++ b/drivers/graphics/driver-graphics/src/lib.rs @@ -5,9 +5,9 @@ use std::ffi::c_char; use std::fmt::Debug; use std::fs::File; use std::io::{self, Write}; -use std::mem; use std::os::fd::BorrowedFd; use std::sync::{Arc, Mutex}; +use std::{cmp, mem}; use drm_sys::{ drm_mode_modeinfo, drm_mode_property_enum, DRM_MODE_CURSOR_BO, DRM_MODE_CURSOR_MOVE, @@ -15,7 +15,6 @@ use drm_sys::{ DRM_MODE_PROP_IMMUTABLE, DRM_MODE_PROP_OBJECT, DRM_MODE_PROP_RANGE, DRM_MODE_PROP_SIGNED_RANGE, DRM_PROP_NAME_LEN, }; -use graphics_ipc::v2::Damage; use inputd::{DisplayHandle, VtEventKind}; use libredox::Fd; use redox_scheme::scheme::{register_scheme_inner, SchemeState, SchemeSync}; @@ -29,6 +28,56 @@ use crate::kms::properties::KmsPropertyKind; pub mod kms; +#[derive(Debug, Copy, Clone)] +#[repr(C, packed)] +pub struct Damage { + pub x: u32, + pub y: u32, + pub width: u32, + pub height: u32, +} + +impl Damage { + fn merge(self, other: Self) -> Self { + if self.width == 0 || self.height == 0 { + return other; + } + + if other.width == 0 || other.height == 0 { + return self; + } + + let x = cmp::min(self.x, other.x); + let y = cmp::min(self.y, other.y); + let x2 = cmp::max(self.x + self.width, other.x + other.width); + let y2 = cmp::max(self.y + self.height, other.y + other.height); + + Damage { + x, + y, + width: x2 - x, + height: y2 - y, + } + } + + #[must_use] + pub fn clip(mut self, width: u32, height: u32) -> Self { + // Clip damage + let x2 = self.x + self.width; + self.x = cmp::min(self.x, width); + if x2 > width { + self.width = width - self.x; + } + + let y2 = self.y + self.height; + self.y = cmp::min(self.y, height); + if y2 > height { + self.height = height - self.y; + } + self + } +} + pub trait GraphicsAdapter: Sized + Debug { type Connector: Debug; type Crtc: Debug; diff --git a/drivers/graphics/fbbootlogd/src/scheme.rs b/drivers/graphics/fbbootlogd/src/scheme.rs index b925629c43..ac9085d130 100644 --- a/drivers/graphics/fbbootlogd/src/scheme.rs +++ b/drivers/graphics/fbbootlogd/src/scheme.rs @@ -1,10 +1,10 @@ use std::cmp; use std::collections::VecDeque; -use console_draw::{TextScreen, V2DisplayMap}; +use console_draw::{Damage, TextScreen, V2DisplayMap}; use drm::buffer::Buffer; use drm::control::Device; -use graphics_ipc::v2::{Damage, V2GraphicsHandle}; +use graphics_ipc::v2::V2GraphicsHandle; use inputd::ConsumerHandle; use orbclient::{Event, EventOption}; use redox_scheme::scheme::SchemeSync; diff --git a/drivers/graphics/fbcond/src/display.rs b/drivers/graphics/fbcond/src/display.rs index 480fe20420..eb323627b6 100644 --- a/drivers/graphics/fbcond/src/display.rs +++ b/drivers/graphics/fbcond/src/display.rs @@ -1,7 +1,7 @@ -use console_draw::{TextScreen, V2DisplayMap}; +use console_draw::{Damage, TextScreen, V2DisplayMap}; use drm::buffer::Buffer; use drm::control::Device; -use graphics_ipc::v2::{Damage, V2GraphicsHandle}; +use graphics_ipc::v2::V2GraphicsHandle; use inputd::ConsumerHandle; use std::io; diff --git a/drivers/graphics/graphics-ipc/src/common.rs b/drivers/graphics/graphics-ipc/src/common.rs deleted file mode 100644 index ca5dc48392..0000000000 --- a/drivers/graphics/graphics-ipc/src/common.rs +++ /dev/null @@ -1,61 +0,0 @@ -use std::cmp; - -// 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(C, packed)] -pub struct Damage { - pub x: u32, - pub y: u32, - pub width: u32, - pub height: u32, -} - -impl Damage { - pub const NONE: Self = Damage { - x: 0, - y: 0, - width: 0, - height: 0, - }; - - pub fn merge(self, other: Self) -> Self { - if self.width == 0 || self.height == 0 { - return other; - } - - if other.width == 0 || other.height == 0 { - return self; - } - - let x = cmp::min(self.x, other.x); - let y = cmp::min(self.y, other.y); - let x2 = cmp::max(self.x + self.width, other.x + other.width); - let y2 = cmp::max(self.y + self.height, other.y + other.height); - - Damage { - x, - y, - width: x2 - x, - height: y2 - y, - } - } - - #[must_use] - pub fn clip(mut self, width: u32, height: u32) -> Self { - // Clip damage - let x2 = self.x + self.width; - self.x = cmp::min(self.x, width); - if x2 > width { - self.width = width - self.x; - } - - let y2 = self.y + self.height; - self.y = cmp::min(self.y, height); - if y2 > height { - self.height = height - self.y; - } - self - } -} diff --git a/drivers/graphics/graphics-ipc/src/lib.rs b/drivers/graphics/graphics-ipc/src/lib.rs index a27c4421c6..7083bd82d0 100644 --- a/drivers/graphics/graphics-ipc/src/lib.rs +++ b/drivers/graphics/graphics-ipc/src/lib.rs @@ -1,4 +1 @@ -#![feature(macro_metavar_expr_concat)] - -mod common; pub mod v2; diff --git a/drivers/graphics/graphics-ipc/src/v2.rs b/drivers/graphics/graphics-ipc/src/v2.rs index 9c6a340c72..cf6ed3d3a6 100644 --- a/drivers/graphics/graphics-ipc/src/v2.rs +++ b/drivers/graphics/graphics-ipc/src/v2.rs @@ -6,8 +6,6 @@ use drm::control::connector::{self, State}; use drm::control::Device as _; use drm::{Device as _, DriverCapability}; -pub use crate::common::Damage; - /// A graphics handle using the v2 graphics API. /// /// The v2 graphics API allows creating framebuffers on the fly, using them for page flipping and diff --git a/drivers/graphics/ihdgd/src/device/scheme.rs b/drivers/graphics/ihdgd/src/device/scheme.rs index 52cbb218d2..5ddd72ad74 100644 --- a/drivers/graphics/ihdgd/src/device/scheme.rs +++ b/drivers/graphics/ihdgd/src/device/scheme.rs @@ -8,10 +8,9 @@ use std::sync::Mutex; use driver_graphics::kms::connector::KmsConnectorStatus; use driver_graphics::kms::objects::{self, KmsCrtc, KmsObjectId, KmsObjects}; use driver_graphics::kms::properties::DPMS; -use driver_graphics::{Buffer, CursorPlane, GraphicsAdapter}; +use driver_graphics::{Buffer, CursorPlane, Damage, GraphicsAdapter}; use drm_sys::{drm_mode_modeinfo, DRM_MODE_DPMS_ON}; use graphics_ipc::v2::ipc::{DRM_CAP_DUMB_BUFFER, DRM_CLIENT_CAP_CURSOR_PLANE_HOTSPOT}; -use graphics_ipc::v2::Damage; use syscall::{error::EINVAL, PAGE_SIZE}; use super::Device; diff --git a/drivers/graphics/vesad/src/scheme.rs b/drivers/graphics/vesad/src/scheme.rs index 45c828f2ac..eed74e1c54 100644 --- a/drivers/graphics/vesad/src/scheme.rs +++ b/drivers/graphics/vesad/src/scheme.rs @@ -6,10 +6,9 @@ use std::sync::Mutex; use driver_graphics::kms::connector::KmsConnectorStatus; use driver_graphics::kms::objects::{self, KmsCrtc, KmsObjectId, KmsObjects}; use driver_graphics::kms::properties::DPMS; -use driver_graphics::{Buffer, CursorPlane, GraphicsAdapter}; +use driver_graphics::{Buffer, CursorPlane, Damage, GraphicsAdapter}; use drm_sys::{drm_mode_modeinfo, DRM_MODE_DPMS_ON}; use graphics_ipc::v2::ipc::{DRM_CAP_DUMB_BUFFER, DRM_CLIENT_CAP_CURSOR_PLANE_HOTSPOT}; -use graphics_ipc::v2::Damage; use syscall::{EINVAL, PAGE_SIZE}; #[derive(Debug)] diff --git a/drivers/graphics/virtio-gpud/src/scheme.rs b/drivers/graphics/virtio-gpud/src/scheme.rs index 8265846d61..4abeae0320 100644 --- a/drivers/graphics/virtio-gpud/src/scheme.rs +++ b/drivers/graphics/virtio-gpud/src/scheme.rs @@ -5,10 +5,9 @@ use common::{dma::Dma, sgl}; use driver_graphics::kms::connector::KmsConnectorStatus; use driver_graphics::kms::objects::{self, KmsCrtc, KmsObjectId, KmsObjects}; use driver_graphics::kms::properties::{DPMS, EDID}; -use driver_graphics::{Buffer as DrmBuffer, CursorPlane, GraphicsAdapter, GraphicsScheme}; +use driver_graphics::{Buffer as DrmBuffer, CursorPlane, Damage, GraphicsAdapter, GraphicsScheme}; use drm_sys::{drm_mode_modeinfo, DRM_CAP_CURSOR_HEIGHT, DRM_CAP_CURSOR_WIDTH, DRM_MODE_DPMS_ON}; use graphics_ipc::v2::ipc::{DRM_CAP_DUMB_BUFFER, DRM_CLIENT_CAP_CURSOR_PLANE_HOTSPOT}; -use graphics_ipc::v2::Damage; use syscall::{EINVAL, PAGE_SIZE};