# gpui_apple: Share dispatcher and Metal renderer with iOS \(\#64990\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/40180d9c40e2d20eb63d388bff920818f2910b53)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 40180d9c40e2d20eb63d388bff920818f2910b53

Requested commit: 40180d9c40e2d20eb63d388bff920818f2910b53

Commit: 40180d9c40e2d20eb63d388bff920818f2910b53

Tree: 3a3729a610fc94d33807ac4f3cf8964bf58e0d95

Author: Anthony Eid

Committer: GitHub

## Message

```
gpui_apple: Share dispatcher and Metal renderer with iOS (#64990)

Prepares GPUI's shared Apple code for the upcoming iOS backend. macOS
behavior is unchanged except for the test-only screenshot path noted
below.

## Changes

- **Dispatcher:** moves `MacDispatcher` from `gpui_macos` into
`gpui_apple` as `AppleDispatcher`, and `MacActivity` as `AppleActivity`.
`is_main_thread` uses the typed `NSThread::isMainThread_class()` instead
of a raw `msg_send`. `gpui_macos` drops its now-unused `async-task`,
`libc`, and `mach2` dependencies.
- **Metal renderer:**
- Adds a safe `MetalRenderer::from_layer(&CAMetalLayer)` for layers
owned by a platform view (UIKit creates a view's backing layer itself).
Layer setup is shared with `new` through `configure_layer`.
- Removes `gpui_apple`'s dependencies on `cocoa` and `objc` 0.2. Layer
setters the `metal` crate doesn't bind now use typed `objc2-quartz-core`
methods; drawable sizing uses `CGSize`.
- iOS always uses shared storage, since managed storage doesn't exist
there (including in the simulator on Intel hosts). The atlas parameter
is renamed `supports_shared_storage` to reflect that.
- `render_scene_to_image` (tests and benchmarks only) now uses shared
storage on Apple Silicon, matching the atlas, and synchronizes whenever
the texture is managed. Intel Macs keep managed textures.
- **Surfaces:** `gpui`'s CoreVideo surface API (`gpui::surface`,
`SurfaceSource::Surface`, `Window::paint_surface`) is now available on
iOS as well as macOS, so the shared renderer no longer needs platform
stubs.
- **Build script:** chooses the Metal SDK from `CARGO_CFG_TARGET_OS` and
`CARGO_CFG_TARGET_ENV` (`macosx`, `iphoneos`, or `iphonesimulator`), so
`x86_64-apple-ios` builds use the simulator SDK. Other targets, such as
Mac Catalyst, fail with a clear error.
- **Cargo:** `gpui_apple` builds for macOS and iOS; `dispatch2` and
`objc2-quartz-core` become workspace dependencies.

## Verification

- `clippy` is clean and tests pass for `gpui`, `gpui_apple`,
`gpui_macos`, and `gpui_platform` on macOS; `gpui_macos` builds with
`runtime_shaders`.
- `cargo clippy -p gpui -p gpui_apple` is clean for
`aarch64-apple-ios-sim` and `x86_64-apple-ios`, including the Metal
shader build with the simulator SDK.
- Not verified at runtime on iOS; nothing on iOS uses these APIs until
the iOS backend lands.

Release Notes:

- [GPUI] Improved the shared Apple Metal renderer and dispatcher so they
can be used by an iOS backend, and made CoreVideo surfaces available on
iOS
```

## Parents

- [bb7751c37998081b05172d46a470cb7b75dc3d77](https://git.cafe/gitcafe/zed/commit/bb7751c37998081b05172d46a470cb7b75dc3d77?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/40180d9c40e2d20eb63d388bff920818f2910b53?format=markdown)
