TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Smithay/drm-rs/llms.txt
Use this file to discover all available pages before exploring further.
drm::buffer module provides the core types for GPU buffer management. GEM (Graphics Execution Manager) buffers are the kernel’s abstraction for GPU memory, represented by 32-bit handles local to the current process. These handles are automatically reference-counted in the kernel, but drm-rs does not track their lifetimes — it is the caller’s responsibility to close buffers correctly and avoid use-after-free.
The module also re-exports pixel format and modifier types from the drm-fourcc crate, which are used throughout the drm-rs API wherever a buffer format is required.
buffer::Handle
A handle to an open GEM buffer in the current process.
Handle is a repr(transparent) newtype over control::RawResourceHandle, which is itself a NonZeroU32. This means a Handle is guaranteed to be non-zero, and Option<Handle> is pointer-sized with no overhead.
Trait implementations: Copy, Clone, Hash, PartialEq, Eq, Debug (manual implementation, formats as buffer::Handle(N)).
Conversions:
| From | To | Notes |
|---|---|---|
control::RawResourceHandle | Handle | Via From<RawResourceHandle> |
Handle | control::RawResourceHandle | Via Into<RawResourceHandle> |
Handle | u32 | Via Into<u32> |
buffer::Name
A global 32-bit “Flink” name used to share a GEM buffer across processes.
Name is produced by the kernel’s Flink mechanism and can be passed to another process, which can then open it with control::Device::open_buffer(). Like Handle, there is no runtime validation — the caller must ensure the name is still valid.
Conversion: Into<u32>.
Buffer trait
The Buffer trait describes any single-plane GPU buffer. It is implemented by DumbBuffer and can be implemented by any user-defined buffer type.
control::Device that accept a buffer (such as add_framebuffer) are generic over B: Buffer, so any type implementing this trait can be used directly without wrapping.
PlanarBuffer trait
The PlanarBuffer trait extends buffer abstraction to multi-plane formats (e.g. YUV 4:2:0, NV12) and formats with hardware-specific layout modifiers (tiling, compression).
control::Device::add_planar_framebuffer() to register a planar buffer as a KMS framebuffer.
Re-exports from drm-fourcc
The drm::buffer module re-exports the following types from the drm-fourcc crate:
| Type | Description |
|---|---|
DrmFourcc | Pixel format codes, e.g. DrmFourcc::Xrgb8888, DrmFourcc::Nv12 |
DrmModifier | Format modifiers that describe memory layout, e.g. tiling or vendor compression schemes |
DrmVendor | Vendor namespace for modifier codes |
UnrecognizedFourcc | Error type returned when a raw FourCC code is not a known DrmFourcc variant |
UnrecognizedVendor | Error type returned when a vendor code is not a known DrmVendor variant |
DumbBuffer and DumbMapping
DumbBuffer is a software-backed, driver-agnostic buffer type returned by control::Device::create_dumb_buffer(). It is the simplest way to allocate a CPU-accessible GPU buffer without any driver-specific library. Performance is limited — dumb buffers are not hardware-accelerated — but they work with any DRM driver that supports kernel modesetting.
DumbBuffer implements the Buffer trait. The following accessors are available:
| Method | Return type | Description |
|---|---|---|
size() | (u32, u32) | Width and height in pixels |
format() | DrmFourcc | Pixel format as specified at creation |
pitch() | u32 | Bytes per row, as determined by the kernel |
handle() | buffer::Handle | GEM handle for this buffer |
DumbMapping<'_>
DumbMapping is a CPU memory mapping of a DumbBuffer, returned by control::Device::map_dumb_buffer(). It borrows the buffer mutably for its lifetime and unmaps the memory automatically when dropped.
AsRef<[u8]>, AsMut<[u8]>, Borrow<[u8]>, BorrowMut<[u8]>, Deref<Target = [u8]>, DerefMut.
The mapping unmaps itself via munmap in its Drop implementation, so there is no need to call an explicit unmap function.
Full usage example
To share a
DumbBuffer (or any GEM buffer) with another process, convert it to a PRIME file descriptor using control::Device::buffer_to_prime_fd(handle, flags), then pass the OwnedFd over a Unix socket. The receiving process can import it back with control::Device::prime_fd_to_buffer(fd). This is more secure than Flink (buffer::Name) because the kernel enforces that only the holder of the file descriptor can access the buffer.