Skip to content

Commit

Permalink
refactor: ThorVG 1.0.0-pre8 breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
theashraf committed Dec 13, 2024
1 parent 2158fd6 commit c4a3891
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
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() as *const i8;
let data_len: u32 = data.as_bytes().len() as u32;
let mimetype_ptr: *const i8 = mimetype_cstr.as_ptr() as *const i8;

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

0 comments on commit c4a3891

Please sign in to comment.