Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions drm-ffi/src/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,12 +639,9 @@ pub fn get_property_blob(
}

/// Create a property blob
pub fn create_property_blob(
fd: BorrowedFd<'_>,
data: &mut [u8],
) -> io::Result<drm_mode_create_blob> {
pub fn create_property_blob(fd: BorrowedFd<'_>, data: &[u8]) -> io::Result<drm_mode_create_blob> {
let mut blob = drm_mode_create_blob {
data: data.as_mut_ptr() as _,
data: data.as_ptr() as _,
length: data.len() as _,
..Default::default()
};
Expand Down
22 changes: 18 additions & 4 deletions src/control/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ use std::error;
use std::fmt;
use std::io;
use std::iter::Zip;
use std::mem;
use std::ops::RangeBounds;
use std::os::unix::io::{AsFd, BorrowedFd, FromRawFd, OwnedFd, RawFd};
use std::time::Duration;
Expand Down Expand Up @@ -534,9 +533,23 @@ pub trait Device: super::Device {
}

/// Create a property blob value from a given data blob
fn create_property_blob<T: ?Sized>(&self, data: &T) -> io::Result<property::Value<'static>> {
let size = mem::size_of_val(data);
let data = unsafe { std::slice::from_raw_parts_mut(data as *const _ as *mut u8, size) };
fn create_property_blob<T: bytemuck::NoUninit>(
&self,
data: &T,
) -> io::Result<property::Value<'static>> {
let data = bytemuck::bytes_of(data);
let blob = ffi::mode::create_property_blob(self.as_fd(), data)?;

Ok(property::Value::Blob(blob.blob_id.into()))
}

/// Create a property blob value from a given data slice
fn create_property_blob_from_slice<T: bytemuck::NoUninit>(
&self,
data: &[T],
) -> io::Result<property::Value<'static>> {
let data = bytemuck::try_cast_slice(data)
.map_err(|_| io::Error::from(io::ErrorKind::InvalidData))?;
let blob = ffi::mode::create_property_blob(self.as_fd(), data)?;

Ok(property::Value::Blob(blob.blob_id.into()))
Expand Down Expand Up @@ -1257,6 +1270,7 @@ pub struct Mode {
// to convert to/from an abstracted type, just use the raw object.
mode: ffi::drm_mode_modeinfo,
}
unsafe impl bytemuck::NoUninit for Mode {}

impl Mode {
/// Returns the name of this mode.
Expand Down