Skip to main content

Buffer

Struct Buffer 

Source
pub struct Buffer { /* private fields */ }
Expand description

An owned dumb buffer, its optional KMS framebuffer, and its CPU mapping.

Dumb buffers are KMS’s GPU-free allocation path: any driver implementing DRM_CAP_DUMB_BUFFER — every modern KMS driver — can allocate a CPU-mappable linear pixel buffer with no accelerator involved. They are the right tool for cursors, client-side decorations, software-rendered UI, and test harnesses.

§Deviation: the mapping is established once, not per map()

The drm crate’s map_dumb_buffer performs an mmap on every call and its guard munmaps on drop. That is the opposite of what invariant 6 requires — one mapping held for the buffer’s lifetime, and a free map() per frame. So the allocation and destruction ioctls come from the drm crate (DR-2), while the mapping is established once here at creation and held. See Mapping for why the cost contract matters.

Implementations§

Source§

impl Buffer

Source

pub const fn new() -> Self

An empty buffer holding no resources.

Source

pub fn create(device: &Device, config: &Config) -> Result<Self>

Allocate a single-plane dumb buffer.

§Errors
Source

pub fn create_planar( device: &Device, fourcc_code: u32, width: u32, height: u32, ) -> Result<Self>

Allocate a dumb buffer for a recognized semi-planar YUV format — NV12, NV21, P010, P012, or P016.

The kernel allocates one linear region; the framebuffer points the Y and interleaved-UV planes at distinct byte offsets within it. Pass the image dimensions: the over-allocation for the half-height chroma plane and the 8- versus 16-bit sample width are derived internally.

height should be even. The chroma half-height uses integer division, so an odd height rounds down.

§Errors
Source

pub const fn is_empty(&self) -> bool

Whether the buffer holds no allocation.

Source

pub const fn width(&self) -> u32

Width in pixels.

Source

pub const fn height(&self) -> u32

Height in pixels — the image height, not the over-allocated row count of a planar buffer.

Source

pub const fn stride(&self) -> u32

Bytes per row, as the kernel reported it.

Source

pub fn size_bytes(&self) -> usize

Total mapped bytes.

Source

pub fn gem_handle(&self) -> Option<u32>

The GEM handle on the originating descriptor.

Legacy cursor paths consume this directly; atomic paths use fb_id.

Source

pub fn fb_id(&self) -> Option<u32>

The KMS framebuffer id, if one was registered.

Source

pub fn data(&self) -> &[u8] ⓘ

The pixel storage, read only.

Source

pub fn data_mut(&mut self) -> &mut [u8] ⓘ

The pixel storage, mutable.

Source

pub fn map(&mut self, access: MapAccess) -> Mapping<'_>

Acquire a scoped CPU view.

Free in both directions — see Mapping and invariant 6. The access mode is recorded on the view but ignored here; it exists so the same scoped painting code works against dumb and GBM buffers.

Yields an empty view when the buffer is empty.

Source

pub fn forget(&mut self)

Abandon the GEM handle and framebuffer id without issuing ioctls.

For when the originating descriptor is known to be dead — libseat’s session-resume replaced the device. The CPU mapping is still torn down, because munmap is descriptor-independent, so the caller is left with a valid empty buffer. The kernel reclaims the orphaned handles when the descriptor closes.

Trait Implementations§

Source§

impl Debug for Buffer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Buffer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for Buffer

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.