typedef struct Lottie_Animation_S Lottie_Animation;
+/**
+ * @brief Runs lottie initialization code when rlottie library is loaded
+ * dynamically.
+ *
+ *
+ * This api should be called before any other api when rlottie library
+ * is loaded using dlopen() or equivalent.
+ *
+ * @see lottie_shutdown()
+ *
+ * @ingroup Lottie_Animation
+ * @internal
+ */
+RLOTTIE_API void lottie_init();
+
+/**
+ * @brief Runs lottie teardown code when rlottie library is loaded
+ * dynamically.
+ *
+ * This api should be called before unloading the rlottie library for
+ * proper cleanup of the resource without doing so will result in undefined
+ * behaviour.
+ *
+ * @see lottie_init()
+ *
+ * @ingroup Lottie_Animation
+ * @internal
+ */
+RLOTTIE_API void lottie_shutdown();
+
/**
* @brief Constructs an animation object from file path.
*
using namespace rlottie;
+extern void lottie_init_impl();
+extern void lottie_shutdown_impl();
+
extern "C" {
#include <string.h>
#include <stdarg.h>
LOTMarkerList *mMarkerList;
};
+static uint32_t _lottie_lib_ref_count = 0;
+
+RLOTTIE_API void lottie_init()
+{
+ if (_lottie_lib_ref_count > 0) {
+ _lottie_lib_ref_count++;
+ return;
+ }
+ lottie_init_impl();
+
+ _lottie_lib_ref_count = 1;
+}
+
+RLOTTIE_API void lottie_shutdown()
+{
+ if (_lottie_lib_ref_count <= 0) {
+ // lottie_init() is not called before lottie_shutdown()
+ // or multiple shutdown is getting called.
+ return;
+ }
+
+ _lottie_lib_ref_count--;
+
+ if (_lottie_lib_ref_count == 0) {
+ lottie_shutdown_impl();
+ }
+}
+
RLOTTIE_API Lottie_Animation_S *lottie_animation_from_file(const char *path)
{
if (auto animation = Animation::loadFromFile(path) ) {
for (unsigned n = 0; n != _count; ++n) {
_threads.emplace_back([&, n] { run(n); });
}
+
+ IsRunning = true;
}
public:
+ static bool IsRunning;
+
static RenderTaskScheduler &instance()
{
static RenderTaskScheduler singleton;
return singleton;
}
- ~RenderTaskScheduler()
+ ~RenderTaskScheduler() { stop(); }
+
+ void stop()
{
- for (auto &e : _q) e.done();
+ if (IsRunning) {
+ IsRunning = false;
- for (auto &e : _threads) e.join();
+ for (auto &e : _q) e.done();
+ for (auto &e : _threads) e.join();
+ }
}
std::future<Surface> process(SharedRenderTask task)
#else
class RenderTaskScheduler {
public:
+ static bool IsRunning;
+
static RenderTaskScheduler &instance()
{
static RenderTaskScheduler singleton;
return singleton;
}
+ void stop() {}
+
std::future<Surface> process(SharedRenderTask task)
{
auto result = task->playerImpl->render(task->frameNo, task->surface,
return std::move(task->receiver);
}
};
+
#endif
+bool RenderTaskScheduler::IsRunning{false};
+
std::future<Surface> AnimationImpl::renderAsync(size_t frameNo,
Surface &&surface,
bool keepAspectRatio)
mDrawArea.h = height;
}
+namespace {
+void lottieShutdownRenderTaskScheduler()
+{
+ if (RenderTaskScheduler::IsRunning) {
+ RenderTaskScheduler::instance().stop();
+ }
+}
+} // namespace
+
+// private apis exposed to c interface
+void lottie_init_impl()
+{
+ // do nothing for now.
+}
+
+extern void lottieShutdownRasterTaskScheduler();
+
+void lottie_shutdown_impl()
+{
+ lottieShutdownRenderTaskScheduler();
+ lottieShutdownRasterTaskScheduler();
+}
+
#ifdef LOTTIE_LOGGING_SUPPORT
void initLogging()
{
for (unsigned n = 0; n != _count; ++n) {
_threads.emplace_back([&, n] { run(n); });
}
+
+ IsRunning = true;
}
public:
+ static bool IsRunning;
+
static RleTaskScheduler &instance()
{
static RleTaskScheduler singleton;
return singleton;
}
- ~RleTaskScheduler()
+ ~RleTaskScheduler() { stop(); }
+
+ void stop()
{
- for (auto &e : _q) e.done();
+ if (IsRunning) {
+ IsRunning = false;
- for (auto &e : _threads) e.join();
+ for (auto &e : _q) e.done();
+ for (auto &e : _threads) e.join();
+ }
}
void process(VTask task)
SW_FT_Stroker stroker;
public:
+ static bool IsRunning;
+
static RleTaskScheduler &instance()
{
static RleTaskScheduler singleton;
return singleton;
}
+ void stop() {}
+
RleTaskScheduler() { SW_FT_Stroker_New(&stroker); }
~RleTaskScheduler() { SW_FT_Stroker_Done(stroker); }
};
#endif
+bool RleTaskScheduler::IsRunning{false};
+
struct VRasterizer::VRasterizerImpl {
VRleTask mTask;
updateRequest();
}
+void lottieShutdownRasterTaskScheduler()
+{
+ if (RleTaskScheduler::IsRunning) {
+ RleTaskScheduler::instance().stop();
+ }
+}
+
V_END_NAMESPACE