Revert dependency updates in #9836 (#10089)

Due to: https://github.com/zed-industries/zed/issues/9985 and an
abundance of caution, I'm reverting the image and svg rendering updates
for now until we can debug the issue. cc: @niklaswimmer

Release Notes:

- N/A
This commit is contained in:
Mikayla Maki 2024-04-02 11:27:48 -07:00 committed by GitHub
parent 6121bfc5a4
commit 55c897d993
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 267 additions and 496 deletions

683
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
font-kit = { git = "https://github.com/zed-industries/font-kit", rev = "5a5c4d4" }
gpui_macros.workspace = true
image = "0.25"
image = "0.23"
itertools.workspace = true
lazy_static.workspace = true
linkme = "0.3"
@ -54,7 +54,9 @@ profiling.workspace = true
rand.workspace = true
raw-window-handle = "0.6"
refineable.workspace = true
resvg = "0.40"
resvg = "0.14"
tiny-skia = "0.5"
usvg = { version = "0.14", features = [] }
schemars.workspace = true
seahash = "4.1"
semantic_version.workspace = true

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,
@ -43,12 +43,12 @@ pub(crate) struct RenderImageParams {
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

@ -330,7 +330,7 @@ impl Asset for Image {
};
let data = if let Ok(format) = image::guess_format(&bytes) {
let data = image::load_from_memory_with_format(&bytes, format)?.into_rgba8();
let data = image::load_from_memory_with_format(&bytes, format)?.into_bgra8();
ImageData::new(data)
} else {
let pixmap =
@ -369,7 +369,7 @@ pub enum ImageCacheError {
Image(Arc<ImageError>),
/// An error that occurred while processing an SVG.
#[error("svg error: {0}")]
Usvg(Arc<resvg::usvg::Error>),
Usvg(Arc<usvg::Error>),
}
impl From<std::io::Error> for ImageCacheError {
@ -384,8 +384,8 @@ impl From<ImageError> for ImageCacheError {
}
}
impl From<resvg::usvg::Error> for ImageCacheError {
fn from(error: resvg::usvg::Error) -> Self {
impl From<usvg::Error> for ImageCacheError {
fn from(error: usvg::Error) -> Self {
Self::Usvg(Arc::new(error))
}
}

View file

@ -115,7 +115,7 @@ impl MetalAtlasState {
usage = metal::MTLTextureUsage::ShaderRead;
}
AtlasTextureKind::Polychrome => {
pixel_format = metal::MTLPixelFormat::RGBA8Unorm;
pixel_format = metal::MTLPixelFormat::BGRA8Unorm;
usage = metal::MTLTextureUsage::ShaderRead;
}
AtlasTextureKind::Path => {

View file

@ -72,7 +72,7 @@ impl MetalRenderer {
let layer = metal::MetalLayer::new();
layer.set_device(&device);
layer.set_pixel_format(MTLPixelFormat::RGBA8Unorm);
layer.set_pixel_format(MTLPixelFormat::BGRA8Unorm);
layer.set_opaque(false);
layer.set_maximum_drawable_count(3);
unsafe {
@ -128,7 +128,7 @@ impl MetalRenderer {
"path_sprites",
"path_sprite_vertex",
"path_sprite_fragment",
MTLPixelFormat::RGBA8Unorm,
MTLPixelFormat::BGRA8Unorm,
);
let shadows_pipeline_state = build_pipeline_state(
&device,
@ -136,7 +136,7 @@ impl MetalRenderer {
"shadows",
"shadow_vertex",
"shadow_fragment",
MTLPixelFormat::RGBA8Unorm,
MTLPixelFormat::BGRA8Unorm,
);
let quads_pipeline_state = build_pipeline_state(
&device,
@ -144,7 +144,7 @@ impl MetalRenderer {
"quads",
"quad_vertex",
"quad_fragment",
MTLPixelFormat::RGBA8Unorm,
MTLPixelFormat::BGRA8Unorm,
);
let underlines_pipeline_state = build_pipeline_state(
&device,
@ -152,7 +152,7 @@ impl MetalRenderer {
"underlines",
"underline_vertex",
"underline_fragment",
MTLPixelFormat::RGBA8Unorm,
MTLPixelFormat::BGRA8Unorm,
);
let monochrome_sprites_pipeline_state = build_pipeline_state(
&device,
@ -160,7 +160,7 @@ impl MetalRenderer {
"monochrome_sprites",
"monochrome_sprite_vertex",
"monochrome_sprite_fragment",
MTLPixelFormat::RGBA8Unorm,
MTLPixelFormat::BGRA8Unorm,
);
let polychrome_sprites_pipeline_state = build_pipeline_state(
&device,
@ -168,7 +168,7 @@ impl MetalRenderer {
"polychrome_sprites",
"polychrome_sprite_vertex",
"polychrome_sprite_fragment",
MTLPixelFormat::RGBA8Unorm,
MTLPixelFormat::BGRA8Unorm,
);
let surfaces_pipeline_state = build_pipeline_state(
&device,
@ -176,7 +176,7 @@ impl MetalRenderer {
"surfaces",
"surface_vertex",
"surface_fragment",
MTLPixelFormat::RGBA8Unorm,
MTLPixelFormat::BGRA8Unorm,
);
let command_queue = device.new_command_queue();

View file

@ -425,8 +425,9 @@ impl MacTextSystemState {
);
if params.is_emoji {
// Convert from RGBA with premultiplied alpha to RGBA with straight alpha.
// Convert from RGBA with premultiplied alpha to BGRA 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;

View file

@ -1,10 +1,7 @@
use crate::{AssetSource, DevicePixels, IsZero, Result, SharedString, Size};
use anyhow::anyhow;
use resvg::tiny_skia::Pixmap;
use std::{
hash::Hash,
sync::{Arc, OnceLock},
};
use std::{hash::Hash, sync::Arc};
use tiny_skia::Pixmap;
#[derive(Clone, PartialEq, Hash, Eq)]
pub(crate) struct RenderSvgParams {
@ -46,40 +43,28 @@ impl SvgRenderer {
Ok(alpha_mask)
}
pub fn render_pixmap(&self, bytes: &[u8], size: SvgSize) -> Result<Pixmap, resvg::usvg::Error> {
let tree =
resvg::usvg::Tree::from_data(&bytes, &resvg::usvg::Options::default(), svg_fontdb())?;
pub fn render_pixmap(&self, bytes: &[u8], size: SvgSize) -> Result<Pixmap, usvg::Error> {
let tree = usvg::Tree::from_data(&bytes, &usvg::Options::default())?;
let tree_size = tree.svg_node().size;
let size = match size {
SvgSize::Size(size) => size,
SvgSize::ScaleFactor(scale) => crate::size(
DevicePixels((tree.size().width() * scale) as i32),
DevicePixels((tree.size().height() * scale) as i32),
DevicePixels((tree_size.width() * scale as f64) as i32),
DevicePixels((tree_size.height() * scale as f64) as i32),
),
};
// Render the SVG to a pixmap with the specified width and height.
let mut pixmap =
resvg::tiny_skia::Pixmap::new(size.width.into(), size.height.into()).unwrap();
let ratio = size.width.0 as f32 / tree.size().width();
let mut pixmap = tiny_skia::Pixmap::new(size.width.into(), size.height.into()).unwrap();
resvg::render(
&tree,
resvg::tiny_skia::Transform::from_scale(ratio, ratio),
&mut pixmap.as_mut(),
usvg::FitTo::Width(size.width.into()),
pixmap.as_mut(),
);
Ok(pixmap)
}
}
/// Returns the global font database used for SVG rendering.
pub(crate) 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
})
}

View file

@ -36,7 +36,7 @@ pub mod core_video {
use super::*;
pub use crate::bindings::{
kCVPixelFormatType_420YpCbCr8BiPlanarFullRange,
kCVPixelFormatType_32BGRA, kCVPixelFormatType_420YpCbCr8BiPlanarFullRange,
kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange, kCVPixelFormatType_420YpCbCr8Planar,
};
use crate::bindings::{kCVReturnSuccess, CVReturn, OSType};