Skip to main content

Surface

Struct Surface 

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

A decoration’s pixels, and the framebuffer they scan out through.

Implementations§

Source§

impl Surface

Source

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

Allocate a decoration surface.

§Errors

SurfaceError::Invalid for a zero dimension — refused here rather than passed to the kernel, which reports the same thing less clearly — and SurfaceError::Allocate if the driver refuses it.

Source

pub const fn is_empty(&self) -> bool

Whether this surface holds no buffer.

Source

pub fn fb_id(&self) -> u32

The framebuffer id, or zero when empty.

Zero rather than an error because that is what a presenter writes to disarm a plane — an empty surface and a disarmed slot are the same thing said twice.

Source

pub fn width(&self) -> u32

Width in pixels, or zero when empty.

Source

pub fn height(&self) -> u32

Height in pixels, or zero when empty.

Source

pub fn stride(&self) -> u32

Bytes between rows, or zero when empty.

Source

pub const fn format(&self) -> u32

Always SURFACE_FOURCC, empty or not.

A constant rather than a stored field: an empty surface still answers, because a caller laying out a decoration it has not allocated yet needs to know what it will be.

Source

pub const fn generation(&self) -> u64

How many times this surface has been painted — mapped by paint for anything other than MapAccess::Read.

Source

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

Map the pixels for drawing, and count the paint.

The generation is bumped for any map that allows writing, whether or not anything is actually written: a caller that mapped for writing intends to, and under-reporting a change leaves a stale decoration on screen where over-reporting only costs a recomposite. A read-only (MapAccess::Read) map does not bump it.

§Errors

SurfaceError::Empty when there is no buffer.

Source

pub fn export(&self, device: &Device) -> Result<OwnedFd, SurfaceError>

Export the buffer as a DMA-BUF.

The descriptor is close-on-exec, as the reference exports it, so a compositor that spawns a client does not hand it the decoration.

§Errors

SurfaceError::Empty when there is no buffer, and SurfaceError::Export with the kernel’s errno when the export is refused.

Source

pub fn forget(&mut self)

Drop the buffer without issuing ioctls against its descriptor.

For a session that lost its device: the handles are already dead, so destroying them would fail, and the kernel reclaims them when the descriptor closes. Forgetting an already-empty surface is a no-op, which is what a caller tearing down twice does.

Trait Implementations§

Source§

impl Debug for Surface

Source§

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

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

impl Default for Surface

Source§

fn default() -> Self

Returns the “default value” for a type. 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.