pub trait Device: AsFd {
// Provided methods
fn acquire_master_lock(&self) -> Result<()> { ... }
fn release_master_lock(&self) -> Result<()> { ... }
fn generate_auth_token(&self) -> Result<AuthToken> { ... }
fn authenticate_auth_token(&self, token: AuthToken) -> Result<()> { ... }
fn set_client_capability(
&self,
cap: ClientCapability,
enable: bool,
) -> Result<()> { ... }
fn get_bus_id(&self) -> Result<OsString> { ... }
fn authenticated(&self) -> Result<bool> { ... }
fn get_driver_capability(&self, cap: DriverCapability) -> Result<u64> { ... }
fn get_driver(&self) -> Result<Driver> { ... }
fn wait_vblank(
&self,
target_sequence: VblankWaitTarget,
flags: VblankWaitFlags,
high_crtc: u32,
user_data: usize,
) -> Result<VblankWaitReply> { ... }
}
Expand description
This trait should be implemented by any object that acts as a DRM device. It is a prerequisite for using any DRM functionality.
This crate does not provide a concrete device object due to the various ways it can be implemented. The user of this crate is expected to implement it themselves and derive this trait as necessary. The example below demonstrates how to do this using a small wrapper.
§Example
use drm::Device;
use std::fs::File;
use std::fs::OpenOptions;
use std::os::unix::io::AsFd;
use std::os::unix::io::BorrowedFd;
#[derive(Debug)]
/// A simple wrapper for a device node.
struct Card(File);
/// Implementing [`AsFd`] is a prerequisite to implementing the traits found
/// in this crate. Here, we are just calling [`File::as_fd()`] on the inner
/// [`File`].
impl AsFd for Card {
fn as_fd(&self) -> BorrowedFd<'_> {
self.0.as_fd()
}
}
/// With [`AsFd`] implemented, we can now implement [`drm::Device`].
impl Device for Card {}
impl Card {
/// Simple helper method for opening a [`Card`].
fn open() -> Self {
let mut options = OpenOptions::new();
options.read(true);
options.write(true);
// The normal location of the primary device node on Linux
Card(options.open("/dev/dri/card0").unwrap())
}
}
Provided Methods§
sourcefn acquire_master_lock(&self) -> Result<()>
fn acquire_master_lock(&self) -> Result<()>
Acquires the DRM Master lock for this process.
§Notes
Acquiring the DRM Master is done automatically when the primary device node is opened. If you opened the primary device node and did not acquire the lock, another process likely has the lock.
This function is only available to processes with CAP_SYS_ADMIN privileges (usually as root)
sourcefn release_master_lock(&self) -> Result<()>
fn release_master_lock(&self) -> Result<()>
Releases the DRM Master lock for another process to use.
sourcefn generate_auth_token(&self) -> Result<AuthToken>
👎Deprecated: Consider opening a render node instead.
fn generate_auth_token(&self) -> Result<AuthToken>
Generates an AuthToken
for this process.
sourcefn authenticate_auth_token(&self, token: AuthToken) -> Result<()>
fn authenticate_auth_token(&self, token: AuthToken) -> Result<()>
Authenticates an AuthToken
from another process.
sourcefn set_client_capability(
&self,
cap: ClientCapability,
enable: bool,
) -> Result<()>
fn set_client_capability( &self, cap: ClientCapability, enable: bool, ) -> Result<()>
Requests the driver to expose or hide certain capabilities. See
ClientCapability
for more information.
sourcefn get_bus_id(&self) -> Result<OsString>
fn get_bus_id(&self) -> Result<OsString>
Gets the bus ID of this device.
sourcefn authenticated(&self) -> Result<bool>
fn authenticated(&self) -> Result<bool>
Check to see if our AuthToken
has been authenticated
by the DRM Master
sourcefn get_driver_capability(&self, cap: DriverCapability) -> Result<u64>
fn get_driver_capability(&self, cap: DriverCapability) -> Result<u64>
Gets the value of a capability.
sourcefn get_driver(&self) -> Result<Driver>
fn get_driver(&self) -> Result<Driver>
§Possible errors:
EFAULT
: Kernel could not copy fields into userspace
sourcefn wait_vblank(
&self,
target_sequence: VblankWaitTarget,
flags: VblankWaitFlags,
high_crtc: u32,
user_data: usize,
) -> Result<VblankWaitReply>
fn wait_vblank( &self, target_sequence: VblankWaitTarget, flags: VblankWaitFlags, high_crtc: u32, user_data: usize, ) -> Result<VblankWaitReply>
Waits for a vblank.