lottie: minor optimization.

remove an unnecessary scene in the lottie render tree.
This commit is contained in:
Hermet Park 2024-02-02 01:03:52 +09:00
parent 816afc6a27
commit 025104b64d
4 changed files with 13 additions and 26 deletions

View file

@ -1136,19 +1136,10 @@ bool LottieBuilder::update(LottieComposition* comp, float frameNo)
if (frameNo < comp->startFrame) frameNo = comp->startFrame; if (frameNo < comp->startFrame) frameNo = comp->startFrame;
if (frameNo >= comp->endFrame) frameNo = (comp->endFrame - 1); 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 //update children layers
auto root = comp->root;
root->scene->clear();
for (auto child = root->children.end() - 1; child >= root->children.data; --child) { for (auto child = root->children.end() - 1; child >= root->children.data; --child) {
_updateLayer(root, static_cast<LottieLayer*>(*child), frameNo); _updateLayer(root, static_cast<LottieLayer*>(*child), frameNo);
} }
@ -1158,10 +1149,10 @@ bool LottieBuilder::update(LottieComposition* comp, float frameNo)
void LottieBuilder::build(LottieComposition* comp) void LottieBuilder::build(LottieComposition* comp)
{ {
if (!comp || !comp->root || comp->scene) return; if (!comp) return;
comp->scene = Scene::gen().release(); comp->root->scene = Scene::gen().release();
if (!comp->scene) return; if (!comp->root->scene) return;
_buildComposition(comp, comp->root); _buildComposition(comp, comp->root);
@ -1170,5 +1161,5 @@ void LottieBuilder::build(LottieComposition* comp)
//viewport clip //viewport clip
auto clip = Shape::gen(); auto clip = Shape::gen();
clip->appendRect(0, 0, static_cast<float>(comp->w), static_cast<float>(comp->h)); 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);
} }

View file

@ -50,15 +50,13 @@ static float _str2float(const char* str, int len)
void LottieLoader::run(unsigned tid) void LottieLoader::run(unsigned tid)
{ {
//update frame //update frame
if (comp && comp->scene) { if (comp) {
builder->update(comp, frameNo); builder->update(comp, frameNo);
//initial loading //initial loading
} else { } else {
if (!comp) { LottieParser parser(content, dirName);
LottieParser parser(content, dirName); if (!parser.parse()) return;
if (!parser.parse()) return; comp = parser.comp;
comp = parser.comp;
}
builder->build(comp); builder->build(comp);
} }
} }
@ -294,7 +292,7 @@ Paint* LottieLoader::paint()
this->done(); this->done();
if (!comp) return nullptr; if (!comp) return nullptr;
comp->initiated = true; comp->initiated = true;
return comp->scene; return comp->root->scene;
} }

View file

@ -207,7 +207,7 @@ float LottieLayer::remap(float frameNo)
LottieComposition::~LottieComposition() LottieComposition::~LottieComposition()
{ {
if (!initiated) delete(scene); if (!initiated) delete(root->scene);
delete(root); delete(root);
free(version); free(version);

View file

@ -609,8 +609,6 @@ struct LottieComposition
return endFrame - startFrame; return endFrame - startFrame;
} }
Scene* scene = nullptr; //tvg render data
LottieLayer* root = nullptr; LottieLayer* root = nullptr;
char* version = nullptr; char* version = nullptr;
char* name = nullptr; char* name = nullptr;