diff --git a/Cargo.lock b/Cargo.lock index 06575e383339a8..ec12c5265002ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7917,6 +7917,28 @@ dependencies = [ "ztracing", ] +[[package]] +name = "gpui_apple" +version = "0.1.0" +dependencies = [ + "anyhow", + "block", + "cbindgen", + "cocoa 0.26.0", + "collections", + "core-foundation 0.10.0", + "core-video", + "derive_more", + "etagere", + "foreign-types 0.5.0", + "gpui", + "image", + "log", + "metal", + "objc", + "parking_lot", +] + [[package]] name = "gpui_linux" version = "0.1.0" @@ -7978,21 +8000,18 @@ dependencies = [ "async-task", "block", "block2 0.6.2", - "cbindgen", "cocoa 0.26.0", "collections", "core-foundation 0.10.0", "core-foundation-sys", "core-graphics 0.24.0", "core-text", - "core-video", "ctor", - "derive_more", "dispatch2", - "etagere", "foreign-types 0.5.0", "futures 0.3.32", "gpui", + "gpui_apple", "gpui_util", "image", "itertools 0.14.0", diff --git a/Cargo.toml b/Cargo.toml index 9af94b2395a260..96717ccea2540e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -91,6 +91,7 @@ members = [ "crates/google_ai", "crates/grammars", "crates/gpui", + "crates/gpui_apple", "crates/gpui_shared_string", "crates/gpui_linux", "crates/gpui_macos", @@ -353,6 +354,7 @@ go_to_line = { path = "crates/go_to_line" } google_ai = { path = "crates/google_ai" } grammars = { path = "crates/grammars" } gpui = { path = "crates/gpui", default-features = false } +gpui_apple = { path = "crates/gpui_apple" } gpui_shared_string = { path = "crates/gpui_shared_string" } gpui_linux = { path = "crates/gpui_linux", default-features = false } gpui_macos = { path = "crates/gpui_macos", default-features = false } diff --git a/crates/gpui_apple/Cargo.toml b/crates/gpui_apple/Cargo.toml new file mode 100644 index 00000000000000..fb5f07a2cdaecb --- /dev/null +++ b/crates/gpui_apple/Cargo.toml @@ -0,0 +1,43 @@ +[package] +name = "gpui_apple" +version = "0.1.0" +edition.workspace = true +publish.workspace = true +license = "Apache-2.0" + +[lints] +workspace = true + +[lib] +path = "src/gpui_apple.rs" + +[features] +default = [] +test-support = ["gpui/test-support"] +runtime_shaders = [] + +[dependencies] +gpui.workspace = true + +[target.'cfg(target_os = "macos")'.dependencies] +anyhow.workspace = true +block.workspace = true +cocoa.workspace = true +collections.workspace = true +core-foundation.workspace = true +core-video.workspace = true +derive_more.workspace = true +etagere.workspace = true +foreign-types.workspace = true +image.workspace = true +log.workspace = true +metal.workspace = true +objc.workspace = true +parking_lot.workspace = true + +[target.'cfg(target_os = "macos")'.build-dependencies] +cbindgen.workspace = true +gpui.workspace = true + +[target.'cfg(target_os = "macos")'.dev-dependencies] +gpui = { workspace = true, features = ["test-support"] } diff --git a/crates/gpui_apple/LICENSE-APACHE b/crates/gpui_apple/LICENSE-APACHE new file mode 120000 index 00000000000000..1cd601d0a3affa --- /dev/null +++ b/crates/gpui_apple/LICENSE-APACHE @@ -0,0 +1 @@ +../../LICENSE-APACHE \ No newline at end of file diff --git a/crates/gpui_macos/build.rs b/crates/gpui_apple/build.rs similarity index 100% rename from crates/gpui_macos/build.rs rename to crates/gpui_apple/build.rs diff --git a/crates/gpui_apple/src/gpui_apple.rs b/crates/gpui_apple/src/gpui_apple.rs new file mode 100644 index 00000000000000..208d297ea1062a --- /dev/null +++ b/crates/gpui_apple/src/gpui_apple.rs @@ -0,0 +1,8 @@ +#![cfg(target_os = "macos")] +//! Shared Apple platform support for GPUI. +//! +//! This crate contains the Metal renderer and GPU resource management shared +//! by GPUI's Apple platform backends. + +mod metal_atlas; +pub mod metal_renderer; diff --git a/crates/gpui_macos/src/metal_atlas.rs b/crates/gpui_apple/src/metal_atlas.rs similarity index 99% rename from crates/gpui_macos/src/metal_atlas.rs rename to crates/gpui_apple/src/metal_atlas.rs index ce5664d778a82f..9cfd445ba805df 100644 --- a/crates/gpui_macos/src/metal_atlas.rs +++ b/crates/gpui_apple/src/metal_atlas.rs @@ -10,7 +10,7 @@ use metal::Device; use parking_lot::Mutex; use std::borrow::Cow; -pub(crate) struct MetalAtlas(Mutex); +pub struct MetalAtlas(Mutex); impl MetalAtlas { pub(crate) fn new(device: Device, is_apple_gpu: bool) -> Self { diff --git a/crates/gpui_macos/src/metal_renderer.rs b/crates/gpui_apple/src/metal_renderer.rs similarity index 99% rename from crates/gpui_macos/src/metal_renderer.rs rename to crates/gpui_apple/src/metal_renderer.rs index 4f6b0fee78a599..0f41297297cc9b 100644 --- a/crates/gpui_macos/src/metal_renderer.rs +++ b/crates/gpui_apple/src/metal_renderer.rs @@ -41,10 +41,10 @@ const PATH_SAMPLE_COUNT: u32 = 4; const INSTANCE_BUFFER_ALIGNMENT: usize = 256; const MAX_INSTANCE_BUFFER_SIZE: usize = 256 * 1024 * 1024; -pub(crate) type Context = Arc>; -pub(crate) type Renderer = MetalRenderer; +pub type Context = Arc>; +pub type Renderer = MetalRenderer; -pub(crate) unsafe fn new_renderer( +pub unsafe fn new_renderer( context: self::Context, _native_window: *mut c_void, _native_view: *mut c_void, @@ -54,7 +54,7 @@ pub(crate) unsafe fn new_renderer( MetalRenderer::new(context, transparent) } -pub(crate) struct InstanceBufferPool { +pub struct InstanceBufferPool { buffer_size: usize, buffers: Vec, } @@ -109,7 +109,7 @@ impl InstanceBufferPool { } } -pub(crate) struct MetalRenderer { +pub struct MetalRenderer { device: metal::Device, layer: Option, is_apple_gpu: bool, diff --git a/crates/gpui_macos/src/shaders.metal b/crates/gpui_apple/src/shaders.metal similarity index 100% rename from crates/gpui_macos/src/shaders.metal rename to crates/gpui_apple/src/shaders.metal diff --git a/crates/gpui_macos/Cargo.toml b/crates/gpui_macos/Cargo.toml index 5e0dbf57805147..ff10902a37c69a 100644 --- a/crates/gpui_macos/Cargo.toml +++ b/crates/gpui_macos/Cargo.toml @@ -13,8 +13,8 @@ path = "src/gpui_macos.rs" [features] default = ["gpui/default"] -test-support = ["gpui/test-support"] -runtime_shaders = [] +test-support = ["gpui/test-support", "gpui_apple/test-support"] +runtime_shaders = ["gpui_apple/runtime_shaders"] font-kit = ["dep:font-kit"] screen-capture = ["gpui/screen-capture"] @@ -34,15 +34,13 @@ core-foundation.workspace = true core-foundation-sys.workspace = true core-graphics.workspace = true core-text.workspace = true -core-video.workspace = true ctor.workspace = true -derive_more.workspace = true dispatch2 = "0.3.1" -etagere.workspace = true # WARNING: If you change this, you must also publish a new version of zed-font-kit to crates.io font-kit = { git = "https://github.com/zed-industries/font-kit", rev = "94b0f28166665e8fd2f53ff6d268a14955c82269", package = "zed-font-kit", version = "0.14.1-zed", optional = true } foreign-types.workspace = true futures.workspace = true +gpui_apple.workspace = true gpui_util.workspace = true image.workspace = true itertools.workspace = true @@ -64,16 +62,9 @@ smallvec.workspace = true strum.workspace = true uuid.workspace = true -[target.'cfg(target_os = "macos")'.build-dependencies] -cbindgen.workspace = true -gpui.workspace = true - -# When this crate is itself being tested (cargo test -p gpui_macos), its own -# cfg(test) flag enables impls of test-only traits like PlatformHeadlessRenderer -# and PlatformWindow::render_to_image. Those traits/methods only exist in gpui -# when gpui's `test-support` feature is on, so we have to turn that feature on -# as a dev-dependency. The `cfg(test)` flag of a dependent crate doesn't -# propagate to its dependencies, but dev-dependencies do, so this is the -# correct way to enable the feature exactly when needed. +# The macOS test-only window implementation depends on test-only APIs from both +# GPUI and the extracted renderer. A dependency does not inherit this crate's +# `cfg(test)`, so dev-dependencies enable those APIs only for test builds. [target.'cfg(target_os = "macos")'.dev-dependencies] gpui = { workspace = true, features = ["test-support"] } +gpui_apple = { workspace = true, features = ["test-support"] } diff --git a/crates/gpui_macos/src/gpui_macos.rs b/crates/gpui_macos/src/gpui_macos.rs index 9a9e4d7ae801a8..1ee187299449c9 100644 --- a/crates/gpui_macos/src/gpui_macos.rs +++ b/crates/gpui_macos/src/gpui_macos.rs @@ -15,10 +15,14 @@ mod system_notifications; #[cfg(feature = "screen-capture")] mod screen_capture; -mod metal_atlas; -pub mod metal_renderer; +use gpui_apple::metal_renderer as renderer; -use metal_renderer as renderer; +pub mod metal_renderer { + pub use gpui_apple::metal_renderer::{PathRasterizationVertex, PathSprite, SurfaceBounds}; + + #[cfg(any(test, feature = "test-support"))] + pub use gpui_apple::metal_renderer::MetalHeadlessRenderer; +} #[cfg(feature = "font-kit")] mod open_type;