GBM surfaces serve as the bridge between GPU rendering and KMS display output. 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.
Surface<T> type created by gbm.rs implements the EGL native window interface: its raw pointer — obtained via the AsRaw trait — is passed to eglCreateWindowSurface as the EGLNativeWindowType. After each eglSwapBuffers call, GBM promotes the rendered back buffer to the front and makes it available for scanout. You then lock that front buffer with lock_front_buffer, wrap it in a DRM framebuffer, and issue a page flip. This cycle repeats every frame, giving you tear-free, GPU-accelerated output on bare-metal DRM with no display server required.
Required Feature Flags
The full rendering loop depends on two gbm.rs features:| Feature | Purpose |
|---|---|
drm-support | Enables add_framebuffer and the drm::buffer::Buffer impl on BufferObject |
import-egl | Exposes EGLImage type alias and import_buffer_object_from_egl |
Cargo.toml:
Rendering Loop Overview
Create the GBM Surface
Allocate a
Surface<T> with the SCANOUT and RENDERING flags. RENDERING tells the allocator the buffer will be used as a render target; SCANOUT signals it will also be presented to the display. Use Format::Argb8888 for surfaces that may include transparency during composition.Pass the Raw Pointer to EGL
EGL expects an
EGLNativeWindowType, which on GBM is simply the raw gbm_surface pointer. Retrieve it with AsRaw::as_raw and cast it to the platform native window type before passing it to eglCreateWindowSurface.as_raw() returns a *const gbm_surface. Most EGL bindings expect a *mut c_void; cast with as *mut _ — this is safe because EGL only reads the pointer value and does not mutate through it.Check for Free Buffers
Before beginning a new frame, verify that the surface has at least one unlocked buffer available. After the first frame, previously locked front buffers may not yet have been released by the display controller.
Render a Frame with OpenGL ES
Issue your OpenGL ES draw calls through the EGL context. When finished, call
eglSwapBuffers to flush rendering and promote the back buffer to the front. This must happen before lock_front_buffer.Lock the Front Buffer
After
eglSwapBuffers, call lock_front_buffer to obtain a BufferObject wrapping the rendered frame. This function is unsafe because it must be called exactly once per eglSwapBuffers invocation.Always check
surface.has_free_buffers() before starting a new frame. A GBM surface has a finite pool of backing buffers. If you lock a front buffer but do not release it before the next eglSwapBuffers, the surface may run out of free buffers and lock_front_buffer will return a FrontBufferError.