diff --git a/dotlottie-rs/src/lottie_renderer/mod.rs b/dotlottie-rs/src/lottie_renderer/mod.rs index 4500da47..f6c60332 100644 --- a/dotlottie-rs/src/lottie_renderer/mod.rs +++ b/dotlottie-rs/src/lottie_renderer/mod.rs @@ -122,7 +122,7 @@ impl LottieRenderer for LottieRendererImpl { height: u32, copy: bool, ) -> Result<(), LottieRendererError> { - self.renderer.clear(true, false).map_err(into_lottie::)?; + self.renderer.clear(true).map_err(into_lottie::)?; self.picture_width = 0.0; self.picture_height = 0.0; @@ -224,11 +224,7 @@ impl LottieRenderer for LottieRendererImpl { fn render(&mut self) -> Result<(), LottieRendererError> { self.renderer.update().map_err(into_lottie::)?; - - #[cfg(feature = "thorvg-v1")] - self.renderer.clear(false, true).map_err(into_lottie::)?; - - self.renderer.draw().map_err(into_lottie::)?; + self.renderer.draw(true).map_err(into_lottie::)?; self.renderer.sync().map_err(into_lottie::)?; Ok(()) diff --git a/dotlottie-rs/src/lottie_renderer/renderer.rs b/dotlottie-rs/src/lottie_renderer/renderer.rs index 3023fde3..894d2e8b 100644 --- a/dotlottie-rs/src/lottie_renderer/renderer.rs +++ b/dotlottie-rs/src/lottie_renderer/renderer.rs @@ -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) -> 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>; diff --git a/dotlottie-rs/src/lottie_renderer/thorvg.rs b/dotlottie-rs/src/lottie_renderer/thorvg.rs index 40773ecd..b5235a71 100644 --- a/dotlottie-rs/src/lottie_renderer/thorvg.rs +++ b/dotlottie-rs/src/lottie_renderer/thorvg.rs @@ -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::()) } #[cfg(feature = "thorvg-v0")] { - tvg::tvg_canvas_clear(self.raw_canvas, paints) + tvg::tvg_canvas_clear(self.raw_canvas, free) } } .into_result() @@ -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> { @@ -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, ) @@ -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> {