Skip to content

Commit

Permalink
chore: handle breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
theashraf committed Dec 9, 2024
1 parent ec16a0a commit 47fe9ab
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 32 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
13 changes: 7 additions & 6 deletions dotlottie-ffi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand All @@ -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"
11 changes: 4 additions & 7 deletions dotlottie-ffi/Cargo.wasm.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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"
17 changes: 9 additions & 8 deletions dotlottie-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion dotlottie-rs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions dotlottie-rs/src/dotlottie_player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -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))),
Expand Down
7 changes: 4 additions & 3 deletions dotlottie-rs/src/lottie_renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -122,7 +122,7 @@ impl<R: Renderer> LottieRenderer for LottieRendererImpl<R> {
height: u32,
copy: bool,
) -> Result<(), LottieRendererError> {
self.renderer.clear(true).map_err(into_lottie::<R>)?;
self.renderer.clear(true, false).map_err(into_lottie::<R>)?;

self.picture_width = 0.0;
self.picture_height = 0.0;
Expand Down Expand Up @@ -224,6 +224,7 @@ impl<R: Renderer> LottieRenderer for LottieRendererImpl<R> {

fn render(&mut self) -> Result<(), LottieRendererError> {
self.renderer.update().map_err(into_lottie::<R>)?;
self.renderer.clear(false, true).map_err(into_lottie::<R>)?;
self.renderer.draw().map_err(into_lottie::<R>)?;
self.renderer.sync().map_err(into_lottie::<R>)?;

Expand Down
2 changes: 1 addition & 1 deletion dotlottie-rs/src/lottie_renderer/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self>) -> Result<(), Self::Error>;

Expand Down
30 changes: 29 additions & 1 deletion dotlottie-rs/src/lottie_renderer/thorvg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion examples/demo-player/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion examples/demo-state-machine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 47fe9ab

Please sign in to comment.