use std::time::Duration;
use windows::{Graphics::DirectX::DirectXPixelFormat, Win32::Graphics::Dxgi::Common::DXGI_FORMAT};
#[derive(smart_default::SmartDefault, Debug, Clone, Copy)]
pub struct WgcSettings {
#[default(PixelFormat::RGBA8)]
pub pixel_format: PixelFormat,
#[default(1)]
pub frame_queue_length: i32,
#[default(None)]
pub capture_cursor: Option<bool>,
#[default(None)]
pub display_border: Option<bool>,
#[default(None)]
pub include_secondary_windows: Option<bool>,
#[default(None)]
pub dirty_region_mode: Option<bool>,
#[default(None)]
pub min_update_interval: Option<Duration>,
#[default(FrameInterpolationMode::Linear)]
pub frame_interpolation_mode: FrameInterpolationMode,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FrameInterpolationMode {
NearestNeighbor,
Linear,
Cubic,
MultiSampleLinear,
HighQualityCubic,
}
impl From<FrameInterpolationMode> for windows::Win32::Graphics::Direct2D::D2D1_INTERPOLATION_MODE {
fn from(value: FrameInterpolationMode) -> Self {
use windows::Win32::Graphics::Direct2D::*;
match value {
FrameInterpolationMode::NearestNeighbor => D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR,
FrameInterpolationMode::Linear => D2D1_INTERPOLATION_MODE_LINEAR,
FrameInterpolationMode::Cubic => D2D1_INTERPOLATION_MODE_CUBIC,
FrameInterpolationMode::MultiSampleLinear => {
D2D1_INTERPOLATION_MODE_MULTI_SAMPLE_LINEAR
}
FrameInterpolationMode::HighQualityCubic => D2D1_INTERPOLATION_MODE_HIGH_QUALITY_CUBIC,
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct PixelFormat {
format: DirectXPixelFormat,
bytes_per_pixel: u32,
}
impl PixelFormat {
pub fn new(format: DirectXPixelFormat, bytes_per_pixel: u32) -> Self {
Self {
format,
bytes_per_pixel,
}
}
pub const RGBA8: Self = Self {
format: DirectXPixelFormat::R8G8B8A8UIntNormalized,
bytes_per_pixel: 4,
};
pub const BGRA8: Self = Self {
format: DirectXPixelFormat::B8G8R8A8UIntNormalized,
bytes_per_pixel: 4,
};
pub fn format(&self) -> DirectXPixelFormat {
self.format
}
pub fn bytes_per_pixel(&self) -> u32 {
self.bytes_per_pixel
}
}
impl From<PixelFormat> for DirectXPixelFormat {
fn from(pixel_format: PixelFormat) -> Self {
pixel_format.format
}
}
impl From<PixelFormat> for DXGI_FORMAT {
fn from(pixel_format: PixelFormat) -> Self {
Self(pixel_format.format.0)
}
}