Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mem shrink rlottie. #516

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "src/lottie/JSON"]
path = src/lottie/JSON
url = https://github.com/X-Ryl669/JSON.git
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ option(LOTTIE_CACHE "Enable LOTTIE CACHE SUPPORT" ON)
option(LOTTIE_TEST "Build LOTTIE AUTOTESTS" OFF)
option(LOTTIE_CCACHE "Enable LOTTIE ccache SUPPORT" OFF)
option(LOTTIE_ASAN "Compile with asan" OFF)
option(LOTTIE_JSON "Use readonly JSON parser" OFF)
option(LOTTIE_MEMSHRINK "Minimize memory but increase parsing time" OFF)
option(LOTTIE_EXAMPLE "Build examples" ON)

set(LOTTIE_MODULE_PATH "${CMAKE_SHARED_LIBRARY_PREFIX}rlottie-image-loader${CMAKE_SHARED_LIBRARY_SUFFIX}"
CACHE STRING "Absolute or relative path to dynamic loader plugin.")
Expand Down Expand Up @@ -137,7 +140,10 @@ endif (NOT LIB_INSTALL_DIR)
#declare source and include files
add_subdirectory(inc)
add_subdirectory(src)
add_subdirectory(example)

if (LOTTIE_EXAMPLE)
add_subdirectory(example)
endif()

if (LOTTIE_TEST)
enable_testing()
Expand Down
12 changes: 12 additions & 0 deletions cmake/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,15 @@
#ifdef LOTTIE_CACHE
#define LOTTIE_CACHE_SUPPORT
#endif

#cmakedefine LOTTIE_JSON

#ifdef LOTTIE_JSON
#define LOTTIE_JSON_SUPPORT
#endif

#cmakedefine LOTTIE_MEMSHRINK

#ifdef LOTTIE_MEMSHRINK
#define LOTTIE_MEMSHRINK_SUPPORT
#endif
14 changes: 12 additions & 2 deletions example/lottieperf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ class PerfTest
{
_resourceList = jsonFiles(std::string(DEMO_DIR));
}
explicit PerfTest(const std::string& filename):
_resourceCount(1), _iterations(1)
{
_resourceList.push_back(filename);
}
void test(bool async)
{
setup();
Expand Down Expand Up @@ -125,7 +130,7 @@ class PerfTest

static int help()
{
std::cout<<"\nUsage : ./perf [--sync] [-c] [resource count] [-i] [iteration count] \n";
std::cout<<"\nUsage : ./perf [--sync] [-c] [resource count] [-i] [iteration count] [-f] [filename] \n";
std::cout<<"\nExample : ./perf -c 50 -i 100 \n";
std::cout<<"\n\t runs perf test for 100 iterations. renders 50 resource per iteration\n\n";
return 0;
Expand All @@ -137,6 +142,7 @@ main(int argc, char ** argv)
size_t resourceCount = 250;
size_t iterations = 500;
auto index = 0;
std::string filename;

while (index < argc) {
const char* option = argv[index];
Expand All @@ -151,10 +157,14 @@ main(int argc, char ** argv)
} else if (!strcmp(option,"-i")) {
iterations = (index < argc) ? atoi(argv[index]) : iterations;
index++;
} else if (!strcmp(option,"-f")) {
filename = (index < argc) ? argv[index] : "";
index++;
}
}

PerfTest obj(resourceCount, iterations);

PerfTest obj = filename.length() ? PerfTest(filename) : PerfTest(resourceCount, iterations);
obj.test(async);
return 0;
}
1 change: 1 addition & 0 deletions example/lottieview.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include<future>
#include <cmath>
#include <algorithm>
#include <vector>

class RenderStrategy {
public:
Expand Down
23 changes: 21 additions & 2 deletions example/lottieviewtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ class LottieViewTest
ecore_animator_frametime_set(1.0f/120.0f);
}

void show(const char * filepath) {
std::unique_ptr<LottieView> view(new LottieView(mApp->evas(), mStrategy));
view->setFilePath(filepath);
view->setPos(3, 3);
int vw = mApp->width() - 6;
view->setSize(vw, vw);
view->show();
view->play();
view->loop(true);
mViews.push_back(std::move(view));
}


void show(int numberOfImage) {
auto resource = EvasApp::jsonFiles(std::string(DEMO_DIR));

Expand Down Expand Up @@ -92,9 +105,10 @@ class LottieViewTest
}

static int help() {
printf("Usage ./lottieviewTest [-s] [strategy] [-t] [timeout] [-c] [count]\n");
printf("Usage ./lottieviewTest [-s] [strategy] [-t] [timeout] [-c] [count] [-f] path\n");
printf("\n \t-t : timeout duration in seconds\n");
printf("\n \t-c : number of resource in the grid\n");
printf("\n \t-f : File to play\n");
printf("\n \t-s : Rendering Strategy\n");
printf("\t\t 0 - Test Lottie SYNC Renderer with CPP API\n");
printf("\t\t 1 - Test Lottie ASYNC Renderer with CPP API\n");
Expand Down Expand Up @@ -134,6 +148,7 @@ main(int argc, char **argv)
auto index = 0;
double timeOut = 0;
size_t itemCount = 250;
std::string filePath;
while (index < argc) {
const char* option = argv[index];
index++;
Expand All @@ -148,14 +163,18 @@ main(int argc, char **argv)
} else if (!strcmp(option,"-c")) {
itemCount = (index < argc) ? atoi(argv[index]) : 10;
index++;
} else if (!strcmp(option,"-f")) {
filePath = argv[index];
index++;
}
}

EvasApp *app = new EvasApp(800, 800);
app->setup();

LottieViewTest *view = new LottieViewTest(app, st, timeOut);
view->show(itemCount);
if (filePath.length()) view->show(filePath.c_str());
else view->show(itemCount);

app->addExitCb(onExitCb, view);

Expand Down
35 changes: 31 additions & 4 deletions inc/rlottie.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#define _RLOTTIE_H_

#include <future>
#include <vector>
#include <memory>
#include "../src/vector/vvector.h"

#if defined _WIN32 || defined __CYGWIN__
#ifdef RLOTTIE_BUILD
Expand Down Expand Up @@ -142,7 +142,7 @@ class RLOTTIE_API Surface {
* @brief Sets the Draw Area available on the Surface.
*
* Lottie will use the draw region size to generate frame image
* and will update only the draw rgion of the surface.
* and will update only the draw region of the surface.
*
* @param[in] x region area x position.
* @param[in] y region area y position.
Expand Down Expand Up @@ -255,15 +255,15 @@ class RLOTTIE_API Surface {
}mDrawArea;
};

using MarkerList = std::vector<std::tuple<std::string, int , int>>;
using MarkerList = VVector<std::tuple<std::string, int , int>>;
/**
* @brief https://helpx.adobe.com/after-effects/using/layer-markers-composition-markers.html
* Markers exported form AE are used to describe a segmnet of an animation {comment/tag , startFrame, endFrame}
* Marker can be use to devide a resource in to separate animations by tagging the segment with comment string ,
* start frame and duration of that segment.
*/

using LayerInfoList = std::vector<std::tuple<std::string, int , int>>;
using LayerInfoList = VVector<std::tuple<std::string, int , int>>;


using ColorFilter = std::function<void(float &r , float &g, float &b)>;
Expand Down Expand Up @@ -308,6 +308,21 @@ class RLOTTIE_API Animation {
loadFromData(std::string jsonData, const std::string &key,
const std::string &resourcePath="", bool cachePolicy=true);

/**
* @brief Constructs an animation object from JSON string read only data.
*
* @param[in] data The JSON string internal data (not modified)
* @param[in] len The pointed data array length in bytes
* @param[in] resourcePath the path will be used to search for external resource.
*
* @return Animation object that can render the contents of the
* Lottie resource represented by JSON string data.
*
* @internal
*/
static std::unique_ptr<Animation>
loadFromROData(const char * data, const size_t len, const char * resourcePath);

/**
* @brief Constructs an animation object from JSON string data and update.
* the color properties using ColorFilter.
Expand Down Expand Up @@ -421,6 +436,18 @@ class RLOTTIE_API Animation {
*/
void renderSync(size_t frameNo, Surface surface, bool keepAspectRatio=true);

/**
* @brief Renders the content to partial surface synchronously.
* for performance use the async rendering @see render
*
* @param[in] frameNo Content corresponds to the @p frameNo needs to be drawn
* @param[in] surface Surface in which content will be drawn
*
* @internal
*/
void renderPartialSync(size_t frameNo, Surface surface);


/**
* @brief Returns root layer of the composition updated with
* content of the Lottie resource at frame number @p frameNo.
Expand Down
34 changes: 34 additions & 0 deletions inc/rlottie_capi.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ RLOTTIE_API Lottie_Animation *lottie_animation_from_file(const char *path);
*/
RLOTTIE_API Lottie_Animation *lottie_animation_from_data(const char *data, const char *key, const char *resource_path);

/**
* @brief Constructs an animation object from JSON string data.
*
* @param[in] data The JSON string data.
* @param[in] len The data length in bytes
* @param[in] resource_path the path that will be used to load external resource needed by the JSON data.
*
* @return Animation object that can build the contents of the
* Lottie resource represented by JSON string data.
*
* @ingroup Lottie_Animation
* @internal
*/
RLOTTIE_API Lottie_Animation *lottie_animation_from_rodata(const char *data, const size_t len, const char *resourcePath);

/**
* @brief Free given Animation object resource.
*
Expand Down Expand Up @@ -231,6 +246,25 @@ RLOTTIE_API size_t lottie_animation_get_frame_at_pos(const Lottie_Animation *ani
*/
RLOTTIE_API void lottie_animation_render(Lottie_Animation *animation, size_t frame_num, uint32_t *buffer, size_t width, size_t height, size_t bytes_per_line);

/**
* @brief Request to render the content of the frame @p frame_num to buffer @p buffer.
*
* @param[in] animation Animation object.
* @param[in] frame_num the frame number needs to be rendered.
* @param[in] buffer surface buffer use for rendering.
* @param[in] width width of the surface
* @param[in] height height of the surface
* @param[in] top offset to render from
* @param[in] bottom offset to render from
* @param[in] bytes_per_line stride of the surface in bytes.
*
*
* @ingroup Lottie_Animation
* @internal
*/
RLOTTIE_API void lottie_animation_render_partial(Lottie_Animation *animation, size_t frame_num, uint32_t *buffer, size_t width, size_t height, size_t top, size_t bottom, size_t bytes_per_line);


/**
* @brief Request to render the content of the frame @p frame_num to buffer @p buffer asynchronously.
*
Expand Down
18 changes: 18 additions & 0 deletions inc/rlottiecommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@
#endif
#endif

#if defined LOTTIE_JSON_SUPPORT
#define RLOTTIE_FEATURE_RO_JSON 1
#else
#define RLOTTIE_FEATURE_RO_JSON 0
#endif

#if defined LOTTIE_THREAD_SUPPORT
#define RLOTTIE_FEATURE_THREAD 1
#else
#define RLOTTIE_FEATURE_THREAD 0
#endif

#if defined LOTTIE_NO_PARTIAL_RENDER
#define RLOTTIE_FEATURE_PARTIAL_RENDER 0
#else
#define RLOTTIE_FEATURE_PARTIAL_RENDER 1
#endif


/**
* @defgroup Lottie_Animation Lottie_Animation
Expand Down
8 changes: 8 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ if get_option('dumptree') == true
config_h.set10('LOTTIE_DUMP_TREE_SUPPORT', true)
endif

if get_option('json') == true
config_h.set10('LOTTIE_JSON_SUPPORT', true)
endif

if get_option('memshrink') == true
config_h.set10('LOTTIE_MEMSHRINK_SUPPORT', true)
endif


configure_file(
output: 'config.h',
Expand Down
9 changes: 8 additions & 1 deletion meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,12 @@ option('cmake',
value: false,
description: 'Enable Generating CMake config files')

option('json',
type: 'boolean',
value: false,
description: 'Use readonly JSON parser instead of RapidJSON')


option('memshrink',
type: 'boolean',
value: false,
description: 'Minimize memory usage but increase parsing time')
29 changes: 29 additions & 0 deletions src/binding/c/lottieanimation_capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ RLOTTIE_API Lottie_Animation_S *lottie_animation_from_data(const char *data, con
}
}

RLOTTIE_API Lottie_Animation_S *lottie_animation_from_rodata(const char *data, const size_t len, const char *resourcePath)
{
if (auto animation = Animation::loadFromROData(data, len, resourcePath) ) {
Lottie_Animation_S *handle = new Lottie_Animation_S();
handle->mAnimation = std::move(animation);
return handle;
}
return nullptr;
}


RLOTTIE_API void lottie_animation_destroy(Lottie_Animation_S *animation)
{
if (animation) {
Expand Down Expand Up @@ -168,6 +179,24 @@ lottie_animation_render(Lottie_Animation_S *animation,
animation->mAnimation->renderSync(frame_number, surface);
}

RLOTTIE_API void
lottie_animation_render_partial(Lottie_Animation_S *animation,
size_t frame_number,
uint32_t *buffer,
size_t width,
size_t height,
size_t top,
size_t bottom,
size_t bytes_per_line)
{
if (!animation) return;

rlottie::Surface surface(buffer, width, height, bytes_per_line);
surface.setDrawRegion(0, top, width, bottom - top);
animation->mAnimation->renderPartialSync(frame_number, surface);
}


RLOTTIE_API void
lottie_animation_render_async(Lottie_Animation_S *animation,
size_t frame_number,
Expand Down
Loading