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.
MappedBufferObject<'a, T> is a short-lived view of a CPU-mapped GBM buffer region. It is created exclusively through BufferObject::map (read-only) or BufferObject::map_mut (read-write) and exists only for the duration of the closure passed to those methods. When the MappedBufferObject is dropped at the end of the closure, gbm_bo_unmap is called automatically, flushing any pending writes back to the GPU buffer and releasing the CPU mapping. You never construct MappedBufferObject directly.
Type Definition
'a is borrowed from the BufferObject<T> that produced this mapping — either &'a BufferObject<T> (read-only) or &'a mut BufferObject<T> (read-write). This ensures the mapping cannot outlive the buffer object it came from, and that a mutable mapping holds an exclusive borrow, preventing concurrent access.
Trait Implementations
| Trait | Notes |
|---|---|
Debug | Prints the mapping mode (read or write) and the inner BufferObject debug output. |
Deref<Target = BufferObject<T>> | Provides transparent access to all BufferObject<T> methods (width, height, format, fd, etc.) through the mapped view. |
DerefMut | Available only for mutable mappings (map_mut). Panics at runtime if attempted on a read-only mapping (this case is unreachable under safe usage). |
Drop | Calls gbm_bo_unmap and frees the mapping when the closure scope ends. |
Methods
stride
BufferObject::stride() if the backend uses a staging buffer internally.
The total byte length of the mapped pixel data is
height() * stride(). Always use the mapped stride — not the buffer’s stride — when indexing into buffer() or buffer_mut().height
height argument supplied to map or map_mut.
width
width argument supplied to map or map_mut.
x
x argument supplied to map or map_mut.
y
y argument supplied to map or map_mut.
buffer
height * stride bytes. Pixels are laid out row by row; each row is stride bytes wide, with width * bytes_per_pixel bytes of actual pixel data followed by any padding bytes required for alignment.
buffer_mut
map_mut closure. Changes written to this slice are flushed to the GPU buffer when the mapping is dropped at closure return.
Read Example
Read a 1×1 pixel region from aFormat::Argb8888 buffer and decode it into component channels:
Write Example
Map a full buffer for writing and paint every pixel red usingmap_mut:
The byte length of the slice returned by
buffer() and buffer_mut() is always height * stride, not height * width * bytes_per_pixel. The stride is guaranteed to be at least width * bytes_per_pixel, but may be larger due to hardware row-alignment requirements. Always iterate rows using the stride value to avoid reading padding bytes as pixel data.