Skip to main content

gpui_apple/
gpui_apple.rs

1#![cfg(any(target_os = "macos", target_os = "ios"))]
2//! Shared Apple rendering, task dispatch, and system services for GPUI.
3//!
4//! This crate renders GPUI scenes directly with Metal on Apple platforms. It
5//! owns GPU resources, text rendering, Keychain access, and thermal notifications
6//! while leaving application lifecycle, windowing, and input to each platform backend.
7
8pub mod custom_draw;
9mod dispatcher;
10pub mod display_link;
11pub mod keychain;
12pub mod metal;
13mod metal_atlas;
14pub mod metal_renderer;
15pub mod process_info;
16
17#[cfg(feature = "font-kit")]
18mod open_type;
19#[cfg(feature = "font-kit")]
20mod text_system;
21
22use objc2::MainThreadMarker;
23
24pub use dispatcher::{AppleActivity, AppleDispatcher};
25#[cfg(feature = "font-kit")]
26pub use text_system::AppleTextSystem;
27
28#[inline]
29pub fn main_thread_marker() -> Option<MainThreadMarker> {
30    thread_local! {
31        static MAIN_THREAD_MARKER: Option<MainThreadMarker> = MainThreadMarker::new();
32    }
33    MAIN_THREAD_MARKER.with(|marker| *marker)
34}
35
36#[cfg(test)]
37mod tests {
38    use super::main_thread_marker;
39
40    #[test]
41    fn main_thread_marker_rejects_background_threads() {
42        std::thread::spawn(|| {
43            assert_eq!(main_thread_marker(), None);
44            assert_eq!(main_thread_marker(), None);
45        })
46        .join()
47        .expect("background thread panicked");
48    }
49}