mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 05:33:36 +00:00
renderer/loader: ensure unique scene instances for each Lottie loader
The Lottie loader now utilizes an individual scene instance per loader. This guarantees that each instance retains a unique frame number, essential for maintaining the integrity of animation states. As a result, sharing loaders between Lottie animations is prohibited to uphold frame context isolation. This may be subject to optimization review in the future.
This commit is contained in:
parent
1228f52dc9
commit
06a34a4c65
1 changed files with 33 additions and 14 deletions
|
@ -294,15 +294,24 @@ LoadModule* LoaderMgr::loader(const string& path, bool* invalid)
|
|||
{
|
||||
*invalid = false;
|
||||
|
||||
if (auto loader = _findFromCache(path)) return loader;
|
||||
//TODO: lottie is not sharable.
|
||||
auto allowCache = true;
|
||||
auto ext = path.substr(path.find_last_of(".") + 1);
|
||||
if (!ext.compare("json")) allowCache = false;
|
||||
|
||||
if (allowCache) {
|
||||
if (auto loader = _findFromCache(path)) return loader;
|
||||
}
|
||||
|
||||
if (auto loader = _findByPath(path)) {
|
||||
if (loader->open(path)) {
|
||||
loader->hashpath = strdup(path.c_str());
|
||||
loader->pathcache = true;
|
||||
{
|
||||
ScopedLock lock(key);
|
||||
_activeLoaders.back(loader);
|
||||
if (allowCache) {
|
||||
loader->hashpath = strdup(path.c_str());
|
||||
loader->pathcache = true;
|
||||
{
|
||||
ScopedLock lock(key);
|
||||
_activeLoaders.back(loader);
|
||||
}
|
||||
}
|
||||
return loader;
|
||||
}
|
||||
|
@ -312,11 +321,13 @@ LoadModule* LoaderMgr::loader(const string& path, bool* invalid)
|
|||
for (int i = 0; i < static_cast<int>(FileType::Raw); i++) {
|
||||
if (auto loader = _find(static_cast<FileType>(i))) {
|
||||
if (loader->open(path)) {
|
||||
loader->hashpath = strdup(path.c_str());
|
||||
loader->pathcache = true;
|
||||
{
|
||||
ScopedLock lock(key);
|
||||
_activeLoaders.back(loader);
|
||||
if (allowCache) {
|
||||
loader->hashpath = strdup(path.c_str());
|
||||
loader->pathcache = true;
|
||||
{
|
||||
ScopedLock lock(key);
|
||||
_activeLoaders.back(loader);
|
||||
}
|
||||
}
|
||||
return loader;
|
||||
}
|
||||
|
@ -353,7 +364,15 @@ LoadModule* LoaderMgr::loader(const char* data, uint32_t size, const string& mim
|
|||
{
|
||||
//Note that users could use the same data pointer with the different content.
|
||||
//Thus caching is only valid for shareable.
|
||||
if (!copy) {
|
||||
auto allowCache = !copy;
|
||||
|
||||
//TODO: lottie is not sharable.
|
||||
if (allowCache) {
|
||||
auto type = _convert(mimeType);
|
||||
if (type == FileType::Lottie) allowCache = false;
|
||||
}
|
||||
|
||||
if (allowCache) {
|
||||
if (auto loader = _findFromCache(data, size, mimeType)) return loader;
|
||||
}
|
||||
|
||||
|
@ -361,7 +380,7 @@ LoadModule* LoaderMgr::loader(const char* data, uint32_t size, const string& mim
|
|||
if (!mimeType.empty()) {
|
||||
if (auto loader = _findByType(mimeType)) {
|
||||
if (loader->open(data, size, rpath, copy)) {
|
||||
if (!copy) {
|
||||
if (allowCache) {
|
||||
loader->hashkey = HASH_KEY(data);
|
||||
ScopedLock lock(key);
|
||||
_activeLoaders.back(loader);
|
||||
|
@ -378,7 +397,7 @@ LoadModule* LoaderMgr::loader(const char* data, uint32_t size, const string& mim
|
|||
auto loader = _find(static_cast<FileType>(i));
|
||||
if (loader) {
|
||||
if (loader->open(data, size, rpath, copy)) {
|
||||
if (!copy) {
|
||||
if (allowCache) {
|
||||
loader->hashkey = HASH_KEY(data);
|
||||
ScopedLock lock(key);
|
||||
_activeLoaders.back(loader);
|
||||
|
|
Loading…
Add table
Reference in a new issue