mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-12-04 15:46:07 +00:00
Drmtap packet min (#17286)
* drm: capture multi-plane scanouts with the libdrmtap packet API KWin 6.8 on Intel can scan a window out of its own plane, above the desktop (overlay) or below a desktop with a hole (underlay). One dma-buf descriptor cannot describe that frame: the window was missing, or during an underlay the window alone was streamed as the whole screen (#17187). libdrmtap 0.6 grabs every lit plane as an opaque packet plus its fds and composes them on the unprivileged side. When the loaded libdrmtap has the packet API, the service sends the packet in the existing dma-buf message (new field, all fds of the message belong to it) and the consumer converts it with drmtap_convert_packet. With an older libdrmtap nothing changes. The fd transport now carries up to 16 fds per message instead of one. The ABI gate accepts minor 6 next to 5. * drm: gate the packet path on the libdrmtap ABI level The loader accepts libdrmtap 0.5.0 up to 0.6.x. When the library exports drmtap_abi, the level range it serves must include 2 (the 0.6.0 header); without the symbol it is a 0.5 library, level 1. The packet path is on only at level 2 or above with its three symbols resolved. The consumer reads the rotation of a packet frame from its converting context after drmtap_convert_packet: libdrmtap knows there whether the frame was composed (rotate-0) or one plane converted as its buffer. drmtap_convert_packet errors and output checks now match convert(): EAGAIN, EBUSY and EINTR skip the frame instead of demoting the display. The frame arm sends through drm_send_frame and send_msg keeps its one fd signature. Comments and two log lines updated for the packet path. * drm: let build.py package any accepted libdrmtap minor, keep the last frame on E2BIG build.py required the pinned libdrmtap minor to equal DRMTAP_ABI_MINOR, so raising the runtime gate to 0.6 made it refuse the 0.5.12 pin. It now accepts the same range as the runtime loader. grab_packet maps E2BIG (more than four lit planes, none covering the CRTC) to WouldBlock so the last frame stays, like grab_desc on an underlay. * build: pin libdrmtap v0.6.0 rustdesk-org/libdrmtap is synced with upstream, so the package can ship 0.6.0 and the packet path runs. Before this, a packaged build carried 0.5.12 and has_packet() was always false. * drm: turn a composed frame by the primary plane rotation A frame libdrmtap composed from several planes is the CRTC raster and answers rotate-0, so it was turned by the wl_output transform. That transform does not carry the panel orientation: on a panel whose primary plane rotated in hardware the composed frame came out upside down (180) or transposed against the session size (90/270), which rebuilt the session on every frame while an overlay was lit. The CPU path does the same once it composes. Enumeration now records the primary plane rotation next to plane_transposed, read from the same query. A frame answering rotate-0 is turned by that rotation when the plane rotated, else by the output transform as before. One-layer frames still answer their plane rotation and are left alone. * drm: a failed packet convert drops to one descriptor first A convert error on a packet set prefer_cpu, which kept that monitor on the CPU path for the rest of the process run. It now sets no_packet: the next session asks the service for one descriptor (grab_desc) through a new DrmStart field, and only a failed descriptor convert sets prefer_cpu. The field defaults to false, so a consumer that does not send it keeps the packet path. The ABI gate test checks again that a library below the floor (0.4.x) is refused. * build: pin libdrmtap v0.6.1 rustdesk-org/libdrmtap is synced with v0.6.1. It fixes the frame size of a single plane that is scaled to the screen or smaller than it: that plane came out at its buffer size and the session was rebuilt. --------- Co-authored-by: Mariano Abad <weimaraner@gmail.com>
This commit is contained in:
1 parent
a98982d702
commit
130b84119b
8 files changed
+508
-131
No files matched your search
@@ -376,9 +376,9 @@ def ffi_bindgen_function_refactor():
|
||||
# The commit is fetched directly by sha, so no branch or tag name takes part in the build: see
|
||||
# build_libdrmtap_so(). This is the SINGLE source of truth for the pin, deliberately not duplicated in
|
||||
# any workflow, so a bump is one edit here (plus the informational version comment in
|
||||
# libs/scrap/Cargo.toml). This commit is libdrmtap v0.5.12.
|
||||
# libs/scrap/Cargo.toml). This commit is libdrmtap v0.6.1.
|
||||
LIBDRMTAP_REPO_PINNED = 'https://github.com/rustdesk-org/libdrmtap'
|
||||
LIBDRMTAP_SHA_PINNED = '5936a7a88b94aa43516a3dd0eb509d2383f31e2d'
|
||||
LIBDRMTAP_SHA_PINNED = '12600215d37ae66417a8dcef1e56c01ccf2933ac'
|
||||
LIBDRMTAP_REPO = os.environ.get('DRMTAP_REPO', LIBDRMTAP_REPO_PINNED)
|
||||
LIBDRMTAP_SHA = os.environ.get('DRMTAP_SHA', LIBDRMTAP_SHA_PINNED)
|
||||
# Every way of getting a different .so than the pin needs the same explicit opt-in. Otherwise the
|
||||
@@ -628,15 +628,15 @@ def assert_so_satisfies_the_runtime_abi_gate(so_path):
|
||||
'could not parse the libdrmtap ABI gate out of drmtap_dl.rs (DRMTAP_ABI_MAJOR / '
|
||||
'DRMTAP_ABI_MINOR / DRMTAP_MIN_MINOR_PATCH). The gate moved and this check did not; '
|
||||
'fix the check rather than removing it, or the pin and the gate can drift silently.')
|
||||
accepted = so_ver[0] == major and so_ver[1] == minor and (so_ver[1], so_ver[2]) >= floor
|
||||
accepted = so_ver[0] == major and so_ver[1] <= minor and (so_ver[1], so_ver[2]) >= floor
|
||||
if not accepted:
|
||||
raise Exception(
|
||||
f'the libdrmtap being packaged is {so_ver[0]}.{so_ver[1]}.{so_ver[2]}, which the '
|
||||
f'runtime loader would REFUSE: drmtap_dl.rs accepts exactly major {major}, minor '
|
||||
f'{minor}, patch >= {floor[1]}. Shipping it produces a deb whose DRM capture can never '
|
||||
f'runtime loader would REFUSE: drmtap_dl.rs accepts major {major}, from '
|
||||
f'{floor[0]}.{floor[1]} up to minor {minor}. Shipping it produces a deb whose DRM capture can never '
|
||||
'start. Move the build pin and the gate together, or fix whichever one is wrong.')
|
||||
print(f'[drm] libdrmtap {so_ver[0]}.{so_ver[1]}.{so_ver[2]} satisfies the runtime ABI gate '
|
||||
f'(major {major}, minor {minor}, patch >= {floor[1]})')
|
||||
f'(major {major}, {floor[0]}.{floor[1]} up to minor {minor})')
|
||||
|
||||
|
||||
def stage_libdrmtap_into_deb(so_path):
|
||||
|
||||
@@ -14,7 +14,7 @@ wayland = ["gstreamer", "gstreamer-app", "gstreamer-video", "dbus", "tracing", "
|
||||
# `drm` is a pure runtime-dlopen backend: rustdesk loads `libdrmtap.so.0` at runtime (`drmtap_dl.rs`)
|
||||
# and NEVER link-time links it, so the graceful PipeWire fallback when the .so or EGL is absent is
|
||||
# preserved and the drm build pulls in no libdrm/seccomp/cap/EGL link-time deps. The .so is pinned by
|
||||
# `DRMTAP_SHA` in build.py, which fetches that exact commit (libdrmtap v0.5.12). We deliberately do
|
||||
# `DRMTAP_SHA` in build.py, which fetches that exact commit (libdrmtap v0.6.1). We deliberately do
|
||||
# NOT depend on the `libdrmtap-sys` crate: its build.rs statically compiles the whole libdrmtap C tree
|
||||
# and a CAP_SYS_ADMIN helper and emits `-ldrm -lseccomp -lcap`, which would defeat the dlopen model.
|
||||
# Depends on `wayland`: the three drm modules live inside the `#[cfg(feature = "wayland")]` arm of
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use super::drmtap_dl::{
|
||||
self, drmtap_config, drmtap_ctx, drmtap_cursor_info, drmtap_device, drmtap_display,
|
||||
drmtap_dmabuf_desc, drmtap_frame_info, DrmtapLib,
|
||||
drmtap_dmabuf_desc, drmtap_frame_info, drmtap_packet, DrmtapLib,
|
||||
};
|
||||
use hbb_common::log;
|
||||
use std::ffi::CString;
|
||||
@@ -666,6 +666,62 @@ impl DrmReader {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn has_packet(&self) -> bool {
|
||||
self.lib.packet.is_some()
|
||||
}
|
||||
|
||||
/// libdrmtap 0.6 packet grab: every lit plane of the CRTC, so also a window the compositor
|
||||
/// put on an overlay or underlay plane, as opaque bytes plus a CLOEXEC dup of each of its
|
||||
/// read-only dma-buf fds, in order. Errors map like `grab_desc`. Needs `has_packet()`. The
|
||||
/// rotation of the frame is known only after the convert, so it is asked on that side.
|
||||
pub fn grab_packet(&mut self) -> io::Result<(Vec<u8>, Vec<OwnedFd>)> {
|
||||
let Some((grab, release, _)) = self.lib.packet else {
|
||||
return Err(io::ErrorKind::Unsupported.into());
|
||||
};
|
||||
// SAFETY: self.ctx is valid and `pkt` zeroed caller storage. A successful grab owns its
|
||||
// fds until `release`, which runs after they are dup'd; a failed grab owns none.
|
||||
unsafe {
|
||||
let mut pkt: drmtap_packet = std::mem::zeroed();
|
||||
let ret = grab(self.ctx, &mut pkt);
|
||||
if ret < 0 {
|
||||
let errno = -ret;
|
||||
if errno == hbb_common::libc::EAGAIN
|
||||
|| errno == hbb_common::libc::EBUSY
|
||||
|| errno == hbb_common::libc::EINTR
|
||||
{
|
||||
return Err(io::ErrorKind::WouldBlock.into());
|
||||
}
|
||||
// More than four lit planes and none of the kept ones covers the CRTC: keep the
|
||||
// last frame, like grab_desc does on an underlay.
|
||||
if errno == hbb_common::libc::E2BIG {
|
||||
return Err(io::ErrorKind::WouldBlock.into());
|
||||
}
|
||||
if errno == hbb_common::libc::ENOTSUP {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::Unsupported,
|
||||
"drmtap_grab_packet: no transferable dma-buf (ENOTSUP)",
|
||||
));
|
||||
}
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!("drmtap_grab_packet failed: errno {errno}"),
|
||||
));
|
||||
}
|
||||
let bytes = pkt.bytes[..(pkt.len as usize).min(pkt.bytes.len())].to_vec();
|
||||
let fds = pkt.fds[..(pkt.nfds as usize).min(pkt.fds.len())]
|
||||
.iter()
|
||||
.map(|&fd| {
|
||||
match hbb_common::libc::fcntl(fd, hbb_common::libc::F_DUPFD_CLOEXEC, 0) {
|
||||
d if d >= 0 => Ok(OwnedFd::from_raw_fd(d)),
|
||||
_ => Err(io::Error::last_os_error()),
|
||||
}
|
||||
})
|
||||
.collect::<io::Result<Vec<_>>>();
|
||||
release(&mut pkt);
|
||||
fds.map(|fds| (bytes, fds))
|
||||
}
|
||||
}
|
||||
|
||||
/// Read the hardware cursor plane: the hidden sentinel when the plane reports the cursor invisible, the real shape when visible, and `None` when the read fails.
|
||||
pub fn cursor(&mut self) -> Option<CursorSnapshot> {
|
||||
// SAFETY: ctx valid; c zeroed; released on EVERY path after a successful get_cursor. Only a failed get_cursor returns without releasing, because then there is nothing to release.
|
||||
@@ -912,7 +968,7 @@ const DRM_MODE_ROTATE_0: u32 = 1 << 0;
|
||||
/// turned the scanout, so the frame arrives turned by the whole output transform, which is the
|
||||
/// virtio-gpu and vmwgfx case this exists for. Anything else (`-ENOENT` with no plane bound, a
|
||||
/// failed property read) is `None`, and the consumer keeps its pre-0.5.8 rule.
|
||||
fn plane_rotation_answer(rc: c_int, rotation: u32) -> Option<u32> {
|
||||
pub(super) fn plane_rotation_answer(rc: c_int, rotation: u32) -> Option<u32> {
|
||||
if rc == 0 {
|
||||
Some(rotation)
|
||||
} else if rc == -hbb_common::libc::ENOTSUP {
|
||||
|
||||
@@ -170,6 +170,97 @@ impl RenderConverter {
|
||||
Ok((data, w, h, pixfmt))
|
||||
}
|
||||
}
|
||||
|
||||
/// Composes a packet from `DrmReader::grab_packet` into one CRTC-sized frame; libdrmtap checks
|
||||
/// the bytes and every fd before it uses them. Same output contract and checks as `convert()`.
|
||||
pub fn convert_packet(
|
||||
&mut self,
|
||||
bytes: &[u8],
|
||||
fds: &[RawFd],
|
||||
) -> io::Result<(&[u8], u32, u32, Pixfmt)> {
|
||||
let Some((_, _, convert_packet)) = self.lib.packet else {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
"drm: libdrmtap has no packet API",
|
||||
));
|
||||
};
|
||||
// SAFETY: self.ctx is a valid render context; `bytes` and `fds` are only read during the
|
||||
// call; `frame` is zeroed and libdrmtap owns its pixels, as in `convert()`.
|
||||
unsafe {
|
||||
let mut frame: drmtap_frame_info = std::mem::zeroed();
|
||||
let ret = convert_packet(
|
||||
self.ctx,
|
||||
bytes.as_ptr(),
|
||||
bytes.len(),
|
||||
fds.as_ptr(),
|
||||
fds.len(),
|
||||
&mut frame,
|
||||
);
|
||||
if ret < 0 {
|
||||
let errno = -ret;
|
||||
if errno == hbb_common::libc::EAGAIN
|
||||
|| errno == hbb_common::libc::EBUSY
|
||||
|| errno == hbb_common::libc::EINTR
|
||||
{
|
||||
return Err(io::ErrorKind::WouldBlock.into());
|
||||
}
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!("drmtap_convert_packet failed: errno {errno}"),
|
||||
));
|
||||
}
|
||||
if frame.data.is_null() || frame.width == 0 || frame.height == 0 || frame.stride == 0 {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
"drmtap_convert_packet produced an empty frame",
|
||||
));
|
||||
}
|
||||
let w = frame.width;
|
||||
let h = frame.height;
|
||||
let stride = frame.stride as usize;
|
||||
if w > MAX_DIM || h > MAX_DIM || stride < (w as usize) * 4 {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!(
|
||||
"drmtap_convert_packet bad geometry {w}x{h} stride {stride} fourcc {:#010x}",
|
||||
frame.format
|
||||
),
|
||||
));
|
||||
}
|
||||
let len = match stride.checked_mul(h as usize) {
|
||||
Some(sz) if sz > 0 && sz <= MAX_FRAME_BYTES => sz,
|
||||
other => {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!("drmtap_convert_packet frame size out of range ({other:?} bytes)"),
|
||||
));
|
||||
}
|
||||
};
|
||||
let pixfmt = match frame.format {
|
||||
DRM_FORMAT_XRGB8888 | DRM_FORMAT_ARGB8888 => Pixfmt::BGRA,
|
||||
DRM_FORMAT_XBGR8888 | DRM_FORMAT_ABGR8888 => Pixfmt::RGBA,
|
||||
other => {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!("drmtap_convert_packet produced an unsupported output fourcc {other:#010x}"),
|
||||
));
|
||||
}
|
||||
};
|
||||
let data = std::slice::from_raw_parts(frame.data as *const u8, len);
|
||||
Ok((data, w, h, pixfmt))
|
||||
}
|
||||
}
|
||||
|
||||
/// The DRM `rotation` of the frame the last `convert_packet` produced: rotate-0 for a composed
|
||||
/// frame, the plane's own for one layer converted as its buffer. Same answers as
|
||||
/// `DrmReader::plane_rotation`.
|
||||
pub fn plane_rotation(&mut self) -> Option<u32> {
|
||||
let f = self.lib.plane_rotation?;
|
||||
let mut rotation: u32 = 0;
|
||||
// SAFETY: self.ctx is a live context and `rotation` outlives the call.
|
||||
let rc = unsafe { f(self.ctx, &mut rotation) };
|
||||
super::drm_reader::plane_rotation_answer(rc, rotation)
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for RenderConverter {
|
||||
|
||||
@@ -116,6 +116,16 @@ pub struct drmtap_cursor_info {
|
||||
pub _priv: *mut c_void,
|
||||
}
|
||||
|
||||
/// `drmtap_packet` (libdrmtap 0.6.0): every lit plane of the CRTC as opaque bytes plus their
|
||||
/// dma-buf fds, filled by `drmtap_grab_packet` and handed as is to `drmtap_convert_packet`.
|
||||
#[repr(C)]
|
||||
pub struct drmtap_packet {
|
||||
pub bytes: [u8; 1024],
|
||||
pub len: u32,
|
||||
pub nfds: u32,
|
||||
pub fds: [c_int; 16],
|
||||
}
|
||||
|
||||
// Resolved symbol typedefs.
|
||||
|
||||
type FnVersion = unsafe extern "C" fn() -> c_int;
|
||||
@@ -152,6 +162,17 @@ type FnPlaneRotation = unsafe extern "C" fn(*mut drmtap_ctx, *mut u32) -> c_int;
|
||||
type FnCrtcRefresh = unsafe extern "C" fn(*mut drmtap_ctx, *mut u64, *mut u64) -> c_int;
|
||||
type FnConvertDmabuf =
|
||||
unsafe extern "C" fn(*mut drmtap_ctx, *const drmtap_dmabuf_desc, *mut drmtap_frame_info) -> c_int;
|
||||
type FnGrabPacket = unsafe extern "C" fn(*mut drmtap_ctx, *mut drmtap_packet) -> c_int;
|
||||
type FnPacketRelease = unsafe extern "C" fn(*mut drmtap_packet);
|
||||
type FnConvertPacket = unsafe extern "C" fn(
|
||||
*mut drmtap_ctx,
|
||||
*const u8,
|
||||
usize,
|
||||
*const c_int,
|
||||
usize,
|
||||
*mut drmtap_frame_info,
|
||||
) -> c_int;
|
||||
type FnAbi = unsafe extern "C" fn(*mut u32, *mut u32);
|
||||
|
||||
/// The dlopen'd libdrmtap; the `Library` is kept alive for the process lifetime, so the raw fn pointers stay valid.
|
||||
pub struct DrmtapLib {
|
||||
@@ -178,6 +199,9 @@ pub struct DrmtapLib {
|
||||
/// Optional: it only exists from libdrmtap 0.5.9. Absent means the producer takes the
|
||||
/// whole-hertz refresh of the enumeration as its pacing floor.
|
||||
pub crtc_refresh: Option<FnCrtcRefresh>,
|
||||
/// Optional: grab, release and convert of libdrmtap 0.6.0, all three or none. Absent means
|
||||
/// frames travel as one `drmtap_dmabuf_desc`, as before.
|
||||
pub packet: Option<(FnGrabPacket, FnPacketRelease, FnConvertPacket)>,
|
||||
pub version: (c_int, c_int, c_int),
|
||||
}
|
||||
|
||||
@@ -229,6 +253,7 @@ impl DrmtapLib {
|
||||
render_node: None,
|
||||
plane_rotation: Some(plane_rotation),
|
||||
crtc_refresh: None,
|
||||
packet: None,
|
||||
version: (0, 5, 8),
|
||||
}
|
||||
}
|
||||
@@ -246,14 +271,18 @@ const DRMTAP_ABI_MAJOR: c_int = 0;
|
||||
// has been present since 0.4.10.
|
||||
const DRMTAP_MIN_MINOR_PATCH: (c_int, c_int) = (5, 0);
|
||||
|
||||
// The MINOR series this build's mirrored structs were verified against: libdrmtap's header freezes
|
||||
// only `drmtap_device` and `drmtap_dmabuf_desc`, so an unverified minor could be read at wrong offsets.
|
||||
const DRMTAP_ABI_MINOR: c_int = 5;
|
||||
// The newest MINOR series this build's mirrored structs were verified against: libdrmtap's header
|
||||
// freezes only `drmtap_device`, `drmtap_dmabuf_desc` and `drmtap_packet`, so an unverified minor
|
||||
// could be read at wrong offsets. 0.6 changed none of the structs 0.5 mirrors.
|
||||
const DRMTAP_ABI_MINOR: c_int = 6;
|
||||
// `DRMTAP_ABI_LEVEL` of the header this build mirrors (0.6.0). Level 2 adds the packet API; a
|
||||
// library without `drmtap_abi` (0.5.x) is level 1.
|
||||
const DRMTAP_ABI_LEVEL: u32 = 2;
|
||||
|
||||
/// Whether a library reporting `major.minor.patch` may be loaded (major and minor exact, patch at or above the floor).
|
||||
/// Whether a library reporting `major.minor.patch` may be loaded (major exact, minor not newer than the verified one, at or above the floor).
|
||||
fn abi_accepted(major: c_int, minor: c_int, patch: c_int) -> bool {
|
||||
major == DRMTAP_ABI_MAJOR
|
||||
&& minor == DRMTAP_ABI_MINOR
|
||||
&& minor <= DRMTAP_ABI_MINOR
|
||||
&& (minor, patch) >= DRMTAP_MIN_MINOR_PATCH
|
||||
}
|
||||
|
||||
@@ -302,8 +331,8 @@ impl DrmtapLib {
|
||||
let why = if major != DRMTAP_ABI_MAJOR {
|
||||
"the struct layouts this build mirrors track the ABI major, so reading a \
|
||||
frame descriptor through a mismatched one would mis-decode it"
|
||||
} else if minor != DRMTAP_ABI_MINOR {
|
||||
"this build mirrors the struct layouts of one minor and only that one; \
|
||||
} else if minor > DRMTAP_ABI_MINOR {
|
||||
"this build mirrors the struct layouts of the minors it was verified against; \
|
||||
under 0.x semver the minor is the breaking axis, so an unverified minor \
|
||||
could be read at the wrong offsets. Widening it is a deliberate act, done \
|
||||
with the layouts re-checked field by field"
|
||||
@@ -314,12 +343,29 @@ impl DrmtapLib {
|
||||
let (min_minor, min_patch) = DRMTAP_MIN_MINOR_PATCH;
|
||||
log::warn!(
|
||||
"libdrmtap {name} reports v{major}.{minor}.{patch}, which this build cannot \
|
||||
use (needs ABI major {DRMTAP_ABI_MAJOR}, minor {DRMTAP_ABI_MINOR}, at least \
|
||||
use (needs ABI major {DRMTAP_ABI_MAJOR}, minor at most {DRMTAP_ABI_MINOR}, at least \
|
||||
v{DRMTAP_ABI_MAJOR}.{min_minor}.{min_patch}): {why}. Refusing to load; \
|
||||
falling back to PipeWire/portal."
|
||||
);
|
||||
return None;
|
||||
}
|
||||
// The level range the library serves; it must include the level this build was written for.
|
||||
let abi_level = match lib.get::<FnAbi>(b"drmtap_abi") {
|
||||
Ok(abi) => {
|
||||
let (mut current, mut oldest) = (0u32, 0u32);
|
||||
abi(&mut current, &mut oldest);
|
||||
if !(oldest..=current).contains(&DRMTAP_ABI_LEVEL) {
|
||||
log::warn!(
|
||||
"libdrmtap {name} v{major}.{minor}.{patch} serves ABI levels \
|
||||
{oldest}..={current}, not {DRMTAP_ABI_LEVEL}. Refusing to load; \
|
||||
falling back to PipeWire/portal."
|
||||
);
|
||||
return None;
|
||||
}
|
||||
current
|
||||
}
|
||||
Err(_) => 1,
|
||||
};
|
||||
let open: FnOpen = *lib.get(b"drmtap_open").ok()?;
|
||||
let close: FnClose = *lib.get(b"drmtap_close").ok()?;
|
||||
let list_displays: FnListDisplays = *lib.get(b"drmtap_list_displays").ok()?;
|
||||
@@ -363,6 +409,16 @@ impl DrmtapLib {
|
||||
lib.get(b"drmtap_plane_rotation").ok().map(|s| *s);
|
||||
let crtc_refresh: Option<FnCrtcRefresh> =
|
||||
lib.get(b"drmtap_crtc_refresh").ok().map(|s| *s);
|
||||
let packet = (|| {
|
||||
if abi_level < 2 {
|
||||
return None;
|
||||
}
|
||||
Some((
|
||||
*lib.get::<FnGrabPacket>(b"drmtap_grab_packet").ok()?,
|
||||
*lib.get::<FnPacketRelease>(b"drmtap_packet_release").ok()?,
|
||||
*lib.get::<FnConvertPacket>(b"drmtap_convert_packet").ok()?,
|
||||
))
|
||||
})();
|
||||
// Log the load only now that every required symbol resolved: this fn still returns None on a missing one.
|
||||
let loaded_from = real
|
||||
.as_ref()
|
||||
@@ -439,6 +495,7 @@ impl DrmtapLib {
|
||||
render_node,
|
||||
plane_rotation,
|
||||
crtc_refresh,
|
||||
packet,
|
||||
version: (major, minor, patch),
|
||||
})
|
||||
}
|
||||
@@ -462,7 +519,9 @@ pub fn get() -> Option<&'static DrmtapLib> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{abi_accepted, DRMTAP_ABI_MAJOR, DRMTAP_ABI_MINOR, DRMTAP_MIN_MINOR_PATCH};
|
||||
use super::{
|
||||
abi_accepted, drmtap_packet, DRMTAP_ABI_MAJOR, DRMTAP_ABI_MINOR, DRMTAP_MIN_MINOR_PATCH,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn abi_gate_accepts_the_floor_and_later_patches_of_the_same_minor() {
|
||||
@@ -474,6 +533,8 @@ mod tests {
|
||||
"v0.{minor}.{patch} is a patch of the verified minor and must be accepted"
|
||||
);
|
||||
}
|
||||
// Accepting 0.6 relies on its frozen `drmtap_packet`: bytes[1024], len, nfds, fds[16].
|
||||
assert_eq!(std::mem::size_of::<drmtap_packet>(), 1024 + 4 + 4 + 16 * 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -481,16 +542,17 @@ mod tests {
|
||||
// Relative to DRMTAP_ABI_MINOR, so the next bump cannot leave this test asserting that the
|
||||
// NEW verified minor must be refused -- which is what a hardcoded list did before.
|
||||
let verified = DRMTAP_ABI_MINOR;
|
||||
for (minor, patch) in [
|
||||
(verified - 1, 99),
|
||||
(verified + 1, 0),
|
||||
(verified + 1, 99),
|
||||
(verified + 4, 9),
|
||||
] {
|
||||
for (minor, patch) in [(verified + 1, 0), (verified + 1, 99), (verified + 4, 9)] {
|
||||
assert!(
|
||||
!abi_accepted(DRMTAP_ABI_MAJOR, minor, patch),
|
||||
"v0.{minor}.{patch} is an unverified minor and must be refused"
|
||||
);
|
||||
}
|
||||
// Below the floor (0.4.x) is refused too.
|
||||
let below = DRMTAP_MIN_MINOR_PATCH.0 - 1;
|
||||
assert!(
|
||||
!abi_accepted(DRMTAP_ABI_MAJOR, below, 99),
|
||||
"v0.{below}.99 is below the floor"
|
||||
);
|
||||
}
|
||||
}
|
||||
+7
-1
@@ -550,7 +550,13 @@ pub enum Data {
|
||||
// (drmtap_open_render failed, e.g. no /dev/dri/renderD* access). The service then streams the
|
||||
// CPU-converted `DrmFrame` path for this connection instead of a dma-buf fd the consumer cannot
|
||||
// detile, so a render-node-less seat still captures instead of losing the stream.
|
||||
DrmStart { display: i32, need_cpu: bool },
|
||||
// `no_packet`: a libdrmtap packet failed to convert here, so stream one descriptor instead.
|
||||
DrmStart {
|
||||
display: i32,
|
||||
need_cpu: bool,
|
||||
#[serde(default)]
|
||||
no_packet: bool,
|
||||
},
|
||||
/// Service -> client: the enumerated DRM displays (sent once, before frames).
|
||||
#[cfg(all(target_os = "linux", feature = "drm"))]
|
||||
DrmDisplayList(Vec<DrmDisplayInfo>),
|
||||
|
||||
+162
-89
@@ -2,7 +2,7 @@
|
||||
|
||||
use super::ipc_auth::active_uid_cached;
|
||||
use super::*;
|
||||
use std::os::fd::{AsFd, AsRawFd, BorrowedFd, FromRawFd, OwnedFd, RawFd};
|
||||
use std::os::fd::{AsRawFd, BorrowedFd, FromRawFd, OwnedFd, RawFd};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
|
||||
pub struct DrmDisplayInfo {
|
||||
@@ -27,11 +27,14 @@ pub struct DrmDisplayInfo {
|
||||
/// mode TRANSPOSED whatever the compositor reports (gamescope's wl_output has no transform).
|
||||
#[serde(default)]
|
||||
pub plane_transposed: bool,
|
||||
/// The primary plane's `rotation` mask at enumeration; None when it cannot be read.
|
||||
#[serde(default)]
|
||||
pub primary_rotation: Option<u32>,
|
||||
}
|
||||
|
||||
/// Mirrors `scrap::drm_reader::drmtap_dmabuf_desc` except `dma_buf_fd` (never serializes — it rides
|
||||
/// SCM_RIGHTS ancillary), and adds `buffer_id` (fb_id tagged with a per-connection epoch; no consumer reads it today) and `has_fd`.
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
/// SCM_RIGHTS ancillary), and adds `buffer_id` (fb_id tagged with a per-connection epoch; no consumer reads it today), `has_fd` and `packet`.
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||
pub struct DmabufDesc {
|
||||
pub buffer_id: u64,
|
||||
pub width: u32,
|
||||
@@ -64,6 +67,10 @@ pub struct DmabufDesc {
|
||||
/// capture worker; the consumer only acts on a position that held still for several frames.
|
||||
#[serde(default)]
|
||||
pub cursor_pos: Option<(i32, i32)>,
|
||||
/// Non-empty: a libdrmtap 0.6 packet (every lit plane of the CRTC, opaque) that replaces the
|
||||
/// geometry fields above, and every fd of this message belongs to it, in order.
|
||||
#[serde(default)]
|
||||
pub packet: Vec<u8>,
|
||||
}
|
||||
|
||||
pub(crate) fn drm_ipc_path() -> String {
|
||||
@@ -109,11 +116,8 @@ fn new_drm_listener() -> ResultType<Incoming> {
|
||||
enum DrmProducerMsg {
|
||||
/// Enumerated displays, sent once before any frame.
|
||||
Displays(Vec<DrmDisplayInfo>),
|
||||
/// Zero-copy path: descriptor + scanout fd; the `OwnedFd` is closed once the send has dup'd it.
|
||||
Frame {
|
||||
desc: DmabufDesc,
|
||||
fd: Option<OwnedFd>,
|
||||
},
|
||||
/// Zero-copy path: descriptor + scanout fd(s); the `OwnedFd`s are closed once the send has dup'd them.
|
||||
Frame { desc: DmabufDesc, fds: Vec<OwnedFd> },
|
||||
/// CPU-mapped fallback (packed BGRA): consumer has no convert context (`need_cpu`), or ENOTSUP.
|
||||
FrameCpu {
|
||||
width: u32,
|
||||
@@ -167,6 +171,7 @@ mod cursor_pos_tests {
|
||||
has_fd: false,
|
||||
plane_rotation: None,
|
||||
cursor_pos: None,
|
||||
packet: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +194,10 @@ mod cursor_pos_tests {
|
||||
let visible = snapshot(7);
|
||||
let hidden = snapshot(scrap::drm_reader::HIDDEN_CURSOR_ID);
|
||||
|
||||
let mut frame = DrmProducerMsg::Frame { desc: desc(), fd: None };
|
||||
let mut frame = DrmProducerMsg::Frame {
|
||||
desc: desc(),
|
||||
fds: vec![],
|
||||
};
|
||||
stamp_cursor_pos(&mut frame, Some(&visible));
|
||||
assert!(matches!(&frame, DrmProducerMsg::Frame { desc, .. } if desc.cursor_pos == Some((10, 20))));
|
||||
stamp_cursor_pos(&mut frame, Some(&hidden));
|
||||
@@ -277,17 +285,22 @@ fn drm_displays_from_reader(
|
||||
}
|
||||
true
|
||||
})
|
||||
.map(|d| DrmDisplayInfo {
|
||||
plane_transposed: plane_transposed(device, d.crtc_id),
|
||||
name: d.name,
|
||||
crtc_id: d.crtc_id,
|
||||
x: d.x,
|
||||
y: d.y,
|
||||
width: d.width,
|
||||
height: d.height,
|
||||
active: d.active,
|
||||
render_node: render_node.clone(),
|
||||
device: device.to_owned(),
|
||||
.map(|d| {
|
||||
let primary_rotation = primary_rotation(device, d.crtc_id);
|
||||
DrmDisplayInfo {
|
||||
plane_transposed: primary_rotation
|
||||
.is_some_and(|m| m & (DRM_MODE_ROTATE_90 | DRM_MODE_ROTATE_270) != 0),
|
||||
primary_rotation,
|
||||
name: d.name,
|
||||
crtc_id: d.crtc_id,
|
||||
x: d.x,
|
||||
y: d.y,
|
||||
width: d.width,
|
||||
height: d.height,
|
||||
active: d.active,
|
||||
render_node: render_node.clone(),
|
||||
device: device.to_owned(),
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
(displays, undriven)
|
||||
@@ -298,26 +311,24 @@ const DRM_MODE_ROTATE_270: u32 = 0x8;
|
||||
|
||||
/// Through a reader bound to `crtc_id`: the enumerating reader is bound to whichever crtc
|
||||
/// auto-select picked.
|
||||
fn plane_transposed(device: &str, crtc_id: u32) -> bool {
|
||||
fn primary_rotation(device: &str, crtc_id: u32) -> Option<u32> {
|
||||
let dev = (!device.is_empty()).then_some(device);
|
||||
let Some(mut r) = scrap::drm_reader::DrmReader::open(dev, crtc_id) else {
|
||||
return false;
|
||||
};
|
||||
let transposed = match r.query_plane_rotation() {
|
||||
Some(m) => m & (DRM_MODE_ROTATE_90 | DRM_MODE_ROTATE_270) != 0,
|
||||
let mut r = scrap::drm_reader::DrmReader::open(dev, crtc_id)?;
|
||||
let rotation = r.query_plane_rotation();
|
||||
match rotation {
|
||||
Some(m) if m & (DRM_MODE_ROTATE_90 | DRM_MODE_ROTATE_270) != 0 => {
|
||||
log::trace!("drm: crtc {crtc_id} ({device:?}) is rotated 90/270 by its plane");
|
||||
}
|
||||
Some(_) => {}
|
||||
None => {
|
||||
hbb_common::throttled_log!(
|
||||
std::time::Duration::from_secs(600),
|
||||
debug,
|
||||
"drm: crtc {crtc_id} ({device:?}): plane rotation unreadable; sized as unrotated"
|
||||
);
|
||||
false
|
||||
}
|
||||
};
|
||||
if transposed {
|
||||
log::trace!("drm: crtc {crtc_id} ({device:?}) is rotated 90/270 by its plane");
|
||||
}
|
||||
transposed
|
||||
rotation
|
||||
}
|
||||
|
||||
/// Active displays of every DRM device + the connected-but-undriven identities, from ONE look.
|
||||
@@ -961,7 +972,7 @@ async fn handle_drm_conn(stream: Connection) -> ResultType<()> {
|
||||
};
|
||||
|
||||
let (frame_tx, mut frame_rx) = tokio::sync::mpsc::channel::<DrmProducerMsg>(2);
|
||||
let (crtc_tx, crtc_rx) = std::sync::mpsc::channel::<(String, u32, bool)>();
|
||||
let (crtc_tx, crtc_rx) = std::sync::mpsc::channel::<(String, u32, bool, bool)>();
|
||||
let stop = Arc::new(AtomicBool::new(false));
|
||||
let _stop_guard = DrmStopGuard(stop.clone());
|
||||
let worker_stop = stop.clone();
|
||||
@@ -992,8 +1003,15 @@ async fn handle_drm_conn(stream: Connection) -> ResultType<()> {
|
||||
};
|
||||
conn.send_msg(&Data::DrmDisplayList(displays.clone()), None).await?;
|
||||
|
||||
let (display_idx, need_cpu) = match conn.recv_msg_timeout2(10_000).await {
|
||||
Some(Ok((Data::DrmStart { display, need_cpu }, _fd))) => (display, need_cpu),
|
||||
let (display_idx, need_cpu, no_packet) = match conn.recv_msg_timeout2(10_000).await {
|
||||
Some(Ok((
|
||||
Data::DrmStart {
|
||||
display,
|
||||
need_cpu,
|
||||
no_packet,
|
||||
},
|
||||
_fd,
|
||||
))) => (display, need_cpu, no_packet),
|
||||
Some(Ok((_, _fd))) => {
|
||||
log::info!("drm: peer sent something other than DrmStart in the handshake; closing");
|
||||
return Ok(());
|
||||
@@ -1013,7 +1031,10 @@ async fn handle_drm_conn(stream: Connection) -> ResultType<()> {
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
if crtc_tx.send((target_device, target_crtc, need_cpu)).is_err() {
|
||||
if crtc_tx
|
||||
.send((target_device, target_crtc, need_cpu, no_packet))
|
||||
.is_err()
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -1125,18 +1146,18 @@ async fn handle_drm_conn(stream: Connection) -> ResultType<()> {
|
||||
continue;
|
||||
}
|
||||
match latest_frame {
|
||||
Some(DrmProducerMsg::Frame { mut desc, fd }) => {
|
||||
Some(DrmProducerMsg::Frame { mut desc, fds }) => {
|
||||
// Every exported frame carries its fd: the kernel can recycle an fb_id onto another
|
||||
// buffer with the same geometry/modifier and this side cannot see the dma-buf inode
|
||||
// that would tell the difference, so eliding it can serve a stale EGLImage. libdrmtap's
|
||||
// import cache keys on fb_id AND inode, and can only re-import when handed a real fd.
|
||||
let send_fd = fd.is_some();
|
||||
desc.has_fd = send_fd;
|
||||
let borrowed = if send_fd { fd.as_ref().map(|f| f.as_fd()) } else { None };
|
||||
conn.send_msg(&Data::DrmFrameDmabuf(desc), borrowed).await?;
|
||||
desc.has_fd = !fds.is_empty();
|
||||
let raw: Vec<RawFd> = fds.iter().map(|f| f.as_raw_fd()).collect();
|
||||
let payload = serde_json::to_vec(&Data::DrmFrameDmabuf(desc))?;
|
||||
drm_send_frame(&conn.stream, &payload, &raw).await?;
|
||||
credit -= 1; // one frame in flight until the consumer acks it
|
||||
// `fd` (OwnedFd) is closed here whether or not it was attached (the cmsg dup'd it
|
||||
// into the peer), which bounds our fd usage to ~1 in flight per frame.
|
||||
// `fds` (OwnedFd) are closed here whether or not attached (the cmsg dup'd them
|
||||
// into the peer), which bounds our fd usage to one frame's fds in flight.
|
||||
}
|
||||
Some(DrmProducerMsg::FrameCpu {
|
||||
width,
|
||||
@@ -1260,7 +1281,7 @@ fn drm_worker_wake(now: std::time::Instant, next_frame: std::time::Instant) -> s
|
||||
|
||||
fn drm_capture_worker(
|
||||
frame_tx: tokio::sync::mpsc::Sender<DrmProducerMsg>,
|
||||
crtc_rx: std::sync::mpsc::Receiver<(String, u32, bool)>,
|
||||
crtc_rx: std::sync::mpsc::Receiver<(String, u32, bool, bool)>,
|
||||
stop: std::sync::Arc<std::sync::atomic::AtomicBool>,
|
||||
frames_gated: std::sync::Arc<std::sync::atomic::AtomicBool>,
|
||||
demand_fps: std::sync::Arc<std::sync::atomic::AtomicU8>,
|
||||
@@ -1287,7 +1308,7 @@ fn drm_capture_worker(
|
||||
return;
|
||||
}
|
||||
|
||||
let (target_device, target_crtc, need_cpu) = match crtc_rx.recv() {
|
||||
let (target_device, target_crtc, need_cpu, no_packet) = match crtc_rx.recv() {
|
||||
Ok(c) => c,
|
||||
Err(_) => return,
|
||||
};
|
||||
@@ -1333,6 +1354,17 @@ fn drm_capture_worker(
|
||||
// `stalled` is left untouched because the device is healthy -- the task bounds this
|
||||
// state itself (CREDIT_STALL) since our watchdog cannot advance.
|
||||
None
|
||||
} else if use_dmabuf && reader.has_packet() && !no_packet {
|
||||
// libdrmtap 0.6 on both ends (one deb): the packet also carries a window the compositor
|
||||
// put on its own plane, which one descriptor cannot.
|
||||
Some(reader.grab_packet().map(|(packet, fds)| DrmProducerMsg::Frame {
|
||||
// No plane_rotation: the consumer asks its converting context after the convert.
|
||||
desc: DmabufDesc {
|
||||
packet,
|
||||
..Default::default()
|
||||
},
|
||||
fds,
|
||||
}))
|
||||
} else if use_dmabuf {
|
||||
// Read right after the grab: the library answers for the plane that grab read from.
|
||||
Some(match reader.grab_desc() {
|
||||
@@ -1352,8 +1384,9 @@ fn drm_capture_worker(
|
||||
has_fd: true, // every exported frame carries its fd; see the send below
|
||||
plane_rotation: reader.plane_rotation(),
|
||||
cursor_pos: None, // stamped below, from the one cursor read of this tick
|
||||
packet: Vec::new(),
|
||||
},
|
||||
fd: Some(fd),
|
||||
fds: vec![fd],
|
||||
}),
|
||||
Err(err) => Err(err),
|
||||
})
|
||||
@@ -1391,7 +1424,11 @@ fn drm_capture_worker(
|
||||
log::debug!(
|
||||
"drm: first frame for crtc {target_crtc} in {:?} ({} path)",
|
||||
t_conn.elapsed(),
|
||||
if use_dmabuf { "dma-buf" } else { "cpu" }
|
||||
match (use_dmabuf, reader.has_packet() && !no_packet) {
|
||||
(true, true) => "dma-buf packet",
|
||||
(true, false) => "dma-buf",
|
||||
(false, _) => "cpu",
|
||||
}
|
||||
);
|
||||
}
|
||||
if frame_tx.blocking_send(msg).is_err() {
|
||||
@@ -1411,7 +1448,7 @@ fn drm_capture_worker(
|
||||
}
|
||||
Some(Err(err)) if use_dmabuf && err.kind() == std::io::ErrorKind::Unsupported => {
|
||||
log::warn!(
|
||||
"drm: grab_desc unsupported ({err}); switching to CPU-mapped fallback for this connection"
|
||||
"drm: dma-buf grab unsupported ({err}); switching to CPU-mapped fallback for this connection"
|
||||
);
|
||||
use_dmabuf = false;
|
||||
logged_first = false;
|
||||
@@ -1504,17 +1541,19 @@ const DRM_BODY_TIMEOUT_MS: u64 = 5_000;
|
||||
const DRM_SEND_TIMEOUT_MS: u64 = 5_000;
|
||||
|
||||
const MAX_DRM_RAW_BYTES: usize = 512 * 1024 * 1024;
|
||||
/// `CMSG_SPACE(sizeof(int))` is 24 bytes on our targets; 64 gives headroom and the `align(8)`
|
||||
/// matches `cmsghdr` alignment.
|
||||
const DRM_CMSG_CAP: usize = 64;
|
||||
/// Most fds one message carries: the 16 of a libdrmtap packet.
|
||||
const DRM_MAX_FDS: usize = 16;
|
||||
/// `CMSG_SPACE` of `DRM_MAX_FDS` ints is 80 bytes on our targets; 128 gives headroom and the
|
||||
/// `align(8)` matches `cmsghdr` alignment. More fds than fit truncate (MSG_CTRUNC) and are refused.
|
||||
const DRM_CMSG_CAP: usize = 128;
|
||||
|
||||
/// Aligned storage for the SCM_RIGHTS control buffer (`msg_control` must be `cmsghdr`-aligned).
|
||||
#[repr(align(8))]
|
||||
struct DrmCmsgBuf([u8; DRM_CMSG_CAP]);
|
||||
|
||||
/// One non-blocking `sendmsg`; the cmsg is attached ONLY when a fd is present (-1 fails the call).
|
||||
/// SAFETY: `fd` a valid open socket fd, `buf` a readable slice, `pass_fd` (if any) a valid open fd.
|
||||
unsafe fn drm_sendmsg(fd: RawFd, buf: &[u8], pass_fd: Option<RawFd>) -> std::io::Result<usize> {
|
||||
/// One non-blocking `sendmsg`; the cmsg is attached ONLY when fds are present (-1 fails the call).
|
||||
/// SAFETY: `fd` a valid open socket fd, `buf` a readable slice, every `pass_fds` entry a valid open fd.
|
||||
unsafe fn drm_sendmsg(fd: RawFd, buf: &[u8], pass_fds: &[RawFd]) -> std::io::Result<usize> {
|
||||
use hbb_common::libc;
|
||||
let mut iov = libc::iovec {
|
||||
iov_base: buf.as_ptr() as *mut libc::c_void,
|
||||
@@ -1524,9 +1563,13 @@ unsafe fn drm_sendmsg(fd: RawFd, buf: &[u8], pass_fd: Option<RawFd>) -> std::io:
|
||||
msg.msg_iov = &mut iov;
|
||||
msg.msg_iovlen = 1;
|
||||
let mut cbuf = DrmCmsgBuf([0u8; DRM_CMSG_CAP]);
|
||||
if let Some(sfd) = pass_fd {
|
||||
if pass_fds.len() > DRM_MAX_FDS {
|
||||
return Err(std::io::ErrorKind::InvalidInput.into()); // they would overflow `cbuf`
|
||||
}
|
||||
if !pass_fds.is_empty() {
|
||||
let fds_len = (pass_fds.len() * std::mem::size_of::<libc::c_int>()) as u32;
|
||||
msg.msg_control = cbuf.0.as_mut_ptr() as *mut libc::c_void;
|
||||
msg.msg_controllen = libc::CMSG_SPACE(std::mem::size_of::<libc::c_int>() as u32) as _;
|
||||
msg.msg_controllen = libc::CMSG_SPACE(fds_len) as _;
|
||||
let cmsg = libc::CMSG_FIRSTHDR(&msg);
|
||||
if cmsg.is_null() {
|
||||
return Err(std::io::Error::new(
|
||||
@@ -1536,12 +1579,11 @@ unsafe fn drm_sendmsg(fd: RawFd, buf: &[u8], pass_fd: Option<RawFd>) -> std::io:
|
||||
}
|
||||
(*cmsg).cmsg_level = libc::SOL_SOCKET;
|
||||
(*cmsg).cmsg_type = libc::SCM_RIGHTS;
|
||||
(*cmsg).cmsg_len = libc::CMSG_LEN(std::mem::size_of::<libc::c_int>() as u32) as _;
|
||||
let sfd_c: libc::c_int = sfd;
|
||||
(*cmsg).cmsg_len = libc::CMSG_LEN(fds_len) as _;
|
||||
std::ptr::copy_nonoverlapping(
|
||||
&sfd_c as *const libc::c_int as *const u8,
|
||||
pass_fds.as_ptr() as *const u8,
|
||||
libc::CMSG_DATA(cmsg),
|
||||
std::mem::size_of::<libc::c_int>(),
|
||||
fds_len as usize,
|
||||
);
|
||||
}
|
||||
let n = libc::sendmsg(fd, &msg, libc::MSG_NOSIGNAL);
|
||||
@@ -1552,9 +1594,9 @@ unsafe fn drm_sendmsg(fd: RawFd, buf: &[u8], pass_fd: Option<RawFd>) -> std::io:
|
||||
}
|
||||
}
|
||||
|
||||
/// One non-blocking `recvmsg`: keeps at most one SCM_RIGHTS fd (surplus closed), rejects MSG_CTRUNC.
|
||||
/// One non-blocking `recvmsg`: keeps the SCM_RIGHTS fds in order, rejects MSG_CTRUNC.
|
||||
/// SAFETY: `fd` must be a valid open socket fd; `buf` a valid writable slice.
|
||||
unsafe fn drm_recvmsg(fd: RawFd, buf: &mut [u8]) -> std::io::Result<(usize, Option<OwnedFd>)> {
|
||||
unsafe fn drm_recvmsg(fd: RawFd, buf: &mut [u8]) -> std::io::Result<(usize, Vec<OwnedFd>)> {
|
||||
use hbb_common::libc;
|
||||
let mut iov = libc::iovec {
|
||||
iov_base: buf.as_mut_ptr() as *mut libc::c_void,
|
||||
@@ -1570,7 +1612,7 @@ unsafe fn drm_recvmsg(fd: RawFd, buf: &mut [u8]) -> std::io::Result<(usize, Opti
|
||||
if n < 0 {
|
||||
return Err(std::io::Error::last_os_error());
|
||||
}
|
||||
let mut got: Option<OwnedFd> = None;
|
||||
let mut got: Vec<OwnedFd> = Vec::new();
|
||||
let mut cmsg = libc::CMSG_FIRSTHDR(&msg);
|
||||
while !cmsg.is_null() {
|
||||
if (*cmsg).cmsg_level == libc::SOL_SOCKET && (*cmsg).cmsg_type == libc::SCM_RIGHTS {
|
||||
@@ -1586,10 +1628,7 @@ unsafe fn drm_recvmsg(fd: RawFd, buf: &mut [u8]) -> std::io::Result<(usize, Opti
|
||||
std::mem::size_of::<libc::c_int>(),
|
||||
);
|
||||
if rawfd >= 0 {
|
||||
let owned = OwnedFd::from_raw_fd(rawfd);
|
||||
if got.is_none() {
|
||||
got = Some(owned);
|
||||
} // else: surplus fd, dropped here -> closed
|
||||
got.push(OwnedFd::from_raw_fd(rawfd));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1608,7 +1647,7 @@ unsafe fn drm_recvmsg(fd: RawFd, buf: &mut [u8]) -> std::io::Result<(usize, Opti
|
||||
async fn drm_write_all(
|
||||
stream: &tokio::net::UnixStream,
|
||||
mut buf: &[u8],
|
||||
mut pass_fd: Option<RawFd>,
|
||||
mut pass_fds: &[RawFd],
|
||||
) -> ResultType<()> {
|
||||
// ONE deadline for the whole write: arming it per readiness wait lets a dripping peer re-arm it.
|
||||
let deadline =
|
||||
@@ -1623,13 +1662,13 @@ async fn drm_write_all(
|
||||
}
|
||||
let raw = stream.as_raw_fd();
|
||||
let chunk = buf;
|
||||
let fd_now = pass_fd;
|
||||
let fds_now = pass_fds;
|
||||
match stream.try_io(tokio::io::Interest::WRITABLE, || unsafe {
|
||||
drm_sendmsg(raw, chunk, fd_now)
|
||||
drm_sendmsg(raw, chunk, fds_now)
|
||||
}) {
|
||||
Ok(0) => bail!("drm: socket write returned 0 (peer closed)"),
|
||||
Ok(n) => {
|
||||
pass_fd = None; // ancillary delivered with these bytes; do not re-send it
|
||||
pass_fds = &[]; // ancillary delivered with these bytes; do not re-send it
|
||||
buf = &buf[n..];
|
||||
}
|
||||
Err(ref e) if e.kind() == std::io::ErrorKind::WouldBlock => continue,
|
||||
@@ -1642,14 +1681,14 @@ async fn drm_write_all(
|
||||
async fn drm_send_frame(
|
||||
stream: &tokio::net::UnixStream,
|
||||
payload: &[u8],
|
||||
pass_fd: Option<RawFd>,
|
||||
pass_fds: &[RawFd],
|
||||
) -> ResultType<()> {
|
||||
if payload.len() > u32::MAX as usize {
|
||||
bail!("drm: frame too large ({} bytes)", payload.len());
|
||||
}
|
||||
let prefix = (payload.len() as u32).to_be_bytes();
|
||||
drm_write_all(stream, &prefix, pass_fd).await?;
|
||||
drm_write_all(stream, payload, None).await?;
|
||||
drm_write_all(stream, &prefix, pass_fds).await?;
|
||||
drm_write_all(stream, payload, &[]).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1658,14 +1697,14 @@ async fn drm_read_full(
|
||||
buf: &mut [u8],
|
||||
want_cmsg: bool,
|
||||
progress: &mut bool,
|
||||
) -> ResultType<Option<OwnedFd>> {
|
||||
) -> ResultType<Vec<OwnedFd>> {
|
||||
use hbb_common::libc;
|
||||
let mut off = 0usize;
|
||||
let mut got: Option<OwnedFd> = None;
|
||||
let mut got: Vec<OwnedFd> = Vec::new();
|
||||
while off < buf.len() {
|
||||
stream.readable().await?;
|
||||
let raw = stream.as_raw_fd();
|
||||
let use_cmsg = want_cmsg && got.is_none();
|
||||
let use_cmsg = want_cmsg && got.is_empty();
|
||||
let n = {
|
||||
let dst: &mut [u8] = &mut buf[off..];
|
||||
match stream.try_io(tokio::io::Interest::READABLE, move || unsafe {
|
||||
@@ -1676,16 +1715,14 @@ async fn drm_read_full(
|
||||
if m < 0 {
|
||||
Err(std::io::Error::last_os_error())
|
||||
} else {
|
||||
Ok((m as usize, None))
|
||||
Ok((m as usize, Vec::new()))
|
||||
}
|
||||
}
|
||||
}) {
|
||||
Ok((0, _fd)) => bail!("drm: socket closed by peer"),
|
||||
Ok((m, fd)) => {
|
||||
if let Some(f) = fd {
|
||||
if got.is_none() {
|
||||
got = Some(f);
|
||||
}
|
||||
Ok((m, fds)) => {
|
||||
if got.is_empty() {
|
||||
got = fds;
|
||||
}
|
||||
m
|
||||
}
|
||||
@@ -1714,7 +1751,7 @@ impl DrmConn {
|
||||
pub async fn send_msg(&mut self, data: &Data, fd: Option<BorrowedFd<'_>>) -> ResultType<()> {
|
||||
let payload = serde_json::to_vec(data)?;
|
||||
let pass_fd = fd.map(|f| f.as_raw_fd());
|
||||
drm_send_frame(&self.stream, &payload, pass_fd).await
|
||||
drm_send_frame(&self.stream, &payload, pass_fd.as_slice()).await
|
||||
}
|
||||
|
||||
pub async fn send_frame_ack(&self, demand_fps: u8) -> ResultType<()> {
|
||||
@@ -1764,7 +1801,7 @@ impl DrmConn {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn recv_msg(&mut self) -> ResultType<(Data, Option<OwnedFd>)> {
|
||||
pub async fn recv_msg(&mut self) -> ResultType<(Data, Vec<OwnedFd>)> {
|
||||
self.consumed = false;
|
||||
let mut prefix = [0u8; 4];
|
||||
let fd = drm_read_full(&self.stream, &mut prefix, true, &mut self.consumed).await?;
|
||||
@@ -1785,7 +1822,7 @@ impl DrmConn {
|
||||
pub async fn recv_msg_timeout2(
|
||||
&mut self,
|
||||
ms_timeout: u64,
|
||||
) -> Option<ResultType<(Data, Option<OwnedFd>)>> {
|
||||
) -> Option<ResultType<(Data, Vec<OwnedFd>)>> {
|
||||
let ready = timeout(ms_timeout, self.stream.readable()).await;
|
||||
match ready {
|
||||
Err(_) => None, // no frame started: clean boundary, caller re-checks `stop`
|
||||
@@ -1801,7 +1838,7 @@ impl DrmConn {
|
||||
}
|
||||
|
||||
pub async fn send_raw(&mut self, data: Bytes) -> ResultType<()> {
|
||||
drm_send_frame(&self.stream, &data, None).await
|
||||
drm_send_frame(&self.stream, &data, &[]).await
|
||||
}
|
||||
|
||||
pub async fn next_raw_into(&mut self, out: &mut Vec<u8>) -> ResultType<()> {
|
||||
@@ -1815,9 +1852,9 @@ impl DrmConn {
|
||||
|
||||
async fn next_raw_into_unbounded(&mut self, out: &mut Vec<u8>) -> ResultType<()> {
|
||||
let mut prefix = [0u8; 4];
|
||||
if drm_read_full(&self.stream, &mut prefix, true, &mut self.consumed)
|
||||
if !drm_read_full(&self.stream, &mut prefix, true, &mut self.consumed)
|
||||
.await?
|
||||
.is_some()
|
||||
.is_empty()
|
||||
{
|
||||
log::warn!("drm: unexpected fd on a raw-body frame; dropping");
|
||||
}
|
||||
@@ -1901,7 +1938,10 @@ mod drm_conn_tests {
|
||||
.await
|
||||
.unwrap();
|
||||
let (_data, fd) = rx.recv_msg().await.unwrap();
|
||||
let recv_fd = fd.expect("an fd was attached, it must be received");
|
||||
let recv_fd = fd
|
||||
.into_iter()
|
||||
.next()
|
||||
.expect("an fd was attached, it must be received");
|
||||
let sentinel = [0xABu8];
|
||||
assert_eq!(
|
||||
unsafe { libc::write(wr.as_raw_fd(), sentinel.as_ptr() as *const libc::c_void, 1) },
|
||||
@@ -1915,6 +1955,39 @@ mod drm_conn_tests {
|
||||
assert_eq!(got[0], 0xAB, "received fd must be the same pipe");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_packet_frame_carries_its_bytes_and_every_fd_in_order() {
|
||||
let (a, b) = tokio::net::UnixStream::pair().unwrap();
|
||||
let tx = DrmConn::new(a);
|
||||
let mut rx = DrmConn::new(b);
|
||||
let pipes: Vec<(OwnedFd, OwnedFd)> = (0..3).map(|_| pipe()).collect();
|
||||
let read_ends: Vec<RawFd> = pipes.iter().map(|(r, _)| r.as_raw_fd()).collect();
|
||||
let desc = DmabufDesc {
|
||||
packet: vec![1, 2, 3, 250],
|
||||
..Default::default()
|
||||
};
|
||||
let payload = serde_json::to_vec(&Data::DrmFrameDmabuf(desc)).unwrap();
|
||||
drm_send_frame(&tx.stream, &payload, &read_ends)
|
||||
.await
|
||||
.unwrap();
|
||||
let (data, fds) = rx.recv_msg().await.unwrap();
|
||||
assert!(matches!(data, Data::DrmFrameDmabuf(d) if d.packet == [1, 2, 3, 250]));
|
||||
assert_eq!(fds.len(), 3);
|
||||
for (i, ((_, wr), fd)) in pipes.iter().zip(&fds).enumerate() {
|
||||
let b = [i as u8];
|
||||
assert_eq!(
|
||||
unsafe { libc::write(wr.as_raw_fd(), b.as_ptr() as *const libc::c_void, 1) },
|
||||
1
|
||||
);
|
||||
let mut got = [9u8; 1];
|
||||
assert_eq!(
|
||||
unsafe { libc::read(fd.as_raw_fd(), got.as_mut_ptr() as *mut libc::c_void, 1) },
|
||||
1
|
||||
);
|
||||
assert_eq!(got[0], i as u8, "fd {i} must be the pipe sent at index {i}");
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn roundtrip_raw_body() {
|
||||
let (a, b) = tokio::net::UnixStream::pair().unwrap();
|
||||
|
||||
+106
-17
@@ -179,6 +179,9 @@ pub struct IpcDrmCapturer {
|
||||
// unless the plane rotated the scanout (`frame_transform`). Fixed per session; a rotation
|
||||
// rebuilds the capturer.
|
||||
transform: i32,
|
||||
// The primary plane's rotation at enumeration: what turns a frame in CRTC raster back when
|
||||
// the plane rotated (`frame_transform`).
|
||||
primary_rotation: Option<u32>,
|
||||
// The wayland snapshot generation this session was built from: a later invalidation means
|
||||
// the layout (a rotation included) may have changed, and frame() asks for a rebuild.
|
||||
snapshot_gen: u64,
|
||||
@@ -320,10 +323,16 @@ const PLANE_ROTATE_0: u32 = 0x1;
|
||||
/// out what the compositor drew, and the frame is turned by the whole transform. `None` (a
|
||||
/// libdrmtap before 0.5.8, or nothing the library could read) keeps the pre-0.5.8 rule: 90/270
|
||||
/// turned, 180 left alone. The cursor does not go through this: see `Shared::cursor_transform`.
|
||||
fn frame_transform(wl_transform: i32, plane_rotation: Option<u32>) -> i32 {
|
||||
/// A frame composed of several planes (libdrmtap 0.6) answers rotate-0 too: it is the CRTC
|
||||
/// raster. When the primary plane rotated at enumeration, that rotation is the CRTC transform,
|
||||
/// panel orientation included, so a rotate-0 frame is turned by it instead of `wl_transform`.
|
||||
fn frame_transform(wl_transform: i32, plane_rotation: Option<u32>, primary: Option<u32>) -> i32 {
|
||||
match plane_rotation {
|
||||
Some(mask) if mask != PLANE_ROTATE_0 => 0,
|
||||
Some(_) => wl_transform,
|
||||
Some(_) => match primary.map(plane_degrees) {
|
||||
Some(d) if d != 0 => d,
|
||||
_ => wl_transform,
|
||||
},
|
||||
None => {
|
||||
if wl_transform == 90 || wl_transform == 270 {
|
||||
wl_transform
|
||||
@@ -334,6 +343,16 @@ fn frame_transform(wl_transform: i32, plane_rotation: Option<u32>) -> i32 {
|
||||
}
|
||||
}
|
||||
|
||||
/// The turn that undoes a plane `rotation` mask: DRM rotates counter-clockwise, like `wl_output`.
|
||||
fn plane_degrees(mask: u32) -> i32 {
|
||||
match mask & 0xf {
|
||||
0x2 => 90,
|
||||
0x4 => 180,
|
||||
0x8 => 270,
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
|
||||
/// Takes DRM_STATE: never call it while holding one of the per-display maps below.
|
||||
fn display_info_of(display: i32) -> Option<DrmDisplayInfo> {
|
||||
match &*DRM_STATE.lock().unwrap() {
|
||||
@@ -354,6 +373,8 @@ struct DisplayHealth {
|
||||
/// The dma-buf convert failed for this display. The COMMON cause is multi-GPU: our render node
|
||||
/// is not the GPU that exported the scanout. Follows the monitor for the process run.
|
||||
prefer_cpu: bool,
|
||||
/// A packet convert failed: ask for one descriptor first, `prefer_cpu` if that fails too.
|
||||
no_packet: bool,
|
||||
/// The PipeWire fallback for this display was rejected on geometry (a transposed stream), so
|
||||
/// the lone-display carve-out in `mark_demoted_displays` must not keep advertising it online.
|
||||
fallback_rejected: bool,
|
||||
@@ -368,6 +389,7 @@ impl DisplayHealth {
|
||||
last_build: None,
|
||||
rapid_builds: 0,
|
||||
prefer_cpu: false,
|
||||
no_packet: false,
|
||||
fallback_rejected: false,
|
||||
}
|
||||
}
|
||||
@@ -420,14 +442,26 @@ fn drm_prefer_cpu(key: &Option<String>) -> bool {
|
||||
})
|
||||
}
|
||||
|
||||
fn drm_set_prefer_cpu(key: &Option<String>) {
|
||||
if let Some(k) = key {
|
||||
fn drm_no_packet(key: &Option<String>) -> bool {
|
||||
key.as_ref().is_some_and(|k| {
|
||||
DRM_DISPLAY_HEALTH
|
||||
.lock()
|
||||
.unwrap()
|
||||
.entry(k.clone())
|
||||
.or_insert_with(DisplayHealth::new)
|
||||
.prefer_cpu = true;
|
||||
.get(k)
|
||||
.is_some_and(|h| h.no_packet)
|
||||
})
|
||||
}
|
||||
|
||||
/// A failed packet convert sets `no_packet`, a failed descriptor convert `prefer_cpu`.
|
||||
fn drm_note_convert_failed(key: &Option<String>, packet: bool) {
|
||||
if let Some(k) = key {
|
||||
let mut health = DRM_DISPLAY_HEALTH.lock().unwrap();
|
||||
let h = health.entry(k.clone()).or_insert_with(DisplayHealth::new);
|
||||
if packet {
|
||||
h.no_packet = true;
|
||||
} else {
|
||||
h.prefer_cpu = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -527,6 +561,7 @@ impl IpcDrmCapturer {
|
||||
)
|
||||
}),
|
||||
transform: wl_transform,
|
||||
primary_rotation: displays.get(wire_idx).and_then(|d| d.primary_rotation),
|
||||
snapshot_gen,
|
||||
cur: Vec::new(),
|
||||
cur_w: 0,
|
||||
@@ -626,7 +661,7 @@ impl TraitCapturer for IpcDrmCapturer {
|
||||
// over the landscape mode and `t` is 90; both land on the session size.
|
||||
// convert_to_yuv only refuses a LARGER source (a smaller one leaves stale edges);
|
||||
// first frame: CRTC mode vs scanout fb.
|
||||
let t = frame_transform(self.transform, plane_rotation);
|
||||
let t = frame_transform(self.transform, plane_rotation, self.primary_rotation);
|
||||
let (fw, fh) = rotated_dims(t, w, h);
|
||||
if self.session_size.is_some_and(|(sw, sh)| (fw, fh) != (sw, sh)) {
|
||||
self.shared.slot.lock().unwrap().recycle(buf);
|
||||
@@ -820,6 +855,7 @@ async fn recv_thread(
|
||||
&Data::DrmStart {
|
||||
display: wire_idx as i32,
|
||||
need_cpu,
|
||||
no_packet: drm_no_packet(&our_key),
|
||||
},
|
||||
None,
|
||||
)
|
||||
@@ -876,7 +912,7 @@ async fn recv_thread(
|
||||
};
|
||||
// Valid in THIS process; -1 is an import-once cache hit on `fb_id`.
|
||||
let received_fd: RawFd = if desc.has_fd {
|
||||
match recv_fd.as_ref() {
|
||||
match recv_fd.first() {
|
||||
Some(f) => f.as_raw_fd(),
|
||||
None => {
|
||||
break "dma-buf frame set has_fd but carried no SCM_RIGHTS fd".to_owned()
|
||||
@@ -900,7 +936,13 @@ async fn recv_thread(
|
||||
hdr_eotf: desc.hdr_eotf,
|
||||
hdr_max_nits: desc.hdr_max_nits,
|
||||
};
|
||||
match conv.convert(&mut ddesc, received_fd) {
|
||||
let converted = if desc.packet.is_empty() {
|
||||
conv.convert(&mut ddesc, received_fd)
|
||||
} else {
|
||||
let fds: Vec<RawFd> = recv_fd.iter().map(|f| f.as_raw_fd()).collect();
|
||||
conv.convert_packet(&desc.packet, &fds)
|
||||
};
|
||||
match converted {
|
||||
Ok((data, w, h, fmt)) => {
|
||||
// Borrowed from the render context, valid only until the next convert.
|
||||
// Copy into a recycled buffer, and OUTSIDE the slot lock, so a
|
||||
@@ -908,13 +950,19 @@ async fn recv_thread(
|
||||
let mut buf = shared.slot.lock().unwrap().take_free().unwrap_or_default();
|
||||
buf.clear();
|
||||
buf.extend_from_slice(data);
|
||||
// A packet's rotation is known after the convert (composed or one layer).
|
||||
let rotation = if desc.packet.is_empty() {
|
||||
desc.plane_rotation
|
||||
} else {
|
||||
conv.plane_rotation()
|
||||
};
|
||||
let mut slot = shared.slot.lock().unwrap();
|
||||
slot.publish(w as usize, h as usize, fmt, desc.plane_rotation, buf);
|
||||
slot.publish(w as usize, h as usize, fmt, rotation, buf);
|
||||
shared.cv.notify_one();
|
||||
}
|
||||
Err(err) if err.kind() == io::ErrorKind::WouldBlock => {}
|
||||
Err(err) => {
|
||||
drm_set_prefer_cpu(&our_key);
|
||||
drm_note_convert_failed(&our_key, !desc.packet.is_empty());
|
||||
break format!("convert: {err}");
|
||||
}
|
||||
}
|
||||
@@ -2529,6 +2577,7 @@ mod drm_capturer_tests {
|
||||
connector,
|
||||
session_size: session,
|
||||
transform: 0,
|
||||
primary_rotation: None,
|
||||
snapshot_gen: scrap::wayland::display::wayland_snapshot_generation(),
|
||||
cur: Vec::new(),
|
||||
cur_w: 0,
|
||||
@@ -2749,10 +2798,46 @@ mod drm_capturer_tests {
|
||||
/// master delivered it upright. So the plane answer is not measured against `wl_output`.
|
||||
#[test]
|
||||
fn a_plane_that_rotated_holds_the_logical_desktop_whatever_wl_output_says() {
|
||||
assert_eq!(frame_transform(0, Some(0x4)), 0);
|
||||
assert_eq!(frame_transform(90, Some(0x4)), 0);
|
||||
assert_eq!(frame_transform(180, Some(0x2)), 0);
|
||||
assert_eq!(frame_transform(90, Some(0x8)), 0);
|
||||
assert_eq!(frame_transform(0, Some(0x4), None), 0);
|
||||
assert_eq!(frame_transform(90, Some(0x4), None), 0);
|
||||
assert_eq!(frame_transform(180, Some(0x2), None), 0);
|
||||
assert_eq!(frame_transform(90, Some(0x8), None), 0);
|
||||
}
|
||||
|
||||
/// A frame of several planes answers rotate-0, also on a panel whose primary plane rotated
|
||||
/// for its orientation, which `wl_output` does not carry: it is turned by the primary plane.
|
||||
#[test]
|
||||
fn a_composed_frame_on_a_rotated_panel_is_turned_by_the_primary_plane() {
|
||||
use scrap::TraitPixelBuffer;
|
||||
let upright = vec![vec![1, 2, 3], vec![4, 5, 6]];
|
||||
// Portrait panel used as landscape: the plane turned the 3x2 desktop 90 counter-clockwise.
|
||||
let (raster, rw, rh) = px_frame(&[&[3, 6], &[2, 5], &[1, 4]], 0);
|
||||
let mut c = capturer_with(Some((rh, rw)));
|
||||
c.primary_rotation = Some(0x2);
|
||||
put_frame_with(&c, rw, rh, Some(0x1), &raster);
|
||||
match c.frame(Duration::from_millis(50)) {
|
||||
Ok(Frame::PixelBuffer(pb)) => {
|
||||
assert_eq!((pb.width(), pb.height()), (rh, rw));
|
||||
assert_eq!(labels_of(pb.data(), rh, rw), upright);
|
||||
}
|
||||
Ok(_) => panic!("expected a pixel-buffer frame"),
|
||||
Err(err) => panic!("expected a delivered frame, got {err}"),
|
||||
}
|
||||
// Panel mounted upside down: composed comes back upright, one layer is left alone.
|
||||
let (src, w, h) = px_frame(&[&[6, 5, 4], &[3, 2, 1]], 0);
|
||||
let mut c = capturer_with(Some((w, h)));
|
||||
c.primary_rotation = Some(0x4);
|
||||
for (rotation, want) in [
|
||||
(0x1, upright.clone()),
|
||||
(0x4, vec![vec![6, 5, 4], vec![3, 2, 1]]),
|
||||
] {
|
||||
put_frame_with(&c, w, h, Some(rotation), &src);
|
||||
match c.frame(Duration::from_millis(50)) {
|
||||
Ok(Frame::PixelBuffer(pb)) => assert_eq!(labels_of(pb.data(), w, h), want),
|
||||
Ok(_) => panic!("expected a pixel-buffer frame"),
|
||||
Err(err) => panic!("expected a delivered frame, got {err}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -3104,7 +3189,10 @@ mod drm_capturer_tests {
|
||||
}
|
||||
// A plane that rotated folds 180 to 0 for the FRAME; that fold must never reach the
|
||||
// calibration.
|
||||
assert_eq!(frame_transform(transform_and_origin(&drm, 0, &one(180)).0, Some(0x4)), 0);
|
||||
assert_eq!(
|
||||
frame_transform(transform_and_origin(&drm, 0, &one(180)).0, Some(0x4), None),
|
||||
0
|
||||
);
|
||||
// Partial snapshot: two connectors, one output, even one with a matching name.
|
||||
let two = [
|
||||
drm_display("HDMI-A-1", 1920, 1080),
|
||||
@@ -3193,6 +3281,7 @@ mod drm_capturer_tests {
|
||||
render_node: String::new(),
|
||||
device: String::new(),
|
||||
plane_transposed: false,
|
||||
primary_rotation: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user