loader/lottie: code refactoring.

migrate transform from the group to the layer.
transformation is not necessary in group but layer.

This helps to reduce the unnecessary assigning of the transformation
in group instances.
This commit is contained in:
Hermet Park 2023-09-18 22:46:06 +09:00
parent 549f4b1308
commit 2cada9c446
3 changed files with 12 additions and 20 deletions

View file

@ -177,10 +177,6 @@ static void _updateGroup(LottieGroup* parent, LottieGroup* group, int32_t frameN
{
//Prepare render data
group->scene = parent->scene;
auto opacity = group->opacity(frameNo);
if (opacity == 0) return;
auto ctx2 = ctx;
_updateChildren(group, frameNo, ctx2);
}

View file

@ -123,7 +123,6 @@ Fill* LottieGradient::fill(int32_t frameNo)
void LottieGroup::prepare(LottieObject::Type type)
{
LottieObject::type = type;
if (transform) statical &= transform->statical;
for (auto child = children.data; child < children.end(); ++child) {
statical &= (*child)->statical;
if (!statical) break;
@ -133,13 +132,16 @@ void LottieGroup::prepare(LottieObject::Type type)
void LottieLayer::prepare()
{
LottieGroup::prepare(LottieObject::Layer);
if (transform) statical &= transform->statical;
/* if layer is hidden, only useulf data is its transform matrix.
/* if layer is hidden, only useful data is its transform matrix.
so force it to be a Null Layer and release all resource. */
if (!hidden) return;
type = LottieLayer::Null;
children.reset();
if (hidden) {
type = LottieLayer::Null;
children.reset();
return;
}
LottieGroup::prepare(LottieObject::Layer);
}

View file

@ -386,20 +386,13 @@ struct LottieGroup : LottieObject
virtual ~LottieGroup()
{
for (auto p = children.data; p < children.end(); ++p) delete(*p);
delete(transform);
}
void prepare(LottieObject::Type type = LottieObject::Group);
virtual uint8_t opacity(int32_t frameNo)
{
return (transform ? transform->opacity(frameNo) : 255);
}
Scene* scene = nullptr; //tvg render data
Array<LottieObject*> children;
LottieTransform* transform = nullptr;
};
@ -420,14 +413,14 @@ struct LottieLayer : LottieGroup
}
delete(matte.target);
delete(transform);
}
uint8_t opacity(int32_t frameNo) override
uint8_t opacity(int32_t frameNo)
{
//return zero if the visibility is false.
if (frameNo < inFrame || frameNo > outFrame) return 0;
if (type == Null) return 255;
return LottieGroup::opacity(frameNo);
return transform->opacity(frameNo);
}
void prepare();
@ -445,6 +438,7 @@ struct LottieLayer : LottieGroup
LottieLayer* parent = nullptr;
LottieFloat timeRemap = 0.0f;
LottieComposition* comp = nullptr;
LottieTransform* transform = nullptr;
Array<LottieMask*> masks;
float timeStretch = 1.0f;