2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 #include "lottieview.h"
31 static Eina_Bool onTestDone(void *data);
33 * To check the frame rate with rendermode off run
34 * ECORE_EVAS_FPS_DEBUG=1 ./lottieviewTest --disable-render
36 * To check the frame rate with render backend
37 * ECORE_EVAS_FPS_DEBUG=1 ./lottieviewTest
44 LottieViewTest(EvasApp *app, Strategy st, double timeout) {
45 mStartTime = std::chrono::high_resolution_clock::now();
50 ecore_timer_add(timeout, onTestDone, mApp);
52 // work around for 60fps
53 ecore_animator_frametime_set(1.0f/120.0f);
56 void show(int numberOfImage) {
57 auto resource = EvasApp::jsonFiles(std::string(DEMO_DIR));
59 if (resource.empty()) return;
61 int count = numberOfImage;
62 int colums = (int) ceil(sqrt(count));
64 int vw = (mApp->width() - (offset * colums))/colums;
68 int resourceSize = resource.size();
69 for (int i = 0 ; i < numberOfImage; i++) {
70 int index = i % resourceSize;
71 std::unique_ptr<LottieView> view(new LottieView(mApp->evas(), mStrategy));
72 view->setFilePath(resource[index].c_str());
73 view->setPos(posx, posy);
74 view->setSize(vw, vh);
78 //view->setRepeatMode(LottieView::RepeatMode::Reverse);
80 if ((mApp->width() - posx) < vw) {
82 posy = posy + vh + offset;
84 mViews.push_back(std::move(view));
89 const auto frames = mViews.empty() ? 0 : mViews[0]->renderCount();
90 const double secs = std::chrono::duration<double>(std::chrono::high_resolution_clock::now() - mStartTime).count();
91 std::cout<<"\tTestTime : "<< secs<<" sec \n\tTotalFrames : "<<frames<<"\n\tFramesPerSecond : "<< frames / secs <<" fps\n";
95 printf("Usage ./lottieviewTest [-s] [strategy] [-t] [timeout] [-c] [count]\n");
96 printf("\n \t-t : timeout duration in seconds\n");
97 printf("\n \t-c : number of resource in the grid\n");
98 printf("\n \t-s : Rendering Strategy\n");
99 printf("\t\t 0 - Test Lottie SYNC Renderer with CPP API\n");
100 printf("\t\t 1 - Test Lottie ASYNC Renderer with CPP API\n");
101 printf("\t\t 2 - Test Lottie SYNC Renderer with C API\n");
102 printf("\t\t 3 - Test Lottie ASYNC Renderer with C API\n");
103 printf("\t\t 4 - Test Lottie Tree Api using Efl VG Render\n");
104 printf(" Default : ./lottieviewTest -s 1 \n");
110 std::vector<std::unique_ptr<LottieView>> mViews;
111 std::chrono::high_resolution_clock::time_point mStartTime;
115 onExitCb(void *data, void */*extra*/)
117 LottieViewTest *view = (LottieViewTest *)data;
123 onTestDone(void *data)
125 EvasApp *app = (EvasApp *)data;
127 return ECORE_CALLBACK_CANCEL;
131 main(int argc, char **argv)
133 Strategy st = Strategy::renderCppAsync;
136 size_t itemCount = 250;
137 while (index < argc) {
138 const char* option = argv[index];
140 if (!strcmp(option,"--help") || !strcmp(option,"-h")) {
141 return LottieViewTest::help();
142 } else if (!strcmp(option,"-s")) {
143 st = (index < argc) ? static_cast<Strategy>(atoi(argv[index])) : Strategy::renderCppAsync;
145 } else if (!strcmp(option,"-t")) {
146 timeOut = (index < argc) ? atoi(argv[index]) : 10;
148 } else if (!strcmp(option,"-c")) {
149 itemCount = (index < argc) ? atoi(argv[index]) : 10;
154 EvasApp *app = new EvasApp(800, 800);
157 LottieViewTest *view = new LottieViewTest(app, st, timeOut);
158 view->show(itemCount);
160 app->addExitCb(onExitCb, view);