Skip to content

Commit 023cc8e

Browse files
committed
Update to thorvg 0.15.12
1 parent 246e609 commit 023cc8e

File tree

6 files changed

+76
-31
lines changed

6 files changed

+76
-31
lines changed

thirdparty/thorvg/src/loaders/lottie/tvgLottieBuilder.cpp

+14-13
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,8 @@ void LottieBuilder::updateTransform(LottieLayer* layer, float frameNo)
167167

168168
_updateTransform(transform, frameNo, layer->autoOrient, matrix, layer->cache.opacity, exps);
169169

170-
if (parent) {
171-
if (!identity((const Matrix*) &parent->cache.matrix)) {
172-
if (identity((const Matrix*) &matrix)) layer->cache.matrix = parent->cache.matrix;
173-
else layer->cache.matrix = parent->cache.matrix * matrix;
174-
}
175-
}
170+
if (parent) layer->cache.matrix = parent->cache.matrix * matrix;
171+
176172
layer->cache.frameNo = frameNo;
177173
}
178174

@@ -182,25 +178,30 @@ void LottieBuilder::updateTransform(LottieGroup* parent, LottieObject** child, f
182178
auto transform = static_cast<LottieTransform*>(*child);
183179
if (!transform) return;
184180

181+
Matrix m;
185182
uint8_t opacity;
186183

187184
if (parent->mergeable()) {
188-
if (!ctx->transform) ctx->transform = (Matrix*)malloc(sizeof(Matrix));
189-
_updateTransform(transform, frameNo, false, *ctx->transform, opacity, exps);
185+
if (ctx->transform) {
186+
_updateTransform(transform, frameNo, false, m, opacity, exps);
187+
*ctx->transform *= m;
188+
} else {
189+
ctx->transform = new Matrix;
190+
_updateTransform(transform, frameNo, false, *ctx->transform, opacity, exps);
191+
}
190192
return;
191193
}
192194

193195
ctx->merging = nullptr;
194196

195-
Matrix matrix;
196-
if (!_updateTransform(transform, frameNo, false, matrix, opacity, exps)) return;
197+
if (!_updateTransform(transform, frameNo, false, m, opacity, exps)) return;
197198

198-
ctx->propagator->transform(PP(ctx->propagator)->transform() * matrix);
199+
ctx->propagator->transform(PP(ctx->propagator)->transform() * m);
199200
ctx->propagator->opacity(MULTIPLY(opacity, PP(ctx->propagator)->opacity));
200201

201202
//FIXME: preserve the stroke width. too workaround, need a better design.
202203
if (P(ctx->propagator)->rs.strokeWidth() > 0.0f) {
203-
auto denominator = sqrtf(matrix.e11 * matrix.e11 + matrix.e12 * matrix.e12);
204+
auto denominator = sqrtf(m.e11 * m.e11 + m.e12 * m.e12);
204205
if (denominator > 1.0f) ctx->propagator->stroke(ctx->propagator->strokeWidth() / denominator);
205206
}
206207
}
@@ -1510,7 +1511,6 @@ void LottieBuilder::updateLayer(LottieComposition* comp, Scene* scene, LottieLay
15101511

15111512
updateEffect(layer, frameNo);
15121513

1513-
//the given matte source was composited by the target earlier.
15141514
if (!layer->matteSrc) scene->push(cast(layer->scene));
15151515
}
15161516

@@ -1600,6 +1600,7 @@ static bool _buildComposition(LottieComposition* comp, LottieLayer* parent)
16001600
}
16011601

16021602
if (child->matteTarget) {
1603+
child->matteTarget->matteSrc = true;
16031604
//parenting
16041605
_buildHierarchy(parent, child->matteTarget);
16051606
//precomp referencing

thirdparty/thorvg/src/loaders/lottie/tvgLottieBuilder.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct RenderContext
7171
~RenderContext()
7272
{
7373
PP(propagator)->unref();
74-
free(transform);
74+
delete(transform);
7575
delete(roundness);
7676
delete(offsetPath);
7777
}
@@ -84,6 +84,10 @@ struct RenderContext
8484
this->repeaters = rhs.repeaters;
8585
if (rhs.roundness) this->roundness = new LottieRoundnessModifier(rhs.roundness->r);
8686
if (rhs.offsetPath) this->offsetPath = new LottieOffsetModifier(rhs.offsetPath->offset, rhs.offsetPath->miterLimit, rhs.offsetPath->join);
87+
if (rhs.transform) {
88+
transform = new Matrix;
89+
*transform = *rhs.transform;
90+
}
8791
}
8892
};
8993

thirdparty/thorvg/src/loaders/lottie/tvgLottieExpressions.cpp

+51-3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,25 @@ static ExpContent* _expcontent(LottieExpression* exp, float frameNo, LottieObjec
6868
}
6969

7070

71+
static float _rand()
72+
{
73+
return (float)(rand() % 10000001) * 0.0000001f;
74+
}
75+
76+
77+
static jerry_value_t _point2d(const Point& pt)
78+
{
79+
auto obj = jerry_object();
80+
auto v1 = jerry_number(pt.x);
81+
auto v2 = jerry_number(pt.y);
82+
jerry_object_set_index(obj, 0, v1);
83+
jerry_object_set_index(obj, 1, v2);
84+
jerry_value_free(v1);
85+
jerry_value_free(v2);
86+
return obj;
87+
}
88+
89+
7190
static void contentFree(void *native_p, struct jerry_object_native_info_t *info_p)
7291
{
7392
free(native_p);
@@ -603,8 +622,7 @@ static jerry_value_t _length(const jerry_call_info_t* info, const jerry_value_t
603622

604623
static jerry_value_t _random(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt)
605624
{
606-
auto val = (float)(rand() % 10000001);
607-
return jerry_number(val * 0.0000001f);
625+
return jerry_number(_rand());
608626
}
609627

610628

@@ -821,6 +839,32 @@ static jerry_value_t _speedAtTime(const jerry_call_info_t* info, const jerry_val
821839
}
822840

823841

842+
843+
static jerry_value_t _wiggle(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt)
844+
{
845+
auto data = static_cast<ExpContent*>(jerry_object_get_native_ptr(info->function, &freeCb));
846+
auto freq = jerry_value_as_number(args[0]);
847+
auto amp = jerry_value_as_number(args[1]);
848+
auto octaves = (argsCnt > 2) ? jerry_value_as_int32(args[2]) : 1;
849+
auto ampm = (argsCnt > 3) ? jerry_value_as_number(args[3]) : 5.0f;
850+
auto time = (argsCnt > 4) ? jerry_value_as_number(args[4]) : data->exp->comp->timeAtFrame(data->frameNo);
851+
852+
Point result = {100.0f, 100.0f};
853+
854+
for (int o = 0; o < octaves; ++o) {
855+
auto repeat = int(time * freq);
856+
auto frac = (time * freq - float(repeat)) * 1.25f;
857+
for (int i = 0; i < repeat; ++i) {
858+
result.x += (_rand() * 2.0f - 1.0f) * amp * frac;
859+
result.y += (_rand() * 2.0f - 1.0f) * amp * frac;
860+
}
861+
freq *= 2.0f;
862+
amp *= ampm;
863+
}
864+
return _point2d(result);
865+
}
866+
867+
824868
static bool _loopOutCommon(LottieExpression* exp, const jerry_value_t args[], const jerry_length_t argsCnt)
825869
{
826870
exp->loop.mode = LottieExpression::LoopMode::OutCycle;
@@ -1044,7 +1088,11 @@ static void _buildProperty(float frameNo, jerry_value_t context, LottieExpressio
10441088
jerry_object_set_native_ptr(speedAtTime, nullptr, exp);
10451089
jerry_value_free(speedAtTime);
10461090

1047-
//wiggle(freq, amp, octaves=1, amp_mult=.5, t=time)
1091+
auto wiggle = jerry_function_external(_wiggle);
1092+
jerry_object_set_sz(context, "wiggle", wiggle);
1093+
jerry_object_set_native_ptr(wiggle, &freeCb, _expcontent(exp, frameNo, exp->object));
1094+
jerry_value_free(wiggle);
1095+
10481096
//temporalWiggle(freq, amp, octaves=1, amp_mult=.5, t=time)
10491097
//smooth(width=.2, samples=5, t=time)
10501098

thirdparty/thorvg/src/loaders/lottie/tvgLottieModel.cpp

+1-9
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,7 @@ void LottieFont::prepare()
201201
{
202202
if (!data.b64src || !name) return;
203203

204-
TaskScheduler::async(false);
205204
Text::load(name, data.b64src, data.size, "ttf", false);
206-
TaskScheduler::async(true);
207205
}
208206

209207

@@ -214,13 +212,9 @@ void LottieImage::prepare()
214212
auto picture = Picture::gen().release();
215213

216214
//force to load a picture on the same thread
217-
TaskScheduler::async(false);
218-
219215
if (data.size > 0) picture->load((const char*)data.b64Data, data.size, data.mimeType, false);
220216
else picture->load(data.path);
221217

222-
TaskScheduler::async(true);
223-
224218
picture->size(data.width, data.height);
225219
PP(picture)->ref();
226220

@@ -231,13 +225,11 @@ void LottieImage::prepare()
231225
void LottieImage::update()
232226
{
233227
//Update the picture data
234-
TaskScheduler::async(false);
235228
for (auto p = pooler.begin(); p < pooler.end(); ++p) {
236229
if (data.size > 0) (*p)->load((const char*)data.b64Data, data.size, data.mimeType, false);
237230
else (*p)->load(data.path);
238231
(*p)->size(data.width, data.height);
239232
}
240-
TaskScheduler::async(true);
241233
}
242234

243235

@@ -434,7 +426,7 @@ void LottieGroup::prepare(LottieObject::Type type)
434426

435427
/* Figure out if this group is a simple path drawing.
436428
In that case, the rendering context can be sharable with the parent's. */
437-
if (allowMerge && (child->type == LottieObject::Group || !child->mergeable())) allowMerge = false;
429+
if (allowMerge && !child->mergeable()) allowMerge = false;
438430

439431
//Figure out this group has visible contents
440432
switch (child->type) {

thirdparty/thorvg/src/loaders/lottie/tvgLottieModel.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,7 @@ struct LottieTransform : LottieObject
544544

545545
bool mergeable() override
546546
{
547-
if (!opacity.frames && opacity.value == 255) return true;
548-
return false;
547+
return true;
549548
}
550549

551550
LottieProperty* property(uint16_t ix) override

thirdparty/thorvg/src/loaders/lottie/tvgLottieProperty.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -947,18 +947,19 @@ struct LottieBitmap : LottieProperty
947947
if (shallow) {
948948
b64Data = rhs.b64Data;
949949
mimeType = rhs.mimeType;
950+
951+
rhs.b64Data = nullptr;
952+
rhs.mimeType = nullptr;
950953
} else {
951954
//TODO: optimize here by avoiding data copy
952955
TVGLOG("LOTTIE", "Shallow copy of the image data!");
953956
b64Data = strdup(rhs.b64Data);
954957
mimeType = strdup(rhs.mimeType);
955958
}
959+
956960
size = rhs.size;
957961
width = rhs.width;
958962
height = rhs.height;
959-
960-
rhs.b64Data = nullptr;
961-
rhs.mimeType = nullptr;
962963
}
963964
};
964965

0 commit comments

Comments
 (0)