Skip to content

Commit

Permalink
~ Using separate method to initialize the logger in the rlottie.
Browse files Browse the repository at this point in the history
  • Loading branch information
gindemit committed Sep 5, 2023
1 parent 9af5362 commit d121bff
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 16 deletions.
9 changes: 5 additions & 4 deletions projects/CMake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ if (WIN32)
endif()

add_subdirectory(${RLOTTIE_ROOT} ${CMAKE_CURRENT_BINARY_DIR}/rlottie_build)

include_directories ($<BUILD_INTERFACE:${RLOTTIE_ROOT}/inc>)

add_definitions(-DLOTTIE_LOGGING_SUPPORT)
target_compile_definitions(rlottie PRIVATE LOTTIE_LOGGING_SUPPORT)
include_directories ($<BUILD_INTERFACE:${RLOTTIE_ROOT}/inc> ${RLOTTIE_ROOT}/src/vector/ ${RLOTTIE_ROOT}/vs2019/)
message("Lottie root directory: ${RLOTTIE_ROOT}")

set (RLOTTIE_PLUGIN_LIBRARY_SOURCES
../../src/LottiePlugin.cpp)
Expand All @@ -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)
Expand Down
18 changes: 13 additions & 5 deletions src/LottiePlugin.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "LottiePlugin.h"
#define LOTTIE_LOGGING_SUPPORT
#include "vdebug.h"

extern "C" {
Expand Down Expand Up @@ -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<void(float& r, float& g, float& b)>& null_func = nullptr;
auto animation = rlottie::Animation::loadFromData(std::string(json_data), std::string(resource_path), null_func);
if(!animation) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
}
14 changes: 12 additions & 2 deletions src/LottiePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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_
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -146,12 +148,25 @@ private void UpdateInternal(float animationSpeed, Action<int> 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;
}
}
}
15 changes: 10 additions & 5 deletions unity/RLottieUnity/Assets/LottiePlugin/Runtime/src/NativeBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@ internal static class NativeBridge
private static extern int LottieLoadFromData(
string jsonData,
string resourcePath,
string logDirectoryPath,
out IntPtr animationWrapper);

[DllImport(PLUGIN_NAME,
CallingConvention = CallingConvention.Cdecl,
EntryPoint = "lottie_load_from_file")]
private static extern int LottieLoadFromFile(
string filePath,
string logDirectoryPath,
out IntPtr animationWrapper);

[DllImport(PLUGIN_NAME,
Expand Down Expand Up @@ -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<LottieAnimationWrapper>(animationWrapper);
}
internal static LottieAnimationWrapper LoadFromFile(string filePath, out IntPtr animationWrapper)
{
LottieLoadFromFile(filePath, Application.persistentDataPath, out animationWrapper);
LottieLoadFromFile(filePath, out animationWrapper);
return Marshal.PtrToStructure<LottieAnimationWrapper>(animationWrapper);
}
internal static void Dispose(LottieAnimationWrapper lottieAnimationWrapper)
Expand Down

0 comments on commit d121bff

Please sign in to comment.