From: subhransu mohanty Date: Tue, 4 Jun 2019 04:58:32 +0000 (+0900) Subject: rlottie/example: refactor to use evas_object_image_pixels_dirty_set() api X-Git-Tag: accepted/tizen/unified/20190620.071909~11 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=df5fe2c62c114a6143fa76f99e5ce38955a2e606;p=platform%2Fcore%2Fuifw%2Flottie-player.git rlottie/example: refactor to use evas_object_image_pixels_dirty_set() api --- diff --git a/example/demo.cpp b/example/demo.cpp index a61aef9..3509362 100644 --- a/example/demo.cpp +++ b/example/demo.cpp @@ -31,13 +31,6 @@ onExitCb(void *data, void */*extra*/) delete view; } -static void -onRenderPreCb(void *data, void */*extra*/) -{ - LottieView *view = (LottieView *)data; - view->render(); -} - int main(void) { @@ -69,7 +62,6 @@ main(void) view->setRepeatMode(LottieView::RepeatMode::Reverse); app->addExitCb(onExitCb, view); - app->addRenderPreCb(onRenderPreCb, view); app->run(); delete app; return 0; diff --git a/example/lottieview.cpp b/example/lottieview.cpp index 755b2e0..8659c16 100644 --- a/example/lottieview.cpp +++ b/example/lottieview.cpp @@ -20,6 +20,17 @@ using namespace rlottie; +static void +_image_update_cb(void *data, Evas_Object *obj EINA_UNUSED) +{ + RenderStrategy *info = (RenderStrategy *)data; + info->dataCb(); +} + +void RenderStrategy::addCallback(){ + evas_object_image_pixels_get_callback_set(_renderObject, _image_update_cb, this); +} + static Eina_Bool animator(void *data , double pos) { @@ -101,7 +112,7 @@ void LottieView::seek(float pos) mCurFrame = mRenderDelegate->frameAtPos(mPos); - mRenderDelegate->renderRequest(mCurFrame); + mRenderDelegate->render(mCurFrame); } float LottieView::getPos() @@ -109,11 +120,6 @@ float LottieView::getPos() return mPos; } -void LottieView::render() -{ - mRenderDelegate->renderFlush(); -} - void LottieView::setFilePath(const char *filePath) { mRenderDelegate->loadFromFile(filePath); diff --git a/example/lottieview.h b/example/lottieview.h index 0874e97..34c414f 100644 --- a/example/lottieview.h +++ b/example/lottieview.h @@ -42,7 +42,9 @@ public: virtual ~RenderStrategy() { evas_object_del(renderObject()); } - RenderStrategy(Evas_Object *obj):_renderObject(obj){} + RenderStrategy(Evas_Object *obj):_renderObject(obj){ + addCallback(); + } virtual rlottie::Animation *player() {return nullptr;} virtual void loadFromFile(const char *filePath) = 0; virtual void loadFromData(const std::string &jsonData, const std::string &key, const std::string &resourcePath) = 0; @@ -50,14 +52,28 @@ public: virtual double frameRate() = 0; virtual size_t frameAtPos(double pos) = 0; virtual double duration() = 0; - virtual void renderRequest(int frame) = 0; - virtual void renderFlush() {} + void render(int frame) { + _redraw = renderRequest(frame); + if (_redraw) + evas_object_image_pixels_dirty_set(renderObject(), EINA_TRUE); + } + void dataCb() { + if (_redraw) { + evas_object_image_data_set(renderObject(), buffer()); + } + _redraw = false; + } virtual void resize(int width, int height) = 0; virtual void setPos(int x, int y) {evas_object_move(renderObject(), x, y);} void show() {evas_object_show(_renderObject);} void hide() {evas_object_hide(_renderObject);} + void addCallback(); Evas_Object* renderObject() const {return _renderObject;} +protected: + virtual bool renderRequest(int) = 0; + virtual uint32_t* buffer() = 0; private: + bool _redraw{false}; Evas_Object *_renderObject; }; @@ -129,29 +145,34 @@ class RlottieRenderStrategy_CPP : public RlottieRenderStrategy { public: RlottieRenderStrategy_CPP(Evas *evas):RlottieRenderStrategy(evas) {} - void renderRequest(int frame) { + bool renderRequest(int frame) { int width , height; Evas_Object *image = renderObject(); evas_object_image_size_get(image, &width, &height); - auto buffer = (uint32_t *)evas_object_image_data_get(image, EINA_TRUE); + mBuffer = (uint32_t *)evas_object_image_data_get(image, EINA_TRUE); size_t bytesperline = evas_object_image_stride_get(image); - rlottie::Surface surface(buffer, width, height, bytesperline); + rlottie::Surface surface(mBuffer, width, height, bytesperline); mPlayer->renderSync(frame, surface); - evas_object_image_data_set(image, surface.buffer()); - evas_object_image_data_update_add(image, 0 , 0, surface.width(), surface.height()); + return true; + } + uint32_t* buffer() { + return mBuffer; } + +private: + uint32_t * mBuffer; }; -class RlottieRenderStrategy_CPP_ASYNC : public RlottieRenderStrategy_CPP { +class RlottieRenderStrategy_CPP_ASYNC : public RlottieRenderStrategy { public: - RlottieRenderStrategy_CPP_ASYNC(Evas *evas):RlottieRenderStrategy_CPP(evas) {} + RlottieRenderStrategy_CPP_ASYNC(Evas *evas):RlottieRenderStrategy(evas) {} ~RlottieRenderStrategy_CPP_ASYNC() { if (mRenderTask.valid()) mRenderTask.get(); } - void renderRequest(int frame) { - if (mRenderTask.valid()) return; - mDirty = true; + bool renderRequest(int frame) { + //addCallback(); + if (mRenderTask.valid()) return true; int width , height; Evas_Object *image = renderObject(); evas_object_image_size_get(image, &width, &height); @@ -159,23 +180,15 @@ public: size_t bytesperline = evas_object_image_stride_get(image); rlottie::Surface surface(buffer, width, height, bytesperline); mRenderTask = mPlayer->render(frame, surface); - // to force a redraw - evas_object_image_data_update_add(renderObject(), 0 , 0, surface.width(), surface.height()); + return true; } - void renderFlush() { - if (!mDirty) return; - - if (!mRenderTask.valid()) return; - + uint32_t* buffer() { auto surface = mRenderTask.get(); - evas_object_image_data_set(renderObject(), surface.buffer()); - evas_object_image_data_update_add(renderObject(), 0 , 0, surface.width(), surface.height()); - mDirty = false; + return surface.buffer(); } private: std::future mRenderTask; - bool mDirty{true}; }; @@ -219,18 +232,22 @@ public: return lottie_animation_get_duration(mPlayer); } - void renderRequest(int frame) { + bool renderRequest(int frame) { int width , height; Evas_Object *image = renderObject(); evas_object_image_size_get(image, &width, &height); - auto buffer = (uint32_t *)evas_object_image_data_get(image, EINA_TRUE); + mBuffer = (uint32_t *)evas_object_image_data_get(image, EINA_TRUE); size_t bytesperline = evas_object_image_stride_get(image); - lottie_animation_render_async(mPlayer, frame, buffer, width, height, bytesperline); - lottie_animation_render_flush(mPlayer); - evas_object_image_data_set(image, buffer); - evas_object_image_data_update_add(image, 0 , 0, width, height); + lottie_animation_render(mPlayer, frame, mBuffer, width, height, bytesperline); + return true; + } + + uint32_t* buffer() { + return mBuffer; } +private: + uint32_t * mBuffer; protected: Lottie_Animation *mPlayer; }; @@ -241,25 +258,23 @@ public: ~RlottieRenderStrategy_C_ASYNC() { if (mDirty) lottie_animation_render_flush(mPlayer); } - void renderRequest(int frame) { - if (mDirty) return; + bool renderRequest(int frame) { + if (mDirty) return true; mDirty = true; Evas_Object *image = renderObject(); evas_object_image_size_get(image, &mWidth, &mHeight); mBuffer = (uint32_t *)evas_object_image_data_get(image, EINA_TRUE); size_t bytesperline = evas_object_image_stride_get(image); lottie_animation_render_async(mPlayer, frame, mBuffer, mWidth, mHeight, bytesperline); - // to force a redraw - evas_object_image_data_update_add(renderObject(), 0 , 0, mWidth, mWidth); + return true; } - void renderFlush() { - if (!mDirty) return; - lottie_animation_render_flush(mPlayer); - evas_object_image_data_set(renderObject(), mBuffer); - evas_object_image_data_update_add(renderObject(), 0 , 0, mWidth, mHeight); - mDirty = false; + uint32_t* buffer() { + lottie_animation_render_flush(mPlayer); + mDirty =false; + return mBuffer; } + private: uint32_t * mBuffer; int mWidth; @@ -305,7 +320,6 @@ public: void play(); void pause(); void stop(); - void render(); void initializeBufferObject(Evas *evas); void setMinProgress(float progress) { @@ -357,7 +371,7 @@ public: std::unique_ptr mRenderDelegate; }; - +#include class EflVgRenderStrategy : public CppApiBase { int mW; int mH; @@ -370,9 +384,14 @@ public: evas_object_resize(renderObject(), width, height); } - void renderRequest(int frame) { + uint32_t *buffer() { + assert(false); + } + + bool renderRequest(int frame) { const LOTLayerNode *root = mPlayer->renderTree(frame, mW, mH); updateTree(root); + return false; } void updateTree(const LOTLayerNode * node) diff --git a/example/lottieviewer.cpp b/example/lottieviewer.cpp index 1439d4a..75921b1 100644 --- a/example/lottieviewer.cpp +++ b/example/lottieviewer.cpp @@ -124,13 +124,6 @@ _button_clicked_cb(void *data, Evas_Object */*obj*/, void */*event_info*/) _toggle_start_button(info); } -static void -_image_update_cb(void *data, Evas_Object *obj EINA_UNUSED) -{ - AppInfo *info = (AppInfo *)data; - info->view->render(); -} - Evas_Object * create_layout(Evas_Object *parent, const char *file) { @@ -157,7 +150,6 @@ create_layout(Evas_Object *parent, const char *file) //IMAGE from LOTTIEVIEW image = view->getImage(); evas_object_show(image); - evas_object_image_pixels_get_callback_set(image, _image_update_cb, info); elm_object_part_content_set(layout, "lottie", image); //SLIDER @@ -183,8 +175,6 @@ create_layout(Evas_Object *parent, const char *file) elm_object_part_text_set(layout, "text", buf); view->seek(0.0); - view->render(); - return layout; } diff --git a/example/lottieviewtest.cpp b/example/lottieviewtest.cpp index c7f8043..57cbc71 100644 --- a/example/lottieviewtest.cpp +++ b/example/lottieviewtest.cpp @@ -63,7 +63,6 @@ public: view->play(); view->loop(true); //view->setRepeatMode(LottieView::RepeatMode::Reverse); - posx += vw+offset; if ((mApp->width() - posx) < vw) { posx = offset; @@ -73,15 +72,6 @@ public: } } - void render() { - //auto clock = std::chrono::high_resolution_clock::now(); - for (auto &i : mViews) { - i->render(); - } - //double d = std::chrono::duration(std::chrono::high_resolution_clock::now()-clock).count(); - //printf("total time taken = %f\n", d); - } - public: EvasApp *mApp; Strategy mStrategy; @@ -95,13 +85,6 @@ 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) { @@ -132,7 +115,6 @@ main(int argc, char **argv) view->show(250); app->addExitCb(onExitCb, view); - app->addRenderPreCb(onRenderPreCb, view); app->run(); delete app; diff --git a/example/uxsampletest.cpp b/example/uxsampletest.cpp index 48871c5..6fcbae8 100644 --- a/example/uxsampletest.cpp +++ b/example/uxsampletest.cpp @@ -104,14 +104,6 @@ onKeyCb(void *data, void *extra) } static void -onRenderPreCb(void *data, void */*extra*/) -{ - UxSampleTest *view = (UxSampleTest *)data; - if (view->mView) - view->mView->render(); -} - -static void onResizeCb(void *data, void */*extra*/) { UxSampleTest *view = (UxSampleTest *)data; @@ -134,7 +126,6 @@ main(int argc, char **argv) app->addExitCb(onExitCb, view); app->addKeyCb(onKeyCb, view); - app->addRenderPreCb(onRenderPreCb, view); app->addResizeCb(onResizeCb, view); app->run();