gbm.rs and drm-rs are designed to work together as a complete, safe Rust stack for Kernel Mode Setting (KMS) display output. GBM acts as the buffer allocator, producingDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Smithay/gbm.rs/llms.txt
Use this file to discover all available pages before exploring further.
BufferObject handles that the DRM kernel interface can directly consume as scanout framebuffers. With the drm-support feature enabled, the two crates share types seamlessly: Device<T> automatically gains drm::Device and drm::control::Device implementations, and BufferObject<T> satisfies the drm::buffer::Buffer and drm::buffer::PlanarBuffer traits required by drm-rs APIs.
Prerequisites
drm-support feature
Enable the
drm-support feature flag in your Cargo.toml. It is on by default.DRM device access
A readable and writable DRM device node, typically
/dev/dri/card0, opened before creating a GBM device.Setup
Cargo.toml
Implementation
Implement a DRM Device Wrapper
Create a minimal
Card newtype that wraps a File and satisfies the drm-rs traits. Device<T> requires T: AsFd, and the blanket implementations in gbm.rs will propagate drm::Device and drm::control::Device automatically when your inner type does too.Create a GBM Device
Wrap the
Card in a gbm::Device. The GBM device borrows the underlying file descriptor from the inner type via AsFd, so the Card is moved in and can still be reached through Deref.Allocate a Scanout Buffer
Allocate a
BufferObject with the SCANOUT usage flag so the kernel knows it will be presented to the display. Format::Xrgb8888 is the most widely supported scanout format for opaque framebuffers.Create a DRM Framebuffer
Pass the
BufferObject directly to add_framebuffer. Because BufferObject<T> implements drm::buffer::Buffer when drm-support is enabled, drm-rs can read the size, pitch, format, and GEM handle from it without any manual extraction.When the
drm-support feature is active, BufferObject<T> implements both drm::buffer::Buffer and drm::buffer::PlanarBuffer. This means you can pass a BufferObject directly to any drm-rs API that accepts those traits — including add_framebuffer, add_planar_framebuffer, and page-flip helpers — without manually extracting GEM handles, strides, or offsets.