lottie: code refactoring++

renamed internal variable for improved simplicity.
no logical changes.
This commit is contained in:
Hermet Park 2025-01-29 17:50:33 +09:00 committed by Hermet Park
parent a67f90951c
commit 2b97cf7a0d
4 changed files with 45 additions and 45 deletions

View file

@ -373,7 +373,7 @@ static void _repeat(LottieGroup* parent, Shape* path, RenderContext* ctx)
}
static void _appendRect(Shape* shape, float x, float y, float w, float h, float r, const LottieOffsetModifier* offsetPath, Matrix* transform, bool clockwise)
static void _appendRect(Shape* shape, float x, float y, float w, float h, float r, const LottieOffsetModifier* offset, Matrix* transform, bool clockwise)
{
//sharp rect
if (tvg::zero(r)) {
@ -400,7 +400,7 @@ static void _appendRect(Shape* shape, float x, float y, float w, float h, float
}
}
if (offsetPath) offsetPath->modifyRect(commands, 5, points, 4, SHAPE(shape)->rs.path.cmds, SHAPE(shape)->rs.path.pts);
if (offset) offset->modifyRect(commands, 5, points, 4, SHAPE(shape)->rs.path.cmds, SHAPE(shape)->rs.path.pts);
else shape->appendPath(commands, 5, points, 4);
//round rect
} else {
@ -453,7 +453,7 @@ static void _appendRect(Shape* shape, float x, float y, float w, float h, float
}
}
if (offsetPath) offsetPath->modifyRect(commands, cmdCnt, points, ptsCnt, SHAPE(shape)->rs.path.cmds, SHAPE(shape)->rs.path.pts);
if (offset) offset->modifyRect(commands, cmdCnt, points, ptsCnt, SHAPE(shape)->rs.path.cmds, SHAPE(shape)->rs.path.pts);
else shape->appendPath(commands, cmdCnt, points, ptsCnt);
}
}
@ -475,18 +475,18 @@ void LottieBuilder::updateRect(LottieGroup* parent, LottieObject** child, float
if (!ctx->repeaters.empty()) {
auto shape = rect->pooling();
shape->reset();
_appendRect(shape, position.x - size.x * 0.5f, position.y - size.y * 0.5f, size.x, size.y, r, ctx->offsetPath, ctx->transform, rect->clockwise);
_appendRect(shape, position.x - size.x * 0.5f, position.y - size.y * 0.5f, size.x, size.y, r, ctx->offset, ctx->transform, rect->clockwise);
_repeat(parent, shape, ctx);
} else {
_draw(parent, rect, ctx);
_appendRect(ctx->merging, position.x - size.x * 0.5f, position.y - size.y * 0.5f, size.x, size.y, r, ctx->offsetPath, ctx->transform, rect->clockwise);
_appendRect(ctx->merging, position.x - size.x * 0.5f, position.y - size.y * 0.5f, size.x, size.y, r, ctx->offset, ctx->transform, rect->clockwise);
}
}
static void _appendCircle(Shape* shape, float cx, float cy, float rx, float ry, const LottieOffsetModifier* offsetPath, Matrix* transform, bool clockwise)
static void _appendCircle(Shape* shape, float cx, float cy, float rx, float ry, const LottieOffsetModifier* offset, Matrix* transform, bool clockwise)
{
if (offsetPath) offsetPath->modifyEllipse(rx, ry);
if (offset) offset->modifyEllipse(rx, ry);
if (rx == 0.0f || ry == 0.0f) return;
@ -536,11 +536,11 @@ void LottieBuilder::updateEllipse(LottieGroup* parent, LottieObject** child, flo
if (!ctx->repeaters.empty()) {
auto shape = ellipse->pooling();
shape->reset();
_appendCircle(shape, position.x, position.y, size.x * 0.5f, size.y * 0.5f, ctx->offsetPath, ctx->transform, ellipse->clockwise);
_appendCircle(shape, position.x, position.y, size.x * 0.5f, size.y * 0.5f, ctx->offset, ctx->transform, ellipse->clockwise);
_repeat(parent, shape, ctx);
} else {
_draw(parent, ellipse, ctx);
_appendCircle(ctx->merging, position.x, position.y, size.x * 0.5f, size.y * 0.5f, ctx->offsetPath, ctx->transform, ellipse->clockwise);
_appendCircle(ctx->merging, position.x, position.y, size.x * 0.5f, size.y * 0.5f, ctx->offset, ctx->transform, ellipse->clockwise);
}
}
@ -552,18 +552,18 @@ void LottieBuilder::updatePath(LottieGroup* parent, LottieObject** child, float
if (!ctx->repeaters.empty()) {
auto shape = path->pooling();
shape->reset();
path->pathset(frameNo, SHAPE(shape)->rs.path.cmds, SHAPE(shape)->rs.path.pts, ctx->transform, ctx->roundness, ctx->offsetPath, exps);
path->pathset(frameNo, SHAPE(shape)->rs.path.cmds, SHAPE(shape)->rs.path.pts, ctx->transform, ctx->roundness, ctx->offset, exps);
_repeat(parent, shape, ctx);
} else {
_draw(parent, path, ctx);
if (path->pathset(frameNo, SHAPE(ctx->merging)->rs.path.cmds, SHAPE(ctx->merging)->rs.path.pts, ctx->transform, ctx->roundness, ctx->offsetPath, exps)) {
if (path->pathset(frameNo, SHAPE(ctx->merging)->rs.path.cmds, SHAPE(ctx->merging)->rs.path.pts, ctx->transform, ctx->roundness, ctx->offset, exps)) {
PAINT(ctx->merging)->update(RenderUpdateFlag::Path);
}
}
}
static void _updateStar(TVG_UNUSED LottieGroup* parent, LottiePolyStar* star, Matrix* transform, const LottieRoundnessModifier* roundness, const LottieOffsetModifier* offsetPath, float frameNo, Shape* merging, LottieExpressions* exps)
static void _updateStar(TVG_UNUSED LottieGroup* parent, LottiePolyStar* star, Matrix* transform, const LottieRoundnessModifier* roundness, const LottieOffsetModifier* offset, float frameNo, Shape* merging, LottieExpressions* exps)
{
static constexpr auto POLYSTAR_MAGIC_NUMBER = 0.47829f / 0.28f;
@ -585,7 +585,7 @@ static void _updateStar(TVG_UNUSED LottieGroup* parent, LottiePolyStar* star, Ma
bool roundedCorner = roundness && (tvg::zero(innerRoundness) || tvg::zero(outerRoundness));
Shape* shape;
if (roundedCorner || offsetPath) {
if (roundedCorner || offset) {
shape = star->pooling();
shape->reset();
} else {
@ -680,19 +680,19 @@ static void _updateStar(TVG_UNUSED LottieGroup* parent, LottiePolyStar* star, Ma
shape->close();
if (roundedCorner) {
if (offsetPath) {
if (offset) {
auto intermediate = Shape::gen();
roundness->modifyPolystar(SHAPE(shape)->rs.path.cmds, SHAPE(shape)->rs.path.pts, SHAPE(intermediate)->rs.path.cmds, SHAPE(intermediate)->rs.path.pts, outerRoundness, hasRoundness);
offsetPath->modifyPolystar(SHAPE(intermediate)->rs.path.cmds, SHAPE(intermediate)->rs.path.pts, SHAPE(merging)->rs.path.cmds, SHAPE(merging)->rs.path.pts);
offset->modifyPolystar(SHAPE(intermediate)->rs.path.cmds, SHAPE(intermediate)->rs.path.pts, SHAPE(merging)->rs.path.cmds, SHAPE(merging)->rs.path.pts);
delete(intermediate);
} else {
roundness->modifyPolystar(SHAPE(shape)->rs.path.cmds, SHAPE(shape)->rs.path.pts, SHAPE(merging)->rs.path.cmds, SHAPE(merging)->rs.path.pts, outerRoundness, hasRoundness);
}
} else if (offsetPath) offsetPath->modifyPolystar(SHAPE(shape)->rs.path.cmds, SHAPE(shape)->rs.path.pts, SHAPE(merging)->rs.path.cmds, SHAPE(merging)->rs.path.pts);
} else if (offset) offset->modifyPolystar(SHAPE(shape)->rs.path.cmds, SHAPE(shape)->rs.path.pts, SHAPE(merging)->rs.path.cmds, SHAPE(merging)->rs.path.pts);
}
static void _updatePolygon(LottieGroup* parent, LottiePolyStar* star, Matrix* transform, const LottieRoundnessModifier* roundness, const LottieOffsetModifier* offsetPath, float frameNo, Shape* merging, LottieExpressions* exps)
static void _updatePolygon(LottieGroup* parent, LottiePolyStar* star, Matrix* transform, const LottieRoundnessModifier* roundness, const LottieOffsetModifier* offset, float frameNo, Shape* merging, LottieExpressions* exps)
{
static constexpr auto POLYGON_MAGIC_NUMBER = 0.25f;
@ -711,7 +711,7 @@ static void _updatePolygon(LottieGroup* parent, LottiePolyStar* star, Matrix* tr
angle += anglePerPoint * direction;
Shape* shape;
if (roundedCorner || offsetPath) {
if (roundedCorner || offset) {
shape = star->pooling();
shape->reset();
} else {
@ -767,15 +767,15 @@ static void _updatePolygon(LottieGroup* parent, LottiePolyStar* star, Matrix* tr
shape->close();
if (roundedCorner) {
if (offsetPath) {
if (offset) {
auto intermediate = Shape::gen();
roundness->modifyPolystar(SHAPE(shape)->rs.path.cmds, SHAPE(shape)->rs.path.pts, SHAPE(intermediate)->rs.path.cmds, SHAPE(intermediate)->rs.path.pts, 0.0f, false);
offsetPath->modifyPolystar(SHAPE(intermediate)->rs.path.cmds, SHAPE(intermediate)->rs.path.pts, SHAPE(merging)->rs.path.cmds, SHAPE(merging)->rs.path.pts);
offset->modifyPolystar(SHAPE(intermediate)->rs.path.cmds, SHAPE(intermediate)->rs.path.pts, SHAPE(merging)->rs.path.cmds, SHAPE(merging)->rs.path.pts);
delete(intermediate);
} else {
roundness->modifyPolystar(SHAPE(shape)->rs.path.cmds, SHAPE(shape)->rs.path.pts, SHAPE(merging)->rs.path.cmds, SHAPE(merging)->rs.path.pts, 0.0f, false);
}
} else if (offsetPath) offsetPath->modifyPolystar(SHAPE(shape)->rs.path.cmds, SHAPE(shape)->rs.path.pts, SHAPE(merging)->rs.path.cmds, SHAPE(merging)->rs.path.pts);
} else if (offset) offset->modifyPolystar(SHAPE(shape)->rs.path.cmds, SHAPE(shape)->rs.path.pts, SHAPE(merging)->rs.path.cmds, SHAPE(merging)->rs.path.pts);
}
@ -796,13 +796,13 @@ void LottieBuilder::updatePolystar(LottieGroup* parent, LottieObject** child, fl
if (!ctx->repeaters.empty()) {
auto shape = star->pooling();
shape->reset();
if (star->type == LottiePolyStar::Star) _updateStar(parent, star, identity ? nullptr : &matrix, ctx->roundness, ctx->offsetPath, frameNo, shape, exps);
else _updatePolygon(parent, star, identity ? nullptr : &matrix, ctx->roundness, ctx->offsetPath, frameNo, shape, exps);
if (star->type == LottiePolyStar::Star) _updateStar(parent, star, identity ? nullptr : &matrix, ctx->roundness, ctx->offset, frameNo, shape, exps);
else _updatePolygon(parent, star, identity ? nullptr : &matrix, ctx->roundness, ctx->offset, frameNo, shape, exps);
_repeat(parent, shape, ctx);
} else {
_draw(parent, star, ctx);
if (star->type == LottiePolyStar::Star) _updateStar(parent, star, identity ? nullptr : &matrix, ctx->roundness, ctx->offsetPath, frameNo, ctx->merging, exps);
else _updatePolygon(parent, star, identity ? nullptr : &matrix, ctx->roundness, ctx->offsetPath, frameNo, ctx->merging, exps);
if (star->type == LottiePolyStar::Star) _updateStar(parent, star, identity ? nullptr : &matrix, ctx->roundness, ctx->offset, frameNo, ctx->merging, exps);
else _updatePolygon(parent, star, identity ? nullptr : &matrix, ctx->roundness, ctx->offset, frameNo, ctx->merging, exps);
PAINT(ctx->merging)->update(RenderUpdateFlag::Path);
}
}
@ -821,8 +821,8 @@ void LottieBuilder::updateRoundedCorner(TVG_UNUSED LottieGroup* parent, LottieOb
void LottieBuilder::updateOffsetPath(TVG_UNUSED LottieGroup* parent, LottieObject** child, float frameNo, TVG_UNUSED Inlist<RenderContext>& contexts, RenderContext* ctx)
{
auto offsetPath = static_cast<LottieOffsetPath*>(*child);
if (!ctx->offsetPath) ctx->offsetPath = new LottieOffsetModifier(offsetPath->offset(frameNo, exps), offsetPath->miterLimit(frameNo, exps), offsetPath->join);
auto offset = static_cast<LottieOffsetPath*>(*child);
if (!ctx->offset) ctx->offset = new LottieOffsetModifier(offset->offset(frameNo, exps), offset->miterLimit(frameNo, exps), offset->join);
}

View file

@ -56,7 +56,7 @@ struct RenderContext
Array<RenderRepeater> repeaters;
Matrix* transform = nullptr;
LottieRoundnessModifier* roundness = nullptr;
LottieOffsetModifier* offsetPath = nullptr;
LottieOffsetModifier* offset = nullptr;
bool fragmenting = false; //render context has been fragmented by filling
bool reqFragment = false; //requirement to fragment the render context
@ -72,7 +72,7 @@ struct RenderContext
propagator->unref(false);
free(transform);
delete(roundness);
delete(offsetPath);
delete(offset);
}
RenderContext(const RenderContext& rhs, Shape* propagator, bool mergeable = false)
@ -80,9 +80,9 @@ struct RenderContext
if (mergeable) merging = rhs.merging;
propagator->ref();
this->propagator = propagator;
this->repeaters = rhs.repeaters;
if (rhs.roundness) this->roundness = new LottieRoundnessModifier(rhs.roundness->r);
if (rhs.offsetPath) this->offsetPath = new LottieOffsetModifier(rhs.offsetPath->offset, rhs.offsetPath->miterLimit, rhs.offsetPath->join);
repeaters = rhs.repeaters;
if (rhs.roundness) roundness = new LottieRoundnessModifier(rhs.roundness->r);
if (rhs.offset) offset = new LottieOffsetModifier(rhs.offset->offset, rhs.offset->miterLimit, rhs.offset->join);
}
};

View file

@ -112,13 +112,13 @@ public:
}
template<typename Property>
bool result(float frameNo, Array<PathCommand>& cmds, Array<Point>& pts, Matrix* transform, const LottieRoundnessModifier* roundness, const LottieOffsetModifier* offsetPath, LottieExpression* exp)
bool result(float frameNo, Array<PathCommand>& cmds, Array<Point>& pts, Matrix* transform, const LottieRoundnessModifier* roundness, const LottieOffsetModifier* offset, LottieExpression* exp)
{
auto bm_rt = evaluate(frameNo, exp);
if (jerry_value_is_undefined(bm_rt)) return false;
if (auto pathset = static_cast<Property*>(jerry_object_get_native_ptr(bm_rt, nullptr))) {
(*pathset)(frameNo, cmds, pts, transform, roundness, offsetPath);
(*pathset)(frameNo, cmds, pts, transform, roundness, offset);
}
jerry_value_free(bm_rt);
return true;

View file

@ -448,7 +448,7 @@ struct LottiePathSet : LottieProperty
return (*frames)[frames->count];
}
bool operator()(float frameNo, Array<PathCommand>& cmds, Array<Point>& pts, Matrix* transform, const LottieRoundnessModifier* roundness, const LottieOffsetModifier* offsetPath)
bool operator()(float frameNo, Array<PathCommand>& cmds, Array<Point>& pts, Matrix* transform, const LottieRoundnessModifier* roundness, const LottieOffsetModifier* offset)
{
PathSet* path = nullptr;
LottieScalarFrame<PathSet>* frame = nullptr;
@ -474,15 +474,15 @@ struct LottiePathSet : LottieProperty
if (!interpolate) {
if (roundness) {
if (offsetPath) {
if (offset) {
Array<PathCommand> cmds1(path->cmdsCnt);
Array<Point> pts1(path->ptsCnt);
roundness->modifyPath(path->cmds, path->cmdsCnt, path->pts, path->ptsCnt, cmds1, pts1, transform);
return offsetPath->modifyPath(cmds1.data, cmds1.count, pts1.data, pts1.count, cmds, pts);
return offset->modifyPath(cmds1.data, cmds1.count, pts1.data, pts1.count, cmds, pts);
}
return roundness->modifyPath(path->cmds, path->cmdsCnt, path->pts, path->ptsCnt, cmds, pts, transform);
}
if (offsetPath) return offsetPath->modifyPath(path->cmds, path->cmdsCnt, path->pts, path->ptsCnt, cmds, pts);
if (offset) return offset->modifyPath(path->cmds, path->cmdsCnt, path->pts, path->ptsCnt, cmds, pts);
_copy(path, cmds);
_copy(path, pts, transform);
@ -492,7 +492,7 @@ struct LottiePathSet : LottieProperty
auto s = frame->value.pts;
auto e = (frame + 1)->value.pts;
if (!roundness && !offsetPath) {
if (!roundness && !offset) {
for (auto i = 0; i < frame->value.ptsCnt; ++i, ++s, ++e) {
auto pt = lerp(*s, *e, t);
if (transform) pt *= *transform;
@ -510,13 +510,13 @@ struct LottiePathSet : LottieProperty
}
if (roundness) {
if (offsetPath) {
if (offset) {
Array<PathCommand> cmds1;
Array<Point> pts1;
roundness->modifyPath(frame->value.cmds, frame->value.cmdsCnt, interpPts, frame->value.ptsCnt, cmds1, pts1, nullptr);
offsetPath->modifyPath(cmds1.data, cmds1.count, pts1.data, pts1.count, cmds, pts);
offset->modifyPath(cmds1.data, cmds1.count, pts1.data, pts1.count, cmds, pts);
} else roundness->modifyPath(frame->value.cmds, frame->value.cmdsCnt, interpPts, frame->value.ptsCnt, cmds, pts, nullptr);
} else if (offsetPath) offsetPath->modifyPath(frame->value.cmds, frame->value.cmdsCnt, interpPts, frame->value.ptsCnt, cmds, pts);
} else if (offset) offset->modifyPath(frame->value.cmds, frame->value.cmdsCnt, interpPts, frame->value.ptsCnt, cmds, pts);
free(interpPts);
@ -524,13 +524,13 @@ struct LottiePathSet : LottieProperty
}
bool operator()(float frameNo, Array<PathCommand>& cmds, Array<Point>& pts, Matrix* transform, const LottieRoundnessModifier* roundness, const LottieOffsetModifier* offsetPath, LottieExpressions* exps)
bool operator()(float frameNo, Array<PathCommand>& cmds, Array<Point>& pts, Matrix* transform, const LottieRoundnessModifier* roundness, const LottieOffsetModifier* offset, LottieExpressions* exps)
{
if (exps && exp) {
frameNo = _loop(frames, frameNo, exp);
if (exps->result<LottiePathSet>(frameNo, cmds, pts, transform, roundness, offsetPath, exp)) return true;
if (exps->result<LottiePathSet>(frameNo, cmds, pts, transform, roundness, offset, exp)) return true;
}
return operator()(frameNo, cmds, pts, transform, roundness, offsetPath);
return operator()(frameNo, cmds, pts, transform, roundness, offset);
}
void prepare() {}