gpui_platform/
screen_capture.rs1use crate::ForegroundExecutor;
4use anyhow::Result;
5use futures::channel::oneshot;
6use gpui_shared_string::SharedString;
7use gpui_types::{DevicePixels, Size};
8
9#[cfg(all(
10 any(target_os = "windows", target_os = "linux"),
11 feature = "screen-capture"
12))]
13pub type PlatformScreenCaptureFrame = scap::frame::Frame;
15#[cfg(not(feature = "screen-capture"))]
16pub type PlatformScreenCaptureFrame = ();
18#[cfg(all(target_os = "macos", feature = "screen-capture"))]
19pub type PlatformScreenCaptureFrame =
21 objc2_core_foundation::CFRetained<objc2_core_video::CVImageBuffer>;
22
23#[derive(Clone)]
25pub struct SourceMetadata {
26 pub id: u64,
28 pub label: Option<SharedString>,
30 pub is_main: Option<bool>,
32 pub resolution: Size<DevicePixels>,
34}
35
36pub trait ScreenCaptureSource {
38 fn metadata(&self) -> Result<SourceMetadata>;
40
41 fn stream(
44 &self,
45 foreground_executor: &ForegroundExecutor,
46 frame_callback: Box<dyn Fn(ScreenCaptureFrame) + Send>,
47 ) -> oneshot::Receiver<Result<Box<dyn ScreenCaptureStream>>>;
48}
49
50pub trait ScreenCaptureStream {
52 fn metadata(&self) -> Result<SourceMetadata>;
54}
55
56pub struct ScreenCaptureFrame(pub PlatformScreenCaptureFrame);