added lottie2gif converter for both cmake and meson build
[platform/core/uifw/lottie-player.git] / example / lottieviewtest.cpp
1 /* 
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
3  * 
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  * 
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  * 
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18
19 #include "evasapp.h"
20 #include "lottieview.h"
21 #include<iostream>
22 #include <dirent.h>
23 #include <stdio.h>
24 using namespace std;
25
26 /*
27  * To check the frame rate with rendermode off run
28  * ECORE_EVAS_FPS_DEBUG=1 ./lottieviewTest --disable-render
29  *
30  * To check the frame rate with  render backend
31  * ECORE_EVAS_FPS_DEBUG=1 ./lottieviewTest
32  *
33  */
34
35 class LottieViewTest
36 {
37 public:
38   LottieViewTest(EvasApp *app, Strategy st) {
39       mStrategy = st;
40       mApp = app;
41   }
42
43   void show(int numberOfImage) {
44     auto resource = EvasApp::jsonFiles(std::string(DEMO_DIR));
45
46     if (resource.empty()) return;
47
48     int count = numberOfImage;
49     int colums = (int) ceil(sqrt(count));
50     int offset = 3;
51     int vw = (mApp->width() - (offset * colums))/colums;
52     int vh = vw;
53     int posx = offset;
54     int posy = offset;
55     int resourceSize = resource.size();
56     for (int i = 0 ; i < numberOfImage; i++) {
57         int index = i % resourceSize;
58         std::unique_ptr<LottieView> view(new LottieView(mApp->evas(), mStrategy));
59         view->setFilePath(resource[index].c_str());
60         view->setPos(posx, posy);
61         view->setSize(vw, vh);
62         view->show();
63         view->play();
64         view->loop(true);
65         //view->setRepeatMode(LottieView::RepeatMode::Reverse);
66
67         posx += vw+offset;
68         if ((mApp->width() - posx) < vw) {
69           posx = offset;
70           posy = posy + vh + offset;
71         }
72         mViews.push_back(std::move(view));
73     }
74   }
75
76   void render() {
77       //auto clock = std::chrono::high_resolution_clock::now();
78       for (auto &i : mViews) {
79           i->render();
80       }
81       //double d = std::chrono::duration<double, std::milli>(std::chrono::high_resolution_clock::now()-clock).count();
82       //printf("total time taken = %f\n", d);
83   }
84
85 public:
86   EvasApp     *mApp;
87   Strategy     mStrategy;
88   std::vector<std::unique_ptr<LottieView>>   mViews;
89 };
90
91 static void
92 onExitCb(void *data, void *extra)
93 {
94     LottieViewTest *view = (LottieViewTest *)data;
95     delete view;
96 }
97
98 static void
99 onRenderPreCb(void *data, void *extra)
100 {
101     LottieViewTest *view = (LottieViewTest *)data;
102     view->render();
103 }
104
105 int
106 main(int argc, char **argv)
107 {
108     if (argc > 1) {
109         if (!strcmp(argv[1],"--help") || !strcmp(argv[1],"-h")) {
110             printf("Usage ./lottieviewTest 1 \n");
111             printf("\t 0  - Test Lottie SYNC Renderer with CPP API\n");
112             printf("\t 1  - Test Lottie ASYNC Renderer with CPP API\n");
113             printf("\t 2  - Test Lottie SYNC Renderer with C API\n");
114             printf("\t 3  - Test Lottie ASYNC Renderer with C API\n");
115             printf("\t 4  - Test Lottie Tree Api using Efl VG Render\n");
116             printf("\t Default is ./lottieviewTest 1 \n");
117             return 0;
118         }
119     } else {
120         printf("Run ./lottieviewTest -h  for more option\n");
121     }
122
123    EvasApp *app = new EvasApp(800, 800);
124    app->setup();
125
126    Strategy st = Strategy::renderCppAsync;
127    if (argc > 1) {
128        int option = atoi(argv[1]);
129        st = static_cast<Strategy>(option);
130    }
131    LottieViewTest *view = new LottieViewTest(app, st);
132    view->show(150);
133
134    app->addExitCb(onExitCb, view);
135    app->addRenderPreCb(onRenderPreCb, view);
136
137    app->run();
138    delete app;
139    return 0;
140 }
141
142
143
144
145