1
//! POD types for the screen-capture surface
2
//! (SUPER_PLAN_2 ยง4 Priority 6 + research/01).
3
//!
4
//! Symmetric to the camera surface: screen capture is a "dumb widget"
5
//! (`azul_layout::widgets::screencap::ScreenCaptureWidget`) that owns a
6
//! background capture thread + a GL-texture `ImageRef`, identical to the
7
//! camera widget โ€” only the *source* differs (a display / window instead of
8
//! a camera). Defined here in `azul-core` so the config types cross the FFI
9
//! without `azul-layout` (or ScreenCaptureKit / MediaProjection / PipeWire)
10
//! as a dependency.
11
//!
12
//! Reuses the camera surface's generic capture status types
13
//! ([`crate::camera::StreamState`], `CaptureStats`, `CaptureStreamId`,
14
//! `CaptureErrorCode`) โ€” those are capture-agnostic.
15

            
16
use crate::resources::RawImageFormat;
17

            
18
/// What to capture.
19
#[repr(C, u8)]
20
#[derive(Debug, Clone, Copy, PartialEq)]
21
pub enum ScreenCaptureSource {
22
    /// The primary display (the default).
23
    PrimaryDisplay,
24
    /// A specific display by index (0-based).
25
    Display(u32),
26
    /// A specific window by its platform id / handle.
27
    Window(u64),
28
}
29

            
30
impl Default for ScreenCaptureSource {
31
    fn default() -> Self {
32
        ScreenCaptureSource::PrimaryDisplay
33
    }
34
}
35

            
36
/// Requested screen-capture configuration โ€” the input to the screencap
37
/// widget. Zero `fps` means "let the backend pick its default".
38
#[repr(C)]
39
#[derive(Debug, Clone, Copy, PartialEq)]
40
pub struct ScreenCaptureConfig {
41
    /// What to capture (display / window).
42
    pub source: ScreenCaptureSource,
43
    /// Preferred frame rate (0 = backend default).
44
    pub fps: u32,
45
    /// Texture format the backend should deliver. `BGRA8` is the portable
46
    /// default; `Nv12` (a later `RawImageFormat` addition) is the zero-copy
47
    /// path on platforms that produce it natively.
48
    pub output_format: RawImageFormat,
49
}
50

            
51
impl Default for ScreenCaptureConfig {
52
    fn default() -> Self {
53
        Self {
54
            source: ScreenCaptureSource::PrimaryDisplay,
55
            fps: 0,
56
            output_format: RawImageFormat::BGRA8,
57
        }
58
    }
59
}
60

            
61
impl ScreenCaptureConfig {
62
    /// A default config for the given `source` (backend-chosen fps, `BGRA8`).
63
    pub fn new(source: ScreenCaptureSource) -> Self {
64
        Self {
65
            source,
66
            ..Self::default()
67
        }
68
    }
69
}