diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-03-09 23:58:59 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-03-09 23:58:59 +0100 |
commit | 6fa77e0f1442328a969c9ad0651047fae34f72a3 (patch) | |
tree | adbcdca713d10d162423970a36a3ea6e57298789 /thirdparty/thorvg/src/renderer/tvgLoader.cpp | |
parent | 0ace0a129284ffc6646b199699c1607a316fcec0 (diff) | |
download | redot-engine-6fa77e0f1442328a969c9ad0651047fae34f72a3.tar.gz |
thorvg: Update to 0.12.7
Diffstat (limited to 'thirdparty/thorvg/src/renderer/tvgLoader.cpp')
-rw-r--r-- | thirdparty/thorvg/src/renderer/tvgLoader.cpp | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/thirdparty/thorvg/src/renderer/tvgLoader.cpp b/thirdparty/thorvg/src/renderer/tvgLoader.cpp index fc93a0cbdc..2853b83895 100644 --- a/thirdparty/thorvg/src/renderer/tvgLoader.cpp +++ b/thirdparty/thorvg/src/renderer/tvgLoader.cpp @@ -57,9 +57,9 @@ #include "tvgRawLoader.h" -uint64_t HASH_KEY(const char* data, uint64_t size) +uintptr_t HASH_KEY(const char* data) { - return (((uint64_t) data) << 32) | size; + return reinterpret_cast<uintptr_t>(data); } /************************************************************************/ @@ -219,7 +219,7 @@ static LoadModule* _findFromCache(const string& path) auto loader = _activeLoaders.head; while (loader) { - if (loader->hashpath && !strcmp(loader->hashpath, path.c_str())) { + if (loader->pathcache && !strcmp(loader->hashpath, path.c_str())) { ++loader->sharing; return loader; } @@ -237,7 +237,7 @@ static LoadModule* _findFromCache(const char* data, uint32_t size, const string& ScopedLock lock(key); auto loader = _activeLoaders.head; - auto key = HASH_KEY(data, size); + auto key = HASH_KEY(data); while (loader) { if (loader->type == type && loader->hashkey == key) { @@ -281,7 +281,7 @@ bool LoaderMgr::retrieve(LoadModule* loader) { if (!loader) return false; if (loader->close()) { - { + if (loader->cached()) { ScopedLock lock(key); _activeLoaders.remove(loader); } @@ -300,6 +300,7 @@ LoadModule* LoaderMgr::loader(const string& path, bool* invalid) if (auto loader = _findByPath(path)) { if (loader->open(path)) { loader->hashpath = strdup(path.c_str()); + loader->pathcache = true; { ScopedLock lock(key); _activeLoaders.back(loader); @@ -313,6 +314,7 @@ LoadModule* LoaderMgr::loader(const string& path, bool* invalid) 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); @@ -338,7 +340,7 @@ LoadModule* LoaderMgr::loader(const char* key) auto loader = _activeLoaders.head; while (loader) { - if (loader->hashpath && strstr(loader->hashpath, key)) { + if (loader->pathcache && strstr(loader->hashpath, key)) { ++loader->sharing; return loader; } @@ -350,15 +352,21 @@ LoadModule* LoaderMgr::loader(const char* key) LoadModule* LoaderMgr::loader(const char* data, uint32_t size, const string& mimeType, bool copy) { - if (auto loader = _findFromCache(data, size, mimeType)) return loader; + //Note that users could use the same data pointer with the different content. + //Thus caching is only valid for shareable. + if (!copy) { + if (auto loader = _findFromCache(data, size, mimeType)) return loader; + } //Try with the given MimeType if (!mimeType.empty()) { if (auto loader = _findByType(mimeType)) { if (loader->open(data, size, copy)) { - loader->hashkey = HASH_KEY(data, size); - ScopedLock lock(key); - _activeLoaders.back(loader); + if (!copy) { + loader->hashkey = HASH_KEY(data); + ScopedLock lock(key); + _activeLoaders.back(loader); + } return loader; } else { TVGLOG("LOADER", "Given mimetype \"%s\" seems incorrect or not supported.", mimeType.c_str()); @@ -371,8 +379,8 @@ 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)) { - loader->hashkey = HASH_KEY(data, size); - { + if (!copy) { + loader->hashkey = HASH_KEY(data); ScopedLock lock(key); _activeLoaders.back(loader); } @@ -387,14 +395,18 @@ LoadModule* LoaderMgr::loader(const char* data, uint32_t size, const string& mim LoadModule* LoaderMgr::loader(const uint32_t *data, uint32_t w, uint32_t h, bool copy) { - //TODO: should we check premultiplied?? - if (auto loader = _findFromCache((const char*)(data), w * h, "raw")) return loader; + //Note that users could use the same data pointer with the different content. + //Thus caching is only valid for shareable. + if (!copy) { + //TODO: should we check premultiplied?? + if (auto loader = _findFromCache((const char*)(data), w * h, "raw")) return loader; + } //function is dedicated for raw images only auto loader = new RawLoader; if (loader->open(data, w, h, copy)) { - loader->hashkey = HASH_KEY((const char*)data, w * h); - { + if (!copy) { + loader->hashkey = HASH_KEY((const char*)data); ScopedLock lock(key); _activeLoaders.back(loader); } |