From 1fb9f25baba3e93a15c969b796839d70396cfb57 Mon Sep 17 00:00:00 2001 From: Subhransu Mohanty Date: Tue, 11 Aug 2020 15:29:36 +0900 Subject: [PATCH] example: update test example with fps info --- example/evasapp.cpp | 4 +++ example/evasapp.h | 1 + example/lottieview.h | 7 ++++ example/lottieviewtest.cpp | 74 +++++++++++++++++++++++++++----------- 4 files changed, 65 insertions(+), 21 deletions(-) diff --git a/example/evasapp.cpp b/example/evasapp.cpp index 64fabb5..61725af 100644 --- a/example/evasapp.cpp +++ b/example/evasapp.cpp @@ -74,6 +74,10 @@ on_post_render(Ecore_Evas *ee) app->mRenderPostCb(app->mRenderPostData, nullptr); } +void EvasApp::exit() +{ + _on_delete(mEcoreEvas); +} EvasApp::EvasApp(int w, int h) { if (!ecore_evas_init()) diff --git a/example/evasapp.h b/example/evasapp.h index 934eb3b..e1fdb18 100644 --- a/example/evasapp.h +++ b/example/evasapp.h @@ -58,6 +58,7 @@ public: void addKeyCb(appCb keycb, void *data) {mKeyCb = keycb; mKeyData = data;} void addRenderPreCb(appCb renderPrecb, void *data) {mRenderPreCb = renderPrecb; mRenderPreData = data;} void addRenderPostCb(appCb renderPostcb, void *data) {mRenderPostCb = renderPostcb; mRenderPostData = data;} + void exit(); static std::vector jsonFiles(const std::string &dir, bool recurse=false); public: int mw{0}; diff --git a/example/lottieview.h b/example/lottieview.h index 163d947..ca8de7e 100644 --- a/example/lottieview.h +++ b/example/lottieview.h @@ -58,6 +58,7 @@ public: virtual size_t frameAtPos(double pos) = 0; virtual double duration() = 0; void render(int frame) { + _renderCount++; _redraw = renderRequest(frame); if (_redraw && _useImage) evas_object_image_pixels_dirty_set(renderObject(), EINA_TRUE); @@ -76,10 +77,12 @@ public: void hide() {evas_object_hide(_renderObject);} void addCallback(); Evas_Object* renderObject() const {return _renderObject;} + size_t renderCount() const {return _renderCount;} protected: virtual bool renderRequest(int) = 0; virtual uint32_t* buffer() = 0; private: + size_t _renderCount{0}; bool _redraw{false}; Evas_Object *_renderObject; bool _useImage{true}; @@ -360,6 +363,10 @@ public: //clamp it to [0,1] mMaxprogress = progress; } + + size_t renderCount() const { + return mRenderDelegate ? mRenderDelegate->renderCount() : 0; + } private: float mapProgress(float progress) { //clamp it to the segment diff --git a/example/lottieviewtest.cpp b/example/lottieviewtest.cpp index 477bb92..296d606 100644 --- a/example/lottieviewtest.cpp +++ b/example/lottieviewtest.cpp @@ -25,8 +25,10 @@ #include #include #include +#include using namespace std; +static Eina_Bool onTestDone(void *data); /* * To check the frame rate with rendermode off run * ECORE_EVAS_FPS_DEBUG=1 ./lottieviewTest --disable-render @@ -39,9 +41,16 @@ using namespace std; class LottieViewTest { public: - LottieViewTest(EvasApp *app, Strategy st) { + LottieViewTest(EvasApp *app, Strategy st, double timeout) { + mStartTime = std::chrono::high_resolution_clock::now(); mStrategy = st; mApp = app; + + if (timeout > 0) { + ecore_timer_add(timeout, onTestDone, mApp); + } + // work around for 60fps + ecore_animator_frametime_set(1.0f/120.0f); } void show(int numberOfImage) { @@ -76,10 +85,28 @@ public: } } + ~LottieViewTest() { + const auto frames = mViews.empty() ? 0 : mViews[0]->renderCount(); + const double secs = std::chrono::duration(std::chrono::high_resolution_clock::now() - mStartTime).count(); + std::cout<<"TestTime : "<< secs<<" Sec, TotalFrames : "<> mViews; + std::chrono::high_resolution_clock::time_point mStartTime; }; static void @@ -89,34 +116,39 @@ onExitCb(void *data, void */*extra*/) delete view; } + +static Eina_Bool +onTestDone(void *data) +{ + EvasApp *app = (EvasApp *)data; + app->exit(); + return ECORE_CALLBACK_CANCEL; +} + int main(int argc, char **argv) { - if (argc > 1) { - if (!strcmp(argv[1],"--help") || !strcmp(argv[1],"-h")) { - printf("Usage ./lottieviewTest 1 \n"); - printf("\t 0 - Test Lottie SYNC Renderer with CPP API\n"); - printf("\t 1 - Test Lottie ASYNC Renderer with CPP API\n"); - printf("\t 2 - Test Lottie SYNC Renderer with C API\n"); - printf("\t 3 - Test Lottie ASYNC Renderer with C API\n"); - printf("\t 4 - Test Lottie Tree Api using Efl VG Render\n"); - printf("\t Default is ./lottieviewTest 1 \n"); - return 0; - } - } else { - printf("Run ./lottieviewTest -h for more option\n"); + Strategy st = Strategy::renderCppAsync; + auto index = 0; + double timeOut = 0; + while (index < argc) { + const char* option = argv[index]; + index++; + if (!strcmp(option,"--help") || !strcmp(option,"-h")) { + return LottieViewTest::help(); + } else if (!strcmp(option,"-s")) { + st = (index < argc) ? static_cast(atoi(argv[index])) : Strategy::renderCppAsync; + index++; + } else if (!strcmp(option,"-t")) { + timeOut = (index < argc) ? atoi(argv[index]) : 10; + index++; + } } - Strategy st = Strategy::renderCppAsync; - if (argc > 1) { - int option = atoi(argv[1]); - st = static_cast(option); - } - EvasApp *app = new EvasApp(800, 800); app->setup(); - LottieViewTest *view = new LottieViewTest(app, st); + LottieViewTest *view = new LottieViewTest(app, st, timeOut); view->show(250); app->addExitCb(onExitCb, view); -- 2.34.1