Function rasterize_app_icon

Source
pub fn rasterize_app_icon(
    icon: &AppIcon,
    px: u32,
) -> Result<RasterizedIcon, IconError>
Expand description

Validates and rasterizes an app icon, caching by source digest and side length.

px clamps to one for both key and output. Validation (including a 64-pixel preview) runs before every cache lookup. On a miss, source bytes are parsed a second time for final rendering. Sequential cache hits clone the RasterizedIcon and share its pixel Arc; concurrent misses can render redundantly and return different allocations before one cached value wins. The process-global cache has no eviction or byte/count bound.

§Errors

Returns any validate_app_icon error, a second-stage IconError::InvalidSvg, or IconError::Allocation for the requested normalized raster size.

§Panics

Panics with "app icon cache poisoned" if another thread poisons the global cache mutex. Allocation failures may also abort rather than return depending on the allocator.

§Examples

use std::sync::Arc;
use ailloli_ui_core::AppIcon;
use ailloli_ui_icon::rasterize_app_icon;
const SVG: &[u8] = br#"<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1 1"><rect width="1" height="1"/></svg>"#;
let icon = AppIcon::from_static_svg(SVG, "icon.svg");
let first = rasterize_app_icon(&icon, 0).unwrap();
let second = rasterize_app_icon(&icon, 1).unwrap();
assert_eq!((first.width, first.height), (1, 1));
assert!(Arc::ptr_eq(&first.rgba, &second.rgba));