lottie: ++scene rendering optimization

Apply LottieRenderPooler to maskings.
This commit is contained in:
Hermet Park 2024-07-24 15:10:13 +09:00
parent 49f586b3e7
commit 9f5a83f067
3 changed files with 16 additions and 16 deletions

View file

@ -342,7 +342,7 @@ static void _updateGradientStroke(TVG_UNUSED LottieGroup* parent, LottieObject**
}
static void _updateSolidFill(TVG_UNUSED LottieGroup* parent, LottieObject** child, float frameNo, TVG_UNUSED Inlist<RenderContext>& contexts, RenderContext* ctx, LottieExpressions* exps)
static void _updateSolidFill(TVG_UNUSED LottieGroup* parent, LottieObject** child, float frameNo, Inlist<RenderContext>& contexts, RenderContext* ctx, LottieExpressions* exps)
{
if (_fragmented(child, contexts, ctx)) return;
@ -357,7 +357,7 @@ static void _updateSolidFill(TVG_UNUSED LottieGroup* parent, LottieObject** chil
}
static void _updateGradientFill(TVG_UNUSED LottieGroup* parent, LottieObject** child, float frameNo, TVG_UNUSED Inlist<RenderContext>& contexts, RenderContext* ctx, LottieExpressions* exps)
static void _updateGradientFill(TVG_UNUSED LottieGroup* parent, LottieObject** child, float frameNo, Inlist<RenderContext>& contexts, RenderContext* ctx, LottieExpressions* exps)
{
if (_fragmented(child, contexts, ctx)) return;
@ -1056,7 +1056,7 @@ static void _updatePrecomp(LottieComposition* comp, LottieLayer* precomp, float
}
//clip the layer viewport
auto clipper = precomp->pooling(true);
auto clipper = precomp->statical.pooling(true);
clipper->transform(precomp->cache.matrix);
precomp->scene->composite(cast(clipper), CompositeMethod::ClipPath);
}
@ -1064,7 +1064,7 @@ static void _updatePrecomp(LottieComposition* comp, LottieLayer* precomp, float
static void _updateSolid(LottieLayer* layer)
{
auto solidFill = layer->pooling(true);
auto solidFill = layer->statical.pooling(true);
solidFill->opacity(layer->cache.opacity);
layer->scene->push(cast(solidFill));
}
@ -1215,12 +1215,11 @@ static void _updateMaskings(LottieLayer* layer, float frameNo, LottieExpressions
auto pMask = static_cast<LottieMask*>(layer->masks[0]);
auto pMethod = pMask->method;
auto pShape = Shape::gen().release();
auto pShape = layer->pooling();
pShape->reset();
pShape->fill(255, 255, 255, pMask->opacity(frameNo));
pShape->transform(layer->cache.matrix);
if (pMask->pathset(frameNo, P(pShape)->rs.path.cmds, P(pShape)->rs.path.pts, nullptr, 0.0f, exps)) {
P(pShape)->update(RenderUpdateFlag::Path);
}
pMask->pathset(frameNo, P(pShape)->rs.path.cmds, P(pShape)->rs.path.pts, nullptr, 0.0f, exps);
if (pMethod == CompositeMethod::SubtractMask || pMethod == CompositeMethod::InvAlphaMask) {
layer->scene->composite(tvg::cast(pShape), CompositeMethod::InvAlphaMask);
@ -1239,12 +1238,11 @@ static void _updateMaskings(LottieLayer* layer, float frameNo, LottieExpressions
mask->pathset(frameNo, P(pShape)->rs.path.cmds, P(pShape)->rs.path.pts, nullptr, 0.0f, exps);
//Chain composition
} else {
auto shape = Shape::gen().release();
auto shape = layer->pooling();
shape->reset();
shape->fill(255, 255, 255, mask->opacity(frameNo));
shape->transform(layer->cache.matrix);
if (mask->pathset(frameNo, P(shape)->rs.path.cmds, P(shape)->rs.path.pts, nullptr, 0.0f, exps)) {
P(shape)->update(RenderUpdateFlag::Path);
}
mask->pathset(frameNo, P(shape)->rs.path.cmds, P(shape)->rs.path.pts, nullptr, 0.0f, exps);
pShape->composite(tvg::cast(shape), method);
pShape = shape;
pMethod = method;

View file

@ -400,14 +400,14 @@ void LottieLayer::prepare(RGB24* color)
auto clipper = Shape::gen().release();
clipper->appendRect(0.0f, 0.0f, w, h);
PP(clipper)->ref();
pooler.push(clipper);
statical.pooler.push(clipper);
//prepare solid fill in advance if it is a layer type.
} else if (color && type == LottieLayer::Solid) {
auto solidFill = Shape::gen().release();
solidFill->appendRect(0, 0, static_cast<float>(w), static_cast<float>(h));
solidFill->fill(color->rgb[0], color->rgb[1], color->rgb[2]);
PP(solidFill)->ref();
pooler.push(solidFill);
statical.pooler.push(solidFill);
}
LottieGroup::prepare(LottieObject::Layer);

View file

@ -659,7 +659,7 @@ struct LottieRepeater : LottieObject
};
struct LottieGroup : LottieObject
struct LottieGroup : LottieObject, LottieRenderPooler<tvg::Shape>
{
LottieGroup();
@ -696,7 +696,7 @@ struct LottieGroup : LottieObject
};
struct LottieLayer : LottieGroup, LottieRenderPooler<tvg::Shape>
struct LottieLayer : LottieGroup
{
enum Type : uint8_t {Precomp = 0, Solid, Image, Null, Shape, Text};
@ -722,6 +722,8 @@ struct LottieLayer : LottieGroup, LottieRenderPooler<tvg::Shape>
Array<LottieMask*> masks;
LottieLayer* matteTarget = nullptr;
LottieRenderPooler<tvg::Shape> statical; //static pooler for solid fill and clipper
float timeStretch = 1.0f;
float w = 0.0f, h = 0.0f;
float inFrame = 0.0f;