Vendor i-slint-renderer-skia 1.16.1 with a second-chance typeface workaround: skia bug 310510989 makes new_from_data fail for TTC faces at index > 0 on macOS, and for AppleSDGothicNeo.ttc — which packs every weight at index > 0 — the upstream read/write-fonts rebuild is ALSO rejected by CoreText, so draw_glyph_run silently dropped every Korean glyph run at non-regular weights (Japanese survived because Hiragino ships one file per weight, always index 0). Resolve the same face through CoreText by family name (typographic name preferred, localized names resolve too) + OS/2 weight; the match points at the same installed file so parley's glyph ids stay valid, enforced by cmap spot checks that reject a mismatching face rather than draw wrong glyphs. Probe-verified on the Mac Mini: matched face returns identical glyph ids for U+C0AC across w500/600/700. cc
96 lines
3.1 KiB
Rust
96 lines
3.1 KiB
Rust
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
|
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
|
|
|
|
use foreign_types::ForeignType;
|
|
use i_slint_core::api::PhysicalSize as PhysicalWindowSize;
|
|
|
|
use skia_safe::gpu::mtl;
|
|
|
|
use wgpu_27 as wgpu;
|
|
|
|
pub unsafe fn make_metal_surface(
|
|
size: PhysicalWindowSize,
|
|
gr_context: &mut skia_safe::gpu::DirectContext,
|
|
frame: &wgpu::SurfaceTexture,
|
|
) -> Option<skia_safe::Surface> {
|
|
unsafe {
|
|
let metal_texture = frame.texture.as_hal::<wgpu::wgc::api::Metal>();
|
|
|
|
let texture_info =
|
|
mtl::TextureInfo::new(metal_texture.unwrap().raw_handle().as_ptr() as mtl::Handle);
|
|
|
|
let backend_render_target = skia_safe::gpu::backend_render_targets::make_mtl(
|
|
(size.width as i32, size.height as i32),
|
|
&texture_info,
|
|
);
|
|
|
|
skia_safe::gpu::surfaces::wrap_backend_render_target(
|
|
gr_context,
|
|
&backend_render_target,
|
|
skia_safe::gpu::SurfaceOrigin::TopLeft,
|
|
skia_safe::ColorType::BGRA8888,
|
|
None,
|
|
None,
|
|
)
|
|
}
|
|
}
|
|
|
|
pub unsafe fn import_metal_texture(
|
|
canvas: &skia_safe::Canvas,
|
|
texture: wgpu::Texture,
|
|
) -> Option<skia_safe::Image> {
|
|
unsafe {
|
|
let metal_texture = texture.as_hal::<wgpu::wgc::api::Metal>();
|
|
|
|
let texture_info =
|
|
mtl::TextureInfo::new(metal_texture.unwrap().raw_handle().as_ptr() as mtl::Handle);
|
|
let size = texture.size();
|
|
|
|
let backend_texture = skia_safe::gpu::backend_textures::make_mtl(
|
|
(size.width as _, size.height as _),
|
|
skia_safe::gpu::Mipmapped::No,
|
|
&texture_info,
|
|
"Borrowed Metal texture",
|
|
);
|
|
Some(
|
|
skia_safe::image::Image::from_texture(
|
|
canvas.recording_context().as_mut().unwrap(),
|
|
&backend_texture,
|
|
skia_safe::gpu::SurfaceOrigin::TopLeft,
|
|
match texture.format() {
|
|
wgpu::TextureFormat::Rgba8Unorm => skia_safe::ColorType::RGBA8888,
|
|
wgpu::TextureFormat::Rgba8UnormSrgb => skia_safe::ColorType::SRGBA8888,
|
|
_ => return None,
|
|
},
|
|
skia_safe::AlphaType::Unpremul,
|
|
None,
|
|
)
|
|
.unwrap(),
|
|
)
|
|
}
|
|
}
|
|
|
|
pub fn make_metal_context(
|
|
device: &wgpu::Device,
|
|
queue: &wgpu::Queue,
|
|
) -> Option<skia_safe::gpu::DirectContext> {
|
|
let backend = unsafe {
|
|
let maybe_metal_device = device.as_hal::<wgpu::wgc::api::Metal>();
|
|
let maybe_metal_queue = queue.as_hal::<wgpu::wgc::api::Metal>();
|
|
|
|
maybe_metal_device.and_then(|metal_device| {
|
|
let metal_device_raw = &*metal_device.raw_device().lock();
|
|
|
|
maybe_metal_queue.map(|metal_queue| {
|
|
let metal_queue_raw = &*metal_queue.as_raw().lock();
|
|
mtl::BackendContext::new(
|
|
metal_device_raw.as_ptr() as mtl::Handle,
|
|
metal_queue_raw.as_ptr() as mtl::Handle,
|
|
)
|
|
})
|
|
})?
|
|
};
|
|
|
|
skia_safe::gpu::direct_contexts::make_metal(&backend, None)
|
|
}
|