Update tiny-skia and resvg
This commit is contained in:
parent
e63cc181bd
commit
9c63eb7df5
11 changed files with 37 additions and 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" }
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ version = "0.9"
|
|||
path = "../core"
|
||||
|
||||
[dependencies.tiny-skia]
|
||||
version = "0.8"
|
||||
version = "0.9"
|
||||
optional = true
|
||||
|
||||
[dependencies.image]
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
clip_mask.fill_path(
|
||||
&path,
|
||||
tiny_skia::FillRule::EvenOdd,
|
||||
false,
|
||||
)
|
||||
.expect("Set path of clipping area");
|
||||
tiny_skia::Transform::default(),
|
||||
);
|
||||
}
|
||||
|
||||
fn group_damage(
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ version = "1.0"
|
|||
optional = true
|
||||
|
||||
[dependencies.resvg]
|
||||
version = "0.29"
|
||||
version = "0.32"
|
||||
optional = true
|
||||
|
||||
[dependencies.tracing]
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue