Add a SplitRenderElements type, with useful methods

`(w_elements, p_elements)` tuples are used in a bunch of places. A
struct with named fields is generally an improvement just due to the
fact the order is non-obvious.

But we can also add methods. In particular,
`extend_from_workspace_elements` abstracts out some of the more
redundant code in `workspace_elements`.

It would be nice to avoid allocation everywhere, but iterators would
complicate lifetimes, run into issues with needing multiple mutable
borrows to things like the `Renderer`, and be awkward in certain
functions without generator syntax. In any case, cosmic-comp already
relies on allocating vectors here.

If this abstraction is commonly useful in compositors, perhaps it could
be moved to Smithay.
This commit is contained in:
Ian Douglas Scott 2024-07-09 15:21:16 -07:00 committed by Victoria Brekenfeld
parent c506d94ac8
commit 94fecec9cb
9 changed files with 374 additions and 379 deletions

View file

@ -1,5 +1,8 @@
use crate::{
backend::render::cursor::{CursorShape, CursorState},
backend::render::{
cursor::{CursorShape, CursorState},
SplitRenderElements,
},
shell::{
focus::target::PointerFocusTarget,
grabs::{ReleaseMode, ResizeEdge},
@ -317,7 +320,7 @@ impl CosmicWindow {
location: smithay::utils::Point<i32, smithay::utils::Physical>,
scale: smithay::utils::Scale<f64>,
alpha: f32,
) -> (Vec<C>, Vec<C>)
) -> SplitRenderElements<C>
where
R: Renderer + ImportAll + ImportMem,
<R as Renderer>::TextureId: Send + Clone + 'static,
@ -331,12 +334,17 @@ impl CosmicWindow {
location
};
let (mut window_elements, popup_elements) = self.0.with_program(|p| {
p.window
.split_render_elements::<R, CosmicWindowRenderElement<R>>(
renderer, window_loc, scale, alpha,
)
});
let mut elements = SplitRenderElements::default();
elements.extend_map(
self.0.with_program(|p| {
p.window
.split_render_elements::<R, CosmicWindowRenderElement<R>>(
renderer, window_loc, scale, alpha,
)
}),
C::from,
);
if has_ssd {
let ssd_loc = location
@ -344,15 +352,16 @@ impl CosmicWindow {
.0
.with_program(|p| p.window.geometry().loc)
.to_physical_precise_round(scale);
window_elements.extend(AsRenderElements::<R>::render_elements::<
CosmicWindowRenderElement<R>,
>(&self.0, renderer, ssd_loc, scale, alpha))
elements.w_elements.extend(
AsRenderElements::<R>::render_elements::<CosmicWindowRenderElement<R>>(
&self.0, renderer, ssd_loc, scale, alpha,
)
.into_iter()
.map(C::from),
)
}
(
window_elements.into_iter().map(C::from).collect(),
popup_elements.into_iter().map(C::from).collect(),
)
elements
}
pub(crate) fn set_theme(&self, theme: cosmic::Theme) {