• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

examples/25-Apr-2025-867664

src/25-Apr-2025-3,4462,313

.cargo-checksum.jsonD25-Apr-20252.8 KiB11

Android.bpD25-Apr-2025932 3834

Cargo.lockD25-Apr-202517.4 KiB672592

Cargo.tomlD25-Apr-20251.4 KiB7059

LICENSED25-Apr-20251,023 2421

METADATAD25-Apr-2025383 1817

MODULE_LICENSE_MITD25-Apr-20250

README.mdD25-Apr-20253 KiB8160

cargo_embargo.jsonD25-Apr-202587 76

README.md

1# drm-rs
2
3[![Crates.io](https://img.shields.io/crates/v/drm.svg)](https://crates.io/crates/drm)
4[![docs.rs](https://docs.rs/drm/badge.svg)](https://docs.rs/drm)
5[![Build Status](https://github.com/Smithay/drm-rs/actions/workflows/ci.yml/badge.svg)](https://github.com/Smithay/drm-rs/actions/workflows/ci.yml)
6
7A safe interface to the Direct Rendering Manager.
8
9## Direct Rendering Manager
10
11The Direct Rendering Manager is a subsystem found on multiple Unix-based
12operating systems that provides a userspace API to graphics hardware.
13See the [Wikipedia article](https://en.wikipedia.org/wiki/Direct_Rendering_Manager)
14for more details.
15
16## Usage
17
18### Basic
19
20The DRM is accessed using [ioctls](https://en.wikipedia.org/wiki/Ioctl)
21on a file representing a graphics card. These can normally be
22found in `/dev/dri`, but can also be opened in other ways (ex. udev).
23
24This crate does not provide a method of opening these files. Instead, the
25user program must provide a way to access the file descriptor representing the
26device through the [AsFd](https://doc.rust-lang.org/std/os/fd/trait.AsFd.html)
27trait. Here is a basic example using `File` as a backend:
28
29```rust
30/// A simple wrapper for a device node.
31pub struct Card(std::fs::File);
32
33/// Implementing [`AsFd`] is a prerequisite to implementing the traits found
34/// in this crate. Here, we are just calling [`File::as_fd()`] on the inner
35/// [`File`].
36impl AsFd for Card {
37    fn as_fd(&self) -> BorrowedFd<'_> {
38        self.0.as_fd()
39    }
40}
41
42/// Simple helper methods for opening a `Card`.
43impl Card {
44    pub fn open(path: &str) -> Self {
45        let mut options = std::fs::OpenOptions::new();
46        options.read(true);
47        options.write(true);
48        Card(options.open(path).unwrap())
49    }
50}
51```
52
53Finally, you can implement `drm::Device` to gain access to the basic DRM
54functionality:
55
56```rust
57impl drm::Device for Card {}
58
59fn main() {
60    let gpu = Card::open("/dev/dri/card0");
61    println!("{:#?}", gpu.get_driver().unwrap());
62}
63```
64
65### Control (modesetting)
66
67See [`drm::control::Device`](https://docs.rs/drm/*/drm/control/trait.Device.html)
68as well as our mode-setting examples: [`atomic_modeset`](https://github.com/Smithay/drm-rs/blob/develop/examples/atomic_modeset.rs)
69and [`legacy_modeset`](https://github.com/Smithay/drm-rs/blob/develop/examples/legacy_modeset.rs)
70
71### Rendering
72
73Rendering is done by [creating](https://docs.rs/drm/*/drm/control/trait.Device.html#method.add_framebuffer) and
74[attaching](https://docs.rs/drm/*/drm/control/trait.Device.html#method.page_flip) [framebuffers](https://docs.rs/drm/*/drm/control/framebuffer/index.html)
75to [crtcs](https://docs.rs/drm/*/drm/control/crtc/index.html).
76
77A framebuffer is created from anything implementing [`Buffer`](https://docs.rs/drm/*/drm/buffer/trait.Buffer.html) like the always
78available, but very limited, [`DumbBuffer`](https://docs.rs/drm/*/drm/control/dumbbuffer/struct.DumbBuffer.html).
79
80For faster hardware-backed buffers, checkout [gbm.rs](https://github.com/Smithay/gbm.rs).
81