pub struct FormatTable { /* private fields */ }Expand description
A plane’s accepted (fourcc, modifier) pairs, sorted and de-duplicated.
Implementations§
Source§impl FormatTable
impl FormatTable
Sourcepub fn from_blob(data: &[u8]) -> Self
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());Sourcepub fn from_pairs<I>(pairs: I) -> Self
pub fn from_pairs<I>(pairs: I) -> Self
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);Sourcepub fn supports(&self, fourcc: u32, modifier: Modifier) -> bool
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.
Sourcepub fn modifiers_for(&self, fourcc: u32) -> impl Iterator<Item = Modifier> + '_
pub fn modifiers_for(&self, fourcc: u32) -> impl Iterator<Item = Modifier> + '_
Every modifier advertised for fourcc, ascending.