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.
Surface<T> represents a GBM rendering surface backed by an open GBM device. It serves as the native window type for EGL on DRM/KMS platforms — you pass the raw pointer obtained via AsRaw directly to eglCreateWindowSurface, and EGL allocates and manages the underlying pixel buffers for you. The type parameter T is the userdata type attached to any BufferObject<T> produced by this surface.
Surfaces are always created through Device methods rather than constructed directly. See the Device Methods reference for create_surface, create_surface_with_modifiers, and create_surface_with_modifiers2.
Struct Definition
Trait Implementations
| Trait | Notes |
|---|---|
Debug | Prints the raw surface pointer and device pointer. |
AsRaw<gbm_surface> | Returns *const gbm_surface for use with EGL and other C APIs. |
Send | Safe to transfer across threads. |
Sync | Safe to share references across threads. |
Methods
has_free_buffers
true if the surface has at least one unlocked (free) buffer available for rendering into.
Before a surface has ever been used, one buffer is free by default. Once buffers are locked via lock_front_buffer, the pool of free buffers shrinks. If all buffers are currently locked — for example, because a DRM page flip is still pending — this returns false and you must wait before starting a new frame.
Returns: true if a buffer is available, false if all buffers are locked.
Example
lock_front_buffer
BufferObject<T>. This is the buffer that was most recently rendered into and presented by calling eglSwapBuffers.
The returned BufferObject<T> holds an exclusive lock on that buffer. When you drop the BufferObject, the lock is automatically released and the buffer re-enters the free pool — you do not call any release function manually.
Returns: Ok(BufferObject<T>) on success, Err(FrontBufferError) if libgbm returns a null pointer.
Example
Front Buffer Protocol
The correct rendering loop withSurface<T> follows a strict ordering. Deviating from it can result in undefined behavior or visual corruption.
- Check
has_free_buffers()— only proceed iftrue. Iffalse, wait for an in-flight page flip to complete. - Bind the GBM surface as an EGL surface — call
eglMakeCurrentwith the EGL surface backed by thisSurface<T>. - Render with OpenGL ES — issue your draw calls as normal.
- Call
eglSwapBuffers— present the rendered image to the front buffer. - Call
lock_front_buffer()— obtain aBufferObject<T>representing the rendered frame. - Create a DRM framebuffer — pass the
BufferObject<T>toadd_framebuffer(or equivalent) to get a framebuffer handle. - Issue a page flip — schedule the framebuffer on the CRTC with
page_flip. - In the page flip completion callback: drop the old
BufferObject<T>— dropping it releases the GBM lock and returns the buffer to the free pool, makinghas_free_buffers()returntrueagain.
AsRaw for EGL Integration
Surface<T> implements AsRaw<gbm_surface>, which provides the raw *const gbm_surface pointer required when registering the surface as a native window with EGL.
Surface<T> value. Do not store it beyond that lifetime.