From 9b9a8daa6eecfe687abe5d7d233b5ced8bb938fc Mon Sep 17 00:00:00 2001 From: Abdelrahman Ashraf Date: Wed, 22 May 2024 01:26:52 +0700 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=A4=96=20update=20dependencies?= =?UTF-8?q?=20(thorvg@v0.13.4)=20(#148)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: 🤖 update dependencies (thorvg@v0.13.3) * chore: 🤖 update workflow * chore: 🤖 rerun tests * chore: 🤖 enable lottie expressions for ios and android * chore: 🤖 upgrade thorvg to 0.13.4 * chore: 🤖 update thorvg * run ci --- .github/workflows/check-pr.yaml | 2 +- Makefile | 13 +++++------ deps/modules/thorvg | 2 +- dotlottie-rs/src/dotlottie_player.rs | 30 +++++++------------------ dotlottie-rs/src/lottie_renderer/mod.rs | 29 ++++++++++++------------ 5 files changed, 31 insertions(+), 45 deletions(-) diff --git a/.github/workflows/check-pr.yaml b/.github/workflows/check-pr.yaml index c85c2cb1..818d5f84 100644 --- a/.github/workflows/check-pr.yaml +++ b/.github/workflows/check-pr.yaml @@ -26,6 +26,6 @@ jobs: - name: Build Artifacts env: APPLE_MACOSX_SDK: MacOSX13 - run: make all + run: make demo-player - name: Run Tests run: make test diff --git a/Makefile b/Makefile index 39122017..1bb9f441 100644 --- a/Makefile +++ b/Makefile @@ -315,8 +315,7 @@ define SETUP_MESON -Dbindings=capi \ -Dlog=$(LOG) \ -Dstatic=$(STATIC) \ - -Dsavers=$(SAVERS) \ - -Dthreads=true \ + -Dextra=$(EXTRA) \ $(CROSS_FILE) "$(THORVG_DEP_SOURCE_DIR)" "$(THORVG_DEP_BUILD_DIR)" endef @@ -583,7 +582,7 @@ $$($1_THORVG_DEP_BUILD_DIR)/$(NINJA_BUILD_FILE): THORVG_DEP_BUILD_DIR := $$($1_T $$($1_THORVG_DEP_BUILD_DIR)/$(NINJA_BUILD_FILE): CROSS_FILE := --cross-file $$($1_THORVG_DEP_BUILD_DIR)/../$(MESON_CROSS_FILE) $$($1_THORVG_DEP_BUILD_DIR)/$(NINJA_BUILD_FILE): LOG := $2 $$($1_THORVG_DEP_BUILD_DIR)/$(NINJA_BUILD_FILE): STATIC := $3 -$$($1_THORVG_DEP_BUILD_DIR)/$(NINJA_BUILD_FILE): SAVERS := $4 +$$($1_THORVG_DEP_BUILD_DIR)/$(NINJA_BUILD_FILE): EXTRA := $4 $$($1_THORVG_DEP_BUILD_DIR)/$(NINJA_BUILD_FILE): $$($1_THORVG_DEP_BUILD_DIR)/../$(MESON_CROSS_FILE) $(if $(filter $3,false), $$($1_THORVG_DEP_BUILD_DIR)/$(NINJA_BUILD_FILE): $$($1_DEPS_LIB_DIR)/$(LIBJPEG_TURBO_LIB) @@ -605,7 +604,7 @@ $(eval $(call NEW_ANDROID_CMAKE_BUILD,$1,LIBPNG_LIB,$(LIBPNG),$$($1_LIBPNG_DEP_B $(eval $(call NEW_ANDROID_CMAKE_BUILD,$1,ZLIB,$(ZLIB),$$($1_ZLIB_DEP_BUILD_DIR),$(ZLIB_LIB))) $(eval $(call NEW_ANDROID_CMAKE_BUILD,$1,WEBP,$(WEBP),$$($1_WEBP_DEP_BUILD_DIR),$(WEBP_LIB))) $(eval $(call NEW_ANDROID_CROSS_FILE,$1)) -$(eval $(call NEW_THORVG_BUILD,$1,true,false,all)) +$(eval $(call NEW_THORVG_BUILD,$1,false,false,"lottie_expressions")) endef define NEW_APPLE_DEPS_BUILD @@ -614,12 +613,12 @@ $(eval $(call NEW_APPLE_CMAKE_BUILD,$1,LIBPNG_LIB,$(LIBPNG),$$($1_LIBPNG_DEP_BUI $(eval $(call NEW_APPLE_CMAKE_BUILD,$1,ZLIB,$(ZLIB),$$($1_ZLIB_DEP_BUILD_DIR),$(ZLIB_LIB))) $(eval $(call NEW_APPLE_CMAKE_BUILD,$1,WEBP,$(WEBP),$$($1_WEBP_DEP_BUILD_DIR),$(WEBP_LIB))) $(eval $(call NEW_APPLE_CROSS_FILE,$1)) -$(eval $(call NEW_THORVG_BUILD,$1,true,false,all)) +$(eval $(call NEW_THORVG_BUILD,$1,false,false,"lottie_expressions")) endef define NEW_WASM_DEPS_BUILD $(eval $(call NEW_WASM_CROSS_FILE,$1,$$($1_THORVG_DEP_BUILD_DIR)/..,windows)) -$(eval $(call NEW_THORVG_BUILD,$1,false,true,)) +$(eval $(call NEW_THORVG_BUILD,$1,false,true,"lottie_expressions")) endef define NEW_ANDROID_BUILD @@ -784,7 +783,7 @@ $(THORVG_LOCAL_ARCH_BUILD_DIR)/$(NINJA_BUILD_FILE): THORVG_DEP_SOURCE_DIR := $(D $(THORVG_LOCAL_ARCH_BUILD_DIR)/$(NINJA_BUILD_FILE): THORVG_DEP_BUILD_DIR := $(THORVG_LOCAL_ARCH_BUILD_DIR) $(THORVG_LOCAL_ARCH_BUILD_DIR)/$(NINJA_BUILD_FILE): LOG := false $(THORVG_LOCAL_ARCH_BUILD_DIR)/$(NINJA_BUILD_FILE): STATIC := false -$(THORVG_LOCAL_ARCH_BUILD_DIR)/$(NINJA_BUILD_FILE): SAVERS := all +$(THORVG_LOCAL_ARCH_BUILD_DIR)/$(NINJA_BUILD_FILE): EXTRA := lottie_expressions $(THORVG_LOCAL_ARCH_BUILD_DIR)/$(NINJA_BUILD_FILE): $(LOCAL_ARCH_LIB_DIR)/$(LIBJPEG_TURBO_LIB) $(THORVG_LOCAL_ARCH_BUILD_DIR)/$(NINJA_BUILD_FILE): $(LOCAL_ARCH_LIB_DIR)/$(LIBPNG_LIB) $(THORVG_LOCAL_ARCH_BUILD_DIR)/$(NINJA_BUILD_FILE): $(LOCAL_ARCH_LIB_DIR)/$(ZLIB_LIB) diff --git a/deps/modules/thorvg b/deps/modules/thorvg index ce90e140..770ad3f1 160000 --- a/deps/modules/thorvg +++ b/deps/modules/thorvg @@ -1 +1 @@ -Subproject commit ce90e140798581071f9e464d38a8d7fa75f80e6d +Subproject commit 770ad3f1791d54f26100d99b9e89e4b70792794f diff --git a/dotlottie-rs/src/dotlottie_player.rs b/dotlottie-rs/src/dotlottie_player.rs index d49fc99a..d6a3200e 100644 --- a/dotlottie-rs/src/dotlottie_player.rs +++ b/dotlottie-rs/src/dotlottie_player.rs @@ -83,8 +83,6 @@ impl Default for Config { } } -const FRAME_DIFF_THRESHOLD: f32 = 0.001; - struct DotLottieRuntime { renderer: LottieRenderer, playback_state: PlaybackState, @@ -281,29 +279,17 @@ impl DotLottieRuntime { Direction::Reverse => end_frame - raw_next_frame, }; - if !self.config.use_frame_interpolation { - next_frame = next_frame.round(); - } - - /* - Note: - If we're close to the end frame, we should snap to it as tvg_set_frame ignore the frame which is 0.001 less than the current frame. - */ - match self.direction { - Direction::Forward => { - if (next_frame - end_frame).abs() < FRAME_DIFF_THRESHOLD { - next_frame = end_frame; - } - } - Direction::Reverse => { - if (next_frame - start_frame).abs() < FRAME_DIFF_THRESHOLD { - next_frame = start_frame - } - } + // Apply frame interpolation + next_frame = if self.config.use_frame_interpolation { + (next_frame * 1000.0).round() / 1000.0 + } else { + next_frame.round() }; + // Clamp the next frame to the start & end frames next_frame = next_frame.clamp(start_frame, end_frame); + // Handle different modes next_frame = match self.config.mode { Mode::Forward => self.handle_forward_mode(next_frame, end_frame), Mode::Reverse => self.handle_reverse_mode(next_frame, start_frame), @@ -505,7 +491,7 @@ impl DotLottieRuntime { } pub fn current_frame(&self) -> f32 { - self.renderer.current_frame().unwrap_or(0.0) + self.renderer.current_frame } pub fn loop_count(&self) -> u32 { diff --git a/dotlottie-rs/src/lottie_renderer/mod.rs b/dotlottie-rs/src/lottie_renderer/mod.rs index 7df05343..d421e822 100644 --- a/dotlottie-rs/src/lottie_renderer/mod.rs +++ b/dotlottie-rs/src/lottie_renderer/mod.rs @@ -24,6 +24,7 @@ pub struct LottieRenderer { pub height: u32, pub buffer: Vec, pub background_color: u32, + pub current_frame: f32, layout: Layout, } @@ -43,6 +44,7 @@ impl LottieRenderer { picture_width: 0.0, picture_height: 0.0, background_color: 0, + current_frame: 0.0, layout: Layout::default(), } } @@ -80,9 +82,8 @@ impl LottieRenderer { self.picture_width = pw; self.picture_height = ph; - let (scaled_picture_width, scaled_picture_height, shift_x, shift_y) = self - .layout - .compute_layout_transform( + let (scaled_picture_width, scaled_picture_height, shift_x, shift_y) = + self.layout.compute_layout_transform( self.width as f32, self.height as f32, self.picture_width, @@ -123,10 +124,8 @@ impl LottieRenderer { .map_err(|e| LottieRendererError::ThorvgError(e)) } - pub fn current_frame(&self) -> Result { - self.thorvg_animation - .get_frame() - .map_err(|e| LottieRendererError::ThorvgError(e)) + pub fn current_frame(&self) -> f32 { + self.current_frame } pub fn clear(&mut self) { @@ -156,7 +155,11 @@ impl LottieRenderer { self.thorvg_animation .set_frame(no) - .map_err(|e| LottieRendererError::ThorvgError(e)) + .map_err(LottieRendererError::ThorvgError)?; + + self.current_frame = no; + + Ok(()) } pub fn resize(&mut self, width: u32, height: u32) -> Result<(), LottieRendererError> { @@ -186,9 +189,8 @@ impl LottieRenderer { ) .map_err(LottieRendererError::ThorvgError)?; - let (scaled_picture_width, scaled_picture_height, shift_x, shift_y) = self - .layout - .compute_layout_transform( + let (scaled_picture_width, scaled_picture_height, shift_x, shift_y) = + self.layout.compute_layout_transform( self.width as f32, self.height as f32, self.picture_width, @@ -242,9 +244,8 @@ impl LottieRenderer { self.layout = layout.clone(); - let (scaled_picture_width, scaled_picture_height, shift_x, shift_y) = self - .layout - .compute_layout_transform( + let (scaled_picture_width, scaled_picture_height, shift_x, shift_y) = + self.layout.compute_layout_transform( self.width as f32, self.height as f32, self.picture_width,