lottie: ++ scene composing optimization

retain reusable precomp clipper shapes during animation.
This commit is contained in:
Hermet Park 2024-07-11 00:06:30 +09:00
parent f7728a8b7a
commit 3adee7238c
3 changed files with 17 additions and 10 deletions

View file

@ -1000,18 +1000,21 @@ static void _updatePrecomp(LottieLayer* precomp, float frameNo, LottieExpression
if (!child->matteSrc) _updateLayer(precomp, child, frameNo, exps);
}
//clip the layer viewport
if (precomp->w > 0 && precomp->h > 0) {
auto clipper = Shape::gen().release();
clipper->appendRect(0, 0, static_cast<float>(precomp->w), static_cast<float>(precomp->h));
clipper->transform(precomp->cache.matrix);
//TODO: remove the intermediate scene....
auto cscene = Scene::gen();
cscene->composite(cast(clipper), CompositeMethod::ClipPath);
//TODO: remove the intermediate scene....
if (precomp->scene->composite(nullptr) != tvg::CompositeMethod::None) {
auto cscene = Scene::gen().release();
cscene->push(cast(precomp->scene));
precomp->scene = cscene.release();
precomp->scene = cscene;
}
//clip the layer viewport
if (!precomp->clipper) {
precomp->clipper = Shape::gen().release();
precomp->clipper->appendRect(0, 0, static_cast<float>(precomp->w), static_cast<float>(precomp->h));
PP(precomp->clipper)->ref();
}
precomp->clipper->transform(precomp->cache.matrix);
precomp->scene->composite(cast(precomp->clipper), CompositeMethod::ClipPath);
}

View file

@ -331,6 +331,8 @@ LottieLayer::~LottieLayer()
delete(*m);
}
if (clipper && PP(clipper)->unref() == 0) delete(clipper);
delete(transform);
free(name);
}

View file

@ -594,6 +594,8 @@ struct LottieLayer : LottieGroup
RGB24 color; //used by Solid layer
LottieLayer* matteTarget = nullptr;
tvg::Shape* clipper = nullptr;
float timeStretch = 1.0f;
float w = 0.0f, h = 0.0f;
float inFrame = 0.0f;