chore: Revert "gpui: update dependencies" (#9774)

Reverts zed-industries/zed#9741

/cc @niklaswimmer it looks like that PR change broke our rendering of
avatars (as @bennetbo found out) - they have a blue-ish tint now, which
I suppose might have to do with change between BGRA and RGBA. I'm gonna
revert it for now, let's reopen it though.


![image](https://github.com/zed-industries/zed/assets/24362066/3078d9c6-9638-441b-8b32-d969c46951e0)

Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2024-03-25 15:27:16 +01:00 committed by GitHub
parent 6776688987
commit a7047f67fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 600 additions and 731 deletions

893
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -40,7 +40,7 @@ etagere = "0.2"
futures.workspace = true futures.workspace = true
font-kit = { git = "https://github.com/zed-industries/font-kit", rev = "5a5c4d4" } font-kit = { git = "https://github.com/zed-industries/font-kit", rev = "5a5c4d4" }
gpui_macros.workspace = true gpui_macros.workspace = true
image = "0.25" image = "0.23"
itertools.workspace = true itertools.workspace = true
lazy_static.workspace = true lazy_static.workspace = true
linkme = "0.3" linkme = "0.3"
@ -54,7 +54,7 @@ profiling.workspace = true
rand.workspace = true rand.workspace = true
raw-window-handle = "0.6" raw-window-handle = "0.6"
refineable.workspace = true refineable.workspace = true
resvg = "0.40" resvg = "0.14"
schemars.workspace = true schemars.workspace = true
seahash = "4.1" seahash = "4.1"
serde.workspace = true serde.workspace = true
@ -67,6 +67,8 @@ sum_tree.workspace = true
taffy = { git = "https://github.com/DioxusLabs/taffy", rev = "1876f72bee5e376023eaa518aa7b8a34c769bd1b" } taffy = { git = "https://github.com/DioxusLabs/taffy", rev = "1876f72bee5e376023eaa518aa7b8a34c769bd1b" }
thiserror.workspace = true thiserror.workspace = true
time.workspace = true time.workspace = true
tiny-skia = "0.5"
usvg = { version = "0.14", features = [] }
util.workspace = true util.workspace = true
uuid = { version = "1.1.2", features = ["v4", "v5"] } uuid = { version = "1.1.2", features = ["v4", "v5"] }
waker-fn = "1.1.0" waker-fn = "1.1.0"
@ -76,7 +78,7 @@ backtrace = "0.3"
collections = { workspace = true, features = ["test-support"] } collections = { workspace = true, features = ["test-support"] }
util = { workspace = true, features = ["test-support"] } util = { workspace = true, features = ["test-support"] }
[target.'cfg(target_os = "macos")'.build-dependencies] [build-dependencies]
bindgen = "0.65.1" bindgen = "0.65.1"
cbindgen = "0.26.0" cbindgen = "0.26.0"
@ -99,15 +101,13 @@ blade-graphics.workspace = true
blade-macros.workspace = true blade-macros.workspace = true
blade-rwh.workspace = true blade-rwh.workspace = true
bytemuck = "1" bytemuck = "1"
cosmic-text = "0.11.2" cosmic-text = "0.10.0"
copypasta = "0.10.1" copypasta = "0.10.1"
[target.'cfg(target_os = "linux")'.dependencies] [target.'cfg(target_os = "linux")'.dependencies]
as-raw-xcb-connection = "1" open = "5.0.1"
ashpd = "0.8.0" ashpd = "0.7.0"
calloop = "0.12.4" x11rb = { version = "0.13.0", features = ["allow-unsafe-code", "xkb", "randr"] }
calloop-wayland-source = "0.2.0"
wayland-backend = { version = "0.3.3", features = ["client_system"] }
wayland-client = { version = "0.31.2" } wayland-client = { version = "0.31.2" }
wayland-cursor = "0.31.1" wayland-cursor = "0.31.1"
wayland-protocols = { version = "0.31.2", features = [ wayland-protocols = { version = "0.31.2", features = [
@ -115,10 +115,12 @@ wayland-protocols = { version = "0.31.2", features = [
"staging", "staging",
"unstable", "unstable",
] } ] }
oo7 = "0.3.0" wayland-backend = { version = "0.3.3", features = ["client_system"] }
open = "5.1.2"
x11rb = { version = "0.13.0", features = ["allow-unsafe-code", "xkb", "randr"] }
xkbcommon = { version = "0.7", features = ["wayland", "x11"] } xkbcommon = { version = "0.7", features = ["wayland", "x11"] }
as-raw-xcb-connection = "1"
calloop = "0.12.4"
calloop-wayland-source = "0.2.0"
oo7 = "0.3.0"
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
windows.workspace = true windows.workspace = true

View file

@ -1,36 +1,29 @@
#![cfg_attr(any(not(target_os = "macos"), feature = "macos-blade"), allow(unused))] #![cfg_attr(any(not(target_os = "macos"), feature = "macos-blade"), allow(unused))]
use std::{
env,
path::{Path, PathBuf},
};
use cbindgen::Config;
//TODO: consider generating shader code for WGSL //TODO: consider generating shader code for WGSL
//TODO: deprecate "runtime-shaders" and "macos-blade" //TODO: deprecate "runtime-shaders" and "macos-blade"
fn main() { fn main() {
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
macos::build();
}
#[cfg(target_os = "macos")]
mod macos {
use std::{
env,
path::{Path, PathBuf},
};
use cbindgen::Config;
pub(super) fn build() {
generate_dispatch_bindings(); generate_dispatch_bindings();
#[cfg(not(feature = "macos-blade"))] #[cfg(all(target_os = "macos", not(feature = "macos-blade")))]
{
let header_path = generate_shader_bindings(); let header_path = generate_shader_bindings();
#[cfg(all(target_os = "macos", not(feature = "macos-blade")))]
#[cfg(feature = "runtime_shaders")] #[cfg(feature = "runtime_shaders")]
emit_stitched_shaders(&header_path); emit_stitched_shaders(&header_path);
#[cfg(all(target_os = "macos", not(feature = "macos-blade")))]
#[cfg(not(feature = "runtime_shaders"))] #[cfg(not(feature = "runtime_shaders"))]
compile_metal_shaders(&header_path); compile_metal_shaders(&header_path);
} }
}
fn generate_dispatch_bindings() { fn generate_dispatch_bindings() {
println!("cargo:rustc-link-lib=framework=System"); println!("cargo:rustc-link-lib=framework=System");
println!("cargo:rerun-if-changed=src/platform/mac/dispatch.h"); println!("cargo:rerun-if-changed=src/platform/mac/dispatch.h");
@ -61,9 +54,9 @@ mod macos {
bindings bindings
.write_to_file(out_path.join("dispatch_sys.rs")) .write_to_file(out_path.join("dispatch_sys.rs"))
.expect("couldn't write dispatch bindings"); .expect("couldn't write dispatch bindings");
} }
fn generate_shader_bindings() -> PathBuf { fn generate_shader_bindings() -> PathBuf {
let output_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("scene.h"); let output_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("scene.h");
let crate_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); let crate_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
let mut config = Config::default(); let mut config = Config::default();
@ -121,19 +114,18 @@ mod macos {
.write_to_file(&output_path); .write_to_file(&output_path);
output_path output_path
} }
/// To enable runtime compilation, we need to "stitch" the shaders file with the generated header /// To enable runtime compilation, we need to "stitch" the shaders file with the generated header
/// so that it is self-contained. /// so that it is self-contained.
#[cfg(feature = "runtime_shaders")] #[cfg(feature = "runtime_shaders")]
fn emit_stitched_shaders(header_path: &Path) { fn emit_stitched_shaders(header_path: &Path) {
use std::str::FromStr; use std::str::FromStr;
fn stitch_header(header: &Path, shader_path: &Path) -> std::io::Result<PathBuf> { fn stitch_header(header: &Path, shader_path: &Path) -> std::io::Result<PathBuf> {
let header_contents = std::fs::read_to_string(header)?; let header_contents = std::fs::read_to_string(header)?;
let shader_contents = std::fs::read_to_string(shader_path)?; let shader_contents = std::fs::read_to_string(shader_path)?;
let stitched_contents = format!("{header_contents}\n{shader_contents}"); let stitched_contents = format!("{header_contents}\n{shader_contents}");
let out_path = let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("stitched_shaders.metal");
PathBuf::from(env::var("OUT_DIR").unwrap()).join("stitched_shaders.metal");
std::fs::write(&out_path, stitched_contents)?; std::fs::write(&out_path, stitched_contents)?;
Ok(out_path) Ok(out_path)
} }
@ -141,15 +133,13 @@ mod macos {
let shader_path = PathBuf::from_str(shader_source_path).unwrap(); let shader_path = PathBuf::from_str(shader_source_path).unwrap();
stitch_header(header_path, &shader_path).unwrap(); stitch_header(header_path, &shader_path).unwrap();
println!("cargo:rerun-if-changed={}", &shader_source_path); println!("cargo:rerun-if-changed={}", &shader_source_path);
} }
#[cfg(not(feature = "runtime_shaders"))]
#[cfg(not(feature = "runtime_shaders"))] fn compile_metal_shaders(header_path: &Path) {
fn compile_metal_shaders(header_path: &Path) {
use std::process::{self, Command}; use std::process::{self, Command};
let shader_path = "./src/platform/mac/shaders.metal"; let shader_path = "./src/platform/mac/shaders.metal";
let air_output_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("shaders.air"); let air_output_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("shaders.air");
let metallib_output_path = let metallib_output_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("shaders.metallib");
PathBuf::from(env::var("OUT_DIR").unwrap()).join("shaders.metallib");
println!("cargo:rerun-if-changed={}", shader_path); println!("cargo:rerun-if-changed={}", shader_path);
let output = Command::new("xcrun") let output = Command::new("xcrun")
@ -193,5 +183,4 @@ mod macos {
); );
process::exit(1); process::exit(1);
} }
}
} }

View file

@ -1,6 +1,6 @@
use crate::{size, DevicePixels, Result, SharedString, Size}; use crate::{size, DevicePixels, Result, SharedString, Size};
use anyhow::anyhow; use anyhow::anyhow;
use image::RgbaImage; use image::{Bgra, ImageBuffer};
use std::{ use std::{
borrow::Cow, borrow::Cow,
fmt, fmt,
@ -38,12 +38,12 @@ pub struct ImageId(usize);
pub struct ImageData { pub struct ImageData {
/// The ID associated with this image /// The ID associated with this image
pub id: ImageId, pub id: ImageId,
data: RgbaImage, data: ImageBuffer<Bgra<u8>, Vec<u8>>,
} }
impl ImageData { impl ImageData {
/// Create a new image from the given data. /// Create a new image from the given data.
pub fn new(data: RgbaImage) -> Self { pub fn new(data: ImageBuffer<Bgra<u8>, Vec<u8>>) -> Self {
static NEXT_ID: AtomicUsize = AtomicUsize::new(0); static NEXT_ID: AtomicUsize = AtomicUsize::new(0);
Self { Self {

View file

@ -91,7 +91,7 @@ impl ImageCache {
async move { async move {
match uri_or_path { match uri_or_path {
UriOrPath::Path(uri) => { UriOrPath::Path(uri) => {
let image = image::open(uri.as_ref())?.into_rgba8(); let image = image::open(uri.as_ref())?.into_bgra8();
Ok(Arc::new(ImageData::new(image))) Ok(Arc::new(ImageData::new(image)))
} }
UriOrPath::Uri(uri) => { UriOrPath::Uri(uri) => {
@ -110,7 +110,7 @@ impl ImageCache {
let format = image::guess_format(&body)?; let format = image::guess_format(&body)?;
let image = let image =
image::load_from_memory_with_format(&body, format)? image::load_from_memory_with_format(&body, format)?
.into_rgba8(); .into_bgra8();
Ok(Arc::new(ImageData::new(image))) Ok(Arc::new(ImageData::new(image)))
} }
} }

View file

@ -286,7 +286,6 @@ impl LinuxTextSystemState {
params.glyph_id.0 as u16, params.glyph_id.0 as u16,
(params.font_size * params.scale_factor).into(), (params.font_size * params.scale_factor).into(),
(0.0, 0.0), (0.0, 0.0),
cosmic_text::CacheKeyFlags::empty(),
) )
.0, .0,
) )
@ -320,7 +319,6 @@ impl LinuxTextSystemState {
params.glyph_id.0 as u16, params.glyph_id.0 as u16,
(params.font_size * params.scale_factor).into(), (params.font_size * params.scale_factor).into(),
(0.0, 0.0), (0.0, 0.0),
cosmic_text::CacheKeyFlags::empty(),
) )
.0, .0,
) )
@ -383,7 +381,6 @@ impl LinuxTextSystemState {
font_size.0, font_size.0,
f32::MAX, // We do our own wrapping f32::MAX, // We do our own wrapping
cosmic_text::Wrap::None, cosmic_text::Wrap::None,
None,
); );
let mut runs = Vec::new(); let mut runs = Vec::new();

View file

@ -213,19 +213,11 @@ impl WindowsTextSystemState {
_features: FontFeatures, _features: FontFeatures,
) -> Result<SmallVec<[FontId; 4]>> { ) -> Result<SmallVec<[FontId; 4]>> {
let mut font_ids = SmallVec::new(); let mut font_ids = SmallVec::new();
let families = self let family = self
.font_system .font_system
.db() .get_font_matches(Attrs::new().family(cosmic_text::Family::Name(name)));
.faces() for font in family.as_ref() {
.filter(|face| face.families.iter().any(|family| *name == family.0)) let font = self.font_system.get_font(*font).unwrap();
.map(|face| (face.id, face.post_script_name.clone()))
.collect::<SmallVec<[_; 4]>>();
for (font_id, postscript_name) in families {
let font = self
.font_system
.get_font(font_id)
.ok_or_else(|| anyhow!("Could not load font"))?;
// TODO: figure out why this is causing fluent icons from loading // TODO: figure out why this is causing fluent icons from loading
// if font.as_swash().charmap().map('m') == 0 { // if font.as_swash().charmap().map('m') == 0 {
// self.font_system.db_mut().remove_face(font.id()); // self.font_system.db_mut().remove_face(font.id());
@ -235,8 +227,6 @@ impl WindowsTextSystemState {
let font_id = FontId(self.fonts.len()); let font_id = FontId(self.fonts.len());
font_ids.push(font_id); font_ids.push(font_id);
self.fonts.push(font); self.fonts.push(font);
self.postscript_names_by_font_id
.insert(font_id, postscript_name);
} }
Ok(font_ids) Ok(font_ids)
} }
@ -284,7 +274,6 @@ impl WindowsTextSystemState {
params.glyph_id.0 as u16, params.glyph_id.0 as u16,
(params.font_size * params.scale_factor).into(), (params.font_size * params.scale_factor).into(),
(0.0, 0.0), (0.0, 0.0),
cosmic_text::CacheKeyFlags::empty(),
) )
.0, .0,
) )
@ -318,7 +307,6 @@ impl WindowsTextSystemState {
params.glyph_id.0 as u16, params.glyph_id.0 as u16,
(params.font_size * params.scale_factor).into(), (params.font_size * params.scale_factor).into(),
(0.0, 0.0), (0.0, 0.0),
cosmic_text::CacheKeyFlags::empty(),
) )
.0, .0,
) )
@ -354,7 +342,6 @@ impl WindowsTextSystemState {
font_size.0, font_size.0,
f32::MAX, // todo(windows) we don't have a width cause this should technically not be wrapped I believe f32::MAX, // todo(windows) we don't have a width cause this should technically not be wrapped I believe
cosmic_text::Wrap::None, cosmic_text::Wrap::None,
None,
); );
let mut runs = Vec::new(); let mut runs = Vec::new();
// todo(windows) what I think can happen is layout returns possibly multiple lines which means we should be probably working with it higher up in the text rendering // todo(windows) what I think can happen is layout returns possibly multiple lines which means we should be probably working with it higher up in the text rendering

View file

@ -1,9 +1,6 @@
use crate::{AssetSource, DevicePixels, IsZero, Result, SharedString, Size}; use crate::{AssetSource, DevicePixels, IsZero, Result, SharedString, Size};
use anyhow::anyhow; use anyhow::anyhow;
use std::{ use std::{hash::Hash, sync::Arc};
hash::Hash,
sync::{Arc, OnceLock},
};
#[derive(Clone, PartialEq, Hash, Eq)] #[derive(Clone, PartialEq, Hash, Eq)]
pub(crate) struct RenderSvgParams { pub(crate) struct RenderSvgParams {
@ -27,19 +24,15 @@ impl SvgRenderer {
// Load the tree. // Load the tree.
let bytes = self.asset_source.load(&params.path)?; let bytes = self.asset_source.load(&params.path)?;
let tree = let tree = usvg::Tree::from_data(&bytes, &usvg::Options::default())?;
resvg::usvg::Tree::from_data(&bytes, &resvg::usvg::Options::default(), svg_fontdb())?;
// Render the SVG to a pixmap with the specified width and height. // Render the SVG to a pixmap with the specified width and height.
let mut pixmap = let mut pixmap =
resvg::tiny_skia::Pixmap::new(params.size.width.into(), params.size.height.into()) tiny_skia::Pixmap::new(params.size.width.into(), params.size.height.into()).unwrap();
.unwrap();
let ratio = params.size.width.0 as f32 / tree.size().width();
resvg::render( resvg::render(
&tree, &tree,
resvg::tiny_skia::Transform::from_scale(ratio, ratio), usvg::FitTo::Width(params.size.width.into()),
&mut pixmap.as_mut(), pixmap.as_mut(),
); );
// Convert the pixmap's pixels into an alpha mask. // Convert the pixmap's pixels into an alpha mask.
@ -51,13 +44,3 @@ impl SvgRenderer {
Ok(alpha_mask) Ok(alpha_mask)
} }
} }
/// Returns the global font database used for SVG rendering.
fn svg_fontdb() -> &'static resvg::usvg::fontdb::Database {
static FONTDB: OnceLock<resvg::usvg::fontdb::Database> = OnceLock::new();
FONTDB.get_or_init(|| {
let mut fontdb = resvg::usvg::fontdb::Database::new();
fontdb.load_system_fonts();
fontdb
})
}