Skip to content

Commit

Permalink
Refactor: introduce FrameGuard, ScreenCapturer, and Logical/EmbeddedR…
Browse files Browse the repository at this point in the history
…egion
  • Loading branch information
Decodetalkers authored and AndreasBackx committed Oct 31, 2023
1 parent 6d3da9a commit 4d3819a
Show file tree
Hide file tree
Showing 6 changed files with 433 additions and 188 deletions.
29 changes: 12 additions & 17 deletions libwayshot/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ use crate::{
screencopy::FrameFormat,
};

#[derive(Debug)]
pub struct OutputCaptureState {
pub outputs: Vec<OutputInfo>,
}

impl Dispatch<WlRegistry, ()> for OutputCaptureState {
#[tracing::instrument(skip(wl_registry, qh), ret, level = "trace")]
fn event(
state: &mut Self,
wl_registry: &WlRegistry,
Expand Down Expand Up @@ -76,6 +78,7 @@ impl Dispatch<WlRegistry, ()> for OutputCaptureState {
}

impl Dispatch<WlOutput, ()> for OutputCaptureState {
#[tracing::instrument(skip(wl_output), ret, level = "trace")]
fn event(
state: &mut Self,
wl_output: &WlOutput,
Expand Down Expand Up @@ -114,6 +117,7 @@ impl Dispatch<WlOutput, ()> for OutputCaptureState {
delegate_noop!(OutputCaptureState: ignore ZxdgOutputManagerV1);

impl Dispatch<ZxdgOutputV1, usize> for OutputCaptureState {
#[tracing::instrument(ret, level = "trace")]
fn event(
state: &mut Self,
_: &ZxdgOutputV1,
Expand All @@ -128,19 +132,20 @@ 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!");
}
zxdg_output_v1::Event::Done => {}
zxdg_output_v1::Event::Name { .. } => {}
zxdg_output_v1::Event::Description { .. } => {}
_ => {}
};
}
}

/// State of the frame after attemting to copy it's data to a wl_buffer.
/// State of the frame after attempting to copy it's data to a wl_buffer.
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum FrameState {
/// Compositor returned a failed event on calling `frame.copy`.
Expand All @@ -156,6 +161,7 @@ pub struct CaptureFrameState {
}

impl Dispatch<ZwlrScreencopyFrameV1, ()> for CaptureFrameState {
#[tracing::instrument(skip(frame), ret, level = "trace")]
fn event(
frame: &mut Self,
_: &ZwlrScreencopyFrameV1,
Expand All @@ -171,7 +177,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 +189,20 @@ 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");
frame.state.replace(FrameState::Finished);
}
zwlr_screencopy_frame_v1::Event::Failed => {
tracing::debug!("Received Failed event");
frame.state.replace(FrameState::Failed);
}
zwlr_screencopy_frame_v1::Event::Damage { .. } => {
tracing::debug!("Received Damage event");
}
zwlr_screencopy_frame_v1::Event::LinuxDmabuf { .. } => {
tracing::debug!("Received LinuxDmaBuf event");
}
zwlr_screencopy_frame_v1::Event::Damage { .. } => {}
zwlr_screencopy_frame_v1::Event::LinuxDmabuf { .. } => {}
zwlr_screencopy_frame_v1::Event::BufferDone => {
tracing::debug!("Received bufferdone event");
frame.buffer_done.store(true, Ordering::SeqCst);
}
_ => unreachable!(),
_ => {}
};
}
}
Expand Down
1 change: 1 addition & 0 deletions libwayshot/src/image_util.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use image::RgbaImage;
use wayland_client::protocol::wl_output::Transform;

#[tracing::instrument(skip(image))]
pub(crate) fn rotate_image_buffer(
image: RgbaImage,
transform: Transform,
Expand Down
Loading

0 comments on commit 4d3819a

Please sign in to comment.