tighten visibility and clear the remaining mechanical lint noise

This commit is contained in:
2026-09-21 00:44:25 +03:00
parent 1332600148
commit 03b2fec744
11 changed files with 158 additions and 172 deletions
+25 -25
View File
@@ -40,14 +40,14 @@ const FULLSCREEN_VS: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/fullscree
const TONEMAP_PS: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/tonemap_ps.cso"));
/// Hard ceiling for the Full quality mode so a 4K recording can't balloon to
/// 8K on exotic hardware. Auto mode caps at AUTO_ENCODE_WIDTH instead.
/// 8K on exotic hardware. Auto mode caps at `AUTO_ENCODE_WIDTH` instead.
const MAX_ENCODE_WIDTH: u32 = 3840;
const AUTO_ENCODE_WIDTH: u32 = 1920;
const FALLBACK_REFRESH_HZ: u32 = 60;
/// Returns the cap to apply to the encode width, or None for native res.
/// Auto keeps the historic 1920 cap so nothing changes for existing users;
/// Full records at native res up to MAX_ENCODE_WIDTH (3840).
/// Full records at native res up to `MAX_ENCODE_WIDTH` (3840).
fn encode_width_limit(quality: CaptureQuality) -> Option<u32> {
match quality {
CaptureQuality::Auto => Some(AUTO_ENCODE_WIDTH),
@@ -56,7 +56,7 @@ fn encode_width_limit(quality: CaptureQuality) -> Option<u32> {
}
#[derive(Debug, Clone)]
pub struct CaptureSetup {
pub(crate) struct CaptureSetup {
pub output_path: PathBuf,
pub ffmpeg_path: PathBuf,
pub width: u32,
@@ -67,7 +67,7 @@ pub struct CaptureSetup {
pub frame_counter: Arc<std::sync::atomic::AtomicU64>,
}
pub struct CaptureHandler {
pub(crate) struct CaptureHandler {
stdin: Option<ChildStdin>,
child: Option<Child>,
width: u32,
@@ -100,7 +100,7 @@ impl TonemapPipeline {
// Vertex shader: fullscreen-triangle pass-through (no vertex buffer).
let mut vs = None;
unsafe {
device.CreateVertexShader(FULLSCREEN_VS, None, Some(&mut vs))?;
device.CreateVertexShader(FULLSCREEN_VS, None, Some(&raw mut vs))?;
}
let vs = vs.ok_or_else(|| anyhow!("CreateVertexShader returned null"))?;
@@ -131,7 +131,7 @@ impl TonemapPipeline {
device.CreateInputLayout(
&input_elements,
FULLSCREEN_VS,
Some(&mut input_layout),
Some(&raw mut input_layout),
)?;
}
let input_layout = input_layout.ok_or_else(|| anyhow!("CreateInputLayout returned null"))?;
@@ -146,7 +146,7 @@ impl TonemapPipeline {
-1.0, 3.0, 0.0, -1.0, // top-left (off-screen)
];
let vb_desc = D3D11_BUFFER_DESC {
ByteWidth: std::mem::size_of_val(&verts) as u32,
ByteWidth: size_of_val(&verts) as u32,
Usage: D3D11_USAGE_IMMUTABLE,
BindFlags: D3D11_BIND_VERTEX_BUFFER.0 as u32,
CPUAccessFlags: 0,
@@ -154,20 +154,20 @@ impl TonemapPipeline {
StructureByteStride: 0,
};
let vb_init = D3D11_SUBRESOURCE_DATA {
pSysMem: verts.as_ptr() as *const std::ffi::c_void,
pSysMem: verts.as_ptr().cast::<std::ffi::c_void>(),
SysMemPitch: 0,
SysMemSlicePitch: 0,
};
let mut vertex_buffer = None;
unsafe {
device.CreateBuffer(&vb_desc, Some(&vb_init), Some(&mut vertex_buffer))?;
device.CreateBuffer(&raw const vb_desc, Some(&raw const vb_init), Some(&raw mut vertex_buffer))?;
}
let vertex_buffer = vertex_buffer.ok_or_else(|| anyhow!("CreateBuffer vb returned null"))?;
// Pixel shader: Hable tonemap + bt709 OETF.
let mut ps = None;
unsafe {
device.CreatePixelShader(TONEMAP_PS, None, Some(&mut ps))?;
device.CreatePixelShader(TONEMAP_PS, None, Some(&raw mut ps))?;
}
let ps = ps.ok_or_else(|| anyhow!("CreatePixelShader returned null"))?;
@@ -186,7 +186,7 @@ impl TonemapPipeline {
};
let mut sampler = None;
unsafe {
device.CreateSamplerState(&sampler_desc, Some(&mut sampler))?;
device.CreateSamplerState(&raw const sampler_desc, Some(&raw mut sampler))?;
}
let sampler = sampler.ok_or_else(|| anyhow!("CreateSamplerState returned null"))?;
@@ -208,7 +208,7 @@ impl TonemapPipeline {
};
let mut rasterizer = None;
unsafe {
device.CreateRasterizerState(&rasterizer_desc, Some(&mut rasterizer))?;
device.CreateRasterizerState(&raw const rasterizer_desc, Some(&raw mut rasterizer))?;
}
let rasterizer =
rasterizer.ok_or_else(|| anyhow!("CreateRasterizerState returned null"))?;
@@ -228,7 +228,7 @@ impl TonemapPipeline {
};
let mut render_target = None;
unsafe {
device.CreateTexture2D(&rt_desc, None, Some(&mut render_target))?;
device.CreateTexture2D(&raw const rt_desc, None, Some(&raw mut render_target))?;
}
let render_target = render_target.ok_or_else(|| anyhow!("CreateTexture2D rt returned null"))?;
@@ -241,7 +241,7 @@ impl TonemapPipeline {
};
let mut rtv = None;
unsafe {
device.CreateRenderTargetView(&render_target, Some(&view_desc), Some(&mut rtv))?;
device.CreateRenderTargetView(&render_target, Some(&raw const view_desc), Some(&raw mut rtv))?;
}
let rtv = rtv.ok_or_else(|| anyhow!("CreateRenderTargetView returned null"))?;
@@ -260,7 +260,7 @@ impl TonemapPipeline {
};
let mut staging = None;
unsafe {
device.CreateTexture2D(&staging_desc, None, Some(&mut staging))?;
device.CreateTexture2D(&raw const staging_desc, None, Some(&raw mut staging))?;
}
let staging = staging.ok_or_else(|| anyhow!("CreateTexture2D staging returned null"))?;
@@ -290,7 +290,7 @@ impl TonemapPipeline {
out: &mut dyn Write,
) -> Result<()> {
let mut desc = D3D11_TEXTURE2D_DESC::default();
unsafe { src.GetDesc(&mut desc) };
unsafe { src.GetDesc(&raw mut desc) };
if desc.Width != self.width || desc.Height != self.height {
// Resize - rebuild the RT/staging at the new dimensions.
tracing::info!(
@@ -313,7 +313,7 @@ impl TonemapPipeline {
},
};
let mut srv: Option<ID3D11ShaderResourceView> = None;
device.CreateShaderResourceView(src, Some(&srv_desc), Some(&mut srv))?;
device.CreateShaderResourceView(src, Some(&raw const srv_desc), Some(&raw mut srv))?;
let srv = srv.ok_or_else(|| anyhow!("CreateShaderResourceView returned null"))?;
// Canonical bind sequence: IA -> shaders -> resources -> output
@@ -357,7 +357,7 @@ impl TonemapPipeline {
// Copy to staging and read back.
context.CopyResource(&self.staging, &self.render_target);
let mut mapped = D3D11_MAPPED_SUBRESOURCE::default();
context.Map(&self.staging, 0, D3D11_MAP_READ, 0, Some(&mut mapped))?;
context.Map(&self.staging, 0, D3D11_MAP_READ, 0, Some(&raw mut mapped))?;
let row_bytes = self.width * 4;
let src_slice = std::slice::from_raw_parts(
mapped.pData as *const u8,
@@ -397,11 +397,11 @@ impl GraphicsCaptureApiHandler for CaptureHandler {
let y = c.y.max(0);
let w = c.width.min(setup.width.saturating_sub(x.cast_unsigned()));
let h = c.height.min(setup.height.saturating_sub(y.cast_unsigned()));
filter_parts.push(format!("crop={}:{}:{}:{}", w, h, x, y));
filter_parts.push(format!("crop={w}:{h}:{x}:{y}"));
}
if let Some(limit) = setup.encode_width_limit {
if setup.width > limit {
filter_parts.push(format!("scale={}:-2", limit));
filter_parts.push(format!("scale={limit}:-2"));
} else {
filter_parts.push("scale=trunc(iw/2)*2:trunc(ih/2)*2".to_string());
}
@@ -512,7 +512,7 @@ pub struct CaptureSession {
control: CaptureControl<CaptureHandler, anyhow::Error>,
}
pub fn primary_monitor_dims() -> Result<(u32, u32)> {
pub(crate) fn primary_monitor_dims() -> Result<(u32, u32)> {
let monitor = Monitor::primary().map_err(|e| anyhow!("primary monitor: {e:?}"))?;
let w = monitor
.width()
@@ -566,7 +566,7 @@ fn monitor_at_point(x: i32, y: i32) -> Result<Monitor> {
Ok(Monitor::from_raw_hmonitor(hmonitor.0))
}
pub fn start(
pub(crate) fn start(
output_path: PathBuf,
ffmpeg_path: PathBuf,
capture_cursor: bool,
@@ -693,7 +693,7 @@ impl CaptureSession {
/// Idempotent: if `input` has already been consumed (e.g. a previous
/// pause/resume cycle ran this to completion and removed it), and
/// `output` exists, returns Ok without re-running ffmpeg.
pub fn fix_intermediate_fps(
pub(crate) fn fix_intermediate_fps(
ffmpeg: &std::path::Path,
input: &std::path::Path,
output: &std::path::Path,
@@ -740,7 +740,7 @@ pub fn fix_intermediate_fps(
.arg("-y")
.arg("-hide_banner")
.args(["-loglevel", "error"])
.args(["-itsscale", &format!("{:.6}", pts_scale)])
.args(["-itsscale", &format!("{pts_scale:.6}")])
.args(["-i", &input.to_string_lossy()])
.args(["-c", "copy"])
.arg(output)
@@ -761,7 +761,7 @@ pub fn fix_intermediate_fps(
.arg("-hide_banner")
.args(["-loglevel", "error"])
.args(["-i", &input.to_string_lossy()])
.args(["-vf", &format!("setpts=PTS*{:.4}", pts_scale)])
.args(["-vf", &format!("setpts=PTS*{pts_scale:.4}")])
.args(["-c:v", "libx264"])
.args(["-preset", "veryfast"])
.args(["-crf", "18"])