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

View file

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

View file

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