pub struct ImageData {
pub id: u64,
pub width: u32,
pub height: u32,
/* private fields */
}Fields§
§id: u64Content address: equal pixels at equal dimensions give equal ids, whoever built them and whenever.
The renderers key their texture caches on this and nothing else, so the id has to identify the image. A per-construction counter identified the allocation instead: a caller that rebuilt the same image each frame — which is what building an ImageData inside a widget body does — minted a fresh key every time, and every entry behind it became unreachable weight the cache could only shed by hitting its byte budget.
An external texture cannot be hashed, so its owner supplies the id and carries the same duty: keep it stable while the texture is, and change it when the texture object is replaced.
width: u32§height: u32Implementations§
Source§impl ImageData
impl ImageData
pub fn new(pixels: Vec<u8>, width: u32, height: u32) -> Self
Sourcepub fn from_premultiplied(pixels: Vec<u8>, width: u32, height: u32) -> Self
pub fn from_premultiplied(pixels: Vec<u8>, width: u32, height: u32) -> Self
Builds from bytes that are ALREADY premultiplied (e.g. a resvg Pixmap), skipping the premultiply step new() performs.
Sourcepub fn external(
texture: Arc<dyn ExternalTexture>,
id: u64,
width: u32,
height: u32,
) -> Self
pub fn external( texture: Arc<dyn ExternalTexture>, id: u64, width: u32, height: u32, ) -> Self
Refers to a texture the application owns and keeps filling, rather than pixels Telar uploads.
id addresses the texture object, not its contents: the whole point is that the contents change
every frame without Telar being told. Bump it only when the texture itself is replaced — a resize,
a format change — so the bind group built against the old one is dropped.
Sourcepub fn pixels(&self) -> &[u8] ⓘ
pub fn pixels(&self) -> &[u8] ⓘ
The premultiplied RGBA8 bytes; empty when the picture lives in a texture Telar does not own.
Empty rather than Option so a backend that cannot use an external texture needs no special case:
every path that turns these bytes into a raster already has to reject a buffer too short for the
dimensions, and an empty one takes that branch.