When a Wayland compositor receives a buffer commit from a client, the underlying pixel memory is often already GPU-accessible — either as a GBM buffer the client allocated itself or as a DMA-BUF shared through theDocumentation 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.
zwp_linux_dmabuf_v1 protocol. Rather than copying that pixel data into a new allocation, gbm.rs provides import_buffer_object_from_wayland, which wraps the client’s WlBuffer in a GBM BufferObject that shares the same backing memory. The resulting buffer object can then be passed directly to a DRM framebuffer or composited using EGL — without any extra allocation or copy.
Prerequisites
import-wayland feature
The
import-wayland feature must be enabled. It is on by default and pulls in wayland-server 0.31 and wayland-backend.wayland-server 0.31
Your compositor must use
wayland-server = "0.31" so that WlBuffer matches the type expected by gbm.rs.Cargo.toml Configuration
import-wayland feature is included in gbm’s default feature set, so you only need to opt out explicitly if you want to exclude it:
Importing a WlBuffer
The method signature for importing a Wayland buffer is:buffer— a reference to theWlBufferreceived in awl_surface::commitorwl_buffer::attachhandler.usage— a combination of [BufferObjectFlags] describing intended use. UseSCANOUTto present via KMS, and addRENDERINGif you need to sample from it in a shader.- Returns —
IoResult<BufferObject<U>>, whereUis any'staticuserdata type (use()if you need none).
Example: Handling a Buffer Commit
The following example shows how to import aWlBuffer inside a wl_surface::commit handler and immediately create a DRM framebuffer for scanout.
Feature Gate Details
The
import-wayland feature pulls in two crates:wayland-server = "0.31"— provides theWlBuffertype and theResourcetrait used to extract the underlying object pointer.wayland-backend = "0.3"with theserver_systemfeature — required bywayland-serverfor the system-level dispatch backend.
wayland-server, you must align on 0.31 or disable import-wayland and implement your own import path using import_buffer_object_from_dma_buf with the buffer’s DMA-BUF file descriptor.