lottie: improve the compatiblity

merge the scene with more accurate condition to allow
the evenodd pathes among the lottie render tree.
This commit is contained in:
Hermet Park 2025-03-27 13:11:57 +09:00 committed by Hermet Park
parent e5d55d0651
commit 93cb33fb8e
4 changed files with 20 additions and 16 deletions

View file

@ -150,12 +150,8 @@ void LottieBuilder::updateTransform(LottieLayer* layer, float frameNo)
_updateTransform(transform, frameNo, matrix, layer->cache.opacity, layer->autoOrient, tween, exps);
if (parent) {
if (!tvg::identity((const Matrix*) &parent->cache.matrix)) {
if (tvg::identity((const Matrix*) &matrix)) layer->cache.matrix = parent->cache.matrix;
else layer->cache.matrix = parent->cache.matrix * matrix;
}
}
if (parent) layer->cache.matrix = parent->cache.matrix * matrix;
layer->cache.frameNo = frameNo;
}
@ -165,25 +161,30 @@ void LottieBuilder::updateTransform(LottieGroup* parent, LottieObject** child, f
auto transform = static_cast<LottieTransform*>(*child);
if (!transform) return;
Matrix m;
uint8_t opacity;
if (parent->mergeable()) {
if (!ctx->transform) ctx->transform = tvg::malloc<Matrix*>(sizeof(Matrix));
_updateTransform(transform, frameNo, *ctx->transform, opacity, false, tween, exps);
if (ctx->transform) {
_updateTransform(transform, frameNo, m, opacity, false, tween, exps);
*ctx->transform *= m;
} else {
ctx->transform = new Matrix;
_updateTransform(transform, frameNo, *ctx->transform, opacity, false, tween, exps);
}
return;
}
ctx->merging = nullptr;
Matrix matrix;
if (!_updateTransform(transform, frameNo, matrix, opacity, false, tween, exps)) return;
if (!_updateTransform(transform, frameNo, m, opacity, false, tween, exps)) return;
ctx->propagator->transform(ctx->propagator->transform() * matrix);
ctx->propagator->transform(ctx->propagator->transform() * m);
ctx->propagator->opacity(MULTIPLY(opacity, PAINT(ctx->propagator)->opacity));
//FIXME: preserve the stroke width. too workaround, need a better design.
if (SHAPE(ctx->propagator)->rs.strokeWidth() > 0.0f) {
auto denominator = sqrtf(matrix.e11 * matrix.e11 + matrix.e12 * matrix.e12);
auto denominator = sqrtf(m.e11 * m.e11 + m.e12 * m.e12);
if (denominator > 1.0f) ctx->propagator->strokeWidth(ctx->propagator->strokeWidth() / denominator);
}
}

View file

@ -73,7 +73,7 @@ struct RenderContext
~RenderContext()
{
propagator->unref(false);
tvg::free(transform);
delete(transform);
delete(roundness);
delete(offset);
}
@ -92,6 +92,10 @@ struct RenderContext
offset = new LottieOffsetModifier(rhs.offset->offset, rhs.offset->miterLimit, rhs.offset->join);
update(offset);
}
if (rhs.transform) {
transform = new Matrix;
*transform = *rhs.transform;
}
}
void update(LottieModifier* next)

View file

@ -551,7 +551,7 @@ void LottieGroup::prepare(LottieObject::Type type)
/* Figure out if this group is a simple path drawing.
In that case, the rendering context can be sharable with the parent's. */
if (allowMerge && (child->type == LottieObject::Group || !child->mergeable())) allowMerge = false;
if (allowMerge && !child->mergeable()) allowMerge = false;
//Figure out this group has visible contents
switch (child->type) {

View file

@ -569,8 +569,7 @@ struct LottieTransform : LottieObject
bool mergeable() override
{
if (!opacity.frames && opacity.value == 255) return true;
return false;
return true;
}
LottieProperty* property(uint16_t ix) override