21 releases (11 breaking)

new 0.12.0 Apr 18, 2024
0.11.1 Jan 4, 2024
0.11.0 Nov 14, 2023
0.9.0 Mar 24, 2023
0.1.0 Jan 24, 2017

#24 in Unix APIs

Download history 5577/week @ 2023-12-23 6041/week @ 2023-12-30 7174/week @ 2024-01-06 8521/week @ 2024-01-13 8639/week @ 2024-01-20 9946/week @ 2024-01-27 11339/week @ 2024-02-03 11491/week @ 2024-02-10 14522/week @ 2024-02-17 12297/week @ 2024-02-24 12825/week @ 2024-03-02 13511/week @ 2024-03-09 13776/week @ 2024-03-16 14432/week @ 2024-03-23 12692/week @ 2024-03-30 9101/week @ 2024-04-06

52,016 downloads per month
Used in 17 crates (9 directly)

MIT license

3.5K SLoC


Crates.io docs.rs Build Status

A safe interface to the Direct Rendering Manager.

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<'_> {

/// Simple helper methods for opening a `Card`.
impl Card {
    pub fn open(path: &str) -> Self {
        let mut options = std::fs::OpenOptions::new();

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());

Control (modesetting)

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.


~140K SLoC