Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | - | - | ||||
examples/ | 25-Apr-2025 | - | 867 | 664 | ||
src/ | 25-Apr-2025 | - | 3,446 | 2,313 | ||
.cargo-checksum.json | D | 25-Apr-2025 | 2.8 KiB | 1 | 1 | |
Android.bp | D | 25-Apr-2025 | 932 | 38 | 34 | |
Cargo.lock | D | 25-Apr-2025 | 17.4 KiB | 672 | 592 | |
Cargo.toml | D | 25-Apr-2025 | 1.4 KiB | 70 | 59 | |
LICENSE | D | 25-Apr-2025 | 1,023 | 24 | 21 | |
METADATA | D | 25-Apr-2025 | 383 | 18 | 17 | |
MODULE_LICENSE_MIT | D | 25-Apr-2025 | 0 | |||
README.md | D | 25-Apr-2025 | 3 KiB | 81 | 60 | |
cargo_embargo.json | D | 25-Apr-2025 | 87 | 7 | 6 |
README.md
1# drm-rs 2 3[](https://crates.io/crates/drm) 4[](https://docs.rs/drm) 5[](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