mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
This reverts commit 55c897d993
.
This commit is contained in:
parent
55c897d993
commit
c8b14ee2cb
681
Cargo.lock
generated
681
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -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.23"
|
image = "0.25"
|
||||||
itertools.workspace = true
|
itertools.workspace = true
|
||||||
lazy_static.workspace = true
|
lazy_static.workspace = true
|
||||||
linkme = "0.3"
|
linkme = "0.3"
|
||||||
@ -54,9 +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.14"
|
resvg = "0.40"
|
||||||
tiny-skia = "0.5"
|
|
||||||
usvg = { version = "0.14", features = [] }
|
|
||||||
schemars.workspace = true
|
schemars.workspace = true
|
||||||
seahash = "4.1"
|
seahash = "4.1"
|
||||||
semantic_version.workspace = true
|
semantic_version.workspace = true
|
||||||
|
@ -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::{Bgra, ImageBuffer};
|
use image::RgbaImage;
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Cow,
|
borrow::Cow,
|
||||||
fmt,
|
fmt,
|
||||||
@ -43,12 +43,12 @@ pub(crate) struct RenderImageParams {
|
|||||||
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: ImageBuffer<Bgra<u8>, Vec<u8>>,
|
data: RgbaImage,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ImageData {
|
impl ImageData {
|
||||||
/// Create a new image from the given data.
|
/// 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);
|
static NEXT_ID: AtomicUsize = AtomicUsize::new(0);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
@ -330,7 +330,7 @@ impl Asset for Image {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let data = if let Ok(format) = image::guess_format(&bytes) {
|
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)
|
ImageData::new(data)
|
||||||
} else {
|
} else {
|
||||||
let pixmap =
|
let pixmap =
|
||||||
@ -369,7 +369,7 @@ pub enum ImageCacheError {
|
|||||||
Image(Arc<ImageError>),
|
Image(Arc<ImageError>),
|
||||||
/// An error that occurred while processing an SVG.
|
/// An error that occurred while processing an SVG.
|
||||||
#[error("svg error: {0}")]
|
#[error("svg error: {0}")]
|
||||||
Usvg(Arc<usvg::Error>),
|
Usvg(Arc<resvg::usvg::Error>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<std::io::Error> for ImageCacheError {
|
impl From<std::io::Error> for ImageCacheError {
|
||||||
@ -384,8 +384,8 @@ impl From<ImageError> for ImageCacheError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<usvg::Error> for ImageCacheError {
|
impl From<resvg::usvg::Error> for ImageCacheError {
|
||||||
fn from(error: usvg::Error) -> Self {
|
fn from(error: resvg::usvg::Error) -> Self {
|
||||||
Self::Usvg(Arc::new(error))
|
Self::Usvg(Arc::new(error))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ impl MetalAtlasState {
|
|||||||
usage = metal::MTLTextureUsage::ShaderRead;
|
usage = metal::MTLTextureUsage::ShaderRead;
|
||||||
}
|
}
|
||||||
AtlasTextureKind::Polychrome => {
|
AtlasTextureKind::Polychrome => {
|
||||||
pixel_format = metal::MTLPixelFormat::BGRA8Unorm;
|
pixel_format = metal::MTLPixelFormat::RGBA8Unorm;
|
||||||
usage = metal::MTLTextureUsage::ShaderRead;
|
usage = metal::MTLTextureUsage::ShaderRead;
|
||||||
}
|
}
|
||||||
AtlasTextureKind::Path => {
|
AtlasTextureKind::Path => {
|
||||||
|
@ -72,7 +72,7 @@ impl MetalRenderer {
|
|||||||
|
|
||||||
let layer = metal::MetalLayer::new();
|
let layer = metal::MetalLayer::new();
|
||||||
layer.set_device(&device);
|
layer.set_device(&device);
|
||||||
layer.set_pixel_format(MTLPixelFormat::BGRA8Unorm);
|
layer.set_pixel_format(MTLPixelFormat::RGBA8Unorm);
|
||||||
layer.set_opaque(false);
|
layer.set_opaque(false);
|
||||||
layer.set_maximum_drawable_count(3);
|
layer.set_maximum_drawable_count(3);
|
||||||
unsafe {
|
unsafe {
|
||||||
@ -128,7 +128,7 @@ impl MetalRenderer {
|
|||||||
"path_sprites",
|
"path_sprites",
|
||||||
"path_sprite_vertex",
|
"path_sprite_vertex",
|
||||||
"path_sprite_fragment",
|
"path_sprite_fragment",
|
||||||
MTLPixelFormat::BGRA8Unorm,
|
MTLPixelFormat::RGBA8Unorm,
|
||||||
);
|
);
|
||||||
let shadows_pipeline_state = build_pipeline_state(
|
let shadows_pipeline_state = build_pipeline_state(
|
||||||
&device,
|
&device,
|
||||||
@ -136,7 +136,7 @@ impl MetalRenderer {
|
|||||||
"shadows",
|
"shadows",
|
||||||
"shadow_vertex",
|
"shadow_vertex",
|
||||||
"shadow_fragment",
|
"shadow_fragment",
|
||||||
MTLPixelFormat::BGRA8Unorm,
|
MTLPixelFormat::RGBA8Unorm,
|
||||||
);
|
);
|
||||||
let quads_pipeline_state = build_pipeline_state(
|
let quads_pipeline_state = build_pipeline_state(
|
||||||
&device,
|
&device,
|
||||||
@ -144,7 +144,7 @@ impl MetalRenderer {
|
|||||||
"quads",
|
"quads",
|
||||||
"quad_vertex",
|
"quad_vertex",
|
||||||
"quad_fragment",
|
"quad_fragment",
|
||||||
MTLPixelFormat::BGRA8Unorm,
|
MTLPixelFormat::RGBA8Unorm,
|
||||||
);
|
);
|
||||||
let underlines_pipeline_state = build_pipeline_state(
|
let underlines_pipeline_state = build_pipeline_state(
|
||||||
&device,
|
&device,
|
||||||
@ -152,7 +152,7 @@ impl MetalRenderer {
|
|||||||
"underlines",
|
"underlines",
|
||||||
"underline_vertex",
|
"underline_vertex",
|
||||||
"underline_fragment",
|
"underline_fragment",
|
||||||
MTLPixelFormat::BGRA8Unorm,
|
MTLPixelFormat::RGBA8Unorm,
|
||||||
);
|
);
|
||||||
let monochrome_sprites_pipeline_state = build_pipeline_state(
|
let monochrome_sprites_pipeline_state = build_pipeline_state(
|
||||||
&device,
|
&device,
|
||||||
@ -160,7 +160,7 @@ impl MetalRenderer {
|
|||||||
"monochrome_sprites",
|
"monochrome_sprites",
|
||||||
"monochrome_sprite_vertex",
|
"monochrome_sprite_vertex",
|
||||||
"monochrome_sprite_fragment",
|
"monochrome_sprite_fragment",
|
||||||
MTLPixelFormat::BGRA8Unorm,
|
MTLPixelFormat::RGBA8Unorm,
|
||||||
);
|
);
|
||||||
let polychrome_sprites_pipeline_state = build_pipeline_state(
|
let polychrome_sprites_pipeline_state = build_pipeline_state(
|
||||||
&device,
|
&device,
|
||||||
@ -168,7 +168,7 @@ impl MetalRenderer {
|
|||||||
"polychrome_sprites",
|
"polychrome_sprites",
|
||||||
"polychrome_sprite_vertex",
|
"polychrome_sprite_vertex",
|
||||||
"polychrome_sprite_fragment",
|
"polychrome_sprite_fragment",
|
||||||
MTLPixelFormat::BGRA8Unorm,
|
MTLPixelFormat::RGBA8Unorm,
|
||||||
);
|
);
|
||||||
let surfaces_pipeline_state = build_pipeline_state(
|
let surfaces_pipeline_state = build_pipeline_state(
|
||||||
&device,
|
&device,
|
||||||
@ -176,7 +176,7 @@ impl MetalRenderer {
|
|||||||
"surfaces",
|
"surfaces",
|
||||||
"surface_vertex",
|
"surface_vertex",
|
||||||
"surface_fragment",
|
"surface_fragment",
|
||||||
MTLPixelFormat::BGRA8Unorm,
|
MTLPixelFormat::RGBA8Unorm,
|
||||||
);
|
);
|
||||||
|
|
||||||
let command_queue = device.new_command_queue();
|
let command_queue = device.new_command_queue();
|
||||||
|
@ -425,9 +425,8 @@ impl MacTextSystemState {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if params.is_emoji {
|
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) {
|
for pixel in bytes.chunks_exact_mut(4) {
|
||||||
pixel.swap(0, 2);
|
|
||||||
let a = pixel[3] as f32 / 255.;
|
let a = pixel[3] as f32 / 255.;
|
||||||
pixel[0] = (pixel[0] as f32 / a) as u8;
|
pixel[0] = (pixel[0] as f32 / a) as u8;
|
||||||
pixel[1] = (pixel[1] as f32 / a) as u8;
|
pixel[1] = (pixel[1] as f32 / a) as u8;
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
use crate::{AssetSource, DevicePixels, IsZero, Result, SharedString, Size};
|
use crate::{AssetSource, DevicePixels, IsZero, Result, SharedString, Size};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use std::{hash::Hash, sync::Arc};
|
use resvg::tiny_skia::Pixmap;
|
||||||
use tiny_skia::Pixmap;
|
use std::{
|
||||||
|
hash::Hash,
|
||||||
|
sync::{Arc, OnceLock},
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Hash, Eq)]
|
#[derive(Clone, PartialEq, Hash, Eq)]
|
||||||
pub(crate) struct RenderSvgParams {
|
pub(crate) struct RenderSvgParams {
|
||||||
@ -43,28 +46,40 @@ impl SvgRenderer {
|
|||||||
Ok(alpha_mask)
|
Ok(alpha_mask)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render_pixmap(&self, bytes: &[u8], size: SvgSize) -> Result<Pixmap, usvg::Error> {
|
pub fn render_pixmap(&self, bytes: &[u8], size: SvgSize) -> Result<Pixmap, resvg::usvg::Error> {
|
||||||
let tree = usvg::Tree::from_data(&bytes, &usvg::Options::default())?;
|
let tree =
|
||||||
|
resvg::usvg::Tree::from_data(&bytes, &resvg::usvg::Options::default(), svg_fontdb())?;
|
||||||
let tree_size = tree.svg_node().size;
|
|
||||||
|
|
||||||
let size = match size {
|
let size = match size {
|
||||||
SvgSize::Size(size) => size,
|
SvgSize::Size(size) => size,
|
||||||
SvgSize::ScaleFactor(scale) => crate::size(
|
SvgSize::ScaleFactor(scale) => crate::size(
|
||||||
DevicePixels((tree_size.width() * scale as f64) as i32),
|
DevicePixels((tree.size().width() * scale) as i32),
|
||||||
DevicePixels((tree_size.height() * scale as f64) as i32),
|
DevicePixels((tree.size().height() * scale) as i32),
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
// 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 = 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(
|
resvg::render(
|
||||||
&tree,
|
&tree,
|
||||||
usvg::FitTo::Width(size.width.into()),
|
resvg::tiny_skia::Transform::from_scale(ratio, ratio),
|
||||||
pixmap.as_mut(),
|
&mut pixmap.as_mut(),
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(pixmap)
|
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
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@ -36,7 +36,7 @@ pub mod core_video {
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
pub use crate::bindings::{
|
pub use crate::bindings::{
|
||||||
kCVPixelFormatType_32BGRA, kCVPixelFormatType_420YpCbCr8BiPlanarFullRange,
|
kCVPixelFormatType_420YpCbCr8BiPlanarFullRange,
|
||||||
kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange, kCVPixelFormatType_420YpCbCr8Planar,
|
kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange, kCVPixelFormatType_420YpCbCr8Planar,
|
||||||
};
|
};
|
||||||
use crate::bindings::{kCVReturnSuccess, CVReturn, OSType};
|
use crate::bindings::{kCVReturnSuccess, CVReturn, OSType};
|
||||||
|
Loading…
Reference in New Issue
Block a user