Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subsurface_widget fixes #189

Merged
merged 8 commits into from
Dec 3, 2024
2 changes: 0 additions & 2 deletions graphics/src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ pub trait Compositor: Sized {
fn screenshot<T: AsRef<str>>(
&mut self,
renderer: &mut Self::Renderer,
surface: &mut Self::Surface,
viewport: &Viewport,
background_color: Color,
overlay: &[T],
Expand Down Expand Up @@ -213,7 +212,6 @@ impl Compositor for () {
fn screenshot<T: AsRef<str>>(
&mut self,
_renderer: &mut Self::Renderer,
_surface: &mut Self::Surface,
_viewport: &Viewport,
_background_color: Color,
_overlay: &[T],
Expand Down
41 changes: 17 additions & 24 deletions renderer/src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,34 +378,27 @@ where
fn screenshot<T: AsRef<str>>(
&mut self,
renderer: &mut Self::Renderer,
surface: &mut Self::Surface,
viewport: &graphics::Viewport,
background_color: Color,
overlay: &[T],
) -> Vec<u8> {
match (self, renderer, surface) {
(
Self::Primary(compositor),
Renderer::Primary(renderer),
Surface::Primary(surface),
) => compositor.screenshot(
renderer,
surface,
viewport,
background_color,
overlay,
),
(
Self::Secondary(compositor),
Renderer::Secondary(renderer),
Surface::Secondary(surface),
) => compositor.screenshot(
renderer,
surface,
viewport,
background_color,
overlay,
),
match (self, renderer) {
(Self::Primary(compositor), Renderer::Primary(renderer)) => {
compositor.screenshot(
renderer,
viewport,
background_color,
overlay,
)
}
(Self::Secondary(compositor), Renderer::Secondary(renderer)) => {
compositor.screenshot(
renderer,
viewport,
background_color,
overlay,
)
}
_ => unreachable!(),
}
}
Expand Down
9 changes: 5 additions & 4 deletions tiny_skia/src/window/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,11 @@ impl crate::graphics::Compositor for Compositor {
fn screenshot<T: AsRef<str>>(
&mut self,
renderer: &mut Self::Renderer,
surface: &mut Self::Surface,
viewport: &Viewport,
background_color: Color,
overlay: &[T],
) -> Vec<u8> {
screenshot(renderer, surface, viewport, background_color, overlay)
screenshot(renderer, viewport, background_color, overlay)
}
}

Expand Down Expand Up @@ -219,7 +218,6 @@ pub fn present<T: AsRef<str>>(

pub fn screenshot<T: AsRef<str>>(
renderer: &mut Renderer,
surface: &mut Surface,
viewport: &Viewport,
background_color: Color,
overlay: &[T],
Expand All @@ -229,14 +227,17 @@ pub fn screenshot<T: AsRef<str>>(
let mut offscreen_buffer: Vec<u32> =
vec![0; size.width as usize * size.height as usize];

let mut clip_mask = tiny_skia::Mask::new(size.width, size.height)
.expect("Create clip mask");

renderer.draw(
&mut tiny_skia::PixmapMut::from_bytes(
bytemuck::cast_slice_mut(&mut offscreen_buffer),
size.width,
size.height,
)
.expect("Create offscreen pixel map"),
&mut surface.clip_mask,
&mut clip_mask,
viewport,
&[Rectangle::with_size(Size::new(
size.width as f32,
Expand Down
1 change: 0 additions & 1 deletion wgpu/src/window/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,6 @@ impl graphics::Compositor for Compositor {
fn screenshot<T: AsRef<str>>(
&mut self,
renderer: &mut Self::Renderer,
_surface: &mut Self::Surface,
viewport: &Viewport,
background_color: Color,
overlay: &[T],
Expand Down
7 changes: 7 additions & 0 deletions winit/src/platform_specific/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ impl PlatformSpecific {
}
}

pub(crate) fn clear_subsurface_list(&mut self) {
#[cfg(all(feature = "wayland", target_os = "linux"))]
{
self.wayland.clear_subsurface_list();
}
}

pub(crate) fn update_subsurfaces(
&mut self,
id: window::Id,
Expand Down
9 changes: 4 additions & 5 deletions winit/src/platform_specific/wayland/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ pub(crate) struct WaylandSpecific {
modifiers: Modifiers,
surface_ids: HashMap<ObjectId, SurfaceIdWrapper>,
destroyed_surface_ids: HashMap<ObjectId, SurfaceIdWrapper>,
subsurface_ids: HashMap<ObjectId, (i32, i32, window::Id)>,
subsurface_state: Option<SubsurfaceState>,
surface_subsurfaces: HashMap<window::Id, Vec<SubsurfaceInstance>>,
}
Expand Down Expand Up @@ -138,7 +137,6 @@ impl WaylandSpecific {
display_handle,
surface_ids,
destroyed_surface_ids,
subsurface_ids,
modifiers,
subsurface_state,
surface_subsurfaces,
Expand All @@ -165,7 +163,6 @@ impl WaylandSpecific {
compositor,
window_manager,
surface_ids,
subsurface_ids,
sender,
event_sender,
proxy,
Expand All @@ -181,6 +178,10 @@ impl WaylandSpecific {
};
}

pub(crate) fn clear_subsurface_list(&mut self) {
let _ = crate::subsurface_widget::take_subsurfaces();
}

pub(crate) fn update_subsurfaces(
&mut self,
id: window::Id,
Expand All @@ -194,8 +195,6 @@ impl WaylandSpecific {
};

subsurface_state.update_subsurfaces(
id,
&mut self.subsurface_ids,
wl_surface,
surface_subsurfaces,
&subsurfaces,
Expand Down
18 changes: 3 additions & 15 deletions winit/src/platform_specific/wayland/sctk_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ impl SctkEvent {
compositor: &mut C,
window_manager: &mut crate::program::WindowManager<P, C>,
surface_ids: &mut HashMap<ObjectId, SurfaceIdWrapper>,
subsurface_ids: &mut HashMap<ObjectId, (i32, i32, window::Id)>,
sctk_tx: &channel::Sender<super::Action>,
control_sender: &mpsc::UnboundedSender<Control>,
proxy: &EventLoopProxy,
Expand Down Expand Up @@ -356,34 +355,23 @@ impl SctkEvent {
iced_runtime::core::Event::Mouse(mouse::Event::CursorLeft),
)),
PointerEventKind::Motion { .. } => {
let offset = if let Some((x_offset, y_offset, _)) =
subsurface_ids.get(&variant.surface.id())
{
(*x_offset, *y_offset)
} else {
(0, 0)
};
let id = surface_ids
.get(&variant.surface.id())
.map(|id| id.inner());
if let Some(w) =
id.clone().and_then(|id| window_manager.get_mut(id))
{
w.state.set_logical_cursor_pos(
(
variant.position.0 + offset.0 as f64,
variant.position.1 + offset.1 as f64,
)
.into(),
(variant.position.0, variant.position.1).into(),
)
}
events.push((
id,
iced_runtime::core::Event::Mouse(
mouse::Event::CursorMoved {
position: Point::new(
variant.position.0 as f32 + offset.0 as f32,
variant.position.1 as f32 + offset.1 as f32,
variant.position.0 as f32,
variant.position.1 as f32,
),
},
),
Expand Down
Loading
Loading