From d121bff376195de1b401197bb892e733bf56337d Mon Sep 17 00:00:00 2001 From: Konstantin Gindemit Date: Tue, 5 Sep 2023 10:16:08 +0200 Subject: [PATCH] ~ Using separate method to initialize the logger in the rlottie. --- projects/CMake/CMakeLists.txt | 9 +++++---- src/LottiePlugin.cpp | 18 +++++++++++++----- src/LottiePlugin.h | 14 ++++++++++++-- .../Runtime/src/LottieAnimation.cs | 15 +++++++++++++++ .../LottiePlugin/Runtime/src/NativeBridge.cs | 15 ++++++++++----- 5 files changed, 55 insertions(+), 16 deletions(-) diff --git a/projects/CMake/CMakeLists.txt b/projects/CMake/CMakeLists.txt index 164f726..ee02e77 100644 --- a/projects/CMake/CMakeLists.txt +++ b/projects/CMake/CMakeLists.txt @@ -23,10 +23,9 @@ if (WIN32) endif() add_subdirectory(${RLOTTIE_ROOT} ${CMAKE_CURRENT_BINARY_DIR}/rlottie_build) - -include_directories ($) - -add_definitions(-DLOTTIE_LOGGING_SUPPORT) +target_compile_definitions(rlottie PRIVATE LOTTIE_LOGGING_SUPPORT) +include_directories ($ ${RLOTTIE_ROOT}/src/vector/ ${RLOTTIE_ROOT}/vs2019/) +message("Lottie root directory: ${RLOTTIE_ROOT}") set (RLOTTIE_PLUGIN_LIBRARY_SOURCES ../../src/LottiePlugin.cpp) @@ -39,6 +38,8 @@ else() add_library (LottiePlugin SHARED ${RLOTTIE_PLUGIN_LIBRARY_SOURCES}) endif() +target_compile_definitions(LottiePlugin PRIVATE LOTTIE_LOGGING_SUPPORT) + if (RLOTTIE_IOS OR ANDROID OR RLOTTIE_OSX) message("Compile cpp source for iOS or Android") target_sources(rlottie PRIVATE ${PIXMAN_ROOT}/pixman-cpp-standard.cpp) diff --git a/src/LottiePlugin.cpp b/src/LottiePlugin.cpp index 9ae8e4c..4900fb5 100644 --- a/src/LottiePlugin.cpp +++ b/src/LottiePlugin.cpp @@ -1,5 +1,4 @@ #include "LottiePlugin.h" -#define LOTTIE_LOGGING_SUPPORT #include "vdebug.h" extern "C" { @@ -30,9 +29,7 @@ extern "C" { EXPORT_API int32_t lottie_load_from_data( const char* json_data, const char* resource_path, - const char* log_dir_path, lottie_animation_wrapper** animation_wrapper) { - initialize(GuaranteedLogger(), std::string(log_dir_path), std::string("rlottie_log"), 1); const std::function& null_func = nullptr; auto animation = rlottie::Animation::loadFromData(std::string(json_data), std::string(resource_path), null_func); if(!animation) { @@ -44,9 +41,7 @@ extern "C" { } EXPORT_API int32_t lottie_load_from_file( const char* file_path, - const char* log_dir_path, lottie_animation_wrapper** animation_wrapper) { - initialize(GuaranteedLogger(), std::string(log_dir_path), std::string("rlottie_log"), 1); auto animation = rlottie::Animation::loadFromFile(std::string(file_path)); if(!animation) { @@ -112,4 +107,17 @@ extern "C" { *render_data = nullptr; return 0; } + EXPORT_API int32_t initialize_logger(const char* log_dir_path, const char* log_file_name, int32_t log_file_roll_size_mb) { + fprintf(stderr, "Initializing logger (stderr)\n"); + // print the paths + fprintf(stderr, "log_dir_path: %s\n", log_dir_path); + fprintf(stderr, "log_file_name: %s\n", log_file_name); + fprintf(stderr, "log_file_roll_size_mb: %d\n", log_file_roll_size_mb); + fprintf(stdout, "Initializing logger (stdout)\n"); + initialize(GuaranteedLogger(), std::string(log_dir_path), std::string(log_file_name), log_file_roll_size_mb); + vDebug << "Initialized logger (debug)"; + vWarning << "Initialized logger (warning)"; + vCritical << "Initialized logger (critical)"; + return 0; + } } diff --git a/src/LottiePlugin.h b/src/LottiePlugin.h index 41937c2..d0287cd 100644 --- a/src/LottiePlugin.h +++ b/src/LottiePlugin.h @@ -25,8 +25,13 @@ typedef struct lottie_render_data { } lottie_render_data; extern "C" { - EXPORT_API int32_t lottie_load_from_data(const char* json_data, const char* resource_path, lottie_animation_wrapper** animation_wrapper); - EXPORT_API int32_t lottie_load_from_file(const char *file_path, lottie_animation_wrapper **animation_wrapper); + EXPORT_API int32_t lottie_load_from_data( + const char* json_data, + const char* resource_path, + lottie_animation_wrapper** animation_wrapper); + EXPORT_API int32_t lottie_load_from_file( + const char *file_path, + lottie_animation_wrapper **animation_wrapper); EXPORT_API int32_t lottie_dispose_wrapper(lottie_animation_wrapper **animation_wrapper); EXPORT_API int32_t lottie_render_immediately( lottie_animation_wrapper* animation_wrapper, @@ -45,6 +50,11 @@ extern "C" { EXPORT_API int32_t lottie_allocate_render_data(lottie_render_data** render_data); EXPORT_API int32_t lottie_dispose_render_data(lottie_render_data** render_data); + + EXPORT_API int32_t initialize_logger( + const char* log_dir_path, + const char* log_file_name, + int32_t log_file_roll_size_mb); } #endif // !_VORBIS_PLUGIN_H_ \ No newline at end of file diff --git a/unity/RLottieUnity/Assets/LottiePlugin/Runtime/src/LottieAnimation.cs b/unity/RLottieUnity/Assets/LottiePlugin/Runtime/src/LottieAnimation.cs index 3ec4b72..82d5cab 100644 --- a/unity/RLottieUnity/Assets/LottiePlugin/Runtime/src/LottieAnimation.cs +++ b/unity/RLottieUnity/Assets/LottiePlugin/Runtime/src/LottieAnimation.cs @@ -9,6 +9,8 @@ namespace LottiePlugin { public sealed class LottieAnimation : IDisposable { + private static bool sLoggerInitialized; + public Texture2D Texture { get; private set; } public int CurrentFrame { get; private set; } public double FrameRate => _animationWrapper.frameRate; @@ -146,12 +148,25 @@ private void UpdateInternal(float animationSpeed, Action drawOneFrameMethod public static LottieAnimation LoadFromJsonFile(string filePath, uint width, uint height) { ThrowIf.String.IsNullOrEmpty(filePath, nameof(filePath)); + InitializeLogger(Application.persistentDataPath, "rlottie.log", 1); return new LottieAnimation(filePath, width, height); } public static LottieAnimation LoadFromJsonData(string jsonData, string resourcesPath, uint width, uint height) { ThrowIf.String.IsNullOrEmpty(jsonData, nameof(jsonData)); + InitializeLogger(Application.persistentDataPath, "rlottie.log", 1); return new LottieAnimation(jsonData, resourcesPath, width, height); } + public static void InitializeLogger(string logDirectoryPath, string logFileName, int logFileRollSizeMB) + { + ThrowIf.String.IsNullOrEmpty(logDirectoryPath, nameof(logDirectoryPath)); + ThrowIf.String.IsNullOrEmpty(logFileName, nameof(logFileName)); + if (sLoggerInitialized) + { + return; + } + NativeBridge.InitializeLogger(logDirectoryPath, logFileName, logFileRollSizeMB); + sLoggerInitialized = true; + } } } diff --git a/unity/RLottieUnity/Assets/LottiePlugin/Runtime/src/NativeBridge.cs b/unity/RLottieUnity/Assets/LottiePlugin/Runtime/src/NativeBridge.cs index 99e6cdf..18f33f7 100644 --- a/unity/RLottieUnity/Assets/LottiePlugin/Runtime/src/NativeBridge.cs +++ b/unity/RLottieUnity/Assets/LottiePlugin/Runtime/src/NativeBridge.cs @@ -37,7 +37,6 @@ internal static class NativeBridge private static extern int LottieLoadFromData( string jsonData, string resourcePath, - string logDirectoryPath, out IntPtr animationWrapper); [DllImport(PLUGIN_NAME, @@ -45,7 +44,6 @@ private static extern int LottieLoadFromData( EntryPoint = "lottie_load_from_file")] private static extern int LottieLoadFromFile( string filePath, - string logDirectoryPath, out IntPtr animationWrapper); [DllImport(PLUGIN_NAME, @@ -88,16 +86,23 @@ internal static extern int LottieAllocateRenderData( EntryPoint = "lottie_dispose_render_data")] internal static extern int LottieDisposeRenderData( ref IntPtr animationWrapper); + + [DllImport(PLUGIN_NAME, + CallingConvention = CallingConvention.Cdecl, + EntryPoint = "initialize_logger")] + internal static extern int InitializeLogger( + string logDirectoryPath, + string logFileName, + int logFileRollSizeMB); internal static LottieAnimationWrapper LoadFromData(string filePath, string resourcesPath, out IntPtr animationWrapper) { - Debug.Log(Application.persistentDataPath); - LottieLoadFromData(filePath, resourcesPath, Application.persistentDataPath, out animationWrapper); + LottieLoadFromData(filePath, resourcesPath, out animationWrapper); return Marshal.PtrToStructure(animationWrapper); } internal static LottieAnimationWrapper LoadFromFile(string filePath, out IntPtr animationWrapper) { - LottieLoadFromFile(filePath, Application.persistentDataPath, out animationWrapper); + LottieLoadFromFile(filePath, out animationWrapper); return Marshal.PtrToStructure(animationWrapper); } internal static void Dispose(LottieAnimationWrapper lottieAnimationWrapper)