Skip to content

Commit

Permalink
Merge pull request #2672 from ids1024/screenshot
Browse files Browse the repository at this point in the history
Remove `surface` argument of `Compositor::screenshot`
  • Loading branch information
hecrj authored Nov 22, 2024
2 parents 6d50c62 + 3fc57b7 commit 53b7f50
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 32 deletions.
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 @@ -201,7 +200,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 @@ -353,34 +353,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 @@ -212,7 +211,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 @@ -222,14 +220,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 @@ -370,7 +370,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
1 change: 0 additions & 1 deletion winit/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1456,7 +1456,6 @@ fn run_action<P, C>(
if let Some(window) = window_manager.get_mut(id) {
let bytes = compositor.screenshot(
&mut window.renderer,
&mut window.surface,
window.state.viewport(),
window.state.background_color(),
&debug.overlay(),
Expand Down

0 comments on commit 53b7f50

Please sign in to comment.