Enable Blade on MacOS via "macos-blade" feature (#7669)

Depends on https://github.com/zed-industries/font-kit/pull/2 and
https://github.com/kvark/blade/pull/77

This change enables Blade to be also used on MacOS. It will also make it
easier to use it on Windows.

What works: most of the things. Zed loads as fast and appears equally
responsive to the current renderer.
<img width="306" alt="Screenshot 2024-02-11 at 12 09 15 AM"
src="https://github.com/zed-industries/zed/assets/107301/66d82f45-5ea2-4e2b-86c6-5b3ed333c827">

Things missing:
- [x] video streaming. ~~Requires a bit of plumbing on both Blade and
Zed sides, but all fairly straightforward.~~
  -  verified with a local setup
- [x] resize. ~~Not sure where exactly to hook up the reaction on the
window size change. Once we know where, the fix is one line.~~
- [ ] fine-tune CA Layer
- this isn't a blocker for merging the PR, but it would be a blocker if
we wanted to switch to the new path by default
- [ ] rebase on latest, get the dependency merged (need review/merge of
https://github.com/zed-industries/font-kit/pull/2!)

Update: I implemented resize support as well as "surface" rendering on
the Blade path (which will be useful on Linux/Windows later on). I
haven't tested the latter though - not sure how to get something
streaming. Would appreciate some help! I don't think this should be a
blocker to this PR, anyway.

The only little piece that's missing for the Blade on MacOS path to be
full-featured is fine-tuning the CALayer configuration. Zed does a lot
of careful logic in configuring the layer, such as switching the
"present with transaction" on/off intermittently, which Blade path
doesn't have yet.

Release Notes:
- N/A

---------

Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
Dzmitry Malyshau 2024-02-16 13:39:40 -08:00 committed by GitHub
parent 1c361ac579
commit 9ad1862f2f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 492 additions and 163 deletions

View file

@ -1,6 +1,20 @@
//todo!(linux): remove
#![allow(unused)]
use crate::{
platform::blade::BladeRenderer, size, Bounds, GlobalPixels, Pixels, PlatformDisplay,
PlatformInput, PlatformInputHandler, PlatformWindow, Point, Size, WindowAppearance,
WindowBounds, WindowOptions, X11Display,
};
use blade_graphics as gpu;
use parking_lot::Mutex;
use raw_window_handle as rwh;
use xcb::{
x::{self, StackMode},
Xid as _,
};
use std::{
ffi::c_void,
mem,
@ -10,17 +24,6 @@ use std::{
sync::{self, Arc},
};
use blade_graphics as gpu;
use parking_lot::Mutex;
use raw_window_handle as rwh;
use xcb::{x, Xid as _};
use crate::platform::linux::blade_renderer::BladeRenderer;
use crate::{
Bounds, GlobalPixels, Pixels, PlatformDisplay, PlatformInput, PlatformInputHandler,
PlatformWindow, Point, Size, WindowAppearance, WindowBounds, WindowOptions, X11Display,
};
#[derive(Default)]
struct Callbacks {
request_frame: Option<Box<dyn FnMut()>>,
@ -293,9 +296,13 @@ impl X11WindowState {
let mut inner = self.inner.lock();
let old_bounds = mem::replace(&mut inner.bounds, bounds);
do_move = old_bounds.origin != bounds.origin;
//todo!(linux): use normal GPUI types here, refactor out the double
// viewport check and extra casts ( )
let gpu_size = query_render_extent(&self.xcb_connection, self.x_window);
if inner.renderer.viewport_size() != gpu_size {
inner.renderer.resize(gpu_size);
inner
.renderer
.update_drawable_size(size(gpu_size.width as f64, gpu_size.height as f64));
resize_args = Some((inner.content_size(), inner.scale_factor));
}
}
@ -493,7 +500,7 @@ impl PlatformWindow for X11Window {
fn sprite_atlas(&self) -> sync::Arc<dyn crate::PlatformAtlas> {
let inner = self.0.inner.lock();
inner.renderer.atlas().clone()
inner.renderer.sprite_atlas().clone()
}
fn set_graphics_profiler_enabled(&self, enabled: bool) {