mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-13 19:44:28 +00:00
lottie: minor optimization.
remove an unnecessary scene in the lottie render tree.
This commit is contained in:
parent
816afc6a27
commit
025104b64d
4 changed files with 13 additions and 26 deletions
|
@ -1136,19 +1136,10 @@ bool LottieBuilder::update(LottieComposition* comp, float frameNo)
|
|||
if (frameNo < comp->startFrame) frameNo = comp->startFrame;
|
||||
if (frameNo >= comp->endFrame) frameNo = (comp->endFrame - 1);
|
||||
|
||||
//Update root layer
|
||||
auto root = comp->root;
|
||||
|
||||
//Prepare render data
|
||||
if (!root->scene) {
|
||||
auto scene = Scene::gen();
|
||||
root->scene = scene.get();
|
||||
comp->scene->push(std::move(scene));
|
||||
} else {
|
||||
root->scene->clear();
|
||||
}
|
||||
|
||||
//update children layers
|
||||
auto root = comp->root;
|
||||
root->scene->clear();
|
||||
|
||||
for (auto child = root->children.end() - 1; child >= root->children.data; --child) {
|
||||
_updateLayer(root, static_cast<LottieLayer*>(*child), frameNo);
|
||||
}
|
||||
|
@ -1158,10 +1149,10 @@ bool LottieBuilder::update(LottieComposition* comp, float frameNo)
|
|||
|
||||
void LottieBuilder::build(LottieComposition* comp)
|
||||
{
|
||||
if (!comp || !comp->root || comp->scene) return;
|
||||
if (!comp) return;
|
||||
|
||||
comp->scene = Scene::gen().release();
|
||||
if (!comp->scene) return;
|
||||
comp->root->scene = Scene::gen().release();
|
||||
if (!comp->root->scene) return;
|
||||
|
||||
_buildComposition(comp, comp->root);
|
||||
|
||||
|
@ -1170,5 +1161,5 @@ void LottieBuilder::build(LottieComposition* comp)
|
|||
//viewport clip
|
||||
auto clip = Shape::gen();
|
||||
clip->appendRect(0, 0, static_cast<float>(comp->w), static_cast<float>(comp->h));
|
||||
comp->scene->composite(std::move(clip), CompositeMethod::ClipPath);
|
||||
comp->root->scene->composite(std::move(clip), CompositeMethod::ClipPath);
|
||||
}
|
||||
|
|
|
@ -50,15 +50,13 @@ static float _str2float(const char* str, int len)
|
|||
void LottieLoader::run(unsigned tid)
|
||||
{
|
||||
//update frame
|
||||
if (comp && comp->scene) {
|
||||
if (comp) {
|
||||
builder->update(comp, frameNo);
|
||||
//initial loading
|
||||
} else {
|
||||
if (!comp) {
|
||||
LottieParser parser(content, dirName);
|
||||
if (!parser.parse()) return;
|
||||
comp = parser.comp;
|
||||
}
|
||||
LottieParser parser(content, dirName);
|
||||
if (!parser.parse()) return;
|
||||
comp = parser.comp;
|
||||
builder->build(comp);
|
||||
}
|
||||
}
|
||||
|
@ -294,7 +292,7 @@ Paint* LottieLoader::paint()
|
|||
this->done();
|
||||
if (!comp) return nullptr;
|
||||
comp->initiated = true;
|
||||
return comp->scene;
|
||||
return comp->root->scene;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -207,7 +207,7 @@ float LottieLayer::remap(float frameNo)
|
|||
|
||||
LottieComposition::~LottieComposition()
|
||||
{
|
||||
if (!initiated) delete(scene);
|
||||
if (!initiated) delete(root->scene);
|
||||
|
||||
delete(root);
|
||||
free(version);
|
||||
|
|
|
@ -609,8 +609,6 @@ struct LottieComposition
|
|||
return endFrame - startFrame;
|
||||
}
|
||||
|
||||
Scene* scene = nullptr; //tvg render data
|
||||
|
||||
LottieLayer* root = nullptr;
|
||||
char* version = nullptr;
|
||||
char* name = nullptr;
|
||||
|
|
Loading…
Add table
Reference in a new issue