Update tiny-skia and resvg

This commit is contained in:
Héctor Ramón Jiménez 2023-04-26 16:46:27 +02:00
parent e63cc181bd
commit 9c63eb7df5
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
11 changed files with 37 additions and 42 deletions

View file

@ -86,6 +86,3 @@ incremental = false
opt-level = 3 opt-level = 3
overflow-checks = false overflow-checks = false
strip = "debuginfo" strip = "debuginfo"
[patch.crates-io]
tiny-skia = { version = "0.8", git = "https://github.com/hecrj/tiny-skia.git", rev = "213890dcbb3754d51533f5b558d9f5ffa3bf6da1" }

View file

@ -31,7 +31,7 @@ version = "0.9"
path = "../core" path = "../core"
[dependencies.tiny-skia] [dependencies.tiny-skia]
version = "0.8" version = "0.9"
optional = true optional = true
[dependencies.image] [dependencies.image]

View file

@ -123,11 +123,10 @@ impl<Theme> crate::graphics::Compositor for Compositor<Theme> {
), ),
#[cfg(feature = "tiny-skia")] #[cfg(feature = "tiny-skia")]
( (
Self::TinySkia(compositor), Self::TinySkia(_compositor),
crate::Backend::TinySkia(backend), crate::Backend::TinySkia(backend),
Surface::TinySkia(surface), Surface::TinySkia(surface),
) => iced_tiny_skia::window::compositor::present( ) => iced_tiny_skia::window::compositor::present(
compositor,
backend, backend,
surface, surface,
primitives, primitives,

View file

@ -11,7 +11,7 @@ geometry = ["iced_graphics/geometry"]
[dependencies] [dependencies]
raw-window-handle = "0.5" raw-window-handle = "0.5"
softbuffer = "0.2" softbuffer = "0.2"
tiny-skia = "0.8" tiny-skia = "0.9"
cosmic-text = "0.8" cosmic-text = "0.8"
bytemuck = "1" bytemuck = "1"
rustc-hash = "1.1" rustc-hash = "1.1"
@ -32,5 +32,5 @@ version = "1.6.1"
features = ["std"] features = ["std"]
[dependencies.resvg] [dependencies.resvg]
version = "0.29" version = "0.32"
optional = true optional = true

View file

@ -44,7 +44,7 @@ impl Backend {
pub fn draw<T: AsRef<str>>( pub fn draw<T: AsRef<str>>(
&mut self, &mut self,
pixels: &mut tiny_skia::PixmapMut<'_>, pixels: &mut tiny_skia::PixmapMut<'_>,
clip_mask: &mut tiny_skia::ClipMask, clip_mask: &mut tiny_skia::Mask,
primitives: &[Primitive], primitives: &[Primitive],
viewport: &Viewport, viewport: &Viewport,
background_color: Color, background_color: Color,
@ -124,7 +124,7 @@ impl Backend {
None, None,
); );
adjust_clip_mask(clip_mask, pixels, region); adjust_clip_mask(clip_mask, region);
for primitive in primitives { for primitive in primitives {
self.draw_primitive( self.draw_primitive(
@ -172,7 +172,7 @@ impl Backend {
&mut self, &mut self,
primitive: &Primitive, primitive: &Primitive,
pixels: &mut tiny_skia::PixmapMut<'_>, pixels: &mut tiny_skia::PixmapMut<'_>,
clip_mask: &mut tiny_skia::ClipMask, clip_mask: &mut tiny_skia::Mask,
clip_bounds: Rectangle, clip_bounds: Rectangle,
scale_factor: f32, scale_factor: f32,
translation: Vector, translation: Vector,
@ -427,7 +427,7 @@ impl Backend {
return; return;
} }
adjust_clip_mask(clip_mask, pixels, bounds); adjust_clip_mask(clip_mask, bounds);
self.draw_primitive( self.draw_primitive(
content, content,
@ -438,7 +438,7 @@ impl Backend {
translation, translation,
); );
adjust_clip_mask(clip_mask, pixels, clip_bounds); adjust_clip_mask(clip_mask, clip_bounds);
} }
} }
Primitive::Cache { content } => { Primitive::Cache { content } => {
@ -611,11 +611,9 @@ fn arc_to(
} }
} }
fn adjust_clip_mask( fn adjust_clip_mask(clip_mask: &mut tiny_skia::Mask, bounds: Rectangle) {
clip_mask: &mut tiny_skia::ClipMask, clip_mask.clear();
pixels: &tiny_skia::PixmapMut<'_>,
bounds: Rectangle,
) {
let path = { let path = {
let mut builder = tiny_skia::PathBuilder::new(); let mut builder = tiny_skia::PathBuilder::new();
builder.push_rect(bounds.x, bounds.y, bounds.width, bounds.height); builder.push_rect(bounds.x, bounds.y, bounds.width, bounds.height);
@ -623,15 +621,12 @@ fn adjust_clip_mask(
builder.finish().unwrap() builder.finish().unwrap()
}; };
clip_mask clip_mask.fill_path(
.set_path( &path,
pixels.width(), tiny_skia::FillRule::EvenOdd,
pixels.height(), false,
&path, tiny_skia::Transform::default(),
tiny_skia::FillRule::EvenOdd, );
false,
)
.expect("Set path of clipping area");
} }
fn group_damage( fn group_damage(

View file

@ -31,7 +31,7 @@ impl Pipeline {
bounds: Rectangle, bounds: Rectangle,
pixels: &mut tiny_skia::PixmapMut<'_>, pixels: &mut tiny_skia::PixmapMut<'_>,
transform: tiny_skia::Transform, transform: tiny_skia::Transform,
clip_mask: Option<&tiny_skia::ClipMask>, clip_mask: Option<&tiny_skia::Mask>,
) { ) {
if let Some(image) = self.cache.borrow_mut().allocate(handle) { if let Some(image) = self.cache.borrow_mut().allocate(handle) {
let width_scale = bounds.width / image.width() as f32; let width_scale = bounds.width / image.width() as f32;

View file

@ -50,7 +50,7 @@ impl Pipeline {
horizontal_alignment: alignment::Horizontal, horizontal_alignment: alignment::Horizontal,
vertical_alignment: alignment::Vertical, vertical_alignment: alignment::Vertical,
pixels: &mut tiny_skia::PixmapMut<'_>, pixels: &mut tiny_skia::PixmapMut<'_>,
clip_mask: Option<&tiny_skia::ClipMask>, clip_mask: Option<&tiny_skia::Mask>,
) { ) {
let font_system = self.font_system.get_mut(); let font_system = self.font_system.get_mut();
let key = Key { let key = Key {

View file

@ -32,7 +32,7 @@ impl Pipeline {
color: Option<Color>, color: Option<Color>,
bounds: Rectangle, bounds: Rectangle,
pixels: &mut tiny_skia::PixmapMut<'_>, pixels: &mut tiny_skia::PixmapMut<'_>,
clip_mask: Option<&tiny_skia::ClipMask>, clip_mask: Option<&tiny_skia::Mask>,
) { ) {
if let Some(image) = self.cache.borrow_mut().draw( if let Some(image) = self.cache.borrow_mut().draw(
handle, handle,
@ -72,6 +72,8 @@ struct RasterKey {
impl Cache { impl Cache {
fn load(&mut self, handle: &Handle) -> Option<&usvg::Tree> { fn load(&mut self, handle: &Handle) -> Option<&usvg::Tree> {
use usvg::TreeParsing;
let id = handle.id(); let id = handle.id();
if let hash_map::Entry::Vacant(entry) = self.trees.entry(id) { if let hash_map::Entry::Vacant(entry) = self.trees.entry(id) {
@ -131,9 +133,9 @@ impl Cache {
resvg::render( resvg::render(
tree, tree,
if size.width > size.height { if size.width > size.height {
usvg::FitTo::Width(size.width) resvg::FitTo::Width(size.width)
} else { } else {
usvg::FitTo::Height(size.height) resvg::FitTo::Height(size.height)
}, },
tiny_skia::Transform::default(), tiny_skia::Transform::default(),
image.as_mut(), image.as_mut(),

View file

@ -7,13 +7,13 @@ use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle};
use std::marker::PhantomData; use std::marker::PhantomData;
pub struct Compositor<Theme> { pub struct Compositor<Theme> {
clip_mask: tiny_skia::ClipMask,
_theme: PhantomData<Theme>, _theme: PhantomData<Theme>,
} }
pub struct Surface { pub struct Surface {
window: softbuffer::GraphicsContext, window: softbuffer::GraphicsContext,
buffer: Vec<u32>, buffer: Vec<u32>,
clip_mask: tiny_skia::Mask,
} }
impl<Theme> crate::graphics::Compositor for Compositor<Theme> { impl<Theme> crate::graphics::Compositor for Compositor<Theme> {
@ -43,6 +43,8 @@ impl<Theme> crate::graphics::Compositor for Compositor<Theme> {
Surface { Surface {
window, window,
buffer: vec![0; width as usize * height as usize], buffer: vec![0; width as usize * height as usize],
clip_mask: tiny_skia::Mask::new(width, height)
.expect("Create clip mask"),
} }
} }
@ -53,6 +55,8 @@ impl<Theme> crate::graphics::Compositor for Compositor<Theme> {
height: u32, height: u32,
) { ) {
surface.buffer.resize((width * height) as usize, 0); surface.buffer.resize((width * height) as usize, 0);
surface.clip_mask =
tiny_skia::Mask::new(width, height).expect("Create clip mask");
} }
fn fetch_information(&self) -> Information { fn fetch_information(&self) -> Information {
@ -72,7 +76,6 @@ impl<Theme> crate::graphics::Compositor for Compositor<Theme> {
) -> Result<(), SurfaceError> { ) -> Result<(), SurfaceError> {
renderer.with_primitives(|backend, primitives| { renderer.with_primitives(|backend, primitives| {
present( present(
self,
backend, backend,
surface, surface,
primitives, primitives,
@ -85,18 +88,15 @@ impl<Theme> crate::graphics::Compositor for Compositor<Theme> {
} }
pub fn new<Theme>(settings: Settings) -> (Compositor<Theme>, Backend) { pub fn new<Theme>(settings: Settings) -> (Compositor<Theme>, Backend) {
// TOD
( (
Compositor { Compositor {
clip_mask: tiny_skia::ClipMask::new(),
_theme: PhantomData, _theme: PhantomData,
}, },
Backend::new(settings), Backend::new(settings),
) )
} }
pub fn present<Theme, T: AsRef<str>>( pub fn present<T: AsRef<str>>(
compositor: &mut Compositor<Theme>,
backend: &mut Backend, backend: &mut Backend,
surface: &mut Surface, surface: &mut Surface,
primitives: &[Primitive], primitives: &[Primitive],
@ -113,7 +113,7 @@ pub fn present<Theme, T: AsRef<str>>(
physical_size.height, physical_size.height,
) )
.expect("Create pixel map"), .expect("Create pixel map"),
&mut compositor.clip_mask, &mut surface.clip_mask,
primitives, primitives,
viewport, viewport,
background_color, background_color,

View file

@ -58,7 +58,7 @@ version = "1.0"
optional = true optional = true
[dependencies.resvg] [dependencies.resvg]
version = "0.29" version = "0.32"
optional = true optional = true
[dependencies.tracing] [dependencies.tracing]

View file

@ -43,6 +43,8 @@ type ColorFilter = Option<[u8; 4]>;
impl Cache { impl Cache {
/// Load svg /// Load svg
pub fn load(&mut self, handle: &svg::Handle) -> &Svg { pub fn load(&mut self, handle: &svg::Handle) -> &Svg {
use usvg::TreeParsing;
if self.svgs.contains_key(&handle.id()) { if self.svgs.contains_key(&handle.id()) {
return self.svgs.get(&handle.id()).unwrap(); return self.svgs.get(&handle.id()).unwrap();
} }
@ -116,9 +118,9 @@ impl Cache {
resvg::render( resvg::render(
tree, tree,
if width > height { if width > height {
usvg::FitTo::Width(width) resvg::FitTo::Width(width)
} else { } else {
usvg::FitTo::Height(height) resvg::FitTo::Height(height)
}, },
tiny_skia::Transform::default(), tiny_skia::Transform::default(),
img.as_mut(), img.as_mut(),