Put samsung copyright header to all our own source code.
[platform/core/uifw/lottie-player.git] / example / lottieviewtest.cpp
index 6c27f40..e0c5e2e 100644 (file)
@@ -1,3 +1,19 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 #include "evasapp.h"
 #include "lottieview.h"
 #include<iostream>
@@ -20,39 +36,49 @@ public:
   LottieViewTest(EvasApp *app, bool renderMode) {
       mApp = app;
       mRenderMode = renderMode;
+      ecore_animator_frametime_set(1.0/120.0);
   }
 
-  void show() {
+  void show(int numberOfImage) {
     auto resource = EvasApp::jsonFiles(std::string(DEMO_DIR));
 
     if (resource.empty()) return;
 
-    int count = resource.size();
+    int count = numberOfImage;
     int colums = (int) ceil(sqrt(count));
     int offset = 3;
-    int vw = (mApp->width() - (2 * offset * colums))/colums;
+    int vw = (mApp->width() - (offset * colums))/colums;
     int vh = vw;
     int posx = offset;
     int posy = offset;
-    for(auto filePath : resource) {
-
+    int resourceSize = resource.size();
+    for (int i = 0 ; i < numberOfImage; i++) {
+        int index = i % resourceSize;
         std::unique_ptr<LottieView> view(new LottieView(mApp->evas(), mRenderMode));
-       view->setFilePath(filePath.c_str());
-       view->setPos(posx, posy);
-       view->setSize(vw, vh);
-       view->show();
-       view->play();
-       view->loop(true);
-       //view->setRepeatMode(LottieView::RepeatMode::Reverse);
-
-       posx += vw+offset;
-       if ((mApp->width() - posx) < vw) {
+        view->setFilePath(resource[index].c_str());
+        view->setPos(posx, posy);
+        view->setSize(vw, vh);
+        view->show();
+        view->play();
+        view->loop(true);
+        //view->setRepeatMode(LottieView::RepeatMode::Reverse);
+
+        posx += vw+offset;
+        if ((mApp->width() - posx) < vw) {
           posx = offset;
           posy = posy + vh + offset;
-       }
-       mViews.push_back(std::move(view));
+        }
+        mViews.push_back(std::move(view));
     }
+  }
 
+  void render() {
+      //auto clock = std::chrono::high_resolution_clock::now();
+      for (auto &i : mViews) {
+          i->render();
+      }
+      //double d = std::chrono::duration<double, std::milli>(std::chrono::high_resolution_clock::now()-clock).count();
+      //printf("total time taken = %f\n", d);
   }
 
 public:
@@ -68,6 +94,13 @@ onExitCb(void *data, void *extra)
     delete view;
 }
 
+static void
+onRenderPreCb(void *data, void *extra)
+{
+    LottieViewTest *view = (LottieViewTest *)data;
+    view->render();
+}
+
 int
 main(int argc, char **argv)
 {
@@ -80,9 +113,10 @@ main(int argc, char **argv)
            renderMode = false;
    }
    LottieViewTest *view = new LottieViewTest(app, renderMode);
-   view->show();
+   view->show(250);
 
    app->addExitCb(onExitCb, view);
+   app->addRenderPreCb(onRenderPreCb, view);
 
    app->run();
    delete app;