diff options
author | 2023-04-26 16:46:27 +0200 | |
---|---|---|
committer | 2023-04-26 16:46:27 +0200 | |
commit | 9c63eb7df559e58b14188b4096e9bd206444bbf3 (patch) | |
tree | 23bc9de2e8a83358c6c08d0b689d8345b9af3f6e | |
parent | e63cc181bddbdc0a5b9b091cfeee5e4343b3d906 (diff) | |
download | iced-9c63eb7df559e58b14188b4096e9bd206444bbf3.tar.gz iced-9c63eb7df559e58b14188b4096e9bd206444bbf3.tar.bz2 iced-9c63eb7df559e58b14188b4096e9bd206444bbf3.zip |
Update `tiny-skia` and `resvg`
-rw-r--r-- | Cargo.toml | 3 | ||||
-rw-r--r-- | graphics/Cargo.toml | 2 | ||||
-rw-r--r-- | renderer/src/compositor.rs | 3 | ||||
-rw-r--r-- | tiny_skia/Cargo.toml | 4 | ||||
-rw-r--r-- | tiny_skia/src/backend.rs | 33 | ||||
-rw-r--r-- | tiny_skia/src/raster.rs | 2 | ||||
-rw-r--r-- | tiny_skia/src/text.rs | 2 | ||||
-rw-r--r-- | tiny_skia/src/vector.rs | 8 | ||||
-rw-r--r-- | tiny_skia/src/window/compositor.rs | 14 | ||||
-rw-r--r-- | wgpu/Cargo.toml | 2 | ||||
-rw-r--r-- | wgpu/src/image/vector.rs | 6 |
11 files changed, 37 insertions, 42 deletions
@@ -86,6 +86,3 @@ incremental = false opt-level = 3 overflow-checks = false strip = "debuginfo" - -[patch.crates-io] -tiny-skia = { version = "0.8", git = "https://github.com/hecrj/tiny-skia.git", rev = "213890dcbb3754d51533f5b558d9f5ffa3bf6da1" } diff --git a/graphics/Cargo.toml b/graphics/Cargo.toml index f1ce6b3a..125ea17d 100644 --- a/graphics/Cargo.toml +++ b/graphics/Cargo.toml @@ -31,7 +31,7 @@ version = "0.9" path = "../core" [dependencies.tiny-skia] -version = "0.8" +version = "0.9" optional = true [dependencies.image] diff --git a/renderer/src/compositor.rs b/renderer/src/compositor.rs index e31c2bed..48ed4b1f 100644 --- a/renderer/src/compositor.rs +++ b/renderer/src/compositor.rs @@ -123,11 +123,10 @@ impl<Theme> crate::graphics::Compositor for Compositor<Theme> { ), #[cfg(feature = "tiny-skia")] ( - Self::TinySkia(compositor), + Self::TinySkia(_compositor), crate::Backend::TinySkia(backend), Surface::TinySkia(surface), ) => iced_tiny_skia::window::compositor::present( - compositor, backend, surface, primitives, diff --git a/tiny_skia/Cargo.toml b/tiny_skia/Cargo.toml index f629dab9..a3bddc93 100644 --- a/tiny_skia/Cargo.toml +++ b/tiny_skia/Cargo.toml @@ -11,7 +11,7 @@ geometry = ["iced_graphics/geometry"] [dependencies] raw-window-handle = "0.5" softbuffer = "0.2" -tiny-skia = "0.8" +tiny-skia = "0.9" cosmic-text = "0.8" bytemuck = "1" rustc-hash = "1.1" @@ -32,5 +32,5 @@ version = "1.6.1" features = ["std"] [dependencies.resvg] -version = "0.29" +version = "0.32" optional = true diff --git a/tiny_skia/src/backend.rs b/tiny_skia/src/backend.rs index 756e46b3..16a7f9b8 100644 --- a/tiny_skia/src/backend.rs +++ b/tiny_skia/src/backend.rs @@ -44,7 +44,7 @@ impl Backend { pub fn draw<T: AsRef<str>>( &mut self, pixels: &mut tiny_skia::PixmapMut<'_>, - clip_mask: &mut tiny_skia::ClipMask, + clip_mask: &mut tiny_skia::Mask, primitives: &[Primitive], viewport: &Viewport, background_color: Color, @@ -124,7 +124,7 @@ impl Backend { None, ); - adjust_clip_mask(clip_mask, pixels, region); + adjust_clip_mask(clip_mask, region); for primitive in primitives { self.draw_primitive( @@ -172,7 +172,7 @@ impl Backend { &mut self, primitive: &Primitive, pixels: &mut tiny_skia::PixmapMut<'_>, - clip_mask: &mut tiny_skia::ClipMask, + clip_mask: &mut tiny_skia::Mask, clip_bounds: Rectangle, scale_factor: f32, translation: Vector, @@ -427,7 +427,7 @@ impl Backend { return; } - adjust_clip_mask(clip_mask, pixels, bounds); + adjust_clip_mask(clip_mask, bounds); self.draw_primitive( content, @@ -438,7 +438,7 @@ impl Backend { translation, ); - adjust_clip_mask(clip_mask, pixels, clip_bounds); + adjust_clip_mask(clip_mask, clip_bounds); } } Primitive::Cache { content } => { @@ -611,11 +611,9 @@ fn arc_to( } } -fn adjust_clip_mask( - clip_mask: &mut tiny_skia::ClipMask, - pixels: &tiny_skia::PixmapMut<'_>, - bounds: Rectangle, -) { +fn adjust_clip_mask(clip_mask: &mut tiny_skia::Mask, bounds: Rectangle) { + clip_mask.clear(); + let path = { let mut builder = tiny_skia::PathBuilder::new(); builder.push_rect(bounds.x, bounds.y, bounds.width, bounds.height); @@ -623,15 +621,12 @@ fn adjust_clip_mask( builder.finish().unwrap() }; - clip_mask - .set_path( - pixels.width(), - pixels.height(), - &path, - tiny_skia::FillRule::EvenOdd, - false, - ) - .expect("Set path of clipping area"); + clip_mask.fill_path( + &path, + tiny_skia::FillRule::EvenOdd, + false, + tiny_skia::Transform::default(), + ); } fn group_damage( diff --git a/tiny_skia/src/raster.rs b/tiny_skia/src/raster.rs index 2fd73f8c..3887ec8d 100644 --- a/tiny_skia/src/raster.rs +++ b/tiny_skia/src/raster.rs @@ -31,7 +31,7 @@ impl Pipeline { bounds: Rectangle, pixels: &mut tiny_skia::PixmapMut<'_>, 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) { let width_scale = bounds.width / image.width() as f32; diff --git a/tiny_skia/src/text.rs b/tiny_skia/src/text.rs index f5994d09..1246bbd5 100644 --- a/tiny_skia/src/text.rs +++ b/tiny_skia/src/text.rs @@ -50,7 +50,7 @@ impl Pipeline { horizontal_alignment: alignment::Horizontal, vertical_alignment: alignment::Vertical, 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 key = Key { diff --git a/tiny_skia/src/vector.rs b/tiny_skia/src/vector.rs index 8509b761..fc411fdd 100644 --- a/tiny_skia/src/vector.rs +++ b/tiny_skia/src/vector.rs @@ -32,7 +32,7 @@ impl Pipeline { color: Option<Color>, bounds: Rectangle, 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( handle, @@ -72,6 +72,8 @@ struct RasterKey { impl Cache { fn load(&mut self, handle: &Handle) -> Option<&usvg::Tree> { + use usvg::TreeParsing; + let id = handle.id(); if let hash_map::Entry::Vacant(entry) = self.trees.entry(id) { @@ -131,9 +133,9 @@ impl Cache { resvg::render( tree, if size.width > size.height { - usvg::FitTo::Width(size.width) + resvg::FitTo::Width(size.width) } else { - usvg::FitTo::Height(size.height) + resvg::FitTo::Height(size.height) }, tiny_skia::Transform::default(), image.as_mut(), diff --git a/tiny_skia/src/window/compositor.rs b/tiny_skia/src/window/compositor.rs index 6e4bb6ef..7523e06f 100644 --- a/tiny_skia/src/window/compositor.rs +++ b/tiny_skia/src/window/compositor.rs @@ -7,13 +7,13 @@ use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle}; use std::marker::PhantomData; pub struct Compositor<Theme> { - clip_mask: tiny_skia::ClipMask, _theme: PhantomData<Theme>, } pub struct Surface { window: softbuffer::GraphicsContext, buffer: Vec<u32>, + clip_mask: tiny_skia::Mask, } impl<Theme> crate::graphics::Compositor for Compositor<Theme> { @@ -43,6 +43,8 @@ impl<Theme> crate::graphics::Compositor for Compositor<Theme> { Surface { window, 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, ) { 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 { @@ -72,7 +76,6 @@ impl<Theme> crate::graphics::Compositor for Compositor<Theme> { ) -> Result<(), SurfaceError> { renderer.with_primitives(|backend, primitives| { present( - self, backend, surface, primitives, @@ -85,18 +88,15 @@ impl<Theme> crate::graphics::Compositor for Compositor<Theme> { } pub fn new<Theme>(settings: Settings) -> (Compositor<Theme>, Backend) { - // TOD ( Compositor { - clip_mask: tiny_skia::ClipMask::new(), _theme: PhantomData, }, Backend::new(settings), ) } -pub fn present<Theme, T: AsRef<str>>( - compositor: &mut Compositor<Theme>, +pub fn present<T: AsRef<str>>( backend: &mut Backend, surface: &mut Surface, primitives: &[Primitive], @@ -113,7 +113,7 @@ pub fn present<Theme, T: AsRef<str>>( physical_size.height, ) .expect("Create pixel map"), - &mut compositor.clip_mask, + &mut surface.clip_mask, primitives, viewport, background_color, diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 14dcd550..ffae6e4a 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -58,7 +58,7 @@ version = "1.0" optional = true [dependencies.resvg] -version = "0.29" +version = "0.32" optional = true [dependencies.tracing] diff --git a/wgpu/src/image/vector.rs b/wgpu/src/image/vector.rs index 3624e46b..58bdf64a 100644 --- a/wgpu/src/image/vector.rs +++ b/wgpu/src/image/vector.rs @@ -43,6 +43,8 @@ type ColorFilter = Option<[u8; 4]>; impl Cache { /// Load svg pub fn load(&mut self, handle: &svg::Handle) -> &Svg { + use usvg::TreeParsing; + if self.svgs.contains_key(&handle.id()) { return self.svgs.get(&handle.id()).unwrap(); } @@ -116,9 +118,9 @@ impl Cache { resvg::render( tree, if width > height { - usvg::FitTo::Width(width) + resvg::FitTo::Width(width) } else { - usvg::FitTo::Height(height) + resvg::FitTo::Height(height) }, tiny_skia::Transform::default(), img.as_mut(), |