23 releases (12 breaking)

0.14.1 Oct 24, 2024
0.12.0 Apr 18, 2024
0.11.1 Jan 4, 2024
0.11.0 Nov 14, 2023
0.1.0 Jan 24, 2017

#27 in Unix APIs

Download history 27465/week @ 2024-10-30 22131/week @ 2024-11-06 15675/week @ 2024-11-13 14722/week @ 2024-11-20 15071/week @ 2024-11-27 15562/week @ 2024-12-04 15598/week @ 2024-12-11 16785/week @ 2024-12-18 14307/week @ 2024-12-25 15431/week @ 2025-01-01 23224/week @ 2025-01-08 24817/week @ 2025-01-15 22142/week @ 2025-01-22 21573/week @ 2025-01-29 27561/week @ 2025-02-05 22450/week @ 2025-02-12

96,707 downloads per month
Used in 28 crates (13 directly)

MIT license

175KB
4K SLoC

drm-rs

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.

Usage

Basic

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

Control (modesetting)

See drm::control::Device as well as our mode-setting examples: atomic_modeset and legacy_modeset

Rendering

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.

Dependencies

~2–11MB
~138K SLoC

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy