use crate::backdrop::BackdropSources;
use crate::region::{RegionRect, shape_of};
use crate::renderer::{ClipChains, DrawCommand, FlattenedCommand};
pub(crate) fn regions_from_commands(
commands: &[FlattenedCommand],
chains: &ClipChains,
) -> Vec<RegionRect> {
let mut out = Vec::new();
for cmd in commands {
let DrawCommand::BackdropBlur {
rect,
sources,
corner_radii,
curvature,
..
} = &*cmd.command
else {
continue;
};
if !sources.contains(BackdropSources::COMPOSITOR) {
continue;
}
out.extend(shape_of(cmd, chains, *rect, *corner_radii, *curvature));
}
out.sort_unstable_by_key(|r| (r.y, r.x, r.width, r.height));
out
}
#[cfg(test)]
mod tests {
use super::*;
use crate::renderer::CornerRadii;
use crate::widgets::Rect;
#[test]
fn a_compositor_region_does_not_need_a_radius() {
let command = FlattenedCommand {
command: std::rc::Rc::new(DrawCommand::BackdropBlur {
rect: Rect::new(0.0, 0.0, 100.0, 50.0),
sources: BackdropSources::COMPOSITOR,
radius: 0.0,
corner_radii: CornerRadii::uniform(0.0),
curvature: 1.0,
}),
world_transform: Default::default(),
layer: Default::default(),
opacity: 1.0,
clip: None,
};
assert_eq!(
regions_from_commands(&[command], &Default::default()),
vec![RegionRect {
x: 0,
y: 0,
width: 100,
height: 50
}]
);
}
}