lottieviewtest.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. #include "evasapp.h"
  19. #include "lottieview.h"
  20. #include<iostream>
  21. #include <dirent.h>
  22. #include <stdio.h>
  23. using namespace std;
  24. /*
  25. * To check the frame rate with rendermode off run
  26. * ECORE_EVAS_FPS_DEBUG=1 ./lottieviewTest --disable-render
  27. *
  28. * To check the frame rate with render backend
  29. * ECORE_EVAS_FPS_DEBUG=1 ./lottieviewTest
  30. *
  31. */
  32. class LottieViewTest
  33. {
  34. public:
  35. LottieViewTest(EvasApp *app, Strategy st) {
  36. mStrategy = st;
  37. mApp = app;
  38. }
  39. void show(int numberOfImage) {
  40. auto resource = EvasApp::jsonFiles(std::string(DEMO_DIR));
  41. if (resource.empty()) return;
  42. int count = numberOfImage;
  43. int colums = (int) ceil(sqrt(count));
  44. int offset = 3;
  45. int vw = (mApp->width() - (offset * colums))/colums;
  46. int vh = vw;
  47. int posx = offset;
  48. int posy = offset;
  49. int resourceSize = resource.size();
  50. for (int i = 0 ; i < numberOfImage; i++) {
  51. int index = i % resourceSize;
  52. std::unique_ptr<LottieView> view(new LottieView(mApp->evas(), mStrategy));
  53. view->setFilePath(resource[index].c_str());
  54. view->setPos(posx, posy);
  55. view->setSize(vw, vh);
  56. view->show();
  57. view->play();
  58. view->loop(true);
  59. //view->setRepeatMode(LottieView::RepeatMode::Reverse);
  60. posx += vw+offset;
  61. if ((mApp->width() - posx) < vw) {
  62. posx = offset;
  63. posy = posy + vh + offset;
  64. }
  65. mViews.push_back(std::move(view));
  66. }
  67. }
  68. public:
  69. EvasApp *mApp;
  70. Strategy mStrategy;
  71. std::vector<std::unique_ptr<LottieView>> mViews;
  72. };
  73. static void
  74. onExitCb(void *data, void */*extra*/)
  75. {
  76. LottieViewTest *view = (LottieViewTest *)data;
  77. delete view;
  78. }
  79. int
  80. main(int argc, char **argv)
  81. {
  82. if (argc > 1) {
  83. if (!strcmp(argv[1],"--help") || !strcmp(argv[1],"-h")) {
  84. printf("Usage ./lottieviewTest 1 \n");
  85. printf("\t 0 - Test Lottie SYNC Renderer with CPP API\n");
  86. printf("\t 1 - Test Lottie ASYNC Renderer with CPP API\n");
  87. printf("\t 2 - Test Lottie SYNC Renderer with C API\n");
  88. printf("\t 3 - Test Lottie ASYNC Renderer with C API\n");
  89. printf("\t 4 - Test Lottie Tree Api using Efl VG Render\n");
  90. printf("\t Default is ./lottieviewTest 1 \n");
  91. return 0;
  92. }
  93. } else {
  94. printf("Run ./lottieviewTest -h for more option\n");
  95. }
  96. EvasApp *app = new EvasApp(800, 800);
  97. app->setup();
  98. Strategy st = Strategy::renderCppAsync;
  99. if (argc > 1) {
  100. int option = atoi(argv[1]);
  101. st = static_cast<Strategy>(option);
  102. }
  103. LottieViewTest *view = new LottieViewTest(app, st);
  104. view->show(250);
  105. app->addExitCb(onExitCb, view);
  106. app->run();
  107. delete app;
  108. return 0;
  109. }