summaryrefslogtreecommitdiffstats
path: root/thirdparty/thorvg/src/renderer/tvgLoader.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-05-10 09:30:57 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-05-10 09:30:57 +0200
commit1cf9f37589aad257653b5d038dfefa1283be381f (patch)
tree98e2f725e8eed411358db564450c7dd96b573866 /thirdparty/thorvg/src/renderer/tvgLoader.cpp
parentc4279fe3e0b27d0f40857c00eece7324a967285f (diff)
downloadredot-engine-1cf9f37589aad257653b5d038dfefa1283be381f.tar.gz
thorvg: Update to 0.13.3, add webp loader
Remove embedded png loader, we use the external (libpng) one.
Diffstat (limited to 'thirdparty/thorvg/src/renderer/tvgLoader.cpp')
-rw-r--r--thirdparty/thorvg/src/renderer/tvgLoader.cpp50
1 files changed, 34 insertions, 16 deletions
diff --git a/thirdparty/thorvg/src/renderer/tvgLoader.cpp b/thirdparty/thorvg/src/renderer/tvgLoader.cpp
index 2853b83895..4b8d3256a9 100644
--- a/thirdparty/thorvg/src/renderer/tvgLoader.cpp
+++ b/thirdparty/thorvg/src/renderer/tvgLoader.cpp
@@ -178,7 +178,6 @@ static LoadModule* _findByPath(const string& path)
if (!ext.compare("tvg")) return _find(FileType::Tvg);
if (!ext.compare("svg")) return _find(FileType::Svg);
if (!ext.compare("json")) return _find(FileType::Lottie);
- if (!ext.compare("lottie")) return _find(FileType::Lottie);
if (!ext.compare("png")) return _find(FileType::Png);
if (!ext.compare("jpg")) return _find(FileType::Jpg);
if (!ext.compare("webp")) return _find(FileType::Webp);
@@ -271,7 +270,7 @@ bool LoaderMgr::term()
auto tmp = loader;
loader = loader->next;
_activeLoaders.remove(tmp);
- if (ret) delete(loader);
+ if (ret) delete(tmp);
}
return true;
}
@@ -295,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;
}
@@ -313,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;
}
@@ -354,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;
}
@@ -362,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, copy)) {
- if (!copy) {
+ if (allowCache) {
loader->hashkey = HASH_KEY(data);
ScopedLock lock(key);
_activeLoaders.back(loader);
@@ -379,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, copy)) {
- if (!copy) {
+ if (allowCache) {
loader->hashkey = HASH_KEY(data);
ScopedLock lock(key);
_activeLoaders.back(loader);