From ebaccd876203e5380e9cbadfbfb06788ab551518 Mon Sep 17 00:00:00 2001 From: kossLAN Date: Fri, 29 May 2026 11:27:02 -0400 Subject: [PATCH] video: move dma-buf types into workspace crate --- Cargo.lock | 11 ++++++ Cargo.toml | 2 + src/video.rs | 9 +---- video-types/Cargo.toml | 12 ++++++ {src/video => video-types/src}/dmabuf.rs | 48 +++++++++++++++++++++--- video-types/src/lib.rs | 9 +++++ 6 files changed, 77 insertions(+), 14 deletions(-) create mode 100644 video-types/Cargo.toml rename {src/video => video-types/src}/dmabuf.rs (82%) create mode 100644 video-types/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 93d2fdcf..daefdd2c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -721,6 +721,7 @@ dependencies = [ "jay-tree-types", "jay-units", "jay-utils", + "jay-video-types", "jay-wheel", "jay-wire-buf", "jay-wire-types", @@ -978,6 +979,16 @@ dependencies = [ "uapi", ] +[[package]] +name = "jay-video-types" +version = "0.1.0" +dependencies = [ + "arrayvec", + "jay-formats", + "jay-utils", + "uapi", +] + [[package]] name = "jay-wheel" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index f2512308..c18f1c43 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,6 +42,7 @@ members = [ "pr-caps", "bugs", "logger", + "video-types", "toml-config", "algorithms", "toml-spec", @@ -85,6 +86,7 @@ jay-sighand = { version = "0.1.0", path = "sighand" } jay-pr-caps = { version = "0.1.0", path = "pr-caps" } jay-bugs = { version = "0.1.0", path = "bugs" } jay-logger = { version = "0.1.0", path = "logger" } +jay-video-types = { version = "0.1.0", path = "video-types" } uapi = "0.2.13" thiserror = "2.0.11" diff --git a/src/video.rs b/src/video.rs index 9f8906fe..3257093b 100644 --- a/src/video.rs +++ b/src/video.rs @@ -1,11 +1,4 @@ -pub mod dmabuf; pub mod drm; pub mod gbm; -pub type Modifier = u64; - -pub const INVALID_MODIFIER: Modifier = 0x00ff_ffff_ffff_ffff; -pub const LINEAR_MODIFIER: Modifier = 0; - -// This is required by AMD and therefore everyone else uses this too. -pub const LINEAR_STRIDE_ALIGN: u64 = 256; +pub use jay_video_types::*; diff --git a/video-types/Cargo.toml b/video-types/Cargo.toml new file mode 100644 index 00000000..45544300 --- /dev/null +++ b/video-types/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "jay-video-types" +version = "0.1.0" +edition = "2024" +license = "GPL-3.0-only" + +[dependencies] +jay-formats = { version = "0.1.0", path = "../formats" } +jay-utils = { version = "0.1.0", path = "../utils" } + +arrayvec = "0.7.4" +uapi = "0.2.13" diff --git a/src/video/dmabuf.rs b/video-types/src/dmabuf.rs similarity index 82% rename from src/video/dmabuf.rs rename to video-types/src/dmabuf.rs index e19def66..a096b8b3 100644 --- a/src/video/dmabuf.rs +++ b/video-types/src/dmabuf.rs @@ -1,10 +1,8 @@ use { - crate::{ - format::Format, - utils::{compat::IoctlNumber, oserror::OsError}, - video::{LINEAR_MODIFIER, Modifier}, - }, + crate::{LINEAR_MODIFIER, Modifier}, arrayvec::ArrayVec, + jay_formats::Format, + jay_utils::{compat::IoctlNumber, numcell::NumCell, oserror::OsError}, std::{cell::OnceCell, rc::Rc, sync::OnceLock}, uapi::{ _IOW, _IOWR, OwnedFd, @@ -20,7 +18,45 @@ pub struct DmaBufPlane { pub fd: Rc, } -linear_ids!(DmaBufIds, DmaBufId); +#[derive(Debug)] +pub struct DmaBufIds { + next: NumCell, +} + +impl Default for DmaBufIds { + fn default() -> Self { + Self { + next: NumCell::new(1), + } + } +} + +impl DmaBufIds { + pub fn next(&self) -> DmaBufId { + DmaBufId(self.next.fetch_add(1)) + } +} + +#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] +pub struct DmaBufId(u32); + +impl DmaBufId { + #[allow(dead_code)] + pub fn raw(&self) -> u32 { + self.0 + } + + #[allow(dead_code)] + pub fn from_raw(id: u32) -> Self { + Self(id) + } +} + +impl std::fmt::Display for DmaBufId { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(&self.0, f) + } +} #[derive(Debug, Clone)] pub struct DmaBuf { diff --git a/video-types/src/lib.rs b/video-types/src/lib.rs new file mode 100644 index 00000000..52fdd41d --- /dev/null +++ b/video-types/src/lib.rs @@ -0,0 +1,9 @@ +pub mod dmabuf; + +pub type Modifier = u64; + +pub const INVALID_MODIFIER: Modifier = 0x00ff_ffff_ffff_ffff; +pub const LINEAR_MODIFIER: Modifier = 0; + +// This is required by AMD and therefore everyone else uses this too. +pub const LINEAR_STRIDE_ALIGN: u64 = 256;