gpui: Update dependencies (second attempt) (#9836)
Updated version of #9741 with fixes for the problems raised in #9774. I only verified that the images no longer look blueish on Linux, because I don't have a Mac. cc @osiewicz Release Notes: - N/A --------- Signed-off-by: Niklas Wimmer <mail@nwimmer.me>
This commit is contained in:
parent
94c51c6ac9
commit
e2d6b0deba
13 changed files with 743 additions and 613 deletions
|
@ -1,6 +1,6 @@
|
|||
use crate::{size, DevicePixels, Result, SharedString, Size};
|
||||
use anyhow::anyhow;
|
||||
use image::{Bgra, ImageBuffer};
|
||||
use image::RgbaImage;
|
||||
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: ImageBuffer<Bgra<u8>, Vec<u8>>,
|
||||
data: RgbaImage,
|
||||
}
|
||||
|
||||
impl ImageData {
|
||||
/// Create a new image from the given data.
|
||||
pub fn new(data: ImageBuffer<Bgra<u8>, Vec<u8>>) -> Self {
|
||||
pub fn new(data: RgbaImage) -> Self {
|
||||
static NEXT_ID: AtomicUsize = AtomicUsize::new(0);
|
||||
|
||||
Self {
|
||||
|
|
|
@ -91,7 +91,7 @@ impl ImageCache {
|
|||
async move {
|
||||
match uri_or_path {
|
||||
UriOrPath::Path(uri) => {
|
||||
let image = image::open(uri.as_ref())?.into_bgra8();
|
||||
let image = image::open(uri.as_ref())?.into_rgba8();
|
||||
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_bgra8();
|
||||
.into_rgba8();
|
||||
Ok(Arc::new(ImageData::new(image)))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -159,7 +159,7 @@ impl BladeAtlasState {
|
|||
usage = gpu::TextureUsage::COPY | gpu::TextureUsage::RESOURCE;
|
||||
}
|
||||
AtlasTextureKind::Polychrome => {
|
||||
format = gpu::TextureFormat::Bgra8Unorm;
|
||||
format = gpu::TextureFormat::Rgba8Unorm;
|
||||
usage = gpu::TextureUsage::COPY | gpu::TextureUsage::RESOURCE;
|
||||
}
|
||||
AtlasTextureKind::Path => {
|
||||
|
|
|
@ -286,6 +286,7 @@ impl LinuxTextSystemState {
|
|||
params.glyph_id.0 as u16,
|
||||
(params.font_size * params.scale_factor).into(),
|
||||
(0.0, 0.0),
|
||||
cosmic_text::CacheKeyFlags::empty(),
|
||||
)
|
||||
.0,
|
||||
)
|
||||
|
@ -319,6 +320,7 @@ impl LinuxTextSystemState {
|
|||
params.glyph_id.0 as u16,
|
||||
(params.font_size * params.scale_factor).into(),
|
||||
(0.0, 0.0),
|
||||
cosmic_text::CacheKeyFlags::empty(),
|
||||
)
|
||||
.0,
|
||||
)
|
||||
|
@ -381,6 +383,7 @@ impl LinuxTextSystemState {
|
|||
font_size.0,
|
||||
f32::MAX, // We do our own wrapping
|
||||
cosmic_text::Wrap::None,
|
||||
None,
|
||||
);
|
||||
let mut runs = Vec::new();
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ impl MetalAtlasState {
|
|||
usage = metal::MTLTextureUsage::ShaderRead;
|
||||
}
|
||||
AtlasTextureKind::Polychrome => {
|
||||
pixel_format = metal::MTLPixelFormat::BGRA8Unorm;
|
||||
pixel_format = metal::MTLPixelFormat::RGBA8Unorm;
|
||||
usage = metal::MTLTextureUsage::ShaderRead;
|
||||
}
|
||||
AtlasTextureKind::Path => {
|
||||
|
|
|
@ -72,7 +72,7 @@ impl MetalRenderer {
|
|||
|
||||
let layer = metal::MetalLayer::new();
|
||||
layer.set_device(&device);
|
||||
layer.set_pixel_format(MTLPixelFormat::BGRA8Unorm);
|
||||
layer.set_pixel_format(MTLPixelFormat::RGBA8Unorm);
|
||||
layer.set_opaque(true);
|
||||
layer.set_maximum_drawable_count(3);
|
||||
unsafe {
|
||||
|
@ -128,7 +128,7 @@ impl MetalRenderer {
|
|||
"path_sprites",
|
||||
"path_sprite_vertex",
|
||||
"path_sprite_fragment",
|
||||
MTLPixelFormat::BGRA8Unorm,
|
||||
MTLPixelFormat::RGBA8Unorm,
|
||||
);
|
||||
let shadows_pipeline_state = build_pipeline_state(
|
||||
&device,
|
||||
|
@ -136,7 +136,7 @@ impl MetalRenderer {
|
|||
"shadows",
|
||||
"shadow_vertex",
|
||||
"shadow_fragment",
|
||||
MTLPixelFormat::BGRA8Unorm,
|
||||
MTLPixelFormat::RGBA8Unorm,
|
||||
);
|
||||
let quads_pipeline_state = build_pipeline_state(
|
||||
&device,
|
||||
|
@ -144,7 +144,7 @@ impl MetalRenderer {
|
|||
"quads",
|
||||
"quad_vertex",
|
||||
"quad_fragment",
|
||||
MTLPixelFormat::BGRA8Unorm,
|
||||
MTLPixelFormat::RGBA8Unorm,
|
||||
);
|
||||
let underlines_pipeline_state = build_pipeline_state(
|
||||
&device,
|
||||
|
@ -152,7 +152,7 @@ impl MetalRenderer {
|
|||
"underlines",
|
||||
"underline_vertex",
|
||||
"underline_fragment",
|
||||
MTLPixelFormat::BGRA8Unorm,
|
||||
MTLPixelFormat::RGBA8Unorm,
|
||||
);
|
||||
let monochrome_sprites_pipeline_state = build_pipeline_state(
|
||||
&device,
|
||||
|
@ -160,7 +160,7 @@ impl MetalRenderer {
|
|||
"monochrome_sprites",
|
||||
"monochrome_sprite_vertex",
|
||||
"monochrome_sprite_fragment",
|
||||
MTLPixelFormat::BGRA8Unorm,
|
||||
MTLPixelFormat::RGBA8Unorm,
|
||||
);
|
||||
let polychrome_sprites_pipeline_state = build_pipeline_state(
|
||||
&device,
|
||||
|
@ -168,7 +168,7 @@ impl MetalRenderer {
|
|||
"polychrome_sprites",
|
||||
"polychrome_sprite_vertex",
|
||||
"polychrome_sprite_fragment",
|
||||
MTLPixelFormat::BGRA8Unorm,
|
||||
MTLPixelFormat::RGBA8Unorm,
|
||||
);
|
||||
let surfaces_pipeline_state = build_pipeline_state(
|
||||
&device,
|
||||
|
@ -176,7 +176,7 @@ impl MetalRenderer {
|
|||
"surfaces",
|
||||
"surface_vertex",
|
||||
"surface_fragment",
|
||||
MTLPixelFormat::BGRA8Unorm,
|
||||
MTLPixelFormat::RGBA8Unorm,
|
||||
);
|
||||
|
||||
let command_queue = device.new_command_queue();
|
||||
|
|
|
@ -425,9 +425,8 @@ impl MacTextSystemState {
|
|||
);
|
||||
|
||||
if params.is_emoji {
|
||||
// Convert from RGBA with premultiplied alpha to BGRA with straight alpha.
|
||||
// Convert from RGBA with premultiplied alpha to RGBA with straight alpha.
|
||||
for pixel in bytes.chunks_exact_mut(4) {
|
||||
pixel.swap(0, 2);
|
||||
let a = pixel[3] as f32 / 255.;
|
||||
pixel[0] = (pixel[0] as f32 / a) as u8;
|
||||
pixel[1] = (pixel[1] as f32 / a) as u8;
|
||||
|
|
|
@ -213,11 +213,19 @@ impl WindowsTextSystemState {
|
|||
_features: FontFeatures,
|
||||
) -> Result<SmallVec<[FontId; 4]>> {
|
||||
let mut font_ids = SmallVec::new();
|
||||
let family = self
|
||||
let families = self
|
||||
.font_system
|
||||
.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();
|
||||
.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"))?;
|
||||
// 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());
|
||||
|
@ -227,6 +235,8 @@ 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)
|
||||
}
|
||||
|
@ -274,6 +284,7 @@ impl WindowsTextSystemState {
|
|||
params.glyph_id.0 as u16,
|
||||
(params.font_size * params.scale_factor).into(),
|
||||
(0.0, 0.0),
|
||||
cosmic_text::CacheKeyFlags::empty(),
|
||||
)
|
||||
.0,
|
||||
)
|
||||
|
@ -307,6 +318,7 @@ impl WindowsTextSystemState {
|
|||
params.glyph_id.0 as u16,
|
||||
(params.font_size * params.scale_factor).into(),
|
||||
(0.0, 0.0),
|
||||
cosmic_text::CacheKeyFlags::empty(),
|
||||
)
|
||||
.0,
|
||||
)
|
||||
|
@ -342,6 +354,7 @@ 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
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
use crate::{AssetSource, DevicePixels, IsZero, Result, SharedString, Size};
|
||||
use anyhow::anyhow;
|
||||
use std::{hash::Hash, sync::Arc};
|
||||
use std::{
|
||||
hash::Hash,
|
||||
sync::{Arc, OnceLock},
|
||||
};
|
||||
|
||||
#[derive(Clone, PartialEq, Hash, Eq)]
|
||||
pub(crate) struct RenderSvgParams {
|
||||
|
@ -24,15 +27,19 @@ impl SvgRenderer {
|
|||
|
||||
// Load the tree.
|
||||
let bytes = self.asset_source.load(¶ms.path)?;
|
||||
let tree = usvg::Tree::from_data(&bytes, &usvg::Options::default())?;
|
||||
let tree =
|
||||
resvg::usvg::Tree::from_data(&bytes, &resvg::usvg::Options::default(), svg_fontdb())?;
|
||||
|
||||
// Render the SVG to a pixmap with the specified width and height.
|
||||
let mut pixmap =
|
||||
tiny_skia::Pixmap::new(params.size.width.into(), params.size.height.into()).unwrap();
|
||||
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();
|
||||
resvg::render(
|
||||
&tree,
|
||||
usvg::FitTo::Width(params.size.width.into()),
|
||||
pixmap.as_mut(),
|
||||
resvg::tiny_skia::Transform::from_scale(ratio, ratio),
|
||||
&mut pixmap.as_mut(),
|
||||
);
|
||||
|
||||
// Convert the pixmap's pixels into an alpha mask.
|
||||
|
@ -44,3 +51,13 @@ 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
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue