Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions packages/rsnap-overlay/src/deferred_text_recognition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,34 @@ const PUBLISH_GATE_PENDING_POLL_INTERVAL: Duration = Duration::from_millis(5);
#[derive(Debug)]
pub(crate) enum DeferredTextRecognitionImageSource {
Prepared { image: RgbaImage },
FrozenCrop { frozen_image: RgbaImage, crop_rect: Option<RectPoints> },
FrozenCrop { export_image: RgbaImage, crop_rect: Option<RectPoints> },
}
#[cfg(target_os = "macos")]
impl DeferredTextRecognitionImageSource {
fn image_dimensions(&self) -> (u32, u32) {
match self {
Self::Prepared { image } => image.dimensions(),
Self::FrozenCrop { frozen_image, crop_rect } => crop_rect
Self::FrozenCrop { export_image, crop_rect } => crop_rect
.map(|crop_rect| (crop_rect.width, crop_rect.height))
.unwrap_or_else(|| frozen_image.dimensions()),
.unwrap_or_else(|| export_image.dimensions()),
}
}

#[cfg(test)]
fn export_image(&self) -> Option<RgbaImage> {
match self {
Self::Prepared { image } => Some(image.clone()),
Self::FrozenCrop { frozen_image, crop_rect } => {
export_image_from_frozen_crop(frozen_image, *crop_rect)
Self::FrozenCrop { export_image, crop_rect } => {
export_image_from_frozen_crop(export_image, *crop_rect)
},
}
}

fn into_export_image(self) -> Option<RgbaImage> {
match self {
Self::Prepared { image } => Some(image),
Self::FrozenCrop { frozen_image, crop_rect } => {
export_image_from_frozen_crop(&frozen_image, crop_rect)
Self::FrozenCrop { export_image, crop_rect } => {
export_image_from_frozen_crop(&export_image, crop_rect)
},
}
}
Expand Down Expand Up @@ -99,14 +99,14 @@ impl DeferredTextRecognitionRequest {
pub(crate) fn frozen_crop(
request_id: u64,
requested_at: Instant,
frozen_image: RgbaImage,
export_image: RgbaImage,
crop_rect: Option<RectPoints>,
) -> Self {
Self {
request_id,
requested_at,
image_source: DeferredTextRecognitionImageSource::FrozenCrop {
frozen_image,
export_image,
crop_rect,
},
}
Expand Down Expand Up @@ -499,7 +499,7 @@ fn outcome(

#[cfg(target_os = "macos")]
fn export_image_from_frozen_crop(
frozen_image: &RgbaImage,
export_image: &RgbaImage,
crop_rect: Option<RectPoints>,
) -> Option<RgbaImage> {
match crop_rect {
Expand All @@ -510,7 +510,7 @@ fn export_image_from_frozen_crop(

Some(
imageops::crop_imm(
frozen_image,
export_image,
crop_rect.x,
crop_rect.y,
crop_rect.width,
Expand All @@ -519,7 +519,7 @@ fn export_image_from_frozen_crop(
.to_image(),
)
},
None => Some(frozen_image.clone()),
None => Some(export_image.clone()),
}
}

Expand Down Expand Up @@ -578,7 +578,7 @@ mod tests {
request_id: 7,
requested_at: Instant::now(),
image_source: DeferredTextRecognitionImageSource::FrozenCrop {
frozen_image: image,
export_image: image,
crop_rect: Some(RectPoints::new(2, 1, 2, 2)),
},
};
Expand Down
36 changes: 18 additions & 18 deletions packages/rsnap-overlay/src/overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,7 @@ impl OverlaySession {
&& matches!(
self.frozen_capture_session_state,
FrozenCaptureSessionState::DisplayReady { .. }
) && self.state.frozen_surface_image().is_some()
) && self.state.frozen_display_surface_image().is_some()
}

fn frozen_display_ready_for_monitor(&self, monitor: MonitorRect) -> bool {
Expand Down Expand Up @@ -1906,7 +1906,7 @@ impl OverlaySession {
{
self.state.live_bg_monitor = None;

self.state.finish_freeze(monitor, image);
self.state.commit_frozen_final_image(monitor, image);
self.note_frozen_transition_preview_committed(monitor, "cached_live_background", None);
self.promote_frozen_capture_display_ready(monitor);
self.set_frozen_capture_export_ready(monitor);
Expand Down Expand Up @@ -1934,25 +1934,25 @@ impl OverlaySession {
monitor: MonitorRect,
capture_rect_pixels: RectPoints,
) -> Option<RgbaImage> {
let frozen_image = self.state.frozen_export_image.as_ref()?;
let x = capture_rect_pixels.x.min(frozen_image.width());
let y = capture_rect_pixels.y.min(frozen_image.height());
let max_width = frozen_image.width().saturating_sub(x);
let max_height = frozen_image.height().saturating_sub(y);
let export_image = self.state.frozen_export_image.as_ref()?;
let x = capture_rect_pixels.x.min(export_image.width());
let y = capture_rect_pixels.y.min(export_image.height());
let max_width = export_image.width().saturating_sub(x);
let max_height = export_image.height().saturating_sub(y);
let width = capture_rect_pixels.width.min(max_width);
let height = capture_rect_pixels.height.min(max_height);

if width == 0 || height == 0 {
tracing::debug!(
monitor_id = monitor.id,
capture_rect_pixels = ?capture_rect_pixels,
frozen_image_size = ?(frozen_image.width(), frozen_image.height()),
export_image_size = ?(export_image.width(), export_image.height()),
"Scroll capture base-frame crop resolved to an empty region."
);

None
} else {
Some(imageops::crop_imm(frozen_image, x, y, width, height).to_image())
Some(imageops::crop_imm(export_image, x, y, width, height).to_image())
}
}

Expand Down Expand Up @@ -2224,7 +2224,7 @@ impl OverlaySession {
WindowCaptureAlphaMode::Background => base_image,
WindowCaptureAlphaMode::MatteLight | WindowCaptureAlphaMode::MatteDark => {
let base_image = if had_display_image {
self.state.frozen_image.clone().unwrap_or(base_image)
self.state.frozen_display_image.clone().unwrap_or(base_image)
} else {
base_image
};
Expand Down Expand Up @@ -2613,19 +2613,19 @@ impl OverlaySession {
}

let crop_rect = self.deferred_text_recognition_crop_rect_pixels()?;
let frozen_image = self.state.frozen_export_image.take()?;
let export_image = self.state.frozen_export_image.take()?;

Some(DeferredTextRecognitionRequest::frozen_crop(
request_id,
requested_at,
frozen_image,
export_image,
crop_rect,
))
}

#[cfg(target_os = "macos")]
fn deferred_text_recognition_crop_rect_pixels(&self) -> Option<Option<RectPoints>> {
let frozen_image = self.state.frozen_export_image.as_ref()?;
let export_image = self.state.frozen_export_image.as_ref()?;
let Some(monitor) = self.state.monitor else {
return Some(None);
};
Expand All @@ -2634,17 +2634,17 @@ impl OverlaySession {
.frozen_capture_rect
.unwrap_or_else(|| RectPoints::new(0, 0, monitor.width, monitor.height));
let capture_rect = monitor.local_rect_to_pixels(capture_rect);
let x = capture_rect.x.min(frozen_image.width());
let y = capture_rect.y.min(frozen_image.height());
let max_width = frozen_image.width().saturating_sub(x);
let max_height = frozen_image.height().saturating_sub(y);
let x = capture_rect.x.min(export_image.width());
let y = capture_rect.y.min(export_image.height());
let max_width = export_image.width().saturating_sub(x);
let max_height = export_image.height().saturating_sub(y);
let width = capture_rect.width.min(max_width);
let height = capture_rect.height.min(max_height);

if width == 0 || height == 0 {
return None;
}
if x == 0 && y == 0 && width == frozen_image.width() && height == frozen_image.height() {
if x == 0 && y == 0 && width == export_image.width() && height == export_image.height() {
return Some(None);
}

Expand Down
14 changes: 7 additions & 7 deletions packages/rsnap-overlay/src/overlay/frozen_export_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@ impl OverlaySession {
}
}

let frozen_image = self.state.frozen_export_image.as_ref()?;
let export_image = self.state.frozen_export_image.as_ref()?;
let Some(monitor) = self.state.monitor else {
return Some(frozen_image.clone());
return Some(export_image.clone());
};
let capture_rect = self
.state
.frozen_capture_rect
.unwrap_or_else(|| RectPoints::new(0, 0, monitor.width, monitor.height));
let capture_rect = monitor.local_rect_to_pixels(capture_rect);
let x = capture_rect.x.min(frozen_image.width());
let y = capture_rect.y.min(frozen_image.height());
let max_width = frozen_image.width().saturating_sub(x);
let max_height = frozen_image.height().saturating_sub(y);
let x = capture_rect.x.min(export_image.width());
let y = capture_rect.y.min(export_image.height());
let max_width = export_image.width().saturating_sub(x);
let max_height = export_image.height().saturating_sub(y);
let width = capture_rect.width.min(max_width);
let height = capture_rect.height.min(max_height);

if width == 0 || height == 0 {
None
} else {
Some(imageops::crop_imm(frozen_image, x, y, width, height).to_image())
Some(imageops::crop_imm(export_image, x, y, width, height).to_image())
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/rsnap-overlay/src/overlay/frozen_mosaic_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl OverlaySession {
let preview_rect_px = monitor.local_rect_to_pixels(rect_points);
let Some(preview_patch) = self
.state
.frozen_image
.frozen_display_image
.as_ref()
.and_then(|image| Self::build_frozen_image_patch(image, preview_rect_px))
else {
Expand All @@ -168,7 +168,7 @@ impl OverlaySession {
_ => None,
};

if let Some(image) = self.state.frozen_image.as_mut() {
if let Some(image) = self.state.frozen_display_image.as_mut() {
Self::apply_frozen_image_patch(image, &preview_patch, true);
}
if let Some(image) = self.state.frozen_export_image.as_mut() {
Expand Down Expand Up @@ -196,7 +196,7 @@ impl OverlaySession {
return false;
};

if let Some(image) = self.state.frozen_image.as_mut() {
if let Some(image) = self.state.frozen_display_image.as_mut() {
Self::apply_frozen_image_patch(image, &edit.preview_patch, use_after);
}
if let Some(image) = self.state.frozen_export_image.as_mut() {
Expand Down
2 changes: 1 addition & 1 deletion packages/rsnap-overlay/src/overlay/rendering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,7 @@ impl WindowRenderer {

let draw_frozen_bg = hud_cfg.needs_frozen_surface_bg
&& state.monitor == Some(monitor)
&& state.frozen_surface_image().is_some();
&& state.frozen_display_surface_image().is_some();

self.finish_window_renderer_draw(
gpu,
Expand Down
4 changes: 2 additions & 2 deletions packages/rsnap-overlay/src/overlay/rendering/hud_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl WindowRenderer {
screen_size_points = ?screen_size_points,
flip_y = false,
frozen_generation = state.frozen_generation,
frozen_image_ready = state.frozen_image.is_some(),
display_image_ready = state.frozen_display_image.is_some(),
toolbar_active,
"Frozen frame metrics."
);
Expand Down Expand Up @@ -396,7 +396,7 @@ impl WindowRenderer {
(state.live_bg_generation, state.live_bg_image.as_ref())
},
OverlayMode::Frozen if state.monitor == Some(monitor) => {
(state.frozen_generation, state.frozen_surface_image())
(state.frozen_generation, state.frozen_display_surface_image())
},
OverlayMode::Live => {
self.hud_bg = None;
Expand Down
Loading
Loading