diff --git a/Makefile b/Makefile index 2e740eed..112ee41f 100644 --- a/Makefile +++ b/Makefile @@ -330,6 +330,7 @@ define SETUP_MESON --backend=ninja \ -Dloaders="lottie, png, jpg, webp" \ -Ddefault_library=static \ + -Dengines=sw \ -Dbindings=capi \ -Dlog=false \ -Dthreads=false \ diff --git a/dotlottie-ffi/Cargo.toml b/dotlottie-ffi/Cargo.toml index 52ac92e6..2d08b947 100644 --- a/dotlottie-ffi/Cargo.toml +++ b/dotlottie-ffi/Cargo.toml @@ -1,11 +1,12 @@ [package] name = "dotlottie-ffi" -version = "0.1.33" +version = "0.1.31" edition = "2021" build = "build.rs" [profile.release] lto = true +panic = "abort" [lib] crate-type = ["staticlib", "cdylib", "rlib"] @@ -16,12 +17,12 @@ name = "uniffi-bindgen" path = "uniffi-bindgen.rs" [dependencies] -uniffi = { version = "0.28", features = ["cli"] } -dotlottie-rs = { path = "../dotlottie-rs", features = ["thorvg"] } +uniffi = { version = "0.25", features = ["cli"] } +dotlottie-rs = { path = "../dotlottie-rs", features = ["thorvg1"] } cfg-if = "1.0" bitflags = "2.6.0" [build-dependencies] -uniffi = { version = "0.28", features = ["build"] } -lazy_static = "1.4" -cbindgen = "0.26.0" +uniffi = { version = "0.25", features = ["build"] } +lazy_static = "1.5.0" +cbindgen = "0.27.0" diff --git a/dotlottie-ffi/Cargo.wasm.toml b/dotlottie-ffi/Cargo.wasm.toml index fda35f51..2d08b947 100644 --- a/dotlottie-ffi/Cargo.wasm.toml +++ b/dotlottie-ffi/Cargo.wasm.toml @@ -6,10 +6,7 @@ build = "build.rs" [profile.release] lto = true -opt-level = "z" -strip = true -codegen-units = 1 -panic = "abort" +panic = "abort" [lib] crate-type = ["staticlib", "cdylib", "rlib"] @@ -21,11 +18,11 @@ path = "uniffi-bindgen.rs" [dependencies] uniffi = { version = "0.25", features = ["cli"] } -dotlottie-rs = { path = "../dotlottie-rs", features = ["thorvg"] } +dotlottie-rs = { path = "../dotlottie-rs", features = ["thorvg1"] } cfg-if = "1.0" bitflags = "2.6.0" [build-dependencies] uniffi = { version = "0.25", features = ["build"] } -lazy_static = "1.4" -cbindgen = "0.26.0" +lazy_static = "1.5.0" +cbindgen = "0.27.0" diff --git a/dotlottie-rs/Cargo.toml b/dotlottie-rs/Cargo.toml index 49f74691..0a0d0156 100644 --- a/dotlottie-rs/Cargo.toml +++ b/dotlottie-rs/Cargo.toml @@ -8,28 +8,29 @@ links = "thorvg" crate-type = ["staticlib", "cdylib", "rlib"] [features] -thorvg = [] +thorvg0 = [] +thorvg1 = [] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -thiserror = "1.0.48" +thiserror = "2.0.4" instant = { version = "0.1.13", features = ["inaccurate"] } -serde_json = "1.0.107" -serde = { version = "1.0.188", features = ["derive"] } -zip = { version = "2.2.0", default-features = false, features = ["deflate"] } +serde_json = "1.0.133" +serde = { version = "1.0.215", features = ["derive"] } +zip = { version = "2.2.1", default-features = false, features = ["deflate"] } base64 = "0.22.1" json = "0.12.4" jzon = "0.12.5" [build-dependencies] -bindgen = "0.70.1" -lazy_static = "1.4" +bindgen = "0.71.0" +lazy_static = "1.5.0" conan2 = "0.1" [dev-dependencies] criterion = "0.5.1" # This is a workaround to enable this feature only on dev. -dotlottie-rs= { path = ".", features = ["thorvg"] } +dotlottie-rs= { path = ".", features = ["thorvg0"] } [[bench]] name = "benchmarks" diff --git a/dotlottie-rs/build.rs b/dotlottie-rs/build.rs index d8ed24ba..9bc6c721 100644 --- a/dotlottie-rs/build.rs +++ b/dotlottie-rs/build.rs @@ -97,7 +97,7 @@ fn apply_build_settings(build_settings: &BuildSettings) { } fn main() { - if !cfg!(feature = "thorvg") { + if !cfg!(feature = "thorvg1") && !cfg!(feature = "thorvg0") { return; } diff --git a/dotlottie-rs/src/dotlottie_player.rs b/dotlottie-rs/src/dotlottie_player.rs index 83077b38..83972931 100644 --- a/dotlottie-rs/src/dotlottie_player.rs +++ b/dotlottie-rs/src/dotlottie_player.rs @@ -128,7 +128,7 @@ struct DotLottieRuntime { } impl DotLottieRuntime { - #[cfg(feature = "thorvg")] + #[cfg(any(feature = "thorvg1", feature = "thorvg0"))] pub fn new(config: Config) -> Self { Self::with_renderer( config, @@ -888,7 +888,7 @@ pub struct DotLottiePlayerContainer { } impl DotLottiePlayerContainer { - #[cfg(feature = "thorvg")] + #[cfg(any(feature = "thorvg1", feature = "thorvg0"))] pub fn new(config: Config) -> Self { DotLottiePlayerContainer { runtime: RwLock::new(DotLottieRuntime::new(config)), @@ -1276,7 +1276,7 @@ pub struct DotLottiePlayer { } impl DotLottiePlayer { - #[cfg(feature = "thorvg")] + #[cfg(any(feature = "thorvg1", feature = "thorvg0"))] pub fn new(config: Config) -> Self { DotLottiePlayer { player: Rc::new(RwLock::new(DotLottiePlayerContainer::new(config))), diff --git a/dotlottie-rs/src/lottie_renderer/mod.rs b/dotlottie-rs/src/lottie_renderer/mod.rs index 8d3c42bb..a0b5d60d 100644 --- a/dotlottie-rs/src/lottie_renderer/mod.rs +++ b/dotlottie-rs/src/lottie_renderer/mod.rs @@ -5,11 +5,11 @@ use thiserror::Error; use crate::Layout; mod renderer; -#[cfg(feature = "thorvg")] +#[cfg(any(feature = "thorvg1", feature = "thorvg0"))] mod thorvg; pub use renderer::{Animation, ColorSpace, Drawable, Renderer, Shape}; -#[cfg(feature = "thorvg")] +#[cfg(any(feature = "thorvg1", feature = "thorvg0"))] pub use thorvg::{TvgAnimation, TvgEngine, TvgError, TvgRenderer, TvgShape}; #[derive(Error, Debug)] @@ -122,7 +122,7 @@ impl LottieRenderer for LottieRendererImpl { height: u32, copy: bool, ) -> Result<(), LottieRendererError> { - self.renderer.clear(true).map_err(into_lottie::)?; + self.renderer.clear(true, false).map_err(into_lottie::)?; self.picture_width = 0.0; self.picture_height = 0.0; @@ -224,6 +224,7 @@ impl LottieRenderer for LottieRendererImpl { fn render(&mut self) -> Result<(), LottieRendererError> { self.renderer.update().map_err(into_lottie::)?; + self.renderer.clear(false, true).map_err(into_lottie::)?; self.renderer.draw().map_err(into_lottie::)?; self.renderer.sync().map_err(into_lottie::)?; diff --git a/dotlottie-rs/src/lottie_renderer/renderer.rs b/dotlottie-rs/src/lottie_renderer/renderer.rs index 27cf7dc4..3023fde3 100644 --- a/dotlottie-rs/src/lottie_renderer/renderer.rs +++ b/dotlottie-rs/src/lottie_renderer/renderer.rs @@ -74,7 +74,7 @@ pub trait Renderer: Sized + 'static { color_space: ColorSpace, ) -> Result<(), Self::Error>; - fn clear(&self, free: bool) -> Result<(), Self::Error>; + fn clear(&self, paints: bool, buffer: bool) -> Result<(), Self::Error>; fn push(&mut self, drawable: Drawable) -> Result<(), Self::Error>; diff --git a/dotlottie-rs/src/lottie_renderer/thorvg.rs b/dotlottie-rs/src/lottie_renderer/thorvg.rs index d778c1e4..1568c7b5 100644 --- a/dotlottie-rs/src/lottie_renderer/thorvg.rs +++ b/dotlottie-rs/src/lottie_renderer/thorvg.rs @@ -131,9 +131,15 @@ impl Renderer for TvgRenderer { convert_tvg_result(result, "tvg_swcanvas_set_target") } + #[cfg(feature = "thorvg1")] + fn clear(&self, paints: bool, buffer: bool) -> Result<(), TvgError> { + let result = unsafe { tvg::tvg_canvas_clear(self.raw_canvas, paints, buffer) }; + convert_tvg_result(result, "tvg_canvas_clear") + } + + #[cfg(feature = "thorvg0")] fn clear(&self, free: bool) -> Result<(), TvgError> { let result = unsafe { tvg::tvg_canvas_clear(self.raw_canvas, free) }; - convert_tvg_result(result, "tvg_canvas_clear") } @@ -196,6 +202,28 @@ impl Default for TvgAnimation { impl Animation for TvgAnimation { type Error = TvgError; + #[cfg(feature = "thorvg1")] + fn load_data(&mut self, data: &str, mimetype: &str, copy: bool) -> Result<(), TvgError> { + let mimetype = CString::new(mimetype).expect("Failed to create CString"); + let data = CString::new(data).expect("Failed to create CString"); + + let result = unsafe { + tvg::tvg_picture_load_data( + self.raw_paint, + data.as_ptr(), + data.as_bytes().len() as u32, + mimetype.as_ptr(), + ptr::null(), + copy, + ) + }; + + convert_tvg_result(result, "tvg_picture_load_data")?; + + Ok(()) + } + + #[cfg(feature = "thorvg0")] fn load_data(&mut self, data: &str, mimetype: &str, copy: bool) -> Result<(), TvgError> { let mimetype = CString::new(mimetype).expect("Failed to create CString"); let data = CString::new(data).expect("Failed to create CString"); diff --git a/examples/demo-player/Cargo.toml b/examples/demo-player/Cargo.toml index a814a712..7665a0e5 100644 --- a/examples/demo-player/Cargo.toml +++ b/examples/demo-player/Cargo.toml @@ -5,6 +5,6 @@ edition = "2021" [dependencies] minifb = "0.27" -dotlottie-rs = { path = "../../dotlottie-rs", features = ["thorvg"] } +dotlottie-rs = { path = "../../dotlottie-rs", features = ["thorvg0"] } sysinfo = "0.30" rand = "0.8" diff --git a/examples/demo-state-machine/Cargo.toml b/examples/demo-state-machine/Cargo.toml index c4e513bc..9d3898e7 100644 --- a/examples/demo-state-machine/Cargo.toml +++ b/examples/demo-state-machine/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] minifb = "0.27" -dotlottie-rs = { path = "../../dotlottie-rs", features = ["thorvg"] } +dotlottie-rs = { path = "../../dotlottie-rs", features = ["thorvg0"] } sysinfo = "0.30" rand = "0.8"