lottie: code refactoring.

removed unused static condition.

static was prepared for optimization,
but not used at all.

we will revisit this later when time permits.

binary size: -6kb
This commit is contained in:
Hermet Park 2024-03-27 21:01:16 +09:00
parent 7ec7a4c08c
commit 736a79674b
4 changed files with 4 additions and 33 deletions

View file

@ -1106,7 +1106,6 @@ static void _buildReference(LottieComposition* comp, LottieLayer* layer)
} else if (layer->type == LottieLayer::Image) { } else if (layer->type == LottieLayer::Image) {
layer->children.push(*asset); layer->children.push(*asset);
} }
layer->statical &= (*asset)->statical;
break; break;
} }
} }
@ -1173,15 +1172,11 @@ static bool _buildComposition(LottieComposition* comp, LottieGroup* parent)
_bulidHierarchy(parent, child->matte.target); _bulidHierarchy(parent, child->matte.target);
//precomp referencing //precomp referencing
if (child->matte.target->refId) _buildReference(comp, child->matte.target); if (child->matte.target->refId) _buildReference(comp, child->matte.target);
child->statical &= child->matte.target->statical;
} }
_bulidHierarchy(parent, child); _bulidHierarchy(parent, child);
//attach the necessary font data //attach the necessary font data
if (child->type == LottieLayer::Text) _attachFont(comp, child); if (child->type == LottieLayer::Text) _attachFont(comp, child);
child->statical &= parent->statical;
parent->statical &= child->statical;
} }
return true; return true;
} }

View file

@ -142,9 +142,8 @@ void LottieGroup::prepare(LottieObject::Type type)
size_t fillCnt = 0; size_t fillCnt = 0;
for (auto c = children.end() - 1; c >= children.begin(); --c) { for (auto c = children.end() - 1; c >= children.begin(); --c) {
if (reqFragment && !statical) break; if (reqFragment) break;
auto child = static_cast<LottieObject*>(*c); auto child = static_cast<LottieObject*>(*c);
if (statical) statical &= child->statical;
/* Figure out if the rendering context should be fragmented. /* Figure out if the rendering context should be fragmented.
Multiple stroking or grouping with a stroking would occur this. Multiple stroking or grouping with a stroking would occur this.
This fragment resolves the overlapped stroke outlines. */ This fragment resolves the overlapped stroke outlines. */
@ -180,11 +179,8 @@ LottieLayer::~LottieLayer()
void LottieLayer::prepare() void LottieLayer::prepare()
{ {
if (transform) statical &= transform->statical;
if (timeRemap.frames) statical = false;
/* if layer is hidden, only useful 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. */ so force it to be a Null Layer and release all resource. */
if (hidden) { if (hidden) {
type = LottieLayer::Null; type = LottieLayer::Null;
children.reset(); children.reset();

View file

@ -88,12 +88,6 @@ struct LottieMask
LottieOpacity opacity = 255; LottieOpacity opacity = 255;
CompositeMethod method; CompositeMethod method;
bool inverse = false; bool inverse = false;
bool dynamic()
{
if (opacity.frames || pathset.frames) return true;
return false;
}
}; };
@ -132,7 +126,6 @@ struct LottieObject
char* name = nullptr; char* name = nullptr;
Type type; Type type;
bool statical = true; //no keyframes
bool hidden = false; //remove? bool hidden = false; //remove?
}; };
@ -207,7 +200,6 @@ struct LottieTrimpath : LottieObject
void prepare() void prepare()
{ {
LottieObject::type = LottieObject::Trimpath; LottieObject::type = LottieObject::Trimpath;
if (start.frames || end.frames || offset.frames) statical = false;
} }
void segment(float frameNo, float& start, float& end); void segment(float frameNo, float& start, float& end);
@ -231,7 +223,6 @@ struct LottieRoundedCorner : LottieObject
void prepare() void prepare()
{ {
LottieObject::type = LottieObject::RoundedCorner; LottieObject::type = LottieObject::RoundedCorner;
if (radius.frames) statical = false;
} }
LottieFloat radius = 0.0f; LottieFloat radius = 0.0f;
}; };
@ -242,7 +233,6 @@ struct LottiePath : LottieShape
void prepare() void prepare()
{ {
LottieObject::type = LottieObject::Path; LottieObject::type = LottieObject::Path;
if (pathset.frames) statical = false;
} }
LottiePathSet pathset; LottiePathSet pathset;
@ -254,7 +244,6 @@ struct LottieRect : LottieShape
void prepare() void prepare()
{ {
LottieObject::type = LottieObject::Rect; LottieObject::type = LottieObject::Rect;
if (position.frames || size.frames || radius.frames) statical = false;
} }
LottiePosition position = Point{0.0f, 0.0f}; LottiePosition position = Point{0.0f, 0.0f};
@ -270,7 +259,6 @@ struct LottiePolyStar : LottieShape
void prepare() void prepare()
{ {
LottieObject::type = LottieObject::Polystar; LottieObject::type = LottieObject::Polystar;
if (position.frames || innerRadius.frames || outerRadius.frames || innerRoundness.frames || outerRoundness.frames || rotation.frames || ptsCnt.frames) statical = false;
} }
LottiePosition position = Point{0.0f, 0.0f}; LottiePosition position = Point{0.0f, 0.0f};
@ -289,7 +277,6 @@ struct LottieEllipse : LottieShape
void prepare() void prepare()
{ {
LottieObject::type = LottieObject::Ellipse; LottieObject::type = LottieObject::Ellipse;
if (position.frames || size.frames) statical = false;
} }
LottiePosition position = Point{0.0f, 0.0f}; LottiePosition position = Point{0.0f, 0.0f};
@ -320,9 +307,6 @@ struct LottieTransform : LottieObject
void prepare() void prepare()
{ {
LottieObject::type = LottieObject::Transform; LottieObject::type = LottieObject::Transform;
if (position.frames || rotation.frames || scale.frames || anchor.frames || opacity.frames || (coords && (coords->x.frames || coords->y.frames)) || (rotationEx && (rotationEx->x.frames || rotationEx->y.frames))) {
statical = false;
}
} }
LottiePosition position = Point{0.0f, 0.0f}; LottiePosition position = Point{0.0f, 0.0f};
@ -348,7 +332,6 @@ struct LottieSolidStroke : LottieSolid, LottieStroke
void prepare() void prepare()
{ {
LottieObject::type = LottieObject::SolidStroke; LottieObject::type = LottieObject::SolidStroke;
if (color.frames || opacity.frames || LottieStroke::dynamic()) statical = false;
} }
void override(LottieProperty* prop) override void override(LottieProperty* prop) override
@ -364,7 +347,6 @@ struct LottieSolidFill : LottieSolid
void prepare() void prepare()
{ {
LottieObject::type = LottieObject::SolidFill; LottieObject::type = LottieObject::SolidFill;
if (color.frames || opacity.frames) statical = false;
} }
void override(LottieProperty* prop) override void override(LottieProperty* prop) override
@ -493,7 +475,7 @@ struct LottieGradientFill : LottieGradient
void prepare() void prepare()
{ {
LottieObject::type = LottieObject::GradientFill; LottieObject::type = LottieObject::GradientFill;
if (LottieGradient::prepare()) statical = false; LottieGradient::prepare();
} }
void override(LottieProperty* prop) override void override(LottieProperty* prop) override
@ -511,7 +493,7 @@ struct LottieGradientStroke : LottieGradient, LottieStroke
void prepare() void prepare()
{ {
LottieObject::type = LottieObject::GradientStroke; LottieObject::type = LottieObject::GradientStroke;
if (LottieGradient::prepare() || LottieStroke::dynamic()) statical = false; LottieGradient::prepare();
} }
void override(LottieProperty* prop) override void override(LottieProperty* prop) override
@ -547,7 +529,6 @@ struct LottieRepeater : LottieObject
void prepare() void prepare()
{ {
LottieObject::type = LottieObject::Repeater; LottieObject::type = LottieObject::Repeater;
if (copies.frames || offset.frames || position.frames || rotation.frames || scale.frames || anchor.frames || startOpacity.frames || endOpacity.frames) statical = false;
} }
LottieFloat copies = 0.0f; LottieFloat copies = 0.0f;

View file

@ -1124,7 +1124,6 @@ void LottieParser::parseMasks(LottieLayer* layer)
enterArray(); enterArray();
while (nextArrayValue()) { while (nextArrayValue()) {
auto mask = parseMask(); auto mask = parseMask();
if (mask->dynamic()) layer->statical = false;
layer->masks.push(mask); layer->masks.push(mask);
} }
} }