lottie/player: make sure model or composition available before calling api.

Change-Id: Ia1351bbd076d0e3189d033f708bd3ec281c30cd4
This commit is contained in:
subhransu mohanty 2018-08-09 09:52:20 +09:00
parent d424320bd4
commit de6d53632b

View File

@ -11,7 +11,7 @@ public:
LOTPlayerPrivate(); LOTPlayerPrivate();
bool setFilePath(std::string path); bool setFilePath(std::string path);
void setSize(const VSize &sz); void setSize(const VSize &sz);
void size(int &w, int &h) const; VSize size() const;
float playTime() const; float playTime() const;
bool setPos(float pos); bool setPos(float pos);
float pos(); float pos();
@ -31,31 +31,28 @@ private:
void LOTPlayerPrivate::setSize(const VSize &sz) void LOTPlayerPrivate::setSize(const VSize &sz)
{ {
if (!mCompItem.get()) { mSize = sz;
vWarning << "Set file first!"; if (!mCompItem) {
return; return;
} }
mCompItem->resize(sz); mCompItem->resize(sz);
} }
void LOTPlayerPrivate::size(int &w, int &h) const VSize LOTPlayerPrivate::size() const
{ {
if (!mCompItem.get()) { if (!mCompItem) {
w = 0; return mSize;
h = 0; } else {
return; return mCompItem->size();
} }
VSize size = mCompItem->size();
w = size.width();
h = size.height();
} }
const std::vector<LOTNode *> &LOTPlayerPrivate::renderList() const const std::vector<LOTNode *> &LOTPlayerPrivate::renderList() const
{ {
if (!mCompItem.get()) { if (!mCompItem) {
// FIXME: Reference is not good... static std::vector<LOTNode *> empty;
return empty;
} }
return mCompItem->renderList(); return mCompItem->renderList();
@ -63,7 +60,7 @@ const std::vector<LOTNode *> &LOTPlayerPrivate::renderList() const
float LOTPlayerPrivate::playTime() const float LOTPlayerPrivate::playTime() const
{ {
if (mModel->isStatic()) return 0; if (!mModel || mModel->isStatic()) return 0;
return float(mModel->frameDuration()) / float(mModel->frameRate()); return float(mModel->frameDuration()) / float(mModel->frameRate());
} }
@ -88,6 +85,8 @@ float LOTPlayerPrivate::pos()
bool LOTPlayerPrivate::render(float pos, const LOTBuffer &buffer) bool LOTPlayerPrivate::render(float pos, const LOTBuffer &buffer)
{ {
if (!mCompItem) return false;
bool renderInProgress = mRenderInProgress.load(); bool renderInProgress = mRenderInProgress.load();
if (renderInProgress) if (renderInProgress)
vCritical << "Already Rendering Scheduled for this Player"; vCritical << "Already Rendering Scheduled for this Player";
@ -120,6 +119,8 @@ bool LOTPlayerPrivate::setFilePath(std::string path)
if (loader.load(path)) { if (loader.load(path)) {
mModel = loader.model(); mModel = loader.model();
mCompItem = std::make_unique<LOTCompItem>(mModel.get()); mCompItem = std::make_unique<LOTCompItem>(mModel.get());
if (!mSize.isEmpty())
setSize(mSize);
setPos(0); setPos(0);
return true; return true;
} }
@ -235,7 +236,10 @@ void LOTPlayer::setSize(int width, int height)
void LOTPlayer::size(int &width, int &height) const void LOTPlayer::size(int &width, int &height) const
{ {
d->size(width, height); VSize sz = d->size();
width = sz.width();
height = sz.height();
} }
float LOTPlayer::playTime() const float LOTPlayer::playTime() const