use std::collections::HashSet;
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct Features {
pub gl: bool,
pub egl: bool,
pub wayland: bool,
pub x11: bool,
pub vulkan: bool,
pub metal: bool,
pub d3d: bool,
pub text_layout: bool,
pub svg: bool,
pub webp_encode: bool,
pub webp_decode: bool,
pub embed_freetype: bool,
pub animation: bool,
pub dng: bool,
pub particles: bool,
}
impl Default for Features {
fn default() -> Self {
Features {
gl: cfg!(feature = "gl"),
egl: cfg!(feature = "egl"),
wayland: cfg!(feature = "wayland"),
x11: cfg!(feature = "x11"),
vulkan: cfg!(feature = "vulkan"),
metal: cfg!(feature = "metal"),
d3d: cfg!(feature = "d3d"),
text_layout: cfg!(feature = "textlayout"),
svg: cfg!(feature = "svg"),
webp_encode: cfg!(feature = "webp-encode"),
webp_decode: cfg!(feature = "webp-decode"),
embed_freetype: cfg!(feature = "embed-freetype"),
animation: false,
dng: false,
particles: false,
}
}
}
impl Features {
pub fn gpu(&self) -> bool {
self.gl || self.vulkan || self.metal || self.d3d
}
pub fn ids(&self) -> HashSet<&str> {
let mut feature_ids = Vec::new();
if self.gl {
feature_ids.push(feature_id::GL);
}
if self.egl {
feature_ids.push(feature_id::EGL);
}
if self.x11 {
feature_ids.push(feature_id::X11);
}
if self.wayland {
feature_ids.push(feature_id::WAYLAND);
}
if self.vulkan {
feature_ids.push(feature_id::VULKAN);
}
if self.metal {
feature_ids.push(feature_id::METAL);
}
if self.d3d {
feature_ids.push(feature_id::D3D);
}
if self.text_layout {
feature_ids.push(feature_id::TEXTLAYOUT);
}
if self.svg {
feature_ids.push(feature_id::SVG);
}
if self.webp_encode {
feature_ids.push(feature_id::WEBPE);
}
if self.webp_decode {
feature_ids.push(feature_id::WEBPD);
}
if self.embed_freetype {
feature_ids.push(feature_id::EMBED_FREETYPE);
}
feature_ids.into_iter().collect()
}
}
mod feature_id {
pub const GL: &str = "gl";
pub const VULKAN: &str = "vulkan";
pub const METAL: &str = "metal";
pub const D3D: &str = "d3d";
pub const TEXTLAYOUT: &str = "textlayout";
pub const SVG: &str = "svg";
pub const WEBPE: &str = "webpe";
pub const WEBPD: &str = "webpd";
pub const EGL: &str = "egl";
pub const X11: &str = "x11";
pub const WAYLAND: &str = "wayland";
pub const EMBED_FREETYPE: &str = "freetype";
}