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

View file

@ -1,6 +1,6 @@
use crate::{size, DevicePixels, Result, SharedString, Size};
use anyhow::anyhow;
use image::RgbaImage;
use image::{Bgra, ImageBuffer};
use std::{
borrow::Cow,
fmt,
@ -38,12 +38,12 @@ pub struct ImageId(usize);
pub struct ImageData {
/// The ID associated with this image
pub id: ImageId,
data: RgbaImage,
data: ImageBuffer<Bgra<u8>, Vec<u8>>,
}
impl ImageData {
/// 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);
Self {

View file

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

View file

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

View file

@ -213,19 +213,11 @@ impl WindowsTextSystemState {
_features: FontFeatures,
) -> Result<SmallVec<[FontId; 4]>> {
let mut font_ids = SmallVec::new();
let families = self
let family = self
.font_system
.db()
.faces()
.filter(|face| face.families.iter().any(|family| *name == family.0))
.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"))?;
.get_font_matches(Attrs::new().family(cosmic_text::Family::Name(name)));
for font in family.as_ref() {
let font = self.font_system.get_font(*font).unwrap();
// TODO: figure out why this is causing fluent icons from loading
// if font.as_swash().charmap().map('m') == 0 {
// self.font_system.db_mut().remove_face(font.id());
@ -235,8 +227,6 @@ impl WindowsTextSystemState {
let font_id = FontId(self.fonts.len());
font_ids.push(font_id);
self.fonts.push(font);
self.postscript_names_by_font_id
.insert(font_id, postscript_name);
}
Ok(font_ids)
}
@ -284,7 +274,6 @@ impl WindowsTextSystemState {
params.glyph_id.0 as u16,
(params.font_size * params.scale_factor).into(),
(0.0, 0.0),
cosmic_text::CacheKeyFlags::empty(),
)
.0,
)
@ -318,7 +307,6 @@ impl WindowsTextSystemState {
params.glyph_id.0 as u16,
(params.font_size * params.scale_factor).into(),
(0.0, 0.0),
cosmic_text::CacheKeyFlags::empty(),
)
.0,
)
@ -354,7 +342,6 @@ impl WindowsTextSystemState {
font_size.0,
f32::MAX, // todo(windows) we don't have a width cause this should technically not be wrapped I believe
cosmic_text::Wrap::None,
None,
);
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

View file

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