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); _updateTransform(transform, frameNo, matrix, layer->cache.opacity, layer->autoOrient, tween, exps);
if (parent) { if (parent) layer->cache.matrix = parent->cache.matrix * matrix;
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;
}
}
layer->cache.frameNo = frameNo; layer->cache.frameNo = frameNo;
} }
@ -165,25 +161,30 @@ void LottieBuilder::updateTransform(LottieGroup* parent, LottieObject** child, f
auto transform = static_cast<LottieTransform*>(*child); auto transform = static_cast<LottieTransform*>(*child);
if (!transform) return; if (!transform) return;
Matrix m;
uint8_t opacity; uint8_t opacity;
if (parent->mergeable()) { if (parent->mergeable()) {
if (!ctx->transform) ctx->transform = tvg::malloc<Matrix*>(sizeof(Matrix)); if (ctx->transform) {
_updateTransform(transform, frameNo, *ctx->transform, opacity, false, tween, exps); _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; return;
} }
ctx->merging = nullptr; ctx->merging = nullptr;
Matrix matrix; if (!_updateTransform(transform, frameNo, m, opacity, false, tween, exps)) return;
if (!_updateTransform(transform, frameNo, matrix, 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)); ctx->propagator->opacity(MULTIPLY(opacity, PAINT(ctx->propagator)->opacity));
//FIXME: preserve the stroke width. too workaround, need a better design. //FIXME: preserve the stroke width. too workaround, need a better design.
if (SHAPE(ctx->propagator)->rs.strokeWidth() > 0.0f) { 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); if (denominator > 1.0f) ctx->propagator->strokeWidth(ctx->propagator->strokeWidth() / denominator);
} }
} }

View file

@ -73,7 +73,7 @@ struct RenderContext
~RenderContext() ~RenderContext()
{ {
propagator->unref(false); propagator->unref(false);
tvg::free(transform); delete(transform);
delete(roundness); delete(roundness);
delete(offset); delete(offset);
} }
@ -92,6 +92,10 @@ struct RenderContext
offset = new LottieOffsetModifier(rhs.offset->offset, rhs.offset->miterLimit, rhs.offset->join); offset = new LottieOffsetModifier(rhs.offset->offset, rhs.offset->miterLimit, rhs.offset->join);
update(offset); update(offset);
} }
if (rhs.transform) {
transform = new Matrix;
*transform = *rhs.transform;
}
} }
void update(LottieModifier* next) 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. /* Figure out if this group is a simple path drawing.
In that case, the rendering context can be sharable with the parent's. */ 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 //Figure out this group has visible contents
switch (child->type) { switch (child->type) {

View file

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