Skip to content

Commit

Permalink
Refactor: always screencopy full output, new FrameGuard and ScreenCap…
Browse files Browse the repository at this point in the history
…turer
  • Loading branch information
Decodetalkers authored and AndreasBackx committed Oct 25, 2023
1 parent 6d3da9a commit 4077a85
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 204 deletions.
20 changes: 8 additions & 12 deletions libwayshot/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::{
screencopy::FrameFormat,
};

#[derive(Debug)]
pub struct OutputCaptureState {
pub outputs: Vec<OutputInfo>,
}
Expand Down Expand Up @@ -128,12 +129,10 @@ impl Dispatch<ZxdgOutputV1, usize> for OutputCaptureState {
zxdg_output_v1::Event::LogicalPosition { x, y } => {
output_info.dimensions.x = x;
output_info.dimensions.y = y;
tracing::debug!("Logical position event fired!");
}
zxdg_output_v1::Event::LogicalSize { width, height } => {
output_info.dimensions.width = width;
output_info.dimensions.height = height;
tracing::debug!("Logical size event fired!");
}
_ => {}
};
Expand All @@ -156,6 +155,7 @@ pub struct CaptureFrameState {
}

impl Dispatch<ZwlrScreencopyFrameV1, ()> for CaptureFrameState {
#[tracing::instrument(skip(frame), level = "trace")]
fn event(
frame: &mut Self,
_: &ZwlrScreencopyFrameV1,
Expand All @@ -171,7 +171,6 @@ impl Dispatch<ZwlrScreencopyFrameV1, ()> for CaptureFrameState {
height,
stride,
} => {
tracing::debug!("Received Buffer event");
if let Value(f) = format {
frame.formats.push(FrameFormat {
format: f,
Expand All @@ -184,30 +183,27 @@ impl Dispatch<ZwlrScreencopyFrameV1, ()> for CaptureFrameState {
exit(1);
}
}
zwlr_screencopy_frame_v1::Event::Flags { .. } => {
tracing::debug!("Received Flags event");
}
zwlr_screencopy_frame_v1::Event::Ready { .. } => {
// If the frame is successfully copied, a “flags” and a “ready” events are sent. Otherwise, a “failed” event is sent.
// This is useful when we call .copy on the frame object.
tracing::debug!("Received Ready event");
tracing::trace!("Received Ready event");
frame.state.replace(FrameState::Finished);
}
zwlr_screencopy_frame_v1::Event::Failed => {
tracing::debug!("Received Failed event");
tracing::trace!("Received Failed event");
frame.state.replace(FrameState::Failed);
}
zwlr_screencopy_frame_v1::Event::Damage { .. } => {
tracing::debug!("Received Damage event");
tracing::trace!("Received Damage event");
}
zwlr_screencopy_frame_v1::Event::LinuxDmabuf { .. } => {
tracing::debug!("Received LinuxDmaBuf event");
tracing::trace!("Received LinuxDmaBuf event");
}
zwlr_screencopy_frame_v1::Event::BufferDone => {
tracing::debug!("Received bufferdone event");
tracing::trace!("Received bufferdone event");
frame.buffer_done.store(true, Ordering::SeqCst);
}
_ => unreachable!(),
_ => {}
};
}
}
Expand Down
15 changes: 3 additions & 12 deletions libwayshot/src/image_util.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use image::RgbaImage;
use wayland_client::protocol::wl_output::Transform;

#[tracing::instrument(skip(image))]
pub(crate) fn rotate_image_buffer(
image: RgbaImage,
transform: Transform,
width: u32,
height: u32,
) -> RgbaImage {
let final_buffer = match transform {
tracing::debug!("Rotating image buffer");
match transform {
Transform::_90 => image::imageops::rotate90(&image),
Transform::_180 => image::imageops::rotate180(&image),
Transform::_270 => image::imageops::rotate270(&image),
Expand All @@ -25,16 +27,5 @@ pub(crate) fn rotate_image_buffer(
image::imageops::rotate270(&flipped_buffer)
}
_ => image,
};

if final_buffer.dimensions() == (width, height) {
return final_buffer;
}

image::imageops::resize(
&final_buffer,
width,
height,
image::imageops::FilterType::Gaussian,
)
}
Loading

0 comments on commit 4077a85

Please sign in to comment.