From: subhransu mohanty Date: Tue, 4 Sep 2018 09:41:47 +0000 (+0900) Subject: lottie: added new loadfromdata() api in lottie player. X-Git-Tag: submit/tizen/20180917.042405~35 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F78%2F188378%2F1;p=platform%2Fcore%2Fuifw%2Flottie-player.git lottie: added new loadfromdata() api in lottie player. Change-Id: Iadc6e57953190bdb860415cb3a4d4d02a6ac3cf6 --- diff --git a/inc/lotplayer.h b/inc/lotplayer.h index 0aab90d..a225478 100644 --- a/inc/lotplayer.h +++ b/inc/lotplayer.h @@ -18,6 +18,8 @@ public: ~LOTPlayer(); LOTPlayer(); + bool loadFromData(const char *jsonData, const char *key); + bool setFilePath(const char *filePath); float playTime() const; diff --git a/src/lottie/lottieloader.cpp b/src/lottie/lottieloader.cpp index e819e3c..289876f 100644 --- a/src/lottie/lottieloader.cpp +++ b/src/lottie/lottieloader.cpp @@ -1,4 +1,4 @@ -#include "lottieloader.h" +#include "lottieloader.h" #include "lottieparser.h" #include @@ -14,7 +14,7 @@ public: return CACHE; } - std::shared_ptr find(std::string &key); + std::shared_ptr find(const std::string &key); void add(std::string &key, std::shared_ptr value); private: @@ -23,7 +23,7 @@ private: std::unordered_map> mHash; }; -std::shared_ptr LottieFileCache::find(std::string &key) +std::shared_ptr LottieFileCache::find(const std::string &key) { auto search = mHash.find(key); if (search != mHash.end()) { @@ -65,6 +65,21 @@ bool LottieLoader::load(std::string &path) return true; } +bool LottieLoader::loadFromData(const char *jsonData, const char *key) +{ + LottieFileCache &fileCache = LottieFileCache::get(); + std::string keyString(key); + + mModel = fileCache.find(std::string(keyString)); + if (mModel) return true; + + LottieParser parser(const_cast(jsonData)); + mModel = parser.model(); + fileCache.add(keyString, mModel); + + return true; +} + std::shared_ptr LottieLoader::model() { return mModel; diff --git a/src/lottie/lottieloader.h b/src/lottie/lottieloader.h index e87cd79..32ec5aa 100644 --- a/src/lottie/lottieloader.h +++ b/src/lottie/lottieloader.h @@ -9,6 +9,7 @@ class LottieLoader { public: bool load(std::string &filePath); + bool loadFromData(const char *jsonData, const char *key); std::shared_ptr model(); private: std::shared_ptr mModel; diff --git a/src/lottie/lottieplayer.cpp b/src/lottie/lottieplayer.cpp index 089e28a..551f56a 100644 --- a/src/lottie/lottieplayer.cpp +++ b/src/lottie/lottieplayer.cpp @@ -14,6 +14,8 @@ public: LOTPlayerPrivate(); bool update(float pos); bool setFilePath(std::string path); + bool loadFromData(const char *jsonData, + const char *key); void setSize(const VSize &sz); void setPos(float pos); VSize size() const; @@ -151,6 +153,22 @@ bool LOTPlayerPrivate::setFilePath(std::string path) return false; } +bool LOTPlayerPrivate::loadFromData(const char *jsonData, const char *key) +{ + if (!jsonData) { + vWarning << "jason data is empty"; + return false; + } + + LottieLoader loader; + if (loader.loadFromData(jsonData, key)) { + mModel = loader.model(); + mCompItem = std::make_unique(mModel.get()); + return true; + } + return false; +} + /* * Implement a task stealing schduler to perform render task * As each player draws into its own buffer we can delegate this @@ -250,6 +268,11 @@ LOTPlayer::~LOTPlayer() * @param path add the details */ +bool LOTPlayer::loadFromData(const char *jsonData, const char *key) +{ + return d->loadFromData(jsonData, key); +} + bool LOTPlayer::setFilePath(const char *filePath) { return d->setFilePath(filePath);