Skip to content

Commit

Permalink
feat: upgrade thorvg v1.0-pre10
Browse files Browse the repository at this point in the history
  • Loading branch information
theashraf committed Jan 14, 2025
1 parent c5fa543 commit 86d7377
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/check-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- name: Lint
run: |
cargo clippy --manifest-path=./dotlottie-rs/Cargo.toml --all-targets --all-features -- -D clippy::print_stdout
cargo clippy --manifest-path=./dotlottie-ffi/Cargo.toml --all-targets --all-features -- -D clippy::print_stdout
cargo clippy --manifest-path=./dotlottie-rs/Cargo.toml --all-targets -- -D clippy::print_stdout
cargo clippy --manifest-path=./dotlottie-ffi/Cargo.toml --all-targets -- -D clippy::print_stdout
env:
RUSTFLAGS: "-Dwarnings"
12 changes: 9 additions & 3 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 Expand Up @@ -387,13 +388,17 @@ define CARGO_BUILD
-Z build-std-features="panic_immediate_abort,optimize_for_size" \
--manifest-path $(PROJECT_DIR)/Cargo.toml \
--target $(CARGO_TARGET) \
--no-default-features \
--features thorvg-v1 \
--release; \
else \
IPHONEOS_DEPLOYMENT_TARGET=$(APPLE_IOS_VERSION_MIN) \
MACOSX_DEPLOYMENT_TARGET=$(APPLE_MACOS_VERSION_MIN) \
cargo build \
--manifest-path $(PROJECT_DIR)/Cargo.toml \
--target $(CARGO_TARGET) \
--no-default-features \
--features thorvg-v1 \
--release; \
fi
endef
Expand All @@ -402,7 +407,8 @@ define UNIFFI_BINDINGS_BUILD
rm -rf $(RUNTIME_FFI)/$(RUNTIME_FFI_UNIFFI_BINDINGS)/$(BINDINGS_LANGUAGE)
cargo run \
--manifest-path $(RUNTIME_FFI)/Cargo.toml \
--features=uniffi/cli \
--no-default-features \
--features=uniffi/cli,thorvg-v1 \
--bin uniffi-bindgen \
generate $(RUNTIME_FFI)/src/dotlottie_player.udl \
--language $(BINDINGS_LANGUAGE) \
Expand Down Expand Up @@ -1021,8 +1027,8 @@ bench:
.PHONY: clippy
clippy:
$(info $(YELLOW)Running clippy for workspace$(NC))
cargo clippy --manifest-path $(CORE)/Cargo.toml --all-targets --all-features -- -D clippy::print_stdout
cargo clippy --manifest-path $(RUNTIME_FFI)/Cargo.toml --all-targets --all-features -- -D clippy::print_stdout
cargo clippy --manifest-path $(CORE)/Cargo.toml --all-targets -- -D clippy::print_stdout
cargo clippy --manifest-path $(RUNTIME_FFI)/Cargo.toml --all-targets -- -D clippy::print_stdout

.PHONY: help
help:
Expand Down
2 changes: 1 addition & 1 deletion deps/modules/thorvg
Submodule thorvg updated 415 files
7 changes: 6 additions & 1 deletion dotlottie-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ name = "dotlottie_player"
name = "uniffi-bindgen"
path = "uniffi-bindgen.rs"

[features]
default = ["thorvg-v0"]
thorvg-v0 = ["dotlottie-rs/thorvg-v0"]
thorvg-v1 = ["dotlottie-rs/thorvg-v1"]

[dependencies]
uniffi = { version = "0.28", features = ["cli"] }
dotlottie-rs = { path = "../dotlottie-rs", features = ["thorvg"] }
dotlottie-rs = { path = "../dotlottie-rs", default-features = false }
cfg-if = "1.0"
bitflags = "2.6.0"

Expand Down
9 changes: 7 additions & 2 deletions dotlottie-ffi/Cargo.wasm.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dotlottie-ffi"
version = "0.1.31"
version = "0.1.36"
edition = "2021"
build = "build.rs"

Expand All @@ -19,9 +19,14 @@ name = "dotlottie_player"
name = "uniffi-bindgen"
path = "uniffi-bindgen.rs"

[features]
default = ["thorvg-v0"]
thorvg-v0 = ["dotlottie-rs/thorvg-v0"]
thorvg-v1 = ["dotlottie-rs/thorvg-v1"]

[dependencies]
uniffi = { version = "0.25", features = ["cli"] }
dotlottie-rs = { path = "../dotlottie-rs", features = ["thorvg"] }
dotlottie-rs = { path = "../dotlottie-rs", default-features = false }
cfg-if = "1.0"
bitflags = "2.6.0"

Expand Down
7 changes: 4 additions & 3 deletions dotlottie-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ links = "thorvg"
crate-type = ["staticlib", "cdylib", "rlib"]

[features]
thorvg = []
thorvg-v0 = []
thorvg-v1 = []

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
Expand All @@ -30,8 +31,8 @@ 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 = ["thorvg-v0"] }

[[bench]]
name = "benchmarks"
harness = false
harness = false
6 changes: 5 additions & 1 deletion dotlottie-rs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,14 @@ fn apply_build_settings(build_settings: &BuildSettings) {
}

fn main() {
if !cfg!(feature = "thorvg") {
if !cfg!(feature = "thorvg-v0") && !cfg!(feature = "thorvg-v1") {
return;
}

if !is_artifacts_provided() && cfg!(feature = "thorvg-v1") {
panic!("ARTIFACTS_INCLUDE_DIR and ARTIFACTS_LIB_DIR environment variables are required for thorvg-v1");
}

let mut builder = bindgen::Builder::default().header("wrapper.h");
if is_artifacts_provided() {
let include_dir = find_path(ARTIFACTS_INCLUDE_DIR, true);
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 = "thorvg-v0", feature = "thorvg-v1"))]
pub fn new(config: Config) -> Self {
Self::with_renderer(
config,
Expand Down Expand Up @@ -886,7 +886,7 @@ pub struct DotLottiePlayerContainer {
}

impl DotLottiePlayerContainer {
#[cfg(feature = "thorvg")]
#[cfg(any(feature = "thorvg-v0", feature = "thorvg-v1"))]
pub fn new(config: Config) -> Self {
DotLottiePlayerContainer {
runtime: RwLock::new(DotLottieRuntime::new(config)),
Expand Down Expand Up @@ -1274,7 +1274,7 @@ pub struct DotLottiePlayer {
}

impl DotLottiePlayer {
#[cfg(feature = "thorvg")]
#[cfg(any(feature = "thorvg-v0", feature = "thorvg-v1"))]
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 = "thorvg-v0", feature = "thorvg-v1"))]
mod thorvg;

pub use renderer::{Animation, ColorSpace, Drawable, Renderer, Shape};
#[cfg(feature = "thorvg")]
#[cfg(any(feature = "thorvg-v0", feature = "thorvg-v1"))]
pub use thorvg::{TvgAnimation, TvgEngine, TvgError, TvgRenderer, TvgShape};

#[derive(Error, Debug)]
Expand Down Expand Up @@ -87,6 +87,7 @@ impl dyn LottieRenderer {
let background_shape = R::Shape::default();

renderer.push(Drawable::Shape(&background_shape)).unwrap();
renderer.sync().unwrap();

Box::new(LottieRendererImpl {
animation: R::Animation::default(),
Expand Down Expand Up @@ -229,7 +230,7 @@ impl<R: Renderer> LottieRenderer for LottieRendererImpl<R> {

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

Ok(())
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 @@ -78,7 +78,7 @@ pub trait Renderer: Sized + 'static {

fn push(&mut self, drawable: Drawable<Self>) -> Result<(), Self::Error>;

fn draw(&mut self) -> Result<(), Self::Error>;
fn draw(&mut self, clear_buffer: bool) -> Result<(), Self::Error>;

fn sync(&mut self) -> Result<(), Self::Error>;

Expand Down
45 changes: 36 additions & 9 deletions dotlottie-rs/src/lottie_renderer/thorvg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,15 @@ impl Renderer for TvgRenderer {
}

fn clear(&self, free: bool) -> Result<(), TvgError> {
unsafe { tvg::tvg_canvas_clear(self.raw_canvas, free).into_result() }
#[cfg(feature = "thorvg-v1")]
unsafe {
tvg::tvg_canvas_remove(self.raw_canvas, ptr::null_mut::<tvg::Tvg_Paint>()).into_result()
}

#[cfg(feature = "thorvg-v0")]
unsafe {
tvg::tvg_canvas_clear(self.raw_canvas, free).into_result()
}
}

fn push(&mut self, drawable: Drawable<Self>) -> Result<(), TvgError> {
Expand All @@ -150,10 +158,16 @@ impl Renderer for TvgRenderer {
unsafe { tvg::tvg_canvas_push(self.raw_canvas, raw_paint).into_result() }
}

fn draw(&mut self) -> Result<(), TvgError> {
let result = unsafe { tvg::tvg_canvas_draw(self.raw_canvas) };
fn draw(&mut self, _clear_buffer: bool) -> Result<(), TvgError> {
#[cfg(feature = "thorvg-v1")]
unsafe {
tvg::tvg_canvas_draw(self.raw_canvas, _clear_buffer).into_result()
}

result.into_result()
#[cfg(feature = "thorvg-v0")]
unsafe {
tvg::tvg_canvas_draw(self.raw_canvas).into_result()
}
}

fn sync(&mut self) -> Result<(), TvgError> {
Expand Down Expand Up @@ -202,19 +216,32 @@ impl Animation for TvgAnimation {
type Error = TvgError;

fn load_data(&mut self, data: &str, mimetype: &str, copy: bool) -> Result<(), TvgError> {
let mimetype_cstr = CString::new(mimetype).expect("Failed to create CString");
let data_cstr = CString::new(data).expect("Failed to create CString");
let mimetype_cstr = CString::new(mimetype).unwrap();
let data_cstr = CString::new(data).unwrap();
let data_len = data_cstr.as_bytes().len() as u32;

#[cfg(feature = "thorvg-v1")]
unsafe {
let data_ptr = data_cstr.as_ptr();
let mimetype_ptr = mimetype_cstr.as_ptr();
tvg::tvg_picture_load_data(
self.raw_paint,
data_cstr.as_ptr(),
data.len() as u32,
mimetype_cstr.as_ptr(),
data_ptr,
data_len,
mimetype_ptr,
ptr::null(),
copy,
)
.into_result()
}

#[cfg(feature = "thorvg-v0")]
unsafe {
let data_ptr = data_cstr.as_ptr();
let mimetype_ptr = mimetype_cstr.as_ptr();
tvg::tvg_picture_load_data(self.raw_paint, data_ptr, data_len, mimetype_ptr, copy)
.into_result()
}
}

fn get_layer_bounds(&self, layer_name: &str) -> Result<(f32, f32, f32, f32), TvgError> {
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 = ["thorvg-v0"] }
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 = ["thorvg-v0"] }
sysinfo = "0.30"
rand = "0.8"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use dotlottie_player_core::events::Event;
use dotlottie_player_core::{Config, DotLottiePlayer};
use dotlottie_rs::events::Event;
use dotlottie_rs::{Config, DotLottiePlayer};
use minifb::{Key, MouseButton, MouseMode, Window, WindowOptions};
use std::fs::{self, File};
use std::io::Read;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use dotlottie_player_core::events::Event;
use dotlottie_player_core::{Config, DotLottiePlayer};
use dotlottie_rs::events::Event;
use dotlottie_rs::{Config, DotLottiePlayer};
use minifb::{Key, MouseButton, MouseMode, Window, WindowOptions};
use std::fs::{self, File};
use std::io::Read;
Expand Down

0 comments on commit 86d7377

Please sign in to comment.