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, Eq, Default)]
21
pub enum ScreenCaptureSource {
22
    /// The primary display (the default).
23
    #[default]
24
    PrimaryDisplay,
25
    /// A specific display by index (0-based).
26
    Display(u32),
27
    /// A specific window by its platform id / handle.
28
    Window(u64),
29
}
30

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

            
46
impl Default for ScreenCaptureConfig {
47
150
    fn default() -> Self {
48
150
        Self {
49
150
            source: ScreenCaptureSource::PrimaryDisplay,
50
150
            fps: 0,
51
150
            output_format: RawImageFormat::BGRA8,
52
150
        }
53
150
    }
54
}
55

            
56
impl ScreenCaptureConfig {
57
    /// A default config for the given `source` (backend-chosen fps, `BGRA8`).
58
    #[must_use]
59
139
    pub fn new(source: ScreenCaptureSource) -> Self {
60
139
        Self {
61
139
            source,
62
139
            ..Self::default()
63
139
        }
64
139
    }
65
}
66

            
67
#[cfg(test)]
68
#[path = "screencap_test.rs"]
69
mod screencap_test;