commit | 9cc20bf36aa66552c37925c669ff8078b34cee1d | [log] [tgz] |
---|---|---|
author | James Farrell <[email protected]> | Tue Aug 27 03:59:23 2024 +0000 |
committer | Automerger Merge Worker <[email protected]> | Tue Aug 27 03:59:23 2024 +0000 |
tree | 8afd75c4127a9e54114998727b70871d7ebda491 | |
parent | da6566254467ef888f30e77451f6df7d832edd4a [diff] | |
parent | 59a0a6b6e2033c5b1964556804c9785f3cfc4b5c [diff] |
Migrate 25 crates to monorepo. am: 202a3b831d am: 59a0a6b6e2 Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/drm/+/3241696 Change-Id: Iab9cd5ab7942c13a2956cb58b5cfb0255b6134e1 Signed-off-by: Automerger Merge Worker <[email protected]>
A safe interface to the Direct Rendering Manager.
The Direct Rendering Manager is a subsystem found on multiple Unix-based operating systems that provides a userspace API to graphics hardware. See the Wikipedia article for more details.
The DRM is accessed using ioctls on a file representing a graphics card. These can normally be found in /dev/dri
, but can also be opened in other ways (ex. udev).
This crate does not provide a method of opening these files. Instead, the user program must provide a way to access the file descriptor representing the device through the AsFd trait. Here is a basic example using File
as a backend:
/// A simple wrapper for a device node. pub struct Card(std::fs::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() } } /// Simple helper methods for opening a `Card`. impl Card { pub fn open(path: &str) -> Self { let mut options = std::fs::OpenOptions::new(); options.read(true); options.write(true); Card(options.open(path).unwrap()) } }
Finally, you can implement drm::Device
to gain access to the basic DRM functionality:
impl drm::Device for Card {} fn main() { let gpu = Card::open("/dev/dri/card0"); println!("{:#?}", gpu.get_driver().unwrap()); }
See drm::control::Device
as well as our mode-setting examples: atomic_modeset
and legacy_modeset
Rendering is done by creating and attaching framebuffers to crtcs.
A framebuffer is created from anything implementing Buffer
like the always available, but very limited, DumbBuffer
.
For faster hardware-backed buffers, checkout gbm.rs.