Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(scap-direct3d): only follow the item's size for window captures

Stephen Psaradellisfd8daaa84b8e
diff --git a/crates/recording/src/sources/screen_capture/windows.rs b/crates/recording/src/sources/screen_capture/windows.rs
index 3543679d3..bf99efb64 100644
--- a/crates/recording/src/sources/screen_capture/windows.rs
+++ b/crates/recording/src/sources/screen_capture/windows.rs
@@ -417,6 +417,9 @@ impl ScreenCaptureConfig<Direct3DCapture> {
}),
// Matches `window_capture_size`, which the output is sized from.
even_dimensions: self.config.window.is_some(),
+ // Only a window target follows its item's size; display and area
+ // recordings keep the pool they were created with.
+ follow_item_size: self.config.window.is_some(),
..Default::default()
};
diff --git a/crates/scap-direct3d/src/lib.rs b/crates/scap-direct3d/src/lib.rs
index f5e5effab..77b31a6fa 100644
--- a/crates/scap-direct3d/src/lib.rs
+++ b/crates/scap-direct3d/src/lib.rs
@@ -367,6 +367,10 @@ pub struct Settings {
/// consumer that encodes at even dimensions receives frames it can take as
/// they are. Ignored when `crop` is set.
pub even_dimensions: bool,
+ /// Follow the capture item when it changes size: recreate the frame pool
+ /// at the new size, and drop frames a `crop` box no longer fits inside.
+ /// Off by default so display and area captures behave as they always have.
+ pub follow_item_size: bool,
}
impl Settings {
@@ -601,6 +605,7 @@ impl Capturer {
let pixel_format = settings.pixel_format;
let pool_size = pool_size.clone();
let even_dimensions = settings.even_dimensions && settings.crop.is_none();
+ let follow_item_size = settings.follow_item_size;
move |frame_pool, _| {
let _activity_guard = callback_activity.enter();
@@ -624,7 +629,7 @@ impl Capturer {
// describing its texture and every later frame reads
// back as black. Recreate the pool for the new size and
// skip this frame; the next one arrives correctly sized.
- {
+ if follow_item_size {
let mut pool_size = pool_size
.lock()
.unwrap_or_else(|poisoned| poisoned.into_inner());
@@ -656,8 +661,9 @@ impl Capturer {
// A shrunk item leaves the crop box hanging off the
// edge of the source texture, which copies nothing
// and would vend a stale surface as if it were live.
- if crop.right > size.Width.max(0) as u32
- || crop.bottom > size.Height.max(0) as u32
+ if follow_item_size
+ && (crop.right > size.Width.max(0) as u32
+ || crop.bottom > size.Height.max(0) as u32)
{
return Ok(());
}
diff --git a/crates/scap-direct3d/tests/window_capture.rs b/crates/scap-direct3d/tests/window_capture.rs
index 322b869ca..895f613a1 100644
--- a/crates/scap-direct3d/tests/window_capture.rs
+++ b/crates/scap-direct3d/tests/window_capture.rs
@@ -421,12 +421,15 @@ fn frames_survive_the_capture_item_resizing() {
let window = fixture.window();
let before = window.physical_size().expect("window size");
- let samples = capture_samples(
+ let samples = capture_samples_with(
window
.raw_handle()
.try_as_capture_item()
.expect("window capture item"),
- None,
+ Settings {
+ follow_item_size: true,
+ ..Default::default()
+ },
Duration::from_secs(4),
|| {
std::thread::sleep(Duration::from_millis(500));