Revert "Revert dependency updates in #9836 (#10089)"

This reverts commit 55c897d993.
This commit is contained in:
Conrad Irwin 2024-04-02 12:59:10 -06:00
parent 55c897d993
commit c8b14ee2cb
9 changed files with 495 additions and 266 deletions

681
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.23"
image = "0.25"
itertools.workspace = true
lazy_static.workspace = true
linkme = "0.3"
@ -54,9 +54,7 @@ profiling.workspace = true
rand.workspace = true
raw-window-handle = "0.6"
refineable.workspace = true
resvg = "0.14"
tiny-skia = "0.5"
usvg = { version = "0.14", features = [] }
resvg = "0.40"
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::{Bgra, ImageBuffer};
use image::RgbaImage;
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: 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 {

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_bgra8();
let data = image::load_from_memory_with_format(&bytes, format)?.into_rgba8();
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<usvg::Error>),
Usvg(Arc<resvg::usvg::Error>),
}
impl From<std::io::Error> for ImageCacheError {
@ -384,8 +384,8 @@ impl From<ImageError> for ImageCacheError {
}
}
impl From<usvg::Error> for ImageCacheError {
fn from(error: usvg::Error) -> Self {
impl From<resvg::usvg::Error> for ImageCacheError {
fn from(error: resvg::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::BGRA8Unorm;
pixel_format = metal::MTLPixelFormat::RGBA8Unorm;
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::BGRA8Unorm);
layer.set_pixel_format(MTLPixelFormat::RGBA8Unorm);
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::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();

View File

@ -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;

View File

@ -1,7 +1,10 @@
use crate::{AssetSource, DevicePixels, IsZero, Result, SharedString, Size};
use anyhow::anyhow;
use std::{hash::Hash, sync::Arc};
use tiny_skia::Pixmap;
use resvg::tiny_skia::Pixmap;
use std::{
hash::Hash,
sync::{Arc, OnceLock},
};
#[derive(Clone, PartialEq, Hash, Eq)]
pub(crate) struct RenderSvgParams {
@ -43,28 +46,40 @@ impl SvgRenderer {
Ok(alpha_mask)
}
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;
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())?;
let size = match size {
SvgSize::Size(size) => size,
SvgSize::ScaleFactor(scale) => crate::size(
DevicePixels((tree_size.width() * scale as f64) as i32),
DevicePixels((tree_size.height() * scale as f64) as i32),
DevicePixels((tree.size().width() * scale) as i32),
DevicePixels((tree.size().height() * scale) as i32),
),
};
// Render the SVG to a pixmap with the specified width and height.
let mut pixmap = tiny_skia::Pixmap::new(size.width.into(), size.height.into()).unwrap();
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();
resvg::render(
&tree,
usvg::FitTo::Width(size.width.into()),
pixmap.as_mut(),
resvg::tiny_skia::Transform::from_scale(ratio, ratio),
&mut 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_32BGRA, kCVPixelFormatType_420YpCbCr8BiPlanarFullRange,
kCVPixelFormatType_420YpCbCr8BiPlanarFullRange,
kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange, kCVPixelFormatType_420YpCbCr8Planar,
};
use crate::bindings::{kCVReturnSuccess, CVReturn, OSType};