element: Refactor element acquisition to be push based
This commit is contained in:
parent
178c6593dc
commit
e4c0716951
18 changed files with 1096 additions and 1137 deletions
|
|
@ -3,7 +3,7 @@
|
|||
use crate::{
|
||||
backend::render::{
|
||||
element::AsGlowRenderer,
|
||||
wayland::{SurfaceRenderElement, render_elements_from_surface_tree},
|
||||
wayland::{SurfaceRenderElement, push_render_elements_from_surface_tree},
|
||||
},
|
||||
utils::prelude::*,
|
||||
wayland::handlers::compositor::FRAME_TIME_FILTER,
|
||||
|
|
@ -185,8 +185,8 @@ pub fn draw_surface_cursor<R>(
|
|||
surface: &wl_surface::WlSurface,
|
||||
location: Point<f64, Logical>,
|
||||
scale: impl Into<Scale<f64>>,
|
||||
) -> Vec<(CursorRenderElement<R>, Point<i32, Physical>)>
|
||||
where
|
||||
push: &mut dyn FnMut(CursorRenderElement<R>, Point<i32, Physical>),
|
||||
) where
|
||||
R: Renderer + ImportAll + AsGlowRenderer,
|
||||
R::TextureId: Clone + 'static,
|
||||
{
|
||||
|
|
@ -202,7 +202,7 @@ where
|
|||
.to_physical_precise_round(scale)
|
||||
});
|
||||
|
||||
render_elements_from_surface_tree(
|
||||
push_render_elements_from_surface_tree(
|
||||
renderer,
|
||||
surface,
|
||||
location.to_physical(scale).to_i32_round(),
|
||||
|
|
@ -212,10 +212,9 @@ where
|
|||
false,
|
||||
[0; 4],
|
||||
Kind::Cursor,
|
||||
)
|
||||
.into_iter()
|
||||
.map(|elem| (elem, h))
|
||||
.collect()
|
||||
&mut |elem| push(elem.into(), h),
|
||||
None,
|
||||
);
|
||||
}
|
||||
|
||||
#[profiling::function]
|
||||
|
|
@ -224,8 +223,8 @@ pub fn draw_dnd_icon<R>(
|
|||
surface: &wl_surface::WlSurface,
|
||||
location: Point<f64, Logical>,
|
||||
scale: impl Into<Scale<f64>>,
|
||||
) -> Vec<SurfaceRenderElement<R>>
|
||||
where
|
||||
push: &mut dyn FnMut(SurfaceRenderElement<R>),
|
||||
) where
|
||||
R: Renderer + ImportAll + AsGlowRenderer,
|
||||
R::TextureId: Clone + 'static,
|
||||
{
|
||||
|
|
@ -236,7 +235,7 @@ where
|
|||
);
|
||||
}
|
||||
let scale = scale.into();
|
||||
render_elements_from_surface_tree(
|
||||
push_render_elements_from_surface_tree(
|
||||
renderer,
|
||||
surface,
|
||||
location.to_physical(scale).to_i32_round(),
|
||||
|
|
@ -246,7 +245,9 @@ where
|
|||
false,
|
||||
[0; 4],
|
||||
FRAME_TIME_FILTER,
|
||||
)
|
||||
push,
|
||||
None,
|
||||
);
|
||||
}
|
||||
|
||||
pub type CursorState = Mutex<CursorStateInner>;
|
||||
|
|
@ -330,8 +331,8 @@ pub fn draw_cursor<R>(
|
|||
buffer_scale: f64,
|
||||
time: Time<Monotonic>,
|
||||
draw_default: bool,
|
||||
) -> Vec<(CursorRenderElement<R>, Point<i32, Physical>)>
|
||||
where
|
||||
push: &mut dyn FnMut(CursorRenderElement<R>, Point<i32, Physical>),
|
||||
) where
|
||||
R: Renderer + ImportMem + ImportAll + AsGlowRenderer,
|
||||
R::TextureId: Send + Clone + 'static,
|
||||
{
|
||||
|
|
@ -343,7 +344,7 @@ where
|
|||
let state = &mut *state_ref;
|
||||
|
||||
if state.hidden {
|
||||
return Vec::new();
|
||||
return;
|
||||
}
|
||||
|
||||
let named_cursor = state.current_cursor.or(match cursor_status {
|
||||
|
|
@ -352,7 +353,7 @@ where
|
|||
});
|
||||
if let Some(current_cursor) = named_cursor {
|
||||
if !draw_default && current_cursor == CursorIcon::Default {
|
||||
return Vec::new();
|
||||
return;
|
||||
}
|
||||
|
||||
let integer_scale = (scale.x.max(scale.y) * buffer_scale).ceil() as u32;
|
||||
|
|
@ -389,7 +390,7 @@ where
|
|||
);
|
||||
state.current_image = Some(frame);
|
||||
|
||||
return vec![(
|
||||
push(
|
||||
CursorRenderElement::Static(
|
||||
MemoryRenderBufferRenderElement::from_buffer(
|
||||
renderer,
|
||||
|
|
@ -403,11 +404,9 @@ where
|
|||
.expect("Failed to import cursor bitmap"),
|
||||
),
|
||||
hotspot.to_physical_precise_round(scale),
|
||||
)];
|
||||
);
|
||||
} else if let CursorImageStatus::Surface(ref wl_surface) = cursor_status {
|
||||
return draw_surface_cursor(renderer, wl_surface, location, scale);
|
||||
} else {
|
||||
Vec::new()
|
||||
draw_surface_cursor(renderer, wl_surface, location, scale, push);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue