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 10, 2025
1 parent 9ad8c18 commit b4e4d82
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 34 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"
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,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 @@ -1024,8 +1025,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
8 changes: 2 additions & 6 deletions dotlottie-rs/src/lottie_renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl<R: Renderer> LottieRenderer for LottieRendererImpl<R> {
height: u32,
copy: bool,
) -> Result<(), LottieRendererError> {
self.renderer.clear(true, false).map_err(into_lottie::<R>)?;
self.renderer.clear(true).map_err(into_lottie::<R>)?;

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

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

#[cfg(feature = "thorvg-v1")]
self.renderer.clear(false, true).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
4 changes: 2 additions & 2 deletions dotlottie-rs/src/lottie_renderer/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ pub trait Renderer: Sized + 'static {
color_space: ColorSpace,
) -> Result<(), Self::Error>;

fn clear(&self, paints: bool, buffer: bool) -> Result<(), Self::Error>;
fn clear(&self, free: bool) -> Result<(), Self::Error>;

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
43 changes: 28 additions & 15 deletions dotlottie-rs/src/lottie_renderer/thorvg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,16 @@ impl Renderer for TvgRenderer {
}
}

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

#[cfg(feature = "thorvg-v0")]
{
tvg::tvg_canvas_clear(self.raw_canvas, paints)
tvg::tvg_canvas_clear(self.raw_canvas, free)
}
}
.into_result()
Expand All @@ -161,10 +161,19 @@ 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> {
unsafe {
#[cfg(feature = "thorvg-v1")]
{
tvg::tvg_canvas_draw(self.raw_canvas, _clear_buffer)
}

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

fn sync(&mut self) -> Result<(), TvgError> {
Expand Down Expand Up @@ -213,17 +222,21 @@ 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_ptr: *const i8 = data_cstr.as_ptr();
let data_len = data.as_bytes().len() as u32;
let mimetype_ptr: *const i8 = mimetype_cstr.as_ptr();

unsafe {
#[cfg(feature = "thorvg-v1")]
{
tvg::tvg_picture_load_data(
self.raw_paint,
data.as_ptr(),
data.as_bytes().len() as u32,
mimetype.as_ptr(),
data_ptr,
data_len,
mimetype_ptr,
ptr::null(),
copy,
)
Expand All @@ -233,14 +246,14 @@ impl Animation for TvgAnimation {
{
tvg::tvg_picture_load_data(
self.raw_paint,
data.as_ptr(),
data.as_bytes().len() as u32,
mimetype.as_ptr(),
data_ptr,
data_len,
mimetype_ptr,
copy,
)
}
}
.into_result()?;
.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 b4e4d82

Please sign in to comment.