Skip to main content

FormatTable

Struct FormatTable 

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

A plane’s accepted (fourcc, modifier) pairs, sorted and de-duplicated.

Implementations§

Source§

impl FormatTable

Source

pub const fn new() -> Self

An empty table, accepting nothing.

Source

pub fn from_blob(data: &[u8]) -> Self

Parse a raw IN_FORMATS blob payload.

Malformed input yields an empty (or partial) table rather than an error: a plane whose blob does not parse is simply a plane nothing is eligible for, and the caller’s fallback (“formats[] implies LINEAR only”) is the same either way. This matches the C++, which returns a default- constructed table on every guard.

§Robustness

The blob’s arrays may begin at offsets that are not naturally aligned. In C++ that made indexing a typed pointer into the blob undefined behavior, and it faulted on strict-alignment targets — the C++ fix was to memcpy each element out. Here every field is read byte-wise from a slice with a bounds-checked accessor, so alignment cannot arise as a concern at all. Counts are validated against the remaining length before use, in division form, so no count * size product can overflow.

use drmkit_fmt::FormatTable;
// Too short to hold a header: empty table, no panic.
assert!(FormatTable::from_blob(&[0u8; 4]).all().is_empty());
assert!(FormatTable::from_blob(&[]).all().is_empty());
Source

pub fn from_pairs<I>(pairs: I) -> Self
where I: IntoIterator<Item = (u32, Modifier)>,

Build a table from already-decoded pairs — for a caller that harvested IN_FORMATS by other means and wants the queryable table without re-reading the blob.

Duplicates are removed; input order does not matter.

use drmkit_fmt::{FormatTable, Modifier, fourcc};
let table = FormatTable::from_pairs([
    (fourcc::XRGB8888, Modifier::LINEAR),
    (fourcc::XRGB8888, Modifier::LINEAR), // duplicate
    (fourcc::NV12, Modifier::LINEAR),
]);
assert_eq!(table.all().len(), 2);
Source

pub fn supports(&self, fourcc: u32, modifier: Modifier) -> bool

Whether the plane advertises this exact (fourcc, modifier) pair.

This is exact-match only. Family-aware eligibility — which is what the allocator wants — is crate::layer_fits_plane.

Source

pub fn modifiers_for(&self, fourcc: u32) -> impl Iterator<Item = Modifier> + '_

Every modifier advertised for fourcc, ascending.

Source

pub fn all(&self) -> &[FormatMod]

Every advertised pair, sorted by (fourcc, modifier).

Source

pub fn is_empty(&self) -> bool

Whether the table advertises nothing.

Source

pub fn len(&self) -> usize

Number of advertised pairs.

Trait Implementations§

Source§

impl Clone for FormatTable

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FormatTable

Source§

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

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

impl Default for FormatTable

Source§

fn default() -> Self

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

impl Eq for FormatTable

Source§

impl PartialEq for FormatTable

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for FormatTable

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.