lottie: Fixed a regression bug

Reverted commit db800c8d45,
which introduced another regression that omitted support
for multiple image asset references.

Updated the data of active images in the pooler
within the override() function to resolve the issue.
This commit is contained in:
Hermet Park 2024-11-19 00:04:15 +09:00 committed by Hermet Park
parent 66d4bab696
commit b66ce727ff
3 changed files with 21 additions and 13 deletions

View file

@ -980,7 +980,7 @@ void LottieBuilder::updateSolid(LottieLayer* layer)
void LottieBuilder::updateImage(LottieGroup* layer) void LottieBuilder::updateImage(LottieGroup* layer)
{ {
auto image = static_cast<LottieImage*>(layer->children.first()); auto image = static_cast<LottieImage*>(layer->children.first());
layer->scene->push(image->picture); layer->scene->push(image->pooling(true));
} }

View file

@ -159,10 +159,7 @@ void LottieImage::prepare()
{ {
LottieObject::type = LottieObject::Image; LottieObject::type = LottieObject::Image;
if (!picture) { auto picture = Picture::gen();
picture = Picture::gen();
PP(picture)->ref();
}
//force to load a picture on the same thread //force to load a picture on the same thread
TaskScheduler::async(false); TaskScheduler::async(false);
@ -173,6 +170,22 @@ void LottieImage::prepare()
TaskScheduler::async(true); TaskScheduler::async(true);
picture->size(data.width, data.height); picture->size(data.width, data.height);
PP(picture)->ref();
pooler.push(picture);
}
void LottieImage::update()
{
//Update the picture data
TaskScheduler::async(false);
for (auto p = pooler.begin(); p < pooler.end(); ++p) {
if (data.size > 0) (*p)->load((const char*)data.b64Data, data.size, data.mimeType);
else (*p)->load(data.path);
(*p)->size(data.width, data.height);
}
TaskScheduler::async(true);
} }

View file

@ -672,24 +672,19 @@ struct LottieGradientStroke : LottieGradient, LottieStroke
}; };
struct LottieImage : LottieObject struct LottieImage : LottieObject, LottieRenderPooler<tvg::Picture>
{ {
LottieBitmap data; LottieBitmap data;
Picture* picture = nullptr;
~LottieImage()
{
if (PP(picture)->unref() == 0) delete(picture);
}
void override(LottieProperty* prop, bool byDefault = false) override void override(LottieProperty* prop, bool byDefault = false) override
{ {
if (byDefault) data.release(); if (byDefault) data.release();
data = *static_cast<LottieBitmap*>(prop); data = *static_cast<LottieBitmap*>(prop);
prepare(); update();
} }
void prepare(); void prepare();
void update();
}; };