mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-10 22:51:58 +00:00
lottie: allow image asset sharing among LottiePicture instances
Previously, the Lottie builder didn't account for image asset sharing among multiple layers. This update rectifies the situation. issue: https://github.com/thorvg/thorvg/issues/2428
This commit is contained in:
parent
6d8b973666
commit
cbf124632f
3 changed files with 14 additions and 23 deletions
|
@ -1028,32 +1028,23 @@ static void _updateSolid(LottieLayer* layer)
|
||||||
static void _updateImage(LottieGroup* layer)
|
static void _updateImage(LottieGroup* layer)
|
||||||
{
|
{
|
||||||
auto image = static_cast<LottieImage*>(layer->children.first());
|
auto image = static_cast<LottieImage*>(layer->children.first());
|
||||||
auto picture = image->picture;
|
|
||||||
|
|
||||||
if (!picture) {
|
if (!image->picture) {
|
||||||
picture = Picture::gen().release();
|
image->picture = Picture::gen().release();
|
||||||
|
|
||||||
//force to load a picture on the same thread
|
//force to load a picture on the same thread
|
||||||
TaskScheduler::async(false);
|
TaskScheduler::async(false);
|
||||||
|
|
||||||
if (image->size > 0) {
|
if (image->size > 0) image->picture->load((const char*)image->b64Data, image->size, image->mimeType);
|
||||||
if (picture->load((const char*)image->b64Data, image->size, image->mimeType) != Result::Success) {
|
else image->picture->load(image->path);
|
||||||
delete(picture);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (picture->load(image->path) != Result::Success) {
|
|
||||||
delete(picture);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TaskScheduler::async(true);
|
TaskScheduler::async(true);
|
||||||
|
|
||||||
image->picture = picture;
|
PP(image->picture)->ref();
|
||||||
PP(picture)->ref();
|
|
||||||
}
|
}
|
||||||
layer->scene->push(cast<Picture>(picture));
|
|
||||||
|
if (image->refCnt == 1) layer->scene->push(tvg::cast(image->picture));
|
||||||
|
else layer->scene->push(tvg::cast(image->picture->duplicate()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1190,7 +1181,7 @@ static bool _updateMatte(LottieLayer* root, LottieLayer* layer, float frameNo, L
|
||||||
|
|
||||||
if (target->scene) {
|
if (target->scene) {
|
||||||
layer->scene->composite(cast(target->scene), layer->matteType);
|
layer->scene->composite(cast(target->scene), layer->matteType);
|
||||||
} else if (layer->matteType == CompositeMethod::AlphaMask || layer->matteType == CompositeMethod::LumaMask) {
|
} else if (layer->matteType == CompositeMethod::AlphaMask || layer->matteType == CompositeMethod::LumaMask) {
|
||||||
//matte target is not exist. alpha blending definitely bring an invisible result
|
//matte target is not exist. alpha blending definitely bring an invisible result
|
||||||
delete(layer->scene);
|
delete(layer->scene);
|
||||||
layer->scene = nullptr;
|
layer->scene = nullptr;
|
||||||
|
@ -1272,6 +1263,7 @@ static void _buildReference(LottieComposition* comp, LottieLayer* layer)
|
||||||
layer->reqFragment = assetLayer->reqFragment;
|
layer->reqFragment = assetLayer->reqFragment;
|
||||||
}
|
}
|
||||||
} else if (layer->type == LottieLayer::Image) {
|
} else if (layer->type == LottieLayer::Image) {
|
||||||
|
++static_cast<LottieImage*>(*asset)->refCnt;
|
||||||
layer->children.push(*asset);
|
layer->children.push(*asset);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -110,12 +110,11 @@ void LottieSlot::assign(LottieObject* target)
|
||||||
|
|
||||||
LottieImage::~LottieImage()
|
LottieImage::~LottieImage()
|
||||||
{
|
{
|
||||||
free(b64Data);
|
|
||||||
free(mimeType);
|
|
||||||
|
|
||||||
if (picture && PP(picture)->unref() == 0) {
|
if (picture && PP(picture)->unref() == 0) {
|
||||||
delete(picture);
|
delete(picture);
|
||||||
}
|
}
|
||||||
|
free(b64Data);
|
||||||
|
free(mimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -454,10 +454,10 @@ struct LottieImage : LottieObject
|
||||||
char* b64Data = nullptr;
|
char* b64Data = nullptr;
|
||||||
char* path;
|
char* path;
|
||||||
};
|
};
|
||||||
|
Picture* picture = nullptr; //tvg render data
|
||||||
char* mimeType = nullptr;
|
char* mimeType = nullptr;
|
||||||
uint32_t size = 0;
|
uint32_t size = 0;
|
||||||
|
uint16_t refCnt = 0; //refernce count
|
||||||
Picture* picture = nullptr; //tvg render data
|
|
||||||
|
|
||||||
~LottieImage();
|
~LottieImage();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue