DynamicRenderElementMap as a helper for iter on custom_elements

This commit is contained in:
dragonn 2022-01-19 17:35:30 +01:00
parent 478fe62808
commit 3ae387e991
1 changed files with 56 additions and 42 deletions

View File

@ -48,6 +48,52 @@ pub struct Space {
pub type DynamicRenderElements<R> = pub type DynamicRenderElements<R> =
Box<dyn RenderElement<R, <R as Renderer>::Frame, <R as Renderer>::Error, <R as Renderer>::TextureId>>; Box<dyn RenderElement<R, <R as Renderer>::Frame, <R as Renderer>::Error, <R as Renderer>::TextureId>>;
type SpaceElem<R> =
dyn SpaceElement<R, <R as Renderer>::Frame, <R as Renderer>::Error, <R as Renderer>::TextureId>;
struct DynamicRenderElementMap<'a, R: Renderer>(&'a [DynamicRenderElements<R>]);
impl<'a, R> DynamicRenderElementMap<'a, R>
where
R: Renderer + ImportAll + 'static,
R::TextureId: 'static,
R::Error: 'static,
R::Frame: 'static,
{
pub fn iter_bottom(&'a self) -> Box<dyn Iterator<Item = &SpaceElem<R>> + 'a> {
self.iter_layer(RenderLayer::Bottom)
}
pub fn iter_above_background(&'a self) -> Box<dyn Iterator<Item = &SpaceElem<R>> + 'a> {
self.iter_layer(RenderLayer::AboveBackground)
}
pub fn iter_before_windows(&'a self) -> Box<dyn Iterator<Item = &SpaceElem<R>> + 'a> {
self.iter_layer(RenderLayer::BeforeWindows)
}
pub fn iter_after_windows(&'a self) -> Box<dyn Iterator<Item = &SpaceElem<R>> + 'a> {
self.iter_layer(RenderLayer::AfterWindows)
}
pub fn iter_before_overlay(&'a self) -> Box<dyn Iterator<Item = &SpaceElem<R>> + 'a> {
self.iter_layer(RenderLayer::BeforeOverlay)
}
pub fn iter_top(&'a self) -> Box<dyn Iterator<Item = &SpaceElem<R>> + 'a> {
self.iter_layer(RenderLayer::Top)
}
pub fn iter_layer(&'a self, layer: RenderLayer) -> Box<dyn Iterator<Item = &SpaceElem<R>> + 'a> {
Box::new(
self.0
.iter()
.filter(move |c| c.layer() == layer)
.map(|c| c as &SpaceElem<R>),
)
}
}
impl PartialEq for Space { impl PartialEq for Space {
fn eq(&self, other: &Space) -> bool { fn eq(&self, other: &Space) -> bool {
self.id == other.id self.id == other.id
@ -474,9 +520,6 @@ impl Space {
return Err(RenderError::UnmappedOutput); return Err(RenderError::UnmappedOutput);
} }
type SpaceElem<R> =
dyn SpaceElement<R, <R as Renderer>::Frame, <R as Renderer>::Error, <R as Renderer>::TextureId>;
let mut state = output_state(self.id, output); let mut state = output_state(self.id, output);
let output_size = output let output_size = output
.current_mode() .current_mode()
@ -612,55 +655,26 @@ impl Space {
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
)?; )?;
let custom_elements = DynamicRenderElementMap(custom_elements);
// Then re-draw all windows & layers overlapping with a damage rect. // Then re-draw all windows & layers overlapping with a damage rect.
for element in custom_elements for element in custom_elements
.iter() .iter_bottom()
.filter(|c| c.layer() == RenderLayer::Bottom)
.map(|p| p as &SpaceElem<R>)
.chain( .chain(
layer_map layer_map
.layers_on(WlrLayer::Background) .layers_on(WlrLayer::Background)
.map(|l| l as &SpaceElem<R>) .map(|l| l as &SpaceElem<R>),
)
.chain(
custom_elements
.iter()
.filter(|c| c.layer() == RenderLayer::AboveBackground)
.map(|c| c as &SpaceElem<R>),
) )
.chain(custom_elements.iter_above_background())
.chain(layer_map.layers_on(WlrLayer::Bottom).map(|l| l as &SpaceElem<R>)) .chain(layer_map.layers_on(WlrLayer::Bottom).map(|l| l as &SpaceElem<R>))
.chain( .chain(custom_elements.iter_before_windows())
custom_elements
.iter()
.filter(|c| c.layer() == RenderLayer::BeforeWindows)
.map(|c| c as &SpaceElem<R>),
)
.chain(self.windows.iter().map(|w| w as &SpaceElem<R>)) .chain(self.windows.iter().map(|w| w as &SpaceElem<R>))
.chain( .chain(custom_elements.iter_after_windows())
custom_elements .chain(layer_map.layers_on(WlrLayer::Top).map(|l| l as &SpaceElem<R>))
.iter() .chain(custom_elements.iter_before_overlay())
.filter(|c| c.layer() == RenderLayer::AfterWindows)
.map(|c| c as &SpaceElem<R>),
)
.chain(
layer_map
.layers_on(WlrLayer::Top)
.map(|l| l as &SpaceElem<R>)
)
.chain(
custom_elements
.iter()
.filter(|c| c.layer() == RenderLayer::BeforeOverlay)
.map(|c| c as &SpaceElem<R>),
)
.chain(layer_map.layers_on(WlrLayer::Overlay).map(|l| l as &SpaceElem<R>)) .chain(layer_map.layers_on(WlrLayer::Overlay).map(|l| l as &SpaceElem<R>))
.chain( .chain(custom_elements.iter_top())
custom_elements
.iter()
.filter(|c| c.layer() == RenderLayer::Top)
.map(|c| c as &SpaceElem<R>),
)
{ {
let geo = element.geometry(self.id); let geo = element.geometry(self.id);
if damage.iter().any(|d| d.overlaps(geo)) { if damage.iter().any(|d| d.overlaps(geo)) {