Documentation 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.
Device<T> is the entry point for all gbm.rs operations. It wraps an open DRM file descriptor and owns the lifetime of the underlying gbm_device, providing methods to allocate buffer objects, create rendering surfaces, and import foreign buffers from Wayland, EGL, and DMA-BUF sources. Every other type in gbm.rs — BufferObject<U> and Surface<U> — is produced through a Device<T>.
Struct Definition
Device<T> is generic over any type T that implements AsFd, so it composes cleanly with std::fs::File, std::os::unix::io::OwnedFd, or any custom wrapper around a DRM file descriptor.
Constructor
Device::new
gbm_create_device(fd) and returns Err(IoError::last_os_error()) if the C function returns a null pointer. On success, the device takes ownership of fd and schedules gbm_device_destroy to run when the last reference is dropped.
The file descriptor is typically obtained by opening a DRM node such as /dev/dri/card0 or /dev/dri/renderD128.
An open DRM device file descriptor. The GBM backend uses this descriptor to
communicate with the kernel for memory allocation. For DRI-based drivers this
is typically a node under
/dev/dri/.IoResult<Device<T>> — Ok(device) on success, or Err carrying the OS errno set by gbm_create_device.
Type Examples
| Type | Use case |
|---|---|
Device<File> | Simple ownership via std::fs::File; implements Clone when File: Clone. |
Device<OwnedFd> | Idiomatic file-descriptor ownership in modern Rust; safe to move across threads. |
Trait Implementations
Clone (where T: Clone)
Cloning a Device<T> does not open a second gbm_device. The inner raw pointer is wrapped in an Arc-backed Ptr<gbm_device>, so cloning increments the reference count and both handles share the same underlying device. The device is destroyed only when every clone is dropped.
Debug
Formats as Device { ptr: 0x… }, printing the pointer address of the underlying gbm_device. Useful for logging without exposing the file descriptor.
AsFd
BorrowedFd backed by the raw file descriptor obtained from gbm_device_get_fd. This ensures the fd surfaced through AsFd is always the one the GBM driver is using, even if the original wrapper type normalises or remaps descriptors.
AsRaw<gbm_device>
*const gbm_device for FFI calls that need to drop below gbm.rs’s safe abstraction layer.
Deref<Target = T> / DerefMut
T, so methods on the wrapped file descriptor (for example DRM ioctls via drm-rs) are accessible directly on Device<T> without explicitly extracting the inner value.
Send + Sync
Device<T> is unconditionally Send and Sync. The underlying gbm_device is thread-safe, and shared ownership is managed through an atomic Arc.
drm::Device and drm::control::Device (drm-support feature)
drm-support Cargo feature is enabled and the wrapped T implements the drm-rs device traits, Device<T> forwards those trait implementations automatically. This lets you call drm-rs modesetting APIs — add_framebuffer, set_crtc, etc. — directly on the Device<T>.
Enable the
drm-support feature in Cargo.toml to unlock DRM/KMS integration:Full Method Reference
For a complete listing of every method onDevice<T> — including buffer object creation, surface allocation, and foreign buffer import — see Device Methods.